0% found this document useful (0 votes)
40 views31 pages

Partial and Total Functions

- Primitive recursive functions can be defined using a small set of basic functions like successor, zero, and projections, along with composition and primitive recursion. - Examples of basic primitive recursive functions include addition, multiplication, exponentiation, and the Ackermann function. - While the Ackermann function is computable, it grows faster than any primitive recursive function and is thus not primitive recursive.

Uploaded by

Abhinav Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views31 pages

Partial and Total Functions

- Primitive recursive functions can be defined using a small set of basic functions like successor, zero, and projections, along with composition and primitive recursion. - Examples of basic primitive recursive functions include addition, multiplication, exponentiation, and the Ackermann function. - While the Ackermann function is computable, it grows faster than any primitive recursive function and is thus not primitive recursive.

Uploaded by

Abhinav Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 31

Partial and Total functions

A partial function f from X to Y is a rule which


assigns to every element of X at most one
element of Y.
A total function from X to Y is a rule which
assigns to every element of X a unique
element of Y.
PRIMITIVE RECURSIVE FUNCTIONS
The function which can be implemented using only for-loops.
Three classes of basic functions:
(The initial functions over N are :)
successor,
zero, and
Projections
(The initial functions over are :)
Nil , and
concatenation

Two ways of building new primitive recursive
functions from old:
composition , and
primitive recursion.
The Successor function
The function that takes x to x + 1 can be taken
apart no further.
Therefore, it will be a basic building block for
primitive recursive functions.
We denote it by s (for successor).
Successor function S defined by S(x) = x + 1
Eg: S(4) =5.
The zero function
The zero is used in every computation and
will therefore be a basic building block for
primitive recursive functions.
For technical reasons, we shall use the zero
function
Zero function Z defined by Z(x) = 0
Eg: Z(7) = 0
The projections
Projection function U
i
n
defined by :
U
i
n
(x
1,
x
2,.,
x
n
)=x
i


Projections occur in almost every computation
and will therefore be basic building blocks for
primitive recursive functions.
Eg: U
2
3
(2, 4, 7) = 4, U
1
3
(2, 4, 7) =2
6
Zero function:
0 ) ( = x zero
Successor function: 1 ) ( + = x x succ
Projection functions:
1 2 1 1
) , ( x x x p =
2 2 1 2
) , ( x x x p =
Basic Primitive Recursive Functions
The initial functions over

nil (x) = A
cons a(x) = ax
cons b(x) = bx
Eg:
nil(abab) = A
cons a(abab) =aabab
cons b(abab) = babab
Note: We note that cons a(x) and cons b(x) simply
denote the concatenation of the 'constant' string a
and X and the concatenation of the constant string
band x
Composition Function

If f
1,
f
2,.,
f
k
are partial functions of n variables and
g is a partial function of k variables, then the
composition of g with f
1,
f
2,..,
f
k
is a partial function
of n variables defined by
g(f
1
(x
1,
x
2

,
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

You might also like