theory of computation (fall 2014): primitive recursive functions & predicates

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

Upload: vladimir-kulyukin

Post on 14-Dec-2014

298 views

Category:

Science


7 download

DESCRIPTION

 

TRANSCRIPT

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

Theory of Computation

Primitive Recursive Functions & Predicates

Vladimir Kulyukin

www.vkedco.blogspot.com

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

Outline

● Review● Showing Functions to be Primitive Recursive● Primitive Recursive Predicates● Compound Primitive Recursive Predicates

Page 3: Theory of Computation (Fall 2014): Primitive Recursive Functions & Predicates

Review

Page 4: Theory of Computation (Fall 2014): Primitive Recursive Functions & 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 5: Theory of Computation (Fall 2014): Primitive Recursive Functions & 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 6: Theory of Computation (Fall 2014): Primitive Recursive Functions & 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 7: Theory of Computation (Fall 2014): Primitive Recursive Functions & Predicates

How to Show that Functions are Primitive Recursive

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

Question

How can we show that a function is primitive recursive?

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

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)

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

Example 01

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

Page 11: Theory of Computation (Fall 2014): Primitive Recursive Functions & 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 12: Theory of Computation (Fall 2014): Primitive Recursive Functions & Predicates

Example 01: Using Formal Definition

.0,0, becomes 0,

:Case Base21 xuxhxxf

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

Example 01: Using Formal Definition

.,,,,

where,,,,1,

formally, more Or,

.,,,1,

becomes 1,1,

:Case Recursive

32132321

32

xxxusxxxg

xtxhtgtxh

xtxhtustxh

txftxf

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

Example 01: Using Formal Definition

.,,,,

where,,,,1,

;0,0,

:get wecases, recursive and base theCombining

3213

2321

21

xxxusxxxg

xtxhtgtxh

xuxh

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

Example 02

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

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

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!

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

Example 02: Using Formal Definition

.0, becomes 00,

:Case Base

xnxhxf

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

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

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

Example 02: Using Formal Definition

.,

where,,,,,,,,

where,,,,1,

;0,

:get wecases, recursive and base theCombining

2121

3213

33213

2321

xxxxf

xxxuxxxufxxxg

xtxhtgtxh

xnxh

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

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

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

Example 03

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

Page 22: Theory of Computation (Fall 2014): Primitive Recursive Functions & 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 23: Theory of Computation (Fall 2014): Primitive Recursive Functions & Predicates

Example 03: Using Formal Definition

.0 becomes 00

:Case Base

xnshf

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

Example 03: Using Formal Definition

., and

,,,, where,,1

becomes 1

:Case Recursive

2121

212221

2121

xxsxxf

xxuxxufxxgxhxgxh

xfxsxf

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

Example 03: Using Formal Definition

.,,,

where,,1

;0

:get wecases, recursive and base theCombining

212

2212

121 xxuxxusxxg

xhxgxh

xnsh

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

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

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

Example 04

Show that xy is primitive recursive.

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

Example 04

.1,

.10,1

0

xxxyxf

xxfyy

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

Example 04

.,,,,,, where

,,,,1, becomes 1,

:Case cursiveRe

.0, becomes 00,

:Case Base

32133321

32321 xxxuxxxuxxxg

xyxhygyxhyxf

xnsxhxf

Page 30: Theory of Computation (Fall 2014): Primitive Recursive Functions & 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 31: Theory of Computation (Fall 2014): Primitive Recursive Functions & Predicates

Example 05

0 if 1

0 if 0

:recursive primitive isfunction r predecesso that theShow

xx

xxp

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

Example 05

.,, where,,1

0;0

:derivation Formal

.1;00

:insight Informal

212121 xxuxxgthtgth

h

ttpp

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

Example 06: Dot Minus

yx

yxyxyx

xx

if 0

if

0

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

Example 06

xppxpp

xpxpx

xpxpx

yxpyx

xx

0

10111

010

1

0

recursive primitive isfunction minusdot that theShow

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

Example 06

230313

0012

02122232

pp

pppppp

pppppp

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

Example 07

Show that |x-y| is primitive recursive.

Page 37: Theory of Computation (Fall 2014): Primitive Recursive Functions & Predicates

Example 07

xyyxyx3.

recursive primitive is .2

recursive primitive is .1

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

Primitive Recursive Predicates

Page 39: Theory of Computation (Fall 2014): Primitive Recursive Functions & 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 40: Theory of Computation (Fall 2014): Primitive Recursive Functions & Predicates

Example 01

0 if 0

0 if 1)(

recursive primitive is )( that Show

x

xx

x

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

Example 02

121 , where,,1

10

:srecurrence Formal

0)1(

1)0(

:srecurrence Informal

xnxxgthtgth

h

t

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

Example 02

xx

1)(

:solutionelegant moreA

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

Example 03

Show that x = y is primitive recursive.

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

Example 03

yx

yxyxd

if 0

if 1,

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

Example 03

||,

because recursive, primitive is ,

yxyxd

yxd

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

Example 04

Show that x ≤ y is primitive recursive.

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

Example 04

1

ifonly and if 0

ifonly and if

yx

yx

yx

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

Proof 5.1 (Ch. 3)

QPQP

QPQP

PP

.3

.2

.1

Page 50: Theory of Computation (Fall 2014): Primitive Recursive Functions & 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 51: Theory of Computation (Fall 2014): Primitive Recursive Functions & 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

Page 52: Theory of Computation (Fall 2014): Primitive Recursive Functions & Predicates

Reading Suggestions

● Ch. 3, Computability, Complexity, and Languages, 2nd Edition, by Davis, Weyuker, Sigal

Page 53: Theory of Computation (Fall 2014): Primitive Recursive Functions & Predicates

Reading Suggestions

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