Turing Machines Fall 2006 Costas Busch RPI 1
Turing Machines Fall 2006 Costas Busch - RPI 1
The Language Hierarchy ? ? Context-Free Languages Regular Languages Fall 2006 Costas Busch - RPI 2
Languages accepted by Turing Machines Context-Free Languages Regular Languages Fall 2006 Costas Busch - RPI 3
Tape. . . A Turing Machine. . . Read-Write head Control Unit Fall 2006 Costas Busch - RPI 4
The Tape No boundaries -- infinite length. . . Read-Write head The head moves Left or Right Fall 2006 Costas Busch - RPI 5
. . . Read-Write head The head at each transition (time step): 1. Reads a symbol 2. Writes a symbol 3. Moves Left or Right Fall 2006 Costas Busch - RPI 6
Example: . . . Time 0 Time 1 . . . 1. Reads 2. Writes 3. Moves Left Fall 2006 Costas Busch - RPI 7
. . . Time 1 Time 2 . . . 1. Reads 2. Writes 3. Moves Right Fall 2006 Costas Busch - RPI 8
The Input String Input string Blank symbol . . . head Head starts at the leftmost position of the input string Fall 2006 Costas Busch - RPI 9
States & Transitions Read Write Move Left Move Right Fall 2006 Costas Busch - RPI 10
Example: Time 1. . . current state Fall 2006 Costas Busch - RPI 11
. . . Fall 2006 Time 1 Time 2 Costas Busch - RPI . . . 12
Example: . . . Fall 2006 Time 1 Time 2 Costas Busch - RPI . . . 13
Example: . . . Fall 2006 Time 1 Time 2 Costas Busch - RPI . . . 14
Determinism Turing Machines are deterministic Not Allowed No lambda transitions allowed Fall 2006 Costas Busch - RPI 15
Partial Transition Function Example: . . . Allowed: No transition for input symbol Fall 2006 Costas Busch - RPI 16
Halting The machine halts in a state if there is no transition to follow Fall 2006 Costas Busch - RPI 17
Halting Example 1: . . . No transition from HALT!!! Fall 2006 Costas Busch - RPI 18
Halting Example 2: . . . No possible transition from and symbol HALT!!! Fall 2006 Costas Busch - RPI 19
Accepting States Allowed Not Allowed • Accepting states have no outgoing transitions • The machine halts and accepts Fall 2006 Costas Busch - RPI 20
Acceptance Accept Input string If machine halts in an accept state Reject Input string If machine halts in a non-accept state or If machine enters an infinite loop Fall 2006 Costas Busch - RPI 21
Observation: In order to accept an input string, it is not necessary to scan all the symbols in the string Fall 2006 Costas Busch - RPI 22
Turing Machine Example Input alphabet Accepts the language: Fall 2006 Costas Busch - RPI 23
Time 0 Fall 2006 Costas Busch - RPI 24
Time 1 Fall 2006 Costas Busch - RPI 25
Time 2 Fall 2006 Costas Busch - RPI 26
Time 3 Fall 2006 Costas Busch - RPI 27
Time 4 Halt & Accept Fall 2006 Costas Busch - RPI 28
Rejection Example Time 0 Fall 2006 Costas Busch - RPI 29
Time 1 No possible Transition Halt & Reject Fall 2006 Costas Busch - RPI 30
A simpler machine for same language but for input alphabet Accepts the language: Fall 2006 Costas Busch - RPI 31
Time 0 Halt & Accept Not necessary to scan input Fall 2006 Costas Busch - RPI 32
Infinite Loop Example A Turing machine for language Fall 2006 Costas Busch - RPI 33
Time 0 Fall 2006 Costas Busch - RPI 34
Time 1 Fall 2006 Costas Busch - RPI 35
Time 2 Fall 2006 Costas Busch - RPI 36
Time 2 Infinite loop Time 3 Time 4 Time 5 Fall 2006 Costas Busch - RPI 37
Because of the infinite loop: • The accepting state cannot be reached • The machine never halts • The input string is rejected Fall 2006 Costas Busch - RPI 38
Another Turing Machine Example Turing machine for the language Fall 2006 Costas Busch - RPI 39
Basic Idea: Match a’s with b’s: Repeat: replace leftmost a with x find leftmost b and replace it with y Until there are no more a’s or b’s If there is a remaining a or b reject Fall 2006 Costas Busch - RPI 40
Time 0 Fall 2006 Costas Busch - RPI 41
Time 1 Fall 2006 Costas Busch - RPI 42
Time 2 Fall 2006 Costas Busch - RPI 43
Time 3 Fall 2006 Costas Busch - RPI 44
Time 4 Fall 2006 Costas Busch - RPI 45
Time 5 Fall 2006 Costas Busch - RPI 46
Time 6 Fall 2006 Costas Busch - RPI 47
Time 7 Fall 2006 Costas Busch - RPI 48
Time 8 Fall 2006 Costas Busch - RPI 49
Time 9 Fall 2006 Costas Busch - RPI 50
Time 10 Fall 2006 Costas Busch - RPI 51
Time 11 Fall 2006 Costas Busch - RPI 52
Time 12 Fall 2006 Costas Busch - RPI 53
Time 13 Halt & Accept Fall 2006 Costas Busch - RPI 54
Observation: If we modify the machine for the language we can easily construct a machine for the language Fall 2006 Costas Busch - RPI 55
Formal Definitions for Turing Machines Fall 2006 Costas Busch - RPI 56
Transition Function Fall 2006 Costas Busch - RPI 57
Transition Function Fall 2006 Costas Busch - RPI 58
Turing Machine: States Input alphabet Transition function Fall 2006 Initial blank state. Costas Busch - RPI Tape alphabet Accept states 59
Configuration Instantaneous description: Fall 2006 Costas Busch - RPI 60
Time 4 Time 5 A Move: (yields in one mode) Fall 2006 Costas Busch - RPI 61
Time 4 Time 5 Time 6 Time 7 A computation Fall 2006 Costas Busch - RPI 62
Equivalent notation: Fall 2006 Costas Busch - RPI 63
Initial configuration: Input string Fall 2006 Costas Busch - RPI 64
The Accepted Language For any Turing Machine Initial state Fall 2006 Costas Busch - RPI Accept state 65
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 66
Computing Functions with Turing Machines Fall 2006 Costas Busch - RPI 67
A function Domain: Fall 2006 has: Result Region: Costas Busch - RPI 68
A function may have many parameters: Example: Fall 2006 Addition function Costas Busch - RPI 69
Integer Domain Decimal: 5 Binary: 101 Unary: 11111 We prefer unary representation: easier to manipulate with Turing machines Fall 2006 Costas Busch - RPI 70
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 71
In other words: A function is computable if there is a Turing Machine such that: Initial Configuration For all Fall 2006 Final Configuration Domain Costas Busch - RPI 72
Example is computable The function are integers Turing Machine: Fall 2006 Input string: unary Output string: unary Costas Busch - RPI 73
Start initial state The 0 is the delimiter that separates the two numbers Fall 2006 Costas Busch - RPI 74
Start initial state Finish Fall 2006 final state Costas Busch - RPI 75
The 0 here helps when we use the result for other operations Finish Fall 2006 final state Costas Busch - RPI 76
Turing machine for function Fall 2006 Costas Busch - RPI 77
Execution Example: Time 0 (=2) Final Result Fall 2006 Costas Busch - RPI 78
Time 0 Fall 2006 Costas Busch - RPI 79
Time 1 Fall 2006 Costas Busch - RPI 80
Time 2 Fall 2006 Costas Busch - RPI 81
Time 3 Fall 2006 Costas Busch - RPI 82
Time 4 Fall 2006 Costas Busch - RPI 83
Time 5 Fall 2006 Costas Busch - RPI 84
Time 6 Fall 2006 Costas Busch - RPI 85
Time 7 Fall 2006 Costas Busch - RPI 86
Time 8 Fall 2006 Costas Busch - RPI 87
Time 9 Fall 2006 Costas Busch - RPI 88
Time 10 Fall 2006 Costas Busch - RPI 89
Time 11 Fall 2006 Costas Busch - RPI 90
Time 12 HALT & accept Fall 2006 Costas Busch - RPI 91
Another Example is computable The function is integer Turing Machine: Fall 2006 Input string: unary Output string: unary Costas Busch - RPI 92
Start initial state Finish Fall 2006 accept state Costas Busch - RPI 93
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 94
Turing Machine for Fall 2006 Costas Busch - RPI 95
Start Fall 2006 Example Costas Busch - RPI Finish 96
Another Example if The function if is computable Input: Output: Fall 2006 or Costas Busch - RPI 97
Turing Machine Pseudocode: • Repeat Match a 1 from Until all of Fall 2006 or with a 1 from is matched • If a 1 from is not matched erase tape, write 1 else erase tape, write 0 Costas Busch - RPI 98
Combining Turing Machines Fall 2006 Costas Busch - RPI 99
Block Diagram input Fall 2006 Turing Machine Costas Busch - RPI output 100
Example: if if Adder Comparator Eraser Fall 2006 Costas Busch - RPI 101
- Slides: 101