Published May 25, 2022 - By Marco Garosi
The halting problem in the computability theory, that is the problem of deciding whether a given function (and thus a program) ever terminates, is not decidable: this means that a machine cannot tell wether a program will ever halt or not. It may wait for thousands of years, but never know if the program it’s running will terminate in the next few minutes, centuries or never.
The halting problem states that given a function such that:
is a total yet non-recursive function.
The proof is made by contradiction. Let’s suppose that there exists a program (some code) such that:
We can construct program such that:
Function diverges when converges and vice-versa.
On the other hand,.
This is, of course, a contradiction: hence a Turing Machine cannot tell whether a progamm will halt or not on a given input. It can only try and run it for some finite amount of time (even great amounts of time, like the life of the Universe): if the program halts, at some point, then it can tell it halts; if it doesn’t, it can only keep on going. If the program never halts, the machine only runs forever, without ever returning an answer.
This is much like driving on an infinite road and wondering whether you’ll ever run into some cavity in the asphalt. If you’ve run into one, then you can tell you did. If you did not, you can only keep on driving. However, in a finite amount of time, you cannot tell that the infinite road has no holes at all: one hole may be just some kilometers ahead from you — and you wouldn’t know!