2025-05-07
Everything you need for this course can be found on the course website.
I will make all announcements through Piazza or Quercus (which will send you an email notification).
Part 1: Mathematical tools.
Part 2: Algorithm correctness and runtime.
Part 3: Finite automata.
Is it possible to…
If so, how? Also, how much…
… do we need?
For programmers:
In general:
Are there problems computers can’t solve?
Subset | \(A \subseteq B\) |
Union | \(A \cup B\) |
Intersection | \(A \cap B\) |
Difference | \(A \setminus B\) |
Cardinality (size) | \(|A|\) |
The empty set, denoted \(\emptyset\), is the set containing nothing. I.e., \[\{\}\]
For any set, \(A\), the power set of \(A\), denoted \(\wp(A)\), is the set of all subsets of \(A\). I.e., \[\wp(A)= \{B: B \subseteq A\}\]
A function is a mapping from one set to another. We write a function that maps elements of \(A\) to elements of \(B\) as
\[ f: A \to B \]
\(A\) is called the domain. \(B\) is called the codomain.
Domain: the set of all possible lists of integers
Codomin: the set of integersA function is injective if nothing in the codomain is hit more than once. Formally,
Definition 1 (Injective) A function \(f:A \to B\) is injective if \[\forall x, y \in A.(x \neq y \implies f(x) \neq f(y))\]
“If the inputs are different, the outputs are different.”
Sometimes, the equivalent contrapositive is easier to work with
Definition 2 A function \(f:A \to B\) is injective if \[\forall x, y \in A.(f(x) = f(y) \implies x = y)\]
“If the outputs are the same, the inputs are the same.”
\(f:A \to B\) is injective if \(\forall x, y \in A.(x \neq y \implies f(x) \neq f(y))\)
\(f:A \to B\) is injective if \(\forall x, y \in A.(x \neq y \implies f(x) \neq f(y))\)
Is there an injective function between these two sets?
Theorem 1 (Pigeonhole Principle) Let \(A\), \(B\) be finite sets where \(|A| > |B|\). Then there is no injective function \(f:A \to B\).
\(f:A \to B\) is injective if \(\forall x, y \in A.(x \neq y \implies f(x) \neq f(y))\)
How do you do it?
Now suppose another bus containing an infinite number of people shows up \(b_0, b_1,...\)
Currently, each room is already occupied!
However, eager to impress your boss, you try to think of a way to do the impossible - fit an infinite number of people into an already filled hotel. So, how do you do it?
\(f:A \to B\) is injective if \(\forall x, y \in A.(x \neq y \implies f(x) \neq f(y))\)
\[f(x) = \begin{cases} 2i & x = a_i \\ 2i + 1 & x = b_i \end{cases}\]
Let \(x, y\) be customers such that \(x \neq y\). We’ll show \(f(x) \neq f(y)\). There are several cases.
A function is surjective if everything in the codomain is hit. Formally,
Definition 3 (Surjective) A function, \(f: A \to B\) is surjective if \[\forall b \in B. \exists a \in A. (f(a) = b)\]
\(f\) is surjective if \(\forall b \in B. \exists a \in A. (f(a) = b)\).
Is \(f\) defined by \(f(n) = n\) surjective?
It depends on the domain/codomain! For example, \(f:\mathbb{N}\to \mathbb{N}\) defined by \(f(n) = n\) is surjective, but \(f:\mathbb{N}\to \mathbb{R}\) defined by \(f(n) = n\) is not!
It’s essential to always specify the domain and codomain when defining a function.
A function is bijective if everything in the codomain is hit exactly once. Formally,
Definition 4 A function \(f:A \to B\) is bijective if \(f\) is both injective and surjective.
\(f\) is injective if \(\forall x, y \in A.(x \neq y \implies f(x) \neq f(y))\)
\(f\) is surjective if \(\forall b \in B. \exists a \in A. (f(a) = b)\).
We’ll show \(f:\mathbb{R}\to\mathbb{R}\) defined by \(f(x) = x/2\) is a bijection. To do so, we’ll show that \(f\) is both injective and surjective.
\[ f(a) = f(2b) = 2b/2 = b, \] and thus \(f\) is surjective.
Let \(f: A \to B\) be a function.
\(f\) is… | if \(\forall b \in B\), \(b\) is hit… | Formally… |
---|---|---|
Injective | \(1\) or \(0\) times | \(\forall x, y \in A.(x \neq y \implies f(x) \neq f(y))\) |
Surjective | at least \(1\) time | \(\forall b \in B. \exists a \in A. (f(a) = b)\) |
Bijective | exactly \(1\) time | Injective and Surjective |
\(b \in B\) is hit \(k\) times by \(f\) if there are \(k\) distinct \(a \in A\) are such that \(f(a) = b\). I.e. \[|\{a \in A: f(a) = b\}| = k.\]
\(f\) is surjective if \(\forall b \in B. \exists a \in A. (f(a) = b)\).
Theorem 2 (Cantor’s Theorem) For any set \(A\), there is no surjection between \(A\) and \(\wp(A)\)
Cantor’s Theorem. For any set \(A\), there is no surjection between \(A\) and \(\wp(A)\).
Let \(f: A \to \wp(A)\) be any function. Let \(D = \{a\in A: a \notin f(a)\}\) and note that \(D \subseteq A\), and hence \(D \in \wp(A)\).
To show \(f\) is not surjective, we’ll show that, in particular, there is no \(a \in A\) such that \(f(a) = D\).
By contradiction, assume \(D = f(a)\) for some \(a \in A\). There are two cases, either \(a \in D\) or \(a \notin D\).
Since we reached a contradiction in both cases, our assumption must have been false. Thus, \(f\) is not surjective.
Let’s apply our knowledge of functions to answer the question!
Let Strings be the set of all possible strings. For each subset \(A \subseteq\) Strings, there is the problem of determining whether or not a given input is in \(A\) or not in \(A\).
For example
\(A = \{w \in\) Strings \(: w\) is a palindrome \(\}\)
\[A = \{w: w \text{ is a C program with no syntax errors}\}.\] Let’s only consider problems of this type for now, so set
Problems \(= \wp(\)Strings \()\)
For concreteness, let’s say a program \(P\) solves a problem \(A \subseteq\) Strings, if \(\forall w \in\) Strings,
\(w \in A \iff\) \(P\) run on input \(w\) prints \(1\) and nothing else.
Identify every program with its source code (a string), so Programs \(\subseteq\) Strings
Let Solves: Programs \(\to\) Strings be the function that maps each program to the problem it solves. Since each program solves at most one problem, this function is well-defined.
Our question about whether or not computers can solve all problems is the question of whether or not Solves isThe answer to our original question is no - computers cannot solve all problems! We will prove this by showing that Solves is not surjective.
By contradiction, assume Solves: Programs \(\to \wp(\)Strings\()\) is surjective. The strategy will be to construct a surjective function from Strings\(\to \wp(\)Strings\()\) which contradicts Cantor’s Theorem.
Let \(f:\)Strings\(\to \wp(\)Strings\()\) be defined as follows
\[f(w) = \begin{cases} \text{Solves}(w) & w \in \text{Programs} \\ \emptyset & \text{else} \end{cases} \]
We claim that \(f\) is surjective. Let \(b \in \wp(\)Strings\()\), since Solves is surjective, there is some program \(a\) such that Solves\((a) = b\). Since Programs\(\subseteq\) Strings, \(a \in\) Strings. By the definition of \(f\), \(f(a) =\) Solves\((a) = b.\) Thus, \(f\) is surjective, contradicting Cantor’s Theorem.
Since we have reached a contradiction, the assumption must have been false. Therefore, Solves is not surjective.What are your questions?
CSC236 Summer 2025