You are on page 1of 13

UNIT –IV

TURING MACHINES

TURING MACHINE

Ø In the previous units, we have discussed several sets of languages, and now we
come to a bigger class of languages namely the recursively enumerable
languages.

Ø The model of computation that - recognizes them is called the 'Turing Machine'
named after the famous mathematician Alan Turing who proposed it in 1936.

Ø The Turing Machine is the most powerful model of computation that exists and
we can also prove that the present day digital computers ability to compute is not
powerful than that of a Turing Machine.

Ø Hence, if it can be shown that a Turing machine cannot solve a problem, then
there does not exist an algorithm which can reply a 'yes' or 'no' to the problem.

Ø A Turing Machine unlike the PDA consists of a tape of infinite length. The tape is
divided into cells, each of which can hold only one symbol of the 'tape alphabet'.

Ø The Turing Machine has a head which is capable of reading a symbol from the
tape, or writing any symbol on the tape. The head remains pointing to only one cell
of the tape at a time, and it is said to be reading the symbol present on the cell.

Ø It can be seen that the tape has a beginning but extends to infinity on the
right. The symbols a1, a2, ….belong to the tape alphabet.

Ø There's another special symbol B called the blank. It is used as a seperator,


between two different symbols when 'unary' encoding is used
(Note: All of us are familiar with binary encoding, which uses the alphabet {0,1], but
in unary encoding there's only one symbol say (o} or {1}. Integers are represented as

n = 1n i.. 11111111….1
eg 5 = 111111=15
6 = 111111 = 16

(Exponentiation denotes the no of times the symbol is repeated or concatenated)

In order to distinguish between different symbols a special symbol is required which


is the blank symbol.

For eq: 53 can be written as 15 B 13 . If this is the i/p to the it is written on the tape
as

Formally ,a Turing machine TM is denoted.

M=(Q.Σ,Γ,δ, 0 q ,B, F) ,

Where
Q is the finite set of states,
Γ is the finite set of allowable tape symbol,
B, a symbol of Γ, is the blank,
Σ,a subset of Γ not including B, is the set of input symbol,
δ is the next move function, a mapping from Q X Γ to Q X Γ X{L,R}
q0 in Q is the star state,
F Q ⊆ is the set of final states.
Ø Since the notion of instantaneous description must already be familiar to you
all (as used in the case of PDA), the same can be extended to a Turing Machine
also.

INSTANTANEOUS DESCRIPTION OF A TURING MACHINE

Ø We denote an instantaneous description (ID) of the Turing machine M by 1 2 q


α α. Here q, the current state of M, is in Q; αα is the string in I* that is the contents
head, whichever is rightmost nonblank symbol or the symbol to the left of the head,
whichever is rightmost. (Observe that the blank B may occur in α1α2.)

Ø We assume that Q and Γ are disjoint to avoid confusion. Finally, the tape
head is assumed to be scanning the leftmost symbol of α2, or α2=ε, the head is
scanning a blank.

Ø We define a move of M as follows. Let X1 X2 …Xi-1 q X1…Xn be can ID.

Ø Suppose δ(q,Xi)=(p,Y,L), where if I-1=n, then X1 is taken to be B.

Ø If I=1, then there is no next ID, As the tape head is not allowed to fall off the
left end of the tape.

If i>1, then we write.

X1 X2…Xi-1qXi…Xn X1 X2…Xi-2pXi-1 YXi+1…Xn.

However , if any suffix of Xi-1 YXi+1…Xn is completely blank , that suffix is deleted.

Alternatively, suppose δ(q,Xi) =(p,Y,R ). Then we write.

X1 X2 … Xi-1 q Xi Xi+1… Xn X1 X2…Xi-2pXi-1 YXi+1…Xn.

Note that in the case i-1= n, the string X1…Xn is empty, and the right side is longer
than the left side.

If two ID’s are related by Xn

we say that the second results from the first by one move.
Ø If one ID results from another be some finite number of moves, including zero

moves they are related by the symbol . We drop the subscript M from

or when no confusion results.

Ø The language accepted be M, denoted L(M), is the set of those words in Σ*


that cause M to enter a final state when placed, justified at the left, on the tape of
M, with M in state q0, and the tape head of M at the leftmost cell.

Formally, the language accepted by M=(Q,Σ,Γ,δ,q0,B,F) is

{w|w in Σ* and q0 α1 pα2 for some p in F, and α1 and α2 in Γ*}

COMPUTABLE LANGUAGES AND FUNCTIONS

Thus a Turing Machine is said to have accepted a given input if :


• It reaches the halting state
• Remains in the halting state for all input symbols.
Otherwise a Turing Machine may exhibit the following behaviour:

• The Turing Machine reach any other state other than the halting state and may
remain stationary for all inputs.

• The Turing Machine could enter an infinite loop, in which case we cannot decide
whether the given input string has been accepted or not. Because, at any point of
time we cannot decide if the Turing Machine has entered an infinite loop or not, as
it may reach the halting state any moment.

Hence, the languages recognizable by a TM are divided into two depending upon
the behaviour of the TMs constructed for recognizing it.

• If L is a language and M is a TM that recognizes it, L is called a recursive


language only if M halts on all inputs irrespective of whether it reaches the halting
state or not.

• Any language L1 (M1) (i.e., the language L1 correspondingly to the TM M1) is said
to be recursively enumerable if there is atleast one word belonging to L, which
makes the TM to enter into an “infinite loop”.

Thus it is obvious that recursive languages from a sub-set of recursively enumerable


languages, which is shown in the above diagram.

TM as Computer of Functions that accept and return integer:

Ø Till this point of time, we have seen the TM as a recogniser of any recursive
language for which it is constructed, but it can be used to compute functions (Draw
similarly to C functions) which accept integers as inputs and return an integer.

Ø The input parameters are given to the TM in the form of input symbols on the
tape with each integer encoded in unary and separated by another special symbol.

Ø The TM’s head, during computation reads the input symbols present on the
tape
Ø and comes to a halt after writing the output onto the tape cells.

Ø Refer the TM which we constructed earlier that performs unary addition.


Compare this to a function integer add (integer a, integer b) written using C. In our
TM, the input is in the form of Oa  Ob BBBB. . . . . . .

Ø The TM after scanning OaOb returns the sum of a and b as Oa+bBBBB


which is the value the function returns. Those functions for which a TM can be
constructed to compute them are called “partially recursive functions” which
accepts the same parameters as that of the function and returns a value.

Ø A superset (opposite of subset) of partially recursive function is “totally


recursive functions” which represents all common arithmetic functions. One such
function that cannot be computed by a TM is:

Ackermann function A: NÆN defined by

A(n,0)=n+1
A(0,m+1)=A(1,n)
A(n+1,m+1)=A(A(n,m+1),n)

CONSTRUCTION OF A TURING MACHINE

Techniques for TM construction

Storage in finite control

Ø The memory of the Turing Machine, or in other words, the Turing Machine
remembers the symbol it read previously only by virtue of the state in which it is.
Hence the labeling of the Turing Machine states can be changed accordingly.

Multi Track Turing Machine

Ø A slight variant of the TM that we have seen is the multi track TM. In this type
of TM, the one-way infinite tape containing cells that store upto 1 symbol at a time
is modified to store more than 1 symbol.

Ø This is done by dividing the tape into several tracks, and each track acts as a
separate tape and contains a symbol in its cell. Therefore a k-track TM can
contain upto “k” symbols in each of its cell.

A 1-track Turing Machine

A 3-track Turing Machine:


Ø Although this may seem to add some extra space to the TM’s tape, it does
not add anything in terms of functionality.

Ø In actual practice, when more than one symbol has to be stored in a single
cell, an addition of a new symbol in the next track, causes the previous symbol to
be encoded into a new symbol.

Ø In fact, it can be proved that a multi track TM is equivalent to a single track


TM. Yet our discussion about multi track TM will help us to simplify our solutions to
problems, which can be easily represented using a multi track rather than single
track.

1. Construct a Turing Machine which performs unary addition.

The input is over the alphabet Σ={0,1} and is of the form B0i10jBBB…. The output is
of the form B0i+jBBB….

2. Construct a Turing Machine which performs proper unary subtraction.

Proper subtraction is similar to ordinary subtraction excepting that x-y is defined as


x-y=0 if y>x. The Turing Machine which performs the following is given as under:
3. Construct a Turing Machine for recognizing the language consisting of
alindromes over the alphabet Σ={a,b}
Ø Note that there are two types of palindromes namely even palindromes which
consists of even number of symbols and odd palindromes which contain odd number
of strings.

Ø The logic used in the above diagram is to read a symbol at the beginning of
the string, store it in the finite control of the Turing Machine and check for the same
symbol at the end of the string.

Ø If it finds the same symbol then it deletes it and returns to the beginning to
delete the first symbol, otherwise the turing machine reaches a non-halting state to
remain there.

4. Construct a Turing Machine which halts only if the parenthesis in the input
string is balanced. The input alphabet Σ={X, [, ]}

SUBROUTINES

Ø A Turing Machine can perform the function of any of the sub-routines that we
may write as a part of our computer program, including recursive functions.

Ø The transfer of control in the computer terminology may be compared to


simulation of another Turing Machine, which is built to perform the function of that
sub-routine.
Ø The Turing Machine may extend its number of states by connecting an edge
from the state in which the sub-routine is called and the return of control from the
sub-routine is done by connecting an edge from the halting state of the sub-routine
TM to the next state of the TM from which the sub-routine was called.

TWO-WAY INFINITE TAPE

Ø A Turing machine with a two-way infinite tape is denoted by


M=(Q,Σ,Γ,δ,q0,B,F), as in the original model.

Ø As its name implies, the tape is infinite to the left as well as to the right. We
denoted an ID of such a device as for the one-way infinite TM.

Ø We imagine, however, that there is an infinite of blank cells to both the left
and right of the current nonblank portion of the tape.

Theorem L is recognized by a Turing machine with a two-way infinite tape if and


only if it is recognized by a TM with a one-way infinite tape.

Proof:
Ø There are 2 parts to this proof. First, let us prove that a two-way infinite tape
can simulate a one-way infinite tape, which is easy. In order to do this, the 2-way
infinite tape will mark the cell to the left of the starting position of its head; thereby
effectively detaching the tape from the machine.

Ø After this, it will simulate the 1-way Turing Machine. During simulation, if it
reaches the marked area, it is equivalent to the head of the 1-way TM “falling” off
the tape, and the input will be rejected.

Ø In the second part of the proof we shall prove that the 1-way infinite tape TM
can simulate the 2-way infinite tape TM.

Ø In order to do this, we assume that the 1-way infinite tape TM has 2-tracks. In
the second track of the 1-way TM, those symbols that lie to the initial head position
of the 2-way infinite TM are copied in the reverse order.

Ø The 2-way infinite tape TM can be simulated by the 1-way TM in the following
manner:

• Whenever the 2-way tape TM reads to the right of the initial position of the head,
the 1-way TM reads the upper track of the tape in the same direction as that of the
2-way tape TM.
• Whenever the 2-way tape TM reads to the left of the initial position of the head,
the 1-way TM reads the lower track of the tape in the opposite direction as that of
the 2-way tape TM. This is done because the symbols are written in the reverse
direction.

Let us give the exact construction details of the 1-way tape as under:

Let M1 be the 1-way infinite tape having 2-tracks, and M2 be the 2-way infinite tape
Turing Machine.

The 2-way infinite tape Turing Machine with initial position at A0.

The equivalent 1-way infinite tape Turing Machine with 2 tracks

Ø The first cell of M1’s tape holds the symbol φ in the lower track, indicating that
is left most cell. The finite control of M1 tells whether M2 would be scanning a
symbol appearing on the upper or on the lower track of M1.

Ø The input symbol of M1 are symbol with a blank on the lower track and an
input symbol of M2 on the upper track. Such a symbol can be identified with the
corresponding input symbol of M2.

B is identified with [B,B].

We now give a formal construction of M1=(Q1,Σ1,Γ1,δ1,q1B1,F1). The states Q1, of


M1 are all objects of the from [q,U], or [q,D] where q is in Q2, plus the symbol q1.

Note that the second component will indicate whether M1 is working on the
upper (U for up) or lower (D for down) track. The tape symbols in Γ1 are all objects
of the from [X,Y],

where X and Y are in Γ2.


In addition ,Y may- be φ, a symbol not in Γ2.

Σ1 consists of all symbol [a,B], where a is in Σ2. F1 is {[q,U],[q,D],|q is in F2}.

We define δ1 as follows.

1) For each a in Σ2∪{B}, δ1(q1,[a,B])=([q,U][X, ¢],R) if δ2(q2,a)=(q,X,R).

If M2 moves right on its first move, M1 prints ⊄ in the lower track to mark the end
of tape, sets its second component of state to U, and move right.

The first component of M1’s state holds the state of M2. On the upper track ,M1
prints the symbol X that is printed be M2.

2) For each a in Σ2∪{B}, }, δ1(q1,[a,B])=([q,D][X, ¢],R) if δ2(q2,a)=(q,X,L). If M2


Moves left on its first move M2 as in

(a) buts sets the second component of its state to D and moves right. Again, ¢
printed in the lower track to make left end of the tape.

3) For each [X,Y] in Γ1, with Y≠¢, and A=L or R, δ1([q,U],[X,Y])=([p,U],[Z,Y],A) if


δ2(q,X)=(p,Z,A). M1 simulates M2 on the upper track.

4) For each [X,Y] in Γ1, with Y≠¢, , δ1([q,D],[X,Y])=([p,D],[X,Z],A) if δ2(q,Y)=(p,Z, A ).

Here A is L if A is R, and A is R if A is LM1 simulates M2 on the lower track of M1.

The direction of head motion on M1is opposite to that of M2.

δ1([q,U],[X, ¢])= δ1 ([q,D],[X, ¢],)=([p, ¢],[Y, ¢],R) if δ2(q,X)=(p,Y, A).

Here C=U if A=R, and C=D if A=LM1,

simulates a move of M2 on the cell initially scanned by M2. M1 will always move
right in this situation.
PART – A
1. Define Turing Machine.
2. What are the operations of Turing machine?
3. A function is computable if it can be computed by a Turing machine. Justify.
4. Give formal definition of Turing machine.
5. Define Turing machine as acceptors.
6. Define Turing machine as Transducers.
7. Define Computable languages and functions.
8. Construct a TM M for successor function.
9. Construct TM M for zero function.
10. Construct TM M that compute the constant function.
11. Construct TM M that computes the concatenation function.
12. Construct TM M for a language L={anbn,n>=0}
13. Define Storage in finite control.
14. Define Multiple Tracks.
15. Define Checking off symbols.
16. Define Subroutines.
17. Define two way infinite tape.

PART – B
1. Design a TM that manipulates Addition function.
2. Design a TM that manipulates Subtraction function.
3. Design a TM that manipulates Multiplication function.
4. Construct TM that accepts all palindromes over {a,b}
5. Design TM M, that copies the given string W.
6. Design TM M, that accepts all string contains a substring aba
7. Design TM M, that accepts string over {1} containing even no of 1’s

You might also like