turing machines

18
Turing Machines Turing Machines Section 3.1 CSC 4170 heory of Computatio

Upload: candice-austin

Post on 01-Jan-2016

42 views

Category:

Documents


2 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Turing Machines

Turing MachinesTuring Machines

Section 3.1

CSC 4170

Theory of Computation

Page 2: Turing Machines

Components of a Turing machine (TM) 3.1.a

(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 rejectaccept; the states accept and reject are called halting states.There are no transitions from the halting states, and they immediately take effect!

xy,Rq1 q2

If the current tape symbol is x, replace it with y, move the head right and go to q2. The label xx,R is simply written as xR. 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.

a a b a b b - - - - - -

Page 3: Turing Machines

How a Turing machine works 3.1.b

0x,Rq2 q3start

accept q4

q5

reject

0 -,R

- Rx R

- R0R 0 x,R

- R - L

0 Lx L

xR

xR

xR

- R

- x 0 0 - - - - - - -

Configuration:1. Current state;2. Tape contents;3. Head position

Page 4: Turing Machines

Definitions 3.1.c1

A TM accepts an input string iff, for this input, sooner or later it entersthe accept state. Otherwise the string is considered rejected.

Thus, the input is rejected in two cases:1) The machine enters the reject state at some point, or 2) 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.

Page 5: Turing Machines

Recognizing vs deciding 3.1.c2

accept

reject

0 R - R

- R0 R - R

0 R

What language does the above machine recognize?Does it decide that language?

accept

reject

0 R - R

- R0 R

What language does the above machine recognize?Does it decide that language?

Page 6: Turing Machines

Diagrams without the reject state 3.1.d

0x,Rq2 q3start

acceptq4

q5

0 -,R- R

0R 0 x,R

- R - L

0 Lx L

xR

xR

xR

The reject state can be safely removed.It will be understood that all the missing transitions lead to the reject state.

Page 7: Turing Machines

Designing TM: Example 1 3.1.e1

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 tapeand go to step 2 (state q3).

start q1

R

# R = R q2

- L q9

RL = L x L - L

q3

# L

Page 8: Turing Machines

Designing TM: Example 1 3.1.e2

2. Keep going to the right, replace the first you see before = with x and go to step 3 (state q5); if you reach = without seeing a , go to step 4 (state q6).

q3 q4

xR

# R

x,R q5

q6

= R

Page 9: Turing Machines

Designing TM: Example 1 3.1.e3

3. Keep going to the right, pass = and then replace the first you see with x and go 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.

q5 q7

R

= R

x,R

q9

xR

Page 10: Turing Machines

Designing TM: Example 1 3.1.e4

4. Keep going to the right as long as you see x. If you see a beforereaching a blank, reject; otherwise accept.

q6 accept

xR

- R

Page 11: Turing Machines

Designing TM: Example 1 3.1.e5

start q1

R

# R = R q2

- L q9

RL = L x L - L

q3

# L

q4

xR

# R

x,R q5

= R

q7= R

x,R

q6 accept

xR

- R

# = - - -

R

xR

Page 12: Turing Machines

Designing TM: Example 2 3.1.f

start q1

R

# R < R q2

- L q9

RL < L x L

q3

# L

q4

xR

# R

x,R q5

< R

q7< R

x,R

q6 accept

xR

R

Design a TM that decides {#n <m | n<m}

R

xR

L < L x L - L

Page 13: Turing Machines

Designing TM: Example 3 3.1.g

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 14: Turing Machines

Designing TM: Example 4 3.1.h

Design a TM that decides {#n m = k | nm=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 onthe 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.

Page 15: Turing Machines

Testing whether the head is at the beginning of the tape 3.1.i

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

Page 16: Turing Machines

Implementing the “go to the beginning of the tape” operation

3.1.j

Go to the beginning Beg?

No

Yes

Done

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.

Page 17: Turing Machines

Shifting tape contents3.1.k

Shift Done

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

1. Read the current symbol, remember it, type 0 and move right.2. While the current symbol is not -, remember it, type the previously remembered symbol and move right.3. Once you see a blank, type the remembered symbol and you are done.

Page 18: Turing Machines

A TM for the element distinctness problem3.1.l

0 1# 1 # 0 1 0 # 10 # 1 0 -

x1 x2 x3 x4

See page 135 for a description of such a TM

Design a TM that decides the languageE={#x1#x2#…#xn | each xi{0,1} and xixj for each ij}

# x1 # x2 # x3 # x4 # x5