Primitive recursion corresponds to for loops: the number of iterations is fixed before the loop starts. The Ackermann function shows that this is not enough to obtain all total computable functions. What is missing is the while loop, or equivalently the unbounded search: try until some condition holds. Adding this operation leads to the class of partial recursive functions, introduced by Kleene in 1936.
8.1 The minimization operator
Let be a partial function. The partial function obtained from by minimization, written
is defined as follows: if and only if
- , and
- for every , and .
If there is no such , then .
The definition describes exactly the result of the following procedure: compute , then , and so on, and return the first for which the value is . The procedure fails to return in two different ways: either all values are defined and non-zero, or some computation does not terminate before a zero has been found.
For a predicate we write for , the least such that .
8.2 Partial recursive functions
The schemes of composition and primitive recursion extend to partial functions, with the convention that an expression is undefined as soon as one of its subexpressions is:
- composition: ;
- primitive recursion: and . In particular, if then for all .
The class of partial recursive functions is the smallest class of partial functions () containing the basic functions , , , and closed under composition, primitive recursion and minimization. A partial recursive function which is total is called a (total) recursive function. A predicate is recursive if its characteristic function is recursive.
The terminology varies: partial recursive is also called partial computable, and recursive is also called computable, the modern usage preferred in the following courses. In Kleene’s original work, the total functions obtained from Herbrand–Gödel systems of equations were called general recursive; Kleene proved that they are exactly the total partial recursive functions.
Every partial recursive function is computable: there is an algorithm which, on input , terminates with output if , and does not terminate otherwise.
By induction on the definition of , as for Proposition 5.4, with one additional case: for minimization, the algorithm runs the computations of one after the other, as described above. In the composition and recursion cases, the algorithm computes the subexpressions in order and does not terminate if one of them does not. A precise version of this proof, for WHILE programs, is given in the lesson LOOP and WHILE programs.
Every primitive recursive function is recursive. The converse fails:
The Ackermann function is recursive.
By the last exercise of the lesson The Ackermann function, the graph is primitive recursive. Hence , and the search terminates since .
This is an instance of a general principle: a total function whose graph is recursive is recursive, by searching for the value.
8.3 Examples
- , since iff .
- With , the function is the square root of if is a perfect square, and is undefined otherwise.
- is the nowhere defined function of . In particular the empty function is partial recursive.
- If is a recursive bijection, its inverse is recursive.
8.4 Regular minimization
Kleene originally defined the total recursive functions using minimization only in the regular case.
A total function is regular if for every there is with .
Minimization applied to a regular total function yields a total function. Let be the smallest class of total functions containing the basic functions and closed under composition, primitive recursion and regular minimization. Every function of is recursive, since regular minimization is a special case of minimization. The converse — every total partial recursive function belongs to — is not obvious: a partial recursive definition of a total function may use partial functions in intermediate steps. It is a consequence of the normal form theorem below.
8.5 Kleene’s normal form
The following theorem, proved in the lesson Equivalence of the models, shows that a single unbounded search suffices to compute any partial recursive function.
There are a primitive recursive predicate for each , and a primitive recursive function , such that for every partial recursive there is with
Informally: codes a program for ; states that codes a complete halting computation of the program on input ; and extracts the output from the computation . Checking that a given number codes a correct halting computation only requires bounded loops, hence is primitive recursive. Only finding the computation requires an unbounded search.
Every total recursive function belongs to the class defined with regular minimization.
If is total, then for every there is with , so the function is regular. Hence is obtained from primitive recursive functions by one regular minimization and one composition.
8.6 Exercises
Show that the recursive predicates are closed under the boolean connectives and bounded quantification, and that the recursive functions are closed under bounded minimization over recursive predicates.
Solution
The total recursive functions contain the primitive recursive functions and are closed under composition and primitive recursion, since these operations preserve totality. The proofs given for primitive recursive predicates and functions in the lesson Primitive recursive functions only use these closure properties, applied to characteristic functions, which are total. They therefore apply verbatim to recursive predicates and functions.
Let be recursive and strictly increasing. Show that its range is a recursive set, and that the function “the least such that ” is recursive.
Solution
Since is strictly increasing, , so , a bounded quantification over a recursive predicate. The function is a minimization of a recursive predicate, which is regular since ; hence is recursive (and even ).
Let for a partial recursive . Is it true that ? Give a proof or a counterexample.
Solution
It is false in general: we always have , but the converse fails when diverges for some smaller than every zero. For example, let . For , and ; for , the search diverges. Then holds for all , but is nowhere defined, since the search for is stuck at .
8.7 Notes and references
The general recursive functions were defined by Gödel in 1934, following a suggestion of Herbrand, through systems of equations. Kleene gave the characterization by minimization and proved the normal form theorem in 1936.
- S. C. Kleene, General recursive functions of natural numbers, Mathematische Annalen 112 (1936), 727–742.
- S. C. Kleene, Introduction to Metamathematics, North-Holland, 1952, chapters XI–XII.