Table of contents |

2 Example primitive recursive function definitions 3 Limitations of the primitive recursive functions 4 Relation to the recursive functions |

Primitive recursive functions take natural numbers or tuples of natural numbers as arguments and produce a natural number. A function which takes *n* arguments is called *n*-ary. The basic primitive recursive functions are given by these axioms:

- The constant function 0 is primitive recursive.
- The
*successor function**S*, which takes one argument and returns the succeeding number as given by the Peano postulates, is primitive recursive. - The
*projection functions**P*_{i}^{n}, which take*n*arguments and return their*i*th argument, are primitive recursive.

*Composition*: Given*f*, a*k*-ary primitive recursive function, and*k**l*-ary primitive recursive functions*g*_{0},...,*g*_{k-1}, the composition of*f*with*g*_{0},...,*g*_{k-1}, i.e. the function*h*(*x*_{0},...,*x*_{l-1}) =*f*(*g*_{0}(*x*_{0},...,*x*_{l-1}),...,*g*_{k-1}(*x*_{0},...,*x*_{l-1})), is primitive recursive.*Primitive recursion*: Given*f*a*k*-ary primitive recursive function and*g*a (*k*+2)-ary primitive recursive function, the (*k*+1)-ary function defined as the primitive recursion of*f*and*g*, i.e. the function*h*where*h*(0,*x*_{0},...,*x*_{k-1}) =*f*(*x*_{0},...,*x*_{k-1}) and*h*(*S*(*n*),*x*_{0},...,*x*_{k-1}) =*g*(*h*(*n*,*x*_{0},...,*x*_{k-1}),*n*,*x*_{0},...,*x*_{k-1}), is primitive recursive.

A function is primitive recursive if it is one of the basic functions above, or can be obtained from one of the basic functions by applying the operations a finite number of times.

;Addition: Intuitively we would like to define addition recursively as:

- add(0,
*x*)=*x* - add(
*n*+1,*x*)=add(*n*,*x*)+1

- add(0,
- In order to fit this into a strict primitive recursive definition, we define:
- add(0,
*x*)=*P*_{0}^{1}(*x*) - add(S(
*n*),*x*)=*S*(*P*_{0}^{3}(add(*n*,*x*),*n*,*x*))

- add(0,
- Note that
*P*_{0}^{1}is simply the identity function; its inclusion is required by the definition of the primitive recursion operator above; it plays the role of*h*. The composition of*S*and*P*_{0}^{3}, which is primitive recursive, plays the role of*g*.

- Intuitively we would like to define predecessor as:
- pred(0)=0
- pred(
*n*+1)=*n*

- To fit this in to a formal primitive recursive definition, we write:
- pred(0)=0
- pred(S(
*n*))=*P*_{1}^{2}(pred(*n*),*n*)

- Now we can define subtraction in a very similar way to how we defined addition.
- sub(0,
*x*)=*P*_{0}^{1}(*x*) - sub(S(
*n*),*x*)=pred(*P*_{0}^{3}(sub(*n*,*x*),*n*,*x*))

- sub(0,
- (Note that for the sake of simplicity, the order of the arguments has been switched from the "standard" definition to fit the requirements of primitive recursion, i.e. sub(
*a*,*b*) corresponds to*b*-*a*. This could easily be rectified using composition with suitable projections.)

Primitive recursive functions tend to correspond very closely with our intuition of what a computable function must be. Certainly the initial set of functions are intuitively computable (in their very simplicity), and the two operations by which one can create new primitive recursive functions are also very straightforward. However the set of primitive recursive functions does not include every possible computable function --- this can be seen with a variant of Cantor's diagonalization argument. This argument provides a computable function which is not primitive recursive. A sketch of the proof is as follows:

The primitive recursive functions can be computably numbered. This numbering is unique on the definitions of functions, though not unique on the actual functions themselves (as every function can have an infinite number of definitions --- consider simply composing by the identity operator). The numbering is computable in the sense that it can be defined under format models of computability such as recursive functions or Turing machines; but an appeal to the Church-Turing thesis is likely sufficient.

Now consider a matrix where the rows are the primitive recursive functions of one argument under this numbering, and the columns are the natural numbers. Then each element (*i*, *j*) correponds to the *i*th unary primitive recursive function being calculated on the number *j*. We can write this as *f*_{i}(*j*).

Now consider the function *g*(*x*)=S(*f*_{x}(*x*)). *g* lies on the diagonal of this matrix and simply adds one to the value it finds. This function is computable (by the above), but clearly no primitive recursive function exists which computes it as it differs from each possible primitive recursive function by at least one value. Thus there must be computable functions which are not primitive recursive.

Note that this argument can be applied to any class of computable (total) functions that can be enumerated in this way. Therefore, any such explicit list of computable (total) functions can never be complete. Note however that the *partial* computable functions (those which need not be defined for all arguments) can be explicitly enumerated, for instance by enumerating Turing machine encodings.

One can also explicitly exhibit a simple 1-ary computable function which is recursively defined for any natural number, but which is not primitive recursive, see Ackermann function.

In order to formalize the full class of computable functions, we must allow for partial functions and introduce an additional operator to the above: the *unbounded search* operator (see Recursive function).