0% found this document useful (0 votes)
8 views35 pages

Chapter05 TM

Uploaded by

Shafi Esa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views35 pages

Chapter05 TM

Uploaded by

Shafi Esa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Chapter 5: Turing Machines

5.1 Overview
▪ So far we have discussed some fundamental ideas, the concepts of
regular and context-free languages and their association with finite
automata and pushdown automata.
▪ The regular languages form a proper subset of the context-free
languages and, therefore, that pushdown automata are more powerful
than finite automata.
▪ The context-free languages, while fundamental to the study of
programming languages, are limited in scope.
▪ Some simple languages, such as {anbncn}, is not context-free.
▪ This prompts us to look beyond context-free languages and investigate
how one might define new language families that include these
examples.
▪ A Turing Machine, which is a very simple structure, turns out to be
very powerful and lets us solve many problems that cannot be solved
with a pushdown automaton.
▪ Turing machines are the most general types of automata, in principle
as powerful as any computer.
5.2 Standard Turing Machine
▪ Although we can envision a variety of automata with complex and
sophisticated storage devices, a Turing machine’s storage is actually
quite simple.
▪ It can be visualized as a single, one-dimensional array of cells, each of
which can hold a single symbol.
▪ This array extends indefinitely in both directions and is therefore
capable of holding an unlimited amount of information.
▪ The information can be read and changed in any order.
▪ We call such a storage device a tape.
Definition of a Turing Machine
▪ A Turing machine is an automaton whose temporary storage is a tape.
▪ This tape is divided into cells, each of which is capable of holding one
symbol.
▪ Associated with the tape is a read-write head that can travel right or
left on the tape and that can read and write a single symbol on each
move.
▪ A Turing machine will have neither an input file nor any special output
mechanism.
▪ Whatever input and output is necessary will be done on the machine’s
tape.
Turing Machine Pushdown Automata

Finite Automata
A Turing machine M is defined by
M = (Q, Σ, Γ, δ, q0, B, F),
where
Q is the set of internal states,
Σ is the input alphabet,
Γ is a finite set of symbols called the tape alphabet,
δ is the transition function,
B ∈ Γ is a special symbol called the blank,
q0 ∈ Q is the initial state,
F ⊆ Q is the set of final states.
…cont’d
▪ Σ ⊆ Γ−{B}, that is, that the input alphabet is a subset of the tape
alphabet, not including the blank.
▪ The transition function δ is defined as
δ : Q × Γ → Q × Γ × {L, R} .
▪ The arguments of δ are the current state of the control unit and the
current tape symbol being read.
▪ The result is a new state of the control unit, a new tape symbol, which
replaces the old one, and a move symbol, L or R.
▪ The move symbol indicates whether the read-write head moves left or
right one cell after the new symbol has been written on the tape.
…cont’d
▪ Example – the following figure shows the situation before and after
the move
δ (q0, a)=(q1, d, R).

The situation (a) before the move and (b) after the move.
…cont’d
▪ We can think of a Turing machine as a rather simple computer.
▪ It has a processing unit, which has a finite memory, and in its tape, it
has a secondary storage of unlimited capacity.
▪ The instructions that such a computer can carry out are very limited: It
can sense a symbol on its tape and use the result to decide what to do
next.
▪ The only actions the machine can perform are to rewrite the current
symbol, to change the state of the control, and to move the read-write
head.
▪ As always, the automaton starts in the given initial state with some
information on the tape.
…cont’d
▪ It then goes through a sequence of steps controlled by the transition
function δ.
▪ During this process, the contents of any cell on the tape may be
examined and changed many times.
▪ Eventually, the whole process may terminate, which we achieve in a
Turing machine by putting it into a halt state.
▪ A Turing machine is said to halt whenever it reaches a configuration
for which δ is not defined
▪ No transitions are defined for any final state, so the Turing machine
will halt whenever it enters a final state.
…cont’d
▪ Example: Consider the Turing machine defined by
Q = {q0, q1} ,
Σ = {a, b} ,
Γ = {a, b, B} ,
F = {q1} ,
and
δ (q0, a)=(q0, b, R),
δ (q0, b)=(q0, b, R),
δ (q0, B)=(q1, B, L).
…cont’d
▪ If this Turing machine is started in state q0 with the symbol a under the
read-write head, the applicable transition rule is δ (q0, a)=(q0, b, R).
Therefore, the read-write head will replace the a with a b, then move
right on the tape. The machine will remain in state q0. Any subsequent
a will also be replaced with a b, but b’s will not be modified. When the
machine encounters the first blank, it will move left one cell, then halt
in final state q1.

A sequence of moves
…cont’d
▪ As before, we can use transition graphs to represent Turing machines.
Now we label the edges of the graph with three items: the current tape
symbol, the symbol that replaces it, and the direction in which the
read-write head is to move
…cont’d
▪ Since one can make several different definitions of a Turing machine,
it is worthwhile to summarize the main features of our model, which
we will call a standard Turing machine:
▪ The Turing machine has a tape that is unbounded in both
directions, allowing any number of left and right moves.
▪ The Turing machine is deterministic in the sense that δ defines at
most one move for each configuration.
▪ There is no special input file. We assume that at the initial time the
tape has some specified content. Some of this may be considered
input. Similarly, there is no special output device. Whenever the
machine halts, some or all of the contents of the tape may be
viewed as output.
Instantaneous Description of TM
▪ The most convenient way to exhibit a sequence of configurations of a
Turing machine uses the idea of an instantaneous description.
▪ Any configuration is completely determined by the current state of the
control unit, the contents of the tape, and the position of the read-write
head.
We will use the notation in which
x1qx2
or
a1a2 ··· ak−1qakak+1 ··· an
is the instantaneous description of a machine in state q with the tape
depicted in following Figure.
▪ The symbols a1, ..., an show the tape contents, while q defines the state
of the control unit. The position of the read-write head is over the cell
containing the symbol immediately following q.
▪ The instantaneous description gives only a finite amount of
information to the right and left of the read-write head.
…cont’d
▪ The unspecified part of the tape is assumed to contain all blanks;
normally such blanks are irrelevant and are not shown explicitly in the
instantaneous description.
▪ If the position of blanks is relevant to the discussion, however, the
blank symbol may appear in the instantaneous description.
▪ For example, the instantaneous description qBw indicates that the
read-write head is on the cell to the immediate left of the first symbol
of w and that this cell contains a blank.
…cont’d
▪ The pictures drawn in the following Figure correspond to the sequence
of instantaneous descriptions q0aa, bq0a, bbq0 , bq1b.

▪ A move from one configuration to another will be denoted by ⊢.


Thus, if
δ (q1, c)=(q2, e, R),
then the move
abq1cd ⊢ abeq2d
…cont’d
is made whenever the internal state is q1, the tape contains abcd, and
the read-write head is on the c.
▪ The symbol ⊢∗ has the usual meaning of an arbitrary number of
moves.
▪ Subscripts, such as ⊢M, are used in arguments to distinguish between
several machines.
Example - The action of the Turing machine in above Figure can be
represented by
q0aa ⊢ bq0a ⊢ bbq0 ⊢ bq1b
or
q0aa ⊢∗ bq1b.
…cont’d
▪ Definition – Let M = (Q, Σ, Γ, δ, q0, , F) be a Turing machine. Then
any string a1 ··· ak−1q1akak+1 ··· an, with ai ∈ Γ and q1 ∈ Q, is an
instantaneous description of M.
A move
a1 ··· ak−1q1akak+1 ··· an ⊢ a1 ··· ak−1bq2ak+1 ··· an
is possible if and only if
δ (q1, ak)=(q2, b, R).
A move
a1 ··· ak−1q1akak+1 ··· an ⊢ a1 ··· q2ak−1bak+1 ··· an
is possible if and only if
δ (q1, ak)=(q2, b, L).
…cont’d
M is said to halt starting from some initial configuration x1qix2 if
x1qix2 ⊢∗ y1qjay2
for any qj and a, for which δ (qj , a) is undefined. The sequence of
configurations leading to a halt state will be called a computation.
5.2. Construction of TM
Turing Machines as Language Accepters
▪ A string w is written on the tape, with blanks filling out the unused
portions. The machine is started in the initial state q0 with the read-
write head positioned on the leftmost symbol of w. If, after a sequence
of moves, the Turing machine enters a final state and halts, then w is
considered to be accepted.
▪ Definition - Let M = (Q, Σ, Γ, δ, q0, B, F) be a Turing machine. Then
the language accepted by M is
L (M) = {w ∈ Σ+ : q0w ⊢* x1qf x2 for some qf ∈ F, x1,x2∈ Γ*}.
…cont’d
▪ When w is not in L(M), one of two things can happen:
▪ The machine can halt in a nonfinal state or
▪ It can enter an infinite loop and never halt. Any string for which M
does not halt is by definition not in L(M).
▪ Example 1 – For Σ = {0, 1}, design a Turing machine that
accepts the language denoted by the regular expression 00*
▪ Starting at the left end of the input, we read each symbol and check
that it is a 0. If it is, we continue by moving right. If we reach a
blank without encountering anything but 0, we terminate and
accept the string. If the input contains a 1 anywhere, the string is
not in L(00*), and we halt in a nonfinal state.
…cont’d
▪ To keep track of the computation, two internal states Q = {q0, q1}
and one final state F = {q1} are sufficient. As transition function we
can take
δ (q0, 0) = (q0, 0, R),
δ (q0, B) = (q1, B, R).
▪ As long as a 0 appears under the read-write head, the head will
move to the right. If at any time a 1 is read, the machine will halt in
the nonfinal state q0, since δ (q0, 1) is undefined.
▪ Example 2 - For Σ = {a, b}, design a Turing machine that
accepts
L = {anbn : n ≥ 1} .
…cont’d
▪ Starting at the leftmost a, we check it off by replacing it with some
symbol, say x. We then let the read-write head travel right to find
the leftmost b, which in turn is checked off by replacing it with
another symbol, say y. After that, we go left again to the leftmost a,
replace it with an x, then move to the leftmost b and replace it with
y, and so on.
▪ Traveling back and forth this way, we match each a with a
corresponding b. If after some time no a’s or b’s remain, then the
string must be in L.
▪ Working out the details, we arrive at a complete solution for which
Q = {q0, q1, q2, q3, q4} , F = {q4} , Σ = {a, b} , Γ = {a, b, x, y, B}.
…cont’d
The set
δ (q0, a)=(q1, x, R),
δ (q1, a)=(q1, a, R),
δ (q1, y)=(q1, y, R),
δ (q1, b)=(q2, y, L)
replaces the leftmost a with an x, then causes the read-write head to
travel right to the first b, replacing it with a y. When the y is written,
the machine enters a state q2, indicating that an a has been
successfully paired with a b.
…cont’d
▪ The next set of transitions reverses the direction until an x is
encountered, repositions the read-write head over the leftmost a, and
returns control to the initial state.
δ (q2, y) = (q2, y, L),
δ (q2, a) = (q2, a, L),
δ(q2, x) = (q0, x, R).
We are now back in the initial state q0, ready to deal with the next a & b.
▪ After one pass through this part of the computation, the machine will
have carried out the partial computation
q0aa ··· abb ···b ⊢* xq0a ··· ayb ··· b,
so that a single a has been matched with a single b.
…cont’d
▪ After two passes, we will have completed the partial computation
q0aa ··· abb ··· b ⊢* xxq0 ··· ayy ··· b,
and so on, indicating that the matching process is being carried out
properly.
▪ When the input is a string anbn, the rewriting continues this way,
stopping only when there are no more a’s to be erased. When
looking for the leftmost a, the read-write head travels left with the
machine in state q2. When an x is encountered, the direction is
reversed to get the a. But now, instead of finding an a it will find a
y. To terminate, a final check is made to see if all a’s and b’s have
been replaced (to detect input where an a follows a b).
…cont’d
▪ This can be done by
δ (q0, y)=(q3, y, R),
δ (q3, y)=(q3, y, R),
δ (q3, B)=(q4, B, R)
▪ The particular input aabb gives the following successive
instantaneous descriptions:
q0aabb ⊢ xq1abb ⊢ xaq1bb ⊢xq2ayb
⊢ q2xayb ⊢ xq0ayb ⊢ xxq1yb
⊢ xxyq1b ⊢ xxq2yy ⊢ xq2xyy
⊢ xxq0yy ⊢ xxyq3y ⊢ xxyyq3
⊢ xxyyq4.
▪ At this point the Turing machine halts in a final state, so the string
aabb is accepted.
Language of the Turing Machines
▪ The language accepted by TM’s are called recursively enumerable
(RE) language. Thus, the RE languages are those languages that can be
recognized that can be recognized or accepted by any sort of
computing device.
5.3 Decidability vs Undecidability
▪ A function f on a certain domain is said to be computable if there
exists a Turing machine that computes the value of f for all arguments
in its domain.
▪ A function is uncomputable if no such Turing machine exists. There
may be a Turing machine that can compute f on part of its domain, but
we call the function computable only if there is a Turing machine that
computes the function on the whole of its domain.
▪ A problem is decidable if there exists a Turing machine that gives the
correct answer for every statement in the domain of the problem.
▪ A problem is undecidable if there doesn’t exists a Turing machine that
gives the correct answer for every statement in the domain of the
problem.
…cont’d
▪ Examples of undecidable problem
▪ Consider the statement “For a context-free grammar G, the
language L(G) is ambiguous”. For some G this is true, for others it
is false, but clearly we must have one or the other. Hence, G
undecidable
▪ The TM halting problem: Does a given Turing Machine M halt on a
given input w? may or may not be. Therefore halting problem is
undecidable.
…cont’d
▪ There are two types of TMs (based on halting):
Recursive
▪ TMs that always halt, no matter accepting or non-accepting
(DECIDABLE PROBLEMS)
Recursively Enumerable
▪ TMs that are guaranteed to halt only on acceptance. If non-
accepting, it may or may not halt (i.e., could loop forever).
▪ Undecidability: Undecidable problems are those that are not recursive
…cont’d
▪ Any TM for a Recursive language is going to look like this:

▪ Any TM for a Recursively Enumerable (RE) language is going to look


like this:

You might also like