MathLabs
TheoremProved

Undecidability of the Halting Problem

Statement

There is no algorithm H(e,x)H(e,x) that, for every program index ee and input xx, always halts and correctly outputs whether φe(x)\varphi_e(x) (running program ee on input xx) halts.

Why is it true?

This is the mathematical reason why no antivirus, compiler, or IDE can ever perfectly detect infinite loops, dead code, or "this function always crashes" in full generality — not a limitation of today's engineering, but a hard mathematical wall.

Proof sketch

Suppose, for contradiction, that such a decider HH exists: H(e,x)=1H(e,x)=1 if φe(x) ⁣↓\varphi_e(x)\!\downarrow (halts) and H(e,x)=0H(e,x)=0 if φe(x) ⁣↑\varphi_e(x)\!\uparrow (runs forever), and HH itself always halts with the correct answer.

Using HH, build a new program DD that, on input ee: computes H(e,e)H(e,e); if H(e,e)=1H(e,e)=1, then DD enters an infinite loop; if H(e,e)=0H(e,e)=0, then DD halts immediately. DD is built effectively from HH (just HH plus an if-statement and a loop), so it has some program index dd, i.e. D=φdD=\varphi_d.

Now ask the self-referential question: does φd(d)\varphi_d(d) halt?

Case 1: if φd(d)\varphi_d(d) halts, then by correctness of HH, H(d,d)=1H(d,d)=1. But by the definition of DD, H(d,d)=1H(d,d)=1 makes DD loop forever on input dd — i.e. φd(d)\varphi_d(d) does not halt. Contradiction.

Case 2: if φd(d)\varphi_d(d) does not halt, then by correctness of HH, H(d,d)=0H(d,d)=0. But by the definition of DD, H(d,d)=0H(d,d)=0 makes DD halt on input dd — i.e. φd(d)\varphi_d(d) does halt. Contradiction.

Both cases are contradictory, so the assumption that HH exists is false. The Halting Problem is undecidable. ■\blacksquare

Topics that use this theorem

Step-by-step proofs

No step-by-step proof yet for this theorem.

References

  1. Wikipedia contributors (2024). Halting problem
  2. Wikipedia contributors (2024). Rice's theorem
  3. Wikipedia contributors (2024). Ackermann function