Definition
Halting Problem
The halting problem is a decision problem that asks for an algorithm to determine, for any given program and its input, whether the program will eventually halt or run forever.
Instance: program , input (string)
Question: Does program terminate for every input ?It is undecidable and semi-decidable.
Undecidability
Assume that the halting problem is decidable, i.e. there exists a program with the following properties:
- takes in 2 strings as input:
- : a program
- : the input for
- produces the following output:
Given that exists, trivially, there exists a program that only takes one program as input, duplicates it and calls with those two (duplicate) program strings:
And again, we can generate another program using that does not hold if holds on :
First, we can observe:
- halts on does not halt on input .
- does not hold on halts on input .
What happens when runs with as input?
- Case: halts on input . Then from observation (1) follows that does not hold on input , which is a contradiction.
- Case: does not halt on input . Then from observation (2) follows that halts on input . We found another contradiction.
Therefore, that our initial assumption was wrong, i.e. there is no program that decides the halting problem. We can conclude:
The halting problem is undecidable.