In computability theory, the halting problem is the problem of determining, from a description of an arbitrary computer program and an input, whether the program will finish running (i.e., halt) or continue to run forever.

Alan Turing proved in 1936 that a general algorithm to solve the halting problem for all possible program-input pairs cannot exist. A key part of the proof was a mathematical definition of a computer and program, which became known as a Turing machine; the halting problem is undecidable over Turing machines. It is one of the first examples of a decision problem.

Proof concept

The proof that the halting problem is not solvable is a proof by contradiction. To illustrate the concept of the proof, suppose that there exists a total computable function halts(f) that returns true if the subroutine f halts (when run with no inputs) and returns false otherwise. Now consider the following subroutine:

def g():
    if halts(g):
        loop_forever()

halts(g) must either return true or false, because halts was assumed to be total. If halts(g) returns true, then g will call loop_forever and never halt, which is a contradiction. If halts(g) returns false, then g will halt, because it will not call loop_forever; this is also a contradiction. Overall, halts(g)can not return a truth value that is consistent with whether g halts. Therefore, the initial assumption that halts is a total computable function must be false.

Sketch of proof

The concept above shows the general method of the proof; this section will present additional details. The overall goal is to show that there is no total computable function that decides whether an arbitrary program i halts on arbitrary input x; that is, the following function h is not computable (Penrose 1990, p. 57–63):

h(i,x)={begin{cases}1&{text{if }}{text{  program }}i{text{ halts on input }}x,&{text{otherwise.}}end{cases}}

Here program i refers to the i th program in an enumeration of all the programs of a fixed Turing-complete model of computation.

f(i,j) i
1 2 3 4 5 6
j 1 1 0 0 1 0 1
2 0 0 0 1 0 0
3 0 1 0 1 0 1
4 1 0 0 1 0 0
5 0 0 0 1 1 1
6 1 1 0 0 1 0
               
  f(i,i) 1 0 0 1 1 0
  g(i) U 0 0 U U 0

 

Possible values for a total computable functionf arranged in a 2D array. The orange cells are the diagonal. The values of f(i,i) and g(i) are shown at the bottom; U indicates that the function g is undefined for a particular input value.

The proof proceeds by directly establishing that no total computable function with two arguments can be the required function h. As in the sketch of the concept, given any total computable binary function f, the following partial function g is also computable by some program e:

g(i)={begin{cases}0&{text{if }}f(i,i)=0,{text{undefined}}&{text{otherwise.}}end{cases}}

The verification that g is computable relies on the following constructs (or their equivalents):

  • computable subprograms (the program that computes f is a subprogram in program e),
  • duplication of values (program e computes the inputs i,i for f from the input i for g),
  • conditional branching (program e selects between two results depending on the value it computes for f(i,i)),
  • not producing a defined result (for example, by looping forever),
  • returning a value of 0.

The following pseudocode illustrates a straightforward way to compute g:

procedure compute_g(i):
    if f(i,i) == 0 then
        return 0
    else
        loop forever

Because g is partial computable, there must be a program e that computes g, by the assumption that the model of computation is Turing-complete. This program is one of all the programs on which the halting function h is defined. The next step of the proof shows that h(e,e) will not have the same value as f(e,e).

It follows from the definition of g that exactly one of the following two cases must hold:

  • f(e,e) = 0 and so g(e) = 0. In this case h(e,e) = 1, because program e halts on input e.
  • f(e,e) ≠ 0 and so g(e) is undefined. In this case h(e,e) = 0, because program e does not halt on input e.

In either case, f cannot be the same function as h. Because f was an arbitrary total computable function with two arguments, all such functions must differ from h.

You have no rights to post comments