Presentation is loading. Please wait.

Presentation is loading. Please wait.

Theory of Computation Lecture 6: Primitive Recursive Functions I

Similar presentations


Presentation on theme: "Theory of Computation Lecture 6: Primitive Recursive Functions I"— Presentation transcript:

1 Theory of Computation Lecture 6: Primitive Recursive Functions I
Sample Questions Question 1: Write a program P that computes P(1)(r) = r-2 using no macros. Notice that we only consider natural numbers! This means that, for example, the expression (1-2) is undefined. Any program computing such an expression must never halt. Sample solution: X  X-1 IF X0 GOTO A2 [A1] Z  Z+1 IF Z0 GOTO A1 [A2] X  X-1 Y  Y+1 IF X  0 GOTO A2 Y  Y-1 September 21, 2017 Theory of Computation Lecture 6: Primitive Recursive Functions I

2 Theory of Computation Lecture 6: Primitive Recursive Functions I
Sample Questions Question 2: a) Write a program S that computes S(1)(r) = r Use a macro based on program P of the form W  p(V) (which has the effect W  V-2). Sample solution: Y  p(X) Y  p(Y) September 21, 2017 Theory of Computation Lecture 6: Primitive Recursive Functions I

3 Theory of Computation Lecture 6: Primitive Recursive Functions I
Sample Questions b) Now comes the best part: Expand all macros in S using the method we discussed in the lecture. Z2  0 // expansion of Y  p(X) with m = 2 Z3  X Z4  0 Z3  Z3-1 IF Z30 GOTO A4 [A3] Z4  Z4-1 IF Z40 GOTO A3 [A4] Z3  Z3-1 Z2  Z2+1 Z2  Z2-1 Y  Z2 Z5  0 // exp. of Y  p(Y) with m = 5 Z6  Y Z7  0 Z6  Z6-1 IF Z60 GOTO A7 [A6] Z7  Z7+1 IF Z70 GOTO A6 [A7] Z6  Z6-1 Z5  Z5+1 Z5  Z5-1 Y  Z5 September 21, 2017 Theory of Computation Lecture 6: Primitive Recursive Functions I

4 (Partially) Computable Functions
By introducing macros, we have seen that it is possible to compute complex functions with our very simple programming language L . Notice that macros do not change the specification of the language, but they just simplify writing down programs. As you know, we can always replace macros with actual code. So what are the limitations of the language L ? In order to find out, we need to do some mathematics. September 21, 2017 Theory of Computation Lecture 6: Primitive Recursive Functions I

5 Theory of Computation Lecture 6: Primitive Recursive Functions I
Composition Let us combine computable functions in such a way that the output of one becomes an input to another. For example, we could combine the functions f and g to obtain a new function h: h(x) = f(g(x)) Let us now take a more general view: Definition: Let f be a function of k variables and let g1, …, gk be functions of n variables. Let h(x1, …, xn) = f(g1(x1, …, xn), …, gk(x1, …, xn)). Then h is said to be obtained from f and g1, …, gk by composition. September 21, 2017 Theory of Computation Lecture 6: Primitive Recursive Functions I

6 Theory of Computation Lecture 6: Primitive Recursive Functions I
Composition Theorem 1.1: If h is obtained from the (partially) computable functions f, g1, …, gk by composition, then h is (partially) computable. Proof: The following program obviously computes h: Z1 ← g1(X1, …, Xn) : Zk ← gk(X1, …, Xn) Y ← f(Z1, …, Zk) If f, g1, …, gk are not only partially computable but are also total, then so is h ■ September 21, 2017 Theory of Computation Lecture 6: Primitive Recursive Functions I

7 Theory of Computation Lecture 6: Primitive Recursive Functions I
Composition Let us combine computable functions in such a way that the output of one becomes an input to another. For example, we could combine the functions f and g to obtain a new function h: h(x) = f(g(x)) Let us now take a more general view: Definition: Let f be a function of k variables and let g1, …, gk be functions of n variables. Let h(x1, …, xn) = f(g1(x1, …, xn), …, gk(x1, …, xn)). Then h is said to be obtained from f and g1, …, gk by composition. September 21, 2017 Theory of Computation Lecture 6: Primitive Recursive Functions I

8 Theory of Computation Lecture 6: Primitive Recursive Functions I
Composition Theorem 1.1: If h is obtained from the (partially) computable functions f, g1, …, gk by composition, then h is (partially) computable. Proof: The following program obviously computes h: Z1 ← g1(X1, …, Xn) : Zk ← gk(X1, …, Xn) Y ← f(Z1, …, Zk) If f, g1, …, gk are not only partially computable but are also total, then so is h ■ September 21, 2017 Theory of Computation Lecture 6: Primitive Recursive Functions I


Download ppt "Theory of Computation Lecture 6: Primitive Recursive Functions I"

Similar presentations


Ads by Google