Lecture 9: To Halt or Not to Halt?

A Complete Formal Proof of the Halting Problem

Why This Question Matters

We ask for a single algorithm that takes two inputs, a machine encoding \(\langle M \rangle\) and an input string \(w\), and answers: does \(M\) ever halt on \(w\)?

Core Decision Problem

\(\mathrm{HALT}_{TM} = \{\langle M,w\rangle \mid M \text{ halts on } w\}\).

If this language were decidable, we could algorithmically detect non-termination for every program.

Computational Perspective

  • Universal Turing machines let one TM simulate any other TM from an encoding.
  • So deciding \(\mathrm{HALT}_{TM}\) is equivalent to deciding whether universal simulation will eventually stop.
  • The proof below shows that no decider can solve this for all encoded machines and inputs.

Formal Statement and Assumptions

Theorem (Halting Problem)

\(\mathrm{HALT}_{TM}\) is undecidable.

Assumption for Contradiction

Assume there exists a total Turing machine \(H\) deciding \(\mathrm{HALT}_{TM}\). Then for all \(\langle M,w\rangle\):

\[ H(\langle M,w\rangle)= \begin{cases} \text{YES} & \text{if } M \text{ halts on } w,\\ \text{NO} & \text{if } M \text{ does not halt on } w. \end{cases} \]

Encoding Preconditions

  • Every TM has an effective encoding \(\langle M \rangle\).
  • Pairs are effectively encoded as \(\langle M,w \rangle\).
  • A universal TM \(U\) exists such that \(U(\langle M,w\rangle)\) simulates \(M\) on \(w\).

Complete Formal Proof (By Contradiction)

Step 1. Assume decider \(H\) for \(\mathrm{HALT}_{TM}\) exists (as above).
Step 2. Construct machine \(D\) that takes one input string \(x\):
\[ D(x):\ \text{run } H(\langle x,x\rangle). \\ \text{If } H \text{ outputs YES, then loop forever.}\\ \text{If } H \text{ outputs NO, then halt immediately.} \]
Step 3. Since \(H\) is assumed total and always halts, \(D\) is a valid TM construction.
Step 4. Evaluate \(D\) on its own encoding: input \(\langle D \rangle\).
Step 5. Case analysis:
  • If \(H(\langle D,D\rangle)=\text{YES}\), then \(H\) predicts that \(D\) halts on \(\langle D\rangle\). But by definition of \(D\), it loops forever. Contradiction.
  • If \(H(\langle D,D\rangle)=\text{NO}\), then \(H\) predicts that \(D\) does not halt on \(\langle D\rangle\). But by definition of \(D\), it halts immediately. Contradiction.
Step 6. Both exhaustive cases yield contradiction. Therefore the assumption that \(H\) exists is false.

Conclusion

No Turing machine decides \(\mathrm{HALT}_{TM}\). Hence \(\mathrm{HALT}_{TM}\) is undecidable. \(\square\)

Proof Flow (Inputs, Outputs, and Contradiction)

1) Hypothetical Decider and Diagonal Machine Construction

H decides HALT_TM D(x) query H(<x,x>) YES -> loop forever NO -> halt Output behavior contrary to H's prediction <x,x> invert Self-input later: x = <D> This creates diagonal contradiction at <D,D>

2) Contradiction on Self-Reference Input \(\langle D,D\rangle\)

Input to H: <D,D> Does D halt on its own encoding? Case A: H says YES Prediction: D halts on <D> Rule of D: YES -> loop forever Actual: D does NOT halt Contradiction Case B: H says NO Prediction: D does not halt on <D> Rule of D: NO -> halt immediately Actual: D halts Contradiction

Final takeaway: Any claimed total halting decider can be diagonalized into failure on a self-referential encoded input.

🏠