ATC Seminar Primitive Recursive
ATC Seminar Primitive Recursive
Table of Contents
1 Motivation
2 Definition
4 Computable Functions
5 Computability of P.R.F
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Table of Contents
1 Motivation
2 Definition
4 Computable Functions
5 Computability of P.R.F
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Motivation
Table of Contents
1 Motivation
2 Definition
4 Computable Functions
5 Computability of P.R.F
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
1. Zero Function:-
x Z(x)=0
Z:N → N
Zero Example:
Z(2) = 0
Z() = 0
0
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
2. Successor :-
x S(x)=x+1
S:N → N
succ Example:
S(3) = 4
S(0) = 1
x+1
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
3. Projection:-
Example:
Projni
π23 (4, 5, 6) = 5
π22 (1, 3) = 3
xi
Composition
Composition
Suppose we have an m-ary primitive recursive function f , and
primitive recursive functions g1 , g2 , ... gm , with each of the
gi0 s being k-ary, then the function h(x1 , x2 , ..., xk ) =
f (g1 (x1 , x2 , ..., xk ), ..., gm (x1 , x2 , ..., xk )) is also primitive
recursive. The function h in this case can be viewed as the
composition of the functions f , and all of the gi0 s.
Thus, h is defined from N k → N
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Composition
Example of Composition:
Assume that we have primitive recursive functions
add(x, y ) = x + y and mul(x, y ) = x ∗ y .
Now suppose we need to find h(x, y , z, p) = (x + y ) ∗ (z + p).
This can be achieved using composition as: h(x, y , z, p) =
mul(add(π14 (x, y , z, p), π24 (x, y , z, p)), add(π34 (x, y , z, p),
π44 (x, y , z, p)))
This essentially evaluates to
h(x, y , z, p) = mul(add(x, y ), add(z, p)), which is exactly
what we needed.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Exercise
1 f(x) = x + 5.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Exercise
1 f(x) = x + 5.
f (x) = S(S(S(S(S(x)))))
2 f(x,y,z) = y + 2.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Exercise
1 f(x) = x + 5.
f (x) = S(S(S(S(S(x)))))
2 f(x,y,z) = y + 2.
f (x, y , z) = S(S(π23 (x, y , z)))
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Primitive Recursion
Primitive recursion
Given the k-ary primitive recursive function g (x1 , ...xk ), and
the (k+2)-ary primitive recursive function h(x1 , ...xk+2 ), the
(k+1)-ary function f defined as below, is also primitive
recursive.
f (x1 , . . . , xk , 0) = g (x1 , . . . , xk )
f (x1 , . . . , xk , y + 1) = h(x1 , . . . , xk , y , f (x1 , . . . , xk , y ))
This is the rule that helps us inculcate ”recursion” for any
function.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Primitive Recursion
Primitive Recursion
Table of Contents
1 Motivation
2 Definition
4 Computable Functions
5 Computability of P.R.F
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Addition
Addition
Addition
Multiplication
Multiplication
Multiplication
Since we want to use the primitive recursion rule, we need to
define mul(x, y + 1) = h(x, y , mul(x, y )), as per the rule, for
some primitive recursive function h.
Now we will try to define h as such that it makes
mul(x, y + 1) = mul(x, y ) + x.
We have already shown that add(x, y ) is a primitive recursive
function. So we can use that to define h.
Define h(x, y , mul(x, y )) =
add(π33 (x, y , mul(x, y )), π13 (x, y , mul(x, y )).
add(π33 (x, y , mul(x, y )), π13 (x, y , mul(x, y )) = mul(x, y ) + x.
Thus, we have been able to define mul(x, y ) as:
mul(x, 0) = g (x) = Z (x) = 0
mul(x, y + 1) = h(x, y , mul(x, y )) =
add(π33 (x, y , mul(x, y )), π13 (x, y , mul(x, y )))
Thus, multiplication can be expressed as a primitive recursive
function.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Exponentiation
Can you try defining the function exp(x, y ) = x y as a
primitive recursive function ?
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Exponentiation
Can you try defining the function exp(x, y ) = x y as a
primitive recursive function ?
Similarly to previous cases, we will firstly define the base
condition for the function.
Using the zero function and the successor function we can
write exp(x, 0) = g (x) = S(Z (x)) = 1.
We have defined that mul(x, y ) is a primitive recursive
function. So using that we can define h.
Define h(x, y , exp(x, y )) =
mul(π3 (x, y , exp(x, y )), π1 (x, y , exp(x, y )).
mul(π3 (x, y , exp(x, y )), π1 (x, y , exp(x, y )) = exp(x, y ) * x.
Thus, we can write exp(x, y ) as:
exp(x, 0) = g (x) = S(Z (x)) = 1
exp(x, y + 1) = h(x, y , exp(x, y )) =
mul(π3 (x, y , exp(x, y )), π1 (x, y , exp(x, y )))
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Factorial
Factorial
Table of Contents
1 Motivation
2 Definition
4 Computable Functions
5 Computability of P.R.F
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Computable Functions
Table of Contents
1 Motivation
2 Definition
4 Computable Functions
5 Computability of P.R.F
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Theorem
All Primitive Recursive Functions are Computable
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Proof
Proof
Base Case: In 1 step, we can only get the basic functions i.e. the
successor function, projection function and the zero function. Let’s
try to prove that all of them are computable.
Successor: S(n) : n + 1∀n ∈ N
Consider the natual numbers to be represented in Unary,
represented by the string 1n+1 . For e.g. 0 will be represented
as 1, 1 will be represented as 11 and so on. The TM for this
function would look like: (Assuming tape is of the form
BBBBB...B1111...11BBB...)
1/1,R B/1,R
q0 q1 q2
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Proof
Proof
(n) (n)
Projection Function: pk : pk (x1 , x2 , ..., xn ) = xi , 1 ≤ i ≤ n
Consider the natual numbers to be represented in Unary,
represented by the string 1n+1 . For e.g. 0 will be represented
as 1, 1 will be represented as 11 and so on. The TM for this
function would look like: (Assuming tape is of the form
B..B1..1B1..1B1..1B..)
-/-,R
1/1,R 1/B,R 1/B,R
(n)
The above machine is for p1 . A generic machine for Pkn can be
constructed using Macros, which are out of scope for this
presentation.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Proof
Proof
Induction Step: What can the last step of the derivation (mth
step) be? It has to be one of the basic functions, composition
or the primitive recursion function.
If it is one of the basic functions, then we have already proved
that they are computable.
Examples:
f (x1 ) = S(x1 )
(3)
f (x1 ,x2 ,x3 ) = p3 (x1 , x2 , x3 )
f (x3 ) = Z (x3 )
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Proof
Composition
For composition, there exists functions g1 (x1 , x2 , ..., xn ),
g2 (x1 , x2 , ..., xn ), ..., gk (x1 , x2 , ..., xn ) and h(x1 , x2 , ..., xk )
which are primitive recursive such that each of them takes ≤
m - 1 steps to derive, and f (x1 , x2 , ..., xn ) =
h(g1 (x1 , x2 , ..., xn ), g2 (x1 , x2 , ..., xn ) , ..., gk (x1 , x2 , ..., xn ))
Using the induction hypothesis, each of the gi0 s and h is
computable.
Thus, an algorithm for f can be written as:
begin
input(x1 , x2 , ..., xn )
Proof
Composition
Example: f (x1 ,x2 ,x3 , x4 ) =
(4) (4)
Add(Mul(p1 (x1 ,x2 ,x3 ,x4 ), p2 (x1 ,x2 ,x3 ,x4 )),
(4) (4)
Exp(p3 (x1 ,x2 ,x3 ,x4 ), p4 (x1 ,x2 ,x3 ,x4 )))
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Proof
Primitive Recursion.
Primitive Recursion: Since the last rule used was primitive
recursion, there exists functions g (x1 , x2 , ..., xn−1 ) and
h(x1 , x2 , ..., xn+1 ) which are primitive recursive such that each
of them takes ≤ m - 1 steps to derive, and
f (x1 , x2 , ..., xn−1 , 0) = g (x1 , x2 , ..., xn−1 ), and
f (x1 , x2 , ..., xn−1 , y ) =
h(x1 , x2 , ..., xn−1 , y − 1, f (x1 , x2 , ..., xn−1 , y − 1))
Using the induction hypothesis, g and h are computable.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F
Proof
Proof