Download as pdf or txt
Download as pdf or txt
You are on page 1of 42

Automata Theory and Computability (18CS54): Module 4

DESCRIPTION OF TURING MACHINES


 In the examples discussed so far, the transition function δ was described as a partial function
(function δ: Q x Г → Q x Г x {L, R} is not defined for all (q, x))by spelling out the current state,
the input symbol, the resulting state, the tape symbol replacing the input symbol and the
movement of R/W head to the left or right. We can call this a formal description of a TM.
 We can also have a higher level of description, called the implementation description. In this
case we describe the movement of the head, the symbol stored etc. in English.
For example, a single instruction like 'move to right till the end of the input string' requires
several moves. A single instruction in the implementation description is equivalent to several
moves of a standard TM.
 At a higher level we can give instructions in English language even without specifying the state or
transition function. This is called a high-level description.

TECHNIQUES FOR TM CONSTRUCTION


The Turing machine, which we have discussed so far, is called the standard or Basic Turing machine. In this
section we give some high-level conceptual tools to make the construction of TMs easier.
1. Turing Machine with stationary head
2. Storage in the state
3. Multiple Track Turing Machine
4. Subroutines

1. Turing Machine with stationary head


 In the definition of a TM we defined δ(q, a) = (p, Y, D) where D = L or R. So the head moves to the
left or right after reading an input symbol.
 Suppose we want to include the option that the head can continue to be in the same cell for some input
symbol. Then we define δ(q, a) = (p, Y, S). This means that the TM, on reading the input symbol a,
changes the state to p and writes Y in the current cell in place of a and R/W head continues to remain in
the same cell.
 Stationary move can be simulated by the standard TM with Two moves.

Gayana M N SJEC Mangaluru Page 27


Automata Theory and Computability (18CS54): Module 4

2. Storage in the state


 Turing machine has a finite control unit which can be used to hold some amount of information. Here, in
this technique, state is used to store a symbol as well. i.e, the TMstoresinformation in pair of elements such
as the current state and the current symbol pointed by the R/W head.
 The transition function δ can be written as follows:
For example, δ([q0, 0], 1) = ([q1, 1], X, R)
This means that if finite control shows the initial state is q0and stores the tapesymbol 0, if it reads the
symbol 1,then the machine goes to next state q1and replaces that 1 by X and moves to right. This helps in
building the transition graph of the language.
 So, the new set of states becomes Q x Γ
 Example: Construct a TM that accepts the language 0 1* + 1 0*

The TM for the language L = {0 1* + 1 0*} is given by


M = ({q0, q1, qf}, {0, 1}, { 0, 1, B}, δ, q0, B, {qf})
Where δ is the transition function given by:
δ ( q0,0) = ( q1,0,R)
δ ( q0,1) = ( q2,1,R)
δ ( q1,1) = ( q1,1,R)
δ ( q2,0) = ( q2,0,R)
δ ( q1, B) = ( qf, B,R)
δ ( q2, B) = ( qf, B,R)

The above problem can be simulated as:

Gayana M N SJEC Mangaluru Page 28


Automata Theory and Computability (18CS54): Module 4

 State [ q0, B] : In the initial state, M is in q0and TM has seen only B in its data portion.
o In state [q0, B] on seeing the first symbol as 0, of the input sting w, M moves right, enters into
state[q1,0]
o In state [q0, B] on seeing the first symbol as 1, of the input sting w, M moves right, enters into
state [q2,1]
 In [q1, 0] ,M moves R/W head right without changing state for input symbol 1.
o In state [q1, 0] if it sees next symbol as B, M enters [qf, B], an accepting state.
 In [q2, 1] ,M moves R/W head right without changing state for input symbol 0.
o In state [q2, 1] if it sees next symbol asB, M enters [qf, B], an accepting state.

3. Multiple Track Turing Machine

 In a multiple track TM, a single tape is assumed to be divided into several tracks. Now the tape alphabet
is required to consist of k-tuples of tape symbols, k being the number of tracks. Hence the only
difference between the standard TM and the TM with multiple tracks is the set of tape symbols.
 In the case of the standard Turing machine, tape symbols are elements of Γ; in the case of TM with
multiple track, it is Γk. The moves are defined in a similar way.
 Example:

Here, input symbols are tape symbols defined in 3 tracks. ie:Γ3;for example input is [c, a, b]
δ ( q, c, a, b) = (qnext, Z, X, Y, R)

The resultant tape structure is as shown below:

Gayana M N SJEC Mangaluru Page 29


Automata Theory and Computability (18CS54): Module 4

4. Subroutines
 Subroutines are used in computer languages, when some task has to be done repeatedly. We can
implement this facility for TMs as well.
 TM subroutine is a set of states that perform some pre-defined task. The TM subroutine has a start state
and a state without any moves. This state which has no moves serves as the return state and passes the
control to the state which calls the subroutine.
 First ,TM program for the subroutine is written.
 This TM program will have an initial state and a 'return state.
 After reaching the return state, there is a temporary halt.
 For using a subroutine, new states are introduced.
 When there is a need for calling the subroutine, moves are effected to enter the initial state for the
subroutine (when the return state of the subroutine is reached) and to return to the main program of
TM.

 Example: Design a TM which can multiply two positive integers


The input (m, n) where m, n being given, the positive integers are represented by 0m10n. M starts with
0m10nin its tape. At the end of the computation 0mn(mn in unary representation) surrounded by B's is
obtained as the output.
General Procedure:
1. 0m10n1is placed on the tape (output will be written after the rightmost1).
2. The Leftmost 0is erased (by replacing with B).
3. A block of n0’sis copied onto the right end.
4. Steps2 and 3 are repeated m times and 10m10mnis obtained on thetape.
5. The prefix10m1of10m10mniserased.(replacingall0’sand1’sbyB)leaving the product mn as the output.

For example multiply 2 and 4: Initially tape consists of these two unary numbers, as follows:

Gayana M N SJEC Mangaluru Page 30


Automata Theory and Computability (18CS54): Module 4

1 is used as delimiter for separating two numbers.


At the end of step 4,tape structure is as follows:
B B B B B B B 1 0 0 0 0 1 0 0 0 0 0 0 0 0 B B

After multiplication, the result stored in tape is as follows:

B B B B B B B B B B B B B 0 0 0 0 0 0 0 0 B B

Here we have to copy n number of 0’s from the second group to the last group by replacing n number of
B’s by n number of 0’s
In start state q0replace leftmost 0 by B, change state to q1and move the r/w head towards right till we get
1.
δ (q0, 0) = ( q1, B, R)
Now we should copy n 0’s from the second group to last group.
δ (q1, 0) = ( q1, 0,R)
δ (q1, 1) = ( q2, 1,R)
Now the R/w is pointing to the first 0 of second group. (COPY subroutine in start state q2 ) In q2replace 0
by X and change the state to q3,move r/w head towards right till we get B.
δ (q2, 0) = ( q3, X,R)
δ (q3, 0) = ( q3, 0,R)
δ (q3, 1) = ( q3, 1,R)
In q3 when it reads B, replace B by 0 and change state to q4 and move left.( at this point one symbol is
copied from second group to last group)
δ (q3, B) = ( q4, 0, L)
In q4 we should search for rightmost X.
While moving left in q4, replace 0 by 0 , 1 by 1 till we get X.
δ (q4, 0) = ( q4, 0,L)
δ (q4, 1) = ( q4, 1,L)
When it reads X, change state to q2 , replace X by X and move right.
δ (q4, X) = ( q2, X, R)
When n number of B’s in last group are, replaced by n number of 0’s in second group. In state q2
machine reads 1 then change state to q5 and move left.
δ (q2, 1) = ( q5, 1, L)
In state q5 while moving left, replace all X’s in second group by 0’s, till we get 1.
δ (q5, X) = ( q5, 0, L)
When machine reads 1 in q5 replace 1 by 1 and move right, change state to q6
δ (q5, 1) = ( q6, 1, R)
In state q6 machine reads 0,(pointing to the first symbol of 2nd group) move left and change state to q7.

Gayana M N SJEC Mangaluru Page 31


Automata Theory and Computability (18CS54): Module 4

δ (q6, 0) = ( q7, 1, L)
In q7 machine reads 1; the delimiter of 1st and 2nd group. Change state to q8 and move left, so that
machine enters the 1st group.
δ (q7, 1) = ( q8, 1, L)
In q8 when it reads 0 change state to q9 and move left.
δ (q8, 0) = ( q9, 0, L)
In q9 on any number 0s move the r/w towards left.
δ (q9, 0) = ( q9, 0, L)
In q9 if we encounter B, change the state to q0 and move right.
δ (q9, B) = ( q0, B, R)
But, in state q8, instead of 0’s if machine encounters B’s it means that n0’s have been copied from the
second group to last group m number of times.

Now replace the delimiter1 which precede and follow the second group and second group 0’s by B’s.
δ (q8, B) = ( q10, B,R)
δ (q10,1) = ( q11, B,R)
δ (q11,0) = ( q11, B,R)
δ (q11,1) = ( q12, B,R)
B B B B B B B B B B B B B 0 0 0 0 0 0 0 0 B B

The TM which can multiply two positive integers is given by


M = ({q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12}, {0, 1}, {0, 1,X, B}, δ, q0, B, { q12 })
where δ is the transition function, given by:
δ (q0, 0) = ( q1, B,R)
δ (q1, 0) = ( q1, 0,R)
δ (q1, 1) = ( q2, 1,R)
δ (q2, 0) = ( q3, X, R)
δ (q3, 0) = ( q3, 0,R)
δ (q3, 1) = ( q3, 1,R)
δ (q3, B) = ( q4,0,L)
δ (q4, 0) = ( q4, 0,L)
δ (q4, 1) = ( q4, 1,L)
δ (q4, X) = ( q2, X, R)
δ (q6, 0) = ( q7, 1, L)
δ (q5, X) = ( q5, 0,L)

Gayana M N SJEC Mangaluru Page 32


Automata Theory and Computability (18CS54): Module 4

δ (q5, 1) = ( q6, 1,R)


δ (q2, 1) = ( q5, 1,L)
δ (q7, 1) = ( q8, 1,L)
δ (q8, 0) = ( q9, 0,L)
δ (q9, 0) = ( q9, 0,L)
δ (q9, B) = ( q0, B, R)
δ (q8, B) = ( q10, B,R)
δ (q10,1) = ( q11, B,R)
δ (q11,0) = ( q11, B,R)
δ (q11,1) = ( q12, B,R)
Transition diagram:

VARIANTS OF TURING MACHINES


The standard TM has a single tape. δ (q, a) is either a single triple (p, Y, D), where D = R or L, or is not
defined. If we modify the structure of Turing machine, we get variants of TM such as:
 Multi-tape TM : TM with more than one tape.
 Non-deterministic TM : TM with choice for transitions.

Gayana M N SJEC Mangaluru Page 33


Automata Theory and Computability (18CS54): Module 4

Multi-Tape TM:
 A Turing machine M with more than one tape is said to be Multi-Tape TM.
 The following figure represents a multi-tape TM.

 A multi-tape TM has a finite set Q of states, an initial state q0, a subset F of Q, called the set of final
states, a set P of tape symbols, a new symbol B, not in P called the blank symbol.
 There are k tapes, each divided into cells. The first tape holds the input string w.
 Initially all the other tapes hold the blank symbol.(B)
 Initially the head of the first tape (input tape) is at the left end of the input w.
 All the other heads can be placed at any cell initially.
 δ is a partial transition function from Q x Гk into Q x Гk x {L, R, S}k. where k is the number of tapes.
 Multi-tape TM is more powerful than single tape TM , but the language accepted by Multi- tape TM is
recursively enumerable language. That means language accepted by Multi- tape TM is also accepted
by basic or standard TM. Thus, Multi-tape TM and standard TM are equivalent.
 A move depends on the current state and k tape symbols under k tape heads. In a typical move,
 The Multi-tape TM M enters a new state.
 On each tape, a new symbol is written in the cell under the head.
 Each tape head moves to the left or right or remains stationary. The heads move independently:
some move to the left, some to the right and the remaining heads do not move.

 The initial ID has the initial state q0, the input string w in the first tape (input tape), empty strings of
B's in the remaining k – 1 tapes.
 An accepting ID has a final state, some strings in each of the k tapes.
Example: δ(q, a, b, c) = (p, X, Y, Z, L, R, R)

Theorem-1:
Every language accepted by a multi-tape TM is acceptable by some single-tape TM (that is, the
standard TM).
OR
Show that language accepted by Multi-tape TM is recursively enumerable language.

Gayana M N SJEC Mangaluru Page 34


Automata Theory and Computability (18CS54): Module 4

Proof:
 Suppose, a language L is accepted by a k-tape (Multi tape) TM M.
 We simulate M with a single- tape TM M1with 2k tracks.
 Let us consider the implementation description by considering k = 2 .We will prove this theorem by
simulating the working of 2-tape TM (M) with the working of single tape 4-track TM (M1).
 Assume that the second, fourth, ..., (2k) th tracks hold the contents of the k-tapes. The first, third, ...
,(2k - 1)th tracks hold the R/W head marker (a symbol say X) to indicate the position of the respective
tape head.
 Let’s consider a Multi-tape TM, M with 2-tapes (i.e, k=2) as shown below:

Let a2 and b5 be the current symbols to be scanned.


Let us consider a single move of above multi tape TM:
δ (q, a2, b5) = (qnext , 0, 1, L, R)
 The snapshot of Multi-Tape TM after the above step is shown below:

 Initially, the contents of tapes 1 and 2 of M are stored in the second and fourth tracks of M1.The R/w
head markers (X) of the first and third tracks are at the cells containing the first symbol.

Gayana M N SJEC Mangaluru Page 35


Automata Theory and Computability (18CS54): Module 4

 To simulate the above move of Multi-tape TM M in a single tape TM M1, the single tape TM M1 has
to visit the two R/w head markers and store the scanned symbols in its finite control. Also, the finite
control of single tape TM M1 has the information about the states of multi-tape TM M and its moves.
The initial snapshot of simulating M using M1 is shown below

 Now M1 revisits each of the head markers to perform the following operations:
 It changes the tape symbol in the corresponding track of single tape TM M1 based on the
information regarding the move of 2-tape TM M corresponding to the state (of M) and the tape
symbol in the corresponding tape M.
 It moves the head markers to the left or right.
 M1 changes the state of M in its control
The snapshot of simulating M using M1 for a single move is shown below

 At the end of this, M1 is ready to implement its next move based on the revised positions of its head
markers and the changed state available in its control.
 Single tape TM M1 accepts a string w only when it reaches a state that is recorded as a final state of M
in its control at the end of the processing of w.
 Hence the proof.

Gayana M N SJEC Mangaluru Page 36


Automata Theory and Computability (18CS54): Module 4

Non-Deterministic TM:
 A non-deterministic Turing machine is a type of TM in which the set of rules denote more than one
specific action for a particular input at specific state.
 A Non-deterministic TM can be formally defined as M: which is a 7-tuple, namely (Q, ∑ ,Г, δ, q0. B, F)
where
 Q is a finite nonempty set of states.
 Г is a finite nonempty set of tape symbols,
 B is the blank symbol.
 ∑ is a non empty subset of Г , called the set of input symbols and B≠∑
 δ is the transition function mapping (q, x) onto (q’, y, D) where D denotes the direction of movement
of R/W head, D = L or R
It is a partial function Q X Г into the power set of Q X Г X {L, R}
 q0ϵ Q is the initial state
 F is the subset of Q, is the set of final states.
 If qϵQ and xϵГ and δ(q,x)={(q1,y1,D1), (q2,y2,D2),…….., (qn,yn,Dn)} then the NTM can chose any one
of the actions defined by (qi,yi,Di), for i=1,2,….,n
 Example:

Here, δ(q0,a) is associated with two actions, i.e{(q1,X,R), (q2,Y,L)}

 When δ(q,x)={ (qi,yi,Di) | i=1,2,….,n} then NTM chooses any one of the n triples totally.
 The non-deterministic TM in fact is no more powerful than the deterministic TM. Any language
accepted by non-deterministic TM can be accepted by deterministic TM.

Theorem – 2
If M is a nondeterministic TM, there is a deterministic TM M 1 such that T(M)=T(M1).
Proof:
 We construct M1 as a multi-tape TM.
 Each symbol in the input string leads to a change in ID.
 M1 should be able to reach all IDs and stop when an ID containing a final state is reached.
 So, the first tape is used to store IDs of M as a sequence and also the state of M. These IDs are
separated by the symbol * (included as a tape symbol).
 The current ID is known by marking an x along with the ID-separator * (The symbol * marked with x

Gayana M N SJEC Mangaluru Page 37


Automata Theory and Computability (18CS54): Module 4

is a new tape symbol.).


 All IDs to the left of the current one have been explored already and so can be ignored subsequently.
 The following Figure illustrates the deterministic TM M1.

 To process the current ID, M1 performs the following steps.


1. M1 examines the state and the scanned symbol of the current ID. Using the knowledge of moves of
M stored in the finite control of M1, M1 checks whether the state in the current ID is an accepting
state of M. In this case M1 accepts and stops simulating M.
2. If the state q say in the current ID xqay is not an accepting state of M1 and δ(q,a) has k triples, M1
copies the ID xqay in the second tape and makes k copies of this ID at the end of the sequence of
IDs in tape 2.
3. M1 modifies these k IDs in tape 2 according to the k choices given by δ(q,a).
4. M1 returns to the marked current ID, erases the mark x and marks the next ID-separator * with x.
Then M1 goes back to step1.
 M1 stops when an accepting state of M is reached in step 1.
 Now M1 accepts an input string w only when it is able to find that M has entered an accepting state,
after a finite number of moves.
 Let m be the maximum number of choices that M has for various (q,a)’s.
 For each initial ID of M, there are at most m IDs that M can reach after one move, at most m2 IDs
that M can reach after two moves and so on.
 So, corresponding to n moves of M, there are at most 1+m+m2+…+mn moves of M1
 Therefore, the number of IDs to be explored by M1 is at most nmn.
 We assume that M1 explores these IDs. These IDs have a tree structure having an initial ID as its root.
 Using Breadth first search, if M reaches an accepting ID after n moves, then M1 has to search at most
nmn IDs before reaching an accepting ID.
 So, if M accepts w, then M1 also accepts w. Hence T(M)=T(M1).

Gayana M N SJEC Mangaluru Page 38


Automata Theory and Computability (18CS54): Module 4

THE MODEL OF LINEAR BOUNDED AUTOMATON (LBA)


 A linear bounded automaton is a non-deterministic Turing machine which has a single tape whose
length is not infinite but bounded by a linear function of the length of the input string. A linear
function is used to restrict (to bound) the length of the tape. The set of context-sensitive languages is
accepted by this model.
 LBA is formally defined as M: which is a 9-tuple, namely (Q, ∑ , Г, δ, q0. B, , $, F) where
o Q is a finite nonempty set of states.
o Г is a finite nonempty set of tape symbols,
o B is the blank symbol.
o ∑ is a nonempty set of input symbols with two special symbols ,$ and is a subset of Г and B ≠∑
o δ is the transition function mapping (q, x) onto (q’, y, D) where D denotes the direction of
movement of R/W head: D=L or R
i.e, it is a partial function, Q X Г mapped into Q X Г X { L, R }
o q0ϵ Q is the initial state
o F is the subset of Q, the set of final states
o is called the left end marker, which is entered in the leftmost cell of the input tape and
prevents the R/W head from getting off the left end of the tape.
o $ is called the right end marker, which is entered in the rightmost cell of the input tape and
prevents the R/W head from getting off the right end of the tape.
Note: Both the end markers should not appear on any other cell within the input tape. R/W head
should not print any other symbol over both the end markers.
 Whenever a string needs to be processed in LBA, the string should always be enclosed within the end
markers.
 The model of LBA can be represented by the following block diagram:

Gayana M N SJEC Mangaluru Page 39


Automata Theory and Computability (18CS54): Module 4

 There are two tapes: one is called the input tape, and the other, working tape.
 On the input tape, the head never prints and never moves to the left.
 On the working tape, the head can modify the contents in any way, without any restriction.
 The set of strings accepted by nondeterministic LBA is the set of strings generated by the context-
sensitive grammars, excluding the null strings.
i.e, if L is a context sensitive language, then L is accepted by a linear bounded automaton and vice
versa.

*********************************************************************************

Gayana M N SJEC Mangaluru Page 40

You might also like