10

To my knowledge, halting problem asks if there exists a program that decides whether a program being tested, given some input data (no matter what program it is, or what input data we give) will terminate or not. The answer to this problem is 'no'. In other words, there is no 'single' program that can verify it for all possible pairs (some algorithm, some input data).

But it doesn't mean we can't decide if particular program X will terminate or not.

I can't comment other answers yet, but one of them brought my attention:

In practical terms, it is important because it allows you to tell your ignorant bosses "what you're asking is mathematically impossible".

Maybe you can tell me what that person meant? In my scenario, my ignorant boss can ask me to verify (actually, prove or disprove) if my program (that's a particular program) will terminate or not. And of course there are pairs (algorithm, input data) that can be proven to terminate (or never terminate).

The question is - can I prove it for every such pair (program, input data) separately? Even if the answer is yes, then there's a problem - there can be infinitely many 'input data'. So it's quite natural to ask - can I prove, for every algorithm, that this algorithm will terminate (or the opposite), no matter what input data I provide?

user4205580
  • 273
  • 2
  • 10

3 Answers3

7

No, you cant prove this for every algorithm (Turing machine). This becomes a question about the nature of proofs rather than a question about computation.

Consider the following Turing machine $M(x)$: check if there exists a proof for the statement $\forall x \hspace{1mm} M(x)$ halts, of length $\le |x|$ (for explanation on the self reference, see Klenee's recursion theorem). If such proof is found, get into an infinite loop (otherwise halt).

Clearly you cant prove $M(x)$ halts for all $x$, since if you can find a proof of length $p$, it wont halt for all inputs of size $\ge p$. In addition, you cant prove $M(x)$ doesn't halt for some $x$, since this would mean there exists a proof for the halting of $M$ on all inputs (contradiction). The situation here is, that if our axiom system is consistent, then $M(x)$ halts for all $x$, but you cant prove it (meaning you can prove in your theory $T$ that if $T$ is consistent then $\forall x \hspace{1mm} M(x)$ halts, but you cant prove it halts without this assumption, unless your system is inconsistent).

Ariel
  • 13,614
  • 1
  • 22
  • 39
3

For one specific program, sure I can prove that the program will halt on all inputs: my program has "halt" as its first instruction.

Another example: I can have a specific program that is a Turing machine simulator (i.e. a universal Turing machine). It interprets its input as a description of a Turing machine, and the simulator simulates the machine running on a blank tape. So the simulator will stop if the machine being input stops, and will run for ever if the machine being input runs for ever. (If the input is not in the correct format to describe a Turing machine, the simulator stops.)

We know it is impossible to decide whether an arbitrary Turing machine halts when started on a blank tape. So for my specific simulator machine, there is no algorithm to decide what it does on arbitrary input.

I don't know if these two examples help.

Surely in many problem domains it is reasonable to be able to prove that specific programs terminate. If my program multiplies two matrices I would expect to be able to prove that there is no way it can go on for ever.

user42735
  • 31
  • 1
2

I can at least clarify the hypothetical question the imaginary boss is presumed to ask which lead to this answer:

Can you design a program that takes this other program/template/database query/ etc. which always determines whether it terminates/raises an exception/runs out of memory?

The point of the impossibility proof is that such a task cannot be accomplished. Of course it's common knowledge today that such a task can be approximated quite well, i.e. it is possible to give an algorithm that determines whether a program is going to raise an exception, but sometimes answers "might raise an exception" even though the program doesn't do it in practice.

Some of these are harder to do in practice as well, e.g. termination is quite harder to prove than the absence of null pointer exception for "real world programs" (but equivalent in theory).

cody
  • 8,427
  • 33
  • 64