Some questions are mathematically impossible to answer
Can You Predict If It Halts?
Select a program, then predict: will it eventually HALT (finish), or LOOP forever?
Select a program above
0
Correct
0
Incorrect
-%
Accuracy
The Impossible Algorithm
Suppose we HAD an algorithm HALTS(P, I) that correctly determines if program P halts on input I...
defHALTS(program, input):# Magic oracle that always worksif program_halts_on_input:returnTrueelse:returnFalse
Now construct this EVIL program:
defEVIL(program):if HALTS(program, program):whileTrue: # Loop foreverpasselse:return# Halt immediately
?What happens when we run EVIL(EVIL)?
Case 1: HALTS says EVIL(EVIL) halts
→ EVIL enters infinite loop
→ EVIL does NOT halt
→ CONTRADICTION!
Case 2: HALTS says EVIL(EVIL) loops
→ EVIL returns immediately
→ EVIL DOES halt
→ CONTRADICTION!
Either way, HALTS gives the WRONG ANSWER. Therefore, no such algorithm can exist!
The Diagonal Argument (Visual)
This proof uses the same diagonal technique as Cantor's proof of uncountable infinities:
■ H = Halts
■ L = Loops forever
■ Diagonal (what HALTS predicts for P(P))
■ EVIL = Opposite of diagonal
The Paradox Explained
"We can never have a complete, consistent theory of mathematics. Some truths will always be beyond proof."
— Paraphrase of Gödel's and Turing's results
The Question
Given any computer program and its input, can we determine whether the program will eventually stop (halt) or run forever?
At first, this seems like it should be possible — just analyze the code! But Alan Turing proved in 1936 that no algorithm can solve this for ALL programs.
Why It Matters
Virus detection — We can't perfectly detect all malware (it might be a halting-based bomb)
Program verification — We can't automatically verify all software is bug-free
Compiler optimization — We can't always determine if code is dead
Mathematical proofs — Some mathematical statements are undecidable
The Self-Reference Trick
The proof works by creating a program that asks about itself. This is similar to:
The Liar Paradox: "This sentence is false."
Russell's Paradox: The set of all sets that don't contain themselves.
Gödel's Incompleteness: "This statement cannot be proven."
The Halting Problem: A program that does the opposite of what HALTS predicts.
What We CAN Do
While we can't solve the general halting problem, we can:
Prove specific programs halt (through careful analysis)
Use heuristics that work for "most" programs
Set timeouts (if it hasn't halted in X seconds, give up)
Require programmers to provide proofs of termination
Connection to Other Paradoxes
The Halting Problem is equivalent to many other undecidable problems:
Rice's Theorem: ANY non-trivial property of programs is undecidable
The Entscheidungsproblem: Decidability of first-order logic (answered "no" by Turing)
Busy Beaver: Finding the longest-running terminating program
"The halting problem is undecidable not because we're not smart enough, but because the universe of computation contains inherent limits. This is as fundamental as the speed of light in physics."
Historical Note
Turing published this result in 1936, before electronic computers existed! He invented the theoretical "Turing Machine" specifically to prove this impossibility result. The paper "On Computable Numbers" is one of the most important in computer science history.