Addition A definition of the 2-ary function \operatorname{Add}, to compute the sum of its arguments, can be obtained using the primitive recursion operator \rho. To this end, the well-known equations :\begin{align} 0 + y &= y, \\ S(x) + y &= S(x+y) \end{align} are "rephrased in primitive recursive function terminology": In the definition of \rho(g, h), the first equation suggests to choose g = P_1^1 to obtain \operatorname{Add}(0, y) = g(y) = y; the second equation suggests to choose h = S \circ P_2^3 to obtain \operatorname{Add}(S(x), y) = h(x, \operatorname{Add}(x, y), y) = (S \circ P_2^3)(x, \operatorname{Add}(x, y), y) = S(\operatorname{Add}(x, y)). Therefore, the addition function can be defined as \operatorname{Add} = \rho(P_1^1, S \circ P_2^3). As a computation example, :\begin{align} \operatorname{Add}(1, 7) &= \rho(P_1^1, S \circ P_2^3) (S(0), 7) && \text{ by Def. } \operatorname{Add}, S \\ &= (S \circ P_2^3)(0, \operatorname{Add}(0, 7), 7) && \text{ by case } \rho(g, h) (S(...), ...) \\ &= S(\operatorname{Add}(0, 7)) && \text{ by Def. } \circ, P_2^3 \\ &= S(\rho(P_1^1, S \circ P_2^3) (0, 7)) && \text{ by Def. } \operatorname{Add} \\ &= S(P_1^1(7)) && \text{ by case } \rho(g, h) (0,...) \\ &= S(7) && \text{ by Def. } P_1^1 \\ &= 8 && \text{ by Def. } S. \\ \end{align}
Doubling Given \operatorname{Add}, the 1-ary function \operatorname{Add} \circ (P_1^1, P_1^1) doubles its argument, (\operatorname{Add} \circ (P_1^1, P_1^1))(x) = \operatorname{Add}(x, x) = x + x.
Multiplication In a similar way as addition, multiplication can be defined by \operatorname{Mul} = \rho(C_0^1, \operatorname{Add} \circ(P_2^3, P_3^3)). This reproduces the well-known multiplication equations: :\begin{align} \operatorname{Mul}(0, y) &= \rho(C_0^1, \operatorname{Add} \circ(P_2^3, P_3^3)) (0, y) && \text{ by Def. } \operatorname{Mul} \\ &= C_0^1(y) && \text{ by case } \rho(g, h) (0, ...) \\ &= 0 && \text{ by Def. } C_0^1. \end{align} and :\begin{align} \operatorname{Mul}(S(x), y) &= \rho(C_0^1, \operatorname{Add} \circ(P_2^3, P_3^3)) (S(x),y) && \text{ by Def. } \operatorname{Mul} \\ &= (\operatorname{Add} \circ(P_2^3 ,P_3^3)) (x, \operatorname{Mul}(x, y), y) && \text{ by case } \rho(g, h) (S(...), ...) \\ &= \operatorname{Add}(\operatorname{Mul}(x, y), y) && \text{ by Def. } \circ, P_2^3, P_3^3 \\ &= \operatorname{Mul}(x, y) + y && \text{ by property of } \operatorname{Add}. \end{align}
Predecessor The predecessor function acts as the "opposite" of the successor function and is recursively defined by the rules \operatorname{Pred}(0) = 0 and \operatorname{Pred}(S(n)) = n. A primitive recursive definition is \operatorname{Pred} = \rho(C_0^0, P_1^2). As a computation example, :\begin{align} \operatorname{Pred}(8) &= \rho(C_0^0, P_1^2) (S(7)) && \text{ by Def. } \operatorname{Pred}, S \\ &= P_1^2(7, \operatorname{Pred}(7)) && \text{ by case } \rho(g, h) (S(...), ...) \\ &= 7 && \text{ by Def. } P_1^2. \end{align}
Truncated subtraction The limited subtraction function (also called "
monus", and denoted "\mathbin{\dot{-}}") is definable from the predecessor function. It satisfies the equations :\begin{align} y \mathbin{\dot{-}} 0 &= y, \\ y \mathbin{\dot{-}} S(x) &= \operatorname{Pred}(y \mathbin{\dot{-}} x). \end{align} Since the recursion runs over the second argument, we begin with a primitive recursive definition of the reversed subtraction, \operatorname{RSub}(y, x) = x \mathbin{\dot{-}} y. Its recursion then runs over the first argument, so its primitive recursive definition can be obtained, similar to addition, as \operatorname{RSub} = \rho(P_1^1, \operatorname{Pred} \circ P_2^3). To get rid of the reversed argument order, then define \operatorname{Sub} = \operatorname{RSub} \circ (P_2^2, P_1^2). As a computation example, :\begin{align} \operatorname{Sub}(8, 1) &= (\operatorname{RSub} \circ (P_2^2, P_1^2)) (8, 1) && \text{ by Def. } \operatorname{Sub} \\ &= \operatorname{RSub}(1, 8) && \text{ by Def. } \circ, P_2^2, P_1^2 \\ &= \rho(P_1^1, \operatorname{Pred} \circ P_2^3) (S(0), 8) && \text{ by Def. } \operatorname{RSub}, S \\ &= (\operatorname{Pred} \circ P_2^3) (0, \operatorname{RSub}(0, 8), 8) && \text{ by case } \rho(g, h) (S(...), ...) \\ &= \operatorname{Pred}(\operatorname{RSub}(0, 8)) && \text{ by Def. } \circ, P_2^3 \\ &= \operatorname{Pred}(\rho(P_1^1, \operatorname{Pred} \circ P_2^3) (0, 8)) && \text{ by Def. } \operatorname{RSub} \\ &= \operatorname{Pred}(P_1^1(8)) && \text{ by case } \rho(g, h) (0, ...) \\ &= \operatorname{Pred}(8) && \text{ by Def. } P_1^1 \\ &= 7 && \text{ by property of } \operatorname{Pred}. \end{align}
Converting predicates to numeric functions In some settings, it is natural to consider primitive recursive functions that take as inputs tuples that mix numbers with
truth values (that is, t for true, and f for false), or that produce truth values as outputs. This can be accomplished by identifying the truth values with numbers in any fixed manner. For example, it is common to identify the truth value t with the number 1, and the truth value f with the number 0. Once this identification has been made, the
characteristic function of a set A, which always returns 1 or 0, can be viewed as a predicate that tells whether a number is in the set A. Such an identification of predicates with numeric functions will be assumed for the remainder of this article.
Predicate "Is zero" As an example for a primitive recursive predicate, the 1-ary function \operatorname{IsZero} shall be defined such that \operatorname{IsZero}(x) = 1 if x = 0, and \operatorname{IsZero}(x) = 0 otherwise. This can be achieved by defining \operatorname{IsZero} = \rho(C_1^0, C_0^2). Then \operatorname{IsZero}(0) = \rho(C_1^0, C_0^2)(0) = C_1^0() = 1, and e.g. \operatorname{IsZero}(8) = \rho(C_1^0, C_0^2)(S(7)) = C_0^2(7, \operatorname{IsZero}(7)) = 0.
Predicate "Less or equal" Using the property x \leq y \iff x \mathbin{\dot{-}} y = 0, the 2-ary function \operatorname{Leq} can be defined by \operatorname{Leq} = \operatorname{IsZero} \circ \operatorname{Sub}. Then \operatorname{Leq}(x, y) = 1 if x \leq y, and \operatorname{Leq}(x, y) = 0 otherwise. As a computation example, :\begin{align} \operatorname{Leq}(8, 3) &= \operatorname{IsZero}(\operatorname{Sub}(8, 3)) && \text{ by Def. } \operatorname{Leq} \\ &= \operatorname{IsZero}(5) && \text{ by property of } \operatorname{Sub} \\ &= 0 && \text{ by property of } \operatorname{IsZero} \\ \end{align}
Predicate "Greater or equal" Once a definition of \operatorname{Leq} is obtained, the converse predicate can be defined as \operatorname{Geq} = \operatorname{Leq} \circ (P_2^2, P_1^2). Then, \operatorname{Geq}(x, y) = \operatorname{Leq}(y, x) is true (more precisely: has value 1) if and only if x \geq y.
If-then-else The 3-ary if-then-else operator known from programming languages can be defined by \operatorname{If} = \rho(P_2^2, P_3^4). Then, for arbitrary x, :\begin{align} \operatorname{If}(S(x), y, z) &= \rho(P_2^2, P_3^4) (S(x), y, z) && \text{ by Def. } \operatorname{If} \\ &= P_3^4(x, \operatorname{If}(x, y, z), y, z) && \text{ by case } \rho(S(...), ...) \\ &= y && \text{ by Def. } P_3^4 \end{align} and :\begin{align} \operatorname{If}(0, y, z) &= \rho(P_2^2, P_3^4) (0, y, z) && \text{ by Def. } \operatorname{If} \\ &= P_2^2(y, z) && \text{ by case } \rho(0, ...) \\ &= z && \text{ by Def. } P_2^2. \end{align} That is, \operatorname{If}(x, y, z) returns the then-part (y) if the if-part (x) is true, and the else-part (z) otherwise.
Junctors Based on the \operatorname{If} function, it is easy to define logical junctors. For example, defining \operatorname{And} = \operatorname{If} \circ (P_1^2, P_2^2, C_0^2), one obtains \operatorname{And}(x, y) = \operatorname{If}(x, y, 0), that is, \operatorname{And}(x, y) is true
if and only if both x and y are true (
logical conjunction of x and y). Similarly, \operatorname{Or} = \operatorname{If} \circ (P_1^2, C_1^2, P_2^2) and \operatorname{Not} = \operatorname{If} \circ (P_1^1, C_0^1, C_1^1) lead to appropriate definitions of
disjunction and
negation: \operatorname{Or}(x, y) = \operatorname{If}(x, 1, y) and \operatorname{Not}(x) = \operatorname{If}(x, 0, 1).
Equality predicate Using the above functions \operatorname{Leq}, \operatorname{Geq} and \operatorname{And}, the definition \operatorname{Eq} = \operatorname{And} \circ (\operatorname{Leq}, \operatorname{Geq}) implements the equality predicate. In fact, \operatorname{Eq}(x, y) = \operatorname{And}(\operatorname{Leq}(x, y), \operatorname{Geq}(x, y)) is true if and only if x equals y. Similarly, the definition \operatorname{Lt} = \operatorname{Not} \circ \operatorname{Geq} implements the predicate "less-than", and \operatorname{Gt} = \operatorname{Not} \circ \operatorname{Leq} implements "greater-than".
Other operations on natural numbers Exponentiation and
primality testing are primitive recursive. Given primitive recursive functions e, f, g, and h, a function that returns the value of g when e \leq f and the value of h otherwise is primitive recursive.
Operations on integers and rational numbers By using
Gödel numberings, the primitive recursive functions can be extended to operate on other objects such as integers and
rational numbers. If integers are encoded by Gödel numbers in a standard way, the arithmetic operations including addition, subtraction, and multiplication are all primitive recursive. Similarly, if the rationals are represented by Gödel numbers then the
field operations are all primitive recursive.
Some common primitive recursive functions The following examples and definitions are from . Many appear with proofs. Most also appear with similar names, either as proofs or as examples, in they add the logarithm lo(x, y) or lg(x, y) depending on the exact derivation. In the following the mark " ' ", e.g. a', is the primitive mark meaning "the successor of", usually thought of as " +1", e.g. a +1 =def a'. The functions 16–20 and #G are of particular interest with respect to converting primitive recursive predicates to, and extracting them from, their "arithmetical" form expressed as
Gödel numbers. :# Addition: a+b :# Multiplication: a×b :# Exponentiation: ab :# Factorial a! : 0! = 1, a'! = a!×a' :# pred(a): (Predecessor or decrement): If a > 0 then a−1 else 0 :# Proper subtraction a ∸ b: If a ≥ b then a−b else 0 :# Minimum(a1, ... an) :# Maximum(a1, ... an) :# Absolute difference: | a−b | =def (a ∸ b) + (b ∸ a) :# ~sg(a): NOT[signum(a)]: If a=0 then 1 else 0 :# sg(a): signum(a): If a=0 then 0 else 1 :# a | b: (a divides b): If b=k×a for some k then 0 else 1 :# Remainder(a, b): the leftover if b does not divide a "evenly". Also called MOD(a, b) :# a = b: sg | a − b | (Kleene's convention was to represent
true by 0 and
false by 1; presently, especially in computers, the most common convention is the reverse, namely to represent
true by 1 and
false by 0, which amounts to changing sg into ~sg here and in the next item) :# a def a>1 & NOT(Exists c)1 [ c|a ] :# pi: the i+1th prime number :# (a)i: exponent of pi in a: the unique x such that pix|a & NOT(pix'|a) :# lh(a): the "length" or number of non-vanishing exponents in a :# lo(a, b): (logarithm of a to base b): If a, b > 1 then the greatest x such that bx | a else 0 :
In the following, the abbreviation x =def x1, ... xn; subscripts may be applied if the meaning requires. • #A: A function φ definable explicitly from functions Ψ and constants q1, ... qn is primitive recursive in Ψ. • #B: The finite sum Σy ψ(
x, y) and product Πyψ(
x, y) are primitive recursive in ψ. • #C: A
predicate P obtained by substituting functions χ1,..., χm for the respective variables of a predicate Q is primitive recursive in χ1,..., χm, Q. • #D: The following
predicates are primitive recursive in Q and R: ::* NOT_Q(
x) . ::* Q OR R: Q(
x) V R(
x), ::* Q AND R: Q(
x) & R(
x), ::* Q IMPLIES R: Q(
x) → R(
x) ::* Q is equivalent to R: Q(
x) ≡ R(
x) • #E: The following
predicates are primitive recursive in the
predicate R: ::* (Ey)y R(
x, y) where (Ey)y denotes "there exists at least one y that is less than z such that" ::* (y)y R(
x, y) where (y)y denotes "for all y less than z it is true that" ::* μyy R(
x, y). The operator μyy R(
x, y) is a
bounded form of the so-called minimization- or
mu-operator: Defined as "the least value of y less than z such that R(
x, y) is true; or z if there is no such value." • #F: Definition by cases: The function defined thus, where Q1, ..., Qm are mutually exclusive
predicates (or "ψ(
x) shall have the value given by the first clause that applies), is primitive recursive in φ1, ..., Q1, ... Qm: :: φ(
x) = ::* φ1(
x) if Q1(
x) is true, ::* . . . . . . . . . . . . . . . . . . . ::* φm(
x) if Qm(
x) is true ::* φm+1(
x) otherwise • #G: If φ satisfies the equation: :: φ(y,
x) = χ(y, COURSE-φ(y; x2, ... xn ), x2, ... xn then φ is primitive recursive in χ. The value COURSE-φ(y;
x2 to n ) of the course-of-values function encodes the sequence of values φ(0,
x2 to n), ..., φ(y-1,
x2 to n) of the original function. == Relationship to recursive functions ==