<<

rec.1 Examples of Primitive Recursive Functions cmp:rec:exa: We already have some examples of primitive recursive functions: the sec and functions add and mult. The identity id(x) = x is 1 primitive recursive, since it is just P0 . The constant functions constn(x) = n are primitive recursive since they can be defined from zero and succ by suc- cessive composition. This is useful when we want to use constants in primi- tive recursive , e.g., if we want to define the function f(x) = 2 · x can obtain it by composition from constn(x) and multiplication as f(x) = 1 mult(const2(x),P0 (x)). We’ll make use of this trick from now on. rec.1. The function exp(x, y) = xy is primitive recursive.

Proof. We can define exp primitive recursively as

exp(x, 0) = 1 exp(x, y + 1) = mult(x, exp(x, y)).

Strictly speaking, this is not a recursive from primitive recursive functions. Officially, though, we have:

exp(x, 0) = f(x) exp(x, y + 1) = g(x, y, exp(x, y)).

where

f(x) = succ(zero(x)) = 1 3 3 g(x, y, z) = mult(P0 (x, y, z),P2 (x, y, z)) = x · z

and so f and g are defined from primitive recursive functions by composition.

Proposition rec.2. The predecessor function pred(y) defined by ( 0 if y = 0 pred(y) = y − 1 otherwise

is primitive recursive.

Proof. Note that

pred(0) = 0 and pred(y + 1) = y.

This is almost a primitive . It does not, strictly speaking, fit into the pattern of definition by primitive , since that pattern requires

examples rev: dd20fb6 (2021-09-27) by OLP/ CC–BY 1 at least one extra x. It is also odd in that it does not actually use pred(y) in the definition of pred(y + 1). But we can first define pred′(x, y) by

pred′(x, 0) = zero(x) = 0, ′ 3 ′ pred (x, y + 1) = P1 (x, y, pred (x, y)) = y.

′ 1 and then define pred from it by composition, e.g., as pred(x) = pred (zero(x),P0 (x)).

Proposition rec.3. The function fac(x) = x ! = 1 · 2 · 3 ····· x is primitive recursive.

Proof. The obvious primitive recursive definition is

fac(0) = 1 fac(y + 1) = fac(y) · (y + 1).

Officially, we have to first define a two-place function h

h(x, 0) = const1(x) h(x, y + 1) = g(x, y, h(x, y))

3 3 where g(x, y, z) = mult(P2 (x, y, z), succ(P1 (x, y, z))) and then let

1 1 fac(y) = h(P0 (y),P0 (y)) = h(y, y).

From now on we’ll be a bit more laissez-faire and not give the official definitions by composition and primitive recursion.

Proposition rec.4. Truncated subtraction, x −˙ y, defined by ( 0 if x < y x −˙ y = x − y otherwise is primitive recursive.

Proof. We have:

x −˙ 0 = x x −˙ (y + 1) = pred(x −˙ y)

Proposition rec.5. The distance between x and y, |x − y|, is primitive recur- sive.

Proof. We have |x − y| = (x −˙ y) + (y −˙ x), so the distance can be defined by composition from + and −˙ , which are primitive recursive.

2 examples rev: dd20fb6 (2021-09-27) by OLP/ CC–BY Proposition rec.6. The maximum of x and y, max(x, y), is primitive recur- sive.

Proof. We can define max(x, y) by composition from + and −˙ by

max(x, y) = x + (y −˙ x).

If x is the maximum, i.e., x ≥ y, then y −˙ x = 0, so x + (y −˙ x) = x + 0 = x. If y is the maximum, then y −˙ x = y − x, and so x + (y −˙ x) = x + (y − x) = y. cmp:rec:exa: Proposition rec.7. The minimum of x and y, min(x, y), is primitive recur- prop:min-pr sive.

Proof. Exercise.

Problem rec.1. Prove Proposition rec.7.

Problem rec.2. Show that

2x .  . . f(x, y) = 2(2 ) y 2’s

is primitive recursive.

Problem rec.3. Show that division d(x, y) = ⌊x/y⌋ (i.e., division, where you disregard everything after the decimal point) is primitive recursive. When y = 0, we stipulate d(x, y) = 0. Give an explicit definition of d using primitive recursion and composition.

Proposition rec.8. The of primitive recursive functions is closed under the following two operations:

1. Finite sums: if f(⃗x,z) is primitive recursive, then so is the function

y X g(⃗x,y) = f(⃗x,z). z=0

2. Finite products: if f(⃗x,z) is primitive recursive, then so is the function

y Y h(⃗x,y) = f(⃗x,z). z=0

Proof. For example, finite sums are defined recursively by the equations

g(⃗x, 0) = f(⃗x, 0) g(⃗x,y + 1) = g(⃗x,y) + f(⃗x,y + 1).

3 Photo Credits

Bibliography

4 examples rev: dd20fb6 (2021-09-27) by OLP/ CC–BY