Upcoming SlideShare
×

# Theory of Computation: Lecture 19: Godel Decoding, Universality, Universal Programs, Prime Factorization

496
-1

Published on

1) Godel decoding
2) Universality
3) Universal programs
4) Prime factorization

Published in: Science, Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
496
On Slideshare
0
From Embeds
0
Number of Embeds
19
Actions
Shares
0
0
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Theory of Computation: Lecture 19: Godel Decoding, Universality, Universal Programs, Prime Factorization

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
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
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