Problem statement
A problem that asks: For an arbitrary computer program and input, is it possible to determine if the program will run forever or halt?
Turing proved that the problem is undecidable, meaning that it is impossible to create an algorithm that will determine if an arbitrary program will halt. Turing uses Halting Problem to also prove that the Entscheidungsproblem is also undecidable.
Proof of undecidability
The halting problem’s undecidability was proved via contradiction. Assume that a program exists, where is a program that always gives the solution to the halting problem, is the program to decide the halting program for, and is the input to . Create a second program , where is the input program. does the opposite of , i.e. if says will halt on input , then will not halt.
will then either not halt if says it will halt, or halt if says it will not halt. In either case, is incorrect, which contradicts the initial assumption that is always correct. Therefore, there is no program that determines the solution to the halting problem for a arbitrary program and input. In this model, any input is allowed, which is why programs can be passed as input.
Intuitive proof
Proof by contradiction. Assume that a Turing machine exists (as a Turing machine can model any algorithm), we call it . will take a program and its input(s) and tells you correctly if it will halt. Then, Turing constructs a new Turing machine, call it , that uses as a subroutine. Heres how will work:
- D takes a program as its input
- D passes this program to
- If says the program will halt, will never halt.
- If says the program will not halt, will halt. Now, what happens if you run machine on itself as an input?
- If halts, then, following the logic, it will be passed to , which will say the program will halt, but then never halts.
- If never halts, then, it will be passed to , which will say the program will never halt, but then halts. This is a contradiction.