October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 1Universality Then we append the following instruction: [C]IF K = Lt(Z) + 1 K = 0 GOTO F So if the computation has ended, GOTO F, where the proper value will be output. Otherwise, the current instruction is decoded and executed: U r((Z) K ) P p r(U)+1 Remember that (Z) K = a, b, c is the number of the K-th instruction. So U = b, c is the code of the statement to be executed. The variable mentioned in this statement is the (c + 1)-th, i.e., the (r(U) + 1)-th.
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 2Universality Then l(U) contains the type of the instruction to be executed. IF l(U) = 0 GOTO N IF l(U) = 1 GOTO A IF (P | S) GOTO N IF l(U) = 2 GOTO M If either the instruction is V V, or the instruction is V V-1 and V = 0 (as indicated by the absence of P in S), or the instruction is IF V 0 GOTO L and V = 0, then nothing is done to S (“nothing” - GOTO N). If the instruction is V V+1, then the exponent of P in S needs to be incremented (“add” – GOTO A). If the instruction is V V-1 with V > 0, then the exponent of P in S needs to be decremented (“minus” – GOTO M).
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 3Universality If none of the four previous predicates were true, a GOTO command has to be executed: K min i Lt(Z) [l((Z) i ) + 2 = l(U)] GOTO C So if the label l(U) – 2 exists in the program, the number K of the next instruction to be executed will be set to the first instruction with that label. Otherwise, K will be set to 0. As you remember, if K = 0 or K = Lt(Z) + 1, then the computation stops. In any case, our interpreter program executes a GOTO C to execute the next instruction.
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 4Universality The program continues as follows: [M]S S/P GOTO N [A]S S P [N]K K+1 GOTO C The value of the variable in the current instruction is decremented or incremented by 1 by dividing or multiplying S by P, respectively. Then K is incremented and the next instruction executed.
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 5Universality The program concludes with the following line: [F]Y (S) 1 This way, after termination of the interpreted program, its output value becomes the output value of the interpreter. On the next slide, we will list the entire interpreter program.
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 6Universality Z X n S n i=1 (p 2i ) X i K 1 [C]IF K = Lt(Z) + 1 K = 0 GOTO F U r((Z) K ) P p r(U)+1 IF l(U) = 0 GOTO N IF l(U) = 1 GOTO A IF (P | S) GOTO N IF l(U) = 2 GOTO M K min i Lt(Z) [l((Z) i ) + 2 = l(U)] GOTO C [M]S S/P GOTO N [A]S S P [N]K K+1 GOTO C [F]Y (S) 1
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 7Universality For each n > 0, the sequence (n) (x 1, …, x n, 0), (n) (x 1, …, x n, 1), … enumerates all partially computable functions of n variables. We can also write: y (n) (x 1, …, x n ) = (n) (x 1, …, x n, y). We can omit the superscript (n) when n = 1: y (x) = (x, y) = (1) (x, y).
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 8Universality Consider the following predicates: STP (n) (x 1, …, x n, y, t) Program number y halts after t or fewer steps on inputs x 1, …, x n There is a computation of program y of length t + 1, beginning with inputs x 1, …, x n These predicates are computable, which we can easily prove: We can simply add a counter to our universal programs to determine when we have simulated t steps.
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 9Universality Consider the following predicates: STP (n) (x 1, …, x n, y, t) Program number y halts after t or fewer steps on inputs x 1, …, x n There is a computation of program y of length t + 1, beginning with inputs x 1, …, x n These predicates are computable, which we can easily prove: We can simply add a counter to our universal programs to determine when we have simulated t steps.
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 10Universality We can prove an even stronger theorem: Theorem 3.2 (Step-Counter Theorem): For each n > 0, the predicate STP (n) (x 1, …, x n, y, t) is primitive recursive. Proof: We will provide numerical descriptions of the notions of snapshot and successor snapshot. This will show that the necessary functions are primitive recursive. See pages 74 and 75 in the textbook for the proof.
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 11Universality Now that we know the Step-Counter Theorem, we are ready for yet another theorem. Proving this theorem will be similar to the last one. Theorem 3.3 (Normal Form Theorem): Let f(x 1, …, x n ) be a partially computable function. Then there is a primitive recursive predicate R(x 1, …, x n, y) such that f(x 1, …, x n ) = l(min z R(x 1, …, x n, z))
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 12UniversalityProof: Let y 0 be the number of a program that computes f(x 1, …, x n ). Then consider the equation f(x 1, …, x n ) = l(min z R(x 1, …, x n, z)), where R(x 1, …, x n, z) is the predicate STP (n) (x 1, …, x n, y 0, r(z)) & (r(SNAP (n) (x 1, …, x n, y 0, r(z)))) 1 = l(z) If the right side of the first equation is defined, then there exists a number z such that STP (n) (x 1, …, x n, y 0, r(z)) and (r(SNAP (n) (x 1, …, x n, y 0, r(z)))) 1 = l(z)
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 13Universality For any such z, the computation by the program with number y 0 has reached a terminal snapshot in r(z) or fewer steps, the computation by the program with number y 0 has reached a terminal snapshot in r(z) or fewer steps, l(z) is the value of the output variable Y, that is, l(z) = f(x 1, …, x n ). l(z) is the value of the output variable Y, that is, l(z) = f(x 1, …, x n ). If the right side of the equation is undefined, it must be true that STP (n) (x 1, …, x n, y 0, t) is false for all values of t, that is, f(x 1, …, x n ) is undefined.
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 14Universality Theorem 3.4: A function is partially computable if and only if it can be obtained from the initial functions by a finite number of applications of composition, recursion, and minimalization. Proof: It follows from Theorems 1.1, 2.1, 2.2, 3.1, and 7.2 in Chapter 3 that every function that can be so obtained is partially computable.
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 15Universality Now let us consider the “opposite direction” of the Normal Form Theorem (Theorem 3.3): We can use the normal form theorem to write any given partially computable function in the form l(min y R(x 1, …, x n, y)), where R is a primitive recursive predicate and therefore is obtained from the initial functions by a finite number of applications of composition and recursion. Finally, our given function is obtained from R by one use of minimalization and then by composition with the primitive recursive function l.
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 16Universality When min y R(x 1, …, x n, y)) is a total function (that is, when for each x 1, …, x n there is at least one y for which R(x 1, …, x n, y) is true), we say that we are applying the operation of proper minimalization to R. Now, if l(min y R(x 1, …, x n, y)) is total, then min y R(x 1, …, x n, y) must be total. This gives us the following theorem: Theorem 3.5: A function is computable if and only if it can be obtained from the initial functions by a finite number of applications of composition, recursion, and proper minimalization.
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 17 Recursively Enumerable Sets From previous classes, such as CS 320, you may remember the correspondence between predicates and sets. We now want to use the set notation in our discussion of solvable and unsolvable problems. For example, the predicate HALT(x, y) is the characteristic function of the set {(x, y) N 2 | HALT(x, y)}. We say that a set B N m belongs to some class of functions if and only if the characteristic function P(x 1, …, x n ) of B belongs to the class in question.
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 18 Recursively Enumerable Sets Thus, saying that a set B is computable or recursive is the same as saying that P(x 1, …, x n ) is a computable function. Likewise, B is a primitive recursive set if P(x 1, …, x n ) is a primitive recursive predicate. It follows that: Theorem 4.1: Let the sets B, C belong to some PRC class C. Then so do the sets B C, B C, B. Proof: This is an immediate consequence of Theorem 5.1, Chapter 3.