42.04.02 · mathematical-logic / computability-degrees

The Halting Problem, Undecidability, and the Recursion Theorem

shipped3 tiersLean: none

Anchor (Master): Soare 2016 *Turing Computability: Theory and Applications* (Springer) Ch. 2-4 and the historical notes (the diagonal at $K$, $m$-completeness of $K$, Rice and Rice-Shapiro, the recursion theorem and its iterates, undecidable problems beyond halting); Rogers 1967 *Theory of Recursive Functions and Effective Computability* (McGraw-Hill) Ch. 7-11 (reducibilities, index sets, Rice's theorem, the recursion theorem and the second recursion theorem); Odifreddi 1989 *Classical Recursion Theory, Volume I* (North-Holland) Ch. II-III (the s-m-n / recursion-theorem package, Rice-Shapiro, productive and creative sets, the relation of $K$ to first-order undecidability)

Intuition Beginner

Some questions about computer programs sound like they should have a mechanical answer, yet none exists. The most famous one is the halting question: given a program and an input, will the program eventually stop, or will it loop forever? You might hope for a master checker — a program that reads any other program, looks at its input, and prints "stops" or "loops" without ever being wrong and without itself running forever. The surprising fact of this unit is that no such master checker can exist, and the reason is a single, very short argument.

The argument is a kind of self-reference trap. Suppose the master checker existed. Then you could build a mischief program that first asks the checker, "what will I do when I am run on my own code?" — and then deliberately does the opposite. If the checker says this program stops, the mischief program loops; if the checker says it loops, the mischief program stops. Run the mischief program on its own code and the checker is wrong no matter what it says. Since a correct checker cannot be wrong, the checker cannot exist.

That one trick — feed a thing its own description and flip the answer — is the seed of a whole landscape. Once you know the halting question has no mechanical answer, you can show that many other questions inherit the same fate by quietly smuggling the halting question inside them. A rough rule emerges: almost any interesting yes-or-no question about what a program computes (not how it is written) has no general decision procedure.

There is a hopeful twin to all this. The same self-reference that traps the checker can be used on purpose. You can always write a program that builds and prints its own source code, and more generally a program that is allowed to refer to itself while it runs. Self-reference, handled carefully, is not a paradox but a tool.

Visual Beginner

The diagonal trap, drawn as a table. Imagine listing every program down the side and every input across the top, and in each cell writing whether that program stops on that input. The mischief program is built to disagree with the diagonal of this table — the cells where a program is run on its own number — so it cannot appear anywhere in the list.

            input = program number
            P0    P1    P2    P3   ...
        +-----------------------------
   P0   | STOP  loop  STOP  loop      <- on the diagonal: STOP
   P1   | loop  loop  STOP  STOP      <- on the diagonal: loop
   P2   | STOP  STOP  loop  loop      <- on the diagonal: loop
   P3   | STOP  loop  loop  STOP      <- on the diagonal: STOP
   ...  |
        diagonal reads:  STOP loop loop STOP ...

   mischief program D, run on input n, does the OPPOSITE of cell (Pn, n):
        diagonal:        STOP  loop  loop  STOP ...
        D does instead:  loop  STOP  STOP  loop ...

   Could D be some row Pk in the table?
        At column k, D must differ from Pk's diagonal cell.
        So D's row disagrees with every row at its own column.
        D is not in the list. Contradiction.

Read it as a staring contest between D and the table. Whatever row you guess D is, look at that row's diagonal cell: D was defined to do the opposite there. So D matches no row. Yet if a halting checker existed, D would be a perfectly good program and would have a row. The table cannot hold D, so the checker cannot exist.

program run on its own number diagonal says D is built to do
P0 on 0 STOP loop
P1 on 1 loop STOP
P2 on 2 loop STOP
P3 on 3 STOP loop

The flip down the diagonal is the whole proof: D is everywhere different from the list, so it is not on the list.

Worked example Beginner

We pin down the contradiction with one concrete program, using only addition and "ask the checker." Pretend a perfect halting checker exists: given a program and an input , returns if stops on and if loops on , always correctly and always quickly.

Step 1. Build a new program . On input (a program number), runs on the pair "program number , input " — that is, it asks whether program stops when fed its own number.

Step 2. Make contrary. If answers (program stops on ), then enters a loop and never stops. If answers (program loops on ), then stops immediately.

Step 3. Give its own number. Say is program number . Run on input . Inside, asks whether program stops on — but program is , so this asks whether stops on , the very thing we are running.

Step 4. Watch both answers fail. If says stops on , then by Step 2 loops on — so was wrong. If says loops on , then by Step 2 stops on — so was wrong again. Either way the perfect checker is wrong on this one input.

What this tells us: a checker that is right on every program-and-input pair contradicts itself the moment you feed it on . There is no escape value for to return. So a perfect, always-halting halting checker is impossible — the halting question has no general mechanical answer.

Check your understanding Beginner

Formal definition Intermediate+

Fix the standard enumeration of unary partial computable functions, the universal function , and the s-m-n functions from 42.04.01. Write when the computation halts (the value is defined) and when it diverges; denotes Kleene equality (both sides defined and equal, or both undefined). The halting set (the diagonal halting set) is $$ K = {, e : \varphi_e(e)!\downarrow ,}, $$ and the general halting set is , using a computable pairing . A set is computable if its characteristic function is computable, and computably enumerable (c.e.) if it is the domain of a partial computable function [Soare Ch. 2].

For sets , is many-one reducible to , written , if there is a total computable with $$ x \in A \iff f(x) \in B \qquad \text{for all } x. $$ The relation is reflexive and transitive; means . A c.e. set is -complete if for every c.e. . Many-one reducibility transports decidability downward: if and is computable then is computable, and if and is c.e. then is c.e. The contrapositive is the working tool — to show undecidable, reduce a known-undecidable set (typically ) to it.

An index set is a set that respects the functions computed, not the programs: . Equivalently is the set of indices of the c.e. sets (or partial functions) lying in some class of c.e. sets, where . The two index sets and correspond to the empty class and the class of all c.e. sets; every other index set encodes a property held by some but not all c.e. sets. A fixed point of a total computable is an index with .

Counterexamples to common slips Intermediate+

  • " is uncomputable because it is infinite or complicated." Size and apparent complexity are irrelevant: is c.e., so it is the range of a computable function and can be listed. What fails is deciding non-membership — its complement is not even c.e. Uncomputability is the asymmetry between and , not bulk.

  • " means is a subset of ." It means a computable pulls membership in back from membership in ; need not be injective, monotone, or onto, and may be disjoint. The reduction is a translation of questions, not an inclusion of sets.

  • "Rice's theorem says every property of programs is undecidable." It governs extensional properties — properties of the computed function, i.e. index sets. Properties of the syntax ("does the program have more than ten states?", "does it ever print symbol in its first step?") can be perfectly decidable. The hypothesis " is an index set" is doing real work.

  • "The recursion theorem gives a fixed value, a number with ." It gives a fixed point up to the computed function: , an equality of programs' behaviour, not . The transformation may move every index; the theorem only guarantees one index whose program is unchanged in meaning.

Key theorem with proof Intermediate+

The signature result is that is the simplest possible undecidable set: c.e., and maximally so under . Everything downstream — Rice's theorem, the undecidability of totality and emptiness, Church's theorem — is a reduction from .

Theorem (the halting set is c.e. and -complete). The set is computably enumerable but not computable. Moreover is -complete: for every c.e. set , .

Proof. is c.e. because for the partial computable : running the universal machine on halts exactly when .

is not computable. Suppose were computable. Define $$ g(e) \simeq \begin{cases} \varphi_e(e) + 1 & \text{if } e \in K, \ 0 & \text{if } e \notin K. \end{cases} $$ Since is computable and supplies on , is total computable, so for some index . Evaluate at . If then , impossible. If then , yet is defined and forces , a contradiction. Hence is not computable.

For -completeness, let be c.e., say . Consider the partial computable function of two arguments — it ignores and runs on . Let be an index with . By the s-m-n theorem there is a total computable with for all . Thus is the everywhere-defined-constant or everywhere-undefined function according as or . In particular , so . Hence .

Bridge. This theorem is the foundational reason undecidability is not a scattered collection of accidents but a single phenomenon: sits at the top of the c.e. sets under , so any problem to which reduces is undecidable, and any c.e. problem reduces to . The diagonal that defeats is exactly the self-application the universal machine of 42.04.01 makes available — this is exactly the construction the recursion theorem will run forwards instead of for contradiction. The reduction technique builds toward Rice's theorem, where is reduced into an arbitrary extensional property, and it appears again in the undecidability of first-order validity, where is reduced into provability (Church's theorem, cross-ref 42.01.10 pending). The central insight is that -completeness packages "as hard as the halting problem" into a transitive relation, so putting these together one reduction from certifies an entire family of undecidable questions at once.

Exercises Intermediate+

Advanced results Master

The recursion theorem is the positive form of the diagonal: the same self-application that makes undecidable, run constructively, gives every effective transformation a fixed point. The theorems below develop the fixed-point machinery, sharpen Rice's theorem to the c.e. case, and map the undecidable problems that lie strictly above in logical complexity.

Theorem 1 (Kleene recursion / fixed-point theorem). For every total computable there is an index with [Rogers Ch. 11]. The proof is a single diagonal use of s-m-n: from the partial computable take an index and set , whereupon . The fixed point is obtained uniformly in an index for , and the construction is the mirror image of the halting diagonal — there the self-application produced a contradiction, here it produces an invariant index.

Theorem 2 (second recursion theorem; programs that read their own code). For every partial computable there is an index with for all [Rogers Ch. 11]. Thus any program may be written as though it has access to its own index : define the desired behaviour as treating as a known constant, and the theorem supplies a genuine realising it. This legitimises definition by effective self-reference — recursive definitions that quote the program being defined, self-modifying schemes, and the formal construction of quines — and re-proves Rice's theorem in one line: if an index set were decidable, the program "compute if , else diverge," self-referential in , would land on the wrong side of , contradicting the index-set invariance.

Theorem 3 (Rice-Shapiro). Let be a class of c.e. sets (partial functions) and its index set. If is c.e., then for every c.e. set : iff some finite subset has [Odifreddi Ch. III]. Membership in a c.e. index set is therefore determined by finite approximations: a c.e. property of the computed set cannot depend on the whole infinite behaviour, only on finitely much of it. The totality class violates this (no finite set is total), reproving that is not c.e.; the non-emptiness class violates it in the other direction, confirming is c.e. while is not.

Theorem 4 (undecidable problems beyond halting). Several natural index sets sit strictly above in the arithmetical hierarchy 42.04.05. The totality problem is -complete; the emptiness problem is -complete (so is -equivalent to ); the finiteness problem is -complete [Soare Ch. 4]. Outside the index sets lie undecidable problems of different texture: the Post correspondence problem (PCP) — given finite lists of word pairs, is there a matching concatenation? — is undecidable by reduction from via Turing-machine computation histories; the busy beaver function — the maximum number of s a halting -state machine prints — is total but not computable, growing faster than any computable function, since computing it would decide halting for -state machines; and the word problem for finitely presented groups and Hilbert's tenth problem (Diophantine solvability) are undecidable, the latter because every c.e. set is Diophantine (cross-ref co-produced 42.04.07).

Theorem 5 (the bridge to logic: Church's theorem and the undecidability of arithmetic). Because computation is arithmetisable, and , so the theory of the standard model and the provability set of Peano arithmetic are undecidable [Odifreddi Ch. III]. Likewise reduces to first-order validity: from a machine and input one builds a sentence valid iff the machine halts, so the set of valid first-order sentences is undecidable — Church's theorem on the Entscheidungsproblem, cross-ref 42.01.10 pending. The recursion theorem reappears inside logic as the diagonal lemma behind Gödel's first incompleteness theorem 42.01.09 pending: the construction of a sentence asserting its own unprovability is the syntactic twin of the self-referential index of Theorem 2.

Synthesis. The single diagonal at is the foundational reason the undecidability landscape is connected rather than a list of separate impossibilities: -completeness makes a universal source, so every undecidability proof in the chapter is a reduction , and this is exactly Rice's theorem read as "reduce into any extensional class other than the empty and full ones." The recursion theorem is dual to this diagonal — the self-application that defeats the halting checker, run forwards, gives every effective transformation a fixed point, and the second recursion theorem generalises that into programs with access to their own code. Putting these together, Rice-Shapiro stratifies the undecidable index sets by whether the property is captured by finite approximations, which is precisely what lifts , , and off the c.e. floor into , , and of the arithmetical hierarchy 42.04.05. The bridge from this purely computational diagonal to logic is the arithmetisation that sends into provability and validity: the central insight is that Gödel's self-referential sentence and Kleene's self-referential program are one construction in two languages, so the incompleteness of arithmetic 42.01.09 pending and the unsolvability of the Entscheidungsproblem 42.01.10 pending are the logical shadow of the halting problem proved here.

Full proof set Master

Proposition 1 ( is c.e. but not computable). is computably enumerable and not computable.

Proof. for , partial computable, so is c.e. If were computable, then for and for is total computable; let . If then , impossible; if then while is defined, contradicting . So is not computable.

Proposition 2 ( is -complete). For every c.e. , .

Proof. Write . Let , with index , and by s-m-n, so for all . Then , whence . As is total computable, .

Proposition 3 (recursion theorem). Every total computable has with .

Proof. The function is partial computable, since and are total computable and supplies the outer evaluation. Take with and set . For all , $$ \varphi_n(y) = \varphi_{s^1_1(w,w)}(y) \simeq \varphi^{(2)}w(w, y) = \psi(w, y) \simeq \varphi{f(s^1_1(w,w))}(y) = \varphi_{f(n)}(y), $$ using s-m-n at the first step and the definition of at the last. Hence .

Proposition 4 (second recursion theorem). For every partial computable there is with for all .

Proof. By s-m-n there is a total computable with for all (freeze as a parameter in ). Apply Proposition 3 to : there is with . Then for all .

Proposition 5 (Rice's theorem). If is an index set with , then is undecidable.

Proof. Let compute the everywhere-undefined function . Without loss of generality (otherwise apply the argument to the index set , whose undecidability is equivalent). Since , fix . Define if , and otherwise — operationally, run first, then simulate . This is partial computable; let be an index for it and . Then when and when . As is an index set, (using and ). Thus ; were computable, would be, contradicting Proposition 1.

Proposition 6 (Rice-Shapiro, the finite-approximation direction). Let be c.e. If a c.e. set , then some finite has .

Proof. Suppose but no finite subset of lies in . Build, using the recursion theorem, an index for a c.e. set defined by dovetailing: enumerate , but at each stage also simulate (legitimate since the second recursion theorem hands the construction its own index ); enumerate elements of into only until the moment, if ever, that is witnessed by the c.e. enumeration of , then freeze at its current finite value. If is never enumerated into , then , so — contradiction, so is enumerated, at which point is a finite subset with , i.e. , contradicting the assumption that no finite subset of is in . Hence some finite lies in .

Proposition 7 (the busy beaver function is not computable). Let be the largest number of s printed by a halting Turing machine with states (on blank input, fixed alphabet). Then is total but not computable.

Proof. is total because for each there are finitely many -state machines and the maximum over the halting ones is a well-defined natural number. Suppose were computable. Then so is any total , e.g. . Given a machine with states started on blank tape, run it for a bounded number of steps determined by together with the finite number of distinct configurations expressible with tape cells: if has not halted within that bound it has entered a configuration loop and never halts. This decides whether -state machines halt on blank tape, and a padding argument reduces the general blank-tape halting problem (hence after the standard encoding) to it, contradicting Proposition 1. So is not computable, and in fact dominates every computable function eventually.

Connections Master

  • Models of computation 42.04.01 supplies everything this unit diagonalises against: the enumeration , the universal function that makes a legitimate partial computable object, and the s-m-n theorem that every reduction and the recursion theorem invoke. That unit owns the fixed model and its acceptable-numbering structure; this unit owns the undecidability and fixed-point consequences read off that model — Proposition 4 of 42.04.01 previews the present result, which is developed here in full with -completeness.

  • Computably enumerable sets and the priority method 42.04.03 continue the reducibility theory begun here: is refined to Turing reducibility , becomes the canonical object, and the existence of c.e. sets strictly between computable and -complete (Post's problem, solved by Friedberg-Muchnik) is the next structural question. The co-produced unit 42.04.03 builds the c.e. degree structure on top of the -and-reductions apparatus established here; this unit owns the halting set and the many-one theory it sits atop.

  • The arithmetical hierarchy 42.04.05 classifies the undecidable problems of Theorem 4 by quantifier complexity: is -complete, is -complete, is -complete, and Rice-Shapiro is the tool that lifts a property off the floor by showing it is not finitely approximable. That unit relativises to oracles to build the jump hierarchy; this unit provides the un-relativised base case and the index sets that populate the first levels.

  • Gödel incompleteness 42.01.09 pending and Church's theorem 42.01.10 pending are the logical projection of the halting diagonal: arithmetisation gives and , so undecidability of provability and of validity follow from Proposition 1, and the recursion theorem's self-referential index (Proposition 4) is the computational form of the diagonal lemma that builds the Gödel sentence. The word problem and Hilbert's tenth problem reductions are co-produced in 42.04.07, where the MRDP theorem makes every c.e. set Diophantine.

Historical & philosophical context Master

The halting problem and the recursion theorem are twin consequences of the 1936 analysis of computation. Alan Turing's 1936 paper proved the unsolvability of the Entscheidungsproblem by exhibiting an undecidable problem about his machines — essentially the printing/halting problem — through a diagonal argument modelled on Cantor's proof that the reals are uncountable and on the self-reference in Gödel's 1931 incompleteness theorem [Soare Ch. 2]. Alonzo Church had reached the undecidability of first-order validity the same year by the -calculus route, and the reduction of an undecidable arithmetical problem to validity is now called Church's theorem. Emil Post, in unpublished work of the 1920s–30s and in his 1944 paper on c.e. sets, introduced reducibility and the structure of degrees, posing the problem — whether there is a c.e. set neither computable nor -complete — that organised the next two decades of the subject.

Stephen Kleene proved the recursion theorem and isolated the s-m-n theorem in the 1930s and systematised them in Introduction to Metamathematics (1952); the fixed-point theorem and its second form gave self-reference a rigorous, paradox-free standing, turning the device that defeats the halting checker into a construction principle. Henry Gordon Rice's 1953 paper established that every extensional property of the c.e. sets — every property of what a program computes rather than how it is written — is undecidable, drawing the boundary the chapter's index-set theory formalises [Rogers Ch. 9]. John Myhill identified the -complete c.e. sets with the creative sets and showed them all recursively isomorphic to , fixing the halting set as the canonical representative of its degree.

Bibliography Master

@article{turing1936computable,
  author  = {Turing, Alan M.},
  title   = {On computable numbers, with an application to the {Entscheidungsproblem}},
  journal = {Proceedings of the London Mathematical Society},
  volume  = {s2-42},
  number  = {1},
  year    = {1937},
  pages   = {230--265}
}

@article{church1936entscheidung,
  author  = {Church, Alonzo},
  title   = {A note on the {Entscheidungsproblem}},
  journal = {The Journal of Symbolic Logic},
  volume  = {1},
  number  = {1},
  year    = {1936},
  pages   = {40--41}
}

@article{rice1953classes,
  author  = {Rice, Henry Gordon},
  title   = {Classes of recursively enumerable sets and their decision problems},
  journal = {Transactions of the American Mathematical Society},
  volume  = {74},
  number  = {2},
  year    = {1953},
  pages   = {358--366}
}

@article{post1944recursively,
  author  = {Post, Emil L.},
  title   = {Recursively enumerable sets of positive integers and their decision problems},
  journal = {Bulletin of the American Mathematical Society},
  volume  = {50},
  number  = {5},
  year    = {1944},
  pages   = {284--316}
}

@article{post1946correspondence,
  author  = {Post, Emil L.},
  title   = {A variant of a recursively unsolvable problem},
  journal = {Bulletin of the American Mathematical Society},
  volume  = {52},
  number  = {4},
  year    = {1946},
  pages   = {264--268}
}

@article{myhill1955creative,
  author  = {Myhill, John},
  title   = {Creative sets},
  journal = {Zeitschrift f\"{u}r mathematische Logik und Grundlagen der Mathematik},
  volume  = {1},
  number  = {2},
  year    = {1955},
  pages   = {97--108}
}

@book{kleene1952metamathematics,
  author    = {Kleene, Stephen C.},
  title     = {Introduction to Metamathematics},
  publisher = {North-Holland},
  year      = {1952}
}

@book{soare2016turing,
  author    = {Soare, Robert I.},
  title     = {Turing Computability: Theory and Applications},
  series    = {Theory and Applications of Computability},
  publisher = {Springer},
  year      = {2016}
}

@book{rogers1967theory,
  author    = {Rogers, Hartley},
  title     = {Theory of Recursive Functions and Effective Computability},
  publisher = {McGraw-Hill},
  year      = {1967}
}

@book{odifreddi1989classical,
  author    = {Odifreddi, Piergiorgio},
  title     = {Classical Recursion Theory, Volume I},
  series    = {Studies in Logic and the Foundations of Mathematics},
  volume    = {125},
  publisher = {North-Holland},
  year      = {1989}
}