lecture9: turing machine

72
Lecture 9 2010 SDU Lecture9: Turing Machine

Upload: flavio

Post on 01-Feb-2016

65 views

Category:

Documents


2 download

DESCRIPTION

Lecture9: Turing Machine. 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). Turing Machine ( TM ). Bi-direction Read/Write. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Lecture9: Turing Machine

Lecture 9 2010 SDU

Lecture9: Turing Machine

Page 2: Lecture9: Turing Machine

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

Page 3: Lecture9: Turing Machine

2010 SDU 3

Turing Machine (TM)

. . .

Finite State

control

Bi-directionRead/Write

Page 4: Lecture9: Turing Machine

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.

Page 5: Lecture9: Turing Machine

2010 SDU 5

Turing Machines (cont.)

Each combination of a state and a scanned tape symbol determinesthe next state, the symbol written on the scanned square, and the move (L or R) of the tape head

a c b b c c

q2

tape

headfinite control

q pa b, L At state q, if the scanned symbol is a,

then go to state p, write b on the scannedsquare, and move the head to the left

Page 6: Lecture9: Turing Machine

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 q0

The Turing machine halts when it enters qaccept or qreject, and in these states it accepts or rejects, respectively

Page 7: Lecture9: Turing Machine

2010 SDU 7

Turing Machines (cont.)

A Turing machine is a 7-tuple(Q, , , , q0, qaccept, qreject), 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-{qaccept, qreject}) Q{L, R} is the transition function, //TM is a deterministic machine

5. q0 is the start state,

6. qaccept is the accept state, and

7. qreject is the reject state that is different from qaccept.

They are called halting states

Page 8: Lecture9: Turing Machine

2010 SDU 8

Configurations

a c b b c c

q2

tapehead

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 a1,…,am, …, the head is located on the kth square, and the state is q, then we write a1…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

Page 9: Lecture9: Turing Machine

2010 SDU 9

Configurations (cont.)

The action of a TM can be viewed as rewriting of the configurations.A configuration C1 yields C2 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| = 0The 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?

Page 10: Lecture9: Turing Machine

2010 SDU 10

The languages of Turing MachinesA 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.

Page 11: Lecture9: Turing Machine

2010 SDU 11

Example of TMA TM for recognizing (better deciding )L={w#w | w {0,1}*}

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

All unspecified transitionsgo 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)

Page 12: Lecture9: Turing Machine

2010 SDU 12

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

0 1 0 # 0 01

Page 13: Lecture9: Turing Machine

2010 SDU 13

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x 1 0 # 0 01

Page 14: Lecture9: Turing Machine

2010 SDU 14

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x 1 0 # 0 01

Page 15: Lecture9: Turing Machine

2010 SDU 15

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x 1 0 # 0 01

Page 16: Lecture9: Turing Machine

2010 SDU 16

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x 1 0 # 0 01

Page 17: Lecture9: Turing Machine

2010 SDU 17

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x 1 0 # x 01

Page 18: Lecture9: Turing Machine

2010 SDU 18

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x 1 0 # x 01

Page 19: Lecture9: Turing Machine

2010 SDU 19

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x 1 0 # x 01

Page 20: Lecture9: Turing Machine

2010 SDU 20

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x 1 0 # x 01

Page 21: Lecture9: Turing Machine

2010 SDU 21

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x 1 0 # x 01

Page 22: Lecture9: Turing Machine

2010 SDU 22

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x 0 # x 01

Page 23: Lecture9: Turing Machine

2010 SDU 23

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x 0 # x 01

Page 24: Lecture9: Turing Machine

2010 SDU 24

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x 0 # x 01

Page 25: Lecture9: Turing Machine

2010 SDU 25

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x 0 # x 01

Page 26: Lecture9: Turing Machine

2010 SDU 26

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x 0 # x 0x

Page 27: Lecture9: Turing Machine

2010 SDU 27

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x 0 # x 0x

Page 28: Lecture9: Turing Machine

2010 SDU 28

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x 0 # x 0x

Page 29: Lecture9: Turing Machine

2010 SDU 29

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x 0 # x 0x

Page 30: Lecture9: Turing Machine

2010 SDU 30

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x 0 # x 0x

Page 31: Lecture9: Turing Machine

2010 SDU 31

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x x # x 0x

Page 32: Lecture9: Turing Machine

2010 SDU 32

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x x # x 0x

Page 33: Lecture9: Turing Machine

2010 SDU 33

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x x # x 0x

Page 34: Lecture9: Turing Machine

2010 SDU 34

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x x # x 0x

Page 35: Lecture9: Turing Machine

2010 SDU 35

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x x # x xx

Page 36: Lecture9: Turing Machine

2010 SDU 36

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x x # x xx

Page 37: Lecture9: Turing Machine

2010 SDU 37

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x x # x xx

Page 38: Lecture9: Turing Machine

2010 SDU 38

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x x # x xx

Page 39: Lecture9: Turing Machine

2010 SDU 39

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x x # x xx

Page 40: Lecture9: Turing Machine

2010 SDU 40

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x x # x xx

Page 41: Lecture9: Turing Machine

2010 SDU 41

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x x # x xx

Page 42: Lecture9: Turing Machine

2010 SDU 42

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x x # x xx

Page 43: Lecture9: Turing Machine

2010 SDU 43

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x x # x xx

Page 44: Lecture9: Turing Machine

2010 SDU 44

How a TM works

q0

r1p1

p2

q2

q1

qA

q3

r2

#R

xR

R

1x,R0,1R

#R

xR

1x,L

0x,R

0,1R

#R

xR

0x,L

0,1,xL

#L

0,1LxR

x x x # x xx

Accept

Page 45: Lecture9: Turing Machine

2004 SDU 45

An implementary description

M=“on input string w1. 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.

Page 46: Lecture9: Turing Machine

2004 SDU 46

Example of TM for {0n1n2n | n > 0}

q0

q5q4

q3

q1

0x,R

xR

yR

yRzR

L

0RyRAll unspecified transitions

go to a reject state.

q2

1y,R

1RzR

2z, L

={0, 1}; ={0, 1, , x, y, z}

0L1LyLzL

Page 47: Lecture9: Turing Machine

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

Page 48: Lecture9: Turing Machine

Designing TM: Example 3

start q1

R

+ R = R q2

- L q9

R

+ LL = L x L - L

q3

# L

q4

xR+R

# R

x,R q5

= R

q7= R

x,R

q6 accept

xR

- R

R +R

xR

Design a TM that decides {#n +m = k | n+m=k}

q0# R

R

Page 49: Lecture9: Turing Machine

Testing whether the head is at the beginning of the tape

Tape alphabet: {x1,…,xn} 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?

x1 $,L

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

xn $,L

Page 50: Lecture9: Turing Machine

Testing whether the head is at the beginning of the tape

Tape alphabet: {x1,…,xn} 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?

x1 $,L

$ x1,L

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

$ xn,L

xn $,L

Page 51: Lecture9: Turing Machine

Testing whether the head is at the beginning of the tape

Tape alphabet: {x1,…,xn} 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?

x1 $,L

$ x1,L

a1

x1,…,xn R

Yes

x1,R

L No

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 x1,…,xn R bn

$ xn,L

xn $,L

xn,R

x3 x7

Beg?

Page 52: Lecture9: Turing Machine

Testing whether the head is at the beginning of the tape

Tape alphabet: {x1,…,xn} 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?

x1 $,L

$ x1,L

a1

x1,…,xn R

Yes

x1,R

L No

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 x1,…,xn R bn

$ xn,L

xn $,L

xn,R

$ x7

a3

Page 53: Lecture9: Turing Machine

Testing whether the head is at the beginning of the tape

Tape alphabet: {x1,…,xn} 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?

x1 $,L

$ x1,L

a1

x1,…,xn R

Yes

x1,R

L No

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 x1,…,xn R bn

$ xn,L

xn $,L

xn,R

x3 x7

Yes

Page 54: Lecture9: Turing Machine

Testing whether the head is at the beginning of the tape

Tape alphabet: {x1,…,xn} 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?

x1 $,L

$ x1,L

a1

x1,…,xn R

Yes

x1,R

L No

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 x1,…,xn R bn

$ xn,L

xn $,L

xn,R

x3 x7

Beg?

x9

Page 55: Lecture9: Turing Machine

Testing whether the head is at the beginning of the tape

Tape alphabet: {x1,…,xn} 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?

x1 $,L

$ x1,L

a1

x1,…,xn R

Yes

x1,R

L No

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 x1,…,xn R bn

$ xn,L

xn $,L

xn,R

$ x7

a3

x9

Page 56: Lecture9: Turing Machine

Testing whether the head is at the beginning of the tape

Tape alphabet: {x1,…,xn} 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?

x1 $,L

$ x1,L

a1

x1,…,xn R

Yes

x1,R

L No

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 x1,…,xn R bn

$ xn,L

xn $,L

xn,R

$ x7

b3

x9

Page 57: Lecture9: Turing Machine

Testing whether the head is at the beginning of the tape

Tape alphabet: {x1,…,xn} 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?

x1 $,L

$ x1,L

a1

x1,…,xn R

Yes

x1,R

L No

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 x1,…,xn R bn

$ xn,L

xn $,L

xn,R

x3 x7

Temp

x9

Page 58: Lecture9: Turing Machine

Testing whether the head is at the beginning of the tape

Tape alphabet: {x1,…,xn} 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?

x1 $,L

$ x1,L

a1

x1,…,xn R

Yes

x1,R

L No

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 x1,…,xn R bn

$ xn,L

xn $,L

xn,R

x3 x7

No

x9

Page 59: Lecture9: Turing Machine

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

Page 60: Lecture9: Turing Machine

Shifting tape contents

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

Page 61: Lecture9: Turing Machine

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,RShift

Page 62: Lecture9: Turing Machine

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,RShift

1. If the current symbol is blank, type 0 and you are done.

Page 63: Lecture9: Turing Machine

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.

00,RRemembered 0

Remembered 110,R

- 0,RShift

Page 64: Lecture9: Turing Machine

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

00,R

10,R

- 0,RShift

Page 65: Lecture9: Turing Machine

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

11,R

00,R

01,R 10,R

00,R

10,R

- 0,RShift

Page 66: Lecture9: Turing Machine

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

11,R

00,R

01,R 10,R

00,R

10,R

- 0,RShift

Page 67: Lecture9: Turing Machine

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

11,R

00,R

01,R 10,R

00,R

10,R

- 0,RShift Done

- 1,R

- 0,R

Page 68: Lecture9: Turing Machine

Shifting tape contents

1 0

1 1 -

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

11,R

00,R

01,R 10,R

00,R

10,R

- 0,RShift Done

- 1,R

- 0,R

Page 69: Lecture9: Turing Machine

Shifting tape contents

0 0

1 1 -

Done

Remembered 0

00,R

01,R 10,R

00,R

10,R

- 0,RShift Done

- 1,R

- 0,R

Remembered 1

11,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.

Page 70: Lecture9: Turing Machine

Shifting tape contents

0 1

1 1 -

Done

Remembered 0

Remembered 1

11,R

00,R

01,R 10,R

00,R

10,R

- 0,RShift Done

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

Page 71: Lecture9: Turing Machine

Shifting tape contents

0 1

1 0 -

Done

Remembered 0

Remembered 1

11,R

00,R

01,R 10,R

00,R

10,R

- 0,RShift Done

- 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,-}.

Page 72: Lecture9: Turing Machine

Shifting tape contents

0 1

1 0 1

Done

Remembered 0

Remembered 1

11,R

00,R

01,R 10,R

00,R

10,R

- 0,RShift Done

- 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,-}.