state

advertisement
Turing Machines
1
Turing-Machine Theory
The purpose of the theory of Turing
machines is to prove that certain
specific languages have no algorithm.
Reductions are used to prove more
common questions are undecidable.
2
Turing Machines
 Regular and CF languages are both recognized by a
particular type of machine.
 Regular: Finite Automata (Deterministic, Nondeterministic).
 Context Free: Pushdown Automata.
 Both types of machine are limited.
 Regular: No memory.
 Context Free: A restricted type of memory (first-in, last-out).
 Neither model is acceptable as a general model of
computation
 Clearly some machine should be able to recognize strings in
{w#w|w ∈ {0, 1}* } (which is not a CFL).
 Turing Machines (TMs) are.
 They are the canonical model for computation. To be
computable means to be computable by a Turing Machine
3
Picture of a Turing Machine
Action: based on
the state and the
tape symbol under
the head: change
state, rewrite the
symbol and move the
head one square.
State
...
A
B
C
A
D
...
Infinite tape with
squares containing
tape symbols chosen
from a finite alphabet
4
Why Turing Machines?
Why not deal with C programs or
something like that?
Answer: You can, but it is easier to prove
things about TM’s, because they are so
simple.
 And yet they are as powerful as any
computer.
• More so, in fact, since they have infinite memory.
5
Finite automata to Turing
Machines
A Turing machine can both write on the
tape and read from it
The read write head can move both to
left and right
The tape is infinite
Once accept/reject states are reached,
the computation terminates at once
6
Turing-Machine Formalism
 A TM is described by:
1.
2.
3.
4.
A finite set of states (Q, typically).
An input alphabet (Σ, typically).
A tape alphabet (Γ, typically; contains Σ).
A transition function (δ, typically).
5. A start state (q0, in Q, typically).
6. A blank symbol (B, in Γ- Σ, typically).
 All tape except for the input is blank initially.
7. A set of final states (F ⊆ Q, typically).
7
The Transition Function
 Takes two arguments:
1. A state, in Q.
2. A tape symbol in Γ.
 δ(q, Z) is either undefined or a triple of
the form (p, Y, D).
 p is a state.
 Y is the new tape symbol.
 D is a direction, L or R.
8
Actions of the TM
 If δ(q, Z) = (p, Y, D) then, in state q,
scanning Z under its tape head, the
TM:
1. Changes the state to p.
2. Replaces Z by Y on the tape.
3. Moves the head one square in direction D.
 D = L: move left; D = R; move right.
9
Example: Turing Machine
This TM scans its input right, looking
for a 1.
If it finds one, it changes it to a 0, goes
to final state f, and halts.
If it reaches a blank, it changes it to a
1 and moves left.
10
Example: Turing Machine – (2)
States = {q (start), f (final)}.
Input symbols = {0, 1}.
Tape symbols = {0, 1, B}.
δ(q, 0) = (q, 0, R).
δ(q, 1) = (f, 0, R).
δ(q, B) = (q, 1, L).
11
Simulation of TM
δ(q, 0) = (q, 0, R)
δ(q, 1) = (f, 0, R)
δ(q, B) = (q, 1, L)
q
... B B 0 0 B B ...
12
Simulation of TM
δ(q, 0) = (q, 0, R)
δ(q, 1) = (f, 0, R)
δ(q, B) = (q, 1, L)
q
... B B 0 0 B B ...
13
Simulation of TM
δ(q, 0) = (q, 0, R)
δ(q, 1) = (f, 0, R)
δ(q, B) = (q, 1, L)
q
... B B 0 0 B B ...
14
Simulation of TM
δ(q, 0) = (q, 0, R)
δ(q, 1) = (f, 0, R)
δ(q, B) = (q, 1, L)
q
... B B 0 0 1 B ...
15
Simulation of TM
δ(q, 0) = (q, 0, R)
δ(q, 1) = (f, 0, R)
δ(q, B) = (q, 1, L)
q
... B B 0 0 1 B ...
16
Simulation of TM
δ(q, 0) = (q, 0, R)
δ(q, 1) = (f, 0, R)
δ(q, B) = (q, 1, L)
f
... B B 0 0 0 B ...
No move is possible.
The TM halts and
accepts.
17
Example 2
B = {w#w | w Є {0,1}*
 Repeatedly do: Mark the first “unmarked”
symbol from the beginning and zig-zag across
the tape to its corresponding position on the
other side of the # to check if they are same
(need to remember what you see). If so mark,
otherwise reject
 Stop when there are no unmarked symbols
remaining to the left of #. If there are still
symbols left on the right, reject. Else accept.
18
19
δ
0
1
#
B
x
q0 (start)
(q1,x,R)
(q2,x,R)
(q3,#,R)
q_rej
(q0,x,R)
q1 (see 0)
(q1,0,R)
(q1,1,R)
(q4,#,R)
q_rej
(q1,x,R)
q2 (see 1)
(q2,0,R)
(q2,1,R)
(q5,#,R)
q_rej
(q2,x,R)
q3 (left input q_rej
finished)
q_rej
q_rej
q_acc
(q3,x,R)
q4 (match 0) (q6,x,L)
q_rej
q_rej
q_rej
(q4,x,R)
q5 (match 1) q_rej
(q6,x,L)
q_rej
q_rej
(q5,x,R)
q6 (go back)
(q6,1,L)
(q6,#,L)
(q0,B,R)
(q6,x,L)
(q6,0,L)
20
Instantaneous Descriptions of
a Turing Machine
Initially, a TM has a tape consisting of a
string of input symbols surrounded by
an infinity of blanks in both directions.
The TM is in the start state, and the
head is at the leftmost input symbol.
21
TM ID’s – (2)
An ID is a string q, where  is the
tape between the leftmost and
rightmost nonblanks (inclusive).
The current state q is immediately to
the left of the head (tape symbol
scanned).
If q is at the right end, it is scanning B.
22
TM ID’s – (3)
As for PDA’s we may use symbols ⊦ and
⊦* to represent “becomes in one move”
and “becomes in zero or more moves,”
respectively, on ID’s.
Example: The moves of the previous TM
are q00⊦0q0⊦00q⊦0q01⊦00q1⊦000f
23
ID’s for w#w
Initial tape: …BB01#01BB…
q001#01 ⊦ xq11#01 ⊦* x1#q401
⊦x1#q6x1 ⊦* q0x1#x1 ⊦* xxq2#x1
⊦* xx#q5x1 ⊦x1#xq6x ⊦* q0xx#xx
⊦* xx#q3xx ⊦* xx#xxqacc
24
Languages of a TM
A Turing Machine M defines a language
by final state, as usual.
L(M) = {w | q0w⊦*I, where I is an ID
with a final state}.
L(M), language of M (the language
recognized by M), is the set of strings
accepted by M
25
Recursive vs Recursively
Enumerable
Turing recognizable or Recursively
enumerable
 A language is Turing recognizable or
Recursively Enumerable if there is a Turing
machine accepting it
Turing decidable or recursive
 A language is decidable (or recursive) if
there is a Turing machine accepting it,
which has the additional property that it
halts on all possible inputs
26
Recursive vs Recursively
Enumerable
 It is possible for a TM to never reach a
halting configuration. It might instead
infinitely loop
there are 3 outcomes: accept, reject, loop
If TM accepts or rejects for all inputs then it
is a decidable (recursive) language.
Every decidable lang. is R.E. but not the
converse
27
Decidability
decidable
undecidable
all languages
regular
languages
context free
languages
RE
decidable  RE  all languages
28
Extentions to Turing Machine
Multitape TM
Nondeterministic TM
Multihead TM
Multistack PDA
All are equivalent, any language
accepted by a TM is accepted by any of
them and vice versa
29
30
Download