Turing Machines and Their Variants CSCI 3130 Formal Languages and Automata Theory Siu On CHAN Fall 2018 Chinese University of Hong Kong 1/26
Looping Inputs can be divided into three types: Infjnite loop Reject q rej Accept q acc 2/26 Turing machine may not halt q rej q acc q 0 � / � R 0 / 0R Σ = { 0 , 1 } input: ε 1 / 1R
Halting We say M halts on input x if there is a sequence of confjgurations A TM M is a decider if it halts on every input Language L is decidable if it is recognized by a TM that halts on every input 3/26 C 0 , C 1 , . . . , C k C i yields C i + 1 C 0 is starting C k is accepting or rejecting
Programming Turing machines: Are two strings equal? xxbaa#xbbaa 8 xxbaa#xxbaa Move left past # and to right of fjrst x 7 xxbaa#xxbaa Write x 6 If this entry is different, reject 5 Move right past # and past all x ’s 4 xxbaa#xbbaa Write x 3 xbbaa#xbbaa Read and remember entry 2 Until you reach # 1 Description of Turing Machine 4/26 L 1 = { w # w | w ∈ { a , b } ∗ } If you see only x ’s followed by � , accept
Programming Turing machines: Are two strings equal? b / b L b / b R x / x R a / a R b / b R x / x R a / a L x / x L x / x R # / # L a / a L b / b L x / x R 7 8 everything else a / a R 5/26 1 q rej # / # R q 0 q 1 q acc q a 1 q a 2 q b 1 q b 2 q 2 q 3 L 1 = { w # w | w ∈ { a , b } ∗ } # / # R 4 a / x L 3 2 a / x R 5 6 � / � R b / x R 2 6 5 b / x L 3 # / # R 4
Programming Turing machines: Are two strings equal? b / b L b / b R x / x R q 0 a / a L b / b L x / x L # / # L a / a L x / x R x / x R 7 8 everything else input: aab#aab confjgurations: . . . a / a R 6/26 q 3 q rej a / a R q 1 q acc q a 1 x / x R q a 2 q b 1 q b 2 1 # / # R q 2 b / b R q 0 aab#aab # / # R 4 a / x L x q a 1 ab#aab 3 2 xa q a 1 b#aab a / x R 5 6 xab q a 1 #aab � / � R xab# q a 2 aab b / x R 2 6 xab q 2 #xab 5 b / x L xa q 3 b#xab 3 x q 3 ab#xab # / # R 4 q 3 xab#xab x q 0 ab#xab
Programming Turing machines 3 Cross off this a 4 Uncross the crossed b ’s (but not the c ’s) 7/26 Example: 2 High level description of TM: L 2 = { a i b j c k | ij = k and i , j , k > 0 } 1 For every a : 1 aabbcccc 2 aabbcccc Cross off the same number of b ’s and c ’s 3 aabbcccc 4 aabbcccc 5 If all a ’s and c ’s are crossed off, accept 5 aabbcccc 2 aabbcccc 3 aabbcccc Σ = { a , b } Γ = { a , b , c , a , b , c , � }
Programming Turing machines Low-level description of TM: Move the head to the fjrst symbol of the tape How? For every a : How? Restore the crossed off b ’s (but not the c ’s) Cross off this a If all a ’s and c ’s are crossed off, accept 8/26 L 2 = { a i b j c k | ij = k and i , j , k > 0 } Scan input from left to right to check it looks like aa ∗ bb ∗ cc ∗ Cross off the same number of b ’s and c ’s
Programming Turing machines Low-level description of TM: Move the head to the fjrst symbol of the tape How? For every a : How? Restore the crossed off b ’s (but not the c ’s) Cross off this a If all a ’s and c ’s are crossed off, accept 8/26 L 2 = { a i b j c k | ij = k and i , j , k > 0 } Scan input from left to right to check it looks like aa ∗ bb ∗ cc ∗ Cross off the same number of b ’s and c ’s
Programming Turing machines Move right until you see a c ȧabbcccc ȧabbcccc If any uncrossed b ’s are left, repeat ȧabbcccc ȧabbcccc Implementation details: ȧabbcccc ȧabbcccc Replace b by b ȧabbcccc ȧabbcccc Move the head to the fjrst symbol of the tape: 9/26 Put a special marker on top of the fjrst a Cross off the same number of b ’s and c ’s: Replace c by c Move left just past the last b Σ = { a , b , c } Γ = { a , b , c , a , b , c , ȧ , ȧ , � }
Programming Turing machines: Element distinctness Example: High-level description of TM: On input w If they are the same, reject Accept 10/26 L 3 = { # x 1 # x 2 . . . # x m | x i ∈ { 0 , 1 } ∗ and x i � = x j for every i � = j } #01#0011#1 ∈ L 3 For every pair of blocks x i and x j in w Compare the blocks x i and x j
Programming Turing machines: Element distinctness Low-level desrciption: 0. 1. # and move right #01#0011#1 2. Mark the next unmarked # #0011#1 11/26 L 3 = { # x 1 # x 2 . . . # x m | x i ∈ { 0 , 1 } ∗ and x i � = x j for every i � = j } If input is ε , or has exactly one # , accept Mark the leftmost # as ˙ ˙ ˙ #01 ˙
Programming Turing machines: Element distinctness # #1 #1 #1 Repeat Step 3 5. If not possible, accept # on the next # #1 # to the next # 12/26 #0011#1 3. 4. # If they are equal, reject L 3 = { # x 1 # x 2 . . . # x m | x i ∈ { 0 , 1 } ∗ and x i � = x j for every i � = j } Compare the two strings to the right of ˙ ˙ #01 ˙ Move the right ˙ ˙ #01#0011 ˙ If not possible, move the left ˙ and put the right ˙ ˙ #01#0011 ˙ #01 ˙ #0011 ˙ #01 ˙ #0011 ˙
How to describe Turing Machines Unlike for DFAs, NFAs, PDAs, we rarely give complete state diagrams of Turing Machines unless you’re asked for a low-level description or even state diagram We are interested in algorithms behind the Turing machines 13/26 We usually give a high-level description
Programming Turing machines: Graph connectivity How do we feed a graph into a Turing Machine? 1 2 3 4 (1,2,3,4)((1,4),(2,3),(3,4),(4,2)) Conventions for describing graphs: ( nodes )( edges ) no node appears twice edges are pairs ( fjrst node , second node ) 14/26 L 4 = {� G � | G is a connected undirected graph } How to encode a graph G as a string � G � ?
Programming Turing machines: Graph connectivity already marked node 4 3 2 1 reject 3. If all nodes are marked, accept; otherwise 2.1 For each node, mark it if it is adjacent to an 2. Repeat until no new nodes are marked: 1. Mark the fjrst node of G nodes No node/edge repeats; Edge endpoints are High-level description: 15/26 L 3 = {� G � | G is a connected undirected graph } On input � G � 0. Verify that � G � is the description of a graph
Programming Turing machines: Graph connectivity 2. Repeat until no new nodes are marked: pair If not found, remove underline from u and/or v and try another Try to match them with an edge from the edge list Underline both u and v from the node list For every dotted node u and every undotted node v : 2.1 For each node, mark it if it is attached to an already marked node 12 Some low-level details: 1. Mark the fjrst node of G Also similar to Element distinctness Edge endpoints are nodes: Similar to Element distinctness No node/edge repeats: 16/26 0. Verify that � G � is the description of a graph Mark the leftmost digit with a dot, e.g. 12 becomes ˙
Variants of Turing machines
Multitape Turing machine control Different tape heads can move independent Transitions may depend on the contents of all cells under the heads … b a b … 17/26 a b a … b a b b � � � � �
Multitape Turing machine q 3 q 7 Multiple tapes are convenient One tape can serve as temporary storage 18/26 b a � � … b a � � … � � / � L a / b R a b a � … a b b � … a / a R a a b � … a a b � …
How to argue equivalence Multitape Turing machines are equivalent to singlne-tape Turing machines multiple tapes single tape easy requires simulation 19/26
Simulating multitape Turing machine M S 20/26 b a � � … Γ = { a , b , � } a b b � … a a � � … a # a b b ˙ # b ˙ � # a ˙ a # � … a , ˙ b , ˙ Γ = { a , b , � , ˙ � , # }
Simulating multitape Turing machine We show how to simulate a multitape Turing machine on a single tape Turing machine To be specifjc, let’s simulate a 3-tape TM Multitape TM M Single tape TM S 21/26 x 1 … x r … x i � y 1 … … y s … y j � z 1 … z t … z k � # x 1 x 2 . . . ˙ x r . . . x i # y 1 y 2 . . . ˙ y s . . . y j # z 1 z 2 . . . ˙ z t . . . z k
Simulating multitape Turing machine Single-tape TM: Initialization Remember that M is in state q 0 22/26 w 1 w 2 . . . w n w 1 w 2 . . . w n # ˙ � # ˙ # ˙ � S : On input w 1 . . . w n : w 1 w 2 . . . w n # ˙ � # ˙ Replace tape contents by # ˙ �
Simulating multitape Turing machine q 3 We simulate the move on single-tape TM S like this Single-tape TM: Simulating multitape TM moves q 7 23/26 Suppose Multitape TM M moves like this: b a � � … b a � � … � � / � L a / b R a b a � … a b b � … a / a R a a b � … a a b � … # b a ˙ � # a b ˙ a # ˙ a a b # � a # a b b ˙ # b ˙ � # a ˙ a b # �
Simulating multitape Turing machine z If M reaches accept (reject) state, S accepts (rejects) update state/tape accordingly q b q a 24/26 S simulates a step of M : Remember (in state) that M is in state q 0 S given input w 1 . . . w n : w 1 w 2 . . . w n # ˙ � # ˙ Replace tape contents by # ˙ � Make a pass over tape to fjnd ˙ x , ˙ y , ˙ # x 1 x 2 . . . ˙ x . . . x i # y 1 y 2 . . . ˙ y . . . y j # z 1 z 2 . . . ˙ z . . . z k � x / x ′ A y / y ′ B z / z ′ C If M at state q a has transition
Simulation To simulate a model M by another model N : Say how the state and storage of N is used to represent the state and storage of M Say what should be initially done to convert the input of N Say how each transition of M can be implemented by a sequence of transitions of N 25/26
Recommend
More recommend