Home › Logic › Lesson 10

Computability — Turing Machines and the Halting Problem

Lesson 10 of 13

Key idea of this section

A Turing machine is a finite control acting on an unbounded tape; it formalises "algorithm".
The halting problem K = {e : φₑ(e) halts} is computably enumerable but not computable.
Church–Turing: validity of first-order sentences is undecidable.

Turing machines

A Turing machine M consists of a finite set Q of states with a start state q₀ and a halting state qh, a finite tape alphabet Γ containing a blank symbol ␣ and the input alphabet, and a transition function δ : (Q − {qh}) × Γ → Q × Γ × {L, R}. A configuration records the state, the tape contents (finitely many nonblank cells) and the head position; δ determines a unique successor configuration. M halts on input w if, started in q₀ with w on the tape and the head on its first symbol, it eventually enters qh. A partial function f : ℕ ⇀ ℕ is computable (Turing computable, partial recursive) if some machine, on input the binary representation of n, halts with f(n) on the tape when f(n) is defined and runs forever otherwise. A set is computable (decidable, recursive) if its characteristic function is computable, and computably enumerable (c.e., recursively enumerable) if it is the domain of a computable partial function, equivalently the range of a computable function or empty.

Turing introduced the machines in 1936 by analysing what a human computer does with pencil and paper. Independently, Church defined the λ-definable functions and Gödel and Kleene the general recursive functions; all three classes were shown to coincide. The Church–Turing thesis asserts that this class is exactly the class of functions computable by any effective procedure. It is not a theorem, since "effective" is informal, but it is universally accepted.

Universality and enumeration

Machines are finite objects and can be coded by natural numbers. Fix such a coding and let φₑ be the partial function computed by the machine with code e (φₑ undefined everywhere if e codes nothing). When the index is a compound expression we use Kleene's notation {e}(n) for φₑ(n).

Theorem 10.1 (Universal machine). There is a single machine U such that U(e, n) ≃ φₑ(n) for all e and n, meaning both sides are undefined or both are defined and equal.

U simply decodes e and simulates the coded machine step by step. This is the theoretical origin of the stored-program computer. A second fundamental fact is Kleene's s-m-n theorem: there is a computable total function s such that {s(e, m)}(n) ≃ φₑ(m, n), which lets one hard-wire parameters into programs.

The halting problem

Theorem 10.2 (Turing 1936). The set K = {e : φₑ(e) is defined} is c.e. but not computable. Hence the halting set H = {(e, n) : φₑ(n) is defined} is not computable.

Proof. K is c.e.: run U(e, e) and accept if it halts. Suppose K were computable. Then the function g(e) = 0 if e ∉ K, undefined if e ∈ K, would be computable: decide whether e ∈ K and, if so, enter an infinite loop. Let g = φd. Then d ∈ K iff φd(d) is defined iff g(d) is defined iff d ∉ K, a contradiction. ∎

The argument is Cantor's diagonal argument applied to the list φ₀, φ₁, φ₂, … of computable functions. A set A is computable iff both A and its complement are c.e. (Post): run the two enumerations in parallel. So the complement of K is not c.e.

Reductions and Rice's theorem

A many-one reduction from A to B is a total computable f with x ∈ A iff f(x) ∈ B. If A reduces to B and B is computable, so is A. Using the s-m-n theorem one reduces K to many natural problems.

Theorem 10.3 (Rice 1953). Let 𝒞 be a set of partial computable functions that is neither empty nor all of them. Then {e : φₑ ∈ 𝒞} is not computable.

Proof. We may assume the nowhere-defined function ∅ is not in 𝒞 (otherwise use the complement). Fix ψ ∈ 𝒞. By s-m-n there is a computable f with {f(e)}(n) ≃ ψ(n) if φₑ(e) halts and undefined otherwise (first run φₑ(e), then ψ(n)). Then e ∈ K iff the function computed by f(e) is ψ iff f(e) ∈ {e : φₑ ∈ 𝒞}. ∎

So no algorithm decides, for an arbitrary program, whether it computes a total function, whether it ever outputs 7, or whether it is equivalent to a given program. This is the theoretical reason why perfect static analysis of software is impossible.

Undecidability of first-order logic

Theorem 10.4 (Church 1936, Turing 1936). For a suitable finite language L, the set of valid L-sentences is not computable.

Proof idea. Given a machine M and input w, effectively write a sentence σ(M, w) that describes the computation of M: a binary relation symbol for the successor of time steps, predicate symbols Tapea(t, x) (at time t, cell x holds a), Stateq(t) and Head(t, x), and axioms stating that the initial configuration is correct and that each configuration follows from the previous one by δ. Let σ(M, w) be the conjunction of these axioms implies ∃t Stateh(t), with h the halting state. If M halts, the axioms force the actual finite computation to be embedded in every model and σ(M, w) is valid; if M does not halt, the standard model of the computation falsifies it. So halting reduces to validity. ∎

Thus Hilbert's Entscheidungsproblem has a negative answer. Validity is c.e. (by completeness) but not computable; satisfiability in the finite (Trakhtenbrot 1950) is c.e. but its complement is not, so validity in finite structures is not even c.e. — the completeness theorem fails for finite model theory. By contrast, many fragments are decidable: monadic first-order logic, Presburger arithmetic Th(ℕ, +), and the theory of real closed fields Th(ℝ, +, ·, <) (Tarski).

Other undecidable problems

The same method yields undecidability in ordinary mathematics: the word problem for finitely presented groups (Novikov, Boone, 1950s); Hilbert's tenth problem, whether a polynomial equation with integer coefficients has an integer solution (Matiyasevich 1970, building on Davis, Putnam and Robinson: every c.e. set is Diophantine); the tiling problem for Wang tiles (Berger 1966); and the mortality problem for 3 × 3 integer matrices (Paterson 1970).

Exercise

  • (a)
    Show that the set Tot = {e : φₑ is total} is not computable.
  • (b)
    Is the set {e : φₑ(0) halts within e² steps} computable?
  • (c)
    Show that if A and its complement are both c.e., then A is computable.
Show solution

Answers: (a) Totality is a nontrivial property of the function φₑ (some computable functions are total, some are not), so Rice's theorem applies. (In fact Tot is not even c.e.: it is Π₂-complete.) (b) Yes. Simulate φₑ(0) for e² steps with the universal machine and check; this always terminates. (c) Given x, run enumerations of A and of its complement alternately, one step each; x appears in exactly one of them after finitely many steps, and the algorithm answers accordingly.

V.3.1