TOC Chapter8
TOC Chapter8
8. TURING MACHINES
CHAPTER - 8
TURING MACHINES
In the previous chapters, we have studied the concepts of regular language and context-free
languages, and their association with finite automata and pushdown automata respectively.
It reveals that regular languages is proper subset of context free language. Therefore
pushdown automata is more powerful than finite automata.
If we compare finite automata and pushdown automata, we see the nature of temporary
storage creates the difference. If we extrapolate this observation, we will discover even more
powerful languages families, if we give the automata more flexible storage.
8.1 TURING MACHINE (TM) - INTRODUCTION
Turing machine is a simple mathematical model of a computer. It was proposed by the
mathematician “Alan Turing” in 1936.
It is similar to a finite automaton but with an unlimited and unrestricted memory. Turing
machine, is a much more accurate model of a general purpose computer.
Turing machine can do everything that a real computer do. If turing machine cannot
solve certain problems, then these problems are beyond the theoretical limits of computation.
8.1.1 Turing Machine Model
a1 a2 a3 b b
R/W head
Infinite tape
Finite divided into
state cells
automaton
The turing machine can be thought of as a finite state automaton connected to a R/W
(Read/Write) head. It has an infinite tape which is divided into number of cells.
Each cell stores one symbol. The input to and the output from the finite state automata
(or) control unit are affected by R/W head which can examine one cell at a time.
In one move, the machine examines the present symbol under the R/W head on the
tape and the present state of an automata to determine.
(i) a new symbol to be written on the tape in the cell under the R/W head.
(ii) a motion of the R/W head along the tape; either the head moves one cell left (L),
or one cell right (R).
(iii) the next state of automaton
(iv) whether to halt or not.
8.1.2 Definition of TM
In one move, depending upon the symbol scanned by the tape head and the state of finite
control, the turing machine:
(i) Changes state
(ii) Prints a symbol on the tape cell scanned, replacing what was written there,
(iii) Moves its head left (or) right one cell.
Turing machine T(M) is defined as
M = (Q, ∑, Γ, δ, q0, B, F) where
Q is the finite set of states
Γ is the finite set of allowable tape symbols.
B is a symbol of Γ, is the blank
∑ a subset of Γ not including B, is the set of input symbols.
δ is the next move function, a kind mapping of function, defined as
δ : Q x Γ → QxΓ x {L, R}
q0∈Q is the initial state
F ⊆ Q is the set of final states.
8.2 REPRESENTATION OF TURING MACHINES
We can describe turing machine with three difference ways. They are:
(i) Instantaneous Descriptions
Turing Machines 8.5
Example 8.1
A snapshot of turing machine is shown in Figure 8.2, obtain the instantaneous
description.
Blank
B a4 a1 a2 a1 a2 a2 a1 a4 a2 B B
R/W head
State
q3
Figure 8.2
Solution :
The present symbol under R/W head is a1. The present state is q3. So a1 is written to the right
of q3. The nonblank symbols to the left of a1 form the string a4a1a2a1a2a2 which is written to
the left of q3. The sequence of nonblank symbols to the right of a1 is a4a2.
8.6 Theory of Computation
The ID is
a 4a 1 a 2a 1a 2a 2 q3 a1 a 4a 2
Left sequence Right sequence
Internal state q0
a b c
d b c
δ(q0,a) denotes the current state of control unit q0 and the current tape symbol being processed
or read is a.
(q1, d, R) denotes the result of new state q1 in control unit, a new tape symbol which
replace the old one, and a move to the right.
Example 8.3
Consider a Turing Machine defined as
Q = {q0,q1}, ∑ = {a, b}, Γ= {a, b, B}
Turing Machines 8.7
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 turing machine is q0.
Step 1 :
TM is in state q0, with the symbol a on the read-write head, the applicable transition is
δ(q0, a) = (q0, b, R). So the read-write head will replace a by b and then move right on the
tape.
q0
a a
q0
b a
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.
q0
b b
Step 3:
The machine halts on encountering first blank in state q1 (final state).
q1
b b
8.8 Theory of Computation
Example 8.4
Consider the TM defined as :
Q = {q0, q1}, ∑ = {a, b}, Γ = {a, b, B}
F = {q1} and
δ(q0,a) = (q1, a, R)
δ(q0,b) = (q1,b,R)
δ(q0,B) = (q1,B,R)
δ(q1,a) = (q0, a, L)
δ(q1,b) = (q0, b, L)
δ(q1, B) = (q0, B, L)
Check the validity for the string abab
Solution :
The control unit is in q0, and read-write head is in a. It reads a but does not change it.
Its next state is q1 and read-write moves right, so that it is now over b (second symbol).
This symbol is also left unchanged. The machine goes back into state q0 and the R/W
head moves left. We are now back to the original state, and the sequence of moves starts
again. The machine is in an infinite loop.
Example 8.5
Write the instantaneous descriptions of Example 8.3.
Solution :
q0
1.
a a
b a
3. q0
b b
ID is bbq0B
q1
4.
b b
Solution :
(a) q1011 |–– xq211 |–– q3xy1
|–– xq5y1 |–– xyq51
As δ(q5,1) is not defined, the input string 011 is rejected, (or) not accepted.
(b) q10011 |–– xq2011 |–– x0q211 |–– xq30y1
Turing Machines 8.11
Start Γ = {0, B}
q1 q2
S = q1
0/B→ F = {q2)
8.12 Theory of Computation
8.3 LANGUAGE ACCEPTANCE OF TM
The language accepted by Turing machine (M) denoted by L(M), is defined as:
* α pα , for some p∈F, α , α ∈ Γ*}
L(M) = {w : w ∈ ∑∗ and q0w |–– 1 2 1 2
When a turing machine processes an input string w, there are three possibilities. They
are:
(i) Turing machine can accept the string by entering accepting state
(ii) It can reject the string by entering non-accepting state.
(iii) It can enter an infinite loop so that it never halts.
Example 8.9
Design a turing machine M to accept the language
L = {0n1n : n≥1} Compute 0011.
Solution :
Initially the tape of M contains 0n1n followed by infinity of blanks. Starting at leftmost 0, we
check it off by replacing it with some other symbol, say x. We then let the read-write head
travel right to find the leftmost ‘1’, which in turn is checked off by replacing it with another
symbol, say y. After that, we go to left again to the leftmost 0, replace it with an x, then move
to the leftmost ‘1’, and replace it with y, and so on.
Travelling back and forth the same way, we match each 0 with a corresponding 1. If
after some time no 0’s and 1’s remain, then the string must be in L.
Working on this, the solution is
Q = {q0, q1, q2, q3, q4}
F = {q4}
∑ = {0, 1}
Γ = {0, 1, x, y, B}
The transitions can be broken into several parts. The set
δ(q0,0) = (q1, x, R)
δ(q1,0) = (q1, 0, R)
δ(q1,y) = (q1, y, R)
δ(q1, 1) = (q2, y, L)
replaces the leftmost 0 with an x, then causes the read-write head to travel right to the first 1,
replacing it with a y. When the y is written, the machine enters a state q2, indicating that an 0
has been successfully paired with a 1.
Turing Machines 8.13
The next set of transitions reverses the direction until an x is encountered, repositions
the read-write head over the left most 0, and returns control to initial state.
δ(q2, y) = (q2, y, L)
δ(q2,0) = (q2, 0, L)
δ(q2,x) = (q0, x, R)
We are now back in the initial state q0, ready to deal with the next 0 and 1.
After one pass through this part of the computation, the machine will have carried
partial computation.
* xq 0.....0y1.....1,
i.e. q000....011.....1 |–– 0
So that single 0 has been matched with a single 1. After 2 passes, we will have completed
the partial computation.
q000....011.....1 * xxq 0...... 0yy1.....1 and so on, indicating that the matching is
|–– 0
carried out properly.
When the input is a string 0 n1n, the rewriting continues this way, stopping only when
there are no more 0’s to be erased, when looking for the leftmost 0, the read-write head
travels with the machine in state q2. When an x is encountered, the direction is reversed, to
get the 0. But now, instead of finding an 0, it will find a 1. To terminate, a final check is made
to see if all 0’s and 1’s is replaced. This is done by
δ(q0, y) = (q3, y, R)
δ(q3, y) = (q3, y, R)
δ(q3, B) = (q4, B,R)
If the input string is not in the language, the computation will halt in non-final state.
If the input string is in the language, it will result in final state.
Computation of 0011.
q00011 |–– xq1011 |–– x0q111 |–– xq 20y1
|–– q2x0y1 |–– xq00y1 |–– xxq 1y1
|–– xxyq11 |–– xxq2yy |–– xq 2xyy
|–– xxq0yy |–– xxyq3y |–– xxyyq 3B
|–– xxyyBq4B.
8.14 Theory of Computation
(i) The fundamental objective in scanning a symbol by R/W head is to ‘know’ what
to do in the future. The machine must remember the past symbols scanned. The
turing machine can remember this by going to the next unique state.
(ii) The number of states must be minimised. This can be achieved by changing the
states only when there is a change in the written symbol or when there is a change
in the movement of R/W head.
Example 8.10
Design a Turing machine to recognise all strings consisting of even number of 1’s.
Solution :
∴ Q = {q0, q1}
∑ = {1, B}
Γ = {1, B}
F = {q1}
and δ is given by
Present Tape
State Symbol (1)
Start→ q Bq2R
1
q2 Bq1R
Example 8.11
Design a Turing machine M to recognise the language.
L = {1n 2n 3n : n≥1}
Solution :
Let us evolve the procedure for processing of input string 112233.
Step 1 :
q1 is the initial state. The R/W head scans the leftmost 1, replaces 1 by b, and moves to
the right. M enters q2.
Step 2 :
On scanning the leftmost 2, the R/W head scan replaces 2 by b, and moves to the right,
M enters q3.
Step 3 :
On scanning the leftmost 3, the R/W head replaces 3 by b, and moves to the right. M
enters q4.
Step 4 :
After scanning the rightmost 3, the R/W heads moves to the left until it finds the leftmost
1. As a result, the leftmost 1, 2 and 3 are replaced by b.
Step 5 :
Step 1–4 are repeated until all 1’s, 2’s and 3’s are replaced by blanks.
q1112233 |–– bq212233 |–– b1q22233
|–– b1bq3233 |–– b1b2q333
|–– b1b2bq43 |–– b1b2q5b3
|–– b1bq52b3 |–– b1q5b2b3
|–– b5q5b2b3 |–– q 6b1b2b3
|–– bq11b2b3 |–– bbq2b2b3
|–– bbbq22b3 |–– bbbbq3b3
|–– bbbbbbq4b |–– bbbbbq7bb
8.16 Theory of Computation
Thus
* q bbbbbb
q1112233|––
M 7
where
Q = {q0,q1} q0=start state q1=final state
∑ = {0}
Γ = {0,B}
F = {q1}
The transition function δ can be defined as
Tape Symbols
States
0 B
q0 (q0, 0, R) (q1, 0, R)
q1 – –
q0 Step 1 :
The input string 000B is in input tape.
Step 2 :
On state q0 and current input symbol 0, the tape head moves right until, it sees the
Blank symbol. δ(q0,0)=(q0,0,R)
0 0 0 B B
q0
0 0 0 B B
q0
0 0 0 B B
q0
8.18 Theory of Computation
on δ(q0,B) = (q1, 0, R)
The first blank symbol is replaced by 0 and the state is changed to q1 which is acceptance
state
M enters the final state [q 1,B] if it reaches a blank symbol without having first
encountered a second copy of the leftmost symbol.
For state [q1, 0] and symbol 0 (or) for state [q1,1] and symbol 1, δ is not defined.
8.6.2 Multiple Tracks
We can imagine the tape of the turing machine is divided into multiple tracks, for any finite
k. The symbols on the tape are considered k-tuples, one component for each track.
B 1 0 1 1 $
B B B 1 0 B ○ ○ ○ ○ ○
1 0 1 0 1 B
↑
Finite Control
Figure 8.4 A three track turing machine
8.6.3 Checking off Symbols
It is a useful trick for visualing how a TM recognizes languages defined by repeated
strings, such as
{ww|w in ∑*}, {wcy|w and y in ∑*, w≠y} (or) {wwR|w in ∑*}
It is also useful when lengths of substrings must be compared. For example:
{aibi : i≥1} (or) {aibjck : i≠j, j≠k}
We introduce an extra track on the tape that holds a Blank B (or) 3 and other track to
hold data as usual.
Example 8.14
Consider a turing machine M = (Q, ∑, Γ, δ, q0, B, F) for the language L = {wcw|w∈{a, b} +}
a) Q = {[q,d] | q = q1 q2.... q9 and d = a, b or B}
b) ∑ = {[B, d] | d = a, b or c}
c) Γ = {[x, d] | x = B or 3 and d = a, b, c or B}
d) q0 = [q1, B]
e) F = {[q9, B]}
f) B = [B, B]
g) δ is defined for d = a or b and e = a or b.
8.20 Theory of Computation
δ is defined as
1) δ([q1, B], [B, d]) = ([q2, d], [3, d], R)
M checks the symbol scanned on the tape, stores the symbol in the finite control
and moves right.
2) δ(q2, d], [B, e]) = ([q2, d], [B, e], R)
M continues to move right over unchecked symbols, looking for e.
3) δ([q2,d], [B, c]} = ([q3, d], [B, c], R)
On finding c, M enters a state with first component q3.
4) δ([q3,d], [3, e]) = ([q3,d], [3, e], R)
M moves right over checked symbols.
5) δ([q3,d], [B, d]) = ([q4,B], [3, d], L)
M encounters an unchecked symbol. If the unchecked symbol matches the symbol
stored in the finite control, M checks it and begins moving left. If the symbols
disagree, M has no next move and so halts without accepting. M also halts if in
state q3 it reaches [B, B] before finding an unchecked symbol.
6) δ([q4,B], [3, d]) = ([q4,B], [3, d], L)
M moves left over checked symbols.
7) δ([q4,B], [B, c]) = ([q5,B], [B, c], L)
M encounters the symbol c.
8) δ([q5,B], [B, d]) = ([q6,B], [B, d], L)
If the symbol immediately to the left of c is unchecked, M proceeds left to find
the rightmost checked symbol.
9) δ([q6,B], [B, d]) = ([q6,B], [B, d], L)
M proceeds left.
10) δ([q6,B], [3, d]) = ([q1,B], [3, d], R)
M encounters a checked symbol and moves right to pick up another symbol for
comparison. The first component of state becomes q1 again.
Turing Machines 8.21
Shifting consecutive non blank locations to the right for a finite number is called shifting
over. Here finite control is used as the temporary storage.
Example 8.15
We construct part of a Turing machine, M = (Q, ∑, Γ, δ, q0, B, F), which may occasionally
have a need to shift nonblank symbols two cells to the right. We suppose that M’s tape does
not contain blanks between nonblanks, so when it reaches a blank it knows to stop the shifting
process. Let Q contain states of the form [q, A1, A 2] for q = q1 or q2, and A1 and A2 in Γ. Let
X be a special symbol not used by M except in the shifting process. M starts the shifting
process in state [q1, B, B]. The relevant portions of the function δ are as follows.
8.22 Theory of Computation
Example 8.16
Design a TM that can compute multiplication with subroutine “copy”.
Solution : (Apr/May 2004)
The design of a TM M to implement the total recursive function “multiplication” is given
below. M starts with 0m10n on its tape and ends with 0mn surrounded by blanks. The general
idea is to place a 1 after 0m10n and then copy the block of n 0’s onto the right end m times,
each time erasing one of the m 0’s. The result is 10n10mn. Finally the prefix 10n1 is erased,
leaving 0mn.
Step 1 :
The initial ID q00m10n to B0m–11q10n1. The corresponding set of rules are:
δ(q0,0) = (q6, B, R)
δ(q6, 0) = (q6, 0, R)
δ(q6, 1) = (q1, 1, R)
Step 2 :
The heart of the algorithm is a subroutine COPY, which begins in an ID 0mlq 10n10i and
eventually enters an ID 0mlq50n10i+n. COPY is defined in Figure 8.5. In state ql, on seeing a 0,
M changes it to a 2 and enters state q2. In state q2, M moves right, to the next blank, deposits
the 0, and starts left in state q3. In state q3, M moves left to a 2. On reaching a 2, state q1 is
entered and the process repeats until the l is encountered, signaling that the copying process
is complete. State q4 is used to convert the 2’s back to 0’s, and the subroutine halts in q5.
Inputs
States
0 1 2 B
q1 (q2, 2, R) (q4, 1, L)
q2 (q2, 0, R) (q2, 1, R) (q3, 0, L)
q3 (q3, 0, L) (q3, 1, L) (q1, 2, R)
q4 (q5, 1, R) (q4, 0, L)
Inputs
States
0 1 2 B
q5 (q7,0,L)
q7 (q8,1,L)
q8 (q9,0,L) (q10,B,R)
q9 (q9,0,L) (q0,B, R
q 10 (q11,B,R)
q11 (q11,B,R) (q12,B,R)
on the left by a single move, is defined as for the original model with the exception that if
δ(q,X) = (p, Y, L), then qXα. |–M– pBYα (in the original model, no move could be made), and if
δ(q, X) = (p, B, R), then qXα |–– pα (in the original, the; B would appear to the left of p).
The initial ID is q0w. While there was a left end to the tape in the original model, there
is no left end of the tape for the Turing machine to “fall off,” so it can proceed left as far as
it wishes. The relation |–M*– , as usual, relates two ID’s if the one on the right can be obtained
from the one on the left by some number of moves.
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.
Turing Machines 8.27
Proof
The proof that a TM with a two-way infinite tape can simulate a TM with a one-way infinite
tape is easy. The former marks the cell to the left of its initial head position and then simulates
the latter. If during the simulation the marked cell is reached, the simulation terminates without
acceptance.
Conversely, let M2 = (Q2, ∑2, δ2, B, F2) be a TM with a two-way infinite tape. We construct
M1, a Turing machine simulating M2 and having a tape that is infinite to the right only. M1 will
have two tracks, one to represent the cells of M2’s tape to the right of, and including, the tape cell
initially scanned, the other to represent, in reverse order, the cells to the left of the initial cell. The
relationship between the tapes of M2 and M1 is shown in below Figure 8.7 with the initial cell of
M2 numbered 0, the cells to the right 1,2,..., and the cells to the left –1, –2,......
The first cell of M1’s tape holds the symbol φ in the lower track, indicating that it is the
leftmost cell. The finite control of M1 tells whether M2 would be scanning a symbol appear-
ing on the upper or on the lower track of M1.
(a)
If M 2 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 moves 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 by 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, M1 records the next state of M 2 and the symbol
printed by M2 as in (1) but sets the second component of its state to D and moves right.
Again, φ is printed in the lower track to mark the 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 is R, and A is R if is L. M1 simulates M 2 on the lowertrack of M1.
The direction of head motion of M1 is opposite to that of M2.
5) δ1([q, U], [X, φ]) = δ1([q, D], [X,φ])
= ([p, C], [Y, φ], R) if δ2(q, X) = (p, Y, A)
Here C=U if A=R, and C=D if A = L. M1 simulates a move of M2 on the cell initially
scanned by M2. M1 next works on the upper or lower track, depending on the direction in
which M2 moves. M1 will always move right in this situation.
8.7.2 Multitape Turing Machines
A multitape Turing machine is shown in the Figure 8.8. It consists of a finite control with k
tape heads and k tapes; each tape is infinite in both directions. On a single move, depending
on the state of the finite control and the symbol scanned by each of the tape heads, the
machine can:
(i) change state;
(ii) print a new symbol on each of the cells scanned by its tape heads;
(iii) move each of its tape heads, independently, one cell to the left or right, or keep it
stationary.
Initially, the input appears on the first tape, and the other tapes are blank. We shall not
define the device more formally, as the formalism is cumbersome and a straightforward
generalization of the notation for single-tape TM’s.
Turing Machines 8.29
Theorem
If a language L is accepted by a multitape Turing machine, it is accepted by a single-tape
Turing machine.
Head 1 X
Tape 1 A1 A2 ... ... Am
Head 2 X
Tape 2 B1 B2 ... ... Bm
Head 3 X
Tape 3 C1 C2 ... ... Cm
Transition table
States a b B X Y
q0 – – (q1, B, R) – –
q1 (q2, X, R) (q4, Y, R) (q10, B, L) (q8, X, R) (q8, X, R)
q2 (q2, a, R) (q2, b, R) (q3, B, L) (q3, X, L) (q3, Y, L)
q3 (q6, X, L) (q7, X, L) – (q8, X, R) (q8, X, R)
q4 (q4, a, R) (q4, b, R) (q5, B, L) (q5, X, L) (q5, Y, L)
q5 (q6, Y, L) (q7, Y, L) – (q8, X, R) (q8, Y, R)
q6 (q6, a, L) (q6, b, L) – (q1, X, R) (q1, X, R)
q7 (q7, a, L) (q7, b, L) – (q1, Y, R) (q1, Y, R)
q8 – – (q9, B, L) (q8, X, R) (q8, Y, R)
q9 – – (q10, B, H) (q9, a, L) (q9, b, L)
Transition diagram
8.32 Theory of Computation
Let w = abb, computation is
q0Babb |–– Bq1abb |–– BXq2bb |–– BXbq2b |–– BXbbq2B
|–– BXbq3b |–– BXq7bX |–– Bq7XbX |–– Byq1bX
|–– BYYq4X |–– BYq5YX |–– BYYq8X |–– BYYXq8B
|–– BYYq9X |–– BYq9Ba |–– Bq9Yba |–– q9Bbba
|–– Bq10bba
For string of equal length, let w = baba, the computation is,
q0Bbaba |–– Bq1baba |–– BYq4aba |–– BYaq4ba
|–– BYabq4a |–– BYabaq4B |–– BYabq5a
|–– BYaq6bY |–– BYq6abY |–– Bq6YabY
|–– BXXq3bY |–– BXq7XXY |–– BXYq1XY
|–– BXYXq8Y |–– BXYXYq8B |–– BXYXq9Y
* Bq9abab |–– q10Babab
|––
2. The addition function f(m, n) = m + n is computable by a Turing Machine.
Solution :
Let the input w = 0m0n
ie. m = 0m and n = 0n
∴ the result w = 0 m 0n = 0 m+n
Let M = (Q, ∑, Γ, δ, q1, B, F) be a TM
with Q = {q1, q2, q3, q4}
∑ = {0} = Input alphabet
Γ = {0, 1, B} = Tape alphabet
F = {q4}
and δ is defined as follows
δ(q1, 0) = {q2, B, R}
i.e. on seeing the 1st zero, it is made as Blank and proceed further.
δ(q2, 0) = {q2, 0, R}
δ(q2, 1) = {q3, 0, R}
δ(q3, 0) = {q3, 0, R}
δ(q3, B) = {q4, B, H} H = Halt
Turing Machines 8.33
B 0 0 0 1 0 0 0 0 B
m n
q1
B B 0 0 0 1 0 0 0 0 B
q2
B B B 0 0 1 0 0 0 0 B
q2
B B B 0 0 1 0 0 0 0 B
q3
B B B 0 0 0 0 0 0 0 B
q3
B B B 0 0 0 0 0 0 0 B
m+n It Halts
Inputs
States
0 1 B
q0 (q1, B, R) (q5, B, R) –
q1 (q1, 0, R) (q2, 1, R) –
q2 (q3, 1, L) (q2, 1, R) (q4, B, L)
q3 (q3, 0, L) (q3, 1, L) (q0, B, R)
q4 (q4, 0, L) (q4, B, L) (q6, 0, R)
q5 (q5, B, R) (q5, B, R) (q6, B, R)
Turing Machines 8.35
Example :
(1) m = 2, n = 1
(2) m = 1, n = 2
Solution :
Yes. The turing machine may be viewed as a computer of functions from positive integers to
positive integers. Each integer will be represented in an unary fashion. That is, the integer
i≥0 is represented by the string 0i. If a function has k arguments i1, i2,.... ik then these integers
are initially placed on the tape separated by 1 has 0i1 1 0i2 1 0i2 1 ......... 1 0 ik
Definition :
If f(i1, i2,..... ik) is defined for all (i1, i2,........ ik) then we say that f is total recursive
function. A function f(i1, i2, ...... ik) computed by a TM is called partial recursive function.
5. Explain how a Turing machine with the multiple tracks of the tape can be used to
determine the given number is prime or not?
8.36 Theory of Computation
Solution : (Apr/May 2004)
Consider a TM with a 3 track tape as shown in figure:
⊄ 1 0 1 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
It takes a binary input greater than 2, written on the first track, and determines whether
it is a prime. The input is surrounded by the symbols and $ on the first track. Thus the
allowable input symbols are [⊄, B, B], [0, B, B], [1, B, B] and [$, B, B]. These symbols can
be identified with ⊄, 0, 1, & $ respectively when viewed as input symbols. The blank symbol
can be identified with [B, B, B].
To test if the input is a prime, the TM first writes the number 2 in binary on the second
track and copies the first track on to the third. Then the second track is subtracted as many
times as possible, from the third track effectively dividing the third track by the second and
leaving the remainder.
If the remainder is zero, the number on the first track is not a prime. If the remainder is
non-zero, the number on the second track is increased by one. If the second track equals the
first, the number on the first track is a prime, because it can not be divided by any number
lying properly between 1 and itself. If the second is less than first, the whole operation is
repeated for the new number on the second track.