56
II. Recursive Function Yuxi Fu BASICS, Shanghai Jiao Tong University

II. Recursive Function - basics.sjtu.edu.cnyuxi/teaching/computability2013/slides... · Hilbert’s Program The epochal address of David Hilbert ... In 1931 G odel was aware of the

Embed Size (px)

Citation preview

II. Recursive Function

Yuxi Fu

BASICS, Shanghai Jiao Tong University

Hilbert’s Program

The epochal address of David Hilbert (23Jan.1862-14Feb.1934)to the International Congress of Mathematicians (Paris, 1900):

1. Consistency of the Axioms of Arithmetic.

This is the second among Hilbert’s 23 problems published in 1900(ten were announced in the Paris Congress).

2. Entscheidungsproblem (decision problem) of first order logic.

Yuxi Fu II. Recursive Function 1 / 49

Godel’s Incompleteness Theorem

Hilbert retired in 1930, and gave a special speech to the annualmeeting of the Society of German Scientists and Physicians in hisbirth place, Konigsberg.

It was in this occasion he made his famous remark”Wir mussen wissen. Wir werden wissen.”

Kurt Godel (28April.1906-14Jan.1978), a young man from Viennaand one year past his PhD, announced his IncompletenessTheorem in a roundtable discussion at the Conference onEpistemology held jointly with the Society meetings.(one day before Hilbert’s speech!)

Yuxi Fu II. Recursive Function 2 / 49

History of Recursion Theory

Godel’s remarkable idea is the arithmetization of syntax.

He used primitive recursive functions to do encoding.

In 1931 Godel was aware of the Ackermann function.By taking a suggestion from Herbrand, he developed in 1934 aformal system of Herbrand-Godel recursive functions.

Kleene (5Jan.1909-25Jan.1994) introduced in 1936 theµ-recursive functions, based on the system of the primitiverecursive functions and an unbounded search operator.

Yuxi Fu II. Recursive Function 3 / 49

Synopsis

1. Primitive Recursive Function

2. Ackermann Function

3. Recursive Function

Yuxi Fu II. Recursive Function 4 / 49

1. Primitive Recursive Function

Yuxi Fu II. Recursive Function 5 / 49

Recursion Theory offers a mathematical model for the study ofeffective calculability.

I All effective objects can be encoded by natural numbers.

I All effective procedures can be modeled by functions fromnumbers to numbers.

Yuxi Fu II. Recursive Function 6 / 49

Initial Function

1. The zero function 0def= λx1 . . . λxn.0.

2. The successor function s(x)def= λx .x+1.

3. The projection function Uni (x1, . . . , xn)

def= λx1 . . . λxn.xi .

Yuxi Fu II. Recursive Function 7 / 49

Composition

Suppose f (y1, . . . , yk) is a k-ary function and g1(x), . . . , gk(x) aren-ary functions, where x abbreviates x1, . . . , xn.

The composition function h(x) is defined by

h(x) = f (g1(x), . . . , gk(x)),

Yuxi Fu II. Recursive Function 8 / 49

Recursion

Suppose that f (x) is an n-ary function and g(x , y , z) is an(n+2)-ary function.

The recursion function h(x) is defined by

h(x , 0) = f (x), (1)

h(x , y + 1) = g(x , y , h(x , y)). (2)

Clearly there is a unique function that satisfies (1) and (2).

Yuxi Fu II. Recursive Function 9 / 49

Primitive Recursive Recursion

The set of primitive recursive function is the least set generatedfrom the initial functions, composition and recursion.

Yuxi Fu II. Recursive Function 10 / 49

Dummy Parameter

Proposition. Suppose that f (y1, . . . , yk) is a primitive recursiveand that xi1 , . . . , xik is a sequence of k variables from x1, . . . , xn(possibly with repetition). Then the function h given by

h(x1, . . . , xn) = f (xi1 , . . . , xik )

is primitive recursive.

Proof.h(x) = f (Un

i1(x), . . . ,Unik

(x)).

Yuxi Fu II. Recursive Function 11 / 49

Basic Arithmetic Function

x + y :

x + 0 = x ,

x + (y + 1) = (x + y) + 1.

xy :

x0 = 0,

x(y + 1) = xy + x .

xy :

x0 = 1,

xy+1 = xyx .

Yuxi Fu II. Recursive Function 12 / 49

Basic Arithmetic Function

x−1:

0−1 = 0,

(x + 1)−1 = x .

x−y def=

{x − y , if x ≥ y ,0, otherwise.

:

x−0 = x ,

x−(y + 1) = (x−y)−1.

Yuxi Fu II. Recursive Function 13 / 49

Basic Arithmetic Function

sg(x)def=

{0, if x = 0,1, if x 6= 0.

:

sg(0) = 0,

sg(x + 1) = 1.

sg(x)def=

{1, if x = 0,0, if x 6= 0.

:

sg(x) = 1−sg(x).

Yuxi Fu II. Recursive Function 14 / 49

Basic Arithmetic Function

|x − y | = (x−y) + (y−x).

x!:

0! = 1,

(x + 1)! = x!(x + 1).

min(x , y) = x−(x−y).

max(x , y) = x + (y−x).

Yuxi Fu II. Recursive Function 15 / 49

Basic Arithmetic Function

rm(x , y)def= the remainder when y is devided by x :

rm(x , y + 1)def=

{rm(x , y) + 1 if rm(x , y) + 1 < x ,0, otherwise.

The recursive definition is given by

rm(x , 0) = 0,

rm(x , y + 1) = (rm(x , y) + 1)sg(x−(rm(x , y) + 1)).

Yuxi Fu II. Recursive Function 16 / 49

Basic Arithmetic Function

qt(x , y)def= the quotient when y is devided by x :

qt(x , y + 1)def=

{qt(x , y) + 1, if rm(x , y) + 1 = x ,qt(x , y), if rm(x , y) + 1 6= x .

The recursive definition is given by

qt(x , 0) = 0,

qt(x , y + 1), = qt(x , y) + sg(x − (rm(x , y) + 1)).

Yuxi Fu II. Recursive Function 17 / 49

Basic Arithmetic Function

div(x , y)def=

{1, if x divides y ,0, otherwise.

:

div(x , y) = sg(rm(x , y)).

Yuxi Fu II. Recursive Function 18 / 49

Bounded Sum and Bounded Product

Bounded sum: ∑y<0

f (x , y) = 0,

∑y<z+1

f (x , y) =∑y<z

f (x , y) + f (x , z).

Bounded product:∏y<0

f (x , y) = 1,

∏y<z+1

f (x , y) = (∏y<z

f (x , y)) · f (x , z).

Yuxi Fu II. Recursive Function 19 / 49

Bounded Sum and Bounded Product

By composition the following functions are also primitive recursiveif k(x , w) is primitive recursive:∑

z<k(x ,w)

f (x , z)

and ∏z<k(x ,w)

f (x , z).

Yuxi Fu II. Recursive Function 20 / 49

Bounded Minimization Operator

Bounded search:

µz<y(f (x , z) = 0)def=

{the least z < y , such that f (x , z) = 0;y , if there is no such z .

Proposition.

If f (x , z) is primitive recursive, then so is µz<y(f (x , z) = 0).

Proof.µz<y(f (x , z) = 0) =

∑v<y (

∏u<v+1 sg(f (x , u))).

Yuxi Fu II. Recursive Function 21 / 49

Bounded Minimization Operator

Bounded search:

µz<y(f (x , z) = 0)def=

{the least z < y , such that f (x , z) = 0;y , if there is no such z .

Proposition.

If f (x , z) is primitive recursive, then so is µz<y(f (x , z) = 0).

Proof.µz<y(f (x , z) = 0) =

∑v<y (

∏u<v+1 sg(f (x , u))).

Yuxi Fu II. Recursive Function 21 / 49

Bounded Minimization Operator

If f (x , z) and k(x , w) are primitive recursive functions, then so isthe function

µz<k(x , w)(f (x , z) = 0).

Yuxi Fu II. Recursive Function 22 / 49

Primitive Recursive Predicate

Suppose M(x1, . . . , xn) is an n-ary predicate of natural numbers.The characteristic function cM(x), where x = x1, . . . , xn, is

cM(a1, . . . , an) =

{1, if M(a1, . . . , an) holds,0, if otherwise.

The predicate M(x) is primitive recursive if cM is primitiverecursive.

Yuxi Fu II. Recursive Function 23 / 49

Closure Property

Proposition. The following statements are valid:

I If R(x) is a primitive recursive predicate, then so is ¬R(x).I If R(x), S(x) are primitive recursive predicates, then the

following predicates are primitive recursive:I R(x) ∧ S(x);I R(x) ∨ S(x).

I If R(x , y) is a primitive recursive predicate, then the followingpredicates are primitive recursive:

I ∀z < y .R(x , z);I ∃z < y .R(x , z).

Proof.For example c∀z<y .R(x ,z)(x , y) =

∏z<y cR(x , z).

Yuxi Fu II. Recursive Function 24 / 49

Definition by Case

Suppose that f1(x), . . . , fk(x) are primitive recursive functions, andM1(x), . . . ,Mk(x) are primitive recursive predicates, such that forevery x exactly one of M1(x), . . . ,Mk(x) holds. Then the functiong(x) given by

g(x) =

f1(x), if M1(x) holds,f2(x), if M2(x) holds,...fk(x), if Mk(x) holds.

is primitive recursive.

Proof.g(x) = cM1(x)f1(x) + . . .+ cMk

(x)fk(x).

Yuxi Fu II. Recursive Function 25 / 49

More Arithmetic Function

Proposition. The following functions are primitive recursive.

(i) D(x) = the number of divisors of x ;

(ii) Pr(x) =

{1, if x is prime,0, if x is not prime.

;

(iii) px = the x-th prime number;

(iv) (x)y =

k , k is the exponent of py in the prime

factorisation of x , for x , y > 0,0, if x = 0 or y = 0.

.

Yuxi Fu II. Recursive Function 26 / 49

More Arithmetic Function

Proof.

(i) D(x) =∑

y<x+1 div(y , x).

(ii) Pr(x) = sg(|D(x)− 2|).

(iii) px can be recursively defined as follows:

p0 = 0,

px+1 = µz < (2 + px !)(1−(z−px)Pr(z) = 0

).

(iv) (x)y = µz<x(div(pz+1y , x) = 0).

Yuxi Fu II. Recursive Function 27 / 49

Encoding a Finite Sequence

Suppose s = (a1, a2, . . . , an) is a finite sequence of numbers.It can be coded by the following number

b = pa1+11 pa2+1

2 . . . pan+1n .

Then the length of s can be recovered from

µz<b((b)z+1 = 0),

and the i-th component can be recovered from

(b)i −1.

Yuxi Fu II. Recursive Function 28 / 49

Not all Computable Functions are Primitive Recursive

Using the fact that all primitive recursive functions are total, adiagonalisation argument shows that non-primitive recursivecomputable functions must exist.

The same diagonalisation argument applies to all finiteaxiomatizations of computable total function.

Yuxi Fu II. Recursive Function 29 / 49

2. Ackermann Function

Yuxi Fu II. Recursive Function 30 / 49

Ackermann Function

The Ackermann function [1928] is defined as follows:

ψ(0, y) ' y + 1,

ψ(x + 1, 0) ' ψ(x , 1),

ψ(x + 1, y + 1) ' ψ(x , ψ(x + 1, y)).

The equations clearly define a total function.

Yuxi Fu II. Recursive Function 31 / 49

Ackermann Function is Monotone

The Ackermann function is monotone:

ψ(n,m) < ψ(n,m + 1),

ψ(n,m) < ψ(n + 1,m).

The Ackermann function grows faster on the first parameter:

ψ(n,m + 1) ≤ ψ(n + 1,m)

ψ(n,m) + C is dominated by ψ(J,m) for some large enough J:

ψ(n,m) + ψ(n′,m) < ψ(max(n, n′) + 4,m),

ψ(n,m) + m < ψ(n + 4,m).

Yuxi Fu II. Recursive Function 32 / 49

Ackermann Function Grows Fast

Lemma. Let f (x) be a k-ary primitive recursive function. Thenthere exists some J such that for all n1, . . . , nk we have that

f (n1, . . . , nk) < ψ(J,k∑

i=1

nk).

Proof.

The proof is by structural induction.

(i) f is one of the initial functions. In this case take J to be 1.

Yuxi Fu II. Recursive Function 33 / 49

Ackermann Function Grows Fast

(ii) f is the composition function h(g1(x), . . . , gm(x)). Then

f (n) = h(g1(n), . . . , gm(n))

< ψ(J0,m∑i=1

gi (n)) < ψ(J0,m∑i=1

ψ(Ji ,k∑

j=1

nj))

< ψ(J0, ψ(J∗,k∑

j=1

nj)) < ψ(J∗, ψ(J∗ + 1,k∑

j=1

nj))

= ψ(J∗ + 1,k∑

j=1

nj + 1) ≤ ψ(J∗ + 2,k∑

j=1

nj).

Now set J = J∗ + 2.

Yuxi Fu II. Recursive Function 34 / 49

Ackermann Function Grows Fast

Suppose f is defined by the recursion:

f (x , 0) ' h(x),

f (x , y + 1) ' g(x , y , f (x , y)).

Then h(n) < ψ(Jh,∑

n) and g(n,m, p) < ψ(Jg ,∑

n + m + p).

It is easy to prove

f (n1, . . . , nk ,m) < ψ(J,k∑

i=1

nk + m)

by induction on m. �

Yuxi Fu II. Recursive Function 35 / 49

Faster than any Primitive Recursive Function

Now suppose ψ(x , y) was primitive recursive.By composition ψ(x , x) would be primitive recursive.

According to the Lemma

ψ(n, n) < ψ(J, n)

for some J and all n, which would lead to the contradiction

ψ(J, J) < ψ(J, J).

Yuxi Fu II. Recursive Function 36 / 49

Faster than any Primitive Recursive Function

The Ackermann function grows faster than every primitiverecursive function.

Yuxi Fu II. Recursive Function 37 / 49

3. Recursive Function

Yuxi Fu II. Recursive Function 38 / 49

Minimization Operator, or Search Operator

Minimization function, or µ-function, or search function:

µy(f (x , y) = 0) '

the least y such that

f (x , y) is defined for all z ≤ y , andf (x , y) = 0,

undefined if otherwise.

Here ' is the computational equality.

The recursion operation is a well-founded going-down procedure.

The search operation is a possibly divergent going-up procedure.

Yuxi Fu II. Recursive Function 39 / 49

Minimization Operator, or Search Operator

Minimization function, or µ-function, or search function:

µy(f (x , y) = 0) '

the least y such that

f (x , y) is defined for all z ≤ y , andf (x , y) = 0,

undefined if otherwise.

Here ' is the computational equality.

The recursion operation is a well-founded going-down procedure.

The search operation is a possibly divergent going-up procedure.

Yuxi Fu II. Recursive Function 39 / 49

Recursive Function

The set of recursive functions is the least set generated from theinitial functions, composition, recursion and minimization.

Yuxi Fu II. Recursive Function 40 / 49

Decidable Predicate

A predicate R(x) is decidable if its characteristic function

cR(x)def=

{1, if R(x) is true,0, otherwise.

is a recursive function.

The predicate R(x) is partially decidable ifits partial characteristic function

χR(x)def=

{1, if R(x) is true,↑, otherwise.

is a recursive function.

Yuxi Fu II. Recursive Function 41 / 49

Decidable Predicate

A predicate R(x) is decidable if its characteristic function

cR(x)def=

{1, if R(x) is true,0, otherwise.

is a recursive function. The predicate R(x) is partially decidable ifits partial characteristic function

χR(x)def=

{1, if R(x) is true,↑, otherwise.

is a recursive function.

Yuxi Fu II. Recursive Function 41 / 49

Closure Property

Proposition. The following statements are valid:

I If R(x) is decidable, then so is ¬R(x).I If R(x), S(x) are (partially) decidable, then the following

predicates are (partially) decidable:I R(x) ∧ S(x);I R(x) ∨ S(x).

I If R(x , y) is (partially) decidable, then the following predicatesare (partially) decidable:

I ∀z < y .R(x , y);I ∃z < y .R(x , y).

Yuxi Fu II. Recursive Function 42 / 49

Definition by Cases

Suppose f1(x), . . . , fk(x) are recursive and M1(x), . . . ,Mk(x) arepartially decidable. For every x at most one of M1(x), . . . ,Mk(x)holds. Then the function g(x) given by

g(x) '

f1(x), if M1(x) holds,f2(x), if M2(x) holds,...fk(x), if Mk(x) holds.

is recursive.

Yuxi Fu II. Recursive Function 43 / 49

Minimization via Decidable Predicate

Suppose R(x , y) is a partially decidable predicate. The function

g(x) = µyR(x , y)

=

{the least y such that R(x , y) holds, if there is such a y ,undefined, otherwise.

is recursive.

Proof.g(x) = µy(sg(χR(x , y)) = 0).

Yuxi Fu II. Recursive Function 44 / 49

Comment

The µ-operator allows one to define partial functions.

The diagonalisation argument does not apply to the set F ofrecursive functions.

Using the µ-operator, one may define total functions that are notprimitive recursive.

Yuxi Fu II. Recursive Function 45 / 49

Comment

The µ-operator allows one to define partial functions.

The diagonalisation argument does not apply to the set F ofrecursive functions.

Using the µ-operator, one may define total functions that are notprimitive recursive.

Yuxi Fu II. Recursive Function 45 / 49

Comment

The µ-operator allows one to define partial functions.

The diagonalisation argument does not apply to the set F ofrecursive functions.

Using the µ-operator, one may define total functions that are notprimitive recursive.

Yuxi Fu II. Recursive Function 45 / 49

Minimization Operator is a Search Operator

It is clear from the above proof why the minimization operator issometimes called a search operator.

Yuxi Fu II. Recursive Function 46 / 49

Definable Function

A function is definable if there is a recursive function calculating it.

Yuxi Fu II. Recursive Function 47 / 49

Ackermann Function is Recursive

Proposition. The Ackermann function is recursive.

Proof.

A finite set S of triples is said to be suitable if the followings hold:(i) if (0, y , z) ∈ S then z = y + 1;(ii) if (x + 1, 0, z) ∈ S then (x , 1, z) ∈ S ;(iii) if (x + 1, y + 1, z) ∈ S then ∃u.((x + 1, y , u)∈S ∧ (x , u, z)∈S).

A triple (x , y , z) can be coded up by 2x3y5z .A set {u1, . . . , uk} can be coded up by pu1 · · · puk .

Let R(x , y , v) be “v is a legal code and ∃z < v .(x , y , z)∈Sv”.

The Ackermann function ψ(x , y) ' µz((x , y , z)∈SµvR(x ,y ,v)).

Yuxi Fu II. Recursive Function 48 / 49

Do recursive functions capture all computable functions?

Godel himself wasn’t very sure about it in 1934.

Yuxi Fu II. Recursive Function 49 / 49

Do recursive functions capture all computable functions?

Godel himself wasn’t very sure about it in 1934.

Yuxi Fu II. Recursive Function 49 / 49