Sub topic 10
The Halting Problem and A_TM Are Undecidable
Prerequisites: finite automata, context-free languages, Turing machine configurations, proof by contradiction, and basic set notation.
Two related decision problems
A decision problem asks whether an algorithm can always return the correct yes-or-no answer and halt.
Let
A_TM = {⟨M, w⟩ | Turing machine M accepts input w}.HALT_TM = {⟨M, w⟩ | Turing machine M halts on input w}.
The encoding ⟨M, w⟩ is a finite string describing a machine and its input. A machine can accept, reject, or run forever. Therefore, acceptance and halting are different properties.
| Problem | Yes-instance | What can happen otherwise |
|---|---|---|
| `A_TM` | `M` eventually accepts `w` | `M` rejects or loops |
| `HALT_TM` | `M` eventually halts on `w` | `M` loops forever |
Both problems are undecidable. No Turing machine can answer every instance correctly and halt on every input.
Diagonalization proof for A_TM
Assume that a decider H for A_TM exists. It takes ⟨M, w⟩ and returns:
- yes if
Macceptsw; - no otherwise.
Construct a new machine D that receives an encoding ⟨M⟩:
- Run
Hon⟨M, ⟨M⟩⟩. - If
Hsays thatMaccepts its own encoding, reject. - If
Hsays thatMdoes not accept its own encoding, accept.
Now run D on its own encoding, ⟨D⟩.
- If
Hsays thatDaccepts⟨D⟩, then the definition ofDmakes it reject. - If
Hsays thatDdoes not accept⟨D⟩, then the definition ofDmakes it accept.
Both answers contradict the prediction made by H. Thus, the assumed decider cannot exist, and A_TM is undecidable.
Why HALT_TM is also undecidable
Suppose a decider for HALT_TM existed. Given ⟨M, w⟩, construct a machine N that simulates M on w and halts exactly when M accepts. If the HALT_TM decider says that N halts, then M accepts w. If it says that N does not halt, then M does not accept w.
This would decide A_TM, which is impossible. Therefore, HALT_TM is undecidable.
A bounded simulator illustrates the limitation:
def run_bounded(delta, word, max_steps):
tape = dict(enumerate(word))
state, head = "q0", 0
for _ in range(max_steps):
if state in {"accept", "reject"}:
return state
symbol = tape.get(head, "_")
if (state, symbol) not in delta:
return "reject"
state, write, move = delta[(state, symbol)]
tape[head] = write
head += 1 if move == "R" else -1
return "unknown"
halts = {("q0", "1"): ("accept", "1", "R")}
loops = {("q0", "_"): ("q0", "_", "R")}
print(run_bounded(halts, "1", 10)) # accept
print(run_bounded(loops, "", 10)) # unknownThe result unknown is not a proof of non-halting. It only means that this particular simulation limit was reached.
Exercise
Why does a decider for A_TM need to halt even when the simulated machine loops?
Show answer
Because a decider must return a correct yes-or-no answer for every input. If it also loops on a looping machine, it has not decided the problem.