Mathematics and logic
Halting problem
The halting problem is a fundamental decision problem in computability theory that asks whether a given program will eventually halt or run forever on a specific input. It is known for demonstrating that no general algorithm can solve this problem for all possible program–input pairs. The problem was proven undecidable by Alan Turing in the 1930s using a diagonalization argument on a universal Turing machine. This result shows that some mathematically definable functions are not computable. Today, the halting problem remains a cornerstone of theoretical computer science, influencing areas like program verification and complexity theory.
Definition and Core Idea
In computability theory, the halting problem is the decision problem of, given an arbitrary computer program and an input, determining whether said program will eventually finish running and halt, or will continue to run forever.
For example, in pseudocode, the program while (true) continue never halts; rather, it goes on forever in an infinite loop.
By contrast, print "Hello, world!" halts immediately after printing.
For any specific program and input, the answer is simply 'halts' or 'does not halt'.
The halting problem is a decision problem about properties of computer programs on a fixed Turing-complete model of computation.
A key part of the formal statement of the problem is a mathematical definition of a computer and program, usually via a Turing machine.
The model of computation includes all programs in Turing-equivalent programming languages.
Proof of Undecidability
The halting problem is undecidable, meaning no general algorithm exists that can correctly solve the problem for all possible program–input pairs.
The proof shows that for any program f that might determine whether programs halt, a 'pathological' program g exists for which f makes an incorrect determination.
The proof of the halting problem's undecidability uses a diagonalization technique applied to a universal Turing machine.
The construction of the function g can be visualized using the main diagonal of a two-dimensional array where f(i,j) is placed at column i, row j.
If the array has a 0 at position (i,i), then g(i) is 0. Otherwise, g(i) is undefined.
The contradiction arises from the fact that there is some column e of the array corresponding to g itself.
If g(e) is defined (g(e) = 0), then the program e halts on input e, thus f(e,e) = 1. But g(e) = 0 only when f(e,e) = 0, contradicting f(e,e) = 1.
If g(e) is not defined, then program e does not halt on input e, thus f(e,e) = 0, which leads to g(e) = 0 under g's construction. This contradicts the assumption that g(e) is not defined.
Implications and Applications
The halting problem demonstrates that some functions are mathematically definable but not computable.
In computability theory and computational complexity theory, a reduction is an algorithm for transforming one computational problem into another problem.
A sufficiently efficient reduction from one problem to another may be used to show that the second problem is at least as difficult as the first.
There are two main types of reductions used in computability theory.
Some infinite loops can be quite useful. For instance, event loops are typically coded as infinite loops.
In total functional programming languages these are often encoded using corecursion, as functions that process and produce infinite coinductive data types such as streams.
In hard real-time computing, subroutines must not only finish, but finish before a given deadline.
In order to meet these requirements, programmers apply the rule of least power and use restricted styles, not quite fully Turing-complete, that make it easy to prove that the resulting subroutines finish before the given deadline.
Interpreters are programs that simulate the execution of programs whatever source code they are given.
More
The essence of Turing's proof is that any such algorithm can be made to produce contradictory output and therefore cannot be correct.
The halting problem requires a decision procedure that works for all programs and inputs.
Related
Written by 1x0 AI from public sources. Checked 2 December 2026.
Text: CC BY-SA 4.0, free to reuse and adapt with a link to this page, under the same licence. Photos and illustrations: as credited.