Upcoming SlideShare
×

# Theory of Computation: Lecture 20

• 682 views

1) What is a Universal Program? …

1) What is a Universal Program?
2) Encoding Program States
3) Universality Theorem
4) Developing Universal Programs

More in: Education , Technology
• Comment goes here.
Are you sure you want to
Be the first to comment
Be the first to like this

Total Views
682
On Slideshare
0
From Embeds
0
Number of Embeds
16

Shares
0
0
Likes
0

No embeds

### Report content

No notes for slide

### Transcript

• 1. CS 5000: Theory of Computation Lecture 20 Vladimir Kulyukin Department of Computer Science Utah State Universitywww.youtube.com/vkedco www.vkedco.blogspot.com
• 2. Outline ●Review ●What is a Universal Program? ●Encoding Program States ●Universality Theorem ●Developing Universal Programswww.youtube.com/vkedco www.vkedco.blogspot.com
• 4. Review: GÖDEL Decoder # ( P ) = [ # ( I 1 ) , # ( I 2 ) ,..., # ( I k ) ] − 1. Thus, the source code number is [ # ( I 1 ) , # ( I 2 ) ,..., # ( I k ) ] =# ( P ) + 1.www.youtube.com/vkedco www.vkedco.blogspot.com
• 5. Review: GÖDEL Decoding Algorithm 1. Let n be # ( P ) = [ # ( I 1 ) , # ( I 2 ) ,..., # ( I k ) ] − 1 So, the source code number is n + 1 = [ # ( I 1 ) , # ( I 2 ) ,..., # ( I k ) ]. 2. Run Factors( n + 1,1) 3. Obtain the G - number from the list of prime factors, i.e. get the sequence of prime powers 4. Extract the source code from each element of the G - number obtained in step 3www.youtube.com/vkedco www.vkedco.blogspot.com
• 6. Review: GÖDEL Decoding Example 1. Let #(P) = 199 2. The source code number = 199+1=200 3. The prime factorization of 200 is 233052; Thus, the G-number = [3,0,2] 4. 3 = <2, <0, 0>>; so the label is B1, the instruction variable is Y and the type of instruction is self- assignment; Thus, first instruction is [B1] Y ← Y 5. 0 = <0, <0, 0>>. Thus, second instruction is Y ← Y 6. 2 = <0, <1, 0>>. Thus, third instruction is Y ← Y + 1www.youtube.com/vkedco www.vkedco.blogspot.com
• 7. Review: GÖDEL Decoding Example Let #(P) = 199. The source code number = 199+1=200. So, the source code of P is [B1] Y ← Y Y← Y Y← Y+1www.youtube.com/vkedco www.vkedco.blogspot.com
• 8. Review: The Big Picture Number GÖDEL Coder L Program Number Universal Program GÖDEL Decoder ??? GÖDEL Coder = Compiler GÖDEL Decoder = Reverse Compiler Universal Program = Operating System/VM/Interpreterwww.youtube.com/vkedco www.vkedco.blogspot.com
• 9. Developing Universal Programswww.youtube.com/vkedco www.vkedco.blogspot.com
• 10. Universal Programs ●For each n > 0, such a program is denoted by Un and is called universal because it can run any program of n arguments ●We have a sequence of universal programs: U1, U2, U3, U4, …www.youtube.com/vkedco www.vkedco.blogspot.com
• 11. Review: The Value of Y (m) Ψ P (r1 , r2 ,..., rm ) is the value of Y at the terminal snapshotwww.youtube.com/vkedco www.vkedco.blogspot.com
• 12. Universal Programs: Definition For each n > 0, Φ (n) ( x1 ,..., x n , y ) = Ψ ( x1 ,..., x n ), (n) P where # ( P ) = ywww.youtube.com/vkedco www.vkedco.blogspot.com
• 13. Universal Programs: Definition For each n > 0, Ψ ( n +1) Un ( x1 ,..., xn , xn+1 ) = Φ ( x1 ,..., xn , xn+1 ) (n)www.youtube.com/vkedco www.vkedco.blogspot.com
• 14. Example Let U 1 is a universal program that computes any partially computable function of 1 variable. Let f ( x ) be computed by a program P whose number is y (that compiles into y ) , then ( ∀x ) f ( x ) = Φ ( x, y ) = Ψ ( x, y ). (1) ( 2) U1www.youtube.com/vkedco www.vkedco.blogspot.com
• 15. What Does Un Do? ●Un is given the number of a program y, i.e., a compiled program ●From that number y, U n extracts instructions one by one and executes them ●U keeps track of the state of the program n ●Un runs the instruction counterwww.youtube.com/vkedco www.vkedco.blogspot.com
• 16. Review: Variable and Label Orderings ●The variables are ordered as follows: –Y X1 Z1 X2 Z2 X3 Z3 … ●The labels are ordered as follows: –A1 B1 C1 D1 E1 A2 B2 C2 D2 E2 A3 … ●#(Y)=1, #(X1)=2, #(X3)=6, #(Z2)=5 ●#(B1)=2, #(A2)=6, #(C2)=8www.youtube.com/vkedco www.vkedco.blogspot.com
• 17. Program State and Instruction Counter The state of the program is encoded as a G - number. The positions of the input variables in the G - number are even. The position Y is 1 and the positions of the internal variables are odd. For example, State : {Y = 0, X 1 = 2, Z 1 = 0, X 2 = 1, Z 2 = 0}. G - number : [ 0,2,0,1,0] = [ 0,2,0,1] = 3 2 ⋅ 7 = 63. Let S be the G - number that encodes the state. Let K be the number of the program s instruction to be executed.www.youtube.com/vkedco www.vkedco.blogspot.com
• 18. Program State The idea is that the program state is a G - number. For example, let the program state S = [ a1 , a 2 ,..., a n ]. Each ai encodes the value of a program variable so that : a1 always encodes the value of Y if i > 1 and i is even, then ai encodes the value of X i / 2 if i > 1 and i is odd, then ai encodes the value of Z ( i −1) / 2 a 2 is the value of X 2 / 2 = X 1 ; a3 is the value of Z ( 3−1) / 2 = Z 1 a 4 is the value of X 4 / 2 = X 2 ; a5 is the value of Z ( 5−1) / 2 = Z 2 a 6 is the value of X 6 / 2 = X 3 ; a 7 is the value of Z ( 7 −1) / 2 = Z 3www.youtube.com/vkedco www.vkedco.blogspot.com
• 19. Example State : {Y = 0, X 1 = 2, Z1 = 11, X 2 = 4, Z 2 = 31} G - number : [ 0,2,11,4,31] = 2 ⋅ 3 ⋅ 5 ⋅ 7 ⋅11 0 2 11 4 31www.youtube.com/vkedco www.vkedco.blogspot.com
• 20. Theorem 3.1 (Ch. 4) For each n > 0, the function Φ (n) ( x1 ,..., xn , y ) is partially computablewww.youtube.com/vkedco www.vkedco.blogspot.com
• 21. Back To The Big Picture Number GÖDEL Coder L Program Number Universal Program GÖDEL Decoder ??? GÖDEL Coder = Compiler GÖDEL Decoder = Reverse Compiler Universal Program = Operating System/VM/Interpreterwww.youtube.com/vkedco www.vkedco.blogspot.com
• 22. Theorem 3.1 (Ch. 4): A Perspective ●What is the significance of Theorem 3.1 (Universality Theorem)? ●This theorem gives a mathematical proof of the feasibility of operating systems and interpreters ●Modern operating systems and interpreters, e.g. Windows, Linux, Java Virtual Machine, owe their existence to the Universality Theoremwww.youtube.com/vkedco www.vkedco.blogspot.com
• 23. Theorem 3.1: Proof To prove Theorem 3.1, we will show how, for each n > 0, we can construct U n that computes the following function : Y =Φ (n) ( X 1 ,..., X n , X n+1 )www.youtube.com/vkedco www.vkedco.blogspot.com
• 24. Un Construction: Part 1 1.Extract the source code 2.Initialize the state 3.Initialize the instruction counterwww.youtube.com/vkedco
• 25. Un Construction: Part 1 // This program computes Y = Φ ( n ) ( X 1 ,..., X n , X n +1 ) , where X 1 ,..., X n // are the input variables and X n +1 is a program number. Z ← X n +1 + 1 // 1. Extract the source code. // S is the initial state of the program. S is technically not a legal L variable. // But it is more meaningful. We can always rename it into Z with some // appropriate subscript if we have to. n S ← ∏ ( p 2i ) Xi // 2. Initialize the program state. i =1 // K is the instruction counter. Technically, K is not a legal // L variable. But we can rename it if we have to. K ←1 // 3. Initialize the instruction counter.www.youtube.com/vkedco www.vkedco.blogspot.com
• 26. Reading Suggestions ●Ch. 4, Computability, Complexity, and Languages, 2nd Edition, by Davis, Weyuker, Sigal ●http://en.wikipedia.org/wiki/Kurt_Gödelwww.youtube.com/vkedco www.vkedco.blogspot.com