1 / 18

Turing Machines

CSC 4170 Theory of Computation. Turing Machines. Section 3.1. 3.1.a. Components of a Turing machine (TM). a a b a b b - - - - - -. (Q,  ,  ,  ,start,accept,reject). Q is the set of states

morses
Download Presentation

Turing Machines

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 4170 Theory of Computation Turing Machines Section 3.1

  2. 3.1.a Components of a Turing machine (TM) a a b a b b - - - - - - (Q,,,,start,accept,reject) • Q is the set of states •  is the input alphabet not containing the blank symbol - •  is the tape alphabet, where - and  •  is the transition function of the type Q Q{L,R} • start,accept,rejectQ, where rejectaccept; the states • accept and reject are called halting states. • There are no transitions from the halting states, and they immediately take effect! xy,R q1 q2 If the current tape symbol is x, replace it with y, move the head right and go to q2. The label xx,R is simply written as xR. If we here have L instead of R, then the head is moved left, unless it was on the first cell, in which case it remains where it was.

  3. 3.1.b 0  L x  L How a Turing machine works q5 xR -  R -  L xR start q2 q3 0 -,R 0x,R •  R • x  R -  R 0 x,R 0R xR q4 reject accept • Configuration: • Current state; • Tape contents; • Head position -  R - x 0 0 - - - - - - -

  4. 3.1.c1 Definitions A TM accepts an input string iff, for this input, sooner or later it enters the accept state. Otherwise the string is considered rejected. • Thus, the input is rejected in two cases: • The machine enters the reject state at some point, or • The machine never halts (never enters a halting state). A Turing machine is said to be a decider iff it halts for every input. The language recognized by a TM --- the set the strings that TM accepts; If this machine is a decider, then we say that it not only recognizes, but also decides that language. A language is said to be Turing-recognizable iff some TM recognizes it. A language is said to be Turing-decidable iff some TM decides it.

  5. 3.1.c2 Recognizing vs deciding accept 0  R -  R -  R •  R • 0 R 0  R reject What language does the above machine recognize? Does it decide that language? accept 0  R -  R 0  R -  R reject What language does the above machine recognize? Does it decide that language?

  6. 3.1.d Diagrams without the reject state 0  L x  L xR q5 -  R -  L start xR q2 q3 0 -,R 0x,R -  R 0R 0 x,R accept xR q4 The reject state can be safely removed. It will be understood that all the missing transitions lead to the reject state.

  7. 3.1.e1 Designing TM: Example 1 Design a TM that recognizes (better – decides) {#n =m | n=m} 1. Sweep left to right across the tape, testing if the input has the form #*=*; if not, reject; if yes, go back to the beginning of the tape and go to step 2 (state q3). L = L x L - L R R = R - L # R start q1 q2 q9 #  L q3

  8. 3.1.e2 Designing TM: Example 1 2. Keep going to the right, replace the first  you see before = with x andgo to step 3 (state q5); if you reach = without seeing a , go to step 4 (state q6). xR x,R q4 q3 q5 # R = R q6

  9. 3.1.e3 Designing TM: Example 1 3. Keep going to the right, pass = and then replace the first  you see with x andgo to the beginning of the tape, step 2 (this can be done by going to state q9); if you reach a blank without seeing a , reject. q9 x,R R = R xR q7 q5

  10. 3.1.e4 Designing TM: Example 1 4. Keep going to the right as long as you see x. If you see a  before reaching a blank, reject; otherwise accept. xR - R accept q6

  11. 3.1.e5 Designing TM: Example 1 L = L x L - L R R = R - L # R start q1 q2 q9 #  L x,R xR R x,R = R xR q4 q7 q3 q5 # R xR = R - R accept q6 - - - #     =    

  12. 3.1.f Designing TM: Example 2 Design a TM that decides {#n <m | n<m} L < L x L L < L x L - L R R < R - L # R start q1 q2 q9 #  L x,R xR R x,R < R xR q4 q7 q3 q5 # R xR < R R accept q6

  13. 3.1.g Designing TM: Example 3 Design a TM that decides {#n +m = k | n+m=k} + L L = L x L - L R R R = R - L + R # R start q1 q2 q9 q0 #  L x,R xR +R R +R x,R = R xR q4 q7 q3 q5 # R xR = R - R accept q6

  14. 3.1.h Designing TM: Example 4 Design a TM that decides {#n m = k | nm=k} Step 1: Check if the string has the form #* * = * . If not, reject; If yes, go back to the beginning of the tape, step 2. Step 2: Find the first  between # and, delete it and go to step 3; If no suchwas found, go to step 5. Step 3: Find the first  between and =,delete it and go to step 4; If no suchwas found, go to the beginning of the tape, restoring on the way back all the deletedbetween and=,and go to step 2. Step 4: Find the first  after=, delete it, go back to ,and go to step 3; If no suchwas found before seeing a blank, reject. Step 5: Go right past = ; if no  is found there before reaching a blank, Accept; otherwise reject.       =       - #

  15. 3.1.i Design a fragment of a TM that, from a state “Beg?”, goes to a state “Yes” or “No”, depending on whether you are at the beginning of the tape or not, without corrupting the contents of the tape. Testing whether the head is at the beginning of the tape Tape alphabet: {x1,…,xn} Add a new tape symbol: $ • Read the current symbol, remember it, type $, and move left; • Read the current symbol. • If it is $, restore the remembered symbol and go to “Yes”. • If it is not $, move right, restore the remembered symbol and go to “No”. x1,…,xnR a1 b1 $ x1,L x1,R x1$,L … L Beg? Yes Temp No xn$,L $ xn,L xn,R an bn x1,…,xnR

  16. 3.1.j Implementing the “go to the beginning of the tape” operation Design a fragment of a TM that, from a state “Go to the beginning”, goes to the beginning of the tape and state “Done”. Move left and test if you are at the beginning of the tape. If yes, go to “Done”. If not, repeat the step. No Done Go to the beginning Beg? Yes

  17. 3.1.k Shifting tape contents Design a fragment of a TM that types 0 in the current cell and shifts the (old) contents of the remaining tape one cell to the right. Assume the tape alphabet is {0,1,-}. • Read the current symbol, remember it, type 0 and move right. • While the current symbol is not -, remember it, type the • previously remembered symbol and move right. • Once you see a blank, type • the remembered symbol • and you are done. Shift Done

  18. 3.1.l A TM for the element distinctness problem Design a TM that decides the language E={#x1#x2#…#xn | each xi{0,1} and xixj for each ij} See page 175 for a description of such a TM # x1 # x2 # x3 # x4 #x5 x1 x2 x3 x4 # 0 1 1 # 0 1 0 # 0 # 1 1 0 -

More Related