Turing Machine
Turing Machine
1.Instantaneous Description:
B a1 a2 b1 a3 b2 a4 b3 b4 B
R/W head
State
q0
The present symbol under R/W head is b2. The present state is q0.
So b2 is written to the right of q0
The Non blank symbols to the left of b2 form the string a1a2b1a3 which is written
to the left of q0.
The sequence of non blank symbols to the right of b2 is a4b3b4.
a1a2b1a3 q0 b2 a4b3b4
Present state Symbol under R/W head
NOTE: For ID simply inset the Current state in the I/P string to the left of the symbol under
R/W head
Example :
Show the situation before and after the move caused by the transition
δ (q0, a) = (q1, d, R)
Solu:
internal state q0
d b c
internal state q1
Consider the TM defined as
(Q = {q0,q1}, ∑= {a.b}, Γ= {a,b,B} δ, q0, B, F= {q1})
and
δ (q0,a) = (q0, b, R)
δ (q0,b) = (q0, b, R)
δ (q0,B) = (q1, B , L)
Process the string W=aa, and the initial state of TM is q0.
Solu:
Step1:
TM is in state q0, with the symbol a on the RW head, the applicable transition is δ (q0,a) = (q0,
b, R).
So the RW head will replace a by b and then move right on the tape
ID
B a a B Bq0aa = q0aa
q0
B b a B
ID
bq0a
q0
Step 2:
The machine is still in state q0. The subsequent a will also be replaced by a b, but b’s will
not be modified
ID
bbq0B
B b b B
q0
Step 3:
The machine halts on encountering first blank in state q1 (Final state)
ID
B b b B bq1b
q1
Let us construct a turing machine for L={0n1n|n>=1}
Working on it in the same way, the machine will reach state q3 and head will point to B as
shown:
q1 xRq2 BRq5
q4 0Lq4 XRq1
q5 yRq5 BRq6
q6
a) q1011 Ⱶ xq211 Ⱶ q3xy1 Ⱶ xq5y1 Ⱶ xyq51
as δ (q5,1) is not defined, the input string 011 is rejected or not
accepted
δ (q1,1) = (q2,b, R)
δ (q2,1) = (q2,1, R)
δ (q2,2) = (q3,b, R)
δ (q3,2) = (q3,2, R)
δ (q3,3) = (q4,b, R) δ (q1,1) = (q2,b, R)
δ (q4,3) = (q5,3, L) δ (q2,1) = (q2,1, R)
δ (q2,2) = (q3,b, R)
δ (q5,b) = (q5,b, L) δ (q3,2) = (q3,2, R)
δ (q5,2) = (q5,2, L) δ (q3,3) = (q4,b, L)
δ (q5,1) = (q6,1, L) δ (q4,b) = (q4,b, L)
δ (q4,2) = (q4,2, L)
δ (q6,1) = (q6,1, L) δ (q4,1) = (q4,1, L)
δ (q6,b) = (q1,b, R) δ (q4,b) = (q4,b,L)
δ (q2,b) = (q2,b, R)
δ (q3,b) = (q3,b, R)
δ (q4,b) = (q4,b, L)
δ (q4,B) = (q7,B, H)
Computation languages and Function
TM Addition
f(m,n) = m+n is computable by TM
m=3, n=4
m+n =7
000 1 0000 here 1 is separator
Let the input w=0m0n
i.e m= 0m n=0n
Therefore w=0m0n = 0m+n
(q1,0) = (q2,B,R)
(q2,0) = (q2,0,R)
(q2,1) = (q2,1,R)
(q2,B) = (q3,0,L)
(q3,1) = (q3,1,L)
(q3,0) = (q3,0, L)
(q3,B) = (q1,B,R)
(q1,1) = (q4,B,H)
Design TM for 1’s complement
(q0,0) = (q0,1,R)
(q0,1) = (q0,0 R)
(q0.B) = (q1,B, H)
(q0,0) = (q1,B,R)
(q1,0) = (q1,0,R)
(q1,1) = (q2,1,R) (q0,1) = (q6,B,R)
(q2,0) = (q3,1,L) (q6,0) = (q6,B,R)
m<n
(q3,1) = (q3,1,L) (q6,1) = (q6,B,R)
(q3,0) = (q3,0,L) (q6,B) = (q5,B,H)
(q3,B) = (q0,B,R)
(q2,1) = (q2,1,R)
(q2,B) = (q4,B,L) When (q0,1) scans it will tell us m
(q4,1) = (q4,B,L) m>n is less than n, then change all 1’s
(q4,0) = (q4,0,L) and 0’s to blank then halt
0 0 0 0 1 0 0 B
B B B 0 1 1 1 B
(q0,0) = (q1,B,R)
(q4,1) = (q4,B,L) (q4,0) = (q4,0,L)
B 0 0 0 1 0 0 B
B B B 0 B B B B
(q1,0) = (q1,0,R) (q1,1) = (q2,1,R)
(q2,0) = (q3,1,L)
B B 0 0 B B B B
B 0 0 0 1 1 0 B (q4,B) = (q5,0,H)
(q3,1) = (q3,1,L) (q3,0) = (q3,0,L)
0 0 1 0 0 0 B
(q3,B) = (q0,B,R)
B B 0 0 1 1 0 B B 0 1 1 0 0
m<n
(q2,1) = (q2,1,R) (q2,0) = (q3,1,L)
B B 1 1 1 B
B B 0 0 1 1 1 B
The same problem can be solved with two state but changing the data stored
in finite control.
Let the state be defined as {qo, qA} X {a, b, B}. Hence the states are [q0, a], [qo
b], [qo, B], [qA, a]. [qA, b] and [qA , B] where [qA, B] is the final state.
At state initial state [q0,B], if it finds ‘a’ or ‘b’, it stores in its state
without replacing and moves right and enters the state q A.
At state [qA,a], if it finds ‘b’, then it skips all ‘b’ and moves right
and remains in this same state.
At state [qA,b], if it finds ‘a’, then it skips all ‘a’ and moves right
and remains in this same state.
At state [qA,a], if it finds ‘B’, then it reaches the accepting state
[qA,B]
At state [qA,b], if it finds ‘B’, then it reaches the accepting state
[qA,B]
The transitions are defined as follows.
1. Let the initial configuration be [qo, B].
2. On seeing a symbol store it in finite control and move right.
δ ([qo, B], a) = ([q0, a], a, R)
δ([qo, B], b) = ([q0, b], b, R)
3. In [qo, a] state move right on seeing b and enter to final state [q A, B] on
seeing B.
δ ([q0, a], b) = ([q0, a], b, R)
δ ([q0, a], B) = ([ qA,, B], B, L)
4. In [q0, b] state move right on seeing a and enter to final state [qA,, B] on
Seeing B.
δ ([q0, b], a) = ([q0, b], a, R)
δ ([q0, b), B) = ([qA, B], B, L)
Multi-tape Tracks
The tape is imagined as divided into cells where input to be processed is
placed. We can further imagine that the tape is divided into k tracks for some
finite number k as shown below.
Φ 1 0 1 1 1 1 $ B B …. ….
B B B B 1 0 1 B B B …. ….
B 1 0 0 1 0 1 B B B …. ….
Finite
Control
The reading head considers k symbols each belonging to
different track in same column and processes it.
There are two special symbols Φ and $ used in the first
track which indicates the boundary of the input.
The other tracks are used to place the intermediate results
and the final result of the processing.
The blank input is identified as all B's in all tracks as [B, B,
B].
The input at the current position of the reading head is [1,
1, 1].
Design a Turing machine to find whether the given number is prime
or not.
Solution
To design'a TM to identify the number as prime or not it is required to find
whether the number has factors other than itself.
1. Let us place the given number on first track in binary form bounded by Φ
and $. For example 47 is represented as Φ101111$.
2. On the second track write 2 in binary form as 10.
3. Copy the number on first track to third track.
4. Perform repeated subtraction of number on third track with number on
second track until the number on third track is either 0 or less than number
on second track.
5. If the number on third track is zero and number on second is not
equal to number on first track then the number on first track is not
prime, otherwise prime.
6. If the number on third track in nonzero and increase number on
second track by one
7. Repeat the steps 4-6 until the number on second is equal to
number on first track.
Shifting Over
A Turing machine can make space on its tape by shifting non blank
symbols by a finite number of cells to the right.
To perform this operation we can use the state with small amount of
storage which can be used to store the symbols and replacing the
current cell by blank and move right.
Read the right symbol and replace it with the symbol stored in the
finite control.
To perform this operation without losing the data it requires storage
capacity to store at least two symbols.
The illustration is given to explain the procedure.
Design the Turing machine which can shift the data on the
tape by, two spaces.
Solution
To design the TM which creates two spaces on the left we need to
use finite control which can store two symbols.
Let the state be defined as [q,A1,A2] where q=q0,q1,qA and A1 and A2
can hold the symbols of ∑ or B.
Let X denote a special symbol to indicate the created blank spaces on
the left of input.
The TM starts with initial state [q0,B,B]
1.In [q0,B,B] state the transition is defined to store the current symbol
encountered in the A1 and replacing the cell content with X.
δ([q0,B,B], A1) = ([q0,B,A1], X, R)
2. In [q0,B,A1] the state the transition is defined to move content of A 1 left and
store the current symbol encountered in A2 and replacing the cell content with X.
δ([q0,B,A1],A2) = ([q0,A1,A2],X,R)
3. In [q0,A1,A2] state the transition is defined move content of A2 to A1
and store the current symbol encountered in A2 and replacing the cell
content with A1.
δ([q0,A1,A2],A3) = ([q0,A2,A3],A1,R)
4. If B is encountered in [q0,A1,A2] state the transition is
defined move content of A2 to A1 and store B in A2 and
replacing the cell content with A1.
δ([q0,A1,A2], B) = ([q0,A2,B], A1, R)
5. If B is encountered in [q0,A1, B] state the transition is
defined replacing the cell content with A1 and change to
new state as the entire string is shifted to right
δ([q0,A1,B], B) = ([q1,B,B], A1, R)
Checking off Symbols
This is one useful technique that can be used to visualise how TM would
recognise the languages. This technique uses an extra track which indicates
the symbol on other track is processed.
The languages which have repeated strings or some Conditions relating to
other part of string can be solved with this procedure. Such languages are
listed below.
a){ww/ w in Σ* }
b){wwR /w in Σ*}
c){aibj / i>=1 }
d){aibjck/ i≠j or j≠ k }
e){wcw/ w in Σ*}
For the languages mentioned above we can use the
tape with two tracks where One track we place the
given input and on the other track we place either B
or .
.