theory of computation
play

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

Programs and Computable Functions (2) Primitive Recursive Functions (3) Theory of Computation Course note based on Computability, Complexity, and Languages: Fundamentals of Theoretical Computer Science , 2nd edition, authored by Martin Davis, Ron


  1. Programs and Computable Functions (2) Primitive Recursive Functions (3) 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 2, Spring 2010 1 / 27

  2. Programs and Computable Functions (2) Primitive Recursive Functions (3) About This Course Note ◮ It is prepared for the course Theory of Computation taught at the National Taiwan University in Spring 2010. ◮ 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 3.0 Taiwan” license: http://creativecommons.org/licenses/by-sa/3.0/tw/ 2 / 27

  3. Syntax (2.3) Programs and Computable Functions (2) Computable Functions (2.4) Primitive Recursive Functions (3) More about Macros (2.5) Syntax of Language S ◮ Variables: ◮ Input variables: X 1 , X 2 , X 3 , . . . ◮ Output variable: Y ◮ Local variables: Z 1 , Z 2 , Z 3 , . . . ◮ Labels: A 1 , B 1 , C 1 , D 1 , E 1 , A 2 , B 2 , C 2 , D 2 , E 2 , A 3 , . . . ◮ A statement is one of the following: ◮ V ← V + 1 ◮ V ← V − 1 ◮ V ← V ◮ IF V � = 0 GOTO L where V may be any variable and L may be any label. 3 / 27

  4. Syntax (2.3) Programs and Computable Functions (2) Computable Functions (2.4) Primitive Recursive Functions (3) More about Macros (2.5) Syntax of Language S ◮ Variables: ◮ Input variables: X 1 , X 2 , X 3 , . . . ◮ Output variable: Y ◮ Local variables: Z 1 , Z 2 , Z 3 , . . . ◮ Labels: A 1 , B 1 , C 1 , D 1 , E 1 , A 2 , B 2 , C 2 , D 2 , E 2 , A 3 , . . . ◮ A statement is one of the following: ◮ V ← V + 1 ◮ V ← V − 1 ◮ V ← V ◮ IF V � = 0 GOTO L where V may be any variable and L may be any label. Note: X 1 is a shorthand for X , Z 1 is a shorthand for Z , and A is a shorthand for A 1 , etc. V ← V are harmless “dummy” commands (more on these statements later). 3 / 27

  5. Syntax (2.3) Programs and Computable Functions (2) Computable Functions (2.4) Primitive Recursive Functions (3) More about Macros (2.5) Program ◮ An instruction is either a statement or [ L ] followed by a statement. ◮ A program is a list (i.e., a finite sequence) of instruction. The length of this list is called the length of the program. The empty program is of length 0. 4 / 27

  6. Syntax (2.3) Programs and Computable Functions (2) Computable Functions (2.4) Primitive Recursive Functions (3) More about Macros (2.5) State ◮ A state of a program P is a list of equations of the form V = m where V is a variable and m is a number, including an equation for each variable that occurs in P and including no two equations with the same variable. ◮ Let σ be a state of P and let V be a variable that occurs in σ . The value of V at σ is the (unique) number q such that the equation V = q is one of the equations making up σ . 5 / 27

  7. Syntax (2.3) Programs and Computable Functions (2) Computable Functions (2.4) Primitive Recursive Functions (3) More about Macros (2.5) State ◮ A state of a program P is a list of equations of the form V = m where V is a variable and m is a number, including an equation for each variable that occurs in P and including no two equations with the same variable. ◮ Let σ be a state of P and let V be a variable that occurs in σ . The value of V at σ is the (unique) number q such that the equation V = q is one of the equations making up σ . Note: An number is a nonnegative integer. 5 / 27

  8. Syntax (2.3) Programs and Computable Functions (2) Computable Functions (2.4) Primitive Recursive Functions (3) More about Macros (2.5) A State of A Program: Examples [ A ] IF X � = 0 GOTO B Z ← Z + 1 IF Z � = 0 GOTO E [ B ] X ← X − 1 Y ← Y + 1 Z ← Z + 1 IF Z � = 0 GOTO A Given program P above, each of the following is a state of P : ◮ X = 4 , Y = 3 , Z = 3 ◮ X 1 = 4 , X 2 = 5 , Y = 4 , Z = 4 but each of the following is not a state of P ◮ X = 3 , Z = 3 ◮ X = 3 , X = 4 , Y = 2 , Z = 2 6 / 27

  9. Syntax (2.3) Programs and Computable Functions (2) Computable Functions (2.4) Primitive Recursive Functions (3) More about Macros (2.5) Snapshot Let P be a program of length n . Then, ◮ A snapshot , or instantaneous description , of program P is a pair ( i , σ ) where 1 ≤ i ≤ n + 1, and σ is a state of P . ◮ The value of a variable V at a snapshot ( i , σ ) just means the value of V at σ . ◮ Intuitively the number i indicates that it is the i th instruction which is about to be executed; i = n + 1 corresponds to a “stop” instruction. A snapshot with i = n + 1 is called terminal. 7 / 27

  10. Syntax (2.3) Programs and Computable Functions (2) Computable Functions (2.4) Primitive Recursive Functions (3) More about Macros (2.5) The Successor of A Snapshot Let ( i , σ ) be a nonterminal snapshot of program P , then its successor ( j , τ ) will depend on the i th instruction of P . If the i th instruction is V ← V + 1 then j = i + 1, and τ is σ with equation V = m replaced by V = m + 1; V ← V − 1 then j = i + 1, and τ is σ with equation V = m replaced by V = m − 1; V ← V then j = i + 1, and τ = σ ; IF V � = 0 GOTO L then j = i + 1, and τ = σ if the value of V at σ is 0; otherwise τ = σ and j is the least number such that the j th instruction of P is labeled L (in case no instruction in P is labeled L , let j = n + 1). 8 / 27

  11. Syntax (2.3) Programs and Computable Functions (2) Computable Functions (2.4) Primitive Recursive Functions (3) More about Macros (2.5) The Successor of A Snapshot: Examples [ A ] IF X � = 0 GOTO B Z ← Z + 1 IF Z � = 0 GOTO E [ B ] X ← X − 1 Y ← Y + 1 Z ← Z + 1 IF Z � = 0 GOTO A Given program P above, then ◮ the successor of (1 , { X = 4 , Y = 0 , Z = 0 } ) is (4 , { X = 4 , Y = 0 , Z = 0 } ); ◮ the successor of (2 , { X = 4 , Y = 0 , Z = 0 } ) is (3 , { X = 4 , Y = 0 , Z = 1 } ); ◮ the successor of (7 , { X = 4 , Y = 0 , Z = 0 } ) is (8 , { X = 4 , Y = 0 , Z = 0 } ) which is a terminal snapshot. 9 / 27

  12. Syntax (2.3) Programs and Computable Functions (2) Computable Functions (2.4) Primitive Recursive Functions (3) More about Macros (2.5) Computation A computation of a program P is defined to be a sequence (i.e., a list) s 1 , s 2 , . . . , s k of snapshots of P such that s i +1 is the successor of s i for i = 1 , 2 , . . . , k − 1 and s k is terminal. 10 / 27

  13. Syntax (2.3) Programs and Computable Functions (2) Computable Functions (2.4) Primitive Recursive Functions (3) More about Macros (2.5) Computation from An Initial State Let P be a program, and let r 1 , r 2 , . . . , r m be m given numbers. The state σ of P is defined to consist of the equations X 1 = r 1 , X 2 = r 2 , . . . , X m = r m , Y = 0 together with the equation V = 0 for each variable V in P other than X 1 , X 2 , . . . , X m , Y . This state is called the initial state , and the snapshot (1 , σ ) the initial snapshot . 11 / 27

  14. Syntax (2.3) Programs and Computable Functions (2) Computable Functions (2.4) Primitive Recursive Functions (3) More about Macros (2.5) Computation from An Initial State Let P be a program, and let r 1 , r 2 , . . . , r m be m given numbers. The state σ of P is defined to consist of the equations X 1 = r 1 , X 2 = r 2 , . . . , X m = r m , Y = 0 together with the equation V = 0 for each variable V in P other than X 1 , X 2 , . . . , X m , Y . This state is called the initial state , and the snapshot (1 , σ ) the initial snapshot . Starting from the initial snapshot s 1 = (1 , σ ), there can be either ◮ a computation s 1 , s 2 , . . . , s k of P , or ◮ no such computation (i.e., there is an infinite sequence s 1 , s 2 , s 3 , . . . where each s k +1 is the successor of s k ). 11 / 27

  15. Syntax (2.3) Programs and Computable Functions (2) Computable Functions (2.4) Primitive Recursive Functions (3) More about Macros (2.5) Computation from An Initial State Let P be a program, and let r 1 , r 2 , . . . , r m be m given numbers. The state σ of P is defined to consist of the equations X 1 = r 1 , X 2 = r 2 , . . . , X m = r m , Y = 0 together with the equation V = 0 for each variable V in P other than X 1 , X 2 , . . . , X m , Y . This state is called the initial state , and the snapshot (1 , σ ) the initial snapshot . Starting from the initial snapshot s 1 = (1 , σ ), there can be either ◮ a computation s 1 , s 2 , . . . , s k of P , or ◮ no such computation (i.e., there is an infinite sequence s 1 , s 2 , s 3 , . . . where each s k +1 is the successor of s k ). We write Ψ ( m ) P ( r 1 , r 2 , . . . , r m ) for the value of Y at the terminal snapshot. In the case where there is no computation, Ψ ( m ) P ( r 1 , r 2 , . . . , r m ) is undefined. 11 / 27

  16. Syntax (2.3) Programs and Computable Functions (2) Computable Functions (2.4) Primitive Recursive Functions (3) More about Macros (2.5) Function f ( x ) = x , Revisited [ A ] IF X � = 0 GOTO B (1) Z ← Z + 1 (2) IF Z � = 0 GOTO E (3) [ B ] X ← X − 1 (4) Y ← Y + 1 (5) Z ← Z + 1 (6) IF Z � = 0 GOTO A (7) Given program P above (line numbers added), then Ψ (1) P ( x ) = x for all x . 12 / 27

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