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

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

Post on 11-May-2015

466 views

Category:

Technology

0 download

Embed Size (px)

TRANSCRIPT

<ul><li>1.Theory of Computation Examples of Primitive Recursive Functions &amp; PredicatesVladimir Kulyukin www.vkedco.blogspot.com</li></ul> <p>2. Outline Review Primitive Recursive Functions Primitive Recursive Predicates Compound Primitive Recursive Predicates 3. Primitive Recursion: Definition 01 Suppose k is some fixed number. Let g ( x, y ) be a total function. Let h be obtained from g as follows : h(0) k h(t 1) g (t , h(t )) Then h is obtained from g by primitive recursion (recursion). 4. Primitive Recursion: Definition 02 Suppose that f and g are total functions of n and n 2 variables, respectively. Let h be a function of n 1 variables obtained from f and g as follows : h( x1 ,..., xn ,0) f ( x1 ,..., xn ) h( x1 ,..., xn , t 1) g (t , h( x1 ,..., xn , t ), x1 ,..., xn ). Then h is said to be obtained from f and g by primitive recursion. 5. Definition: Primitive Recursive FunctionA 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 6. QuestionHow can we show that a function is primitive recursive? 7. Answer There are two strategies: 1. Obtain the function from the initial functions through composition 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 recursion (this is a more generic method that requires more insight but less work) 8. Example 01Show that f(x,y) = x + y is primitive recursive. 9. Example 01 Here are the recurrences from Definition 2 of primitive recursion: f(x, 0) = x f(x, t+1) = f(x, t) + 1Let 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! 10. Example 01: Using Formal DefinitionBase Case : f x,0 x becomes h x,0 u x,0 2 1 11. Example 01: Using Formal Definition Recursive Case : f x, t 1 f x, t 1 becomesh x, t 1 s u t , h x, t , x . 3 2Or, more formally, h x, t 1 g t , h x, t , x , whereg x1 , x 2 , x3 s u x1 , x 2 , x3 3 2 12. Example 01: Using Formal Definition Combining the base and recursive cases, we get : hx,0 u x,0 2 1hx, t 1 g t , h x, t , x , whereg x1 , x 2 , x3 s u x1 , x 2 , x3 3 2 13. Example 02Show that f(x,y) = x y is primitive recursive. 14. 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) + xLet 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! 15. Example 02: Using Formal DefinitionBase Case : f x,0 0 becomes h x,0 n x 16. Example 02: Using Formal Definition Recursive Case :f x, t 1 f x, t x becomesh x, t 1 u t , h x, t , x x 3 2Or, more formally,h x, t 1 g t , h x, t , x , whereg x1 , x 2 , x3 f u x1 , x 2 , x3 , u x1 , x 2 , x3 , where f x1 , x 2 x1 x 23 23 3 17. Example 02: Using Formal Definition Combining the base and recursive cases, we get : h x,0 n x h x, t 1 g t , h x, t , x , whereg x1 , x 2 , x3 f u x1 , x 2 , x3 ,u x1 , x 2 , x3 , where f x1 , x 2 x1 x 23 23 3 18. Example 02: Checking Our Solution x 0 : h x,0 n x 0 x 0x 1 : h x,0 1 g 0, h x,0 , x f u 0, h x,0 , x ,u 0, h x,0 , x h x,0 x n x x 0 x x 13 23 3x 2 : h x,1 1 g 1, h x,1, x f u 1, h x,1, x ,u 1, h x,1, x 3 23 3 h x,1 x g 0, h x,0 , x x f u 0, h x,0 , x ,u 0, h x,0 , x 3 2 x h x,0 x x n x x x 0 x x x 23 3 19. Example 03Show that f(x) = x! is primitive recursive. 20. 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! 21. Example 03: Using Formal DefinitionBase Case : f 0 0 becomes h0 s nx 22. Example 03: Using Formal Definition Recursive Case : f x 1 s x f x becomesh x 1 g x, h x , where g x1 , x2 f u x1 , x2 , u x1 , x2 and f x1 , x2 s x1 x22 12 2 23. Example 03: Using Formal DefinitionCombining the base and recursive cases, we get : h0 s n x h x 1 g x, h x , whereg x1 , x 2 s u x1 , x 2 u x1 , x 2 2 12 2 24. Example 03: Checking Our Solution 0!: h0 s nx s 0 11!: h0 1 g 0, h0 s u 1 0, h0 u 2 0, h0 s 0 h0 22 1 1 12!: h1 1 g 1, h1 s u 1 1, h1 u 2 1, h1 s 1 h1 22 2 1 23!: h2 1 g 2, h2 s u 1 2, h2 u 2 2, h2 s 2 h2 3 2 622 25. Example 04Show that xy is primitive recursive. 26. Example 04f x,0 x 1 0f x, y 1 xy 1 x x y 27. Example 04 Base Case : f x,0 0 becomes h x,0 s n x Re cursive Case : f x, y 1 becomes h x, y 1 g y, h x, y , x , where g x1 , x 2 , x3 u x1 , x 2 , x3 u x1 , x 2 , x3 3 23 3 28. Example 04: Checking Our Solution h x,0 s n x 1 3 3 h x,0 1 g 0, h x,0 , x u 2 0, h x,0 , x u3 0, h x,0 , x h x,0 x 1 x x3 3 h x,1 1 g 1, h x,1, x u2 1, h x,1, x u3 1, h x,1, x h x,1 x x x x 2 29. Example 05 Show that the predecessor function is primitive recursive : if x 0 0 px x 1 if x 1 30. Example 05 Informal insight : p 0 0 p t 1 t Formal derivation : h0 0 ht 1 g t , ht , where g x1 , x 2 u12 x1 , x 2 31. Example 06: Dot Minus x0 x x y if x y x y if x y 0 32. Example 06 Show that the dot minus function is primitive recursive x0 x x y 1 p x y x 0 1 p x 0 p x x 1 1 p x 1 p x 0 1 p p x 0 p p x 33. Example 06 2 3 p 2 2 p p 2 1 p p p 2 p p 1 p 0 0 3 1 p 3 0 p 3 2 p p p 2 0 34. Example 07Show that |x-y| is primitive recursive. 35. Example 071. is primitive recursive 2. is primitive recursive 3. x y x y y x 36. Primitive Recursive Predicates 37. Motivation Predicates are Boolean-valued functions 1 is TRUE0 is FALSESince 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 38. Example 01Show that ( x) is primitive recursive 1 if x 0 ( x) 0 if x 0 39. Example 02 Informal recurrences : (0) 1 (t 1) 0 Formal recurrences : h0 1 ht 1 g t , ht , where g x1 , x 2 n x1 40. Example 02A more elegant solution : ( x) 1 x 41. Example 03Show that x = y is primitive recursive. 42. Example 031 if x y d x, y 0 if x y 43. Example 03d x, y is primitive recursive, because d x, y | x y | 44. Example 04Show that x y is primitive recursive. 45. Example 04x y if and only if x y 0 if and only if x y 1 46. Theorem 5.1 (Ch. 3): Compound PredicatesLet C be a PRC class. If P, Q are predicates that belong to C , then so are P, P Q, and P &amp; Q. 47. Proof 5.1 (Ch. 3)1. P P 2. P Q P Q3. P Q P Q 48. 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 49. Corollary 5.2a (Ch. 3) Claim : If P and Q are computable predicates, then so are P, P Q, P Q. Proof : True, because computable functions are a PRC class. 50. Corollary 5.2b (Ch. 3) Claim : If P and Q are primitive recursive predicates, then so are P, P Q, P Q. Proof : True, because primitive recursive functions are a PRC class. 51. Reading Suggestions Chapters 2 &amp; 3, Computability, Complexity, &amp; Languages by Davis, Weyuker, Sigal </p>

Recommended

View more >