Transcript powerpoint
Computing Functions with Turing Machines 1 A function Domain f (w) D Result Region S has: w D f ( w) S 2 Integer Domain: Unary: 11111 Binary: 101 Decimal: 5 We prefer Unary representation: Easier to manipulate 3 A function may have many parameters: Example: Addition function f ( x, y ) x y x, y are integers 4 Definition: f A function is computable if there is a Turing Machine M such that: w f (w) qf q0 Initial Configuration w D final state Final configuration Domain 5 In other words: f A function is computable if there is a Turing Machine M such that: q0 w q f f ( w) Initial Configuration w D Final Configuration Domain 6 Example The function f ( x, y ) x y x, y is computable are integers Turing Machine: Input string: x0 y unary Output string: xy 0 unary 7 Start y x 1 1 1 0 1 1 q0 x y Finish 1 1 q f final state 1 1 0 8 Turing machine for function 1 1, R f ( x, y ) x y 1 1, R 1 1, L , L 0 1 , R 1 0 , L q q0 q3 q1 2 , R q4 9 Execution Example: x 11 y 11 (2) (2) Time 0 y 1 1 0 1 1 x q0 Final Result x y 1 1 1 1 0 q4 10 Time 0 1 1 0 1 1 1 1 0 1 1 q0 q0 1 1, R Time 1 1 1, R 1 1, L , L 0 1 , R 1 0 , L q q0 q3 q1 2 , R q4 11 Time 2 1 1 0 1 1 Time 3 1 1 1 1 1 q0 1 1, R q1 1 1, R 1 1, L , L 0 1 , R 1 0 , L q q0 q3 q1 2 , R q4 12 Time 4 Time 5 1 1 1 1 1 1 1 1 1 1 q1 q1 1 1, R 1 1, R 1 1, L , L 0 1 , R 1 0 , L q q0 q3 q1 2 , R q4 13 Time 6 Time 7 1 1 1 1 1 1 1 1 1 0 q3 q2 1 1, R 1 1, R 1 1, L , L 0 1 , R 1 0 , L q q0 q3 q1 2 , R q4 14 Time 8 1 1 1 1 0 q3 1 1, R Time 9 1 1 1 1 0 q3 1 1, R 1 1, L , L 0 1 , R 1 0 , L q q0 q3 q1 2 , R q4 15 Time 10 1 1 1 1 0 q3 1 1, R Time 11 1 1 1 1 0 q3 1 1, R 1 1, L , L 0 1 , R 1 0 , L q q0 q3 q1 2 , R q4 16 Time 12 1 1 1 1 0 q4 1 1, R HALT & accept 1 1, R 1 1, L , L 0 1 , R 1 0 , L q q0 q3 q1 2 , R q4 17 Another Example The function f ( x) 2 x x is computable is integer Turing Machine: Input string: x unary Output string: xx unary 18 Start x 1 1 1 q0 Finish 2x 1 1 q f final state 1 1 1 19 Turing Machine Pseudocode for f ( x) 2 x 1. Replace every 1 with $ Repeat: 2. Find rightmost $, replace it with 1 3. Go to right end, insert 1 Until no more $ remain 20 Turing Machine for 1 $, R f ( x) 2 x 1 1, L 1 1, R q0 , L q1 $ 1, R , R q3 q2 1, L 21 Start Example 1 1 Finish 1 1 1 1 q0 q3 1 $, R 1 1, L 1 1, R q0 , L q1 $ 1, R , R q3 q2 1, L 22 Another Example The function 1 if x y 0 if x y f ( x, y ) is computable 23 Turing Machine for 1 if x y 0 if x y f ( x, y ) Input: x0 y Output: 1 or 0 24 Turing Machine Pseudocode: 1. Repeat Match a 1 from x with a 1 from y Until all x or y has been matched 2. If a 1 from x is not matched erase tape, write 1 else erase tape, write 0 25 Combining Turing Machines 26 Block Diagram input Turing Machine output 27 Example: x y if x y f ( x, y ) 0 x, y x, y Comparer if x y Adder x y Eraser 0 x y x y 28 Turing’s Thesis 29 Do Turing machines have the same power with a digital computer? 30 Do Turing machines have the same power with a digital computer? Intuitive answer: Yes There is no formal answer 31 Turing’s thesis: Any computation carried out by mechanical means can be performed by Turing Machine (1930) 32 Computer Science Law: A computation is mechanical if and only if it can be performed by a Turing Machine There is no known model of computation more powerful than Turing Machines 33 Definition of Algorithm: An algorithm for function f (w) is a Turing Machine which computes f (w) 34 Algorithms are Turing Machines When we say: There exists an algorithm We mean: There exists a Turing Machine 35