Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 9  2010 SDU Lecture9: Turing Machine.  2010 SDU 2 Historical Note Proposed by Alan Turing in 1936 in: On Computable Numbers, with an application.

Similar presentations


Presentation on theme: "Lecture 9  2010 SDU Lecture9: Turing Machine.  2010 SDU 2 Historical Note Proposed by Alan Turing in 1936 in: On Computable Numbers, with an application."— Presentation transcript:

1 Lecture 9  2010 SDU Lecture9: Turing Machine

2  2010 SDU 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  2010 SDU 3 Turing Machine (TM)... Finite State control Bi-direction Read/Write

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

5  2010 SDU 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 ac bb cc  q2q2 tape head finite control qp 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

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

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

8  2010 SDU 8 Configurations ac bb cc  q2q2 tape head finite control A configuration of a Turing machine consists of the contents of its tape, the head position, and the state. If the tape contents are a 1,…,a m, …, the head is located on the kth square, and the state is q, then we write a 1 …a k-1 qa k …a m 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 acbbccq 2

9  2010 SDU 9 Configurations (cont.) The action of a TM can be viewed as rewriting of the configurations. A configuration C 1 yields C 2 if the Turing machine can go from C 1 to C 2 in a single step.  uaq i bv yields uq j acv if  (q i, b) = (q j, c, L)  q i bv yields q j cv if  (q i, b) = (q j, c, L)  uq i bv yields ucq j v’ if  (q i, b) = (q j, c, R), where v’ is v if |v| > 0 and  if |v| = 0 The start configuration of M on w is q 0 w. An accept configuration (A reject configuration) is one in which the state is q accept (q reject ). Accept configurations and reject configurations are halting configurations. Note! A TM may never halt on an specified input! How about DFA, NFA, PDA?

10  2010 SDU 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 C 1, C 2, …, C m, such that: C 1 is the start configuration of M on w; each C i can yield C i+1 ; C m 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  2010 SDU 11 Example of TM A TM for recognizing (better deciding )L={w#w | w  {0,1}*} q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR All unspecified transitions go to a reject state.  ={0, 1, #};  ={0, 1, #,, x} a  L (R) means a  a, L(R) a, b  L (R) means a  L (R) and b  L (R)

12  2010 SDU 12 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR 010#0 01

13  2010 SDU 13 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR x10#0 01

14  2010 SDU 14 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR x10#0 01

15  2010 SDU 15 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR x10#0 01

16  2010 SDU 16 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR x10#0 01

17  2010 SDU 17 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR x10#x 01

18  2010 SDU 18 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR x10#x 01

19  2010 SDU 19 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR x10#x 01

20  2010 SDU 20 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR x10#x 01

21  2010 SDU 21 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR x10#x 01

22  2010 SDU 22 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xx0#x 01

23  2010 SDU 23 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xx0#x 01

24  2010 SDU 24 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xx0#x 01

25  2010 SDU 25 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xx0#x 01

26  2010 SDU 26 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xx0#x 0x

27  2010 SDU 27 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xx0#x 0x

28  2010 SDU 28 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xx0#x 0x

29  2010 SDU 29 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xx0#x 0x

30  2010 SDU 30 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xx0#x 0x

31  2010 SDU 31 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xxx#x 0x

32  2010 SDU 32 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xxx#x 0x

33  2010 SDU 33 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xxx#x 0x

34  2010 SDU 34 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xxx#x 0x

35  2010 SDU 35 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xxx#x xx

36  2010 SDU 36 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xxx#x xx

37  2010 SDU 37 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xxx#x xx

38  2010 SDU 38 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xxx#x xx

39  2010 SDU 39 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xxx#x xx

40  2010 SDU 40 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xxx#x xx

41  2010 SDU 41 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xxx#x xx

42  2010 SDU 42 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xxx#x xx

43  2010 SDU 43 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xxx#x xx

44  2010 SDU 44 How a TM works q0q0 r1r1 p1p1 p2p2 q2q2 q1q1 qAqA q3q3 r2r2 #R#R xRxR RR 1  x,R 0,1  R #R#R xRxR 1  x,L 0  x,R 0,1  R #R#R xRxR 0  x,L 0,1,x  L #L#L 0,1  L xRxR xxx#x xx Accept

45  2004 SDU 45 An implementary description M=“on input string w 1.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. 2.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  2004 SDU 46 Example of TM for {0 n 1 n 2 n | n > 0} q0q0 q5q5 q4q4 q3q3 q1q1 0x,R0x,R xRxR yRyR yRzRyRzR LL 0RyR0RyR All unspecified transitions go to a reject state. q2q2 1  y,R 1RzR1RzR 2  z, L  ={0, 1};  ={0, 1,, x, y, z} 0L1LyLzL0L1LyLzL

47  2004 SDU 47 An implementary description M = “On input string w: 1.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. 2.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 start q1 RR +  R =  R q2 -  L q9 RR +  L   L =  L x  L -  L q3 #  L q4 xR+RxR+R #  R   x,R q5 =  R q7 =  R   x,R q6 accept xRxR -  R   R +  R xR xR Design a TM that decides {#  n +  m =  k | n+m=k} q0 #  R RR

49 Testing whether the head is at the beginning of the tape Tape alphabet: {x 1,…,x n }Add a new tape symbol: $ 1.Read the current symbol, remember it, type $, and move left; 2.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”. Beg? x 1  $,L a1 a1 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. an an x n  $,L …

50 Testing whether the head is at the beginning of the tape Tape alphabet: {x 1,…,x n }Add a new tape symbol: $ 1.Read the current symbol, remember it, type $, and move left; 2.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”. Beg? x 1  $,L $  x 1,L a1 a1 Yes 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. an an $  x n,L x n  $,L …

51 Testing whether the head is at the beginning of the tape Tape alphabet: {x 1,…,x n }Add a new tape symbol: $ 1.Read the current symbol, remember it, type $, and move left; 2.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”. Beg? x 1  $,L $  x 1,L a1 a1 x 1,…,x n  R Yes  x 1,R LL No b1 b1 Temp 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. an an x 1,…,x n  R bn bn $  x n,L x n  $,L  x n,R … x3x3 x7x7 Beg?

52 Testing whether the head is at the beginning of the tape Tape alphabet: {x 1,…,x n }Add a new tape symbol: $ 1.Read the current symbol, remember it, type $, and move left; 2.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”. Beg? x 1  $,L $  x 1,L a1 a1 x 1,…,x n  R Yes  x 1,R LL No b1 b1 Temp 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. an an x 1,…,x n  R bn bn $  x n,L x n  $,L  x n,R … $x7x7 a3a3

53 Testing whether the head is at the beginning of the tape Tape alphabet: {x 1,…,x n }Add a new tape symbol: $ 1.Read the current symbol, remember it, type $, and move left; 2.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”. Beg? x 1  $,L $  x 1,L a1 a1 x 1,…,x n  R Yes  x 1,R LL No b1 b1 Temp 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. an an x 1,…,x n  R bn bn $  x n,L x n  $,L  x n,R … x3x3 x7x7 Yes

54 Testing whether the head is at the beginning of the tape Tape alphabet: {x 1,…,x n }Add a new tape symbol: $ 1.Read the current symbol, remember it, type $, and move left; 2.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”. Beg? x 1  $,L $  x 1,L a1 a1 x 1,…,x n  R Yes  x 1,R LL No b1 b1 Temp 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. an an x 1,…,x n  R bn bn $  x n,L x n  $,L  x n,R … x3x3 x7x7 Beg? x9x9

55 Testing whether the head is at the beginning of the tape Tape alphabet: {x 1,…,x n }Add a new tape symbol: $ 1.Read the current symbol, remember it, type $, and move left; 2.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”. Beg? x 1  $,L $  x 1,L a1 a1 x 1,…,x n  R Yes  x 1,R LL No b1 b1 Temp 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. an an x 1,…,x n  R bn bn $  x n,L x n  $,L  x n,R … $x7x7 a3a3 x9x9

56 Testing whether the head is at the beginning of the tape Tape alphabet: {x 1,…,x n }Add a new tape symbol: $ 1.Read the current symbol, remember it, type $, and move left; 2.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”. Beg? x 1  $,L $  x 1,L a1 a1 x 1,…,x n  R Yes  x 1,R LL No b1 b1 Temp 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. an an x 1,…,x n  R bn bn $  x n,L x n  $,L  x n,R … $x7x7 b3b3 x9x9

57 Testing whether the head is at the beginning of the tape Tape alphabet: {x 1,…,x n }Add a new tape symbol: $ 1.Read the current symbol, remember it, type $, and move left; 2.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”. Beg? x 1  $,L $  x 1,L a1 a1 x 1,…,x n  R Yes  x 1,R LL No b1 b1 Temp 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. an an x 1,…,x n  R bn bn $  x n,L x n  $,L  x n,R … x3x3 x7x7 Temp x9x9

58 Testing whether the head is at the beginning of the tape Tape alphabet: {x 1,…,x n }Add a new tape symbol: $ 1.Read the current symbol, remember it, type $, and move left; 2.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”. Beg? x 1  $,L $  x 1,L a1 a1 x 1,…,x n  R Yes  x 1,R LL No b1 b1 Temp 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. an an x 1,…,x n  R bn bn $  x n,L x n  $,L  x n,R … x3x3 x7x7 No x9x9

59 Shifting tape contents Done Design a fragment of a TM that, beginning from the current cell, shifts the contents of the tape right, typing in the current cell a 0. Assume the tape alphabet is {0,1,-}. Shift

60 Shifting tape contents ShiftDone Design a fragment of a TM that, beginning from the current cell, shifts the contents of the tape right, typing in the current cell a 0. Assume the tape alphabet is {0,1,-}. 1.If the current symbol is blank, type 0 and you are done.

61 Shifting tape contents Done Design a fragment of a TM that, beginning from the current cell, shifts the contents of the tape right, typing in the current cell a 0. Assume the tape alphabet is {0,1,-}. 1.If the current symbol is blank, type 0 and you are done. -  0,R Shift

62 Shifting tape contents Done Design a fragment of a TM that, beginning from the current cell, shifts the contents of the tape right, typing in the current cell a 0. Assume the tape alphabet is {0,1,-}. 1.Read the current symbol, remember it, type 0 and move right. -  0,R Shift 1.If the current symbol is blank, type 0 and you are done.

63 Shifting tape contents Done Design a fragment of a TM that, beginning from the current cell, shifts the contents of the tape right, typing in the current cell a 0. Assume the tape alphabet is {0,1,-}. 1.If the current symbol is blank, type 0 and you are done. 2.Read the current symbol, remember it, type 0 and move right. 0  0,R Remembered 0 Remembered 1 1  0,R -  0,R Shift

64 Shifting tape contents Done Design a fragment of a TM that, beginning from the current cell, shifts the contents of the tape right, typing in the current cell a 0. Assume the tape alphabet is {0,1,-}. 1.If the current symbol is blank, type 0 and you are done. 2.Read the current symbol, remember it, type 0 and move right. 3.While the current symbol is not -, remember it, type the previously remembered symbol and move right. Remembered 0 Remembered 1 0  0,R 1  0,R -  0,R Shift

65 Shifting tape contents Done Design a fragment of a TM that, beginning from the current cell, shifts the contents of the tape right, typing in the current cell a 0. Assume the tape alphabet is {0,1,-}. 1.If the current symbol is blank, type 0 and you are done. 2.Read the current symbol, remember it, type 0 and move right. 3.While the current symbol is not -, remember it, type the previously remembered symbol and move right. Remembered 0 Remembered 1 1  1,R 0  0,R 0  1,R1  0,R 0  0,R 1  0,R -  0,R Shift

66 Shifting tape contents Done Design a fragment of a TM that, beginning from the current cell, shifts the contents of the tape right, typing in the current cell a 0. Assume the tape alphabet is {0,1,-}. 1.If the current symbol is blank, type 0 and you are done. 2.Read the current symbol, remember it, type 0 and move right. 3.While the current symbol is not -, remember it, type the the previously remembered symbol and move right. Once you see a blank, type the remembered symbol and you are done. Remembered 0 Remembered 1 1  1,R 0  0,R 0  1,R1  0,R 0  0,R 1  0,R -  0,R Shift

67 Shifting tape contents Done Design a fragment of a TM that, beginning from the current cell, shifts the contents of the tape right, typing in the current cell a 0. Assume the tape alphabet is {0,1,-}. 1.If the current symbol is blank, type 0 and you are done. 2.Read the current symbol, remember it, type 0 and move right. 3.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. Remembered 0 Remembered 1 1  1,R 0  0,R 0  1,R1  0,R 0  0,R 1  0,R -  0,R ShiftDone -  1,R -  0,R

68 Shifting tape contents 10 11- Design a fragment of a TM that, beginning from the current cell, shifts the contents of the tape right, typing in the current cell a 0. Assume the tape alphabet is {0,1,-}. 1.If the current symbol is blank, type 0 and you are done. 2.Read the current symbol, remember it, type 0 and move right. 3.While the current symbol is not -, remember it, type the the previously remembered symbol and move right. Once you see a blank, type the remembered symbol and you are done. Done Remembered 0 Remembered 1 1  1,R 0  0,R 0  1,R1  0,R 0  0,R 1  0,R -  0,R ShiftDone -  1,R -  0,R

69 Shifting tape contents 00 11- Done Remembered 0 0  0,R 0  1,R1  0,R 0  0,R 1  0,R -  0,R ShiftDone -  1,R -  0,R Remembered 1 1  1,R Design a fragment of a TM that, beginning from the current cell, shifts the contents of the tape right, typing in the current cell a 0. Assume the tape alphabet is {0,1,-}. 1.If the current symbol is blank, type 0 and you are done. 2.Read the current symbol, remember it, type 0 and move right. 3.While the current symbol is not -, remember it, type the the previously remembered symbol and move right. Once you see a blank, type the remembered symbol and you are done.

70 Shifting tape contents 01 11- Done Remembered 0 Remembered 1 1  1,R 0  0,R 0  1,R1  0,R 0  0,R 1  0,R -  0,R ShiftDone -  1,R -  0,R Design a fragment of a TM that, beginning from the current cell, shifts the contents of the tape right, typing in the current cell a 0. Assume the tape alphabet is {0,1,-}. 1.If the current symbol is blank, type 0 and you are done. 2.Read the current symbol, remember it, type 0 and move right. 3.While the current symbol is not -, remember it, type the the previously remembered symbol and move right. Once you see a blank, type the remembered symbol and you are done.

71 Shifting tape contents 01 10- Done Remembered 0 Remembered 1 1  1,R 0  0,R 0  1,R1  0,R 0  0,R 1  0,R -  0,R ShiftDone -  1,R -  0,R 1.If the current symbol is blank, type 0 and you are done. 2.Read the current symbol, remember it, type 0 and move right. 3.While the current symbol is not -, remember it, type the the previously remembered symbol and move right. Once you see a blank, type the remembered symbol and you are done. Design a fragment of a TM that, beginning from the current cell, shifts the contents of the tape right, typing in the current cell a 0. Assume the tape alphabet is {0,1,-}.

72 Shifting tape contents 01 101 Done Remembered 0 Remembered 1 1  1,R 0  0,R 0  1,R1  0,R 0  0,R 1  0,R -  0,R ShiftDone -  1,R -  0,R 1.If the current symbol is blank, type 0 and you are done. 2.Read the current symbol, remember it, type 0 and move right. 3.While the current symbol is not -, remember it, type the the previously remembered symbol and move right. Once you see a blank, type the remembered symbol and you are done. Design a fragment of a TM that, beginning from the current cell, shifts the contents of the tape right, typing in the current cell a 0. Assume the tape alphabet is {0,1,-}.


Download ppt "Lecture 9  2010 SDU Lecture9: Turing Machine.  2010 SDU 2 Historical Note Proposed by Alan Turing in 1936 in: On Computable Numbers, with an application."

Similar presentations


Ads by Google