Undecidability of the Halting Problem
Statement
There is no algorithm that, for every program index and input , always halts and correctly outputs whether (running program on input ) 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 exists: if (halts) and if (runs forever), and itself always halts with the correct answer.
Using , build a new program that, on input : computes ; if , then enters an infinite loop; if , then halts immediately. is built effectively from (just plus an if-statement and a loop), so it has some program index , i.e. .
Now ask the self-referential question: does halt?
Case 1: if halts, then by correctness of , . But by the definition of , makes loop forever on input — i.e. does not halt. Contradiction.
Case 2: if does not halt, then by correctness of , . But by the definition of , makes halt on input — i.e. does halt. Contradiction.
Both cases are contradictory, so the assumption that exists is false. The Halting Problem is undecidable.
Topics that use this theorem
Step-by-step proofs
No step-by-step proof yet for this theorem.
References
- Wikipedia contributors (2024). Halting problem
- Wikipedia contributors (2024). Rice's theorem
- Wikipedia contributors (2024). Ackermann function