Halting problem and reductions
The first undecidable problems: the acceptance problem A_TM and the halting problem for Turing machines, proved undecidable by diagonalisation (and by counting machines against languages), the universal machine showing A_TM is recognisable, mapping reductions and how they transfer undecidability (A_TM to HALT, E_TM, EQ_TM), the unrecognisable complement of A_TM, and a map of which problems are decidable, recognisable, co-recognisable or neither.
Why it exists
Earlier pages showed that some problems about machines are decidable (is a DFA's language empty?). This page proves the opposite: no algorithm can decide whether a given Turing machine accepts a given input, or whether it halts. This is the most famous negative result of computer science and a staple of GATE: which of these problems is undecidable, which is recognisable, what does a reduction prove.
Prerequisites
You need the notions of decider and recogniser and the theorem about a language and its complement (decidable and recognisable languages).
Precise definitions
Fix an encoding of Turing machines as strings (TM variants). Then:
- (the acceptance problem);
- (the halting problem; halting means accepting or rejecting, not looping).
A mapping (many-one) reduction from to , written , is a computable function (computed by a machine that always halts) with
Reduction theorems. If and is decidable then is decidable; if and is recognisable then is recognisable. Contrapositive: if is undecidable and then is undecidable. To prove a new problem undecidable, reduce a known undecidable problem to it.
How it works
is recognisable
The universal machine on input simulates on and accepts if accepts. If loops, loops; so recognises but does not decide it. (A program that decodes the description and simulates agrees with direct simulation on all test strings.)
is undecidable: diagonalisation
Idea. List all Turing machines (possible, because a machine is a finite string: all strings can be listed by length and alphabetically, and for every size there are finitely many machines; with states and tape symbols there are exactly transition tables, if each entry is a move or missing: for , , found by enumeration) and the strings in the same way. Make a table with a row for each machine and a column for each string; the entry is "accepts" or not. The diagonal machine accepts exactly when does not accept . Then differs from every in the entry of column , so is not in the list: the language of is recognised by no machine of the list. If were decidable, could be built, and is a machine, so it is in the list: contradiction.
Here is the table for six real machines (accepts, rejects, or runs for more than moves without halting) on the first six strings, with the diagonal row computed by flipping the diagonal:
The diagonal argument on six real machines: start
Computed by a script, not typed| machine \ input | ε | a | b | aa | ab | ba |
|---|---|---|---|---|---|---|
| M1: recogniser: accepts strings containing b, loops on a* | ||||||
| M2: decider for a^n b^n | ||||||
| M3: accepts every string | ||||||
| M4: rejects every string | ||||||
| M5: decider: contains a | ||||||
| M6: decider: even length | ||||||
| D: accepts s_i exactly when M_i does not accept s_i |
Step 0
Each row is a machine run on the strings ε, a, b, aa, ab, ba (the strings s_1 ... s_6). The last row is built from the diagonal by flipping it. The same construction works for an infinite list of all machines: the language of D is recognised by no machine in the list.
The last row differs from row at column , for every (a machine that does not halt does not accept, so the flipped entry is "accepts").
The proof in words (Turing's argument). Suppose a machine decides . Build : on input , run on and do the opposite (accept if rejects, reject if accepts). Run on its own description : accepts iff says does not accept , iff does not accept . Contradiction. So no such exists.
A counting version. The set of Turing machines is countable (strings over a finite alphabet), the set of languages over is uncountable (it has the size of the set of infinite 0-1 sequences, by Cantor's diagonal argument). So most languages are recognised by no machine at all; the undecidable problems are not rare curiosities.
The halting problem
is undecidable because . Given construct where is with every place where would halt and reject replaced by an endless loop (move right for ever). Then halts on exactly when accepts . A decider for would therefore decide . The table checks the equivalence on six machines and four strings each:
A_TM reduces to the halting problem: start
Computed by a script, not typed| pair (M, w) | M on w | M' on w | M accepts ⇔ M' halts |
|---|---|---|---|
| M1 on ε | |||
| M1 on a | |||
| M1 on b | |||
| M1 on aa | |||
| M2 on ε | |||
| M2 on a | |||
| M2 on b | |||
| M2 on aa | |||
| M3 on ε | |||
| M3 on a | |||
| M3 on b | |||
| M3 on aa | |||
| M4 on ε | |||
| M4 on a | |||
| M4 on b | |||
| M4 on aa | |||
| M5 on ε | |||
| M5 on a | |||
| M5 on b | |||
| M5 on aa | |||
| M6 on ε | |||
| M6 on a | |||
| M6 on b | |||
| M6 on aa |
Step 0
The reduction maps (M, w) to (M', w), where M' behaves like M but loops for ever wherever M would halt and reject. M' halts on w exactly when M accepts w. If the halting problem were decidable, so would be acceptance.
For example the machine "reject every string" halts on every input but accepts none; its transformed version loops everywhere. is recognisable (simulate and accept when the simulation halts).
Unrecognisable languages
is recognisable and undecidable, so by the theorem of the previous page its complement is not recognisable. Likewise is not recognisable. These are the first examples of languages that no machine recognises in a natural way.
More undecidable problems by reduction
- is undecidable: from build that ignores its input, runs on and accepts if accepts. Then iff accepts (this is the construction behind Rice's theorem). is not recognisable but its complement (non-empty language) is recognisable: dovetail over all strings.
- (do two machines recognise the same language) is undecidable: , comparing with a machine that rejects everything.
- (is the language regular) is undecidable (a similar reduction, quoted).
- Post correspondence problem, equivalence of two context-free grammars, whether a grammar is ambiguous, Hilbert's tenth problem (integer roots of polynomials), and the validity of sentences in first-order logic are undecidable (quoted); the first is the usual starting point for proofs about grammars.
A map of the problems
| problem | decidable | recognisable | complement recognisable |
|---|---|---|---|
| , , , , | yes | yes | yes |
| , | no | yes | no |
| , | no | no | yes |
| no | no | yes | |
| no | no | no (quoted) |
Worked examples
EX 1Is it decidable
EasyDoes a given DFA accept a given string: decidable. Does a given Turing machine accept a given string: undecidable. Does a given Turing machine halt within moves on a given input: decidable (simulate moves). Does a given Turing machine halt on a given input at all: undecidable.
EX 2Direction of a reduction
EasyTo show a new problem undecidable, reduce from an undecidable to (). Reducing to would only show that is no harder than . From we conclude is undecidable; from (also true) we would conclude nothing about .
EX 3Why the transformation works
MediumMachine : rejects every string (no transitions). : loops right for ever on every symbol. For any , halts (and rejects), never halts: so -with- and -with-, consistent with "M accepts iff halts on ". Machine "accept every string": both accept and halt immediately. Rows of the table above show this for all six machines.
EX 4A recognisable, undecidable set
Mediumis recognisable (run on and accept if it halts) and undecidable (reduction from : from build a machine that first writes and then behaves like ). Its complement ( runs for ever on ) is not recognisable.
EX 5Typical questions
GATE level(a) "The halting problem is:" undecidable but recursively enumerable. (b) "Which is undecidable: whether a TM accepts / whether a DFA accepts / whether a CFG is empty?" The first. (c) "The complement of the halting problem is r.e." False. (d) "If and is undecidable then :" is undecidable. (e) "If and is r.e. then :" is r.e. (f) "The set of all Turing machines that accept at least one string:" recursively enumerable and not recursive.
Cheat box
Cheat box
- and : recognisable, undecidable; their complements are not recognisable.
- Proof by diagonalisation: accepts iff does not accept ; contradicts itself.
- Reduction : ; undecidable gives undecidable (reduce FROM the known one).
- : replace rejecting halts by loops. , , undecidable.
- Decidable for DFAs and CFGs: acceptance, emptiness (DFA equivalence too); not for TMs.
Traps and GATE patterns
Connections
Builds on
Across subjects
No cross-subject links yet.
The construction of above is the key step of Rice's theorem (Rice's theorem); the distinction between recognisable and decidable comes from the previous page (decidable and recognisable languages); the universal machine and encoding come from the page on variants (TM variants).
PYQs
6 previous year questions from your book. I re-solved each one myself (0 by running or simulating, 6 by reasoning only); the book's key is shown next to my answer. All PYQs
Consider the following problems. L(G) denotes the language generated by a grammar G. L(M) denotes the language accepted by a machine M. (I) For an unrestricted grammar G and a string w, whether w∈L(G). (II) Given a Turing machine M, whether L(M) is regular. (III)Given two grammar G1 and G2, whether L(G1) = L(G2). (IV) Given an NFA N, whether there is a deterministic PDA P such that N and P accept the same language. Which one of the following statement is correct?
- (a)Only I and II are undecidable
- (b)Only III is undecidable
- (c)Only II and IV are undecidable.
- (d)Only I, II and III are undecidable.
Let L(R) be the language represented by regular expression R. Let L(G) be the language generated by a context free grammar G. Let L(M) be the language accepted by a Turing machine M. Which of the following decision problems are undecidable? I. Given a regular expression R and a string w, is w ∈ L(R)? II. Given a context-free grammar G, is L(G) = ∅? III. Given a context-free grammar G, is L(G) = Σ* for some alphabet Σ? IV. Given a Turing machine M and a string w, is w ∈L(M)?
- (a)I and IV only
- (b)II and III only
- (c)II, III and IV only
- (d)III and IV only
Consider the following languages.
L1 = { ⟨M⟩ | M takes at least 2016 steps on some input },
L2 = { ⟨M⟩ | M takes at least 2016 steps on all inputs },
and
L3 = { ⟨M⟩ | M accepts ε },
Where for each Turing machine M, ⟨M⟩ denotes a specific
encoding of M.
Which one of the following is TRUE?- (a)L1 is recursive and L2, L3 are not recursive
- (b)L2 is recursive and L1, L3 are not recursive
- (c)L1, L2 are recursive and L3 is not recursive
- (d)L1, L2, L3 are recursive
Let A≤mB denotes that language A is mapping reducible (also known as many-to-one reducible) to language B.Which one of the following is FALSE?
- (a)If A≤mB and B is recursive then A is recursive.
- (b)If A≤mB and A is undecidable then B is undecidable.
- (c)If A≤mB and B is recursively enumerable then A is recursively enumerable
- (d)If A≤mB and B is not recursively enumerable then A is not recursively enumerable
Which of the following is/are undecidable? 1. G is a CFG. Is L(G) = φ? 2. G is a CFG. Is L(G) = Σ*? 3. M is a Turing machine. Is L(M) regular? 4. A is a DFA and N is an NFA. Is L(A) = L(N)?
- (a)3 only
- (b)3 and 4 only
- (c)1, 2 and 3 only
- (d)2 and 3 only
Consider three decision problems P1, P2 and P3. It is known that P1 is decidable and P2 is undecidable.
- (a)P3 is decidable if P1 is reducible to P3.
- (b)P3 is undecidable if P3 is reducible to P2
- (c)P3 is undecidable if P2 is reducible to P3
- (d)P3 is decidable if P3 is reducible to P2's complement
Self-check
Question 1
Why is recognisable but not decidable?
Show answerHide
A universal machine accepts exactly the accepted pairs, but a decider would allow the diagonal machine, which accepts iff does not, and cannot exist.
Question 2
What does the reduction do to the machine?
Show answerHide
It makes every rejecting halt of an endless loop, so the new machine halts on exactly when accepts .
Question 3
Is the complement of the halting problem recognisable?
Show answerHide
No: if both it and the halting problem were recognisable, the halting problem would be decidable.
Question 4
To prove a problem undecidable, which way must the reduction go?
Show answerHide
From a known undecidable problem to : .
Revision card
One-screen revision
- , : recognisable, undecidable. Complements: not recognisable.
- Diagonalisation: does the opposite of on .
- : undecidable undecidable . , , .
- DFA and CFG acceptance/emptiness decidable; TM versions not.
References
- ·Sipser, Introduction to the Theory of Computation (3rd edition), Section 4.2 (the diagonalisation method, Theorem 4.11) and Section 5.1 (undecidable problems from language theory, Theorem 5.1)
- ·Hopcroft, Motwani, Ullman, Introduction to Automata Theory, Languages, and Computation (3rd edition), Chapter 9 (undecidability), Sections 9.1 to 9.3
Verification
scripts/enum-checks/toc_compute.py: the diagonal table (six real machines on six strings, each entry recomputed with a second simulator) has a diagonal row that flips the diagonal and so differs from every machine in its own column; the number of machines with k states and g tape symbols is (2kg + 1)^(kg) (brute-force enumeration for k = 1, g = 2 gives 25), so machines can be listed by size; the reduction M -> M' (every halting rejection replaced by an endless loop) was checked on six machines and all strings up to length 7: M' halts exactly when M accepts, M' never halts and rejects, and M' makes the same number of moves as M when M accepts; the universal program decodes a machine description and simulates it with the same verdict and number of moves as direct simulation. The proofs that A_TM and HALT_TM are undecidable (self-reference, no machine is simulated by the decider), the transfer by reductions to E_TM, EQ_TM and REGULAR_TM, the Post correspondence problem, Hilbert's tenth problem and the classification of EQ_TM as neither recognisable nor co-recognisable are standard textbook results, QUOTED and not machine-proved (needs verification). Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (state counts, derivations, parse-tree and move counts, decomposition counts); tables and animations are machine output and were read, not re-run; No other defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)