Top Banner
CS 3240: Languages and Computation Turing Machine
21

CS 3240: Languages and Computation

Feb 01, 2016

Download

Documents

Santa

Turing Machine. CS 3240: Languages and Computation. Turing and Turing Machine. Alan Turing (1912–1954), British mathematician/engineer. In 1936, Turing introduced his abstract model for computation in his article “ On Computable Numbers, with an application to the Entscheidungsproblem ” - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS 3240: Languages and Computation

CS 3240: Languages and Computation

Turing Machine

Page 2: CS 3240: Languages and Computation

Turing and Turing Machine Alan Turing (1912–1954), British

mathematician/engineer. In 1936, Turing introduced his

abstract model for computation in his article “On Computable Numbers, with an application to the Entscheidungsproblem”

Near the same time, Alonzo Church published similar ideas and results.

Turing machine is the ultimate model of computation.

Page 3: CS 3240: Languages and Computation

Comparison of TM and FA

TM has tape you can read from and write to Read-write head can be moved in either

direction Tape is infinite Accept and reject states take effect immediately

Page 4: CS 3240: Languages and Computation

Example I

Language{ w#w | w {0,1}* }

How can we design a Turing machine to test its membership? Zig-zag across tape to corresponding positions on

either side of # to check whether they contain same symbol. If not or if no # found, reject.

Cross off symbols as they are checked When all symbols to the left of # are crossed off, if

anything remain to the right o #, reject; otherwise, accept.

Example: test on string 011001$011001

Page 5: CS 3240: Languages and Computation

Formal definition of TM

Definition: A Turing machine is a 7-tuple (Q,,,,q0,qaccept,qreject), where Q, , and are finite sets and

Q is the set of states, is the input alphabet not containing the

special blank symbol ~ is tape alphabet, where {~}, : QQ{L,R} is the transition

function,

Page 6: CS 3240: Languages and Computation

Formal definition of a TM

Definition: A Turing machine is a 7-tuple (Q,,,,q0,qaccept,qreject), where Q, , and are finite sets and

• q0Q is the start state,

• qacceptQ is the accept state, and

• qrejectQ is the reject state, where qrejectqaccept

Page 7: CS 3240: Languages and Computation

More on Transition Function

Q = set of states, = tape alphabet

: QQ{L,R}

Given: The current internal state Q The symbol on the current tape cell

Then tells us what the TM does: Changes to new internal state Q Either writes new symbol Or moves one cell left or right

Page 8: CS 3240: Languages and Computation

Computing with TM

M receives input w = w1w2…wn* on leftmost n squares of tape Rest of tape is blank (all ~ symbols)

Head position begins at leftmost square of tape Computation follows rules of Head never moves left of leftmost square of the

tape If says to move L, head stays put!

Page 9: CS 3240: Languages and Computation

Completing computation

Continue following transition rules until M reaches qaccept or qreject

Halt at these states

May never halt if machine never reaches one of these states!

Page 10: CS 3240: Languages and Computation

Turing machine notation

(qi,b)=(qk,c,D), where D = L or R, is represented by the following transition

qi qk

b c, D

In the special case where (qi,b)=(qk,b,D), i.e., the tape is unchanged, the right-hand side will just display the direction

Page 11: CS 3240: Languages and Computation

Revisiting Example I (q1, 0) = (q2, x, R);

(q2, 0) = (q2, 0, R); (q2, 1) = (q2, 1, R); (q2, #) = (q4, #, R)

(q4, x)=(q4, x, R); (q4, 0)=(q6, x, L)

(q1, 1) = (q3, x, R)

(q3, 0) = (q3, 0, R); (q3, 1) = (q3, 1, R); (q3, #) = (q5, #, R)

(q5, x)=(q5, x, R); (q5, 1)=(q6, x, L)

(q6, a)=(q6, a, L) for a=0, 1, or x

(q6, #)= (q7, #, L); (q7, 0)= (q7, 0, L); (q7, 1)= (q7, 1, L); (q7, x)= (q1, x, R)

(q1, #) = (q8, #, R); (q8, x) = (q8, x, R); (q8, ~) = (qaccept, ~, R)

Page 12: CS 3240: Languages and Computation

TM state diagram

Page 13: CS 3240: Languages and Computation

Example

E={#x1#x2#x3…#xn | xi {0,1}* and xi≠xj for i ≠ j}

Basic idea: Compare each pair of (xi , xj) by zig-zagging. Use special marks to replace # to indicate which pair of (xi , xj) is being compared

Must take care special cases such as n=0, n=1, missing #, etc.

Page 14: CS 3240: Languages and Computation

Question

How to detect whether we have reached left-most cell?

Alternative 1: If leftmost cell marked by special symbol, then easy

Alternative 2: Use special property that TM “stays put” at left-most cell by replacing cell with special symbol and then recover

Page 15: CS 3240: Languages and Computation

TM configurations

The configuration of a Turing machine is the current setting Current state Current tape contents Current tape location

Notation uqv Current state = q Current tape contents = uv

Only ~ symbols after last symbol of v

Current tape location = first symbol of v

Page 16: CS 3240: Languages and Computation

Configuration C1 yields C2

C1 yields C2 if the TM can legally go from C1 to C2 in one step Assume a, b and u, v *

uaqibv yields uqkacv if (qi,b)=(qk,c,L)

uaqibv yields uacqkv if (qi,b)=(qk,c,R)

Page 17: CS 3240: Languages and Computation

Configuration C1 yields C2

Special cases if head is at beginning or end of tape uaqibv yields uqjacv if (qi,b)=(qk,c,L)

uaqibv yields uacqkv if (qi,b)=(qk,c,R)

Special case: qibv~ yields qkcv~ if (qi,b)=(qk,c,L) and tape head is at

beginning of tape

Page 18: CS 3240: Languages and Computation

Special configurations

Start configuration q0w

Halting configurations Accepting configuration: uqacceptv

Rejecting configuration: uqrejectv u, v *

Page 19: CS 3240: Languages and Computation

Strings accepted by a TM

A Turing machine M accepts input sequence w if a sequence of configurations C1, C2, …, Ck exist, where

– C1 is the start configuration of M on input w

– each Ci yields Ci+1 for i = 1, 2, …, k-1

– Ck is an accepting configuration

Page 20: CS 3240: Languages and Computation

Language of a TM

The language of M, denoted L(M), is L(M) = {w | M accepts w}

A language is called Turing-recognizable if some Turing machine recognizes it

Page 21: CS 3240: Languages and Computation

Deciders

A Turing machine is called a decider if every string in * is either accepted or rejected

A language is called Turing-decidable if some Turing machine decides it These languages are often just called decidable