Partial and Total Functions
Partial and Total Functions
,
x
n
), f
2
(x
1,
x
2,
,
x
n
),, f
k
(x
1,
x
2
.
,
x
n
)
Eg: f1, f2 and f3, are partial functions of two
variables and g is a partial function of three
variables, then the composition of g with f1, f2,f3, is
given by
g(f1 (Xl, X2), f2(x1, X2), f3(X1, X2)).
Example1
Let f1(X, y) =X + y, f2(x, y) =2x,f3(x, y) =xy and
g(x, y, z) =X + Y + z be functions over N.
Then
g(f1(X, y), f2(X, y),f3(x, y)) =g(x + y, 2x, xy)
=x+y+2x+xy
Thus the composition of g with f1,f2,f3 is given
by a function h:
h(x, y) =x + y + 2x + xy
Example2
Let f
1
(x
1,
x
2
)=x
1
x
2
, f
2
(x
1,
x
2
)= ^ ,f
3
(x
1,
x
2
)=x
1
g(x
1,
x
2
,x
3
)= x
2
x
3
be functions over .
Then
g(f
1
(x
1,
x
2
), f
2
(x
1,
x
2
),f
3
(x
1,
x
2
))= g(x
1
x
2,^,
x
1
)
=^ x
1
= x
1
So the composition of g with f
1,
f
2,
f
3
is given by a
function h, where
h(x
1,
x
2
)=x
1
Primitive recursion
A function f(x) over N is defined by recursion if
there exists a constant k (a natural number) and
a function h(x, y) such that
f(0) = k, f(n + 1) = h(n, f(n))
12
)) 1 ( ), ( ( ) 1 (
1 ) 0 (
+ = +
=
x x fact mult x fact
fact
Factorials
)) 1 ) 1 ( ! = n n n
13
Basic Primitive Identity function
...
x x identity
x x
2 1 0 ) (
2 1 0
)) ( ( )) ( (
0 ) 0 (
x ident succ x succ identity
identity
=
=
Recursive definition
14
Basic Primitive Successor function
...
1 3 2 1 ) (
2 1 0
+ x x succ
x x
15
)) ( ( ) ( x zero succ x one =
Using Basic Primitive Zero function
and a Successor function we can
construct Constant functions
etc..
)) ( ( ) ( x one succ x two =
)) ( ( ) ( x two succ x three =
16
3
) 2 (
)) 1 ( (
))) 0 ( ( (
)))) ( ( ( (
))) ( ( (
)) ( ( ) (
=
=
=
=
=
=
=
succ
succ succ
succ succ succ
x zero succ succ succ
x one succ succ
x two succ x three
Example
17
A Primitive Recursive Function
) , ( y x add
x x add = ) 0 , (
(projection)
)) , ( ( ) 1 , ( y x add succ y x add = +
(successor function)
18
5
) 4 (
)) 3 ( (
))) 0 , 3 ( ( (
)) 1 , 3 ( ( ) 2 , 3 (
=
=
=
=
=
succ
succ succ
add succ succ
add succ add
Example
19
Basic Primitive Predecessor function
...
1 1 0 0 ) (
2 1 0
x x pred
x x
20
Predecessor
x x succ pred
pred
=
=
)) ( (
0 ) 0 (
1 ) ( =x x pred
) ( )) ( (
0 ) 0 (
x G x succ pred
pred
=
=
Predecessor is a primitive recursive function with no direct
self-reference.
x) identity( G(x) =
template recursive primitive
21
Subtraction
)) , ( ( )) ( , (
) 0 , (
x y sub pred x succ y sub
y y sub
=
=
x y x y sub = ) , (
) 1 ) ( ) 1 ( ( = + x y x y
22
1
) 2 (
)) 3 ( (
))) 0 , 3 ( ( (
)) 1 , 3 ( ( ) 2 , 3 (
=
=
=
=
=
pred
pred pred
sub pred pred
sub pred sub
Example
23
0 ) 0 , ( = x mult
)) , ( , ( ) 1 , ( y x mult x add y x mult = +
) , ( y x mult A Primitive Recursive Function
) ) ( ) 1 ( ( x xy y x + = +
24
x
x x add
x x add x add
x x add x add x add
x add x add x add x add
x mult x add x add x add x add
x mult x add x add x add
x mult x add x add
x mult x add x mult
4
) 3 , (
)) 2 , ( , (
))) , ( , ( , (
)))) 0 , ( , ( , ( , (
))))) 0 , ( , ( , ( , ( , (
)))) 1 , ( , ( , ( , (
))) 2 , ( , ( , (
)) 3 , ( , ( ) 4 , (
=
=
=
=
=
=
=
=
=
Example
25
1 ) , 0 ( = x exp
) ), , ( ( ) , 1 ( y y x exp mult y x exp = +
) , ( y x exp
A Primitive Recursive Function
) (
1
y y y
x x
=
+
26
Example
4
) ), (
) ), , ( (
) ), ), , ( ( (
) ), ), ), , 1 ( ( ( (
) ), ), ), ), , 0 ( ( ( ( (
) ), ), ), , 1 ( ( ( (
) ), ), , 2 ( ( (
) ), , 3 ( ( ) , 4 (
y y y y y
y y y y mult
y y y y mult mult
y y y y mult mult mult
y y y y mult mult mult mult
y y y y y exp mult mult mult mult
y y y y exp mult mult mult
y y y exp mult mult
y y exp mult y exp
= =
=
=
=
=
=
=
=
=
27
Primitive Recursion: Logic
A predicate (Boolean function) with output in the
set {0,1} which is interpreted as {yes, no}, can be
used to define standard functions.
Logical connectives . ,v ,, ,
Numeric comparisons =, < ,>,
Bounded existential quantification -isn, f(i)
Bounded universal quantification isn, f(i)
Bounded minimization min i isn, f(i)
where result = 0 if f(i) never true within bounds.
28
A specific function that is not primitive
recursive:
Ackermanns function:
)) , ( , 1 ( ) 1 , (
) 1 , 1 ( ) 0 , (
1 ) , 0 (
y x A x A y x A
x A x A
y y A
= +
=
+ =
Grows very fast,
faster than any primitive recursive function
29
The Ackermann function is the simplest
example of a well defined total function
which is computable but not primitive
recursive
Compute A(1. 1), A(2, 1). A(l, 2), A(2, 2).
Solution
A(1, 1)= A(O + 1, 0 + 1)
= A(O, A(1,0))
=A(O, A(O, 1))
= A(O, 2)
= 3
31
otherwise 0,
) (
even is n if , 1
= n even
) ) ( , 1 ( ) 1 (
1 ) 0 (
k even sub k even
even
= +
=
More Examples of Primitive Recursion
A recursive function is a function that calls itself (by using its own name
within its function body).
Even