1 · Why this matters · the BIG picture
The halting problem is the most famous undecidable problem in computer science. Every introductory book mentions it.
Here is the precise statement: no program can examine an arbitrary program + input and reliably tell you whether
that program will eventually halt or run forever.
Practically, this means:
- Compilers cannot warn about every infinite loop.
- Static analyzers cannot guarantee termination of arbitrary code.
- "Will this regex match?" or "Will this script finish?" — undecidable in general.
What we are about to prove
HALTTM = {⟨M, w⟩ : M halts on w} is not Turing-decidable.
Strategy: assume a decider R for HALTTM exists, then build a decider S for ATM using R as a subroutine.
We already know ATM has no decider — contradiction.
2 · Setup · what is a "reduction"?
A reduction is the workhorse of complexity theory. We say "problem A reduces to problem B"
if a solver for B gives us a solver for A. Notation: A ≤ B.
The contrapositive is what we exploit: if A is unsolvable, then B is unsolvable too
(because solving B would solve A — but A cannot be solved).
Two flavors of reduction
- Turing reduction (≤T) · A's decider is allowed to call B's decider as a subroutine
any number of times and do additional computation around the calls.
- Mapping (many-one) reduction (≤m) · A's decider produces one input for B; that one
yes/no answer is exactly A's answer. Stricter, cleaner, preserves recognizability.
For HALTTM we present the Turing reduction first (intuitive), then the mapping reduction
(in Q4 below) for completeness.
3 · The proof · the contradiction machine S
Assume R is a decider for HALTTM. Define:
Decider S for ATM
S = "on input ⟨M, w⟩:
1. run R(⟨M, w⟩) — does M halt on w?
2. if R rejects: reject (M loops, so M does not accept).
3. if R accepts: simulate M on w directly (guaranteed to halt).
4. accept iff the simulation accepts."
S decides ATM: it always halts (step 3 is safe because R confirmed M halts),
and it outputs the correct answer. But Problem 3 told us no decider for ATM exists.
Contradiction ⇒ R does not exist ⇒ HALTTM is undecidable. ∎
4 · Animated demo · auto-plays · loops
5 · Worked example · trace through two inputs
Suppose we have these two specific inputs:
| ⟨M, w⟩ |
M's actual behavior on w |
R's answer (step 1) |
S's answer (final) |
| M1 = "always loop", w = ε |
loops forever |
reject |
reject (step 2) |
| M2 = "check parity", w = 0000 |
halts, accepts (even length) |
accept |
accept (sim accepts) |
| M3 = "check parity", w = 000 |
halts, rejects (odd length) |
accept |
reject (sim rejects) |
Every row terminates with a definite yes or no. Look closely at row 1: S never tried to simulate M1.
R told us up front it would loop, so we shortcut to reject without ever running M1. That shortcut is what
makes S a decider rather than just a recognizer.
6 · Connections · the reduction graph
- ETM (Problem 6) · undecidable. Reduce ATM by building M' that accepts only w.
- REGULARTM, CFLTM (Problem 7) · undecidable via similar reductions.
- EQTM · not recognizable, not co-recognizable. Reduces both ways.
- PCP, tiling, word problem for groups · all reduce from ATM or HALTTM.
- Rice's theorem (Problem 14) · the master generalization: every non-trivial language property reduces from ATM.
All of these proofs share the structure: "If you could solve me, you could solve ATM — which you can't."
7 · Common pitfalls · what students miss
- Reducing in the wrong direction. To prove B undecidable, reduce a known undecidable problem
to B (not the other way around). "A ≤ B" means B is at least as hard as A.
- Forgetting why simulation is now safe. Direct simulation of M(w) only terminates because R already
confirmed M halts. Without R, step 3 could loop.
- Believing HALT is even harder than ATM. Both have the same degree of unsolvability; reductions go both ways.
- "R rejected, so M halts but rejects." No — R rejecting means M does not halt at all.
R is a decider for HALT, not for accept.
- Mixing up Turing and mapping reductions. Turing reductions can do extra work after the call; mapping reductions cannot. For undecidability, either kind suffices.
8 · Q&A defence notes
-
Q1. What if M loops? Why is step 3 safe?
We reach step 3 only when R said M halts. So the direct simulation is guaranteed to terminate. The danger of looping is fully absorbed by R.
-
Q2. Could we skip R and just simulate M directly?
No — if M loops on w, the simulation never returns. Without R there is no way to tell halting from "not yet halted". R is what makes S a decider, not just a recognizer.
-
Q3. Why is this a "Turing reduction" and not a mapping reduction?
S calls R as a subroutine and then does more work (step 3). A mapping reduction would produce a single ⟨M', w'⟩ from ⟨M, w⟩ such that membership in HALTTM directly answers membership in ATM. Both kinds of reduction show undecidability; mapping reductions are stricter.
-
Q4. Construct a mapping reduction ATM ≤m HALTTM.
Given ⟨M, w⟩, output ⟨M', w⟩ where M' on input x simulates M on w; if M accepts, M' halts; if M rejects, M' loops. Then M accepts w ⇔ M' halts on w ⇔ ⟨M', w⟩ ∈ HALTTM.
-
Q5. Is HALTTM at least recognizable?
Yes. Simulate M on w; accept the moment it halts. If it never halts, the recognizer loops — that's allowed for recognizers.
9 · How to present this in class
Total time: 10 minutes.
- (1 min) Open with the practical hook: "Why can't your IDE warn you about every infinite loop?"
- (2 min) State the goal. Define A ≤ B at the level of intuition before writing it precisely.
- (3 min) Walk through the construction of S. Emphasize three regions on the picture: input → R box → simulator box → output.
- (2 min) Run the visualization. Let it play through the 5 stages with the pause control.
- (2 min) Wrap with the worked example table. Highlight row 1 — the "shortcut" — as the heart of the trick.