Decidability and Undecidability

Why some languages cannot be recognised at all, the halting problem and its diagonal proof, reductions, Rice's theorem, Post's correspondence problem, and a table of decidable and undecidable problems.

Some problems have no algorithm at all, no matter how much time or memory is allowed. This lesson shows why, and how to recognise such problems.

There are more languages than machines

Every TM can be written as a finite string, so the TMs can be listed one by one: there are countably many. But the languages over {0, 1} are all subsets of the countable set Σ*, and there are uncountably many of them (Cantor's diagonal argument). So most languages are not recognised by any TM, not even as RE languages. The interesting question is which natural problems fall outside.

The halting problem

HALTTM = { ⟨M, w⟩ : TM M halts on input w }

Proof by contradiction. Suppose a TM H decides it: H(⟨M, w⟩) always halts, answering "yes" if M halts on w and "no" otherwise. Build a new machine D that uses H on a machine's own description:

text
D(⟨M⟩):
    if H(⟨M, ⟨M⟩⟩) says "M halts on its own description":
        loop forever
    else:
        halt

Now run D on its own description ⟨D⟩:

  • If D halts on ⟨D⟩, then H says "halts", so D loops forever. Contradiction.
  • If D loops on ⟨D⟩, then H says "does not halt", so D halts. Contradiction.

Either way we have a contradiction, so H cannot exist. This is a diagonal argument: D is built to differ from every machine M on the input ⟨M⟩.

HALTTM is recursively enumerable: a universal TM simulates M on w and accepts if the simulation halts. So:

  • HALTTM and ATM = { ⟨M, w⟩ : M accepts w } are RE but not recursive.
  • Their complements are not RE (if both a language and its complement were RE, it would be recursive).

Reductions

To show that a new problem B is undecidable, reduce a known undecidable problem A to it: give an algorithm that turns every instance x of A into an instance f(x) of B, with x ∈ A ⟺ f(x) ∈ B. Written A ≤ B.

If A ≤ B and ...then ...
B is decidableA is decidable
B is REA is RE
A is undecidableB is undecidable
A is not REB is not RE

The direction matters: reduce from the known hard problem to the new one. Reducing the new problem to a hard one proves nothing.

Example: ETM = { ⟨M⟩ : L(M) = ∅ } is undecidable. Given ⟨M, w⟩, build a machine M′ that ignores its own input and runs M on w, accepting if M accepts. Then L(M′) is Σ* if M accepts w and ∅ otherwise. A decider for emptiness would therefore decide ATM.

Rice's theorem

  • "Property of the language" means it depends only on L(M), not on how M is built: "L(M) is empty", "L(M) is finite", "L(M) is regular", "L(M) contains 'abc'", "L(M) = Σ*".
  • "Non-trivial" means some TMs have the property and some do not.

Rice's theorem does not apply to properties of the machine itself: "M has more than 5 states" or "M moves left at least once on input ε within 100 steps" are decidable, because they can be checked directly.

Post's correspondence problem

Given a list of dominoes, each with a string on top and a string at the bottom, is there a sequence of dominoes (repetition allowed) in which the top strings and the bottom strings spell the same word? PCP is undecidable, even though every single candidate sequence is easy to check. Because it involves only strings, PCP is the usual starting point for proving grammar problems undecidable, such as ambiguity of CFGs and emptiness of the intersection of two CFLs.

Decidable or not? A summary

ProblemRegular (DFA)CFL (CFG/PDA)Recursive (halting TM)RE (TM)
Membership w ∈ LDDDU (semi-decidable)
Emptiness L = ∅DDUU
FinitenessDDUU
L = Σ*DUUU
Equivalence L₁ = L₂DUUU
Subset L₁ ⊆ L₂DUUU
L₁ ∩ L₂ = ∅DUUU
Is L regular?D (trivially yes)UUU

(D = decidable, U = undecidable.)

Other famous undecidable problems: whether a program has an infinite loop, whether two programs compute the same function, Hilbert's tenth problem (does a polynomial equation have an integer solution?), and the totality problem (does M halt on every input?), which is not even RE or co-RE.

Practice questions

GATE-styleMSQ · one or more correct answers

Which problems are undecidable? (Select all that apply.)

Show answer and explanationAnswer: A, B

Regularity of L(M) is a non-trivial language property, so Rice's theorem applies. CFG equivalence is undecidable. DFA finiteness is decidable (look for a useful cycle). The number of states is a property of the machine, not of its language, and is checked by reading ⟨M⟩.

GATE-styleMCQ · one correct answer

Problem A is known to be undecidable. To prove that problem B is undecidable, you should show:

Show answer and explanationAnswer: A

If A ≤ B and B were decidable, the reduction would give a decider for A. So the reduction must go from the known undecidable problem to the new one.

GATE-styleMCQ · one correct answer

L is recursively enumerable but not recursive. What can be said about its complement L̄?

Show answer and explanationAnswer: C

If L̄ were RE as well, L would be recursive (run both recognisers in parallel). So L̄ is not RE. Example: the complement of the halting problem.

GATE-styleMSQ · one or more correct answers

Which statements are true? (Select all that apply.)

Show answer and explanationAnswer: A, B, D

A universal TM recognises the halting problem by simulation. There are countably many TMs but uncountably many languages. Rice's theorem covers only non-trivial properties of the language, not of the machine. CYK decides CFL membership.