The Primitive Recursive Functions
The Primitive Recursive Functions
The Primitive Recursive Functions
Models of Computation
Bengt Nordstrom,
Department of Computing Science,
Chalmers and University of Goteborg,
Goteborg, Sweden
1
1.1
Models of Computation
Models of Computation
z PRF0
s PRF1
pn (i) PRFn+1 if i n
comp(g, f1 , . . . , fm ) PRFn if g PRFm , fi PRFn , 1 i m
rec(g, h) PRFn+1 if g PRFn , h PRFn+2
Figure 1: Informal syntax
We will give the model by giving a precise description of the syntax and semantics
of the primitive recursive functions.
Let PRFn express the set of all primitive recursive functions of arity n (i.e.
with n arguments). We assume that n N, i.e. we allow the number of arguments to be 0. The intutition is that each program p PRFn denotes a primitive
recursive function f in the set Nn N. We will construct the class by using the
five simple program forming operations showed in figure 1. The simple programs
are z, s och pn (i) and the composite programs are comp and rec. The program
z (which takes no argument) computes always to 0. The program s stands for
the successor function, it adds 1 to its input. The program pn (i) computes to its
(i + 1)-th argument. The program comp(g, f1 , . . . fn ) is a generalization of the
usual functional composition g f . Finally, the program rec(g, h) expresses the
scheme for primitive recursion. The intuitive semantics is shown in figure 7. We
z[] = 0
s[j] = j + 1
pn (i)[j0 , . . . , jn ] = ji
comp(g, f1 , . . . , fm )[j1 , . . . , jn ] = g[f1 [j1 , . . . , jn ], . . . , fm [j1 , . . . , jn ]]
rec(g, h)[0, j1 , . . . , jn ] = g[j1 , . . . , jn ]
rec(g, h)[y + 1, j1 , . . . , jn ] = h[y, rec(g, h)[y, j1 , . . . , jn ], j1 , . . . , jn ]
Figure 2: Informal semantics
notice that we have given the semantics of the programs by telling what value the
programs get when we apply them to an arbitrary input (which in this case always
is a list of natural numbers).
Notice that there are no variables in this model. Instead the projection opera-
Models of Computation
Models of Computation
tion is used. It takes some time to get used to write programs without variables,
we will show some examples in the following section. It can be skipped in the
first reading of this chapter.
1.1.1
Models of Computation
Models of Computation
Models of Computation
1.2
Models of Computation
The syntax and semantics which was given before were not very precise. We
have to remove the three dots which we have in the description of the syntax and
semantics. It is always a sign of imprecision to have the dots, different people
interpret them in different ways.
Let us first define the set Am of vectors of lenght m by the following inductive
definition:
nil A0
a.as An+1 if a A and as An
Now, we can give a more precise definition of the abstract syntax of PRFn ,
we give it in figure 6.
z PRF0
s PRF1
pn (i) PRFn+1 if i n
comp(g, f s) PRFn if g PRFm , f s (PRFn )m
rec(g, h) PRFn+1 if g PRFn , h PRFn+2
Figure 3: Abstract syntax of PRF
1.3
Operational semantics
Models of Computation
Models of Computation
z[] 0
s[n.nil] n + 1
nth(n, i, t) = v
pn (i)[t] v
f s[t] = ns
g[ns] v
comp(g, f s)[t] v
g[t] v
rec(g, h)[0.t] v
rec(g, h)[n.t] i
h[n.i.t] v
rec(g, h)[(n + 1).t] v
f [t] k
f s[t] = ks
(f.f s)[t] = k.ks
Models of Computation
Models of Computation
Notice, that we are using primitive recursion in the meta-language. It should not
be confused with the operator for primitive recursion which we are formalizing in
PRFn !
1.4
Denotational semantics
if p PRFn
Models of Computation
Models of Computation
1.6
Models of Computation
Models of Computation
=3
33
Models of Computation
Models of Computation
33
Notice that already 33 is much bigger than the number of atoms in the universe
12
33
(since 33 = 37 625 597 484 987 > 1010 = 101 000 000 000 000 1070 ).
Now, if 3 3 is difficult to grasp, what about 3 3?
3 3 = 3 (3 3)
= 3 3
33
with 3
33
terms
where we have 7 625 597 484 987 exponentiations in the number of terms.
So if we had 4 (instead of 7 625 597 484 987) number of exponentiations in
the number of terms we could not even write down the expression in the form
3 3 if we used one term for each atom in the universe. And we know
that already 3 3 3 (which is 3 3) was enormous! But as we all know
most numbers are much bigger than 3 3.
We can continue this process and define a whole series of operations , ,
, , . . . . We can now introduce an arbitrary number of operations, one for each
natural number n. We let for instance 5 stand for , so for each k we use
the notation k for the operation with k arrows. Notice that k is not a function
applied to the argument k ! It is only a schematic notation for k repetitions of the
symbol .
We have that
m k+1 n = m k k m
|
{z
}
n terms
It is clear that all these operations are primitive recursive functions. If we have a
definition of the k -operation then we can express the k+1 -operation by primitive
recursion:
k+1 (m, 0) = 1
k+1 (m, s(n)) =k (m, k+1 (m, n))
Notice here that we have a number of operations 1 , 2 , 3 , 4 , 5 , 6 , . . . which all
have a uniform definition. One operation is defined from the previous operation
by using primitive recursion. What happens if we try to look at k as an argument
to the k-th operation? So we will try to look at k as a function applied to the
number k yielding the k-th operation. Let us consider the ternary function which
is defined such that (k, m, n) is equal to the value of k (m, n), for each k, m and
n:
(0, m, n) = mul(m, n)
(k + 1, m, 0) = 1
(k + 1, m, s(n)) =(k, m, (k + 1, m, n))
Models of Computation
Models of Computation
1.7
If we want to extend PRF to the class of all recursive functions we extend it with
an operator min which expresses linear search. We define a new class of functions RFn , the set of all recursive functions of arity n by extending the inductive
definition of the abstract syntax of PRF with one clause:
z RF0
s RF1
pn (i) RFn+1 if i n
comp(g, f s) RFn if g RFm , f s (RFn )m
rec(g, h) RFn+1 if g RFn , h RFn+2
min(f ) RFn if f RFn+1
Figure 6: Abstract syntax of RF
min(g)[j1 , . . . , jn ] = k
if k is the least integer for which g[k, j1 , . . . , jn ] = 0
Figure 7: Informal semantics
Models of Computation
Models of Computation
a function value which is 0. This computation does not have to terminate, since
there is not necessarily a value of the first argument for which the function is 0.
The precise description of the operational semantics is obtained by adding two
clauses to the operational semantics of PRF:
f [0.t] 0
min(f )[t] 0
min(shiftf )[t] i
min(f )[t] i + 1
1.8
Historical remarks
The first to write the ordinary primitive recursive definitions of addition and multiplication was probably Hermann Grassmann [3] . It was later rediscovered by
Dedekind [2]. The class of primitive recursive functions were known by Hilbert
[4] in 1926. At that time his student Wilhelm Ackermann had defined the ternary
-function and showed that it is not primitive recursive. This result was not published until 1928 [1].
The founder of the theory of primitive recursive functions was Rozsa Peter
[6], who also coined the term primitive recursive. She simplified Ackermanns
formulation (together with Raphael Robinson) to a function of two arguments:
A(0, y) =y + 1
A(x + 1, 0) =A(x, 1)
A(x + 1, y + 1) =A(x, A(x + 1, y))
which is now the traditional formulation in modern textbooks. This formulation
may look simpler than the original, but is it more understandable?
The notation originates from Knuth in 1976 [5].
References
[1] W. Ackermann. Zum Hilbertschen Aufbau der reellen Zahlen. Mathematical
Annals, 99:118133, 1928.
Models of Computation
Models of Computation
[2] Richard Dedekind. Was sind und was sollen die Zahlen? F. Vieweg, Braunschweig, 1888. Translated by W.W. Beman and W. Ewald in Ewald (1996):
787832.
[3] Hermann Grassmann. Lehrbuch der Mathematik fur hohere Lehranstalten.
Enslin, 1861.