← Back to Paradoxes

The Halting Problem

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...

def HALTS(program, input): # Magic oracle that always works if program_halts_on_input: return True else: return False

Now construct this EVIL program:

def EVIL(program): if HALTS(program, program): while True: # Loop forever pass else: 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

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:

Connection to Other Paradoxes

The Halting Problem is equivalent to many other undecidable problems:

"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.