20

From my understanding of the proof that halting problem is not computable, this problem is not computable because if we have a program P(x) which computes if the program x halts or not, we got a paradox when giving P as an input to the same P, having: P(P), trying to decide if P halts or not using P itself.

So my question is: is halting problem computable by program P for all other programs used as input but P itself? In other words: is halting problem not computable only in this special case or the proof is more general and I'm missing something?

ela
  • 315
  • 2
  • 7

6 Answers6

22

is halting problem computable by program P for all other programs used as input but P itself?

No. Consider the infinite sequence of programs $P_1, P_2, \dots$, where $P_i$ is "Move the head $i$ squares to the right, then $i$ squares to the left, then do exactly what $P$ would do." Every one of these programs produces exactly the same output as $P$ for every input (including looping forever if $P$ loops forever), but they're all different programs.

And you can't get around this by only requiring $P$ to work on programs that aren't functionally equivalent to itself, since that property is also undecidable. Perhaps the problem would be decidable when restricted to those instances (though I suspect it wouldn't) but the set of instances is undecidable, so you couldn't actually perform the restriction.

David Richerby
  • 82,470
  • 26
  • 145
  • 239
11

If $f$ is any computable function, then $g$, defined as

$$ g(n) = \begin{cases} f(n) & \mbox{if } n \neq k \\ v & \mbox{otherwise} \end{cases} $$

is also computable, for any choice of $k,v$.

Basically, if you have a program $P'$ which computes $g(n)$ for all $n$'s except for $n=k$, you can "fix" that case (e.g. using an if then else) and obtain another program $P$ which computes $g(n)$ for all $n$.

Hence, if you could compute the halting function "except for one case", you could also compute the halting function (with no exceptions). From that, you can obtain a contradiction as usual.

Conclusion: no, you can't decide the halting problem "except one case" (nor "except finitely many cases").

chi
  • 14,704
  • 1
  • 31
  • 40
6

There are algorithms to show that certain classes of programs do or don't halt. For example,

  • It is possible to determine algorithmically whether a program that models a finite-state machine halts.
  • It is possible to determine arithmetically whether a linear-bounded turing machine halts
  • If you know what complexity class a program is in, then you know that the program halts for finite inputs.

While there's no algorithm to determine if an arbitrary program halts, a majority of code was designed either to halt (like most subroutines) or not halt (like an infinite loop to handle events), and it's possible to algorithmically to determine which is which. In other words, you can have an algorithm that answers either "halts", "doesn't halt", or "I dunno", and such an algorithm can be designed to cover enough programs that it would be useful.

4

Proofs by contradiction don't have to be exhaustive, a single counter-example is enough. The proof of the halting problem being undecidable provides you with one example of P for which the halting property cannot be decided. This proof doesn't state that P is the only such program, in fact, there may exist independent proofs constructing completely different classes of P.

Dmitry Grigoryev
  • 532
  • 3
  • 11
3

The proof is indeed more general: the halting problem is a special case of Rice's theorem, which states

If $\Phi$ is a property of programs that is independent of representation, then it is either always true, always false, or undecidable.

where "independent of representation" means that if $A$ and $B$ are programs that have the same behaviour for all inputs, then $\Phi(A)$ holds iff $\Phi(B)$ holds.

This means in particular that for every input $x$, the set of programs that halt on $x$ is undecidable; you cannot get decidability by reducing the input space.

You can get some results by restricting the space of programs you want to work with, though these restrictions have to be fairly drastic. For example, if you are guaranteed that the program you are given either halts within 100 steps or runs forever, deciding whether it halts becomes easy.

A more complicated case is when you know that the program is at most 100 characters long. Since there are only finitely many programs of that length, there exists some number of steps $N$ that is an upper bound on how long such a program can run if it terminates. However, the function that maps a program length $k$ to a maximum number of steps $BB(k)$ is not computable.

Komi Golov
  • 394
  • 2
  • 9
0

Let R be any recursively enumerable but nonrecursive set. There are infinitely many such sets. Let T be a Turing machine that halts on input k if and only if k is in R. Such a T exists for any recursively enumerable set. It is impossible to write a program which can solve the halting problem for this T. This is because any algorithm to determine if T halts would yield an algorithm for determining membership in R, which is impossible if R is nonrecursive. Since there are infinitely many such R, each of which give different Turing machines, there are infinitely many Turing machines that any attempted halting program P would fail on.

John Coleman
  • 171
  • 1
  • 6