Programming Techniques for Turing Machine construction
Programming Techniques for Turing Machine construction
FOR
TURING MACHINE CONSTRUCTION
Programming Techniques in TM
A turing machine is exactly as powerful as a conventional computer.
1.Storage in finite control
2.Multiple Tracks
3.Shift over
4.Checking off symbol
5.Subroutine
Storage in Finite Control
A Turing machine has a finite number of states in its CPU.
However, the number of states is not always small.
For example, all real computers have registers but there are
only a fixed number of them, and each register can only
hold one of a fixed (and finite) number of bits.
Similarly, we define a state as a pair which stores the
details of control and the other stores the symbol.
To account for this modification we can define the Turing
machine as M (Q, ∑, Γ, δ, [q0,B], B, F) where Q is of the form
[q, a] where q is a state and a Ꞓ ∑, the transitions are defined
as ([Q, X ∑] Γ) ([Q X ∑ ], Γ, {R L}).
For example
The transition δ ([q, a], b) = ([p, b], c, R) indicates that the
control is in state q and a is stored in finite control.
On the input symbol b it moves to p state and changes the
symbol in finite control to b, changes the cell content as c and
moves one cell right.
Design a Turing machine that accepts strings of the ab* or ba *.
Solu:
To design this system, it is required to define the transitions Such
that on seeing a it should move to a different state on b and in that
state be in same state until B is encountered.
On B, move to final state. Similarly, if the first symbol is b move to
different state and be in that state on a and finally move to final
state on B.
A sample diagram is shown in Fig
ab* or ba *
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], [q , a]. [q , b] and [q , B] where [q , 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 qA.
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
[q ,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 [qA, 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.
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 .
.
2. In [q0,B,A1] the state the transition is defined to move content of A1 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)