theory of computation (fall 2014): primitive recursive functions & predicates
DESCRIPTION
TRANSCRIPT
Theory of Computation
Primitive Recursive Functions & Predicates
Vladimir Kulyukin
www.vkedco.blogspot.com
Outline
● Review● Showing Functions to be Primitive Recursive● Primitive Recursive Predicates● Compound Primitive Recursive Predicates
Review
Primitive Recursion: Definition 01
).( by from obtained is Then
))(,()1(
)0(
:follows as from obtained be Let
function. a be ),(Let number. fixed some is Suppose
recursionrecursionprimitivegh
thtgth
kh
g h
totalyxgk
Primitive Recursion: Definition 02
. by and from obtained be tosaid is Then
).,...,),,,...,(,()1,,...,(
),...,()0,,...,(
:follows as and
from obtained variables1 offunction a be Let ly.respective
, variables2 and of functions are and that Suppose
111
11
recursionprimitivegfh
xxtxxhtgtxxh
xxfxxh
gf
nh
nntotalgf
nnn
nn
Definition: Primitive Recursive Function
A function is called primitive recursive if it can be obtained from the initial functions (successor, null constant, and projection) by a finite number of applications of composition or primitive recursion
How to Show that Functions are Primitive Recursive
Question
How can we show that a function is primitive recursive?
Two Possible Strategies
1. Obtain the function from the initial functions through composition and/or primitive recursion (first principles reasoning that works on fairly simple functions but gets more complex on more involved functions)
2. Use the knowledge that some functions are already primitive re-cursive in combination with composition or primitive recursion (this is a more generic method that requires more insight but less work)
Example 01
Show that f(x,y) = x + y is primitive recursive.
Example 01
● Here are the recurrences from Definition 2 of primitive recursion: f(x, 0) = x f(x, t+1) = f(x, t) + 1
● Let us play with these recurrences: f(2, 0) = 2. Works! f(2, 1) = f(2, 0) + 1 = 2 + 1 = 3. Works! f(3, 2) = f(3, 1) + 1 = f(3, 0) + 1 + 1 = 3 + 1 + 1 = 5. Works!
Example 01: Using Formal Definition
.0,0, becomes 0,
:Case Base21 xuxhxxf
Example 01: Using Formal Definition
.,,,,
where,,,,1,
formally, more Or,
.,,,1,
becomes 1,1,
:Case Recursive
32132321
32
xxxusxxxg
xtxhtgtxh
xtxhtustxh
txftxf
Example 01: Using Formal Definition
.,,,,
where,,,,1,
;0,0,
:get wecases, recursive and base theCombining
3213
2321
21
xxxusxxxg
xtxhtgtxh
xuxh
Example 02
Show that f(x,y) = x · y is primitive recursive.
Example 02● Basic insight: to compute x · y, add x to itself y times● We can use the fact that x + y has been shown to be primitive
recursive ● Here are the recurrences from Definition 2 of primitive recursion:
f(x, 0) = 0 f(x, t+1) = f(x, t) + x
● Let us play with these recurrences: f(2, 0) = 0. Works! f(2, 1) = f(2, 0) + 2 = 0 + 2 = 2. Works! f(3, 2) = f(3, 1) + 3 = f(3, 0) + 3 + 3 = 0 + 3 + 3 = 6. Works!
Example 02: Using Formal Definition
.0, becomes 00,
:Case Base
xnxhxf
Example 02: Using Formal Definition
.,
where,,,,,,,,
where,,,,1,
formally, more Or,
.,,,1,
becomes ,1,
:Case Recursive
2121
32133321
32321
32
xxxxf
xxxuxxxufxxxg
xtxhtgtxh
xxtxhtutxh
xtxftxf
Example 02: Using Formal Definition
.,
where,,,,,,,,
where,,,,1,
;0,
:get wecases, recursive and base theCombining
2121
3213
33213
2321
xxxxf
xxxuxxxufxxxg
xtxhtgtxh
xnxh
Example 02: Checking Our Solution
.200,
,0,,0,,0,,0
.,0,,01,
,1,,1,,1,,1
,1,,111,:2 Computing
.100,
,0,,0,,0,,0
,0,,010,:1 Computing
.000,:0 Computing
33
32
33
32
33
32
xxxxxxnxxxh
xxxhuxxhuf
xxxhgxxh
xxhuxxhuf
xxhgxhx
xxxxnxxh
xxhuxxhuf
xxhgxhx
xxnxhx
Example 03
Show that f(x) = x! is primitive recursive.
Example 03● Basic insight: view x! as a composition of multiplication and s(x) both
of which have been shown to be primitive recursive ● We use Definition 1 to write the recurrences:
f(0) = 1 f(x+1) = s(x) · f(x)
● Let us play with these recurrences: f(0) = 1. Works! f(1) = f(0+1) = s(0) · f(0) = 1 · 1 = 1. Works! f(2) = f(1+1) = s(1) · f(1) = 2 · 1 = 2. Works!
Example 03: Using Formal Definition
.0 becomes 00
:Case Base
xnshf
Example 03: Using Formal Definition
., and
,,,, where,,1
becomes 1
:Case Recursive
2121
212221
2121
xxsxxf
xxuxxufxxgxhxgxh
xfxsxf
Example 03: Using Formal Definition
.,,,
where,,1
;0
:get wecases, recursive and base theCombining
212
2212
121 xxuxxusxxg
xhxgxh
xnsh
Example 03: Checking Our Solution
.62322
2,22,22,212 :!3 Computing
.212
111,11,11,111 :!2 Computing
.111
000,00,00,010 :!1 Computing
.100 :!0 Computing
22
21
22
21
22
21
hs
huhushgh
hshuhushgh
hshuhushgh
sxnsh
Example 04
Show that xy is primitive recursive.
Example 04
.1,
.10,1
0
xxxyxf
xxfyy
Example 04
.,,,,,, where
,,,,1, becomes 1,
:Case cursiveRe
.0, becomes 00,
:Case Base
32133321
32321 xxxuxxxuxxxg
xyxhygyxhyxf
xnsxhxf
Example 04: Checking Our Solution
2
33
32
33
32
1,
,1,,1,1,,1,1,,111,
10,
,0,,0,0,,0,0,,010,
10,
xxxxxh
xxhuxxhuxxhgxh
xxxxh
xxhuxxhuxxhgxh
xnsxh
Example 05
0 if 1
0 if 0
:recursive primitive isfunction r predecesso that theShow
xx
xxp
Example 05
.,, where,,1
0;0
:derivation Formal
.1;00
:insight Informal
212121 xxuxxgthtgth
h
ttpp
Example 06: Dot Minus
yx
yxyxyx
xx
if 0
if
0
Example 06
xppxpp
xpxpx
xpxpx
yxpyx
xx
0
10111
010
1
0
recursive primitive isfunction minusdot that theShow
Example 06
230313
0012
02122232
pp
pppppp
pppppp
Example 07
Show that |x-y| is primitive recursive.
Example 07
xyyxyx3.
recursive primitive is .2
recursive primitive is .1
Primitive Recursive Predicates
Motivation
● Predicates are Boolean-valued functions 1 is TRUE
0 is FALSE
● Since predicates are functions, it makes sense for us to ask which predicates are primitive recursive and, more generally, explore the relationship b/w predicates and PRC classes
● It makes sense for us to build a repository of primitive recursive predicates
Example 01
0 if 0
0 if 1)(
recursive primitive is )( that Show
x
xx
x
Example 02
121 , where,,1
10
:srecurrence Formal
0)1(
1)0(
:srecurrence Informal
xnxxgthtgth
h
t
Example 02
xx
1)(
:solutionelegant moreA
Example 03
Show that x = y is primitive recursive.
Example 03
yx
yxyxd
if 0
if 1,
Example 03
||,
because recursive, primitive is ,
yxyxd
yxd
Example 04
Show that x ≤ y is primitive recursive.
Example 04
1
ifonly and if 0
ifonly and if
yx
yx
yx
Theorem 5.1 (Ch. 3): Compound Predicates
.& and ,, are so
then, tobelong that predicates
are , If class. PRC a be Let
QPQPP
C
QPC
Proof 5.1 (Ch. 3)
QPQP
QPQP
PP
.3
.2
.1
Theorem 5.1 (Ch. 3): Corollaries
● Recall that we have shown that the classes of primitive recursive and computable functions are primitive recursively closed
● Theorem 5.1 furnishes us with two important corollaries that help us reason about computational properties of compound predicates
Corollary 5.2 (Ch. 3)
class. PRC a are functions recursive primitive because True,:Proof
.,,
are so then ,predicates recursive primitive are and If :Claim
QPQPP
QP
Reading Suggestions
● Ch. 3, Computability, Complexity, and Languages, 2nd Edition, by Davis, Weyuker, Sigal
Reading Suggestions
● Chapters 2 & 3, Computability, Complexity, & Languages by Davis, Weyuker, Sigal