theory of computation
play

Theory of Computation Course note based on Computability, Complexity, - PowerPoint PPT Presentation

A Universal Program (4) Theory of Computation Course note based on Computability, Complexity, and Languages: Fundamentals of Theoretical Computer Science , 2nd edition, authored by Martin Davis, Ron Sigal, and Elaine J. Weyuker. course note


  1. A Universal Program (4) Theory of Computation Course note based on Computability, Complexity, and Languages: Fundamentals of Theoretical Computer Science , 2nd edition, authored by Martin Davis, Ron Sigal, and Elaine J. Weyuker. course note prepared by Tyng–Ruey Chuang Institute of Information Science, Academia Sinica Department of Information Management, National Taiwan University Week 5, Spring 2008 1 / 22

  2. A Universal Program (4) About This Course Note ◮ It is prepared for the course Theory of Computation taught at the National Taiwan University in Spring 2008. ◮ It follows very closely the book Computability, Complexity, and Languages: Fundamentals of Theoretical Computer Science , 2nd edition, by Martin Davis, Ron Sigal, and Elaine J. Weyuker. Morgan Kaufmann Publishers. ISBN: 0-12-206382-1. ◮ It is available from Tyng-Ruey Chuang’s web site: http://www.iis.sinica.edu.tw/~trc/ and released under a Creative Commons “Attribution-ShareAlike 2.5 Taiwan” license: http://creativecommons.org/licenses/by-sa/2.5/tw/ 2 / 22

  3. A Universal Program (4) Universality (4.3) Compute with Numbers of Programs ◮ Programs taking programs as input: Compilers, interpreters, evaluators, Web browsers, . . . . 3 / 22

  4. A Universal Program (4) Universality (4.3) Compute with Numbers of Programs ◮ Programs taking programs as input: Compilers, interpreters, evaluators, Web browsers, . . . . ◮ Can we write a program in language S to accept the number of another program P , as well as the input x to P , then compute Ψ (1) P ( x ) as output? 3 / 22

  5. A Universal Program (4) Universality (4.3) Compute with Numbers of Programs ◮ Programs taking programs as input: Compilers, interpreters, evaluators, Web browsers, . . . . ◮ Can we write a program in language S to accept the number of another program P , as well as the input x to P , then compute Ψ (1) P ( x ) as output? ◮ Yes, we can! The program above is called an universal program. 3 / 22

  6. A Universal Program (4) Universality (4.3) Universality For each n > 0, we define Φ ( n ) ( x 1 , . . . , x n , y ) = Ψ ( n ) P ( x 1 , . . . , x n ) , where #( P ) = y . 4 / 22

  7. A Universal Program (4) Universality (4.3) Universality For each n > 0, we define Φ ( n ) ( x 1 , . . . , x n , y ) = Ψ ( n ) P ( x 1 , . . . , x n ) , where #( P ) = y . Theorem 3.1. For each n > 0, the function Φ ( n ) ( x 1 , . . . , x n , y ) is partially computable. � 4 / 22

  8. A Universal Program (4) Universality (4.3) Universality For each n > 0, we define Φ ( n ) ( x 1 , . . . , x n , y ) = Ψ ( n ) P ( x 1 , . . . , x n ) , where #( P ) = y . Theorem 3.1. For each n > 0, the function Φ ( n ) ( x 1 , . . . , x n , y ) is partially computable. � We shall prove this theorem by showing how to construct, for each n > 0, a program U n which computes Φ ( n ) . That is, Ψ ( n +1) ( x 1 , . . . , x n , x n +1 ) = Φ ( n ) ( x 1 , . . . , x n , x n +1 ) . U n The programs U n are called universal. 4 / 22

  9. A Universal Program (4) Universality (4.3) “Computer Organization” of U n ◮ Program U n accepts n + 1 input variables of which X n +1 is a number of a program P , and X 1 , . . . , X n are provided to P as input variables. ◮ All variables used by P are arranged in the following order Y , X 1 , Z 1 , X 2 , Z 2 , . . . and their state is coded by the G¨ odel number [ y , x 1 , z 1 , x 2 , z 2 , . . . ]. ◮ Let variable S in program U n store the current state of program P coded in the above manner. ◮ Let variable K in program U n store the number such that the K th instruction of program P is about to be executed. ◮ Let variable Z in program U n store the instruction sequence of program P coded as a G¨ odel number. 5 / 22

  10. A Universal Program (4) Universality (4.3) Setting Up As program U n computes Φ ( n ) ( X 1 , . . . , X n , X n +1 ), we begin U n by setting up the initial environment for program (number) X n +1 to execute: Z ← X n +1 + 1 S ← � n i =1 ( p 2 i ) X i K ← 1 6 / 22

  11. A Universal Program (4) Universality (4.3) Setting Up As program U n computes Φ ( n ) ( X 1 , . . . , X n , X n +1 ), we begin U n by setting up the initial environment for program (number) X n +1 to execute: Z ← X n +1 + 1 S ← � n i =1 ( p 2 i ) X i K ← 1 ◮ If X n +1 = #( P ), where P consists of instructions I 1 , . . . , I m , then Z gets the value [#( I 1 ) , . . . , #( I m )]. 6 / 22

  12. A Universal Program (4) Universality (4.3) Setting Up As program U n computes Φ ( n ) ( X 1 , . . . , X n , X n +1 ), we begin U n by setting up the initial environment for program (number) X n +1 to execute: Z ← X n +1 + 1 S ← � n i =1 ( p 2 i ) X i K ← 1 ◮ If X n +1 = #( P ), where P consists of instructions I 1 , . . . , I m , then Z gets the value [#( I 1 ) , . . . , #( I m )]. ◮ S is initialized as [0 , X 1 , 0 , X 2 , . . . , 0 , X n ] which gives the first n input variables their appropriate values and gives all other variables the value 0. 6 / 22

  13. A Universal Program (4) Universality (4.3) Setting Up As program U n computes Φ ( n ) ( X 1 , . . . , X n , X n +1 ), we begin U n by setting up the initial environment for program (number) X n +1 to execute: Z ← X n +1 + 1 S ← � n i =1 ( p 2 i ) X i K ← 1 ◮ If X n +1 = #( P ), where P consists of instructions I 1 , . . . , I m , then Z gets the value [#( I 1 ) , . . . , #( I m )]. ◮ S is initialized as [0 , X 1 , 0 , X 2 , . . . , 0 , X n ] which gives the first n input variables their appropriate values and gives all other variables the value 0. ◮ K , the instruction counter, is given the initial value 1. 6 / 22

  14. A Universal Program (4) Universality (4.3) Decoding Instruction We first see if the execution of program P shall halt. If not, we fetch the K th instruction and decode the instruction. [ C ] IF K = Lt ( Z ) + 1 ∨ K = 0 GOTO F U ← r (( Z ) k ) P ← p r ( U )+1 7 / 22

  15. A Universal Program (4) Universality (4.3) Decoding Instruction We first see if the execution of program P shall halt. If not, we fetch the K th instruction and decode the instruction. [ C ] IF K = Lt ( Z ) + 1 ∨ K = 0 GOTO F U ← r (( Z ) k ) P ← p r ( U )+1 ◮ If the computation has ended, GOTO F , where the proper value will be output. (The case for K = 0 will be explained later.) 7 / 22

  16. A Universal Program (4) Universality (4.3) Decoding Instruction We first see if the execution of program P shall halt. If not, we fetch the K th instruction and decode the instruction. [ C ] IF K = Lt ( Z ) + 1 ∨ K = 0 GOTO F U ← r (( Z ) k ) P ← p r ( U )+1 ◮ If the computation has ended, GOTO F , where the proper value will be output. (The case for K = 0 will be explained later.) ◮ ( Z ) k = � a , � b , c �� is the number of the K th instruction. Thus U = � b , c � is the code of the statement to be executed. 7 / 22

  17. A Universal Program (4) Universality (4.3) Decoding Instruction We first see if the execution of program P shall halt. If not, we fetch the K th instruction and decode the instruction. [ C ] IF K = Lt ( Z ) + 1 ∨ K = 0 GOTO F U ← r (( Z ) k ) P ← p r ( U )+1 ◮ If the computation has ended, GOTO F , where the proper value will be output. (The case for K = 0 will be explained later.) ◮ ( Z ) k = � a , � b , c �� is the number of the K th instruction. Thus U = � b , c � is the code of the statement to be executed. ◮ The variable mentioned in the statement is the ( r ( U ) + 1)th in our list, and its current value is stored as the exponent to which P divides S . 7 / 22

  18. A Universal Program (4) Universality (4.3) Instruction Execution IF l ( U ) = 0 GOTO N IF l ( U ) = 1 GOTO A IF ∼ ( P | S ) GOTO N IF l ( U ) = 2 GOTO M 8 / 22

  19. A Universal Program (4) Universality (4.3) Instruction Execution IF l ( U ) = 0 GOTO N IF l ( U ) = 1 GOTO A IF ∼ ( P | S ) GOTO N IF l ( U ) = 2 GOTO M ◮ If l ( U ) = 0, the instruction is a dummy V ← V and the computation does nothing. Hence, it goes to N (for Nothing ). 8 / 22

  20. A Universal Program (4) Universality (4.3) Instruction Execution IF l ( U ) = 0 GOTO N IF l ( U ) = 1 GOTO A IF ∼ ( P | S ) GOTO N IF l ( U ) = 2 GOTO M ◮ If l ( U ) = 0, the instruction is a dummy V ← V and the computation does nothing. Hence, it goes to N (for Nothing ). ◮ If l ( U ) = 1, the instruction is V ← V + 1 . The computation goes to A (for Add ) to add 1 to the exponent on P in the prime power factorization of S . 8 / 22

  21. A Universal Program (4) Universality (4.3) Instruction Execution IF l ( U ) = 0 GOTO N IF l ( U ) = 1 GOTO A IF ∼ ( P | S ) GOTO N IF l ( U ) = 2 GOTO M ◮ If l ( U ) = 0, the instruction is a dummy V ← V and the computation does nothing. Hence, it goes to N (for Nothing ). ◮ If l ( U ) = 1, the instruction is V ← V + 1 . The computation goes to A (for Add ) to add 1 to the exponent on P in the prime power factorization of S . ◮ If l ( U ) � = 0 , 1, the instruction is either V ← V − 1 , or IF V � = 0 GOTO L . In both cases, if V = 0, the computation does nothing so goes to N . This happens when P is not a divisor of S . 8 / 22

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend