← Student tools · Problem 1 · Lecture 5 · Round 1 (30 pts)

Cantor's diagonal argument

The trick that opens the entire theory of undecidability.

CLO-1 · Diagonalization Round 1 · 30 pts Lecture 5
🔊 Listen

Before we can talk about whether a problem is "computable," we need to know whether there are even enough programs to solve all possible problems. Cantor's 1891 diagonal argument answers that with a definitive no: there are fundamentally more languages than there are programs.

The chain of consequences
  1. Cantor's theorem (this problem): the set of functions ℕ → {0,1} is uncountable.
  2. Each Turing machine has a finite description. The set of all TMs is countable.
  3. Each TM recognizes one language. So the set of TM-recognizable languages is countable.
  4. But the set of all languages over Σ = {0,1} is the same size as 2 — uncountable.
  5. Conclusion: there exist languages that NO Turing machine can recognize.

So even before you've seen the halting problem or ATM, you already know undecidable problems must exist. The diagonal argument is the original proof that "computer scientists have something to do" — there will always be limits.

Real-world analogy

Imagine you tried to list every infinite-digit decimal number 0.d1d2d3… no matter how cleverly you order them. Cantor's argument says: take the i-th digit of the i-th number, add 1 to it (mod 10), and concatenate. The resulting number disagrees with every number on your list at at least one digit. So your list missed at least one real number — and by extension, cannot be exhaustive.

🔊 Listen

Let 2 = {f : ℕ → {0, 1}} denote the set of all functions from the natural numbers to {0, 1}. Equivalently: infinite binary strings.

Theorem (Cantor, 1891)

The set 2 is uncountable. There is no surjection (onto map) from ℕ to 2.

Equivalently: for every supposed enumeration f1, f2, f3, … of functions ℕ → {0,1}, there is some function g that is NOT in the list.

Vocabulary refresher

The proof strategy is proof by contradiction: assume an enumeration exists, then construct a specific function g that cannot be in any position of the list.

🔊 Listen

Suppose for contradiction that 2 were countable. Then we could list all its elements:

f1, f2, f3, f4, …

Picture the list as an infinite table. Row i shows fi's values: fi(0), fi(1), fi(2), …

        col 0   col 1   col 2   col 3   …
f₁  →   f₁(0)   f₁(1)   f₁(2)   f₁(3)   …
f₂  →   f₂(0)   f₂(1)   f₂(2)   f₂(3)   …
f₃  →   f₃(0)   f₃(1)   f₃(2)   f₃(3)   …
f₄  →   f₄(0)   f₄(1)   f₄(2)   f₄(3)   …
 ⋮       ⋮       ⋮       ⋮       ⋮

The diagonal consists of the underlined cells fi(i−1): f1(0), f2(1), f3(2), … Now define a new function:

g(n) = 1 − fn+1(n)

That is, take the (n+1)-th row's n-th entry and flip it.

Why g is not in the list

Suppose, for further contradiction, that g = fk for some specific k ≥ 1. Then in particular g(k−1) = fk(k−1). But by our construction:

g(k−1) = 1 − fk(k−1).

Combining: fk(k−1) = 1 − fk(k−1). But a Boolean value cannot equal its own negation. Contradiction. So no such k exists. ∎

The single key insight

g only needs to disagree at one cell per row. By targeting the diagonal, g is guaranteed to differ from row k at column k−1, no matter what row k contains. The diagonal acts as a "uniform target" — one cell per supposed-listed function.

🔊 Listen
Cantor's diagonal · build rows, then flip Auto-plays
🔊 Listen

Let's do this with concrete numbers. Suppose someone claims they've listed every binary sequence and gives us these 4 as the first four entries:

        n=0   n=1   n=2   n=3   n=4   n=5  …
f₁  →    0     1     0     1     1     0
f₂  →    1     1     0     0     1     0
f₃  →    0     0     1     1     0     0
f₄  →    1     0     0     0     1     1

The bold cells are the diagonal: f1(0)=0, f2(1)=1, f3(2)=1, f4(3)=0.

Now construct g by flipping each diagonal bit:

g(0) = 1 − f₁(0) = 1 − 0 = 1
g(1) = 1 − f₂(1) = 1 − 1 = 0
g(2) = 1 − f₃(2) = 1 − 1 = 0
g(3) = 1 − f₄(3) = 1 − 0 = 1

So g starts 1, 0, 0, 1, ... Compare with each row:

g disagrees with EVERY row at exactly one cell. So g is not in the list, contradicting the assumption of exhaustiveness.

🔊 Listen
Five places in this course where you'll see diagonalization again
  1. ATM is undecidable (Problem 3): rows = TMs, columns = TM descriptions, flip cells to build contradiction TM D.
  2. Rice's theorem (Problem 14): diagonalization shows every nontrivial semantic property of recognizable languages is undecidable.
  3. Time hierarchy theorem (Problem 46): rows = TIME(f) machines, columns = inputs. D times out at f·log f, escapes TIME(f).
  4. Space hierarchy theorem (Problem 45): same idea with space bounds. Concrete proof that SPACE(f) ⊊ SPACE(f · log f).
  5. Gödel's incompleteness (outside this course): self-referential sentence "this sentence is not provable" is built by diagonalization.

Diagonalization is so prevalent that any time you see "for every algorithm X, here's an input that escapes it", you should suspect a diagonal argument is hiding behind it.

Why it works only for the right things

Diagonalization needs three ingredients:

  1. An enumeration of the things you want to show miss something (functions, TMs, programs in time bound).
  2. A way to simulate each item from its description (for TMs: the universal TM).
  3. A way to flip the answer (for {0,1} functions: subtract from 1; for TMs: swap accept and reject).

These are the same ingredients that make P ≠ NP famously HARD to prove — flipping the answer of an NP machine isn't obviously possible while staying in NP.

🔊 Listen
🔊 Listen
🔊 Listen
  1. State the theorem (1 min): "There are more binary sequences than natural numbers."
  2. Real-world hook (1 min): "You will see this proof technique 5 more times this semester. Watch carefully."
  3. Reset the widget; explain rows and columns (1 min).
  4. Step through 5 rows manually; point out diagonal cells (2 min).
  5. Flip the diagonal; show how g escapes each row (2 min).
  6. Walk through the worked example for n = 4 with concrete bits (3 min).
  7. State the consequence: most languages are not Turing-recognizable (1 min).
  8. Q&A (3-5 min): expect "what about g?", "does ordering matter?", "what if we listed g too?".