Chapter 9: Turing Machines
Chapter 9: Turing Machines
Peter Cappello
Department of Computer Science
University of California, Santa Barbara
Santa Barbara, CA 93106
[email protected]
• These notes are supplemented with figures, and material that arises during the lecture in
response to questions.
• Please report any errors in these notes to [email protected]. I’ll fix them immediately.
∗
Based on An Introduction to Formal Languages and Automata, 3rd Ed., Peter Linz, Jones and Bartlett
Publishers, Inc.
1
Turing machines are the outcome of a quest to understand the limits
of computation.
2
Definition of a Turing Machine
• δ is a partial function.
3
• When the machine enters a state with no defined transition, it halts.
• We assume that there is no transition from any final state.
Example: Consider the TM defined by
Q = {q0 , q1},
Σ = {a, b}
Γ = {a, b, 2}
F = {q1 }
and
δ(q0, a) = (q0 , b, R),
δ(q0, b) = (q0 , b, R),
δ(q0, 2) = (q1 , 2, L).
What does it do on input babba?
4
Example 9.3: Consider a TM, whose:
• Q, Σ, and Γ are as defined in the previous example
•F =Ø
• δ is given by
5
Def.: A standard Turing Machine has the following features:
• Its tape is unbounded in both directions.
• It is deterministic: δ defines at most 1 transition for each state.
• There is no input file: its input is on its tape when it starts.
A computation’s state is given by an instantaneous description (ID):
• Tape contents between the leftmost & rightmost non-blank symbols.
• Its internal state.
• The position of the read/write head.
This is displayed as
a1a2 · · · ak−1 q ak ak+1 · · · an, where
q is to the left of the read/write head:
The TM is in internal state q, reading ak .
6
• A sequence of IDs, I1, I2, . . . , In is depicted
I1 ` I2 ` . . . ` In or
I 1 `∗ I 2 I n .
• Illustrate this, using the infinite loop example.
• This notation is summarized by the following definition.
Def. 9.2
• Let M = (Q, Σ, Γ, δ, q0, 2, F ) be a TM.
• Let a1 · · · ak−1 q ak ak+1 · · · an, with ai ∈ Γ, q ∈ Q be an ID of M .
7
• M halts, when starting from initial configuration x1 q x2,
x1 q x2 `∗ y1 p ay2,
where δ(p, a) is undefined.
• The sequence of configurations from the initial configuration to the
halting configuration is called a computation.
• Example shows that a TM may never halt.
• This is depicted by
x1 q x2 `∗ ∞, where
x1 q x2 is the initial state.
8
Turing Machines as Language Acceptors
9
Example: For Σ = {0, 1}, construct a TM that accepts L((0 + 1)∗0).
• When reading an a, provisionally accept and move right;
• When reading a b, provisional reject and move right;
• When reading a 2, accept, if in the provisionally accept state, else
reject.
(diagram)
• M = ({a, r, A, R}, {0, 1}, {0, 1, 2}, δ, r, 2, {A}), where δ is given by
δ(r, 0) = (a, 0, R),
δ(r, 1) = (r, 1, R),
δ(a, 0) = (a, 0, R),
δ(a, 1) = (r, 1, R),
δ(a, 2) = (A, 2, R),
δ(r, 2) = (R, 2, R).
10
Example 9.7: For Σ = {a, b}, make a TM accepting L(anbn : n > 0).
• Starting at leftmost a, replace it with x;
• Go right over a and y symbols until, reading a b;
• replace b with y;
• Go left until x is encountered;
• Go right; // we are now in initial state
• if encounter a y, scan right while encountering y symbols
• if encounter a 2, accept.
• M = ({q0 , q1, q2, q3, q4 }, {a, b}, {a, b, 2}, δ, q0 , 2, {q4 }), where δ is
11
// replace the leftmost a with x and go right until a b is read
δ(q0, a) = (q1, x, R),
δ(q1, a) = (q1, a, R),
δ(q1, y) = (q1, y, R),
δ(q1, b) = (q2, y, L).
// go left until an x is read; go right 1 space
δ(q2, y) = (q2 , y, L),
δ(q2, a) = (q2 , a, L),
δ(q2, x) = (q0 , x, R).
// termination sequence
δ(q0, y) = (q3, y, R),
δ(q3, y) = (q3, y, R),
δ(q3, 2) = (q4, 2, R).
12
• After 1 pass, the TM has accomplished
q0 aa · · · abb · · · b `∗ x q0 a · · · ayb · · · b.
After 2 passes, the TM has accomplished
q0 aa · · · abb · · · b `∗ xx q0 a · · · ayyb · · · b.
13
Example 9.8: For Σ = {a, b}, make a TM accepting L(anbncn : n > 0).
One can extend the strategy used in the previous example to ensure
that both b and c symbols match in number to a symbols.
14