CS 5000: Theory of Computation                          Lecture 21                    Vladimir Kulyukin             Depart...
Outline    ●        Review    ●        Developing Universal Programs    ●        Part 01: Source Code Extraction, Encoding...
Reviewhttp://www.youtube.com/vkedco       www.vkedco.blogspot.com
Review: Variable and Label Orderings   ●       The variables are ordered as follows:       – Y X1 Z1 X2 Z2 X3 Z3 …   ●    ...
Review: The Big Picture                                                                         Number                 GÖD...
Developing Universal Programshttp://www.youtube.com/vkedco   www.vkedco.blogspot.com
Review: Theorem 3.1 (Ch. 4)       For each n > 0, the function Φ   (n)                                              ( x1 ,...
Review: Proof 3.1      To prove Theorem 3.1, we will show how,      for each n > 0, we can construct U n that      compute...
Part 01     Source Code Instruction, Encoding    Program State, Initializing Instruction                 Counterhttp://www...
Review: Program State and Instruction Counter        The state of the program is encoded as a G - number.        The posit...
Review: Program State    The idea is that the program state is a G - number. For example, let    the program state S = [ a...
Review: Un Construction: Part 1   1. Extract the source code   2. Initialize the state   3. Initialize the instruction cou...
Review: Un Construction: Part 1        // This program computes Y = Φ ( n ) ( X 1 ,..., X n , X n +1 ) , where X 1 ,..., X...
Part 02      Establishing Termination Conditionhttp://www.youtube.com/vkedco   www.vkedco.blogspot.com
Un Construction: Part 2   • The next thing that Un must do is check for the     termination condition   • The termination ...
Un Construction: Part 2         [ C ] IF K = Lt ( Z ) + 1 ∨ K = 0 GOTO E         // [ C ] is the CONTINUE label.         /...
Part 03             Decoding Next Instructionhttp://www.youtube.com/vkedco   www.vkedco.blogspot.com
Un Construction: Part 3   • The next thing that Un must do is decode the next     instruction to be executed   • Remember ...
Un Construction: Part 3     ( Z ) K is the current   instruction s number (prime power)     ( Z) K = a, b, c     a = # ( L...
Un Construction: Part 3      U = r ( ( Z ) K ) = b, c      c = r (U ) =# ( V ) − 1      # (V ) = r (U ) + 1      V is the ...
Example 1     Assume that S = [ 0,2,0,1] = 3 2 ⋅ 7 = 63.     Assume that U = b,1 . Then     r ( U ) = c = 1 = # ( V ) − 1....
Example 2     Let S = [ 0,2,0,1] = 3 ⋅ 7 = 63. Let U = b,2 .                                2     Then r (U ) = c = 2 =# (...
Example 3         Assume that S = [ 0,2,0,1] = 3 ⋅ 7 = 63.   2         Let U = b,3 . Then r (U ) = c = 3 =# (V ) − 1.     ...
Un Construction: Part 3   // I = ( Z ) K = a, b, c ; K - th instruction   // U = b, c ; the right part of the K - th instr...
Un Construction: So Far      Z ← X n +1 + 1         // Z is the source code              n         Xi      S ← ∏ ( p 2i ) ...
Part 04    Determining Type of Next Instructionhttp://www.youtube.com/vkedco   www.vkedco.blogspot.com
Un Construction: Part 4   • The next thing that Un must do is to     determine the type of the next instruction to     be ...
Un Construction: Part 4     // I = ( Z ) K = a, b, c ; U = r ( ( Z ) K ) = b,c ; l (U ) = b.     IF l (U ) = 0 GOTO N     ...
Un Construction: Part 4          // I = ( Z ) K = a, b, c ;U = r ( ( Z ) K ) = b, c ; l (U ) = b.          IF l (U ) = 1 G...
Un Construction: Part 4   • Un now has to check if the instruction is     subtraction   • However, if we know that the val...
Observation           Let S be a program state. Recall that S is a G - number.           Then pi | S if and only if ( S ) ...
Un Construction: Part 4          // If ¬( P | S ), the value of the variable          // in the instruction is 0. We do no...
Un Construction: Part 4          // If l (U ) = 2, the instruction type is subtraction.          // We dispatch to the sub...
Un Construction So Far           Z ← X n +1 +1 // Get the source number.                  n           S ← ∏( p2i ) i // En...
Reading Suggestions    ●        Ch. 4, Computability, Complexity, and        Languages, 2nd Edition, by Davis, Weyuker, Si...
Feedback      Errors, comments to vladimir dot kulyukin at gmail dot comhttp://www.youtube.com/vkedco         www.vkedco.b...
Upcoming SlideShare
Loading in …5
×

Theory of Computation: Lecture 21: Developing Universal Programs, Source Code Extraction, Termination Condition of Universal Programs, Instruction Decoding

833 views

Published on

1) Developing universal programs
2) Source code extraction
3) Encoding program state and instruction counters
4) Establishing termination condition
5) Decoding next instruction and determining next instruction's type

Published in: Science, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
833
On SlideShare
0
From Embeds
0
Number of Embeds
290
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Theory of Computation: Lecture 21: Developing Universal Programs, Source Code Extraction, Termination Condition of Universal Programs, Instruction Decoding

  1. 1. CS 5000: Theory of Computation Lecture 21 Vladimir Kulyukin Department of Computer Science Utah State Universityhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  2. 2. Outline ● Review ● Developing Universal Programs ● Part 01: Source Code Extraction, Encoding Program State, Initializing Instruction Counter ● Part 02: Establishing Termination Condition ● Part 03: Decoding Next Instruction ● Part 04: Determining Next Instructions Typehttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  3. 3. Reviewhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  4. 4. 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)=8http://www.youtube.com/vkedco www.vkedco.blogspot.com
  5. 5. 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/Interpreterhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  6. 6. Developing Universal Programshttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  7. 7. Review: Theorem 3.1 (Ch. 4) For each n > 0, the function Φ (n) ( x1 ,..., xn , y ) is partially computablehttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  8. 8. Review: Proof 3.1 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 )http://www.youtube.com/vkedco www.vkedco.blogspot.com
  9. 9. Part 01 Source Code Instruction, Encoding Program State, Initializing Instruction Counterhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  10. 10. Review: 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.http://www.youtube.com/vkedco www.vkedco.blogspot.com
  11. 11. Review: 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 3http://www.youtube.com/vkedco www.vkedco.blogspot.com
  12. 12. Review: Un Construction: Part 1 1. Extract the source code 2. Initialize the state 3. Initialize the instruction counterhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  13. 13. Review: 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.http://www.youtube.com/vkedco www.vkedco.blogspot.com
  14. 14. Part 02 Establishing Termination Conditionhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  15. 15. Un Construction: Part 2 • The next thing that Un must do is check for the termination condition • The termination condition occurs when the instruction counter is I+1 or 0, where I=Lt(Z) is the number of instructions in the source code • The instruction counter is 0 when the program is dispatched to a label that does not exist • We can easily find out the value of I, because we know how to compute the length of a G-numberhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  16. 16. Un Construction: Part 2 [ C ] IF K = Lt ( Z ) + 1 ∨ K = 0 GOTO E // [ C ] is the CONTINUE label. // Note that C is not a legal L variable, but can be // made into one by using a Z with an appropriate // subscript. // E is the usual EXIT label.http://www.youtube.com/vkedco www.vkedco.blogspot.com
  17. 17. Part 03 Decoding Next Instructionhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  18. 18. Un Construction: Part 3 • The next thing that Un must do is decode the next instruction to be executed • Remember that the source code has no macros! All macros are assumed to have been expanded • The source code contains only primitive L instructions • Recall that an instruction is defined by three components: – the label – the instruction type – the variablehttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  19. 19. Un Construction: Part 3 ( Z ) K is the current instruction s number (prime power) ( Z) K = a, b, c a = # ( L) b is the type of instruction c =# (V ) − 1.http://www.youtube.com/vkedco www.vkedco.blogspot.com
  20. 20. Un Construction: Part 3 U = r ( ( Z ) K ) = b, c c = r (U ) =# ( V ) − 1 # (V ) = r (U ) + 1 V is the variable in position r (U ) + 1 in our variable ordering What is p r ( U ) +1 ? p r ( U ) +1 is a prime P such that P v | S , where v = ( S ) r ( U ) +1 , i.e. v is the value of V .http://www.youtube.com/vkedco www.vkedco.blogspot.com
  21. 21. Example 1 Assume that S = [ 0,2,0,1] = 3 2 ⋅ 7 = 63. Assume that U = b,1 . Then r ( U ) = c = 1 = # ( V ) − 1. r (U ) + 1 = 2, which is the # of X 1 in our variable ordering (Y , X 1 , Z 1 ...). Thus, V = X 1 . p r ( U ) +1 = p 2 = 3. Let v be the value of V , i.e. of X 1 . Then v = ( S ) r ( U ) +1 = ( S ) 2 = 2. So, X 1 = 2 and note that 3 2 | 63.http://www.youtube.com/vkedco www.vkedco.blogspot.com
  22. 22. Example 2 Let S = [ 0,2,0,1] = 3 ⋅ 7 = 63. Let U = b,2 . 2 Then r (U ) = c = 2 =# (V ) − 1. So r (U ) + 1 = 3, which is the # of Z 1 in our variable ordering (Y , X 1 , Z 1 , etc). Thus, V = Z 1 . p r ( U ) +1 = p3 = 5. Let v be the value of V , i.e. of Z 1 . Then v = ( S ) r ( U ) +1 = ( S ) 3 = 0. So, Z 1 = 0 and note that 5 | 63, but ¬( 5 | 63). 0 Observe that if v = ( S ) r ( U ) +1 = 0, then ¬( p r ( U ) +1 | S ).http://www.youtube.com/vkedco www.vkedco.blogspot.com
  23. 23. Example 3 Assume that S = [ 0,2,0,1] = 3 ⋅ 7 = 63. 2 Let U = b,3 . Then r (U ) = c = 3 =# (V ) − 1. So r (U ) + 1 = 4, which is the # of X 2 in our variable ordering (Y , X 1 , Z 1 , X 2 , ...), so V = X 2 . p r ( U ) +1 = p 4 = 7. ( S ) r ( U ) +1 = ( S ) 4 = 1. So, X 2 = 1. .http://www.youtube.com/vkedco www.vkedco.blogspot.com
  24. 24. Un Construction: Part 3 // I = ( Z ) K = a, b, c ; K - th instruction // U = b, c ; the right part of the K - th instruction U ← r(( Z ) K ) // P is the ( r (U ) +1) th prime. P ← p r (U ) +1http://www.youtube.com/vkedco www.vkedco.blogspot.com
  25. 25. Un Construction: So Far Z ← X n +1 + 1 // Z is the source code n Xi S ← ∏ ( p 2i ) // S is the program s state i =1 K ←1 // K is the instruction counter U ← r( ( Z ) K ) // ( Z ) K is the K - th instruction P ← p r (U ) +1 // P is the prime corresponding whose power is // the value of K - th instruction s variablehttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  26. 26. Part 04 Determining Type of Next Instructionhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  27. 27. Un Construction: Part 4 • The next thing that Un must do is to determine the type of the next instruction to be executed • The following labels are used: – N – stands for nothing – A – stands for addition – M – stands for subtraction (minus)http://www.youtube.com/vkedco www.vkedco.blogspot.com
  28. 28. Un Construction: Part 4 // I = ( Z ) K = a, b, c ; U = r ( ( Z ) K ) = b,c ; l (U ) = b. IF l (U ) = 0 GOTO N // In other words, if l (U ) = 0, the instruction to be // executed is of type V ← V . We do not have to do anything.http://www.youtube.com/vkedco www.vkedco.blogspot.com
  29. 29. Un Construction: Part 4 // I = ( Z ) K = a, b, c ;U = r ( ( Z ) K ) = b, c ; l (U ) = b. IF l (U ) = 1 GOTO A // In other words, if l (U ) = 1, the instruction to be // executed is of type V ←V +1. We dispatch to the // addition label.http://www.youtube.com/vkedco www.vkedco.blogspot.com
  30. 30. Un Construction: Part 4 • Un now has to check if the instruction is subtraction • However, if we know that the value of the variable is 0, we do not need to subtract 1 from it, because it will remain 0 anyway • So, before we dispatch to subtraction, we check if the value of the variable is 0; if it is, we do nothinghttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  31. 31. Observation Let S be a program state. Recall that S is a G - number. Then pi | S if and only if ( S ) i ≠ 0. This is true because if ( S ) i = 0, pi is not a factor of S . For example, 63 = 32 ⋅ 7 = [ 0,2,0,1]. Only 3 and 7 are the factors of 63, because their powers are greater than 0.http://www.youtube.com/vkedco www.vkedco.blogspot.com
  32. 32. Un Construction: Part 4 // If ¬( P | S ), the value of the variable // in the instruction is 0. We do nothing. IF ¬( P | S ) GOTO Nhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  33. 33. Un Construction: Part 4 // If l (U ) = 2, the instruction type is subtraction. // We dispatch to the subtraction label. IF l (U ) = 2 GOTO Mhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  34. 34. Un Construction So Far Z ← X n +1 +1 // Get the source number. n S ← ∏( p2i ) i // Encode the initial program state. X i =1 K ←1 // Initialize instruction counter. [ C] IF K = Lt ( Z ) +1 ∨ K = 0 GOTO E // Check termination U ← r ( ( Z ) K ) // Get b, c of K - th instruction. P ← pr (U ) +1 // Get the prime corresponding to ( c +1) th variable. IF l (U ) = 0 GOTO N // If V ← V , go to NOTHING. IF l (U ) = 1 GOTO A // If V ←V +1, go to ADD. IF ¬( P | S ) GOTO N // If V = 0, go to NOTHING. IF l (U ) = 2 GOTO M // If V ←V-1, go to MINUS.http://www.youtube.com/vkedco www.vkedco.blogspot.com
  35. 35. Reading Suggestions ● Ch. 4, Computability, Complexity, and Languages, 2nd Edition, by Davis, Weyuker, Sigal ● http://en.wikipedia.org/wiki/Kurt_Gödelhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  36. 36. Feedback Errors, comments to vladimir dot kulyukin at gmail dot comhttp://www.youtube.com/vkedco www.vkedco.blogspot.com

×