The Halting Problem
27 Oct 2024
The halting problem is the problem of determining whether a given program will halt or continue to run forever on a given input. The problem is undecidable: no algorithm exists that can solve it for all possible program-input pairs. We can show this using a two part proof. First, we prove, by contradiction, that the acceptance problem is undecidable. Second, we prove, also by contradiction, that the halting problem is undecidable.
The acceptance problem is the problem of determining whether a given Turing machine accepts a given input. We show that the acceptance problem is undecidable. Let
ATM = {<M, w> | M accepts w}
be the set of strings that encode (M, w) pairs, where M is a Turing machine and w is a string. We claim that ATM is undecidable. Suppose that ATM is decidable. Then, there exists a Turing machine that decides ATM. Call it H:
Now, construct a new Turing machine D that uses H as a subroutine. D takes a string encoding of a Turing machine M as input, and passes M as both the first and second arguments to H, returning the opposite of H's output:
Finally, pass D as input to itself:
In both cases, we reach a contradiction. Therefore, the assumption that ATM is decidable must be false. In other words, ATM is undecidable.
Next, we show that the halting problem is also undecidable. Let
HTM = {<M, w> | M halts on w}.
Again, we claim that HTM is undecidable. Suppose that HTM is decidable. Then, there exists a Turing machine that decides HTM. Call it R:
Now, we can use R to construct a Turing machine S that decides ATM, using R as a subroutine to determine whether M halts on w:
Therefore, if HTM is decidable, then ATM is also decidable. But we have already shown that ATM is undecidable. Therefore, the assumption that HTM is decidable must be false. In other words, HTM is undecidable.