# LT3 ch5 recursivefunctions

Ch

ng 5

Hàm đ quy

 Recursive Function Theory

Lý thuy t tí
ính toá
án
ttính
to
toán

Gödel's Incompleteness Theorem

Zero, Successor, Projector Functions

Functional Composition

PGS.TS. Phan Huy Khá
Khánh

Primitive Recursion

khanhph@vnn.vn

Proving Functions are Primitive Recursive

Ackermann's Function

(Theory
(Theory of
of Computation)
Computation)

Ch ng 5
Hàm đ quy
Hàm
2/32
2/
32

Maths Functions

Computation

An example function:

 Get N a set of Natural Numbers :

Range

Domain
N

N

f (n) = n2 + 1
3

N = { 0, 1, 2, … }
 Building the functions on N
For examples :

x +y
x* y
xy
x 2 + y2

10
f (3) = 10

We need a way to define functions

are computable functions

We need a set of basic functions
3/32
3/
32

4/32
4/
32

Complicated Functions

Function is computable

x  ( y + z)

Factorial function:
n! = n  (n-1)  (n-2)  …  2  1

is complicated functions from the addition and

multiplication function

is computable :

is computable:

there is a sequence of multiplication operations
 The factorial function is not alone the composition of the

there is a sequence of operations
of the addition and the multiplication

 The number of multiplication oprations depends on

Attention :

n

There are also many functions that are not composed
from the basis functions

5/32
5/
32

6/32
6/
32

1

Recursivity

Function is computable
Why is computable?

Factorial function is a recursive definition:
0!
=1
(n + 1) ! = (n + 1)  n !
Uses the recursivity to define some functions
f(n + 1)
is defined from:
f(n)
Start at:
f(0)

 Basic primitive recursive functions:

Computation on the natural number N

 Primitive Recursive Function:

Any function built from the basic primitive recursive
functions

7/32
7/
32

Computable functions

Gödel's Incompleteness Theorem
 “Any interesting consistent system must be incomplete;
that is, it must contain some unprovable propositions”
propositions”

 Basic set of Recursive primitive functions
 Primitive Recursive Functions :
 Mechanism for composition of functions
 by combining previously-defined functions
 composition
 Clearly

8/32
8/
32

 Hierarchy of Functions
1. PrimitivePrimitive-Recursive Functions
2. Recursive (
(-recursive) Functions

and/or recursive definitions

they are infinite in number

3. Interesting wellwell-defined Functions but "unprovable
"unprovable""
 BB Function

Some can have any arity (unary, binary, …)
f (n1, n2 , …, nm), m  1
9/32
9/
32

Primitive Recursive Functions

Zero, Successor, Projector Functions
 Zero function:

 Defined over the domain I = set of all nonnon-negative
integers
 or domain I×I
 or domain I×I×I, etc.
etc.

z(x)
(x) = 0, for all x  I

 Successor function:
s(x)
(x) = x+1

 Definition:

Functions are said to be Primitive Recursive
if they can be built

10/32
10/
32

 Projector functions:
p1(x1, x2) = x1

from the basic functions (zero, successor, and projection)
using functional composition and/or primitive recursion

p2(x1, x2) = x2

11/32
11/
32

12/32
12/
32

2

Example of Primitive Recursives

Subtraction
 pred(0) = 0
pred(x+1) = x

 Constants are Primitive Recursive:
2 = s(s(z(x)))
s(s(z(x)))
3 = s(s(s(z(x))))
s(s(s(z(x))))
5 = s(s(s(s(s(z(x))))))

 monus(x, 0)
0) = x // called subtr in text
monus(x, y+1)
y+1) = pred(monus(x, y))
y))
 absdiff(x, y)
y) = monus(x, y)
y) + monus(y, x)
x)

 mult(x, 0) = 0
mult(x, y+1) = add(x, mult(x, y))

13/32
13/
32

14/32
14/
32

Operators

Other Primitive Recursive Functions

 Relational Operators
 equal(x, y)
y) = test(absdiff(x, y))
y))
 geq(x, y)
y) = test(monus(y, x))
x))
 leq(x, y)
y) = test(monus(x, y))
y))

 Factorial & Exponentiation
 fact(0) = 1
fact(n+1) = mult(s(n), fact(n))
 exp(x, 0) = 1
exp(x, n+1) = mult(x, exp(x, n))

 Test for Zero (Logical Complement)
 test(0)
test(0) = 1
test(x+1) = 0

gt(x, y)
y) = test(leq(x, y))
y))
lt(x, y)
y) = test(geq(x, y))

 Minimum & Maximum
 min(x, y) = lt(x, y)*x + geq(x, y)*y

max(x, y) = geq(x, y)*x + lt(x, y)*y

15/32
15/
32

 Division

remaind(numerator, denominator) = rem(denominator, numerator)

rem(x, 0) = 0
rem(x, y+1) = s(rem(x, y))*test(equal(x, s(rem(x, y))))

div(numerator, denominator) = dv(denominator, numerator)

dv(x, 0) = 0
dv(x, y+1) = dv(x, y) + test(remaind(y+1, x))

16/32
16/
32

 Test for Prime
 numdiv(x)
numdiv(x) = divisors_leq(x, x)
x)
 divisors_leq(x, 0)
0) = 0
divisors_leq(x, y+1)
= divisors_leq(x, y)
y) + test(remaind(x, y+1))
y+1))

 Square Root
 sqrt(0) = 0
 sqrt(x+1) = sqrt(x) +
equal(x+1, (s(sqrt(x))*s(sqrt(x))))

is_prime(x)
is_prime(x) = equal(numdiv(x), 2)

 { a  b mod c }
 congruent(a, b, c)
= equal(remaind(a, c), remaind(b, c))

17/32
17/
32

18/32
18/
32

3

Greatest Common Divisor

Functional Composition

(can’
(can’t use Euclidean Algorithm—
Algorithm—not P.R.)
 gcd(a, 0)
0) = a
gcd(a, b+1)
b+1) = find_gcd(a, b+1, b+1)
b+1)

 f(x, y)
y) = h(g1 (x, y), g2(x, y))
y))

 find_gcd(a, b, 0)
0) = 1
find_gcd(a, b, c+1)
c+1) =
(c+1)*test_rem(a,
(c+1)*test_rem(a, b, c+1)
c+1) +
find_gcd(a, b, c)*test(test_rem(a, b, c+1))
c+1))

from previously defined functions g1, g2, and h

 e.g.:

 test_rem(a, b, c)
c) =
test(remaind(a, c))*test(remaind(b, c))
c))

min(x, y)
y) = lt(x, y)*x
y)*x + geq(x, y)*y
y)*y

h(x, y)
y)

g1(x, y)
y) = mult(lt(x, y), p1(x, y))
y))

g2(x, y)
y) = mult(geq(x, y), p2(x, y))
y))

h = mult(), g 1=lt(), g2=p1()
h = mult(), g 1=geq(), g2=p2()

19/32
19/
32

20/32
20/
32

Ackermann's Function

Primitive Recursion

 We can actually give an example of a total Turing-computable function
that is not primitive recursive, namely Ackermann’s function:
 A(0, n)
= n+1
 A(m+1, 0)
= A(m, 1)
 A(m+1, n+1)
= A(m, A(m+1, n))
 For example,

 Composition:
 f(x, 0)
0) = g1(x)
 f(x, y+1)
y+1) = h(g2(x, y), f(x, y)
y))
 Note: Last argument defined at zero and y+1 only
 e.g.:
 exp(x, 0)
0) = 1
exp(x, n+1)
n+1) = x * exp(x, n)

A(0, 0) = 1
A(0, 1) = 2
A(1, 1) = A(0, A(1, 0)) = A(0, A(0, 1))
= A(0, 1) + 1 = 3.

g1(x) = s(z(x))
h(x, y)
y) = mult(x, y)
y)
g2(x, y)
y) = p1(x, y)
y)
21/32
21/
32

22/32
22/
32

Ackermann's Function

Ackermann's Function

 Theorem
 For every unary primitive recursive function f,
there is some m such that f(m) < A(m, m)
 So A cannot be primitive recursive itself

 Ackermann's Function is NOT Primitive Recursive

23/32
23/
32

Just because it is not defined using the "official" rules of
primitive recursion is not a proof that it IS NOT primitive
recursive
Perhaps there is another definition that uses primitive
recursion
(NOT!) Proof is beyond the scope of this course…
course…

24/32
24/
32

4

"Meaning" of Ackermann's Function

Rates of growth

tetration)

 Growth of Ackerman’
Ackerman’s function:
A(1,0)  2; A(1,1)  3; A(1,2 )  4; A(1,n)  2  (n  3) 3

A(0, n) = n+1 ;
A(3, n) = 2n + 3 – 3

A(2,0)  3; A(2,1)  5; A(2,2)  7; A(2,n)  2 *(n  3)  3

A(1,
A(1, n) = n+2 ;
A(4,
A(4, n) = 2 - 3

Ackerman’
Ackerman’s function and friends
• A(m.n)
n3

A(3,0)  5; A(3,1)  13; A(3,2)  29; A(3,3)  61; A(3, 4)  125; A(3,n)  2

3

Iterated exponentials

2{n  3 times}

65534

 3; A(4, n)  2

2

nn

n

Exponential functions

... 2
2

A(4, 0)  13; A(4,1)  65531; A(4, 2)  2

A(2,
A(2, n) = 2n+3
with n powers of 2

• 3n

3

• n!

• nn

Polynomial functions
• 2n+5

• n3+3n2+2n+1

25/32
25/
32

26/32
26/
32

Countable Sets

Recursively Enumerable Languages

 Countable if it can be put into a 11-toto-1 correspondence
with the positive integers

 A language is said to be recursively enumerable
if there exists a Turing machine that accepts it.

 You should already be familiar with the enumeration
procedure for the set of RATIONAL numbers
[diagonalization, page 278]

 This says nothing about what the machine will do
if it is presented with a word that is not in the language

Quick review…
review…

 You should already be familiar with the fact (and proof)
that the REAL numbers are NOT countable

That is, if the accepting machine is started on a word
in the language, it will halt in qf

(i.e. whether it halts in a nonnon-final state or loops)

Quick review…
review…

27/32
27/
32

28/32
28/
32

Existence of Languages that are not
Recursively Enumerable

Recursive Languages
 A language, L, is recursive if there exists a Turing machine
that accepts L and halts on every w in +
 That is, there exists a membership decision procedure for L

 Let S be an infinite countable set
Then its powerset 2S is not countable

Proof by diagonalization

Recall the fact that the REAL numbers are not countable

 For any nonempty , there exist languages that are not
recursively enumerable.

29/32
29/
32

Every subset of * is a language
Therefore there are exactly 2 * languages
However, there are only a countable number of Turing
machines
Therefore there exist more languages than Turing machines
to accept them
30/32
30/
32

5

Recursively Enumerable but not Recursive
 We can list all Turing machines that eventually halted
on a given input tape (say blank)
 Recall the enumeration procedure for TM’
TM’s from last period
 Once a string of 0’
0’s and 1’
1’s was verified as a valid TM,
we would simply run it (while nonnon-deterministically continuing
to list other machines). [Note how long this would take!]
 A halt on the part of the simulation (recall the Universal
Turing Machine) would trigger adding the TM in question to
the list of those that halted. (copying it to another tape?)
 However, we cannot determine (and
(and always halt)
halt)
whether or not a given TM will halt on a blank tape
 Stay tuned for the unsolvability of the Halting Problem...

The hierarchy of functions
 Recall that a function f :
 Nk  N is total if f is defined on every input from Nk
.  and is partial if we don’t insist that it has to be total
All partial functions from Nk to N

The computable partial functions

•?
• n

The computable total functions

• A(m,n)
The primitive recursive functions

31/32
31/
32

32/32
32/
32

6

### Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay

×