Fall 2004COMP 3351 Turing Machines
Fall 2004COMP 3352 The Language Hierarchy Regular Languages Context-Free Languages ? ?
Fall 2004COMP 3353 Regular Languages Context-Free Languages Languages accepted by Turing Machines
Fall 2004COMP 3354 A Turing Machine Tape Read-Write head Control Unit
Fall 2004COMP 3355 The Tape Read-Write head No boundaries -- infinite length The head moves Left or Right
Fall 2004COMP Read-Write head The head at each time step: 1. Reads a symbol 2. Writes a symbol 3. Moves Left or Right
Fall 2004COMP Example: Time Time 1 1. Reads 2. Writes 3. Moves Left
Fall 2004COMP Time Time 2 1. Reads 2. Writes 3. Moves Right
Fall 2004COMP 3359 The Input String Blank symbol head Head starts at the leftmost position of the input string Input string
Fall 2004COMP Blank symbol head Input string Remark: the input string is never empty
Fall 2004COMP States & Transitions Read Write Move Left Move Right
Fall 2004COMP Example: Time 1 current state
Fall 2004COMP Time Time 2
Fall 2004COMP Time Time 2 Example:
Fall 2004COMP Time Time 2 Example:
Fall 2004COMP Determinism Allowed Not Allowed No lambda transitions allowed Turing Machines are deterministic
Fall 2004COMP Partial Transition Function Example: No transition for input symbol Allowed:
Fall 2004COMP Halting The machine halts if there are no possible transitions to follow
Fall 2004COMP Example: No possible transition HALT!!!
Fall 2004COMP Final States Allowed Not Allowed Final states have no outgoing transitions In a final state the machine halts
Fall 2004COMP Acceptance Accept Input If machine halts in a final state Reject Input If machine halts in a non-final state or If machine enters an infinite loop
Fall 2004COMP Turing Machine Example A Turing machine that accepts the language:
Fall 2004COMP Time 0
Fall 2004COMP Time 1
Fall 2004COMP Time 2
Fall 2004COMP Time 3
Fall 2004COMP Time 4 Halt & Accept
Fall 2004COMP Rejection Example Time 0
Fall 2004COMP Time 1 No possible Transition Halt & Reject
Fall 2004COMP Infinite Loop Example
Fall 2004COMP Time 0
Fall 2004COMP Time 1
Fall 2004COMP Time 2
Fall 2004COMP Time 2 Time 3 Time 4 Time 5 Infinite loop
Fall 2004COMP Because of the infinite loop: The final state cannot be reached The machine never halts The input is not accepted
Fall 2004COMP Another Turing Machine Example Turing machine for the language
Fall 2004COMP Time 0
Fall 2004COMP Time 1
Fall 2004COMP Time 2
Fall 2004COMP Time 3
Fall 2004COMP Time 4
Fall 2004COMP Time 5
Fall 2004COMP Time 6
Fall 2004COMP Time 7
Fall 2004COMP Time 8
Fall 2004COMP Time 9
Fall 2004COMP Time 10
Fall 2004COMP Time 11
Fall 2004COMP Time 12
Fall 2004COMP Halt & Accept Time 13
Fall 2004COMP We easily modify the machine for the language to construct a TM for the language Observation:
Fall 2004COMP Formal Definitions for Turing Machines
Fall 2004COMP Transition Function
Fall 2004COMP Transition Function
Fall 2004COMP Turing Machine: States Input alphabet Tape alphabet Transition function Initial state blank Final states
Fall 2004COMP Configuration Instantaneous description:
Fall 2004COMP Time 4Time 5 A Move:
Fall 2004COMP Time 4Time 5 Time 6Time 7
Fall 2004COMP Equivalent notation:
Fall 2004COMP Initial configuration: Input string
Fall 2004COMP The Accepted Language For any Turing Machine Initial stateFinal state
Fall 2004COMP Standard Turing Machine Deterministic Infinite tape in both directions Tape is the input/output file The machine we described is the standard:
Fall 2004COMP Computing Functions with Turing Machines
Fall 2004COMP A function Domain: Result Region: has:
Fall 2004COMP A function may have several parameters / arguments: Example: The Addition function
Fall 2004COMP Integer Domain Unary: Binary: Decimal: We prefer unary representation: easier to manipulate with Turing machines
Fall 2004COMP Definition: A function is computable if there is a Turing Machine such that: Initial configurationFinal configuration Domain final stateinitial state For all
Fall 2004COMP Initial Configuration Final Configuration A function is computable if there is a Turing Machine such that: In other words: (the domain)
Fall 2004COMP Example The function is computable A Turing Machine M for f: Input string: unary Output string: unary are integers
Fall 2004COMP Start initial state The 0 is the delimiter that separates the two numbers
Fall 2004COMP Start Finish final state initial state
Fall 2004COMP Finish final state The 0 helps when we use the result for other operations
Fall 2004COMP Turing machine M for the function:
Fall 2004COMP Execution Example: Input (time 0) Output (final result) (2)
Fall 2004COMP Time 0
Fall 2004COMP Time 1
Fall 2004COMP Time 2
Fall 2004COMP Time 3
Fall 2004COMP Time 4
Fall 2004COMP Time 5
Fall 2004COMP Time 6
Fall 2004COMP Time 7
Fall 2004COMP Time 8
Fall 2004COMP Time 9
Fall 2004COMP Time 10
Fall 2004COMP Time 11
Fall 2004COMP Time 12
Fall 2004COMP HALT & accept Time 13
Fall 2004COMP Another Example The function is computable Turing Machine: Input string: unary Output string:unary is integer
Fall 2004COMP Start Finish final state initial state
Fall 2004COMP Turing Machine Pseudocode for Replace every 1 with $ Repeat: Find rightmost $, replace it with 1 Go to right end, then insert 1 Until no more $ remains
Fall 2004COMP A Turing Machine for:
Fall 2004COMP Example Start Finish
Fall 2004COMP Another Example The function is computable if
Fall 2004COMP A Turing Machine for Input: Output: or if
Fall 2004COMP Pseudocode for our Turing Machine: Match a 1 from with a 1 from Repeat Until all of or is matched If a 1 from is not matched erase tape, then write 1 else erase tape, then write 0
Fall 2004COMP Combining Turing Machines
Fall 2004COMP Block Diagram Turing Machine inputoutput
Fall 2004COMP Example: if Comparer Adder Eraser