Why can no program check every other program for bugs?
In 1937 Alan Turing proved that a perfect program-checker cannot exist, using a program built to contradict it.
▶ Start the storyNo program can check every other program for bugs because a perfect checker would have to solve a problem Alan Turing proved unsolvable. The simplest version is the halting problem: given any program and an input, decide whether the program will eventually finish or run forever. In 1937 Turing proved that no general can correctly solve this for all possible program and input pairs. Telling whether a program halts is a bug check in miniature, and extends the result: all non-trivial of programs, meaning questions about what they actually do, are .
Turing's proof is a trap built from the checker's own answer. Suppose some program f could always say whether another program halts. Then you can write a program g that passes its own source and its input to f and does the opposite of what f predicts: if f says g halts, g loops forever, and if f says g loops, g halts at once. Whatever f answers about g, it is wrong. The essence of the proof is that any such can be made to produce contradictory output, so it cannot be correct.
That does not mean every program is a mystery. Simple cases are easy to decide: a program that prints a greeting and stops obviously halts. And for a specific program the answer is just "halts" or "does not halt". The impossible part is one procedure that works for all programs and inputs. Nor is waiting a way out: you can run a program and, if it stops, you know it halts, but an will not halt if the program it is running does not, so it can never answer "does not halt".
Step 1: Assume
A program f can always tell whether a program halts
Step 2: Build g
g gives itself to f and does the opposite
Step 3: Ask f
What does f say about g?
Step 4: Contradiction
Whatever f says, g does the opposite
Step 5: Conclude
No such f can exist
Real tools therefore settle for less. Programs such as the T2 Temporal Prover could automatically establish that certain Windows device-driver routines will always eventually return. They succeed on many programs, and no one can build one that succeeds on all.
1928
Hilbert asks whether mathematics is decidable
April 1936
Church publishes his undecidability proof
January 1937
Turing's proof is published
Quiz me
0/3
Recap
A perfect checker can always be handed a program built to contradict it, so some programs can be checked, but never all.
💡 A trick to remember it · Ask the oracle about the trickster: whatever it says, the trickster does the opposite.
Surprising fact · The proof works by building a program that asks the supposed checker about itself and does the opposite.
Sources (2)
No source, no claim. Every fact in this lesson (14 claims) cites at least one of these.