Turing Machines Slides adapted from Costas Busch RPI
Turing Machines Slides adapted from Costas Busch - RPI 1
Doing math with Turing machines Can a Turing machine do some mathematical operations? Fall 2006 Costas Busch - RPI 2
Making one pass through the input, check if it is the right form, that is a+b+c+ Return to the start (keep moving left, ignoring everything) For each a Cross it out Scan until you hit a b For each b, mark it Scan until you hit c Cross out the c If you do not hit any cs, reject Restore the bs to unmarked state If all a’s are crossed out, check if all c’s have also been crossed out If yes – accept If no - reject 3
Configuration Assume q is a state and u and v are strings The configuration uqv means Current tape content is uv Current state is q Current head location is the first symbol of v u Fall 2006 v Costas Busch - RPI 4
Configuration of a Turing Machine As a Turing Machine computes 3 things happen • The state can change • The tape contents can change • The R/W head location can change A current snapshot of the machine = configuration. Fall 2006 Costas Busch - RPI 5
Yielding a configuration Moving from one configuration to another is called yielding a configuration Fall 2006 Costas Busch - RPI 6
Writing transitions in a Turing machine state diagram Current char -> new char, direction The new char is written first and then you move left or right Costas Busch - RPI 7
A Turing machine going into a loop is being used for the blank character Costas Busch - RPI 8
Time 0 Costas Busch - RPI 9
Time 1 Costas Busch - RPI 10
Time 2 Fall 2006 Costas Busch - RPI 11
Time 2 Infinite loop Time 3 Time 4 Time 5 Costas Busch - RPI 12
Because of the infinite loop: • The accepting state cannot be reached • The machine never halts • The input string is rejected Costas Busch - RPI 13
If a language is accepted by a Turing machine then we say that is: • Turing Recognizable Other names used: • Turing Acceptable • Recursively Enumerable Fall 2006 Costas Busch - RPI 14
If a language is decided (no looping, only rejection or acceptance) by a Turing machine then we say that is: • Turing Decidable Other names used: • Recursive Costas Busch - RPI 15
Computing Functions with Turing Machines Not really covered in Sipser Fall 2006 Costas Busch - RPI 16
A function Domain: Fall 2006 has: Result Region: Costas Busch - RPI 17
A function may have many parameters: Example: Fall 2006 Addition function Costas Busch - RPI 18
Integer Domain Decimal: 5 Binary: 101 Unary: 11111 We prefer unary representation: easier to manipulate with Turing machines Fall 2006 Costas Busch - RPI 19
Definition: A function is computable if there is a Turing Machine such that: Initial configuration Final configuration initial state For all Fall 2006 accept state Domain Costas Busch - RPI 20
In other words: A function is computable if there is a Turing Machine such that: Initial Halts Configuration at For all Fall 2006 Final Configuration Domain Costas Busch - RPI 21
Example is computable The function are integers Turing Machine: Fall 2006 Input string: unary Output string: unary Costas Busch - RPI 22
Start initial state The 0 is the delimiter that separates the two numbers Fall 2006 Costas Busch - RPI 23
Start initial state Finish Fall 2006 final state Costas Busch - RPI 24
The 0 here helps when we use the result for other operations Finish Fall 2006 final state Costas Busch - RPI 25
Turing machine for function Fall 2006 Costas Busch - RPI 26
Execution Example: Time 0 (=2) Final Result Fall 2006 Costas Busch - RPI 27
Time 0 Fall 2006 Costas Busch - RPI 28
Time 1 Fall 2006 Costas Busch - RPI 29
Time 2 Fall 2006 Costas Busch - RPI 30
Time 3 Fall 2006 Costas Busch - RPI 31
Time 4 Fall 2006 Costas Busch - RPI 32
Time 5 Fall 2006 Costas Busch - RPI 33
Time 6 Fall 2006 Costas Busch - RPI 34
Time 7 Fall 2006 Costas Busch - RPI 35
Time 8 Fall 2006 Costas Busch - RPI 36
Time 9 Fall 2006 Costas Busch - RPI 37
Time 10 Fall 2006 Costas Busch - RPI 38
Time 11 Fall 2006 Costas Busch - RPI 39
Time 12 HALT & accept Fall 2006 Costas Busch - RPI 40
Another Example is computable The function is integer Turing Machine: Fall 2006 Input string: unary Output string: unary Costas Busch - RPI 41
Start initial state Finish Fall 2006 accept state Costas Busch - RPI 42
Turing Machine Pseudocode for • Replace every 1 with $ • Repeat: • Find rightmost $, replace it with 1 • Go to right end, insert 1 Until no more $ remain Fall 2006 Costas Busch - RPI 43
Turing Machine for Fall 2006 Costas Busch - RPI 44
Start Fall 2006 Example Costas Busch - RPI Finish 45
Back to binary! • How do we add two binary numbers on a Turing machine? • Instead of dealing with it directly, let us divide the problem into 2 parts • How to subtract 1 from a binary number • How to add 1 to a binary number • HW – think about how to do this without subroutines/functions/methods Fall 2006 Costas Busch - RPI 46
How to add 1 to a binary number? What is 11000 + 1 = ? What is 10111 + 1 = ? The pattern that emerges is …. . Fall 2006 Costas Busch - RPI 47
How to subtract 1 from a binary number? Fall 2006 Costas Busch - RPI 48
Putting it all together • • Assume we have some kind of separator character between the two inputs to add First input is x and the second input is y // algorithm repeatedly subtracts one from x, adds one to y until x is zero repeat until x == 0, then HALT { // use subtractor , like a function call, start at leftmost $ subtract 1 from x // use adder , like a function call, start at middle $ add 1 to y // simple TM to read and write the same character go back to the first $ } Fall 2006 Costas Busch - RPI 49
Church-Turing Thesis Lamba Calculus? – Alonzo Church Turing Machines The Church Turing thesis shows that What is an algorithm? Algorithm = something that a Turing machine can do/something that can be done via lambda calculus Fall 2006 Costas Busch - RPI 50
Next time Moving on to complexity and algorithms Fall 2006 Costas Busch - RPI 51
- Slides: 51