0% found this document useful (0 votes)
5 views

ATC Seminar Primitive Recursive

The document discusses Primitive Recursive Functions (PRFs) and their significance in computability theory, emphasizing that they are total and computable functions. It outlines the definition, basic functions, and methods for constructing more complex PRFs using composition and primitive recursion. Additionally, it provides examples of defining basic arithmetic operations like addition, multiplication, and exponentiation as primitive recursive functions.

Uploaded by

guptakriti040
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

ATC Seminar Primitive Recursive

The document discusses Primitive Recursive Functions (PRFs) and their significance in computability theory, emphasizing that they are total and computable functions. It outlines the definition, basic functions, and methods for constructing more complex PRFs using composition and primitive recursion. Additionally, it provides examples of defining basic arithmetic operations like addition, multiplication, and exponentiation as primitive recursive functions.

Uploaded by

guptakriti040
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.

Primitive Recursive Functions and Computability

Aditya Ravishankar Moksha Mevada Ankit Kumar

E0 222: Automata Theory and Computation

Deparment of Computer Science and Automation


Indian Institute of Science, Bangalore

Nov 26, 2021


Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Table of Contents

1 Motivation

2 Definition

3 Representation of Ordinary Functions

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

3 Representation of Ordinary Functions

4 Computable Functions

5 Computability of P.R.F
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Motivation

Why care about another set of functions ?


Primitive Recursive Functions are total and computable,
which means that there is an algorithm which can compute
any value of the function in finite time.
Most functions that we need to consider in computability
theory, proof theory, etc. are in fact primitive recursive, which
means that we don’t need to go beyond primitive recursion
and look for proof techniques that work for more general total
computable functions.
Gives rise to an interesting question: ”Is every computable
function presentable in this form?”
This will be answered in the last part of this presentation.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Table of Contents

1 Motivation

2 Definition

3 Representation of Ordinary Functions

4 Computable Functions

5 Computability of P.R.F
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Introduction to Primitive Recursive Functions

In computability theory, a primitive recursive function is


roughly speaking a function that can be computed by a
computer program whose loops are all ”for” loops (that is, an
upper bound of the number of iterations of every loop can be
determined before entering the loop).

Definition:- A primitive recursive function takes a fixed


number of arguments, each a natural number (non-negative
integer: 0, 1, 2, ...), and returns a natural number. If it takes
n arguments, it is called n-ary.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Basic Primitive Recursive Functions

There are 3 basic primitive recursive functions, which are:

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

Basic Primitive Recursive Functions

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

Basic Primitive Recursive Functions

3. Projection:-

Projection can be defined as:

( x1 , x2 , ....xn ) πin : N n − > N

Example:
Projni
π23 (4, 5, 6) = 5
π22 (1, 3) = 3
xi

Constraint : n > 0, i > 0, i <= n


Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Composition

Other primitive recursive functions can be obtained by applying the


operations given by the next two axioms:

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

Can you describe how the following functions can be written as a


primitive recursive function, using the axioms defined till now ?
(i.e. using Successor, Projection, Zero, Composition of Functions
only)

1 f(x) = x + 5.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Exercise

Can you describe how the following functions can be written as a


primitive recursive function, using the axioms defined till now ?
(i.e. using Successor, Projection, Zero, Composition of Functions
only)

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

Can you describe how the following functions can be written as a


primitive recursive function, using the axioms defined till now ?
(i.e. using Successor, Projection, Zero, Composition of Functions
only)

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

The xi0 s are known as the parameters of the definition of


primitive recursion.
The variable y is the recursive variable.
The condition f (x1 .....xn , 0) = g (x1 , ..., xn ) is the base
condition, like we have for any recursive code.
The recursive call f (x1 , ..., xn , y + 1) is obtained by calling
function h with the all parameters (xi0 s), previous value of the
recursive variable (y ) and previous value of the function
(f (x1 , ..., xn , y )).
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Primitive Recursion

We can visualize the recursion by expanding it.


For the same definition of f (x1 , ..., xn , y + 1), we get the
following:
f (x1 , ..., xn , 0) = g (x1 , ....., xn )
f (x1 , ..., xn , 1) = h(x1 , ....., xn , 0, f (x1 , ..., xn , 0))
f (x1 , ..., xn , 2) = h(x1 , ....., xn , 1, f (x1 , ..., xn , 1))
...
And finally,
f (x1 , ..., xn , y + 1) = h(x1 , ....., xn , y , f (x1 , ..., xn , y ))
Finally, any function that can be written as a combination of
the basic functions (S, π, Z), composition and primitive
recursion is a primitive recursive function.
No other function is primitive recursive.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Table of Contents

1 Motivation

2 Definition

3 Representation of Ordinary Functions

4 Computable Functions

5 Computability of P.R.F
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Addition

We define addition as: add(x, y ) = x + y , with add(2, 3) =


2 + 3 = 5, for example.
Our goal is to write this function recursively.
The basic intuition to write this function recursively is that if
we have to perform add(x, y + 1), then we can write it as
add(x, y ) + 1, which is a function of x and y again.
If we proceed similarly, we can write it as
add(x, y − 1) + 1 + 1 and we continue this till we land up at
add(x, 0) + 1 + 1 + ... + 1 (y + 1 times)
In the end, we will use the base condition of add(x, 0) = x
and obtain the result.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Addition

So firstly, we will define the base condition for the function.


As shown above we need the base condition as add(x, 0) = x.
Using Projection rule, we can write add(x, 0) = g (x) = π11 (x)
=x
Now, we will try to write the recursive call of this function.
Observe that the ”primitive recursion” rule stated earlier, will
help us achieve this, as it has recursion in-built in it.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Addition

Since we want to use the primitive recursion rule, we need to


define add(x, y + 1) = h(x, y , f (x, y )), as per the rule, for
some primitive recursive function h.
Now we will try to define h as such that it makes
add(x, y + 1) = add(x, y ) + 1.
Define h(x, y , add(x, y )) = S(π33 (x, y , add(x, y ))).
S(π33 (x, y , add(x, y ))) = add(x, y ) + 1.
Thus, we have been able to define add(x, y ) as:
add(x, 0) = g (x) = π11 (x)
add(x, y + 1) = h(x, y , add(x, y )) = S(π33 (x, y , add(x, y )))
Thus, addition can be expressed as a primitive recursive
function.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Multiplication

We define Multiplication as: mul(x, y ) = x ∗ y , with mul(2,


3) = 2*3 = 6, for example.
Again, the goal is to write this function recursively.
The basic intuition to write this function recursively is that if
we have to perform mul(x, y + 1) then we can write it as
mul(x, y ) + x, which is a function of x and y again.
If we proceed similarly, we can write it as mul(x, y − 1) + x +
x and we continue this till we land up at mul(x, 0) + x + x +
... (y + 1 times).
In the end, we will use the base condition of mul(x, 0) = 0,
and obtain the result.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Multiplication

Similar to addition we first define the base condition for the


function.
Using the unary zero-function we can write mul(x, 0) = g (x)
= Z (x) = 0.
Now, we will try to write the recursive call of this function.
Observe that the ”primitive recursion” rule stated earlier, will
help us achieve this, as it has recursion in-built in it.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

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

Can you try defining the function fact(x) = x! as a primitive


recursive function ?
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Factorial

Can you try defining the function fact(x) = x! as a primitive


recursive function ?
Similarly to previous cases, we will firstly define the base
condition for the function.
Using zero-function and the successor function we can write
fact(0) = g () = S(Z ()) = 1.
We have defined that mul(x, y ) is a primitive recursive
function. So using that we can define h.
Define h(x, fact(x)) = mul(π22 (x, fact(x)), S(π12 (x, fact(x)))).
mul(π22 (x, fact(x)), S(π12 (x, fact(x)))) = fact(x) * (x + 1).
Thus, we can write fact(x) as:
fact(0) = g () = S(Z ()) = 1
fact(x + 1) = h(x, fact(x)) =
mul(π22 (x, fact(x)), S(π12 (x, fact(x))))
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Table of Contents

1 Motivation

2 Definition

3 Representation of Ordinary Functions

4 Computable Functions

5 Computability of P.R.F
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Computable Functions

f : Nk → N is computable if and only if there is an effective


procedure/ algorithm that, given any k-tuple x of natural
numbers, will produce the value f(x).
Thus, we require some mechanical procedure, like a Turing
Machine, or informally, some ”finite recipe” or algorithm to
compute the function value, for any given input tuple.
Keep in Mind: Computability of these functions does not
imply that they can be efficiently computed (Running time
can even be exponential)
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Table of Contents

1 Motivation

2 Definition

3 Representation of Ordinary Functions

4 Computable Functions

5 Computability of P.R.F
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Computability of Primitive Recursive Functions

Theorem
All Primitive Recursive Functions are Computable
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Proof

Each Primitive recursive function can be seen as a ”recipe” of


the basic functions, composition and primitive recursion. We
will use induction on the number of steps taken (say m) to
derive a primitive recursive function from the basic functions,
composition and primitive recursion.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

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...)

B/B,R 1/1,R -/-,R

1/1,R B/1,R
q0 q1 q2
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Proof

Zero: Z (n) : 0∀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...)

B/B,R 1/1,R 1/B,L -/-,R

1/1,R B/B,L B/B,R B/1,R


q0 q1 q2 q3 q4
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

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

B/B,R B/B,R B/B,R B/B,R B/B,R


q0 q1 q2 ... qn qn+1

(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

Induction Hypothesis: Assume that all primitive recursive


functions achieved after atmost m - 1 steps of derivation are
computable.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

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 )

output(h(g1 (x1 , x2 , ..., xn ), g2 (x1 , x2 , ..., xn ), ..., gk (x1 , x2 , ..., xn )))


end
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

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

Visualize how the recursion will look like.


h(x1 , x2 , ..., xn−1 , y − 1, f (x1 , x2 , ..., xn−1 , y − 1))
h(x1 , x2 , ..., xn−1 , y −
1, h(x1 , x2 , ..., xn−1 , y − 2,f (x1 , x2 , ..., xn−1 , y − 2)))
...
h(x1 , x2 , ..., xn−1 , y − 1, h(x1 , x2 , ..., xn−1 , y − 2
, h(x1 ...xn−1 , y −
3, h(...h(x1 , x2 , ..., xn−1 , 1,f (x1 , x2 , ..., xn−1 , 1)))...))))
h(x1 , x2 , ..., xn−1 , y − 1, h(x1 , x2 , ..., xn−1 , y − 2
, h(x1 ...xn−1 , y −
3, h(...h(x1 , x2 , ..., xn−1 , 0,f (x1 , x2 , ..., xn−1 , 0)))...))))
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Proof

Primitive Recursion: f can now be written as the algorithm:


func := g (x1 , x2 , ..., xn−1 )
for i = 0 to y - 1 do
func := h(x1 , x2 , ..., xn−1 , i, func)
end for
Since h and g are computable, and the for loop runs for a
finite number of iterations, f will also be computable.
Thus, it is proved that primitive recursive functions are
computable.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Computability of Primitive Recursive Functions

Quick-and-Dirty way to show that a function is Primitive Recursive


Sketch out a routine for computing it and check that it can all be
done with a succession of (possibly nested) ‘for’ loops which only
invoke already known primitive recursive functions; then the new
function will be primitive recursive.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Computability of Primitive Recursive Functions

Not all computable numeric functions are primitive recursive


Diagonalization argument.
By definition, each primitive recursive function has a ”full
recipe” in which it is defined by successive recursive,
composition or the basic primitive functions.
Enumerate these functions as f0 , f1 , f2 ,... and so on.
0 1 2 3 ...
f0 f0 (0) f0 (1) f0 (2) f0 (3) ...
f1 f1 (0) f1 (1) f1 (2) f1 (3) ...
f2 f2 (0) f2 (1) f2 (2) f2 (3) ...
... ... ... ... ... ...
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Computability of Primitive Recursive Functions

Not all computable numeric functions are primitive recursive


Define a function δ(n) = fn (n) + 1
Clearly, to compute δ, we need to compute all enumerations fi
until we compute fn . Then, we add one.
Each step is computable, and there are only a finite number of
steps, hence δ is also computable.
Now, if δ were a primitive recursive function, then it must
appear in one of the rows of the above table. Let that row be
corresponding to fk . Hence, δ(k) = fk (k) (As they are the
same). However by definition, δ(k) = fk (k) + 1. So, we have
arrived at a contradiction.
Hence, not all computable numeric functions are primitive
recursive.
Motivation Definition Representation of Ordinary Functions Computable Functions Computability of P.R.F

Non-Primitive Recursive but Computable function

Ackerman’s function is the function defined by


A(0, y ) = y + 1
A(x + 1, 0) = A(x, 1)
A(x + 1, y + 1) = A(x, A(x + 1, y ))
Clearly computable by creating a algorithm with the above
definition.
Intuitive idea about why this is not primitive recursive.
Ackerman’s function grows very fast. It grows faster than any
primitive recursive function.
Given a primitive recursive function, its derivation used the
recursion rule some finite number of times.
Since Ackerman’s function is defined using a recursion which
involves applying the function to itself there is no obvious way
to take the definition and make it primitive recursive.

You might also like