Proof
Turing's Proof by Contradiction
Assume there exists a program H(P, I) that solves the halting problem — returns TRUE if P halts on I, FALSE if not.
# Build a paradoxical program D(P):
SUBROUTINE D(P)
IF H(P, P) = TRUE THEN
loop forever # if P halts on itself, loop
ELSE
RETURN # if P loops on itself, halt
ENDIF
ENDSUBROUTINE
Real Example
Infinite Loop Example
A simple loop in pseudocode — no algorithm can tell for all programs whether they halt:
# Does this halt? Only if Collatz conjecture is true!
n ← USERINPUT
WHILE n ≠ 1 DO
IF n MOD 2 = 0 THEN
n ← n DIV 2
ELSE
n ← 3 * n + 1
ENDIF
ENDWHILE
The Collatz conjecture: we believe this halts for all positive n, but it has never been proved. This illustrates the halting problem in practice.