Halting Problem
- Imagine there is a function
bool doesItHalt({function f, input i})
that returns if the parameter functionf(i)
halts or not. - Now consider the following functions:
pair duplicator(input i) {
return {i, i}
}
bool invertHalt(bool b) {
if(b) {
while(true); // hangs forever
return 0;
} else {
return 0;
}
}
- Essentially, if
f(i)
halts, theinvertHalt
will hang (i.e., wouldn't halt), and iff(i)
hangs, theinvertHalt
will halt. - Let us consider the composition of the two functions:
bool unknown(input i) {
auto a = duplicator(i) // a = {i, i}
auto b = doesItHalt(a) // does i(i) halt?
auto c = invertHalt(b) // hangs if i(i) halts and vice versa.
}
- Will
unknown(unknown)
halt? What shoulddoesItHalt({unknown, unknown})
return? - Let us suppose it will return
true
. Then, it means thatdoesItHalt({unknown, unknown})
returnedfalse
becauseinvertHalt(b)
would've hung otherwise. Therefore, this contradicts our supposition thatdoesItHalt({unknown, unknown})
returnstrue
. - Let us suppose it will return
false
. Then, it means thatdoesItHalt({unknown, unknown})
would returntrue
becauseinvertHalt
wouldn't hang otherwise. Therefore, this contradicts our supposition thatdoesItHalt({unknown, unknown})
returnsfalse
. - Therefore,
unknown
cannot hang nor halt; therefore, no suchdoesItHalt
can exist.