CS 5000: Theory of Computation                         Lecture 19                     Vladimir Kulyukin              Depar...
Outline    ●        Review    ●        Gödel Decoding: Decoding Numbers to Obtain        Programs    ●        Universality...
Reviewwww.youtube.com/vkedco       www.vkedco.blogspot.com
Review: Mapping Instructions to Numbers    Let I be a primitive L instruction. Then # ( I ) = a, b, c , where         1. a...
Review: Mapping Instructions to Numbers     Let I be a primitive L instruction. Then # ( I ) = a, b, c , where     1. if I...
Review: Example 1          I is X 1 ← X 1 + 1; so # ( I ) = a, b, c , where         1. a = 0, because I is unlabeled;     ...
Review: #(P)    Let P be a program that consists of I 1 , I 2 ,..., I k , where k ≥ 0    and I 1 , I 2 ,..., I k are primi...
Review: Example 2                 I 1 is [ A1] X 1 ← X 1 + 1                 I 2 is IF X 1 ≠ 0 GOTO A1                 Thu...
Review: Example 2          # ( I 1 ) = 21          # ( I 2 ) = 46          # ( P ) = [ # ( I 1 ) , # ( I 2 ) ] − 1 = [ 21,...
Review: Big Picture                                                                                   Number              ...
Gödel Decodingwww.youtube.com/vkedco            www.vkedco.blogspot.com
Resolving Ambiguity of Gödel Numbers    ●        The number of Y ← Y is <0, <0, 0>> = 0    ●        The final instruction ...
GÖDEL Decoder: Sub-Task 1              # ( P ) = [ # ( I 1 ) , # ( I 2 ) ,..., # ( I k ) ] − 1.              Thus, the sou...
A Prime Factorization Algorithm       // n is a natural number > 0, i is the prime counter, initially       // set to 1. W...
Prime Factorization Algorithm: Example 3      factors(8,1)      ( p1 = 2) | 8      so add 2 to factors(4, 1)              ...
Prime Factorization Algorithm: Example 4   1. Suppose some program P is compiled into number 7    2. The source code numbe...
GÖDEL Decoder: Sub-Task 3          Now that we have the G - number from sub - task 2, we need to          extract the sour...
#(P)  P: GÖDEL Decoding Algorithm    1. Let n be # ( P ) = [ # ( I 1 ) , # ( I 2 ) ,..., # ( I k ) ] − 1;    So, the sour...
GÖDEL Decoding Algorithm: Example  1. Let #(P) = 199.  2. The source code number = 199+1=200.  3. The prime factorization ...
GÖDEL Decoding Algorithm: Example    Let #(P) = 199. The source code number = 199+1=200.    So, the source code of P is   ...
Back To The Big Picture                                                                        Number                GÖDEL...
Universalitywww.youtube.com/vkedco           www.vkedco.blogspot.com
Church’s Thesis Revisited   ●       The notion of algorithm can be defined only informally   ●       There are many formal...
What is Universality?  ●      Coding programs by numbers gives us a      mathematical theory of compilation  ●      But, c...
Developing Universal Programswww.youtube.com/vkedco       www.vkedco.blogspot.com
Universal Programs: Step 2   ●       But why stop with just one program?   ●       We can attempt to construct a program t...
Universal Programs: Step 2   ●   For each n > 0, such a program is denoted by Un and is       called universal   ●       W...
Reading Suggestions                                                            nd   ●       Ch. 4, Computability, Complexi...
Feedback        Errors, comments to vladimir.kulyukin@gmail.comwww.youtube.com/vkedco          www.vkedco.blogspot.com
Theory of Computation: Lecture 19
Theory of Computation: Lecture 19
Theory of Computation: Lecture 19
Upcoming SlideShare
Loading in...5
×

Theory of Computation: Lecture 19

445

Published on

1) Godel decoding
2) Universality
3) Universal programs
4) Prime factorization
5) Class web page is at http://vkedco.blogspot.com/2011/08/theory-of-computation-home.html

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

  • Be the first to like this

No Downloads
Views
Total Views
445
On Slideshare
0
From Embeds
0
Number of Embeds
19
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Theory of Computation: Lecture 19

  1. 1. CS 5000: Theory of Computation Lecture 19 Vladimir Kulyukin Department of Computer Science Utah State Universitywww.youtube.com/vkedco www.vkedco.blogspot.com
  2. 2. Outline ● Review ● Gödel Decoding: Decoding Numbers to Obtain Programs ● Universalitywww.youtube.com/vkedco www.vkedco.blogspot.com
  3. 3. Reviewwww.youtube.com/vkedco www.vkedco.blogspot.com
  4. 4. Review: Mapping Instructions to Numbers Let I be a primitive L instruction. Then # ( I ) = a, b, c , where 1. a is the label number 2. b is the instruction type number 3. c is the number of the variable used in the instructionwww.youtube.com/vkedco www.vkedco.blogspot.com
  5. 5. Review: Mapping Instructions to Numbers Let I be a primitive L instruction. Then # ( I ) = a, b, c , where 1. if I is unlabeled, then a = 0; 2. if I is labeled with some label L, then a = # ( L ); 3. if a variable V is used in I , then c = # (V ) − 1; 4. if I is V <= V , then b = 0; 5. if I is V <= V + 1, then b = 1; 6. if I is V <= V - 1, then b = 2; 7. if I is IF V != 0 GOTO L, then b = # ( L ) + 2. Note that in this case b = # ( L ) + 2 > 2.www.youtube.com/vkedco www.vkedco.blogspot.com
  6. 6. Review: Example 1 I is X 1 ← X 1 + 1; so # ( I ) = a, b, c , where 1. a = 0, because I is unlabeled; 2. b = 1, because I is addition; 3. c = # ( X 1) − 1 = 1, because # ( X 1) = 2; 4. Thus, # ( I ) = 0, 1,1 = 2 0 ( 2 1,1 + 1) − 1 =  0 [ 1 ] 2 ( 2 ⋅ 2 ( 2 ⋅ 1 + 1) − 1 + 1) − 1 =   1 ⋅ ( 2 ⋅ [ 2 ⋅ 3 − 1] + 1) − 1 = 11 − 1 = 10.   www.youtube.com/vkedco www.vkedco.blogspot.com
  7. 7. Review: #(P) Let P be a program that consists of I 1 , I 2 ,..., I k , where k ≥ 0 and I 1 , I 2 ,..., I k are primitive L instructions, then # ( P ) = [ # ( I 1 ) , # ( I 2 ) ,..., # ( I k ) ] − 1. Remember that [ ] = 1. Thus, if P is the empty program (program with no instructions), # ( P ) = 1 − 1 = 0.www.youtube.com/vkedco www.vkedco.blogspot.com
  8. 8. Review: Example 2 I 1 is [ A1] X 1 ← X 1 + 1 I 2 is IF X 1 ≠ 0 GOTO A1 Thus, # ( P ) = [ # ( I 1 ), # ( I 2 ) ] −1www.youtube.com/vkedco www.vkedco.blogspot.com
  9. 9. Review: Example 2 # ( I 1 ) = 21 # ( I 2 ) = 46 # ( P ) = [ # ( I 1 ) , # ( I 2 ) ] − 1 = [ 21,46] − 1 = 2 21 ⋅ 3 46 − 1 = 18586928403505481978329694207www.youtube.com/vkedco www.vkedco.blogspot.com
  10. 10. Review: Big Picture Number GÖDEL Coder L Program Number Universal Program GÖDEL Decoder ??? The red arrows show the implemented tasks (program compilation): we now know how to map L programs to numbers.www.youtube.com/vkedco www.vkedco.blogspot.com
  11. 11. Gödel Decodingwww.youtube.com/vkedco www.vkedco.blogspot.com
  12. 12. Gödel Decoder ● Sub-Task 1: Obtain the source code number ● Sub-Task 2: Extract from the source code number the numbers for individual instructions ● Sub-Task 3: Extract the source from each individual instruction numberwww.youtube.com/vkedco www.vkedco.blogspot.com
  13. 13. Resolving Ambiguity of Gödel Numbers ● The number of Y ← Y is <0, <0, 0>> = 0 ● The final instruction in a program is not permitted to be the unlabeled statement Y ← Y ● Each number determines a unique programwww.youtube.com/vkedco www.vkedco.blogspot.com
  14. 14. GÖDEL Decoder: Sub-Task 1 # ( 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
  15. 15. A Prime Factorization Algorithm // n is a natural number > 0, i is the prime counter, initially // set to 1. We need this algorithm to solve sub-task 2 of // Gödel Decoding Factors(n, i) If n is prime then n is the factorization; If n is composite then If pi divides n then add pi to the list of factors; Factors((n / pi), i); If pi does not divide n Then Factors(n, i+1)www.youtube.com/vkedco www.vkedco.blogspot.com
  16. 16. Prime Factorization Algorithm: Example 3 factors(8,1) ( p1 = 2) | 8 so add 2 to factors(4, 1) ( p1 = 2) | 4 so add 2 to factors(2, 1) 2 is a prime so return [2] return [2, 2] return [2, 2, 2]www.youtube.com/vkedco www.vkedco.blogspot.com
  17. 17. GÖDEL Decoder: Sub-Task 2 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) , to obtain the list of prime factors 3. From the list of prime factors, obtain the list of prime powers, i.e., the G - numberwww.youtube.com/vkedco www.vkedco.blogspot.com
  18. 18. Prime Factorization Algorithm: Example 4 1. Suppose some program P is compiled into number 7 2. The source code number for P is 8 3. factors(8,1) returns [2, 2, 2] 4. [2,2,2] is converted to the G - number [3] = 2 3 = 8 5. P s source code consists of one instruction that compiles into number 3 1. If P compiles into 13, then factors(14,1) returns [2,7] 2. [2,7] is converted to the G - number [1, 0, 0, 1] = 21 ⋅ 30 ⋅ 5 0 ⋅ 71 = 14 3. P consists of four instructions that compile into 1,0,0, and 1, respectivelywww.youtube.com/vkedco www.vkedco.blogspot.com
  19. 19. GÖDEL Decoder: Sub-Task 3 Now that we have the G - number from sub - task 2, we need to extract the source code of each instruction in the G - number. Let # ( I ) = q = a, b, c . 1. a = l ( q ). If a = 0, I is unlabeled. Otherwise, I has label number l ( q ) in the label ordering. 2. b = l ( r ( q ) ). Then 2.1. I is of type V ← V if b = 0; 2.2. I is of type V ← V + 1 if b = 1; 2.3. I is of type V ← V - 1 if b = 2; 2.4. I is of type IF V ! = 0 GOTO L where L is label whose position is b- 2 in the label ordering. 3. c = r ( r ( q ) ). Thus, the variable used in I is variable whose position is c + 1 in the variable ordering.www.youtube.com/vkedco www.vkedco.blogspot.com
  20. 20. #(P)  P: 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
  21. 21. GÖDEL Decoding Algorithm: Example 1. Let #(P) = 199. 2. The source code number = 199+1=200. 3. The prime factorization of 200 is 2 33052. 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 + 1.www.youtube.com/vkedco www.vkedco.blogspot.com
  22. 22. GÖDEL Decoding Algorithm: 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
  23. 23. 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
  24. 24. Universalitywww.youtube.com/vkedco www.vkedco.blogspot.com
  25. 25. Church’s Thesis Revisited ● The notion of algorithm can be defined only informally ● There are many formal characterizations of algorithms (Note the rapid proliferation of different programming languages!) ● The claim that each of the standard formal characterizations of algorithm is satisfactory cannot be proved ● The claim must be accepted on empirical groundswww.youtube.com/vkedco www.vkedco.blogspot.com
  26. 26. What is Universality? ● Coding programs by numbers gives us a mathematical theory of compilation ● But, compiled programs must be executed ● Universality can be viewed as a mathematical theory of program execution/interpretation, i.e., a mathematical theory of operating systems and interpreters ● A Universal Program is an operating system or an interpreter that can execute other programswww.youtube.com/vkedco www.vkedco.blogspot.com
  27. 27. Developing Universal Programswww.youtube.com/vkedco www.vkedco.blogspot.com
  28. 28. Universal Programs: Step 1 ● Suppose we have a program P that takes n arguments ● Suppose that #(P) = y ● We would like to construct another program that can take #(P) and n argument values x1, … , xn and execute it on those valueswww.youtube.com/vkedco www.vkedco.blogspot.com
  29. 29. Universal Programs: Step 2 ● But why stop with just one program? ● We can attempt to construct a program that can execute/interpret any program of n arguments ● Thus, we can have programs that can execute any program of 1 argument, any program of 2 arguments, any program of 3 arguments, etcwww.youtube.com/vkedco www.vkedco.blogspot.com
  30. 30. Universal Programs: Step 2 ● For each n > 0, such a program is denoted by Un and is called universal ● Why is it 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
  31. 31. Reading Suggestions nd ● Ch. 4, Computability, Complexity, and Languages, 2 Edition, by Davis, Weyuker, Sigal ● http://en.wikipedia.org/wiki/Kurt_Gödelwww.youtube.com/vkedco www.vkedco.blogspot.com
  32. 32. Feedback Errors, comments to vladimir.kulyukin@gmail.comwww.youtube.com/vkedco www.vkedco.blogspot.com

×