theory of computation (fall 2013): examples of primitive recursive functions & primitive...

51
Theory of Computation Examples of Primitive Recursive Functions & Predicates Vladimir Kulyukin www.vkedco.blogspot.com

Upload: vladimir-kulyukin

Post on 11-May-2015

496 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Theory of Computation

Examples of Primitive Recursive Functions & Predicates

Vladimir Kulyukin

www.vkedco.blogspot.com

Page 2: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Outline

● Review● Primitive Recursive Functions● Primitive Recursive Predicates● Compound Primitive Recursive Predicates

Page 3: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & 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

Page 4: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

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

Page 5: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

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

Page 6: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Question

How can we show that a function is primitive recursive?

Page 7: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

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)

Page 8: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 01

Show that f(x,y) = x + y is primitive recursive.

Page 9: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

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!

Page 10: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 01: Using Formal Definition

0,0, becomes 0,

:Case Base21 xuxhxxf

Page 11: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 01: Using Formal Definition

321

32321

32

,,,,

where,,,,1,

formally, more Or,

.,,,1,

becomes 1,1,

:Case Recursive

xxxusxxxg

xtxhtgtxh

xtxhtustxh

txftxf

Page 12: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 01: Using Formal Definition

321

3

2321

21

,,,,

where,,,,1,

0,0,

:get wecases, recursive and base theCombining

xxxusxxxg

xtxhtgtxh

xuxh

Page 13: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 02

Show that f(x,y) = x · y is primitive recursive.

Page 14: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

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!

Page 15: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 02: Using Formal Definition

xnxhxf 0, becomes 00,

:Case Base

Page 16: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

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

Page 17: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 02: Using Formal Definition

2121

3213

33213

2321

,

where,,,,,,,,

where,,,,1,

0,

:get wecases, recursive and base theCombining

xxxxf

xxxuxxxufxxxg

xtxhtgtxh

xnxh

Page 18: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

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

Page 19: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 03

Show that f(x) = x! is primitive recursive.

Page 20: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

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!

Page 21: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 03: Using Formal Definition

xnshf 0 becomes 00

:Case Base

Page 22: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 03: Using Formal Definition

2121

212221

2121

, and

,,,, where,,1

becomes 1

:Case Recursive

xxsxxf

xxuxxufxxgxhxgxh

xfxsxf

Page 23: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 03: Using Formal Definition

21

2

2212

121 ,,,

where,,1

0

:get wecases, recursive and base theCombining

xxuxxusxxg

xhxgxh

xnsh

Page 24: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

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

Page 25: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 04

Show that xy is primitive recursive.

Page 26: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 04

xxxyxf

xxfyy

1

0

1,

10,

Page 27: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 04

321

33321

32321 ,,,,,, where

,,,,1, becomes 1,

:Case cursiveRe

0, becomes 00,

:Case Base

xxxuxxxuxxxg

xyxhygyxhyxf

xnsxhxf

Page 28: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

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

Page 29: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 05

1 if 1

0 if 0

:recursive primitive isfunction r predecesso that theShow

xx

xxp

Page 30: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 05

,,

where,,1

00

:derivation Formal

1

00

:insight Informal

212121 xxuxxg

thtgth

h

ttp

p

Page 31: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 06: Dot Minus

yx

yxyxyx

xx

if 0

if

0

Page 32: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 06

xppxpp

xpxpx

xpxpx

yxpyx

xx

0

10111

010

1

0

recursive primitive isfunction minusdot that theShow

Page 33: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 06

230313

0012

02122232

pp

pppppp

pppppp

Page 34: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 07

Show that |x-y| is primitive recursive.

Page 35: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 07

xyyxyx3.

recursive primitive is .2

recursive primitive is .1

Page 36: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Primitive Recursive Predicates

Page 37: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & 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

Page 38: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 01

0 if 0

0 if 1)(

recursive primitive is )( that Show

x

xx

x

Page 39: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 02

121 , where,,1

10

:srecurrence Formal

0)1(

1)0(

:srecurrence Informal

xnxxgthtgth

h

t

Page 40: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 02

xx

1)(

:solutionelegant moreA

Page 41: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 03

Show that x = y is primitive recursive.

Page 42: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 03

yx

yxyxd

if 0

if 1,

Page 43: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 03

||,

because recursive, primitive is ,

yxyxd

yxd

Page 44: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 04

Show that x ≤ y is primitive recursive.

Page 45: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Example 04

1

ifonly and if 0

ifonly and if

yx

yx

yx

Page 46: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Theorem 5.1 (Ch. 3): Compound Predicates

.& and ,, are so

then, tobelong that predicates

are , If class. PRC a be Let

QPQPP

C

QPC

Page 47: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Proof 5.1 (Ch. 3)

QPQP

QPQP

PP

.3

.2

.1

Page 48: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

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

Page 49: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive 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

Page 50: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

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

Page 51: Theory of Computation (Fall 2013): Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Reading Suggestions

● Chapters 2 & 3, Computability, Complexity, & Languages by Davis, Weyuker, Sigal