Turing & the Halting Problem
Turing asked whether a universal program could decide if any other program halts. A diagonal construction shows that such a decider would contradict itself.
H(P):
if P(P) halts:
return "halts"
else:
return "loops"D():
if H(D) == "halts":
loop forever
else:
haltAssume a program H(P) always halts and correctly reports whether any program P halts.
The diagonal trick is the same idea as Cantor’s argument. H is assumed to work for every program. D is then designed specifically to disagree with H’s answer about D. That single self-reference breaks the assumption, so no general halting algorithm exists.
What you are seeing
Assume a program H(P) always halts and prints “halts” or “loops” for any program P.
Build D that calls H on itself: if H says D halts, D loops; if H says D loops, D halts.
Running D gives the opposite of H’s prediction, so H cannot be correct for every program.
Why it matters
Undecidability sets fundamental limits on software verification, static analysis, and artificial intelligence. Some questions cannot be answered by any general algorithm.
Complexity & details
The proof is a diagonal argument, not an algorithm. It rules out any total decider, regardless of running time.
Frequently asked questions
Can we decide halting for some programs?+
Yes. Many restricted programs are analyzable. The theorem says no single algorithm decides all programs correctly.
Is this related to P vs NP?+
They are different. P vs NP concerns efficient computation; undecidability says no algorithm exists at all, even with unlimited time.