Cite

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

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

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

Lesson 6 of 6

Diagonalization and computation

Counting arguments; effective diagonalization against uniformly computable sequences; partial functions and the halting set; diagonalization by requirements.

40 min8 questions
Before this lesson:The cardinality of the continuum · Equivalence of the models (Models of computation) · The Ackermann function (Models of computation)
Countability and diagonalization · lesson 6 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

This lesson connects the previous ones with computation. Counting shows that almost all functions are not computable, but it exhibits none. Diagonalization does better: applied to an enumeration that is itself computable, it produces a function that is computable, and escapes the enumeration. Applied to the enumeration Φ0,Φ1,Φ2,…\Phi_0, \Phi_1, \Phi_2, \dots of all partial computable functions, it does not produce a contradiction, but a point of divergence, and from there the undecidability of the halting problem. The last section presents diagonalization as the satisfaction of a list of requirements, the form in which it is used in the rest of computability theory.

We use the notation of the course on models of computation: Φe\Phi_e is the partial function computed by the program of code ee, and Φ(e,x)≃Φe(x)\Phi(e, x) \simeq \Phi_e(x) is partial computable (Universal function). We write Φe(x) ⁣ ⁣↓\Phi_e(x)\converge when the computation halts and Φe(x) ⁣ ⁣↑\Phi_e(x)\diverge otherwise.

6.1 Counting

Proposition 6.1.#

The set of partial computable functions N⇀N\nat \rightharpoonup \nat, the set of total computable functions N→N\nat \to \nat and the set of computable subsets of N\nat are countably infinite.

Proof of Proposition 6.1.

By Universal function, every partial computable function is Φe\Phi_e for some ee, so e↦Φee \mapsto \Phi_e is a surjection from N\nat onto the partial computable functions, which are therefore countable (Proposition 3.3). The total computable functions form a subset, and the computable sets are the images of the computable characteristic functions under the bijection X↦{n:X(n)=1}X \mapsto \{ n : X(n) = 1 \}, so both are countable by Corollary 3.4. All three sets are infinite: they contain the constant functions, or the finite sets n‾\underline n.

Corollary 6.2.#

The set of functions N→N\nat \to \nat that are not computable, and the set of subsets of N\nat that are not computable, have the cardinality of the continuum.

Proof of Corollary 6.2.

They are the complements of countable sets in NN\nat^\nat and 2N\cs, which have the cardinality of the continuum by Theorem 5.5. Conclude by Proposition 5.7.

The argument does not depend on the details of the model of computation. It uses only that every computable function has a finite description, so that there are countably many of them. For the same reason, there are only countably many subsets of N\nat definable by a formula of first-order arithmetic, so that most sets are not definable in arithmetic. The argument is not constructive: it does not exhibit any particular non-computable function.

6.2 Effective diagonalization

The diagonal function g(n)=fn(n)+1g(n) = f_n(n) + 1 of Example 4.5 is defined from the whole sequence (fn)(f_n). If this sequence is given by an algorithm, so is gg.

Definition 6.3.#

A sequence (fe)e∈N(f_e)_{e \in \nat} of total functions N→N\nat \to \nat is uniformly computable if the function (e,x)↦fe(x)(e, x) \mapsto f_e(x) is computable. A sequence of sets is uniformly computable if the sequence of their characteristic functions is.

Each function of a uniformly computable sequence is computable, but the converse fails: being uniformly computable means that a single algorithm computes fe(x)f_e(x) from ee and xx, not only that each fef_e has an algorithm of its own. For instance, let fef_e be the constant function with value 11 if e∈∅′e \in \emptyset' and 00 otherwise, where ∅′\emptyset' is the halting set of Corollary 6.8 below. Each fef_e is constant, hence computable, but e↦fe(0)e \mapsto f_e(0) is the characteristic function of ∅′\emptyset', which is not computable.

Theorem 6.4.#

If (fe)(f_e) is a uniformly computable sequence of total functions, then the function g(n)=fn(n)+1g(n) = f_n(n) + 1 is total computable and differs from every fef_e. Consequently, there is no uniformly computable sequence containing all total computable functions.

Proof of Theorem 6.4.

The function gg is obtained by composing the computable function (e,x)↦fe(x)(e, x) \mapsto f_e(x) with n↦(n,n)n \mapsto (n, n) and with the successor, so it is computable; it is total since each fef_e is. It differs from every fef_e by Proposition 4.3. If a uniformly computable sequence contained all total computable functions, it would contain gg.

The primitive recursive functions form a uniformly computable sequence (fe)(f_e): enumerate the derivations and evaluate them. This is the argument of Theorem 7.6 of “The Ackermann function”, which yields a total computable function that is not primitive recursive. The theorem shows that the total computable functions themselves cannot be enumerated in this way. The obstacle is identified by the following consequence.

Corollary 6.5.#

The set Tot={e∈N:Φe is total}\mathrm{Tot} = \{ e \in \nat : \Phi_e \text{ is total} \} is not computable.

Proof of Corollary 6.5.

The set Tot\mathrm{Tot} is infinite: the constant functions are total computable and pairwise distinct, and each of them is Φe\Phi_e for some ee. Suppose Tot\mathrm{Tot} computable. Then its principal function pp (Lemma 3.2) is computable, by

p(0)=μe [e∈Tot],p(n+1)=μe [e>p(n)∧e∈Tot],p(0) = \mu e\, [e \in \mathrm{Tot}], \qquad p(n+1) = \mu e\, [e > p(n) \wedge e \in \mathrm{Tot}],

where each search terminates since Tot\mathrm{Tot} is infinite. Let fn(x)=Φ(p(n),x)f_n(x) = \Phi(p(n), x). Since Φ\Phi is partial computable, (n,x)↦fn(x)(n, x) \mapsto f_n(x) is partial computable; and it is total, since p(n)∈Totp(n) \in \mathrm{Tot}. So (fn)(f_n) is a uniformly computable sequence of total functions. Every total computable function is Φe\Phi_e for some e∈Tote \in \mathrm{Tot}, that is, e=p(n)e = p(n) for some nn, so it is fnf_n. This contradicts Theorem 6.4.

6.3 Partial functions

The enumeration Φ0,Φ1,…\Phi_0, \Phi_1, \dots of the partial computable functions is uniformly computable in the sense that Φ\Phi is partial computable. What happens when one diagonalizes against it?

Proposition 6.6.#

The partial function d(e)≃Φe(e)+1d(e) \simeq \Phi_e(e) + 1 is partial computable. If cc is a code of dd, that is, d=Φcd = \Phi_c, then Φc(c) ⁣ ⁣↑\Phi_c(c)\diverge.

Proof of Proposition 6.6.

dd is obtained by composing Φ\Phi, which is partial computable, with e↦(e,e)e \mapsto (e, e) and with the successor; it is defined exactly when Φe(e) ⁣ ⁣↓\Phi_e(e)\converge. If d=Φcd = \Phi_c and Φc(c) ⁣ ⁣↓\Phi_c(c)\converge, then Φc(c)=d(c)=Φc(c)+1\Phi_c(c) = d(c) = \Phi_c(c) + 1, which is impossible. So Φc(c) ⁣ ⁣↑\Phi_c(c)\diverge.

So the diagonal argument does not fail: it determines a point, cc, where the enumerated function d=Φcd = \Phi_c must be undefined. The partial functions escape diagonalization by being undefined at the diagonal point. This is why an enumeration of all partial computable functions can be computable, while an enumeration of all total computable functions cannot.

Theorem 6.7.#

The partial computable function d(e)≃Φe(e)+1d(e) \simeq \Phi_e(e) + 1 has no total computable extension: there is no total computable hh with h(e)=d(e)h(e) = d(e) whenever d(e) ⁣ ⁣↓d(e)\converge.

Proof of Theorem 6.7.

Suppose hh is such an extension, and let cc be a code of hh, so that Φc=h\Phi_c = h is total. Then Φc(c) ⁣ ⁣↓\Phi_c(c)\converge, so d(c)=Φc(c)+1d(c) = \Phi_c(c) + 1 is defined, and h(c)=d(c)=h(c)+1h(c) = d(c) = h(c) + 1, a contradiction.

Corollary 6.8.#

The halting set ∅′={e:Φe(e) ⁣ ⁣↓}\emptyset' = \{ e : \Phi_e(e)\converge \} is not computable.

Proof of Corollary 6.8.

If ∅′\emptyset' were computable, the function hh defined by h(e)=Φe(e)+1h(e) = \Phi_e(e) + 1 if e∈∅′e \in \emptyset', and h(e)=0h(e) = 0 otherwise, would be total computable: to compute h(e)h(e), decide whether e∈∅′e \in \emptyset', and run the computation of Φe(e)\Phi_e(e) only if it halts. It would extend dd, contradicting Theorem 6.7.

This is the halting problem, which is the starting point of the course on fundamentals (Theorem 3.2 of “The halting problem”). Its proof there is the same diagonal argument, presented directly.

6.4 Diagonalization by requirements

In the diagonal argument, the sequence YY is built to satisfy infinitely many conditions, Y≠XnY \neq X_n for each nn, each of which can be secured by fixing a single bit. Constructions in computability theory are usually organized in this way: one lists requirements R0,R1,R2,…R_0, R_1, R_2, \dots, and builds the desired object by finite approximations, ensuring each requirement at its turn.

For strings σ,τ∈2<N\sigma, \tau \in 2^{<\nat}, write σ⪯τ\sigma \preceq \tau if σ\sigma is a prefix of τ\tau, and σ≺X\sigma \prec X if σ\sigma is a prefix of X∈2NX \in \cs. A requirement is a property of elements of 2N\cs, that is, a subset R⊆2NR \subseteq \cs.

Lemma 6.9 (Finite extension).#

Let (Re)e∈N(R_e)_{e \in \nat} be a sequence of requirements such that for every ee and every σ∈2<N\sigma \in 2^{<\nat}, there is τ⪰σ\tau \succeq \sigma such that every X≻τX \succ \tau satisfies ReR_e. Then there is Y∈2NY \in \cs satisfying every ReR_e.

Proof of Lemma 6.9.

Fix an enumeration ρ0,ρ1,…\rho_0, \rho_1, \dots of 2<N2^{<\nat}, given by Proposition 3.11. If τ\tau is as in the hypothesis, so is every extension of τ\tau; in particular there is such a τ\tau with ∣τ∣>∣σ∣|\tau| > |\sigma|. Define σ0\sigma_0 as the empty string and σe+1\sigma_{e+1} as the first ρi\rho_i such that ρi⪰σe\rho_i \succeq \sigma_e, ∣ρi∣>∣σe∣|\rho_i| > |\sigma_e|, and every X≻ρiX \succ \rho_i satisfies ReR_e. The strings σ0⪯σ1⪯⋯\sigma_0 \preceq \sigma_1 \preceq \cdots have strictly increasing lengths, so there is a unique Y∈2NY \in \cs with σe≺Y\sigma_e \prec Y for every ee: its nn-th bit is the nn-th bit of any σe\sigma_e of length greater than nn. Since σe+1≺Y\sigma_{e+1} \prec Y, YY satisfies ReR_e.

Choosing σe+1\sigma_{e+1} as the first suitable string in a fixed enumeration avoids any use of the axiom of choice, and makes the construction explicit.

Example 6.10.#

Let (Xn)(X_n) be a sequence in 2N\cs, and Rn={Y:Y≠Xn}R_n = \{ Y : Y \neq X_n \}. Given σ\sigma, the string τ=σ i\tau = \sigma \, i with i=1−Xn(∣σ∣)i = 1 - X_n(|\sigma|) satisfies the hypothesis: every Y≻τY \succ \tau differs from XnX_n at position ∣σ∣|\sigma|. This is the diagonal argument, except that the position at which XnX_n is defeated is now chosen by the construction rather than fixed in advance.

Proposition 6.11.#

For every sequence (Xn)(X_n) in 2N\cs, there is Y∈2NY \in \cs that differs from every XnX_n at infinitely many positions. If (Xn)(X_n) is uniformly computable, YY can be taken computable.

For e=⟨n,k⟩e = \langle n, k \rangle, let ReR_e be the requirement ”Y(m)≠Xn(m)Y(m) \neq X_n(m) for some m≥km \geq k”. Given σ\sigma, extend it by zeros to a string σ′\sigma' of length at least kk, and let τ=σ′i\tau = \sigma' i with i=1−Xn(∣σ′∣)i = 1 - X_n(|\sigma'|); every Y≻τY \succ \tau differs from XnX_n at the position ∣σ′∣≥k|\sigma'| \geq k. By Lemma 6.9, some YY satisfies all R⟨n,k⟩R_{\langle n, k \rangle}, that is, differs from each XnX_n beyond every kk.

If (Xn)(X_n) is uniformly computable, use the explicit extension above instead of a search in an enumeration: σe+1\sigma_{e+1} is obtained from σe\sigma_e by padding with zeros to length max⁡(k,∣σe∣)\max(k, |\sigma_e|) and appending the bit 1−Xn(ℓ)1 - X_n(\ell), where ℓ=max⁡(k,∣σe∣)\ell = \max(k, |\sigma_e|); both steps are computable from σe\sigma_e and e=⟨n,k⟩e = \langle n, k \rangle. Then e↦σee \mapsto \sigma_e is computable, and so is YY, since Y(m)Y(m) is the mm-th bit of σm+1\sigma_{m+1}, which has length at least m+1m + 1.

The requirements of this proposition never interfere: once a requirement is satisfied, it remains satisfied whatever is done afterwards. Requirements of this kind can be handled one after the other, by finite extensions. The method was introduced by Kleene and Post to build Turing degrees with prescribed properties, and it is the elementary case of forcing. When requirements conflict, so that satisfying one may later injure another, one needs the priority method, which is the main technique of the theory of computably enumerable sets.

6.5 Exercises

Exercise 6.12 ★.

A function hh dominates a function ff if h(n)≥f(n)h(n) \geq f(n) for all sufficiently large nn. Show that no total computable function dominates every total computable function.

Solution

If hh is total computable and dominates every total computable function, it dominates h+1h + 1, which is total computable: h(n)≥h(n)+1h(n) \geq h(n) + 1 for large nn, a contradiction.

Exercise 6.13 ★.

Show that there is no uniformly computable sequence (Xn)(X_n) of sets containing every computable set.

Solution

If (Xn)(X_n) is uniformly computable, then Y(n)=1−Xn(n)Y(n) = 1 - X_n(n) is computable, as a composition of computable functions, and differs from every XnX_n. Alternatively, apply Theorem 6.4 to the characteristic functions, replacing fn(n)+1f_n(n) + 1 by 1−fn(n)1 - f_n(n).

Exercise 6.14 ★★.

Let A={e:Φe(e) ⁣ ⁣↓=0}A = \{ e : \Phi_e(e)\converge = 0 \} and B={e:Φe(e) ⁣ ⁣↓=1}B = \{ e : \Phi_e(e)\converge = 1 \}. Show that there is no computable set SS with A⊆SA \subseteq S and S∩B=∅S \cap B = \emptyset. (The sets AA and BB are computably inseparable.)

Solution

Let SS be computable, and let cc be a code of its characteristic function, so that Φc\Phi_c is total with values in {0,1}\{0, 1\}. If c∈Sc \in S, then Φc(c)=1\Phi_c(c) = 1, so c∈Bc \in B, and S∩B≠∅S \cap B \neq \emptyset. If c∉Sc \notin S, then Φc(c)=0\Phi_c(c) = 0, so c∈Ac \in A, and A⊈SA \not\subseteq S. This is a diagonal argument in which the program cc is defeated at its own index.

Exercise 6.15 ★★.

Using Proposition 4.4 of “Computably enumerable sets” of the course on fundamentals, where computably enumerable sets are defined, show that Tot\mathrm{Tot} is not even computably enumerable.

Solution

Tot\mathrm{Tot} is infinite. If it were computably enumerable, there would be an injective total computable ff with f(N)=Totf(\nat) = \mathrm{Tot}. Then fn(x)=Φ(f(n),x)f_n(x) = \Phi(f(n), x) defines a uniformly computable sequence of total functions containing every total computable function, contradicting Theorem 6.4. The proof of Corollary 6.5 is the special case where ff is the principal function.

Exercise 6.16 ★★★.

Show that there is a set YY such that neither YY nor its complement contains an infinite computable set.

Hint

For each infinite computable set CC, the requirement is: C⊈YC \not\subseteq Y and C⊈N∖YC \not\subseteq \nat \setminus Y. Satisfy it by a finite extension.

Solution

The infinite computable sets form a countably infinite set, by Proposition 6.1 and Corollary 3.4 (it contains the sets N∖n‾\nat \setminus \underline n); let C0,C1,…C_0, C_1, \dots be an enumeration of them. Requirement R2nR_{2n}: Y(m)=0Y(m) = 0 for some m∈Cnm \in C_n; requirement R2n+1R_{2n+1}: Y(m)=1Y(m) = 1 for some m∈Cnm \in C_n. Given σ\sigma, since CnC_n is infinite there is m∈Cnm \in C_n with m≥∣σ∣m \geq |\sigma|; extend σ\sigma by zeros to length mm, then append the required bit. Every YY extending the result satisfies the requirement. By Lemma 6.9, some YY satisfies all requirements: each infinite computable set meets both YY and its complement, so it is contained in neither. Such a set is called bi-immune.

6.6 Notes and references

The undecidability of the halting problem is due to Turing (1936), in the form that no machine decides whether a given machine is circle-free, that is, prints infinitely many digits. The finite extension method is due to Kleene and Post (1954), and the priority method to Friedberg and Muchnik (1956–1957). Rogers’ and Soare’s textbooks present diagonalization as the basic method of computability theory; Odifreddi gives a historical account of the many forms of the argument.

  • A. M. Turing, On computable numbers, with an application to the Entscheidungsproblem, Proceedings of the London Mathematical Society (2) 42 (1936), 230–265.
  • S. C. Kleene and E. L. Post, The upper semi-lattice of degrees of recursive unsolvability, Annals of Mathematics 59 (1954), 379–407.
  • H. Rogers, Theory of Recursive Functions and Effective Computability, McGraw-Hill, 1967.
  • P. Odifreddi, Classical Recursion Theory, North-Holland, 1989.
  • R. I. Soare, Turing Computability: Theory and Applications, Springer, 2016.