You are on page 1of 33

1.

Turing Machines
Introduction
• FAs and PDAs are models of computation associated with
regular languages and context-free languages, respectively
• Regular languages form a proper subset of the context-free
languages
• FAs have limited (a small amount of) memory
• For example, languages, like L = {anbn: n ≥ 0}, are not regular
languages
• The use of stack (unlimited LIFO memory) as memory in PDA
made it accept the language L = {anbn: n ≥ 0}
• Some simple languages such as {anbncn: n ≥ 0} and {ww} are
not context-free
• This makes us look beyond context-free languages
• How far the concept of automaton can be pushed?
2
Turing Machines
• Turing machine (TM) is a powerful model of computation first
proposed by Alan Turing in 1936
• Similar to an FA but with an unlimited and unrestricted
memory
• A TM is an accurate model of a general purpose computer
• A TM can do everything a real computer can do
• A TM cannot solve some problems that are beyond the
theoretical limits of computation
• A TM model uses an infinite tape as its unlimited memory
• It has a tape head that can read and write symbols and move
around on the tape
• Initially the tape contains only the input string and is blank
everywhere else
3
• If a TM needs to store information, it may write the information on
the tape
• To read information that it has written, the machine can move its
head back over it
• The machine continues computing until it decides to produce an
output
• The whole process terminates by putting the TM in a halt state
• A TM is said to halt whenever it reaches a configuration for which δ
is not defined
• Any final state is a halt state since δ is not defined for a final state
• If it doesn’t enter the halt state, it will go on forever, never halting
• Initially the tape contains only the input string and is blank
everywhere else
• Figure 1.1 shows a schematic representation of a Turing machine

4
tape

... □ □ a b a a □ □ ...

read-write head

control unit

Figure 1.1: Schematic representation of a Turing machine

5
Informal description of Turing machine
• What’s different from a DFA
– Input tape is infinite
– Input head can both READ and WRITE
– Input head can move LEFT and RIGHT
– Has both ACCEPT and REJECT states and
accepts/rejects rightaway (does not need to
reach end of input)

6
• Let L = { w#w | w ∈ {0,1}* }
Give a high-level description of a TM that
accepts an input if it is in L, and rejects if not.

7
• A TM recognizes a language if it accepts all
and only those strings in the language
• A TM decides a language if it accepts all
strings in the language and rejects all strings
not in the language
• A language is called Turing-recognizable or
recursively enumerable if some TM
recognizes it
• A language is called decidable or recursive if
some TM decides it
8
9
The Standard Turing Machine
Definition of a Turing Machine
• A Turing machine is a 7 – tuple (Q, ∑, Γ, δ, q0, □, F) where Q, ∑, Γ are
all finite sets and:
• Q is the set of states
• ∑ is the input alphabet ⊆ Γ – {□}
• Γ is the tape alphabet
• δ: Q × Γ → Q × Γ × {L, R} is the transition function
• □ ∈ Γ is a special symbol called the blank
• q0 ∈ Q is the initial state
• F ⊆ Q is the set of final states
• The heart of a TM is the transition function δ
• When the machine is in a certain state q and the head is over a tape
square containing a, and if δ(q, a) = (r, b, L), the machine writes the
symbol b replacing the a, and goes to state r and moves to left.
10
• The third component is either L or R and indicates whether
the head moves to the left or right after writing, respectively
• Changes occur in the current state, the current tape contents,
and the current head location

Eg: Internal state q0

a b c

fig a:before the move


Internal state q1
d b c

fig b: After the move


δ(q0,a)=(q1,d,R).

11
• Eg: Consider the Turing machine defined by:
Q={q0,q1}
∑={a,b}
Γ={a,b, □}
F={q1}
And
δ(qo,a)=(q0,b,R)
δ(qo,b)=(q0,b,R)
δ(qo, □)=(q1, □,L)
Show the sequences of moves.

qo

□ a b □ □

q0

□ b b □

12
q0

□ b b □

q1

□ b b □

13
• Transition graphs can be used to represent
Turing Machines
• The edges of the graph can be labeled with 3
items:
– The current tape symbol
– The symbol that replaces the current tape symbol
– The direction in which the read-write head is to
move

14
• Ex: The TM given above can be repesented by
the transition graph:
q
a,b,R; 1
q
b,b,R q
1
1
q0 □, □,L q1q
q
q
q
1
1
q

15
Configuration of a Turing Machine
• Any configuration of a TM is completely
determined by the current state of the control
unit, the contents of the tape, and the
position of the read-write head.

16
• A setting of these three items is called a configuration of
TM
• Instantaneous description is a convenient way to exhibit a
sequence of configurations
• We use the notation x1qx2 or a1…ak-1qakak+1…an where the
read-write head is on the cell holding ak, the current state is
q, x1 = a1…ak-1 and x2 = ak…an
• Let M = (Q, ∑, Γ, δ, q0, □, F) be a TM. 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 iff
δ(q1, ak) = (q2, b, R)

17
• A move a1…ak-1q1akak+1…an ˫ a1…q2ak-1bak+1…an is possible iff
δ(q1, ak) = (q2, b, L)
• M is said to halt starting from initial configuration x1qix2 if
x1qix2 ˫* y1qjay2for any qj and a, for which δ(qj, a) is undefined
• The sequence of configurations leading M to a halt state is
called a computation
• If M goes into a loop and never halts we use a special notation
x1qix2 ˫*

18
• Eg: Consider the Turing machine defined by:
Q={q0,q1}
∑={a,b}
Γ={a,b, □}
F={q1}
And
δ(qo,a)=(q0,b,R)
δ(qo,b)=(q0,b,R)
δ(qo, □)=(q1, □,L)
Show the sequence of moves from configuration to another.

qo

□ a a □ □

q0

19
q0aa|- bq0a |- bbq0□ |- bq1b

20
Turing Machines as Language Acceptors
• A string w is written on the tape, with blanks
filling out the unused portions
• The machine started in the initial state q0 with
the read-write head position 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
21
• Let M = (Q, ∑, Γ, δ, q0, □, F) be a TM
• Then the language accepted by M is:
L(M) = {w ∈ ∑+: q0w ˫* x1qfx2 for some qf ∈ F, x1, x2 ∈ Γ*}
• Example 1.1:
For ∑ = {0, 1}, design a TM that accepts the language denoted
by the regular expression 00*
• Example 1.2:
For ∑ = {a, b}, design a TM that accepts L = {a, b}*{ab}
• Example 1.3:
For ∑ = {a, b}, design a TM that accepts L = {anbn: n ≥ 1}
• Example 1.4:
Design a TM that accepts L = {anbncn: n ≥ 1}
• Example 1.5:
Design a TM that accepts L = {xx: x ∈ {a, b}*}
• Example 1.6:
Design a TM that accepts L = {a raised to 2 raised to n: n ≥ 0} 22
Turing Machines as Transducers
• A transducer transforms input to output
• The input for a computation is 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
• We can view a TM transducer M as an implementation of a
function f defined by w’ = f(w) provided that q0w ˫*M qfw’ for
some final state qf
• A function f with domain D is said to be Turing-computable or
just computable if there exists some Turing machine M = (Q,
∑, Γ, δ, q0, □, F) such that q0w ˫*M qff(w), qf ∈ F, for all w ∈ D
• Example 1.7:
Given two positive integers, design a TM that computes x + y

23
• Example 1.8:
Given a unary representation of a positive integer, design a
TM that converts the integer to its binary equivalent
• Example 1.9:
Design a TM that copies a string of 1’s
• Example 1.10:
Let x and y be two positive integers in unary representation.
Construct a TM that will halt in a final state qy if x >= y, and
will halt in a nonfinal state qn if x < y.
Combining Turing Machines for Complicated Tasks
• Basic operations can be put together to perform complicated
tasks
• Example 1.11:
Design a TM that computes the function f(x, y) = x + y if x ≥ y,
f(x, y) = 0 if x < y
• Figure 1.2 shows how TMs can be combined to compute f(x, y)
24
Figure 1.2: A combination of TMs
Turing’s Thesis
• Reading Assignment

25
Other Models of Turing Machines
• The definition of a standard TM is not only possible one
• But, the power does not depend on the choice of a TM
Equivalence of Classes of Automata
• Two automata are equivalent if they accept the same
language. Consider two classes of automata C1 and C2. If for
every automaton M1 in C1 there is an automaton M2 in C2 such
that L(M1) = L(M2), we say C2 is at least as powerful as C1. I f
the converse also holds and for every M2 in C2 there is an M1
in C1 such that L(M1) = L(M2), we say that C1 and C2 are
equivalent
Turing Machines with a Stay-Option
• In our definition of a standard TM, the read-write head must
move either to the right or to the left
26
• Sometimes it is convenient to provide a third option, to have
the read-write head stay in place after rewriting the cell
content
• The transition function will then be defined as
• δ: Q × Γ → Q × Γ × {L, R, S}
• Theorem 1.1: The class of Turing machines with stay-option is
equivalent to the class of standard Turing Machines
Multitrack Turing Machines
• A single head and multiple tracks
• In a single move the TM changes the read-write head changes
all the contents pointed to by the head

27
Turing Machines with Semi-Infinite Tape
• Many authors believe that the standard TM has left boundary
and infinite to the right direction
• This Turing machine is otherwise identical to our standard
model except that no left move is permitted when the read-
write head is at the boundary
The Off-Line Turing Machine
• Reading Assignment

28
Multitape Turing Machines
• Several tapes with independent tape heads
• The transition function is defined as
δ: Q × Γn → Q × Γn × {L, R, S}n
• Theorem 1.2: Every multitape Turing machine has an
equivalent single-tape Turing machine
Multidimensional Turing Machines
• A multidimensional TM is one in which the tape can be
viewed as extending infinitely in more than one dimension
• The formal definition of a two-dimensional TM involves a
transition function δ of the form
• δ: Q × Γ → Q × Γ × {L, R, U, D}
• where U and D specify movement of the read-write head up
and down, respectively

29
Nondeterministic Turing Machines
• A nondeterministic TM is like a standard TM, except that δ is
now a function
δ: Q × Γ → 2Q × Γ × {L, R}
• As always when nondeterminism is involved, the range of δ is
a set of possible transitions, any of which can be chosen by
the machine
• Theorem 1.3: The class of deterministic TMs and the class of
nondeterministic TMs are equivalent

30
A Universal Turing Machine
• A standard TM is a special computer
• Once δ is defined, the TM is restricted to carrying out one
particular type of computations
• Digital computers, on the other hand, are general purpose
machines that can be programmed to do different jobs at
different times
• Consequently, TMs cannot be considered equivalent to
general purpose digital computers
• This objection can be overcome by designing a
reprogrammable TM, called universal Turing machine
• A universal TM Mu is an automaton that, given as input the
description of any TM M and a string w, can simulate the
computation of M on w
• Mu is depicted in Figure 1.3
31
Figure 1.2
• Mu can be created as follows:
– We assume Q = {q1, q2, . . ., qn}, with q1 the initial state and
q2 a single final state, and Γ = {a1, a2, . . ., am}, where a1
represents the blank
– We then select an encoding in which q1 is represented by
1, q2 is represented by 11, and so on. Similarly, a1 is
encoded as 1, a2 as 11, etc
32
– The symbol 0 will be used as a separator between the 1’s
– With the initial and final state and the blank defined by
this convention, any TM can be described completely with
δ only
– The transition function is encoded according to this
scheme, with the arguments and result in some prescribed
sequence
– For example, δ(q1, a2) = (q2, a3, L) might appear as: . . .
10110110111010 . . .

33

You might also like