Contents / Mathematical Logic / Computability Theory
Chapter 6
Computability Theory
Turing machines, recursive functions, decidable and r.e. sets, the halting problem, reductions, Rice's theorem, the arithmetical hierarchy and Turing degrees.
Introduction
Computability theory asks which functions and which questions can be settled by a purely mechanical procedure. The answer turns out to be sharp: there is a single robust class of computable functions, reached independently by half a dozen unrelated formalisms, and there are concrete, entirely natural questions — does this program stop? — that provably lie outside it.
The chapter builds the machinery in the order the proofs need it. Turing machines and the recursive functions give two definitions of algorithm; the universal machine and the - - theorem give the two tools that let programs manipulate programs; diagonalisation then produces the first undecidable set, reductions propagate undecidability outwards from it, Rice's theorem shows how far it spreads, and the arithmetical hierarchy and the Turing jump measure what is left.
One warning about scope. Computability measures whether a function can be computed at all, never how cheaply. Complexity classes such as and live one level down and are not treated here. The dual question — how much information a single finite string contains, measured by the length of the shortest program that prints it — is Kolmogorov complexity, and it is developed in the information-theory chapter Algorithmic Information; we use its vocabulary only in passing.
6.1Turing Machines, Configurations and Computation
A definition of "mechanical procedure" has to be poor in features, or the definition smuggles in the very power it is supposed to explain. Turing's device is deliberately impoverished: a finite control, a tape that is unbounded but written one cell at a time, and a head that moves one step per instruction. Everything else — arithmetic, recursion, self-reference — is reconstructed from those pieces.
Definition 6.1 (Turing machine). A Turing machine is a -tuple
where is a finite set of states; is the finite input alphabet; is the finite tape alphabet, containing a blank symbol ; is the start state; are the two halting states; and
is the transition function. The tape is infinite to the right, initially holds the input followed by blanks, and the head starts on the leftmost cell.
The transition function is total on non-halting states, so a computation never gets stuck for want of an instruction: it either reaches or , or it runs forever. That is the only way a Turing machine can fail, and it is exactly the failure the rest of the chapter is about.
Definition 6.2 (Configuration). A configuration of is a string with and : the tape holds followed by blanks, the machine is in state , and the head scans the first symbol of (a blank if is empty).
Configuration yields , written , when one application of turns the first into the second. Writing : if then , and if then . The start configuration on input is .
A computation is now just a chain of configurations. This is the level at which almost every later proof operates: nobody writes transition tables after this section, but the fact that a computation is a finite string of finite configurations is what makes computations checkable, encodable and countable.
Definition 6.4 (Computation, acceptance, computed function). The computation of on is the (finite or infinite) sequence with . It halts if some contains or , and then is the running time.
accepts if it halts in ; is the set of accepted strings. decides if it halts on every input. The partial function computed by , written , sends to the tape contents at halting if halts on , and is undefined otherwise; we write for "defined" (the machine halts) and for "undefined".
Definition 6.5 (Computable and partial computable). A partial function on is partial computable (partial recursive) if for some Turing machine . It is computable (total recursive) if in addition it is total, i.e. the machine halts on every input.
Pitfall. Halting and accepting are different events, and recognising and deciding are different achievements. A machine that accepts exactly the members of but runs forever on some non-members recognises without deciding it. Almost every undecidability result in this chapter is the statement that some set is recognised but not decided.
Example 6.6 (A machine, traced by configurations). Specify a Turing machine computing the successor on unary notation — the number is the block — and trace its computation on as a chain of configurations.
Solution. Take , states , and
The machine walks right over the block and converts the first blank into a . On input :
Three steps, and the tape reads . On input the machine takes exactly steps, so it halts on every input and the successor is total computable. Note that the table has two lines no matter how large is: a finite program, uniform in the input, is the whole point of the model. □□
Nothing in these traces depends on having one tape, or on the tape being one-dimensional, or on the machine being deterministic. That robustness is what entitles us to stop drawing tables.
Theorem 6.7 (Robustness of the model). Each of the following computes exactly the partial computable functions: single-tape machines; -tape machines for any fixed ; machines with a two-way infinite tape; machines with a two-dimensional tape; nondeterministic machines; and register machines. In particular a function is computable by some multi-tape machine if and only if it is computable by some single-tape machine.
Proof. We give the simulation for tapes in full and sketch the rest. Given a -tape machine , build a single-tape over the enlarged alphabet , where is a dotted copy of marking a head position. keeps the tapes on one tape as , with exactly one dotted symbol per block. To simulate one step of , sweeps the whole tape once to read the scanned symbols — it can remember them in its finite control, since is a fixed constant and the alphabet is finite — consults 's table, and sweeps back writing the new symbols and moving the dots one cell each; when a dot would run off the right end of a block, first shifts everything to the right of that block one cell rightwards to make room. Each simulated step is therefore faithful, so by induction on the tape of after simulating steps encodes the configuration of after steps. Hence halts exactly when does and with the same output, so ; the converse inclusion is trivial, a -tape machine being a -tape machine that ignores tapes.
For the remaining models the same "encode the state of the other device on one tape and simulate a step at a time" argument applies: a two-way infinite tape is folded into two interleaved tracks of a one-way tape, a two-dimensional tape is stored as a list of written cells with their coordinates, a register machine's registers are stored as separated blocks, and a nondeterministic machine is simulated by breadth-first search over its computation tree, one depth at a time — depth-first would be unfaithful, since it can fall into an infinite branch while an accepting branch exists elsewhere. What these arguments do not claim is that the simulations are cheap: the -tape simulation above costs steps for simulated steps, and the nondeterministic one costs exponentially. Cost is a complexity question and is irrelevant to the class of computable functions.∎
Encoding is the other thing this section owes the rest of the chapter. A machine is a finite object, so it can be written down as a string, and strings can be numbered.
Definition 6.8 (Encoding and the standard listing). Fix an effective encoding of Turing machines as numbers, and an effective pairing bijection , for example the Cantor pairing
Every number is taken to be the code of some machine (decode garbage as a fixed trivial machine). Write for the machine coded by and
for the partial computable function it computes. The sequence is the standard listing of the partial computable functions; is an index for . Every partial computable function has infinitely many indices, since padding a machine with unreachable states changes the code but not the function.
That listing immediately settles how much of mathematics is computable: almost none of it.
Theorem 6.9 (Most functions are not computable). There are only countably many partial computable functions, but uncountably many functions . Hence uncountably many functions are not computable, and likewise only countably many subsets of are decidable.
Proof. Each Turing machine is a finite tuple over finite sets, so it has a finite description over a fixed finite alphabet; there are countably many finite strings over a finite alphabet, and maps onto the partial computable functions, which are therefore countably many. The functions are in bijection with , which by Cantor's theorem has cardinality . A countable set cannot contain an uncountable one, so the non-computable functions are uncountable — indeed all but countably many functions are uncomputable.∎
Intuition. Programs are finite texts, and there are only countably many finite texts. Functions on are infinite objects with no such constraint, and there are continuum-many. The mismatch is so violent that a "random" function is uncomputable with probability one. What the rest of the chapter adds is that undecidability is not confined to those exotic objects: the halting set is as concrete and as natural as a set can be.
Pitfall. The counting argument proves that uncomputable functions exist; it exhibits none, and it cannot, because it never mentions a specific function. Producing a named undecidable set takes diagonalisation, which is the work of the section The Halting Problem.
6.2Recursive Functions and the Church-Turing Thesis
The second definition of algorithm never mentions a machine. It builds functions algebraically from a handful of obviously-computable seeds using rules that obviously preserve computability, and the surprise is that this reaches exactly as far as the tape does.
Definition 6.10 (Primitive recursive functions). The primitive recursive functions form the smallest class of total functions containing the base functions
- the zero function ,
- the successor ,
- the projections for ,
and closed under
- composition: ;
- primitive recursion: from of arity and of arity , the function of arity given by
The recursion parameter counts down to a base case reached after exactly unfoldings, so the schema is a bounded loop: the trip count is known before the loop starts. That is the structural reason for the following, and it is also the class's limitation.
Theorem 6.11 (Primitive recursive implies total). Every primitive recursive function is total.
Proof. Induct on the derivation of the function. The three base functions are total. If are total then so is the composition , since every inner value is defined and is defined everywhere. Suppose and are total and arises from them by primitive recursion. Fix and induct on : is defined, and if is defined then is defined because is total. So is defined at every .∎
Example 6.12 (Building the arithmetic you need). Show that addition, multiplication, the predecessor, truncated subtraction and the sign function are primitive recursive, and record the derived tools they give.
Solution. Addition fits the schema with and :
Unfolding checks it: , bottoming out after exactly unfoldings.
Multiplication uses as its step, and ; exponentiation uses the same way. The predecessor is a recursion that discards its recursive value, and , and truncated subtraction iterates it: and . The sign function is , which is at and elsewhere.
With and in hand, predicates become primitive recursive too, identifying a predicate with its characteristic function: the characteristic function of is , and are computed by , by and by . Bounded sums and products and are primitive recursions, and so is bounded search
since it can be written as a bounded sum of products of values. Everything up to and including "is prime?", "what is the -th prime?" and the decoding of sequence codes is therefore primitive recursive. □□
Totality is a ceiling as well as a guarantee. A class of total functions cannot contain a function universal for itself, and it cannot contain the fastest-growing total functions.
Theorem 6.13 (Ackermann's function). Define by
Then is total and computable, but is not primitive recursive.
Proof. Sketch, complete except for the majorisation lemma named below. Totality follows by induction on ordered lexicographically: every right-hand side calls at a lexicographically smaller pair, and the lexicographic order on is a well-order, so the recursion terminates. It is computable because the recursion is a finite, effective rewriting procedure that the Church-Turing thesis (or an explicit stack machine) turns into a program.
Non-primitive-recursiveness rests on a majorisation lemma, proved by induction on the build of : for every primitive recursive of arity there is an with
The inductive step needs the monotonicity facts and , each itself an induction, and composition and primitive recursion each raise the required by a bounded amount. Granting the lemma, suppose were primitive recursive. Then so would be the diagonal , so for some fixed and all ; taking gives , a contradiction. The step left unproved here is the majorisation lemma, a long but routine double induction.∎
Intuition. Ackermann's function diagonalises out of the primitive recursive class in the same way the halting argument will diagonalise out of the computable one, and the reason is the same: a class closed under a uniform construction cannot contain the function that runs down its own list doing something different. Concretely, is essentially , is essentially , is essentially , and a tower of exponentials — each row outgrows every function definable with one fewer level of loop nesting.
To reach the partial functions — and every function a real programming language can define, since a real program can loop — one more rule is needed, and exactly one.
Definition 6.14 (Partial recursive functions). The -operator (unbounded search) applied to a partial function of arity yields
undefined if no such exists. The partial recursive functions are the smallest class containing the base functions and closed under composition, primitive recursion and . A partial recursive function that happens to be total is called total recursive.
Pitfall. is the only source of divergence, and it diverges in two distinct ways: either no witness exists at all, or some earlier value is itself undefined and the search hangs before reaching a witness. The clause " for all " is not pedantry — without it the operator would be uncomputable, since it would demand the least witness while forbidding the machine to test the values below it.
Theorem 6.15 (Kleene normal form, and equivalence with Turing computability). There is a primitive recursive predicate — " codes a halting computation of on input " — and a primitive recursive function ("read the output off a computation") such that for every partial computable there is an index with
for all , where means the two sides are defined for exactly the same and are equal there. Consequently a partial function is partial recursive if and only if it is Turing computable, and a single application of to a primitive recursive predicate always suffices.
Proof. Sketch, resting on the arithmetisation of syntax named at the end. Both directions are simulations. Recursive Turing computable: each base function has a two-line machine, composition is sequencing, primitive recursion is a counted loop, and is an unbounded loop — every rule has a direct machine implementation, so induction on the build gives a machine for every partial recursive function.
Turing computable recursive: encode a configuration as a number by coding the finite strings and symbol by symbol, and code a length- computation history as a single number by the prime-power sequence coding . Then "is the successor configuration of under the table coded by ? " is a bounded arithmetic question about the exponents of , hence primitive recursive by the tools built above; conjoining it over with bounded quantifiers, and adding " is the start configuration on " and "the last configuration is halting", gives the primitive recursive predicate . Searching for a halting history is the single , and extracts the output from the last configuration.
What the sketch compresses is the arithmetisation itself: the verification that sequence coding, decoding and length are primitive recursive. That is the content of Gödel's -function lemma, proved in the chapter Incompleteness and Independence, and everything here rests on it.∎
Remark (The Church-Turing thesis). Thesis. A function is effectively calculable — computable by some finite, deterministic, mechanical procedure in the informal sense — precisely when it is partial recursive, equivalently Turing computable.
This is a thesis, not a theorem, and it cannot be one: "effectively calculable" is an informal notion, so there is nothing to prove it against. What supports it is evidence. Turing machines, the -calculus, Gödel-Herbrand general recursion, Post systems, register machines, Markov algorithms and every programming language ever implemented define the same class, despite having been designed with different intentions. Turing's own argument is the most direct: he analysed what a human computer with paper, finitely many distinguishable states of mind and a bounded field of view can do in one step, and showed that each such step is a Turing-machine step.
The thesis is refutable in principle. Exhibiting a physically realisable procedure that computes a function provably outside the class would kill it. None has been produced; quantum computers, analogue machines and randomised algorithms all compute exactly the same class of functions, differing only in cost.
Pitfall. Do not cite the Church-Turing thesis inside a proof as though it were a theorem, and do not confuse it with the false claim that "everything is computable". The thesis says the two classes coincide; Theorem Most functions are not computable showed the class is countable, so it misses almost every function.
Intuition. In practice the thesis is a licence to stop writing transition tables. Once you accept it, "there is an algorithm that does " is enough to conclude "there is a Turing machine computing ", and every later construction in this chapter — build a machine that simulates another on a modified input, search for a halting computation, dovetail infinitely many simulations at once — is described in that informal register and is none the worse for it.
6.3Decidable and Recursively Enumerable Sets
Undecidability is a property of sets, so the vocabulary has to be fixed before anything can be proved undecidable. Two notions matter, and the gap between them is where the whole subject lives.
Definition 6.16 (Decidable and recursively enumerable). A set is decidable (recursive, computable) if its characteristic function
is computable — some machine halts on every input and answers correctly.
is recursively enumerable (r.e., computably enumerable, semi-decidable) if is the domain of a partial computable function: for some ,
Equivalently, some machine halts exactly on the members of and runs forever on the rest.
Notation. denotes the -th r.e. set, the domain of ; the sequence enumerates all r.e. sets, just as enumerates all partial computable functions. We write for the complement.
Intuition. A decider is a machine with a deadline: it must answer, yes or no, in finite time. A semi-decider has only half a deadline — it must eventually say yes when the answer is yes, and is free to stay silent forever when the answer is no. "Silent forever" is not an answer you can ever observe, which is precisely why semi-decidability is strictly weaker.
Two constructions make semi-decidability workable in practice, and both recur constantly below. The first is the stage, or step-counting, view: if and only if halts within steps for some , and "does halt within steps?" is decidable — simulate for steps and look. The second is dovetailing: to run infinitely many computations at once, run computation for one step, then computations and for one more step each, then , and so on. Every individual computation receives unboundedly many steps, so any one that halts is eventually seen to halt.
Theorem 6.17 (Complementation characterises decidability). A set is decidable if and only if both and are recursively enumerable.
Proof. () Suppose is decidable, with total machine computing . A machine that runs and then halts if the answer is , and enters a deliberate infinite loop if the answer is , has domain exactly ; so is r.e. Swapping the two branches gives a machine with domain , so is r.e.
() Suppose and . Build a machine which, on input , runs the two computations and in parallel — formally, for it simulates each for steps and tests the decidable predicates " halts within steps" and " halts within steps". It stops at the first at which one of them holds, outputting if it was the -computation and if it was the -computation.
halts on every input: lies in exactly one of and , so exactly one of , converges, and it converges after some finite number of steps ; the loop therefore terminates by stage . Because exactly one of the two ever converges, no input can trigger both tests, and the output is unambiguous. And is correct: it outputs only when , that is , and only when , that is . So is computable and is decidable.∎
The theorem is the workhorse of the chapter in its contrapositive form: if is r.e. and not decidable, then is not even r.e. A single undecidability proof therefore yields two sets' worth of information, and it is how we will know, in the next section, that " does not halt on " is not merely undecidable but not semi-decidable either.
Theorem 6.18 (Enumeration characterises r.e.). A non-empty set is r.e. if and only if is the range of a total computable function. Moreover an infinite set is decidable if and only if it is the range of a strictly increasing total computable function.
Proof. If with total computable, then the machine that on input computes and halts at the first with has domain exactly , so is r.e.
Conversely let be non-empty and fix . Using the decidable stage predicate and the pairing bijection, define
This is total and computable, since the test is decidable and every number is a pair. Its range is contained in , because it outputs only and values on which halts; and it contains , because any halts at some stage , whence .
For the last claim let be infinite. If with strictly increasing, then to test compute until the values exceed , which happens by index since , and check whether appeared; this always halts, so is decidable. Conversely if is infinite and decidable, run the decider on and let be the -th member found. The search always succeeds because is infinite, so is total; it is computable; and it is strictly increasing by construction.∎
Pitfall. "Recursively enumerable" means listable in some order, not in increasing order. The last clause above is exactly that difference: an increasing enumeration lets you stop searching and conclude , and that extra power is precisely decidability. Many mistaken arguments that the halting set is decidable amount to forgetting this.
Programs must now become data that other programs can read and write. Two theorems make that legal, and every construction from here to the end of the chapter uses one or both.
Theorem 6.19 (Universal machine, or the enumeration theorem). There is a partial computable function of two arguments, computed by a single machine , with
Consequently the set is r.e.
Proof. Sketch, honest about the one routine but tedious step. On input , decodes into a transition table, writes the start configuration on a work tape, and then repeatedly performs the operation "given a configuration and the table, produce its successor configuration". That operation is decidable: it is a bounded search through the finitely many table entries for the one matching the current state and scanned symbol, followed by a local rewrite of the configuration string. halts exactly when the simulated machine reaches a halting state, and then copies the output; so if and only if , with the same value. Since halts exactly on the pairs with , that set is the domain of a partial computable function and hence r.e.
The step compressed is the bookkeeping: a single tape must hold the table, the simulated tape and a marker for the simulated head, and shifting cells to make room requires care. Theorem Robustness of the model lets us carry out the construction on a three-tape machine, where it is immediate, and then convert.∎
Theorem 6.20 (The - - theorem). For all there is a total computable, injective function of arguments such that
for all and all arguments, where on each side denotes the standard listing of partial computable functions of the appropriate arity. In words: fixing some of a program's inputs can be carried out on the program text, computably and uniformly.
Proof. Sketch. Given and , the function outputs the code of the machine that, on input , first writes the fixed constants to the left of its input — a preamble of finitely many states depending only on the numerals — and then runs . Building this code is textual splicing: read off the table of , renumber its states to make room, prepend the preamble, and re-encode. Every step is a primitive recursive operation on the code, so is total computable, and padding the preamble with unreachable states makes it injective. The displayed equivalence holds because the constructed machine's computation on is, after the preamble, literally the computation of on . What is not spelled out here is the encoding-level detail of the renumbering, which depends on the coding fixed in Definition Encoding and the standard listing.∎
Intuition. The - - theorem is currying, and you have used it whenever you wrote a closure or a partial application. Its content is not that partial application exists but that it is effective on the code: there is an algorithm taking a program and some inputs to a new program. That is what licenses a proof to say "let be the total computable function with ", which is how every reduction in this chapter is built.
Example 6.21 (Building a program that ignores its input). Given , construct — computably in — an index with for every : a program that discards its own input and instead runs on .
Solution. Define the partial computable function of two arguments
which is partial computable because it is for the universal machine , with discarded. Fix an index for as a function of two arguments. By - - with put
Then is total computable, being the total computable with its first argument fixed, and for every
So is the everywhere-undefined function when , and a constant total function when . This three-line pattern — define the partial function you want, take an index for it, apply - - — is the engine of every reduction in the following sections and of the proof of Rice's theorem. □□
Proposition 6.22 (Closure properties). The decidable sets are closed under complement, union and intersection. The r.e. sets are closed under union and intersection, but not under complement.
Proof. For decidable sets, run the deciders and combine their answers with ; all deciders are total, so the combination halts on every input.
For r.e. sets and : for the intersection, run and then in sequence and halt only if both halt, which gives domain . For the union, run the two in parallel by stages exactly as in the proof of Theorem Complementation characterises decidability and halt as soon as either halts, giving domain . Failure of closure under complement follows from Theorem Complementation characterises decidability together with the existence, proved in the next section, of an r.e. set that is not decidable: were the r.e. sets closed under complement, every r.e. set would have r.e. complement and hence be decidable.∎
6.4The Halting Problem and Diagonalisation
Everything so far has been machinery. This section spends it, producing a concrete, completely natural set that no algorithm decides.
Definition 6.23 (The halting problem). The halting problem is the set
"does program halt on input ? ". Its diagonal version is
the set of programs that halt when run on their own code. is also written and called the halting set.
Both sets are r.e.: by Theorem Universal machine, or the enumeration theorem, is the domain of , and is the domain of . So halting is semi-decidable — run the machine and say yes if it stops. What cannot be done is to ever say no.
Theorem 6.24 (Undecidability of the halting problem). is not decidable, and neither is . Hence there is no algorithm which, given a program and an input, always halts and correctly reports whether that program halts on that input.
Proof. Suppose were decidable. Then the partial function
would be partial computable: run the assumed total decider for on , output if it says "no", and enter a deliberate infinite loop if it says "yes". Being partial computable, for some index . Now ask whether :
where the first equivalence is the definition of , the second is , and the third is the definition of . This is a contradiction, so no decider for exists.
For : a decider for would decide , since and is computable. So is undecidable too.∎
Intuition. The argument is Cantor's diagonal argument wearing different clothes. Lay out the infinite table whose entry records whether halts. A decider for would let us compute the diagonal of that table, and is built to disagree with the diagonal at every point: it halts exactly where the diagonal says "does not halt". But is itself one of the rows, say row , and a row cannot differ from the diagonal at its own position. Cantor built a real not in the list; Turing built a program not in the list of programs, which is impossible, so the assumed decider is what fails.
Corollary 6.25 (The complement of is not even r.e.). is not recursively enumerable. Likewise , the set of pairs such that runs forever on , is not r.e.
Proof. is r.e. and, by Theorem Undecidability of the halting problem, not decidable. If were r.e. as well, Theorem Complementation characterises decidability would make decidable. The same argument applies to .∎
So the two halves of the halting question are not symmetric. "This program halts" is confirmable in finite time whenever it is true; "this program never halts" is not confirmable even in principle by any uniform procedure, which is why non-termination proofs are always specific to the program at hand.
Pitfall. Undecidability of halting is not the claim that no program's behaviour can ever be determined. For any particular program you may well have a proof that it halts — the successor machine above halts in steps, and that is a theorem. The undecidable object is the uniform question, one algorithm answering for all pairs. Likewise, undecidability says nothing about approximations: compilers, termination checkers and static analysers are sound but incomplete, answering "halts", "loops", or "don't know", and that third option is exactly what makes them possible.
Example 6.26 (Halting on the empty input). Show that — "does this program halt on the fixed input ? " — is undecidable, even though the input is no longer a parameter.
Solution. Use Example Building a program that ignores its input: the total computable there satisfies for every . In particular
Suppose had a total decider . Then is total computable and decides : it answers yes exactly when , that is, exactly when . This contradicts Theorem Undecidability of the halting problem, so no such exists.
Note the direction, which is the whole content of the argument: we turned a decider for the target problem into a decider for the known-undecidable one. Building a decider for the halting problem out of a decider for would prove nothing about at all. □□
Undecidability also has a quantitative shadow: a function that is perfectly well defined and grows faster than every computable function.
Definition 6.27 (The busy beaver function). For let be the largest number of s that any -state, two-symbol Turing machine can leave on an initially blank tape before halting, the maximum being taken over the finitely many such machines that do halt.
Theorem 6.28 (Busy beaver is not computable). is not computable. Indeed eventually exceeds every computable function: for every computable there is an with for all .
Proof. Suppose were computable, and let be the maximum number of steps taken by a halting -state machine on the blank tape; the same argument applies to either, and is computable if is, since one may run each halting machine to completion once its output length is known to be bounded. Then halting on the blank tape becomes decidable: given an -state machine, simulate it for steps, and if it has not halted by then it never will, because bounds the running time of every halting -state machine. This contradicts the undecidability of blank-tape halting, which follows from Example Halting on the empty input by translating "input " into "blank tape" — a fixed change of encoding.
For the growth claim, let be computable and consider , which is computable, total and non-decreasing. There is a fixed machine of some size computing , so an -state machine can be built, for suitable small overhead, that writes in unary and then runs it; this puts ones on the tape using states, whence . Since is non-decreasing in , this forces past from some point on.∎
Example 6.29 (The known busy beaver values). The values of for small are , , , , and . Explain why the sequence stops there.
Solution. For each fixed there are only finitely many -state two-symbol machines — about of them — so is a perfectly well-defined natural number, and in principle each value is found by examining a finite list. What is not finite is the work of deciding, for each machine on that list, whether it halts at all: a machine that has not halted after a trillion steps might still halt, and no uniform test can tell. Determining required resolving the behaviour of every hold-out machine individually, and is known to exceed , a tower of exponentials, so it will never be pinned down by simulation.
This is Theorem Busy beaver is not computable seen from ground level: the difficulty is not that the values are large, but that no single algorithm produces them, so each new value demands a new mathematical argument. □□
Remark (What undecidability spread to). Many problems far from machine theory are undecidable, each by a reduction from halting: validity in first-order logic (the Entscheidungsproblem, Church and Turing 1936); whether a Diophantine equation has an integer solution (Hilbert's tenth problem, by the MRDP theorem); whether two context-free grammars generate the same language; whether a set of Wang tiles tiles the plane; and the word problem for finitely presented groups. The pattern is always the same: encode the computation history of a machine as an object of the target kind, so that a decision procedure for the target would read off whether the machine halts.
6.5Reductions: Transporting Undecidability
One undecidable set is enough, provided there is a disciplined way to carry its undecidability elsewhere. That way is reduction, and formalising it turns a collection of ad-hoc contradiction arguments into a single lemma applied over and over.
Definition 6.30 (Many-one reducibility). Let . Then is many-one reducible to , written , if there is a total computable with
If in addition is injective the reduction is one-one, written . Sets with and are many-one equivalent, .
Intuition. Read as " is no harder than ": questions about can be rephrased, by a fixed algorithm, as questions about . The function does no deciding — it is total, so it always returns, and it never learns the answer. It only translates. All the difficulty stays in .
Theorem 6.31 (Reduction transfers decidability and enumerability). Suppose . Then:
- if is decidable, so is ;
- if is r.e., so is ;
- contrapositively, if is undecidable then so is , and if is not r.e. then neither is .
Proof. Let be total computable with .
(1) If is a total decider for , then is total — both and halt on every input — and outputs exactly when , that is exactly when . So it decides .
(2) If , consider the machine that on input computes and then runs on it. It halts iff iff iff , so its domain is and is r.e.
(3) is the contrapositive of (1) and (2).∎
Pitfall. The direction is the entire content, and reversing it proves nothing. To show a target is undecidable you must reduce a known-undecidable to : , translating questions about halting into questions about . Writing instead shows only that is no harder than something hard, which is vacuous. A quick check: the reduction must start from an arbitrary instance of the hard problem and produce an instance of the target.
Method 6.32 (Proving a set undecidable by reduction).
- Choose a known-undecidable source, almost always .
- Describe, in plain algorithmic language, a program built from the arbitrary input , whose behaviour encodes whether : typically "on any input , first simulate , and only if that halts do the thing that puts into ".
- Invoke the - - theorem to make a total computable function . This is the step that makes the construction legitimate rather than merely plausible; the definition of requires to be total and computable, never partial.
- Verify both directions: , and . The second is where sloppy constructions fail, because a machine that "does nothing" must genuinely land outside .
- Conclude , so is undecidable by Theorem Reduction transfers decidability and enumerability.
Example 6.33 (The non-emptiness problem). Let , the set of programs that halt on at least one input. Prove , and deduce that is undecidable.
Solution. Follow the recipe. Define the partial computable function of two arguments , take an index for it, and set , which is total computable by the - - theorem. Then for all , so
Both directions are immediate from this: if then , so ; and if then the inner simulation never halts, so is defined nowhere, , and . Hence and is undecidable.
Note that is r.e.: dovetail the computations and halt if any of them halts. So is another r.e. undecidable set, and by Theorem Complementation characterises decidability its complement — "this program halts on no input" — is not r.e. □□
Example 6.34 (Totality is not even r.e.). Let . Show , so is undecidable, and show in addition that is not r.e.
Solution. The same works: is the constant function on all of when , hence total, and the empty function when , hence not total. So and is undecidable.
For the stronger claim, reduce instead. Define to be if does not halt within steps, and undefined otherwise — a legitimate partial computable function, since the step test is decidable, and one whose domain is an initial segment of . By - - get a total computable with . If then halts within no number of steps, so for every and . If , say halts in exactly steps, then is undefined for all , so . Hence , and since is not r.e. by Corollary The complement of is not even r.e., Theorem Reduction transfers decidability and enumerability shows is not r.e. either. □□
Reduction also organises the r.e. sets into a hierarchy with a top.
Definition 6.35 ( -completeness). A set is -complete for the r.e. sets if is r.e. and for every r.e. .
Theorem 6.36 ( is -complete). is r.e., and for every r.e. set . Hence is -complete, and so is .
Proof. is r.e. as noted above. Let be r.e. Define the partial computable function of two arguments
which ignores , and fix an index for it. By - -, is total computable and satisfies for all . In particular, taking ,
So is a many-one reduction of to . Since via , and is r.e., is -complete as well.∎
Corollary 6.37 (Undecidability by completeness). Every -complete set is undecidable, since is undecidable and reduces to it. Conversely, exhibiting a reduction for an r.e. shows is exactly as hard as the halting problem, not merely at least as hard.
Many-one reduction is not the only notion of relative difficulty, and it is deliberately restrictive: the translating function may consult only once, at the very end, and must accept its verdict unchanged. Allowing unrestricted use gives the coarser notion that governs the rest of the chapter.
Definition 6.38 (Oracle machines and Turing reducibility). An oracle machine with oracle is a Turing machine with an extra instruction "is ? ", answered in one step and correctly. Write for the partial function computed by the -th oracle machine with oracle .
is Turing reducible to , written , if for some — that is, is decidable by an algorithm allowed to ask membership questions about . If and , the sets are Turing equivalent, .
Proposition 6.39 (Many-one is strictly finer than Turing). implies , and implies . The converse of the first implication fails: but .
Proof. If reduces to many-one, an oracle machine computes , asks the oracle whether , and returns the answer; so . For the second claim, negate the output of the oracle machine deciding — a decision procedure can always be complemented, which is exactly what a semi-decision procedure cannot do.
: with oracle we decide and return the opposite answer. But : a many-one reduction of to would make r.e. by Theorem Reduction transfers decidability and enumerability, since is r.e., contradicting Corollary The complement of is not even r.e.∎
Remark. The asymmetry in that last proof is worth naming. Many-one reducibility respects the difference between "yes" and "no": it cannot flip an answer, so it can distinguish from . Turing reducibility identifies them, because a decision procedure may negate its answer freely. That is why is the right tool for statements about r.e. sets and is the right tool for measuring absolute information content, which is the subject of the final section.
6.6Rice's Theorem and the Recursion Theorem
The reductions of the last section were each built by hand, and each looked much like the last. Rice's theorem explains why: every question about what a program computes, as opposed to how it is written, is undecidable unless it is trivial. It is the one theorem in the chapter that closes a whole class of questions at once.
Definition 6.40 (Index set). A set is an index set if membership depends only on the function computed:
Equivalently, for some class of partial computable functions. An index set is trivial if it is or .
Index sets are exactly the semantic properties: they cannot distinguish two programs that behave identically, however differently they are written. A property like "the code of has an even number of states" is not an index set, since padding a machine changes the state count without changing its function.
Theorem 6.41 (Rice's theorem). Every non-trivial index set is undecidable. Equivalently: if is a class of partial computable functions that is neither empty nor all of them, then is undecidable.
Proof. Let be a non-trivial index set. Let denote the everywhere-undefined function, and let be an index for it (the machine that loops immediately on every input).
Case 1: . Since , choose , so is some partial computable function in the class. Define the partial function of two arguments
realised by the algorithm. On input , first simulate using the universal machine; if and when that halts, simulate and return its value. This is partial computable, so it has an index , and by the - - theorem there is a total computable with for all .
Check both directions. If then , so the first simulation always completes and for every ; that is, . As is an index set and , we get . If then , so the first simulation never completes and is undefined for every ; that is, . As is an index set and , we get .
So , i.e. , and by Theorem Reduction transfers decidability and enumerability together with Theorem Undecidability of the halting problem, is undecidable.
Case 2: . Then , and is again an index set — the defining implication is preserved under complement — and again non-trivial, since gives and gives . Case 1 applies to , so is undecidable; and a set is decidable exactly when its complement is, by Proposition Closure properties. Hence is undecidable.
Both cases are covered, since either does or does not belong to .∎
Intuition. Read the construction as a behaviour swap. The program is built so that its behaviour is — a behaviour inside the property — when halts, and no behaviour at all when it does not. Any decider for the property would therefore be reporting, in disguise, whether halts. Nothing about the property was used except that some program has it and some program does not; that is why the theorem is so sweeping, and also why triviality is the only escape.
Corollary 6.42 (A catalogue of undecidable questions). Each of the following is an undecidable property of a given program , because each defines a non-trivial index set: is total; is empty; is finite; is infinite; ; ; is a constant function; is decidable; agrees with a fixed partial computable function .
Pitfall. Rice's theorem applies only to index sets, and to non-trivial ones. Three common misapplications:
- "Does halt on the empty tape within steps?" is decidable — simulate for steps. It is not an index set, because two machines computing the same function can differ in speed.
- "Does the code of contain more than seven states?" is decidable by inspection; again not an index set, by padding.
- "Is partial computable?" is trivially true of every , so the index set is and the question is decidable — the answer is always yes.
Rice also does not say the property is non-r.e. Some non-trivial index sets are r.e. (, from the previous section, is) and some are not ( is not). Undecidable and non-r.e. are different claims, and Rice gives only the first.
Theorem 6.43 (Rice-Shapiro, which r.e. index sets look like). Let be a class of partial computable functions such that is r.e. Then for every partial computable ,
In words: an r.e. semantic property must be decided by a finite amount of the function's behaviour, and must be preserved when more behaviour is added.
Proof. Sketch, giving the easy direction in full and the idea of the other. If some finite lies in , then the "monotone" half asserts ; this half is proved by a reduction from of the same shape as in the example, using a machine that computes and then extends it to only while has not yet halted. If no finite sub-function of lies in but does, a symmetric construction reduces to , contradicting that is r.e. The compressed step in both halves is the verification that the approximating machines are uniformly constructible, which is - - applied exactly as in the proof of Rice's theorem.
The theorem immediately explains the catalogue above: " is total" fails the finiteness condition, since no finite sub-function is total, so is not r.e. — recovering by a general principle what the previous section proved by hand.∎
Rice's theorem was proved by reduction. There is a second route to it, through a theorem about self-reference which is worth having in its own right: it is the formal statement that a program can be given access to its own code.
Theorem 6.44 (Kleene's recursion theorem). For every total computable there is an with
Such an is called a fixed point of . In the stronger parametrised form: for every partial computable there is an with for all — a program may use its own index.
Proof. Sketch, complete in structure with one routine - - step left implicit. Define a partial computable function of two arguments by
meaning: compute ; if it converges to a value , run . By - - there is a total computable with , so whenever . Now let be total computable and let be an index for the total computable composition , so for all , and put . Then
where the second equality uses the displayed property of at , legitimate because is defined. The implicit step is the construction of itself, which is the same splicing argument as in Theorem The - - theorem.∎
Intuition. The recursion theorem is the reason self-referential programs are not paradoxical but routine. A quine — a program that prints its own source — is the fixed point of the function "given a program , return the program that prints ". Recursive definitions in programming languages are the same phenomenon: let rec is a fixed-point operator, and the theorem says the fixed point always exists and is computable. The diagonalisation of the halting proof and the self-application here are the same manoeuvre used with opposite intent — there to derive a contradiction, here to construct an object.
Example 6.45 (Rice's theorem again, from the recursion theorem). Derive Rice's theorem from Theorem Kleene's recursion theorem instead of from a reduction.
Solution. Let be a non-trivial index set and suppose it were decidable, with total decider . Non-triviality gives indices and . Define
Since is total and computable, so is . By the recursion theorem has a fixed point with , and since is an index set this gives .
But was built to violate exactly that: if then , and if then . Both cases contradict the displayed equivalence, so cannot exist.
The two proofs differ in flavour: the reduction proof shows how hard is, yielding , whereas this one shows only that is undecidable — but it does so in six lines, and it never mentions the halting problem. □□
6.7The Arithmetical Hierarchy and Turing Degrees
Undecidability is not a single condition. is harder than in a precise sense, is harder than both, and there is an unbounded ladder above them. Two measuring instruments make this precise: a syntactic one counting quantifier alternations, and a computational one counting oracles.
Definition 6.46 (The arithmetical hierarchy). A relation is if it is definable by a formula of arithmetic all of whose quantifiers are bounded, of the form or ; every such relation is decidable. For , a set is
- if for some relation ;
- if for some relation ;
- if it is both and .
The superscript records that the quantifiers range over numbers, not sets; it is often dropped. is if and only if is , directly from the definition and the duality of and .
Notation. Consecutive like quantifiers collapse: is with and decoding the pair, which costs only bounded quantifiers. So the level of a set is the number of alternations in the simplest formula defining it, and adding a dummy quantifier is always allowed: .
Theorem 6.47 (Post's normal-form theorem). A set is recursively enumerable if and only if it is .
Proof. () Suppose with decidable. The machine that on input tests in turn and halts at the first success has domain exactly : it halts when a witness exists and searches forever when none does. So is the domain of a partial computable function, i.e. r.e.
() Suppose . By Theorem Kleene normal form, and equivalence with Turing computability, exactly when some codes a halting computation of on , and is primitive recursive, hence decidable. So
which is .∎
Corollary 6.48 (Decidable equals ). is decidable if and only if is .
Proof. If is decidable then and are both r.e. by Theorem Complementation characterises decidability, so both are by Post's normal-form theorem; means , so . Conversely if is and then and are both , hence both r.e., hence is decidable by the same theorem.∎
Example 6.49 (Reading the level off the definition). Classify , , and in the hierarchy.
Solution. Write everything in terms of the decidable predicate : " halts within steps".
is , and it is not , since a set has complement and is not r.e. So is properly , and dually is properly .
: the inner part is , and one universal quantifier in front makes it . It is in fact properly — no definition exists — which is a sharpening of the earlier fact that it is not r.e.
, an over a matrix, hence ; it is properly so, and note with properly . Counting the alternations in the plainest definition is almost always the right first move; proving that the count cannot be lowered is the harder half and needs the hierarchy theorem below. □□
The computational instrument is the oracle, and iterating it produces exactly the same ladder.
Definition 6.51 (Turing degrees and the jump). The relation of Turing equivalence is an equivalence relation on ; its classes are the Turing degrees, written , and induces a partial order on them. The degree of the decidable sets is written ; it is the least degree.
The Turing jump of is
the halting problem relativised to the oracle . Write and , so and .
Theorem 6.52 (The jump is a strict increase). For every : is r.e. in ; ; and . Hence strictly, and
is a strictly increasing chain of degrees, so there is no hardest undecidable problem.
Proof. is r.e. in : the oracle machine that on input simulates , consulting the oracle whenever the simulation does, halts exactly on .
: for each let be an index of the oracle machine that, on any input, asks the oracle whether and halts if the answer is yes, looping otherwise. The map is total computable by relativised - -, and . So , hence .
: this is the halting proof relativised, and every step survives the addition of the oracle. Suppose were computable from . Then the partial function that on input decides whether using the oracle, outputs if the answer is no, and loops if the answer is yes, is partial computable in , hence equals for some . Then , a contradiction.
Applying the three facts to in turn gives the chain, and each step is strict.∎
Theorem 6.53 (Post's theorem). For every : a set is if and only if is r.e. in ; and is if and only if . Moreover is -complete for when .
Proof. Sketch. The case is Post's normal-form theorem together with Corollary Decidable equals . The induction step in one direction relativises the normal-form proof: a set is over a matrix, and by the induction hypothesis the matrix is decidable with oracle , so searching for a witness is a semi-decision procedure with that oracle. The other direction relativises the -predicate construction, writing "the oracle computation halts" as an existential over a predicate decidable in and then unwinding the oracle queries into the extra quantifiers supplied by the induction hypothesis. The step compressed is that unwinding, which needs the fact that oracle queries can be bundled into a single quantifier using a finite use of the oracle.∎
Corollary 6.54 (The hierarchy is proper). For every , and . In particular the arithmetical hierarchy does not collapse at any level.
Proof. By Post's theorem is . If were closed under complement we would have , hence , hence by Post's theorem — contradicting Theorem The jump is a strict increase, which makes the inequality strict. So , and since the second inclusion is strict too.∎
Intuition. The two instruments measure the same thing from opposite sides. Syntactically, each new quantifier alternation is a new level; computationally, each new jump is a new oracle. Post's theorem says the counts agree: alternations of quantifier is exactly applications of "solve the halting problem for the previous level". being means precisely that with a halting oracle you could semi-decide its complement but not decide it, and would need a second jump to settle it.
Remark (Post's problem and what lies between). Every r.e. set satisfies , and the classical examples — , , — are all of degree exactly . Post asked in 1944 whether there is an r.e. set of degree strictly between and . Friedberg and Muchnik answered yes, independently, in 1956-57, constructing two r.e. sets with and ; both then have intermediate degree. The proof introduced the priority method, in which infinitely many conflicting requirements are met by assigning them priorities and allowing high-priority requirements to injure the work done for lower ones only finitely often. That method is the engine of modern recursion theory and is well beyond this chapter, but the statement is worth carrying: the structure of the r.e. degrees is rich, not a two-element chain.
Remark (Where Kolmogorov complexity fits). A closely related uncomputability runs through the length of the shortest program producing a given string, the Kolmogorov complexity . That function is not computable, essentially by a diagonal argument of the same family as the one above, and the set of incompressible strings is not r.e. although its complement is. The chapter Algorithmic Information in information theory develops that theory — invariance, incompressibility, the connection to entropy and Chaitin's constant — and it is the right place to look for the string-by-string version of everything this chapter says about sets and functions.
- Confusing undecidable with uncomputable-in-general: Undecidability of halting does not mean nothing can be computed. Almost all the mathematics you use daily is computable; what fails is one uniform question about arbitrary programs.
- Applying Rice's theorem to syntax or to resource bounds: "Does the code have an even number of states?" and "does halt within steps?" are both decidable. Rice needs an index set — a property invariant under changes of program that preserve behaviour — and neither of these is one.
- Reducing in the wrong direction: To prove undecidable you need , translating halting instances into -instances. Producing a reduction instead proves nothing about .
- Treating a partial reduction function as a reduction: The in must be total computable. A construction that only sometimes returns a program is not a reduction; this is exactly what the - - theorem is invoked to repair.
- Equating r.e. with decidable: A set can be listable without being decidable — is the standing example. The listing must be in increasing order before you may conclude decidability.
- Equating recursive with primitive recursive: The primitive recursive functions are a proper subclass of the total recursive ones; Ackermann's function is total and computable but not primitive recursive.
- Reading the Church-Turing thesis as a theorem: It equates a formal class with an informal notion and so is not provable, only supportable — and refutable, in principle, by a physically realisable counterexample.
- Believing undecidability forbids tools: Compilers, static analysers and termination checkers all attack undecidable questions successfully, by being sound and incomplete: they are allowed to answer "don't know".
- Confusing halting with speed: A machine that halts on every input may still take astronomically long. Computability says nothing about running time; that is the business of complexity theory.