Slide04 RecursiveFunction
Slide04 RecursiveFunction
Substitution
Recursion
Minimalisation
Recursive Function∗
Xiaofeng Gao
CS363-Computability Theory
∗
Special thanks is given to Prof. Yuxi Fu for sharing his teaching materials.
CSC363-Computability Theory@SJTU Xiaofeng Gao Recursive Function 1/54
Basic Functions
Substitution
Recursion
Minimalisation
Outline
1 Basic Functions
Three Basic Functions
2 Substitution
Definition
Variable Sequences
3 Recursion
Definition
Examples
Corollary
4 Minimalisation
Bounded Minimalisation
Unbounded Minimalisation
A Famous Example
Outline
1 Basic Functions
Three Basic Functions
2 Substitution
Definition
Variable Sequences
3 Recursion
Definition
Examples
Corollary
4 Minimalisation
Bounded Minimalisation
Unbounded Minimalisation
A Famous Example
Proof
Outline
1 Basic Functions
Three Basic Functions
2 Substitution
Definition
Variable Sequences
3 Recursion
Definition
Examples
Corollary
4 Minimalisation
Bounded Minimalisation
Unbounded Minimalisation
A Famous Example
Substitution Theorem
is a computable function.
Substitution Theorem
is a computable function.
Substitution Theorem
is a computable function.
Note: h(x) is defined iff g1 (x), · · · , gk (x) are all defined and
(g1 (x), · · · , gk (x)) ∈ Dom(f ). Thus, if f and g1 , · · · , gk are all total
functions, then h is total.
Proof (Construction)
Proof (Construction)
Registers:
m+n m+n+1 m+n+k
[. . .]m
1 [x]m+1 [g1 (x)]m+n+1 . . . [gk (x)]m+n+k
I1 : T(1, m + 1)
..
.
In : T(n, m + n)
In+1 : G1 [m + 1, . . . , m + n → m + n + 1]
..
.
In+k : Gk [m + 1, . . . , m + n → m + n + k]
In+k+1 : F[m + n + 1 . . . , m + n + k → 1]
is computable.
is computable.
An Example
An Example
An Example
Outline
1 Basic Functions
Three Basic Functions
2 Substitution
Definition
Variable Sequences
3 Recursion
Definition
Examples
Corollary
4 Minimalisation
Bounded Minimalisation
Unbounded Minimalisation
A Famous Example
Recursion Equations
Suppose that f (x) and g(x, y, z) are functions. The function obtained
from f (x) and g(x, y, z) by recursion is defined as follows:
h(x, 0) ≃ f (x),
h(x, y + 1) ≃ g(x, y, h(x, y)).
Domain of h
Uniqueness
Computability Theorem
Proof
Registers:
m+n m+n+1 m+n+2 m+n+3
[. . .]m
1 [x]m+1 [y]m+n+1 [k]m+n+2 [h(x, k)]m+n+3 .
Proof
Registers:
m+n m+n+1 m+n+2 m+n+3
[. . .]m
1 [x]m+1 [y]m+n+1 [k]m+n+2 [h(x, k)]m+n+3 .
Program:
T(1, m + 1)
..
.
T(n + 1, m + n + 1)
F[1, 2, . . . , n → m + n + 3]
Iq : J(n + m + 2, n + m + 1, p)
G[m + 1, . . . , m + n, m + n + 2, m + n + 3 → m + n + 3]
S(n + m + 2)
J(1, 1, q)
Ip : T(n + m + 3, 1)
CSC363-Computability Theory@SJTU Xiaofeng Gao Recursive Function 18/54
Basic Functions
Definition
Substitution
Examples
Recursion
Corollary
Minimalisation
Flow Diagram
Addition
Addition
add(x, 0) = x + 0 = x
add(x, y + 1) = x + (y + 1) = (x + y) + 1
= add(x, y) + 1
Therefore,
add(x, 0) = f (x)
add(x, y + 1) = g(x, y, add(x, y))
where
f : N → N, f (x) := x,
3
g : N → N, g(x, y, z) := z + 1.
Multiplication
Multiplication
mult(x, 0) = x · 0 = 0
mult(x, y + 1) = x · (y + 1) = x · y + x
= mult(x, y) + x
Therefore,
mult(x, 0) = f (x)
mult(x, y + 1) = g(x, y, mult(x, y))
where
f : N → N, f (x) := 0,
3
g : N → N, g(x, y, z) := z + x.
Power Function
Power Function
power(x, 0) = x0 ≃ 1
power(x, y + 1) = x(y+1) ≃ xy · x
Therefore,
power(x, 0) = f (x)
power(x, y + 1) = g(x, y, power(x))
where
f : N → N, f (x) := 1,
2
g : N → N, g(x, y, z) := z · x.
Predecessor
x − 1 if x > 0,
Let pred: N → N, pred(x) := x−̇1 =
0 otherwise.
Predecessor
x − 1 if x > 0,
Let pred: N → N, pred(x) := x−̇1 =
0 otherwise.
pred(0) = 0
pred(x + 1) = x
Therefore,
pred(0) = f (x) = 0
pred(x + 1) = g(x, pred(x))
where
f : N → N, f (x) := 0,
2
g : N → N, g(x, y) := x.
CSC363-Computability Theory@SJTU Xiaofeng Gao Recursive Function 23/54
Basic Functions
Definition
Substitution
Examples
Recursion
Corollary
Minimalisation
Conditional Subtraction
def x − y, if x ≥ y,
Let sub: N2 → N, sub(x, y) := x−̇y =
0, otherwise.
Conditional Subtraction
def x − y, if x ≥ y,
Let sub: N2 → N, sub(x, y) := x−̇y =
0, otherwise.
sub(x, 0) = x−̇0 ≃ x
sub(x, y + 1) = x−̇(y + 1) ≃ (x−̇y)−̇1.
Therefore,
sub(x, 0) = f (x)
sub(x, y + 1) = g(x, y, sub(x))
where
f : N → N, f (x) := x,
2
g : N → N, g(x, y, z) := z−̇1.
CSC363-Computability Theory@SJTU Xiaofeng Gao Recursive Function 24/54
Basic Functions
Definition
Substitution
Examples
Recursion
Corollary
Minimalisation
Sign
Let sg: N → N,
def 0, if x = 0,
sg(x) = :
1, if x 6= 0.
Sign
Let sg: N → N,
def 0, if x = 0,
sg(x) = :
1, if x 6= 0.
sg(0) ≃ 0,
sg(x + 1) ≃ 1.
def 1, if x = 0,
sg(x) = :
0, if x 6= 0.
sg(x) ≃ 1−̇sg(x).
Other Examples
Factorial: x!
0! ≃ 1,
(x + 1)! ≃ x!(x + 1).
Remainder
def
rm(x, y) = the remainder when y is devided by x:
def rm(x, y) + 1, if rm(x, y) + 1 6= x,
rm(x, y + 1) =
0, if rm(x, y) + 1 = x.
Remainder
def
rm(x, y) = the remainder when y is devided by x:
def rm(x, y) + 1, if rm(x, y) + 1 6= x,
rm(x, y + 1) =
0, if rm(x, y) + 1 = x.
rm(x, 0) = 0,
rm(x, y + 1) = (rm(x, y) + 1)sg(|x − (rm(x, y) + 1)|).
Quotient
def
qt(x, y) = the quotient when y is devided by x:
def qt(x, y) + 1, if rm(x, y) + 1 = x,
qt(x, y + 1) =
qt(x, y), if rm(x, y) + 1 6= x.
Quotient
def
qt(x, y) = the quotient when y is devided by x:
def qt(x, y) + 1, if rm(x, y) + 1 = x,
qt(x, y + 1) =
qt(x, y), if rm(x, y) + 1 6= x.
qt(x, 0) = 0,
qt(x, y + 1) = qt(x, y) + sg(|x − (rm(x, y) + 1)|).
Conditional Division
def 1, if x|y,
div(x, y) = :
0, if x6 |y.
Conditional Division
def 1, if x|y,
div(x, y) = : div(x, y) = sg(rm(x,y)).
0, if x6 |y.
Definition by Cases
is computable.
Algebra of decidability
Suppose that M(x) and Q(x) are decidable predicates; then the
following are also decidable.
1 not M(x)
2 M(x) and Q(x)
3 M(x) or Q(x)
Algebra of decidability
Suppose that M(x) and Q(x) are decidable predicates; then the
following are also decidable.
1 not M(x)
2 M(x) and Q(x)
3 M(x) or Q(x)
Proof:
1 1−̇cM (x)
2 cM (x) · cQ (x)
3 max(cM (x), cQ (x))
Outline
1 Basic Functions
Three Basic Functions
2 Substitution
Definition
Variable Sequences
3 Recursion
Definition
Examples
Corollary
4 Minimalisation
Bounded Minimalisation
Unbounded Minimalisation
A Famous Example
Bounded product:
Y
f (x, z) ≃ 1,
z<0
Y Y
f (x, z) ≃ ( f (x, z)) · f (x, y)
z<y+1 z<y
and Y
f (x, z)
z<k(x,w)
def the least z < y, such that f (x, z) = 0;
µz<y(f (x, z) = 0) =
y if there is no such z.
µ-Operator
Theorem.
Proof
Q
Consider h(x, v) = sg(f (x, u)) (Computable).
u≤v
Proof.
1 f (x, y) = µz < y(sg(CR (x, z)) = 0).
Q
2 a) cM1 (x, y) = cR (x, z).
z<y
b) M2 (x, y) ≡ not (∀z < y(not R(x, z)))
Proof.
P
(a) D(x) ≃ y≤x div(y, x).
p0 ≃ 0,
px+1 ≃ µz ≤ (px ! + 1)(z > px and z is prime).
Prime Coding
µz<b((b)z+1 = 0),
(b)i −̇1.
Unbounded Minimization
µ-function:
the least y such that
(i) f (x, y) is defined for all z ≤ y, and
µy(f (x, y) = 0) ≃
(ii) f (x, y) = 0,
undefined if otherwise.
Theorem
Proof
Let F be a program in standard form that computes f (x, y). Let m be
max{n + 1, ρ(F)}.
m+n m+n+1 m+n+2
Registers:[. . .]m
1 [x]m+1 [k]m+n+1 [0]m+n+2 .
Proof
Let F be a program in standard form that computes f (x, y). Let m be
max{n + 1, ρ(F)}.
m+n m+n+1 m+n+2
Registers:[. . .]m
1 [x]m+1 [k]m+n+1 [0]m+n+2 .
Program:
T(1, m + 1)
..
.
T(n, m + n)
Ip : F[m + 1, m + 2, . . . , m + n + 1 → 1]
J(1, m + n + 2, q)
S(m + n + 1)
J(1, 1, p)
Iq : T(m + n + 1, 1)
CSC363-Computability Theory@SJTU Xiaofeng Gao Recursive Function 45/54
Basic Functions
Bounded Minimalisation
Substitution
Unbounded Minimalisation
Recursion
A Famous Example
Minimalisation
Flow Diagram
Corollary
g(x) = µyR(x, y)
the least y such that R(x, y) holds, if there is such a y,
=
undefined, otherwise.
is computable.
Corollary
g(x) = µyR(x, y)
the least y such that R(x, y) holds, if there is such a y,
=
undefined, otherwise.
is computable.
Discussion
Remark
Using the µ-operator, one may define total functions that are not
primitive recursive.
Ackermann Function
ψ(0, y) ≃ y + 1,
ψ(x + 1, 0) ≃ ψ(x, 1),
ψ(x + 1, y + 1) ≃ ψ(x, ψ(x + 1, y)).
Ackermann Function
Ackermann Function
Ackermann Function
Computability Proof
Computability Proof
Computability Proof
Ackermann Function