• Keine Ergebnisse gefunden

Primitive Recursive Functions

The class of primitive recursive functions is inductively defined. For this, the basic functions are the following:

1. The0-ary constant function c(0)0 :→N0:7→0.

2. Themonadic constant function c(1)0 :N0→N0:x7→0.

3. Thesuccessor function ν :N0→N0:x7→x+ 1.

4. Theprojection functions π(n)k :Nn0 →N0: (x1, . . . , xn)7→xk, where n≥1 and 1≤k≤n.

Using these functions, more complex primitive recursive functions can be introduced.

1. If g is a k-ary total function andh1, . . . , hk are n-ary total functions, the composition ofg along (h1, . . . , hk) is ann-ary functionf =g(h1, . . . , hk) defined as

f(x) =g(h1(x), . . . , hk(x)), x∈Nn0. (2.3)

2. If g is an n-ary total function and h is an n+ 2-ary total function, the primitive recursion of g alonghis ann+ 1-ary functionf given as

f(x,0) =g(x), x∈Nn0, (2.4)

and

f(x, y+ 1) =h(x, y, f(x, y)), x∈Nn0, y∈N0. (2.5) This function is denoted byf = pr(g, h).

The class of primitive recursive functions is given by the basic functions and those obtained from the basic functions by applying composition and primitive recursion a finite number of times. These functions were first studied by Richard Dedekind.

Proposition 2.8.Each primitive recursive function is total.

Proof. The basic functions are total. Letf =g(h1, . . . , hk) be the composition ofgalong (h1, . . . , hk).

By induction, it can be assumed that the functions g, h1, . . . , hk are total. Then the functionf is also total.

Let f = pr(g, h) be the primitive recursion of g alongh. By induction, suppose that the functions

g andhare total. Then the functionf is total, too. ⊓⊔

Examples 2.9.The dyadic functions of addition and multiplication are primitive recursive.

1. The function f+:N20→N0: (x, y)7→x+y obeys the following scheme of primitive recursion:

a)f+(x,0) =x= idN0(x) =xfor allx∈N0,

b)f+(x, y+ 1) =f+(x, y) + 1 = (ν◦π(3)3 )(x, y, f+(x, y)) for allx, y∈N0. 2. Define the functionf.:N20→N0: (x, y)7→xyinductively as follows:

a)f.(x,0) = 0 for all x∈N0,

b)f.(x, y+ 1) =f.(x, y) +x=f+(x, f.(x, y)) for all x, y∈N0. This leads to the following scheme of primitive recursion:

a)f.(x,0) =c(1)0 (x) for all x∈N0,

b)f.(x, y+ 1) =f+1(3), π3(3))(x, y, f.(x, y)) for all x, y∈N0. ♦ Theorem 2.10.Each primitive recursive function is URM computable.

Proof. First, claim that the basic functions are URM computable.

1. 0-ary constant function: The URM program

P0(0)=A0;S0 giveskP0(0)k0,1=c(0)0 .

2. Unary constant function: The URM program

P0(1)= (S1)1 provideskP0(1)k1,1=c(1)0 .

3. Successor function: The URM program

P+1=A1 yieldskP+1k1,1=ν.

4. Projection functionπk(n)withn≥1 and 1≤k≤n: The URM program Pp(n,k)=R(k; 0); (S1)1;R(0; 1) shows that kPn,kkn,1(n)k .

Second, consider the composition f = g(h1, . . . , hk). By induction, assume that there are normal URM programs Pg andPh1, . . . , Phk such that kPgkk,1 =g and kPhikn,1 =hi, 1 ≤i ≤k. A normal URM program for the composite functionf can be obtained as follows: For each 1≤i≤k,

• copy the values x1, . . . , xn into the registersRn+k+2, . . . , R2n+k+1,

• compute the valuehi(x1, . . . , xn) by using the registersRn+k+2, . . . , R2n+k+j, wherej ≥1,

• store the resulthi(x1, . . . , xn) inRn+i.

Formally, this computation is carried out as follows:

Qi=C(1;n+k+ 2);. . .;C(n,2n+k+ 1); (Phi)[+n+k+ 1];R(n+k+ 2;n+i) (2.6) Afterwards, the values inRn+i are copied intoRi, 1≤i ≤k, and the functiong(h1(x), . . . , hk(x)) is computed. Formally, the overall computation is achieved by the URM program

Pf=Q1;. . .;Qk; (S1)1;. . .; (Sn)n;R(n+ 1; 1);. . .;R(n+k;k);Pg (2.7) givingkPfkn,1=f.

Third, consider the primitive recursion f = pr(g, h). By induction, assume that there are nor-mal URM programs Pg and Ph such that kPgkn,1 = g and kPhkn+2,1 = h. As usual, the registers R1, . . . , Rn+1 contain the input values for the computation off(x, y).

Note that the computation of the function value f(x, y) is accomplished iny+ 1 steps:

• f(x,0) =g(x), and

• for each 1≤i≤y,f(x, i) =h(x, i−1, f(x, i−1)).

For this, the registerRn+2is used as a counter and the URM programs (Pg)[+n+ 3] and (Ph)[+n+ 3]

make only use of the registers Rn+3+j, where j ≥ 0. Formally, the overall computation is given as follows:

Pf =R(n+ 1;n+ 2);

C(1;n+ 4);. . .;C(n,2n+ 3);

(Pg)[+n+ 3]; (2.8)

(R(n+ 4; 2n+ 5);C(1;n+ 4);. . .;C(n+ 1; 2n+ 4); (Ph)[+n+ 3];An+ 1;Sn+ 2)n+ 2;

(S1)1;. . .; (Sn+ 1)n+ 1;

R(n+ 4; 1).

First, the input value y is stored in Rn+2 to serve as a counter, and the input valuesx1, . . . , xn are copied intoRn+4, . . . , R2n+3, respectively. Thenf(x,0) =g(x) is calculated. Afterwards, the following

iteration is performed while the value of Rn+2 is non-zero: Copy x1, . . . , xn into Rn+4, . . . , R2n+3, respectively, copy the value ofRn+1intoR2n+4, which gives theith iteration, and copy the result of the previous computation intoR2n+5. Then invoke the programPhto obtainf(x, i) =h(x, i−1, f(x, i−1)).

At the end, the input arguments are set to zero and the result of the last iteration is copied into the first register. This provides the desired result:kPfkn+1,1=f. ⊓⊔ The URM programs for composition and primitive recursion also make sense if the URM subpro-grams used in the respective induction step are not primitive recursive. These ideas will be formalized in the remaining part of the section.

Let g : Nk0 → N0 and hi : Nn0 →N0, 1 ≤i≤ k, be partial functions. The composition of g along (h1, . . . , hk) is a partial functionf, denoted by f =g(h1, . . . , hk), such that

dom(f) ={x∈Nn0 |x∈

\k

i=1

dom(hi)∧(h1(x), . . . , hk(x))∈dom(g)} (2.9) and

f(x) =g(h1(x), . . . , hk(x)), x∈dom(f). (2.10) The proof of the previous Theorem provides the following result.

Proposition 2.11.The class of URM computable functions is closed under composition; that is, if g : Nk0 → N0 and hi : Nn0 → N0, 1 ≤ i ≤ k, are URM computable, f = g(h1, . . . , hk) is URM computable.

The situation is analogous for the primitive recursion.

Proposition 2.12.Let g : Nn0 → N0 and h : Nn+20 → N0 be partial functions. There is a unique function f :Nn+10 →N0 such that

1.(x,0)∈dom(f)if and only if x∈dom(g)for allx∈Nn0,

2.(x, y+ 1)∈ dom(f) if and only if (x, y) ∈ dom(f) and (x, y, f(x, y))∈ dom(h) for all x∈ Nn0, y∈N0,

3.f(x,0) =g(x)for all x∈Nn0, and

4.f(x, y+ 1) =h(x, y, f(x, y))for all x∈Nn0,y∈N0.

The proof makes use of the Fundamental Lemma. The partial function f defined by g and hin this Proposition is denoted byf = pr(g, h) and said to be defined byprimitive recursion ofgandh.

Proposition 2.13.The class of URM computable functions is closed under primitive recursion; that is, ifg:Nn0 →N0 andh:Nn+20 →N0 are URM computable,f = pr(g, h)is URM computable.

Primitively Closed Function Classes LetF be a class of functions, i.e.,

F ⊆ [

k≥0

N(0Nk0).

The classF is calledprimitively closed if it contains the basic functions c(0)0 ,c(1)0 ,ν, πk(n), 1≤k≤n, n≥1, and is closed under composition and primitive recursion.

LetP denote the class of all primitive recursive functions,TURM the class of all URM computable total functions, andT the class of all total functions.

Proposition 2.14.The classesP,TURM, andT are primitively closed.

In particular, the classP of primitive recursive functions is the smallest class of functions which is primitively closed. Indeed, we have

P=\

{F | F ⊆ [

k≥0

N(0Nk0),Fprimitively closed}. (2.11) The concept of primitive closure carries over to partial functions, since composition and primitive recursion have been defined for partial functions as well. LetFURMdenote the class of URM computable functions andF the class of all functions.

Proposition 2.15.The classesFURM andF are primitively closed.

The lattice of the introduced classes (under inclusion) is the following:

F

All inclusions are strict. Indeed, the strict inclusionsTURM⊂ FURM andT ⊂ F are obvious, while the strict inclusions TURM ⊂ T and FURM ⊂ F follow by counting arguments. However, the strict inclusion P ⊂ TURM is not clear at all. An example of a total URM computable function that is not primitive recursive will be given in Chapter 4.