Download
lecture9 turing machine n.
Skip this Video
Loading SlideShow in 5 Seconds..
Lecture9: Turing Machine PowerPoint Presentation
Download Presentation
Lecture9: Turing Machine

Lecture9: Turing Machine

234 Vues Download Presentation
Télécharger la présentation

Lecture9: Turing Machine

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Lecture9: Turing Machine

  2. Historical Note • Proposed by Alan Turing in 1936 in: On Computable Numbers, with an application to the Entscheidungsproblem, Proc. Lond. Math. Soc. (2) 42 pp 230-265 (1936-7); correction ibid. 43, pp 544-546 (1937).

  3. Turing Machine (TM) . . . Bi-direction Read/Write Finite State control

  4. Turing Machines • A Turing Machine is a step-wise computing device, which consists of • An infinitely long tape that is divided into tape squares (or tape cells) • A head that scans (is positioned at) a particular tape square at each time step, and • A finite control that maintains the current state.

  5. Turing Machines (cont.) Each combination of a state and a scanned tape symbol determines the next state, the symbol written on the scanned square, and the move (L or R) of the tape head a c c c b b  tape head q2 finite control a  b, L At state q, if the scanned symbol is a, then go to state p, write b on the scanned square, and move the head to the left q p

  6. Computation of a Turing Machine (cont.) At the beginning: The tape contains the input on the leftmost squares, The rest of the tape is filled with blank symbols, The head is at the leftmost cell, and The state is q0 The Turing machine halts when it enters qaccept or qreject, and in these states it accepts or rejects, respectively .  2010 SDU 6

  7. Turing Machines (cont.) • A Turing machine is a 7-tuple(Q, , , , q0, qaccept, qreject), where Q, ,  are finite sets, • Q is a set of states, •  is the input alphabet, •  is the tape alphabet, where   -{} and  is the special blank symbol to indicate the untouched tape area • : (Q-{qaccept, qreject})Q{L, R} is the transition function, //TM is a deterministic machine • q0 is the start state, • qaccept is the accept state, and • qreject is the reject state that is different from qaccept. They are called halting states

  8. a c c c b b  tape head q2 finite control Configurations • A configuration of a Turing machine consists of the contents of its tape, the head position, and the state. If the tape contents are a1,…,am,…, the head is located on the kth square, and the state is q, then we writea1…ak-1qak…am to denote the configuration. The segment of blanks filling the tape is omitted but at least one symbol (possibly  ) is required after the state. • In the above, the configuration is acbbccq2

  9. Configurations (cont.) • The action of a TM can be viewed as rewriting of the configurations. • A configuration C1yieldsC2 if the Turing machine can go from C1 to C2 in a single step. • uaqibv yields uqjacv if (qi, b) = (qj, c, L) • qibv yields qjcv if (qi, b) = (qj, c, L) • uqibv yields ucqjv’ if (qi, b) = (qj, c, R), where v’ is v if |v| > 0 and  if |v| = 0 • The start configuration of M on w is q0w. • An accept configuration (A reject configuration) is one in which the state is qaccept (qreject). Accept configurations and reject configurations are halting configurations. • Note! A TM may never halt on an specified input! • How about DFA, NFA, PDA?

  10. The languages of Turing Machines • A Turing machine M accepts (rejects) a string w if it eventually enters an accept (a reject) state for input w, i.e.: there is a sequence of configurations C1, C2, …, Cm, such that: C1 is the start configuration of M on w; each Ci can yield Ci+1; Cm is an accept configuration. • The language recognized by a Turing machine M is defined as the collection of all the strings accepted by the Turing machine. • A Turing machine M decides a language L, if M recognizes L and halts on all inputs, and M is called a decider. We prefer deciders. • A language is Turing-recognizable if there is a Turing machine that recognizes it. • A language is Turing-decidable(or simply decidable) if there is a Turing machine that decides it.

  11. Example of TM A TM for recognizing (better deciding )L={w#w | w {0,1}*} #R All unspecified transitions go to a reject state. q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR a L (R) means a a , L(R) a, b L (R) means a L (R) and b  L (R) ={0, 1, #}; ={0, 1, #, , x}

  12. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR 1 0 0 1 0 # 0

  13. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR 1 0 x 1 0 # 0

  14. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR 1 0 x 1 0 # 0

  15. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR 1 0 x 1 0 # 0

  16. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR 1 0 x 1 0 # 0

  17. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR 1 0 x 1 0 # x

  18. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR 1 0 x 1 0 # x

  19. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR 1 0 x 1 0 # x

  20. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR 1 0 x 1 0 # x

  21. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR 1 0 x 1 0 # x

  22. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR 1 0 x x 0 # x

  23. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR 1 0 x x 0 # x

  24. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR 1 0 x x 0 # x

  25. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR 1 0 x x 0 # x

  26. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x 0 x x 0 # x

  27. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x 0 x x 0 # x

  28. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x 0 x x 0 # x

  29. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x 0 x x 0 # x

  30. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x 0 x x 0 # x

  31. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x 0 x x x # x

  32. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x 0 x x x # x

  33. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x 0 x x x # x

  34. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x 0 x x x # x

  35. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x x x x x # x

  36. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x x x x x # x

  37. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x x x x x # x

  38. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x x x x x # x

  39. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x x x x x # x

  40. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x x x x x # x

  41. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x x x x x # x

  42. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x x x x x # x

  43. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x x x x x # x

  44. How a TM works #R q0 0x,R 1x,R 0,1R xR 0,1R p1 r1 q3 #R R #R xR p2 xR r2 qA Accept 0x,L 1x,L 0,1,xL q1 #L q2 0,1L xR x x x x x # x

  45. An implementary description • M=“on input string w • Zig-zag across the tape to corresponding positions on either side of the # symbol to check on whether these positions contain the same symbol. If they do not, reject. Cross off symbols as they are checked to keep track of which symbols correspond. • When all symbols to the left of the # have been crossed off, check for any remaining symbols to the right of the #. If any symbols remain, reject; otherwise accept.” • Note: For most TMs, we prefer high-level descriptions to exact description of the 7 components because going to that level of detail can be cumbersome for most TMs but tiniest ones.

  46. Example of TM for {0n1n2n | n > 0} 0R yR 1R zR All unspecified transitions go to a reject state. 0L 1L yL zL 1y,R q1 q2 2z, L 0x,R q3 xR q0 yR zR yR q5 L q4 ={0, 1}; ={0, 1, , x, y, z}

  47. An implementary description • M = “On input string w: • Zig-zag across the tape to corresponding positions to check on whether these positions contain a 0, 1, and 2 respectively. If they do not, reject. Cross off symbols as they are checked to keep track of which symbols correspond. • When all the 0’s have been crossed off, check for any remaining 1’s or 2’s. If any such symbols remain, reject; otherwise accept.”

  48. 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

  49. Testing whether the head is at the beginning of the tape 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. 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”. a1 x1$,L … Beg? xn$,L an

  50. Testing whether the head is at the beginning of the tape 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. 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”. a1 $ x1,L x1$,L … Beg? Yes xn$,L $ xn,L an