Upload
vladimir-kulyukin
View
495
Download
0
Embed Size (px)
Citation preview
Theory of Computation
Examples of Primitive Recursive Functions & Predicates
Vladimir Kulyukin
www.vkedco.blogspot.com
Outline
● Review● Primitive Recursive Functions● Primitive Recursive Predicates● Compound Primitive Recursive Predicates
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
Question
How can we show that a function is primitive recursive?
Answer
There are two strategies:
1. Obtain the function from the initial functions through composi-tion and/or primitive recursion (first principles reasoning that works on fairly simple functions)
2. Use the knowledge that some functions are already primitive recursive in combination with composition or primitive recur-sion (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
321
32321
32
,,,,
where,,,,1,
formally, more Or,
.,,,1,
becomes 1,1,
:Case Recursive
xxxusxxxg
xtxhtgtxh
xtxhtustxh
txftxf
Example 01: Using Formal Definition
321
3
2321
21
,,,,
where,,,,1,
0,0,
:get wecases, recursive and base theCombining
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 was shown to be p.r. ● 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
xnxhxf 0, becomes 00,
:Case Base
Example 02: Using Formal Definition
2121
32133321
32321
32
,
where,,,,,,,,
where,,,,1,
formally, more Or,
,,,1,
becomes ,1,
:Case Recursive
xxxxf
xxxuxxxufxxxg
xtxhtgtxh
xxtxhtutxh
xtxftxf
Example 02: Using Formal Definition
2121
3213
33213
2321
,
where,,,,,,,,
where,,,,1,
0,
:get wecases, recursive and base theCombining
xxxxf
xxxuxxxufxxxg
xtxhtgtxh
xnxh
Example 02: Checking Our Solution
200,
,0,,0,,0,,0,0,,01,
,1,,1,,1,,1,1,,111,:2
100,
,0,,0,,0,,0,0,,010,:1
000,:0
33
32
33
32
33
32
xxxxxxnxxxhx
xxhuxxhufxxxhgxxh
xxhuxxhufxxhgxhx
xxxxnxxh
xxhuxxhufxxhgxhx
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
xnshf 0 becomes 00
:Case Base
Example 03: Using Formal Definition
2121
212221
2121
, and
,,,, where,,1
becomes 1
:Case Recursive
xxsxxf
xxuxxufxxgxhxgxh
xfxsxf
Example 03: Using Formal Definition
21
2
2212
121 ,,,
where,,1
0
:get wecases, recursive and base theCombining
xxuxxusxxg
xhxgxh
xnsh
Example 03: Checking Our Solution
62322
2,22,22,212:!3
212
111,11,11,111:!2
111
000,00,00,010:!1
100:!0
22
21
22
21
22
21
hs
huhushgh
hshuhushgh
hshuhushgh
sxnsh
Example 04
Show that xy is primitive recursive.
Example 04
xxxyxf
xxfyy
1
0
1,
10,
Example 04
321
33321
32321 ,,,,,, where
,,,,1, becomes 1,
:Case cursiveRe
0, becomes 00,
:Case Base
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
1 if 1
0 if 0
:recursive primitive isfunction r predecesso that theShow
xx
xxp
Example 05
,,
where,,1
00
:derivation Formal
1
00
:insight Informal
212121 xxuxxg
thtgth
h
ttp
p
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.2a (Ch. 3)
class. PRC a are functions computable because True,:Proof
.,,
are so then ,predicates computable are and If :Claim
QPQPP
QP
Corollary 5.2b (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
● Chapters 2 & 3, Computability, Complexity, & Languages by Davis, Weyuker, Sigal