Tech●●●●●Difficulty 5 of 5

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 story

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

The trap for a perfect checker
  1. Step 1: Assume

    A program f can always tell whether a program halts

  2. Step 2: Build g

    g gives itself to f and does the opposite

  3. Step 3: Ask f

    What does f say about g?

  4. Step 4: Contradiction

    Whatever f says, g does the opposite

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

From Hilbert's question to Turing's answer
  1. 1928

    Hilbert asks whether mathematics is decidable

  2. April 1936

    Church publishes his undecidability proof

  3. January 1937

    Turing's proof is published

Quiz me

0/3

  1. 1.How does Turing's proof defeat a supposed halting checker f?
  2. 2.Why can't we just run a program and wait to see whether it halts?
  3. 3.What does the halting problem's undecidability still leave possible?

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.

  1. [1]Halting problem · Wikipedia
  2. [2]Turing machines · Stanford Encyclopedia of Philosophy
More lessons in 💻 Tech (3) See all tech lessons →

One more light on your map.

Get one lesson like this every day, about the things you love. Free, in two or five minutes.

Get the share card for this lesson ↗