Upcoming SlideShare
×

# Theory of Computation: Examples of Primitive Recursive Functions & Primitive Recursive Predicates

650 views
554 views

Published on

Examples of Primitive Recursive Functions & Primitive Recursive Predicates

Published in: Science, Spiritual
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
650
On SlideShare
0
From Embeds
0
Number of Embeds
304
Actions
Shares
0
5
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Theory of Computation: Examples of Primitive Recursive Functions & Primitive Recursive Predicates

1. 1. Theory of Computation Examples of Primitive Recursive Functions & Predicates Vladimir Kulyukin www.vkedco.blogspot.com
2. 2. Outline ● ● ● ● Review Primitive Recursive Functions Primitive Recursive Predicates Compound Primitive Recursive Predicates
3. 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. 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. 5. 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
6. 6. Question How can we show that a function is primitive recursive?
7. 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. 8. Example 01 Show that f(x,y) = x + y is primitive recursive.
9. 9. 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!
10. 10. Example 01: Using Formal Definition Base Case : f  x,0   x becomes h x,0   u  x,0  2 1
11. 11. Example 01: Using Formal Definition Recursive Case : f  x, t  1  f  x, t   1 becomes   h x, t  1  s u t , h x, t , x  . 3 2 Or, more formally, h x, t  1  g t , h x, t , x , where   g  x1 , x 2 , x3   s u  x1 , x 2 , x3  3 2
12. 12. Example 01: Using Formal Definition Combining the base and recursive cases, we get : hx,0   u  x,0  2 1 hx, t  1  g t , h x, t , x , where   g  x1 , x 2 , x3   s u  x1 , x 2 , x3  3 2
13. 13. Example 02 Show that f(x,y) = x · y is primitive recursive.
14. 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) + 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!
15. 15. Example 02: Using Formal Definition Base Case : f  x,0   0 becomes h x,0   n x 
16. 16. Example 02: Using Formal Definition Recursive Case : f  x, t  1  f  x, t   x becomes h x, t  1  u t , h x, t , x   x 3 2 Or, more formally, h x, t  1  g t , h x, t , x , where   g  x1 , x 2 , x3   f u  x1 , x 2 , x3 , u  x1 , x 2 , x3  , where f  x1 , x 2   x1  x 2 3 2 3 3
17. 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 , where   g  x1 , x 2 , x3   f u  x1 , x 2 , x3 ,u x1 , x 2 , x3  , where f  x1 , x 2   x1  x 2 3 2 3 3
18. 18. Example 02: Checking Our Solution x  0 : h x,0   n x   0  x  0   x  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  1  3 2 3 3  x  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 2  3 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  2 3 3
19. 19. Example 03 Show that f(x) = x! is primitive recursive.
20. 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. 21. Example 03: Using Formal Definition Base Case : f 0  0 becomes h0   s nx 
22. 22. Example 03: Using Formal Definition Recursive Case : f  x  1  s x   f  x  becomes h x  1  g  x, h x , where g  x1 , x2   f u x1 , x2 , u  x1 , x2  and f  x1 , x2   s x1   x2 2 1 2 2
23. 23. Example 03: Using Formal Definition Combining the base and recursive cases, we get : h0   s n x  h x  1  g x, h x , where   g  x1 , x 2   s u  x1 , x 2  u  x1 , x 2  2 1 2 2
24. 24. Example 03: Checking Our Solution 0!: h0   s nx   s 0   1   1!: h0  1  g 0, h0   s u 1 0, h0  u 2 0, h0   s 0   h0  2 2  1 1  1   2!: h1  1  g 1, h1  s u 1 1, h1 u 2 1, h1  s 1  h1 2 2  2 1  2   3!: h2  1  g 2, h2   s u 1 2, h2  u 2 2, h2   s 2   h2   3  2  6 2 2
25. 25. Example 04 Show that xy is primitive recursive.
26. 26. Example 04 f  x,0   x  1 0 f  x, y  1  x y 1  x x y
27. 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 2 3 3
28. 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  x 3 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. 29. Example 05 Show that the predecessor function is primitive recursive : if x  0 0 px     x  1 if x  1
30. 30. Example 05 Informal insight : p 0   0 p t  1  t Formal derivation : h0   0 ht  1  g t , ht , where g  x1 , x 2   u12  x1 , x 2 
31. 31. Example 06: Dot Minus  x0  x  x  y if x  y x y   if x  y 0 
32. 32. Example 06 Show that the dot minus function is primitive recursive  x0  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. 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. 34. Example 07 Show that |x-y| is primitive recursive.
35. 35. Example 07 1.  is primitive recursive  2.  is primitive recursive     3. x  y   x  y    y  x       
36. 36. Primitive Recursive Predicates
37. 37. 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
38. 38. Example 01 Show that  ( x) is primitive recursive 1 if x  0  ( x)   0 if x  0
39. 39. Example 02 Informal recurrences :  (0)  1  (t  1)  0 Formal recurrences : h0   1 ht  1  g t , ht , where g  x1 , x 2   n x1 
40. 40. Example 02 A more elegant solution :   ( x)  1  x
41. 41. Example 03 Show that x = y is primitive recursive.
42. 42. Example 03 1 if x  y d  x, y    0 if x  y
43. 43. Example 03 d  x, y  is primitive recursive, because d  x, y    | x  y |
44. 44. Example 04 Show that x ≤ y is primitive recursive.
45. 45. Example 04 x y if and only if x  y  0 if and only if   x  y   1 
46. 46. Theorem 5.1 (Ch. 3): Compound Predicates Let C be a PRC class. If P, Q are predicates that belong to C , then so are P, P  Q, and P & Q.
47. 47. Proof 5.1 (Ch. 3) 1. P   P  2. P  Q  P  Q 3. P  Q  P  Q 
48. 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. 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. 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. 51. Reading Suggestions ● Chapters 2 & 3, Computability, Complexity, & Languages by Davis, Weyuker, Sigal