Turing Machines
Part I: Definitions and Properties
Finite State Automata Deterministic Automata (DFSA) M = {Q, Σ, δ, q 0, F} -- Σ = Symbols -- Q = States -- q 0 = Initial State -- F = Accepting States Q -- δ :Q Σ Q = Transition Functions Analog Machine Hard Wired, No Code Read Only, State is Memory
Push-Down Automata Push Down Automata (PDA) Finite State Automata with a Stack Can Write on the Stack -- More Memory in Stack -- Stack can be used for Counting Accept Halts in an Accepting State AND Stack is Empty PDA more Powerful than FSA Non-Deterministic (Analog?) Machine
Turing Machine Informal Definition Control Unit -- States Doubly infinite tape -- input -- output -- memory Tape reader Initial state (See Picture)
Turing Machine Machine with states -- finite automata Tape -- mostly blank Tape head -- on leftmost nonblank symbol
Turing Machine Formal Definition M = {Q, Σ, H, δ, s 0 } Q = set of states s 0 = initial state H = halting states Q Σ = tape alphabet δ :(Q H ) Σ Q Σ {R, L} -- go to new state -- write new symbol on tape -- replace old symbol -- move tape head to left or right -- list of 5-tuples -- (s, x; s, x, L / R)
Turing Machine Machine Move Change symbol under tape head Move tape head Change state Analog Machine? Hardware and Software Turing Machine = Computer (Hardware) 5-tuples = Program (Software) Functions M maps the input x to the output y and then halts. M is a partial function because M might not halt.
Diagrams of Turing Machines Diagrams States = Circles Arrows = Transition Functions -- From Current State to Next State Labels on Arrows = x / y /(L or R) -- Read x -- Write y -- Move Left or Right
Configurations of Turing Machines (q,w L,x, w R ) (q,w L x w R ) -- q = current state -- x = current symbol on tape -- w L = string of non blank symbols to the left of x -- w R = string of non blank symbols to the right of x
What a Turing Machine Can Do Halt -- Accept or Reject Loop -- Cycle Diverge -- Never Halt or Cycle
` Languages and Turing Machines Decidable Languages M Halts in Accept State x L M Halts in Reject State x L Semi Decidable Languages M Always Halts in Accept State x L M Might Loop or Diverge for x L
Decidable Languages L = {a n b n c n } -- Not Context Free L = {wc w w {a,b} } -- Not Context Free
Power of Turing Machine Lemma: L = {a n b n c n } can be recognized by a Turing Machine (L is not context free -- pumping theorem) Proof: If Tape Empty, Halt and Accept Otherwise, Replace first a with 1 Move Right to first b and Replace with 2 -- If no b or if c encountered first, Halt and Reject Move Right to first c and Replace with 3 -- If no c or if a encountered first, Halt and Reject Continue until all a s converted to 1 s If no b s or c s remain, Halt and Accept Otherwise, Halt and Reject
Functions and Turing Machines Turing Machines as Functions Input = Initial String (Non Blanks) on Tape -- x X = Domain Output = Final String on Tape when Machine Halts -- y Y = Range Function -- M : X Y -- M(x) = y Computable (Recursive) Functions -- Functions that can be Computed by Some Turing Machine
Examples Language Recognition x Σ = Domain = Strings Output: Range = {TRUE, FALSE} M recognizes L if and only if -- M Halts and Writes TRUE on the Tape when x L -- M Halts and Writes FALSE on the Tape when x L Functions on Natural Numbers Encode Natural Numbers as Binary (or Decimal) Strings -- Input and Output are Binary (Decimal) Strings Example: Adding 1 to a Binary Number -- Carrying Function
Part II: Equivalent Machines
Equivalent Machines for Simplifying Proofs 1. Multiple Tapes 2. Nondeterminism 3. One Way Tape 4. Two Stacks 5. One Queue
Multiple Tape Turing Machine Description Input on Tape 1 -- All Other Tapes Start Blank ª Output on Tape 1 -- Contents of All Other Tapes Ignored Move all Tape Heads Simultaneously -- Left, Right, or Stay in Same Location Halt
Simulating Multiple Tapes with One Tape Tape Alphabet Introduce New Tape Symbols to Represent with a Single Symbol -- Contents of Each Position on Each Tape -- Location of Each Tape Head -- 0, 1 Number of Tapes One New Symbol for Each Element of (Σ {0,1}) Program Replace Original Tape Symbols by New Tape Symbols Locate and Store (in State) Symbols at Current Head Locations Change Symbols to Simulate Each Head Move Replace New Tape Symbols by Corresponding Original Tape Symbols Halt
Nondeterministic Machines Non Deterministic Finite State Automata Simultaneous Transitions to Many Possible Different States No More Powerful than Deterministic Finite State Automata Non Deterministic Push Down Automata Simultaneous Transitions to Many Possible Different States and Stacks More Powerful than Deterministic Push Down Automata
Nondeterministic Turing Machine Simultaneous Transitions Many Possible Different States Multiple Possible Head Directions Writing Many Possible Different Symbols on Current Tape Location Accept or Reject Accept if at Least One Computation Accepts Reject if ALL Computations Reject
Non-Determinism and Languages Decidable (M Decides L) Finite Number of Paths for Each String Each Path Halts M Accepts w On at Least 1 Path w L Semi-Decidable (M Semi-Decides L) M Accepts w on at Least 1 Path w L M Need Not Halt for w L
Non-Determinism and Functions M Compute F For Each w in Domain F -- Every Path Halts -- Final String is the Same F(w) for Every Path
Simulating Nondeterminism Depth First Search No Why? Breadth First Search Yes Why?
Simulating 1 Two Way Tape with 3 One Way Tapes Tapes Tape #1 = Characters to the Right of Initial Position Tape #2 = Characters Introduced to the Left of Initial Position Tape #3 = Number of Operations in Unary (All 1 s) Simulation Initialize Tape #1 to Initial Characters; Tape #2, Tape 3 Blank Simulate All Moves to Right of Initial Position on Tape #1 Simulate All Moves to Left of Initial Position on Tape # 2 Update Number of Operations on Tape #3 Shift All Characters on Tape #1 to Right by #1 s on Tape #3 Move Characters from Tape #2 to Tape #1
Turing Machines and Push Down Automata Theorems 1. Every Push Down Automaton can be Simulated with a Turing Machine. 2. Every Turing Machine can be Simulated by a Push Down Automaton with 2 Stacks. 3. Turing Machines are more powerful than Push Down Automata with 1 Stack.
Theorem 1 Every Push Down Automaton can be Simulated by a Non-Deterministic Turing Machine with 2 Tapes Simulation Tape #1 = Characters in String -- Read Only -- Move Only to Right Tape #2 = Characters on Stack -- Left to Right on Tape Bottom to Top of Stack -- Head at Right End of Tape #2 (Top of Stack) -- Pop -- Scan Left Replacing Symbols by Blanks -- Push -- Scan Right Replacing Blanks by Symbols
Theorem 2 Every Turing Machine can be Simulated by a Push Down Automaton with 2 Stacks Simulation Stack #1 = Characters to Left of Head and Under Reading Head -- Left to Right Bottom to Top Stack #2 = Characters to Right of Reading Head -- Left to Right Top to Bottom Move Left Move Right Pop Stack #1 Pop Stack #2 Push Stack #2 Push Stack #1
Theorem 3 Turing Machines are more Powerful than Push Down Automaton with 1 Stack. Proof Turing Machines can Recognize the Language L = {a n b n c n }.
Turing Machine with Queue Description Finite State Automata with a Queue Push Down Automata with Queue in Place of Stack Simulating a Turing Machine Queue: Treat as a Loop -- Turing Tape = Queues in Reverse Order (First In First Out) Move Right = Move Head of Queue to Tail of Queue -- If Blank, Insert New Symbol to Tail of Queue Move Left = Move All but the First Symbol from the Head to the Tail -- If Blank, Insert an Additional Symbol onto Tail and Move All Other Symbols From Front to Back of Queue
Simulating a Digital Computer with a Turing Machine Seven Tapes Tape #1 = Memory = Program + Data Tape #2 = Program Counter = Index into Memory in Tape #1 Tape #3 = Address Register Tape #4 = Accumulator Tape #5 = Operation Code of Current Instruction Tape #6 = Input File Tape #7 = Output File
Part III: Universal Turing Machines
Encoding Turing Machines States Number the States in Any Order Code the Numbers in Binary -- Accepting State = y-binary -- Rejecting State = n-binary -- Other States = q-binary Symbols Number the Symbols in Any Order Code the Numbers in Binary Assign a-binary to Each Symbol
Godel Numbering for Special Symbols Symbol Godel Number q 0000 y 0001 n 0010 a 0011 L 0100 R 0101 ( 0110 ) 0111, 1000
Encoding Turing Machines (continued) Transition Functions (State, Input Character, New State, Output Character, Move) (q-binary, a-binary, q-binary, a-binary, L or R) Turing Machine List of Transition Functions Godel Number = Binary Number Corresponding to List of Transition Functions
Universal Turing Machine Input Encoding of Any Turing Machine M -- Also could input just the Number encoding M in Lexicographic Order Encoding of Input Tape for M 3 Tapes Tape #1 = Tape of Input for M Tape #2 = Encoding of (Transition Functions) for M Tape #3 = Current State of M
Universal Turing Machine (continued) Simulation Find Current State of M -- Tape #3 Find Current Character -- Tape #1 Find Appropriate Transition Function for State and Character -- Tape #2 Apply Transition Function -- Update Tape #1 and Tape #3 Continue Until in Halting State Conclusion Universal Turing Machine with input <M, w> reports same result as Turing Machine M on Input w
Universal Turing Machine as Digital Computer Machine Move Change symbol under tape head -- Tape #1 Move tape head -- Tape #1 Change state -- Tape #3 Hardware Universal Turing Machine Software Transition Functions = Program Data = Input String
Number of Turing Machines How Many Turing Machines? Turing Machine Finite List of 5-tuples -- δ :Q Σ Q Σ {R, L} -- (q, x; q, x, L / R) Number of finite lists of 5-tuples in countable -- # Turing machines with 1 state is countable -- # TM with 1 state = # 5-tuples = 2 Σ 2 -- # Turing machines with n states is countable -- # TM with n states = # 5-tuples = 2n 2 Σ 2 Countable union of countable sets is countable Number of Turing machines is countable
Non Computable Functions Existence of Non Computable Functions -- Counting Argument There are only countably many Turing machines -- Turing machines can be listed in Lexicographic order There are uncountably many functions { f : N {0, 1} } P(N) Existence of Non Computable Functions -- Diagonalization Argument List the Turing Machines List all Possible Input Strings Set F(w i ) = 0 if M i (w i ) =1 =1 if M i (w i ) = 0 F not in List Exist Non-Computable Functions