cs.thefarshad
hard

Computability and the Halting Problem

Some problems no algorithm can ever solve — proved by diagonalization and the halting problem.

Turing machines are the most powerful model of computation we know, yet there are precise, well-defined problems that no Turing machine — and so, by the Church-Turing thesis, no algorithm at all — can solve. Computability theory draws this line between what is decidable and what is not.

The classic proof technique is diagonalization. The grid below imagines every program listed in a table, then builds a new behavior D by flipping the diagonal so that D cannot match any row. Step through it.

Diagonalization. Imagine listing every program in a table: row i is program Mi, column j is input j, and the cell is whether Mi accepts j (1) or not (0). We build a row that cannot be anywhere in the table.
in 0in 1in 2in 3in 4in 5
M0101011
M1010011
M2011100
M3011111
M4010001
M5010110
D······

Diagonal cells are boxed. Row D is the flip of the diagonal: D(i) = NOT Mi(i).

1/20
Assume every program is listed: M0, M1, M2, … Cell (i, j) = does Mi accept input j?

Counting argument

There are only countably many programs: each is a finite string, and finite strings can be listed M0,M1,M2,M_0, M_1, M_2, \dots. But there are uncountably many languages over {0,1}\{0,1\} — as many as there are subsets of the natural numbers. Since you cannot pair up a countable set with an uncountable one, most languages have no program at all. Undecidable problems are not exotic; they are the overwhelming majority. The work is exhibiting a specific natural one.

The halting problem

The most famous undecidable problem is the halting problem: given a program MM and an input ww, decide whether MM halts on ww (rather than looping forever).

Suppose a decider HH existed, always halting with the correct yes/no answer. Build a new program DD that takes a program description M\langle M \rangle, runs HH on (M,M)(\langle M \rangle, \langle M \rangle), and then does the opposite:

  • if HH says MM halts on its own description, DD loops forever;
  • if HH says MM loops, DD halts.

Now feed DD its own description D\langle D \rangle. If DD halts on D\langle D \rangle, then by construction it must loop — and if it loops, it must halt. Both branches are contradictions, so HH cannot exist. This is exactly the diagonal flip applied to halting behavior.

Reductions spread undecidability

Once one problem is known undecidable, we transfer the result by reduction: to show a problem BB is undecidable, show that a decider for BB could be used to decide a known-undecidable problem AA. Since AA has no decider, neither does BB.

This makes a whole landscape of questions undecidable: does a program ever print a given output, do two programs compute the same function, is a given string ever produced? Rice’s theorem generalizes the pattern: every nontrivial property of the language a program recognizes is undecidable. You cannot, in general, determine any interesting behavioral property of arbitrary code by analyzing the code.

Why it matters

These limits are not about slow computers or clever-enough engineers; they are mathematical impossibilities. They explain why perfect static analyzers, universal bug detectors, and fully general optimizers cannot exist. Practical tools cope by being sound but incomplete (catching some cases, conservatively giving up on the rest) or by restricting attention to inputs where the question is decidable.

Takeaways

  • A counting argument shows there are far more languages than programs, so most problems are undecidable; the challenge is naming a concrete one.
  • The halting problem is undecidable: assuming a halting-decider and feeding the diagonal construction its own description forces a contradiction.
  • Reductions and Rice’s theorem propagate undecidability to nearly every nontrivial question about program behavior.

References

  • Michael Sipser, Introduction to the Theory of Computation, 3rd ed., Chapter 4 (Decidability) and Chapter 5 (Reducibility).
  • Hopcroft, Motwani, Ullman, Introduction to Automata Theory, Languages, and Computation, 3rd ed., Chapters 8-9.