History of Math

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.

7 minLevel 3/3The interactive stage stays ad-free.
Step1 / 4StatusAssume H existsDecider HAssumedHalting problemUndecidable
1. Assume H existsH always decides2. Build DD calls H(D)3. Run DD does the opposite4. ContradictionH must be wrong
Decider H (assumed)
H(P):
  if P(P) halts:
    return "halts"
  else:
    return "loops"
Program D (diagonal)
D():
  if H(D) == "halts":
    loop forever
  else:
    halt
Assume H exists

Assume 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

1

Assume a program H(P) always halts and prints “halts” or “loops” for any program P.

2

Build D that calls H on itself: if H says D halts, D loops; if H says D loops, D halts.

3

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.