Turing machines § Finite automaton → no storage § Pushdown

Turing machines
Ü
Finite automaton → no storage
Ü
Pushdown automaton → storage is a stack
Ü
What if we give the automaton a more flexible storage?
Ü
What is the most powerful of automata?
Ü
In this lecture we will introduce the Turing machine, a
simple mathematical model of a computer.
Ü
Despite its simplicity, the Turing machine is equivalent in
computing power to the digital computer as we know it
today.
The Turing machine model
Ü
A formal model for an effective procedure should possess
certain properties.
1. Each procedure should be finitely describable.
2. The procedure should consist of discrete steps, each of which
can be carried out mechanically.
Ü
Such a model was introduced by Alan Turing in 1936.
Turing machine
Ü
A Turing machine (TM) is an automaton whose storage is a
tape.
Ü
This tape is divided into cells, each of which is capable of
holding one symbol.
Ü
It has a read-write head that can travel right or left and
that can read and write a single symbol on each move.
Ü
The TM has neither an input file nor any special output
mechanism.
Ü
Whatever input and output is necessary will be done on the
machine’s tape.
Tape
6Read-write head
?
Control unit
Turing machine
Definition
A Turing machine M is defined by M = (Q, Σ, Γ, δ, q0 , 2, F ),
where
Ü
Q is the set of states,
Ü
Σ is the input alphabet,
Ü
Γ is a finite set of symbols called the tape alphabet,
Ü
δ is the transition function defined as
δ : Q × Γ → Q × Γ × {L, R}, (the move symbols L, R
indicate whether the read-write head moves left or right
one cell after the new symbol has been written on the
tape.)
Ü
2 ∈ Γ is a special symbol called the blank,
Ü
q0 ∈ Q is the inital state,
Ü
F ⊆ Q is the set of final states.
We assume that Σ ⊆ Γ \ {2}.
Turing machine
Ü
The automaton starts in the given initial state with some
information on the tape.
Ü
It then goes through a sequence of steps controlled by δ.
Ü
The contents of any cell on the tape may be examined and
changed many times.
Ü
Eventually the whole process may terminate, which is
achieved by putting the TM into a halt state.
Ü
A TM is said to halt whenever it reaches a configuration for
which δ is not defined.
Ü
We assume that no transitions are defined for any final state,
so the TM will halt whenever it enters a final state.
Turing machine
Ü
Example 1:
Turing machine
Ü
Example 2:
Turing machine
Ü
Summarizing the main features of our TM model:
1. The TM has a tape that is unbounded in both directions,
allowing any number of left and right moves.
2. The TM is deterministic in the sense that δ defines at most
one move for each configuration.
3. There is no special input file. We assume that at the inital
time the tape has some specified content.
4. 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.
Turing machine
Ü
The most convenient way to exhibit a sequence of
configurations of a TM uses the idea of an instantaneous
description.
Ü
Any configuration is completely determined by the current
state, the contents of the tape, and the position of the
read-write head.
Ü
We use the notation in which
x1 qx2 or
a1 a2 . . . ak−1 qak ak+1 . . . an
is the instantaneous description of a machine in state q
(scanning ak ).
Turing machine
Ü
The instantaneous description gives only a finite amount of
information to the right and left of the read-write head.
Ü
The unspecified part of the tape is assumed to contain
all blanks.
Ü
If the position of blanks is relevant, the blank symbol may
appear in the instantaneous description.
Turing machine
Ü
A move from one configuration to another will be denoted
by `.
Ü
If
δ(q1 , c) = (q2 , e, R), then the move
abq1 cd ` abeq2 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.
Ü
We use ` to distinguish between several machines.
M
Turing machine
Definition
Let M = (Q, Σ, Γ, δ, q0 , 2, F ) be a TM. Then any string
a1 . . . ak−1 q1 ak ak+1 . . . an ,
with ai ∈ Γ and q1 ∈ Q is an instantaneous description
of M .
A move
a1 . . . ak−1 q1 ak ak+1 . . . an ` a1 . . . ak−1 bq2 ak+1 . . . an
is possible iff δ(q1 , ak ) = (q2 , b, R).
A move
a1 . . . ak−1 q1 ak ak+1 . . . an ` a1 . . . q2 ak−1 bak+1 . . . an
is possible iff δ(q1 , ak ) = (q2 , b, L).
Turing machine
Definition (continued)
M is said to halt starting from some inital configuration
x1 qi x2
if
∗
x1 qi x2 ` y1 qj ay2
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.
Ü
If, from the initial configuration x1 qx2 , the machine goes into
∗
a loop and never halts, then we write x1 qx2 ` ∞.
Turing machines as language acceptors
Ü
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 TM enters a final state
and halts, then w is considered to be accepted.
Turing machines as language acceptors
Definition
Let M = (Q, Σ, Γ, δ, q0 , 2, F ) be a Turing machine.
The language accepted by M is
∗
L(M ) = {w ∈ Σ+ | q0 w ` x1 qf x2 for some qf ∈ F, x1 , x2 ∈ Γ∗ }.
Ü
This definition tells us that the machine will halt when
w ∈ L(M ).
Ü
When w is not in L(M ) then the machine can halt in a
non-final state or it can enter an infinite loop and never
halt.
Turing machines as language acceptors
Ü
Example: For Σ = {a, b}, we design a TM that accepts
L = {an bn | n ≥ 1}.
Intuitively, the problem is solved in the following fashion:
Ü
Starting at the leftmost a we check it off by replacing it with
some x
aaabbb ` xaabbb
Ü
We travel to the right to find the leftmost b, which we check
off by replacing it with y.
xaaybb
Ü
We go left again to the leftmost a
xaaybb
Ü
Traveling back and forth we match each a with a
corresponding b.
Turing machines as transducers
Ü
Turing machines are not only interesting as language
acceptors, they also provide us with a simple abstract model
for digital computers.
Ü
The primary purpose of a computer is to transform input to
output, it acts as a transducer.
Modeling computers using Turing machines
Ü
The input for a computation will be all the nonblank
symbols on the tape at the initial time.
Ü
At the conclusion of the computation, the output will be
whatever is then on the tape.
Ü
Thus, we can view a TM transducer M as an implementation
of a function f defined by
ŵ = f (w),
∗
provided that q0 w ` qf ŵ, for some final state qf .
Turing machines as transducers
Definition
A function f with domain D is said to be Turingcomputable or just computable if there exists some TM
M = (Q, Σ, Γ, δ, q0 , 2, F ) such that
∗
q0 w ` qf f (w),
qf ∈ F , for all w ∈ D.
Ü
All the common mathematical functions, no matter how
complicated, are Turing-computable.
Turing machines as transducers
Ü
Example:
Ü
Given two positive integers x and y, we design a TM that
computes x + y.
Ü
We use unary notation to represent positive integers.
Ü
Any positive integer x is represented by w(x) = {1}+ , such
that |w(x)| = x.
Ü
Initially w(x) and w(y) are on the tape in unary notation,
seperated by a single 0, with the read-write head on the
leftmost symbol of w(x).
Ü
After computation, w(x + y) in on the tape followed by a
single 0, and the read-write head positioned at the left end of
the result.
Turing machines as transducers
Ü
Example (continued):
Ü
We want to design a TM for performing the computation
∗
q0 w(x)0w(y) ` qf w(x + y)0,
where qf is a final state.
Ü
All we need to do is to move the seperating 0 to the right end
of w(y), so that the addition amounts to nothing more than
the concatenation of the two strings.
Ü
Unary notation for practical computations is cumbersome, but
very convenient for programming Turing machines.
Ü
The resulting programs are much shorter and simpler than
binary or decimal representations.
Turing machines as transducers
Ü
Adding numbers is one of the fundamental operations of any
computer, one that plays a part in the synthesis of more
complicated instructions.
Ü
Other basic operations are copying strings and simple
comparisons. These can also be done easily on a Turing
machine.
Turing machines as transducers
Ü
Example:
Ü
Let x and y be two positive integers represented in unary
notation.
Ü
We construct a Turing machine that will halt in a final state
qy if x ≥ y and that will halt in a non-final state qn if x < y.
Ü
More precisely, the machine is to perform the computation
∗
q0 w(x)0w(y) ` qy w(x)0w(y) if x ≥ y,
∗
q0 w(x)0w(y) ` qn w(x)0w(y) if x < y.
Ü
Instead of matching a’s and b’s, we match each 1 on the left
of the dividing 0 with the 1 on the right.
Turing machines as transducers
Ü
Example (continued):
Ü
At the end of the matching, we will have on the tape either
xx . . . 110xx . . . x2 or
xx . . . xx0xx . . . x112,
depending on whether x > y or y > x.
Ü
In the first case, when we attempt to match another 1, we
encounter the blank at the right of the working space. This
can be used as a signal to enter the state qy (halt in final
state).
Ü
In the second case, we still find a 1 on the right when all 1’s
on the left have been replaced. We use this to get into the
state qn (halt in non-final state).
This example makes the important point that a TM can be
programmed to make decisions based on arithmetic comparisons.
Combining TM’s for complicated tasks
Ü
We have shown explicitly how some important operations
found in all computers can be done on a TM.
Ü
Since, in digital computers, such primitive operations are the
building blocks for more complex instructions, let us see how
these basic operations can also be put together on a TM.
Ü
We can describe TM’s in several ways at a high level, namely
either with pseudo code or block diagrams.
Ü
In a block diagram, we encapsulate computations in boxes
whose function is described, but whose interior details are not
shown.
Ü
By using such boxes, we implicitly claim that they can
actually be constructed.
Combining TM’s for complicated tasks
Ü
Example:
Ü
Designing a TM that computes the function
f (x, y) = x + y if x ≥ y,
= 0 if x < y.
Ü
We first use a comparing machine to determine whether or
not x ≥ y.
Ü
If so, the comparer sends a start signal to the adder which
then computes x + y.
Ü
If not, the eraser is started and changes every 1 to a blank.
Combining TM’s for complicated tasks
Ü
Example (continued):
Ü
The computations to be done by the Comparer C are
∗
qC,0 w(x)0w(y) ` qA,0 w(x)0w(y) if x ≥ y,
∗
qC,0 w(x)0w(y) ` qE,0 w(x)0w(y) if x < y.
Ü
Computations performed by the adder A
∗
qA,0 w(x)0w(y) ` qA,f w(x + y)0
Ü
Computations performed by the eraser E
∗
qE,0 w(x)0w(y) ` qE,f 0
The result is a single TM that combines the action of C, A, and E.
References
LINZ, P. An introduction to Formal Languages and Automata.
Jones and Bartlett Learning, 2012.
HOPCROFT, J. and ULLMAN, J. Introduction to Automata
Theory, Languages and Computation. Addison-Wesley, 1979.