Cite

This course has no released version yet: the text at this address may change. Cite a released version when one exists.

/courses/countability/diagonal-argument
@misc{countability-diagonal-argument,
  title = {{The diagonal argument}},
  howpublished = {Lesson 4 of \emph{Countability and diagonalization}, Computability Theory course notes},
  url = {/courses/countability/diagonal-argument},
  note = {Unreleased working version}
}

To cite a single statement, use the # link that appears next to its heading.

Lesson 4 of 6

The diagonal argument

Cantor space; uncountability of the sets of binary sequences, of integer sequences, of power sets and of ℝ by diagonalization; a general form of the argument.

40 min8 questions
Before this lesson:Countable sets
Countability and diagonalization · lesson 4 of 6
  1. Equipotence and subpotence
  2. The Cantor–Bernstein theorem
  3. Countable sets
  4. The diagonal argument
  5. The cardinality of the continuum
  6. Diagonalization and computation

In 1891, Cantor gave a short proof that no sequence of infinite binary sequences contains all of them. The method, called diagonalization, is the most frequently used argument in computability theory: it shows that the halting problem is undecidable, that there are total computable functions which are not primitive recursive, and, in more elaborate forms, it underlies most constructions of non-computable sets. This lesson presents the argument, isolates its general form, and derives the uncountability of 2N2^\nat, NN\nat^\nat, P(A)\mathcal P(A) and R\mathbb R.

4.1 Cantor space

Definition 4.1.#

Cantor space is the set 2N\cs of infinite binary sequences, that is, of functions X:N→{0,1}X : \nat \to \{0, 1\}. For X∈2NX \in \cs and n∈Nn \in \nat, the value X(n)X(n) is the nn-th bit of XX, and one writes X=X(0) X(1) X(2)⋯X = X(0)\,X(1)\,X(2) \cdots.

A sequence X∈2NX \in \cs and the set {n:X(n)=1}⊆N\{ n : X(n) = 1 \} \subseteq \nat determine each other: the map X↦{n:X(n)=1}X \mapsto \{ n : X(n) = 1 \} is a bijection from 2N\cs onto P(N)\mathcal P(\nat), whose inverse sends a set to its characteristic function. In computability theory the two points of view are used interchangeably: the same letter XX denotes a subset of N\nat and its characteristic function, so that n∈Xn \in X if and only if X(n)=1X(n) = 1.

Finite binary strings are written σ,τ,…\sigma, \tau, \dots; the set of finite binary strings is 2<N2^{<\nat}, the length of σ\sigma is ∣σ∣|\sigma|, and X↾n=X(0)⋯X(n−1)X \upharpoonright n = X(0) \cdots X(n-1) is the prefix of length nn of XX. By Proposition 3.11, 2<N2^{<\nat} is countable.

4.2 The diagonal argument

Theorem 4.2 (Cantor).#

The set 2N\cs is uncountable: for every sequence X0,X1,X2,…X_0, X_1, X_2, \dots of elements of 2N\cs, the sequence YY defined by

Y(n)=1−Xn(n)Y(n) = 1 - X_n(n)

is different from every XnX_n.

Proof of Theorem 4.2.

For every nn, the sequences YY and XnX_n differ at position nn, since Y(n)=1−Xn(n)≠Xn(n)Y(n) = 1 - X_n(n) \neq X_n(n). So YY is none of the XnX_n. Hence no function N→2N\nat \to \cs is surjective, and 2N\cs, which is non-empty, is not countable by Proposition 3.3.

0123456⋯X00110100⋯X11101001⋯X20000110⋯X31011011⋯X40101010⋯⋮Y10101⋯⋯Y(n) = 1 − Xₙ(n)

The sequences XnX_n written as the rows of an infinite table. The sequence YY is obtained by flipping the bits of the diagonal, so that it differs from row nn in column nn.

The name of the argument comes from the table: the bits Xn(n)X_n(n) form its diagonal. Two features matter. First, YY is defined from the sequence (Xn)(X_n), explicitly: the proof does not only show that some sequence is missing, it computes one. Second, each XnX_n is defeated at a position of its own, so that the constraints on YY never conflict.

4.3 A general form

The argument uses neither binary values nor the indexing by integers in an essential way. Its general form is the following.

Proposition 4.3 (Diagonal lemma).#

Let AA and BB be sets, F:A×A→BF : A \times A \to B a function, and δ:B→B\delta : B \to B a function without fixed point, that is, δ(b)≠b\delta(b) \neq b for every b∈Bb \in B. Then the function g:A→Bg : A \to B defined by

g(a)=δ(F(a,a))g(a) = \delta\big(F(a, a)\big)

is different from each function F(e,⋅):a↦F(e,a)F(e, \cdot) : a \mapsto F(e, a), for e∈Ae \in A.

Proof of Proposition 4.3.

For e∈Ae \in A, g(e)=δ(F(e,e))≠F(e,e)g(e) = \delta(F(e, e)) \neq F(e, e), so gg and F(e,⋅)F(e, \cdot) differ at ee.

A function F:A×A→BF : A \times A \to B is the same thing as a family (F(e,⋅))e∈A(F(e, \cdot))_{e \in A} of functions A→BA \to B, indexed by AA, that is, a function from AA to the set BAB^A of functions from AA to BB. The lemma says that such a family never contains all functions A→BA \to B, as soon as BB has a fixed-point-free map. Read contrapositively:

Corollary 4.4 (Lawvere’s fixed point theorem).#

If there is a surjection from AA onto BAB^A, then every function δ:B→B\delta : B \to B has a fixed point.

Proof of Corollary 4.4.

Let e↦Fee \mapsto F_e be a surjection from AA onto BAB^A, and let F(e,a)=Fe(a)F(e, a) = F_e(a). If δ\delta had no fixed point, the function gg of Proposition 4.3 would differ from every FeF_e, contradicting surjectivity.

If BB has at least two elements b0≠b1b_0 \neq b_1, the map exchanging b0b_0 and b1b_1 and fixing every other element has no fixed point, so there is no surjection from AA onto BAB^A. The fixed point form is not a curiosity: Kleene’s fixed point theorem in the course on fundamentals (Fixed point theorem) has the same structure, with a numbering of partial computable functions in place of the surjection, and with the conclusion that every total computable transformation ff of programs has a fixed point up to the function computed: Φf(e)=Φe\Phi_{f(e)} = \Phi_e for some ee.

Example 4.5.#
  1. A=NA = \nat, B={0,1}B = \{0, 1\}, δ(b)=1−b\delta(b) = 1 - b, and F(n,m)=Xn(m)F(n, m) = X_n(m) gives Theorem 4.2.
  2. A=B=NA = B = \nat, δ(b)=b+1\delta(b) = b + 1: for every sequence (fn)(f_n) of functions N→N\nat \to \nat, the function g(n)=fn(n)+1g(n) = f_n(n) + 1 differs from every fnf_n. So the Baire space NN\nat^\nat of functions N→N\nat \to \nat is uncountable.
  3. AA arbitrary, B={0,1}B = \{0, 1\}: functions A→{0,1}A \to \{0, 1\} are characteristic functions of subsets of AA; this gives the theorem of the next section.

4.4 Every set is smaller than its power set

Theorem 4.6 (Cantor).#

For every set AA, there is no surjection from AA onto its power set P(A)\mathcal P(A). Hence ∣A∣<∣P(A)∣|A| < |\mathcal P(A)|.

Proof of Theorem 4.6.

Let f:A→P(A)f : A \to \mathcal P(A), and let

D={a∈A:a∉f(a)}.D = \{ a \in A : a \notin f(a) \}.

If D=f(d)D = f(d) for some d∈Ad \in A, then d∈Dd \in D if and only if d∉f(d)=Dd \notin f(d) = D, a contradiction. So DD is not in the image of ff. Finally, a↦{a}a \mapsto \{a\} is an injection A→P(A)A \to \mathcal P(A), so ∣A∣≤∣P(A)∣|A| \leq |\mathcal P(A)|; and ∣A∣≠∣P(A)∣|A| \neq |\mathcal P(A)|, since a bijection would be a surjection.

Iterating, N\nat, P(N)\mathcal P(\nat), P(P(N))\mathcal P(\mathcal P(\nat)), … is a sequence of infinite sets of strictly increasing cardinalities: there is no largest cardinality.

Remark 4.7 (Russell’s paradox).#

Apply the proof to a hypothetical set VV of all sets, with ff the identity: every subset of VV is a set, hence an element of VV, so f(x)=xf(x) = x for x∈P(V)x \in \mathcal P(V) (and, say, f(x)=∅f(x) = \emptyset for the elements of VV that are not sets) is a surjection onto P(V)\mathcal P(V). The diagonal set is D={x:x∉x}D = \{ x : x \notin x \}, essentially Russell’s set, and the contradiction is Russell’s paradox (1901). In axiomatic set theory, the conclusion is that there is no set of all sets; the collection {x:x∉x}\{x : x \notin x\} exists only as a class.

4.5 The real numbers

The diagonal argument gives a short proof of Cantor’s first uncountability theorem (1874). Decimal expansions need some care, because some real numbers have two of them: 0.1999⋯=0.2000⋯0.1999\cdots = 0.2000\cdots. For a real number xx and k≥1k \geq 1, let

dk(x)=⌊10kx⌋−10⌊10k−1x⌋∈{0,1,…,9}d_k(x) = \lfloor 10^k x \rfloor - 10 \lfloor 10^{k-1} x \rfloor \in \{0, 1, \dots, 9\}

be the kk-th decimal digit of the fractional part x−⌊x⌋x - \lfloor x \rfloor, in the expansion that does not end with infinitely many 99s.

Theorem 4.8 (Cantor).#

The set R\mathbb R is uncountable: for every sequence (xn)n∈N(x_n)_{n \in \nat} of real numbers, the number

r=∑n∈Ncn 10−(n+1),cn={4if dn+1(xn)=5,5otherwise,r = \sum_{n \in \nat} c_n \, 10^{-(n+1)}, \qquad c_n = \begin{cases} 4 & \text{if } d_{n+1}(x_n) = 5,\\ 5 & \text{otherwise,}\end{cases}

is different from every xnx_n.

Proof of Theorem 4.8.

We first show dk(r)=ck−1d_{k}(r) = c_{k-1} for every k≥1k \geq 1. For every k≥0k \geq 0, write

10kr=∑n<kcn 10k−1−n+tk,tk=∑n≥kcn 10k−1−n.10^k r = \sum_{n < k} c_n \, 10^{k-1-n} + t_k, \qquad t_k = \sum_{n \geq k} c_n \, 10^{k-1-n}.

The first sum is an integer NkN_k, and since every cnc_n lies in {4,5}\{4, 5\}, the tail satisfies 0<49≤tk≤59<10 < \tfrac49 \leq t_k \leq \tfrac59 < 1. So ⌊10kr⌋=Nk\lfloor 10^k r \rfloor = N_k, and dk(r)=Nk−10Nk−1=ck−1d_k(r) = N_k - 10 N_{k-1} = c_{k-1}.

Now if r=xnr = x_n, then dn+1(xn)=dn+1(r)=cnd_{n+1}(x_n) = d_{n+1}(r) = c_n, which contradicts the definition of cnc_n, chosen different from dn+1(xn)d_{n+1}(x_n).

The digits 44 and 55 are chosen so that the tail tkt_k stays below 11, which makes 0.c0c1c2⋯0.c_0c_1c_2\cdots the expansion of rr that does not end with 99s; any two digits other than 99 would do as well. The digit 99 must be avoided: a rule that only requires cn≠dn+1(xn)c_n \neq d_{n+1}(x_n) could produce c0=0c_0 = 0 and cn=9c_n = 9 for all n≥1n \geq 1, so that r=0.0999⋯=0.1r = 0.0999\cdots = 0.1, while x0=0.1x_0 = 0.1 has d1(x0)=1≠c0d_1(x_0) = 1 \neq c_0.

4.6 Exercises

Exercise 4.9 ★.

Show that the set of infinite subsets of N\nat, and the set of strictly increasing functions N→N\nat \to \nat, are uncountable.

Solution

The map X↦{2n+X(n):n∈N}X \mapsto \{ 2n + X(n) : n \in \nat \} is an injection of 2N\cs into the set of infinite subsets of N\nat: the image contains exactly one element of {2n,2n+1}\{2n, 2n+1\} for each nn, and X(n)X(n) is its parity. Similarly, X↦(n↦2n+X(n))X \mapsto (n \mapsto 2n + X(n)) is an injection of 2N\cs into the set of strictly increasing functions, since 2n+X(n)≤2n+1<2(n+1)+X(n+1)2n + X(n) \leq 2n + 1 < 2(n+1) + X(n+1). A set into which 2N\cs injects is uncountable, since otherwise 2N\cs would be countable by Corollary 3.4.

Exercise 4.10 ★★.

Show that the set of bijections N→N\nat \to \nat is uncountable.

Solution

To X∈2NX \in \cs, associate the permutation πX\pi_X that exchanges 2n2n and 2n+12n + 1 when X(n)=1X(n) = 1, and fixes them when X(n)=0X(n) = 0. It is a bijection (it is its own inverse), and X↦πXX \mapsto \pi_X is injective, since X(n)=1X(n) = 1 if and only if πX(2n)=2n+1\pi_X(2n) = 2n + 1. Conclude as in the previous exercise.

Exercise 4.11 ★★.

(Cantor’s proof of 1874.) Let (xn)(x_n) be a sequence of real numbers. Construct closed intervals [a0,b0]⊇[a1,b1]⊇⋯[a_0, b_0] \supseteq [a_1, b_1] \supseteq \cdots with bn−an=3−nb_n - a_n = 3^{-n} and xn∉[an+1,bn+1]x_n \notin [a_{n+1}, b_{n+1}], and deduce that some real number differs from every xnx_n. Which property of R\mathbb R is used?

Solution

Start from [a0,b0]=[0,1][a_0, b_0] = [0, 1]. Given [an,bn][a_n, b_n], cut it into three closed thirds; xnx_n belongs to at most two of them, since the first and the last third are disjoint. Let [an+1,bn+1][a_{n+1}, b_{n+1}] be the leftmost third not containing xnx_n. The sequence (an)(a_n) is non-decreasing and bounded by b0b_0, so it has a limit rr, by the completeness of R\mathbb R; and am≤r≤bma_m \leq r \leq b_m for every mm, since an≤bma_n \leq b_m for all nn and mm. Then r∈[an+1,bn+1]r \in [a_{n+1}, b_{n+1}], so r≠xnr \neq x_n, for every nn. Over Q\mathbb Q, which is countable, the limit rr need not exist.

Exercise 4.12 ★★.

Let (Xn)(X_n) be a sequence of elements of 2N\cs. Show that the set of Y∈2NY \in \cs different from every XnX_n is uncountable.

Solution

Let M=2N∖{Xn:n∈N}M = \cs \setminus \{ X_n : n \in \nat \}. It is non-empty by Theorem 4.2. If it were countable, there would be a surjection m↦Zmm \mapsto Z_m from N\nat onto MM, and the sequence X0,Z0,X1,Z1,…X_0, Z_0, X_1, Z_1, \dots, that is, W2n=XnW_{2n} = X_n and W2n+1=ZnW_{2n+1} = Z_n, would enumerate all of 2N\cs, contradicting Theorem 4.2. The lesson on the continuum shows more: MM is equipotent to 2N\cs.

4.7 Notes and references

The diagonal argument appears in Cantor’s note of 1891, where it is applied to binary sequences and then to the power set of an arbitrary set. The 1874 proof of the uncountability of R\mathbb R uses nested intervals. The general form of the diagonal lemma and its fixed point reading are due to Lawvere, in the setting of cartesian closed categories; Yanofsky gives an elementary account, with applications to the paradoxes and to incompleteness. Russell communicated his paradox to Frege in a letter of 1902, and published it in the Principles of Mathematics.

  • G. Cantor, Über eine elementare Frage der Mannigfaltigkeitslehre, Jahresbericht der Deutschen Mathematiker-Vereinigung 1 (1891), 75–78.
  • F. W. Lawvere, Diagonal arguments and cartesian closed categories, in Category Theory, Homology Theory and their Applications II, Lecture Notes in Mathematics 92, Springer, 1969, 134–145.
  • N. S. Yanofsky, A universal approach to self-referential paradoxes, incompleteness and fixed points, Bulletin of Symbolic Logic 9 (2003), 362–386.
  • B. Russell, The Principles of Mathematics, Cambridge University Press, 1903.