0% found this document useful (0 votes)
239 views

Programming Techniques for Turing Machine construction

The document discusses various programming techniques for constructing Turing machines, emphasizing their equivalence to conventional computers. It covers topics such as storage in finite control, multi-tape tracks, checking off symbols, subroutines, and shifting data on the tape. Specific examples and designs for Turing machines are provided to illustrate the implementation of these techniques for tasks like recognizing languages and determining if a number is prime.

Uploaded by

venkat Mohan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
239 views

Programming Techniques for Turing Machine construction

The document discusses various programming techniques for constructing Turing machines, emphasizing their equivalence to conventional computers. It covers topics such as storage in finite control, multi-tape tracks, checking off symbols, subroutines, and shifting data on the tape. Specific examples and designs for Turing machines are provided to illustrate the implementation of these techniques for tasks like recognizing languages and determining if a number is prime.

Uploaded by

venkat Mohan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

PROGRAMMING TECHNIQUES

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 .
.

If the upper track symbol is B it indicates the symbol


on lower track is not Considered. If the symbol on
upper track is ,it indicates that the symbol on
lower track is considered.
Design a Turing machine for the language {aibj / i>=1 }
Subroutines
A turing machine can simulate any type of subroutine found in programming
languages, including recursive procedures and any of the known parameter
passing mechanisms.
We can design a TM programme to serve as a subroutine, which has a
designated initial state and a designated return state which temporarily has to
move and which will be used to effect a return to the calling routine.
To design a TM to call the subroutine a new set of states are defined which are
used to enter the initial State of the subroutine and return from the return state
of subroutine.
As an example a TM is designed to accept strings with balanced parenthesis.
Design a Turing machine that accepts only the strings with
balanced parenthesis.
To solve this we need to frame an algorithm that can be used match
“(“ for every occurrence of " )" At the end if any parenthesis is
unmatched then it is not balanced.
Procedure:
1)First search for the occurrence of “)”
For this process in the initial state q0 ignore all “(“ until “)” is
seen. The transitions are as follows.
Therefore δ (q0, ( ) = (q0, (, R)
2. On finding “)” replace it by X, change to new state and travel left
for the first occurrence of “(“.
We consider this state as the initial state of subroutine which is
used to find the corresponding “( “ for “ )”.
While travelling back the possible elements it can see is X.
Transitions required are as follows,
δ(q0, ) ) = (q1, X, L)
δ(q1,X ) = (q1, X, L)
3. If “(“ found replace it by X. If not found enter into rejection state. In this
example q1 acts as both initial and return state of the subroutine.
δ(q1, ( ) = (q0, X, R)
δ(q1, B ) = (q3, B, R)
4. Repeat step 1 and step 2 until a B is encountered
δ(q0, X ) = (q0, X, R)
δ(q0, B ) = (q2, B, L)
5. If B is encountered enter into a new state and check if there is no “(“
unbalanced.
δ(q2, X ) = (q2, B, L)
δ(q2, ( ) = (q3, (, R)
δ(q2, B ) = (qA, B, R)
process the string w= (()) ()
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 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)

You might also like