Turing Machine Variations CIS 301 Theory of Computation Brian C Ladd Computer Science Department SUNY Potsdam Fall 2016 November 16, 2016 Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 ) Turing Machine Variations November 16, 2016 1 / 25
Outline Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 ) Turing Machine Variations November 16, 2016 2 / 25
Formal Definition Definition A Turning Machine (TM) is a 7-tuple M = (Q, Σ, Γ, δ, q 0, q accept, q reject ) 1 Q is a set of states 2 Σ is the input alphabet not including the special blank symbol 3 Γ is the tape alphabet Γ and Σ Γ 4 δ : Q Γ Q Γ {L, R} Example: δ(q,a) = (r,b, L) 5 q 0 Q is the start state 6 q accept Q is the accept state 7 q reject Q is the reject state Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 3 / 25
Variations? What could we vary in the Turing Machine? Head Movement: add stay put ; remove L Do they add any functionality? Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 ) Turing Machine Variations November 16, 2016 4 / 25
Variations? What could we vary in the Turing Machine? Head Movement: add stay put ; remove L Tape: doubly infinite; multiple tapes; 2-d tape Do they add any functionality? Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 ) Turing Machine Variations November 16, 2016 4 / 25
Variations? What could we vary in the Turing Machine? Head Movement: add stay put ; remove L Tape: doubly infinite; multiple tapes; 2-d tape Alphabet: minimize to {0, 1, } Do they add any functionality? Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 ) Turing Machine Variations November 16, 2016 4 / 25
Variations? What could we vary in the Turing Machine? Head Movement: add stay put ; remove L Tape: doubly infinite; multiple tapes; 2-d tape Alphabet: minimize to {0, 1, } Finite control: minimize to 3 states Do they add any functionality? Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 ) Turing Machine Variations November 16, 2016 4 / 25
Reduction to Turing Machine What would show a given variation is no more powerful than a TM? Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 ) Turing Machine Variations November 16, 2016 5 / 25
Reduction to Turing Machine What would show a given variation is no more powerful than a TM? Convert the description of a varying machine to a TM Emulate the varying machine using a standard Turing Machine Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 ) Turing Machine Variations November 16, 2016 5 / 25
Stay Put TM Extend δ to δ S : Q Q Γ {L, R, S} Replace each transition with S, δ S (q i, c j ) = (q k, c l, S), with two transitions: Note: Γ appearing on both sides of a transition means no matter what is read, write the same symbol Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 6 / 25
Stay Put TM Extend δ to δ S : Q Q Γ {L, R, S} Replace each transition with S, δ S (q i, c j ) = (q k, c l, S), with two transitions: δ(q i, c j ) = (q k, c l, R) Note: Γ appearing on both sides of a transition means no matter what is read, write the same symbol Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 6 / 25
Stay Put TM Extend δ to δ S : Q Q Γ {L, R, S} Replace each transition with S, δ S (q i, c j ) = (q k, c l, S), with two transitions: δ(q i, c j ) = (q k, c l, R) δ(q k, Γ) = (q k, Γ, L) Note: Γ appearing on both sides of a transition means no matter what is read, write the same symbol Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 6 / 25
Two-Way Infinite Tape TM Extend the tape to be infinite to the left as well as to the right Head begins reading the left-most non-blank on the tape Blanks not allowed in the input Emulate on a standard Turing Machine: Imagine: Fold the double-infinite tape over on itself Mark the fold and alternate the cells: odd cells are the tape to the right; even cells are the tape to the left Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 7 / 25
Two-Way Infinite Tape TM Extend the tape to be infinite to the left as well as to the right Head begins reading the left-most non-blank on the tape Blanks not allowed in the input Emulate on a standard Turing Machine: Imagine: Fold the double-infinite tape over on itself Mark the fold and alternate the cells: odd cells are the tape to the right; even cells are the tape to the left Start with input on tape Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 7 / 25
Two-Way Infinite Tape TM Extend the tape to be infinite to the left as well as to the right Head begins reading the left-most non-blank on the tape Blanks not allowed in the input Emulate on a standard Turing Machine: Imagine: Fold the double-infinite tape over on itself Mark the fold and alternate the cells: odd cells are the tape to the right; even cells are the tape to the left Start with input on tape Move input one cell to the right Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 7 / 25
Two-Way Infinite Tape TM Extend the tape to be infinite to the left as well as to the right Head begins reading the left-most non-blank on the tape Blanks not allowed in the input Emulate on a standard Turing Machine: Imagine: Fold the double-infinite tape over on itself Mark the fold and alternate the cells: odd cells are the tape to the right; even cells are the tape to the left Start with input on tape Move input one cell to the right Put $ in the first location (marks flip over point) Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 7 / 25
Two-Way Infinite Tape TM Extend the tape to be infinite to the left as well as to the right Head begins reading the left-most non-blank on the tape Blanks not allowed in the input Emulate on a standard Turing Machine: Imagine: Fold the double-infinite tape over on itself Mark the fold and alternate the cells: odd cells are the tape to the right; even cells are the tape to the left Start with input on tape Move input one cell to the right Put $ in the first location (marks flip over point) Spread the input to every other cell, putting blanks between them Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 7 / 25
Two-Way Infinite Tape TM Extend the tape to be infinite to the left as well as to the right Head begins reading the left-most non-blank on the tape Blanks not allowed in the input Emulate on a standard Turing Machine: Imagine: Fold the double-infinite tape over on itself Mark the fold and alternate the cells: odd cells are the tape to the right; even cells are the tape to the left Start with input on tape Move input one cell to the right Put $ in the first location (marks flip over point) Spread the input to every other cell, putting blanks between them For every L : move two to the left (use intermediate state that leaves cell contents alone): if middle cell has $ then reverse direction, moving R by two locations Remember that directions are reversed in the store Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 7 / 25
Two-Way Infinite Tape TM Extend the tape to be infinite to the left as well as to the right Head begins reading the left-most non-blank on the tape Blanks not allowed in the input Emulate on a standard Turing Machine: Imagine: Fold the double-infinite tape over on itself Mark the fold and alternate the cells: odd cells are the tape to the right; even cells are the tape to the left Start with input on tape Move input one cell to the right Put $ in the first location (marks flip over point) Spread the input to every other cell, putting blanks between them For every L : move two to the left (use intermediate state that leaves cell contents alone): if middle cell has $ then reverse direction, moving R by two locations Remember that directions are reversed in the store For every R : move two to the right If directions are reversed, could see $ so react by moving to correct next cell and re-reversing directions Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 7 / 25
Multi-tape TM Extend a TM with k tapes, each with its own read/write head Initially tape 1 contains the input; all other tapes are blank δ M : Q Γ k Q Γ k {L, R} k Example δ M (q i, a 1,, a k ) = (q j, b 1,, b k, L,, R) Theorem (310) Every multi-tape TM has an equivalent single tape TM Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 8 / 25
Multi-tape TM Sketch Show how to emulate multi-tape machine M with a single tape machine, S Finite Control 1 0 1 1 0 a b c c r s r s Γ M = {0, 1, a, b, } Γ S = {0, 1, a, b,, #, 0, 1, ȧ, ḃ, } Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 9 / 25
Multi-tape TM Proof S = On input string w = w 1 w n : 1 First S puts its tape into the format that represents all k tapes of M The formatted tape of S contains: # w 1 w 2 w n # # # 2 To simulate a single move of M, S scans its tape from the first #, which marks the left-hand end, to the (k + 1)st #, which marks the right-hand end, in order to determine the symbols under the virtual heads Then S makes a second pass to update the tapes according to the way that M s transition function dictates 3 If at any point S moves one of the virtual heads to the right onto a #, this action signifies that M has moved the corresponding head onto the previously unread blank portion of that tape So S writes a blank symbol on this tape cell and shifts the tape contents, from this cell until the rightmost #, one unit to the right Then S continues as before Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 10 / 25
Multi-tape TM # 1 0 1 1 0 # a b c ċ # r ṡ r s # Finite Control Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 ) Turing Machine Variations November 16, 2016 11 / 25
Multi-tape TM Definition A language is Turing-recognizable iff TM that recognizes it Corollary A language is Turing-recognizable iff multi-tape TM that recognizes it Proof If a language is Turing-recognizable, then multi-tape TM that recognizes it By definition: if language is Turing-recognizable, L is recognized by some single-tape TM A single-tape TM is a one-tape multi-tape TM multi-tape machine that recognizes L Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 12 / 25
Multi-tape TM Definition A language is Turing-recognizable iff TM that recognizes it Corollary A language is Turing-recognizable iff multi-tape TM that recognizes it Proof If multi-tape TM that recognizes language L, then L is Turing-recognizable Show that any multi-tape TM can be simulated on a single-tape TM (proof is from previous slides) Since any multi-tape machine can run on a single tape, L, recognized by a multi-tape machine is also recognized by some single-tape machine; therefore L is Turing-recognizable Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 13 / 25
Non-deterministic TM Extend TM such that it may proceed in any number of ways δ N : Q Γ P(Q Γ {L, R}) Approach: Where there is a choice point, a new TM is spawned The TMs form a tree If one of the TMs succeeds (enters an accept state), then the nondeterministic machine accepts its input Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 14 / 25
Non-deterministic TM Theorem Every non-deterministic TM has an equivalent deterministic TM Proof Keep a tree of the nondeterministc TMs and search it breadth-first Why not search depth-first? Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 ) Turing Machine Variations November 16, 2016 15 / 25
Non-deterministic TM Theorem Every non-deterministic TM has an equivalent deterministic TM Proof Keep a tree of the nondeterministc TMs and search it breadth-first Why not search depth-first? Must execute each machine, adding one step at a time Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 ) Turing Machine Variations November 16, 2016 15 / 25
Non-deterministic TM Theorem Every non-deterministic TM has an equivalent deterministic TM Proof For D, the deterministic version of N, use three tapes 1 Tape 1 - input string 2 Tape 2 - a copy of N tape run for k steps on one copy of the machine 3 Tape 3 - address tape Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 ) Turing Machine Variations November 16, 2016 16 / 25
Non-deterministic TM Theorem Every non-deterministic TM has an equivalent deterministic TM Proof Description of D s operation: 1 Initially, tape 1 contains w and tapes 2 and 3 are empty, in start state 2 Copy tape 1 to tape 2 3 Use tape 2 to simulate N with input w on one branch of N s computation Before each step on this branch, look at the next symbol on tape 3 to determine which choice to make among those that are possible If no more symbols are on tape 3 (at a blank) or the choice is invalid, abort this computation by going to stage 4 Also go to stage 4 if a rejecting configuration is encountered If an accepting configuration is encountered, accept the input 4 Replace the string on tape 3 with the lexicographically next string, and go to stage 2 Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 17 / 25
Non-deterministic TM Corollary A language, L, is Turing recognizable iff some non-deterministic TM recognizes it Proof Any deterministic TM is also a non-deterministic TM; if L is Turing-recognizable, M L, M L a deterministic TM recognizer: L is recognized by a NTM By previous theorem, NTM recognizer N L can be simulated on a DTM, M N:L : M N:L is a DTM recognizer of L Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 18 / 25
Non-deterministic TM Corollary A language, L, is Turing decidable iff some non-deterministic TM decides it Proof Any deterministic TM is also a non-deterministic TM; if L is Turing-decidable, M L, M L a deterministic TM decider: L is decided by a NTM By previous theorm, NTM decider N L can be simulated on a DTM, M N:L : M N:L is a DTM decider of L Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 19 / 25
Enumerators Definition An enumerator is a TM with a printer The language enumerated by E is the set of all strings printed to its printer Order and repetition are not important Theorem A language is Turing-recognizable iff some enumerator enumerates it How is this different from what I discussed on Monday? What difference does it make Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 ) Turing Machine Variations November 16, 2016 20 / 25
Enumerators Theorem A language is Turing-recognizable iff some enumerator enumerates it Proof If E enumerates the language, A, construct TM M which recognizes the language: M = On input w: 1 Run E Every time that E outputs a string, compare it with w 2 If this output of E matches w, accept, else go to 1 Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 ) Turing Machine Variations November 16, 2016 21 / 25
Enumerators Theorem A language is Turing-recognizable iff some enumerator enumerates it Proof A is Turing-recognizable; construct an enumerator E to enumerate it L(M) = A, M a TM (by definition of Turing-recognizable) A Σ ; let s 1, s 2, s 3, be an infinite sequence of all the strings in Σ E = Ignore the input 1 For i = 1, 2, 3, 1 Run M for i steps on each input s 1,, s i 2 If M accepts any of these strings, print it Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 22 / 25
Enumerators Example Run M for i Steps, i = Strings Tested Printer output 1 s 1 2 s 1, s 2 3 s 1, s 2, s 3 4 s 1,s 2,s 3, s 4 s 2 5 s 1,s 2,s 3, s 4,s 5 s 2, s 5 6 s 1,s 2,s 3, s 4,s 5, s 6 s 2, s 3, s 5 7 s 1,s 2,s 3, s 4,s 5, s 6, s 7 s 2, s 3, s 5 8 s 1,s 2,s 3, s 4,s 5, s 6, s 7 s 1, s 2, s 3, s 5 Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 23 / 25
Turing Machine Summary There are other models of general purpose computation that have been proposed Example A PDA with a deque? Peter Joachim, contributor All are similar to TM: 1 Unrestricted access to a limitless memory FA - limited memory PDA - limitless memory, but restricted access 2 All perform a finite amount of work in a given step All machines with the above two features have the same power of computation as a TM Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 24 / 25
What Does This Mean? 1 Any model of computation can be simulated by a TM and vice versa 2 Any algorithm that runs on any other machine can be run on a TM Definition Since all computational models can simulate each other and compute all the same algorithms, we can describe an algorithm as being able to be run on a computing machine This is a unique, precise description of the class algorithm A precise definition of algorithm was not worked out until Turing and Church came along Brian C Ladd ( Computer Science Department SUNY Potsdam Fall 2016 Turing ) Machine Variations November 16, 2016 25 / 25