Turing Machines

advertisement
Turing Machines
Hopcroft, Motawi, Ullman,
Chap 8
Models of computation

Finite automata and regular expressions



Grammars and pushdown automata



Represent regular languages
Can’t “count”
Represent context free languages
Can count and remember symbols once
Turing machines


Represent recursive languages
Models contemporary programs
Turing Machine Model


Input tape surrounded by infinitely
many blanks
Tape head can move back and forth the
tape and replace current symbol
… BBBBBBB000111BBBBB …
TM
TM definition

A Turing Machine M is a tuple
M = (Q, , , , q0, B, F), where:







Q is a set of states
 is the input alphabet
 is the tape alphabet =   {B}  other tape symbols
: Q    Q    D is the state transition function
mapping (state, symbol) to (state, symbol, direction);
D = {,};  may be undefined for some pairs
q0 is the start state of M
B is the blank symbol (default symbol on input tape)
F  Q is the set of accepting states or final states of M
(if applicable)
TM that accepts 0n1n


Q={q0,q1 ,q2,q3,q4}, ={0,1}, ={0,1,B,Y}
 defined as follows:





(q0,0) = (q1,B,)
(q1,0) = (q1,0,)
(q1,Y) = (q1,Y,)
(q1,1) = (q2,Y,)
(q2,Y) = (q2,Y,)
(q2,0) = (q2,0,)
(q2,B) = (q0,B,)
(q0,Y) = (q3,Y,)
(q3,Y) = (q3,Y,)
(q3,B) = (q4,B,)
erase leftmost 0
move to right until a 1
is encountered, replace
that 1 with Y
move to left until a blank
is encountered, then go
back to initial state
if Y on tape go to state 3
ensure only Y’s remain on tape
accept once B is seen (F={q4})
TM that increments a bit-string


Q={q0,q1 ,q2,q3}, ={0,1}, ={0,1,B,X}
 defined as follows:



(q0,0) = (q0,0,) go to rightmost
(q0,1) = (q0,1,) non-blank
(q0,B) = (q1,B,)
(q1,1) = (q1,0,) replace 1’s with 0’s
(q1,0) = (q2,1,) until 0/B is encountered,
(q1,B) = (q2,1,) replace that 0/B with a 1
No applicable transitions from q2 means the turing
machine halts
Instantaneous descriptions

Instantaneous description (ID): depicts the
characteristics of the machine as transitions are
carried out


For TM’s, the following are needed for an ID:




For finite automata, the state of the machine and the
remaining input is sufficient
State
Symbols on the tape
Position of the tape head
Can be expressed as X1X2…Xi-1qXiXi+1…Xn
which means the TM is in state q, the tape contains
X1X2…Xn and the tape head is at Xi
ID example

Suppose for the first TM example,
the input is 0011


After applying the transition
(q0,0) = (q1,B,), ID: q1011



The initial ID is q00011
Depict this as a move: q00011 | q1011
Next 3 transitions:
(q1,0) = (q1,0,), ID: 0q111
(q1,1) = (q2,Y,), ID: q20Y1
(q2,0) = (q2,0,), ID: q2B0Y1
Eventually, ID will be YYBq4 (TM accepts)
TM as recognizer

A TM accepts a string w if there exists a
sequence of moves from
ID q0w to ID uqfv (u,v  *, qf  F)




q0w |* uqfv
In the previous example, q00011 |* YYBq4
Given a TM M, L(M) is the set of all strings
that M accepts
A language recognized by a TM is called a
recursively enumerable language
TM halting on input



TMs are also useful for computation
In this case, what is important is the machine
halts on input w (and leaves the appropriate
output on the tape)
A TM halts on input w if there exists a
sequence of moves from
ID q0w to ID uqixv (u,v*, x, qiQ)
& (qi,x) is undefined (no transition applies)

The TM can be viewed as a function; f(w) = uxv
About TMs



Church-Turing Thesis: TMs represent what
can be solved by a computer program
(a mathematically unprovable statement)
Some problems cannot be solved by a TM
(e.g., the Halting Problem)
TMs can be deterministic or nondeterministic;
the variation helps in modeling problem
complexity classes (P and NP)
Download