Notes on the Halting Problem
2023-12-07 · 4 min read
- computability
- math
- turing
The computability of the class is a simple problem to solve, which provides a very powerful result. Mainly, that we cannot prove that arbitrary Turing machines halt or not.
Except that this is not accurate. The undecidable nature of merely says that no singular Turing machine (i.e., a single algorithm) can compute whether any Turing machine halts or not.
Proving this is a fun little exercise, and the proof is similar to proving Russel’s paradox.
Proving is undecidable
We begin by assuming that there is some Turing machine, , which can decide whether a given input halts or not (running with input ). Then, construct a Turing machine as follows:
- Given input :
- If halts, then loop forever.
- Otherwise, halt.
Where checking if halts is done using . Now, consider what happens when we run with the input (i.e., feed to itself):
- If halts, then by the construction of , doesn’t halt.
- If doesn’t halt, then again by the construction, should halt.
This results in a contradiction, with the contradiction being the existence of itself.
While this proof is simple and effective, it does not give much insight to this problem. In fact, here is an algorithm which supposedly contradicts this proof:
- Given input :
- Enumerate on all proofs of , alternating between proving halting, and proving non-halting (infinite loop)
- Because must either halt or loop forever, eventually some proof will be found. Via this proof, report back “YES”/“NO”, depending on what proof we found.
Because proofs are always finite, this means that the algorithm above must stop sometime, and report a result. Yet, this contradicts what we’ve just proved: is undecidable, but here is an algorithm which decides it.
Gödel’s Incompleteness Theorems
In 1931, Gödel published an article showcasing two incredible results in mathematical logic. Of those two, the first is relevant to us. The result, also known as Gödel’s first incompleteness theorem, states:
Theorem. (Gödel’s first incompleteness theorem) Given any formal system , there exist some statement (also known as Gödel’s sentence) which cannot be proven or disproven under .
The connection between Gödel’s theorem and the halting problem is striking. Given any supposed algorithm which decides , we can find some Turing machine for which simply cannot decide whether it halts or not. However, this time no clever constructions are needed.
Because we assume to be correct (that is, answer correctly and not randomly), this means that must perform a sequence of logical conclusions, in order to arrive at the answer of whether a given machine halts or not. This is essentially the formal system, , under which is working. From Gödel’s first incompleteness theorem we can draw the conclusion that there is some statement , which is unprovable under . Finally, it is possible to turn into a Turing machine, by halting iff is true, and looping forever if it is false.
The algorithm above fails in deciding , because such proof might not exist, hence causing the algorithm to loop forever. For the sake of completeness: such algorithm cannot exist, because for any algorithm we can encode it as a proof under some formal system , and for each such system there is an unprovable statement.
Gödel’s incompleteness theorems were published before the consideration of the halting problems. At the time of publishing, this created a huge shock, as it implied that some statements simply cannot be proved (roughly speaking). For me, using these theorems in the context of computability is as shocking: it essentially implies that there exist Turing machine on which we cannot prove anything.
Of course, looking at this from a higher-level standpoint is not very impressive; Turing machines can be thought of as just proof enumerations, and in that regard indeed the two results are exactly the same.
Computability vs Decidability
Finally, a word on search problems. A similar construction can build uncomputable functions. That is, functions for which no Turing machine can compute , for sufficient . To do this, we utilize unprovable statements, yet again. Let be some function, and some Gödel statement. We construct the uncomputable function by:
Thus, for example, being able to compute any value of would be equivalent to the Turing machine proving . In other words, any output of an evaluation of at any input would require either proving or disproving .
might perhaps be cheating, as the existence of is dependent on the machine itself, yet we require the machine in order to construct the function. Instead, let us construct a function in two parts. First, let be defined as:
It is clear that is computable for some inputs, such as and , yet not computable for all inputs. Indeed, for the function is not computable by the same machine that might compute some of . Instead, construct a function which is not computable at all, by:
Which by itself is partially computable, yet with being the shortest Gödel statement under . is not computable under any input.