ATC MODULE-5_TM_
ATC MODULE-5_TM_
1.1.1 Membership
"Given a language L and a string w, is w in L?'
This question can be answered for every context-free language and for every context-free language
L there exists a PDA M such that M accepts L. But existence of a PDA that accepts L does not
guarantee the existence of a procedure that decides it.
It turns out that there are two alternative approaches to solving this problem, both
of which work:
Proof: The proof is by a construction that begins by converting G to Greibach normal form.
Now consider again the algorithm cfgtoPDAtopdown, which builds, from any context-free
grammar G, a PDA M that, on input w, simulates G deriving w, starting from
S. M= ({p,q},Σ,V,Δ, p,{q}), where Δ contains:
1. The start-up transition ((p,ε,ε),(q,S)), which pushes the start symbol on to the stack
and goes to state q.
2. For each rule X→s1s 2...sn, in R, the transition ((q,ε,X),(q,s1s2...sn)), which replaces X
by s1s2...sn. If n=0 (i.e., the right-hand side of the rule is ε), then the transition ( (q, ε,
X), (q, ε)).
3. For each character c ∈ Σ. the transition ((q, c, c), (q,ε)), which compares an
expected character from the stack against the next input character.
If G contains the rule X→cs 2...sn, (where c ∈Σ and s2 through sn, are elements of V-Σ), it is
not necessary to push c onto the stack, only to pop it with a rule from step 3.
Instead, we collapse the push and the pop into a single transition. So we create a transition that
can be taken only if the next input character is c. In that case, the string s2 through sn is pushed
onto the stack.
Since terminal symbols are no longer pushed onto the stack. We no longer need the transitions
created in step3 of the original algorithm.
So, M=({p,q},Σ,V,Δ,p,{q}), where Δ contains:
cfgtoPDAnoeps(G:context-freegrammar)=
1. Convert G to Greibach normal form, producing G'.
2. From G' build the PDA M described above.
Proof:
a) Since each computation of M must consume one character of w at each step and M
will halt when it runs out of input, each computation must halt within n steps.
b) M may split into at most b branches at each step in a computation. The number of
steps in a computation is less than or equal to n. So the total number of computations
must be less than or equal to bn.
c) Since the maximum number of computations is bn and the maximum length of each
is n, the maximum number of steps that can be executed before all computations of M
halt is nbn.
So a second way to answer the question, "Given a context-free language L and a
string w, is w in L?" is to execute the following algorithm:
decideCFLusingPDA(L:CFL,w:string)=
1. If L is specified as a PDA, use PDAtoCFG, to construct a grammar G such that
L(G)=L(M).
2. If L is specified as a grammar G, simply use G.
3. If w=ε then if SG is nullable then accept, otherwise reject.
4.If w≠ε then:
1.1. From G, construct G' such that L(G')=L(G)-{ε} and G' is in Greibach
normal form.
1.2. From G' construct, using cfgtoPDAnoeps, a PDA M' such that
L(M')=L(G') and M' has no ε-transitions.
4.3 We have proved previously that, all paths of M' are guaranteed to halt
within a finite
number of steps. So run M' on w, Accept if M' accepts and reject otherwise.
Proof :
decideCFLempty( G: context-free grammar) =
1. Let G' =removeunproductive(G).
2. If S is not present in G' then return True else return False.
decideCFLinfinite(G:context-freegrammar)=
1. Lexicographically enumerate all strings in Σ* of length greater than bn and
less than or equal to bn+1+bn.
2. If, for any such string w, decideCFL(L,w) returns True then return True. L is infinite.
3. If, for all such strings w, decideCFL(L,w) returns False then return False. L is
not infinite.
The Turing machine provides an ideal theoretical model of a computer. Turing machines are
useful in several ways:
• Turing machines are also used for determining the undecidability of certain languages and
• As an automaton, the Turing machine is the most general model, It accepts type-0
languages.
• It can also be used for computing functions. It turns out to be a mathematical model
of partial recursive functions.
• Measuring the space and time complexity of problems.
In Turing machine one scans the cells one at a time and usually performs one of
the three simple operations, namely:
In one move, the machine examines the present symbol under the R/W head on the
tape and the present state of an automaton 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 the automaton, and Whether to halt or not.
Definition:
Turing machine M is a 7-tuple, namely (Q, Σ, 𝚪, ✿, q0, b, F), where
1. Q is a finite nonempty set of states.
2. 𝚪 is a finite nonempty set of tape symbols,
3. b∈ 𝚪 is the blank.
4. Σ is a nonempty set of input symbols and is a subset o f 𝚪 and b∉Σ.
5. ✿ 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 according as the movement is to the left
or right.
6. q0∈Q is the initial state, and
7. F⊆Q is the set of final states.
Notes:
(1) The acceptability of a string is decided by the reachability from the initial state to
some final state.
(2) ✿ may not be defined for some elements of QX 𝚪.
Notes: (1) For constructing the ID, we simply insert the current state in the
input string to the left of the symbol under the R/W head.
(2) We observe that the blank symbol may occur as part of the left or right
substring.
2.2.1 REPRESENTATION BY TRANSITION TABLE
We give the definition of ✿ in the form of a table called the transition table
If 𝛿 (q, a)=(𝛾,𝛼,𝛽). We write 𝛼𝛽𝛾 under the 𝛼-column and in the q-row. So if
we get 𝛼𝛽𝛾 in the table, it means that 𝛼 is written in the current cell, 𝛽
gives the movement of the head (L or R) and 𝛾 denotes the new state into
which the Turing machine enters.
EXAMPLE:
Consider, for example, a Turing machine with five states q1,...,q5 where q1
is the initial state and q5 is the (only) final state. The tape symbols are
0,1and b. The transition table given below describes ✿ :
(b)
q1OOll |- xq2011 |- xOq211 |- xq30y1 |- q4 XOyl |- xq1Oy1 |-xxq2y1 |- xxyq21 |- xxq3yy
|- xq3xyy|- xxq5yy |- x.xyyq5b· |- xxyyq5b |- xxyybq6
M halts. As q6 is an accepting state, the input string 0011is accepted by M.
(c)
M halts. As q2 is not an accepting state,001 is not accepted by M.
2. The number of states must be minimized. 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 the R/W head.
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) as (q',y,S).This means that the TM, on reading the input
symbol a, changes the state to q' and writes y in the current cell in place of a and continues to
remain in the same cell. In this model (q, a) =(q', y, D) where D = L, R or S.
4. SUBROUTINES
First a TM program for the subroutine is written. This 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, return to the
main program of TM.
2.6 VARIANTS OF TURING MACHINES
The Turing machine we have introduced has a single tape. δ(q, a) is either a single triple
(p, y, D), where D = R or L, or is not defined.
i. Multitape TM:
A multitape TM has : a finite set Q of states. an initial state q o. 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.
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 function from Q x Гk into Q x Гk x {L, R, S} k.
A move depends on the current state and k tape symbols under k tape heads. In a
typical move:
(i) M enters a new state.
(ii) On each tape, a new symbol is written in the cell under the head.
(iii) 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 remain- ing
heads do not move.
The initial ID has the initial state qo, 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.
Initially the contents of tapes 1 and 2 of M are stored in the second and fourth tracks of MI'
The head markers of the first and third tracks are at the cells containing the first symbol.
To simulate a move of M, the 2k-track TM M1 has to visit the two head markers and store the
scanned symbols in its control. Keeping track of the head markers visited and those to be visited
is achieved by keeping a count and storing it in the finite control of M1' Note that the finite control
of M1 has also the information about the states of M and its moves. After visiting both head
markers. M1 knows the tape symbols being scanned by the two heads of M.
M1 accepts a string w if the new state of M, as recorded in its control at the end of the processing
of w, is a final state of M.
All the symbols have the same meaning as in the basic model of Turing machines with the
difference that the input alphabet L contains two special symbols ¢ and $. ¢ 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. $ 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. Both the end markers should not appear on any other cell within the input tape,
and the R/W head should not print any other symbol over both the end markers.
Let us consider the input string w with |w|= n-2. The input string w can be recognized by an
LBA if it can also be recognized by a Turing machine using no more than kn cells of input
tape, where k is a constant specified in the description of LBA. The value of k does not
depend on the input string but is purely a property of the machine. Whenever we process
any string in LBA, we shall assume that the input string is enclosed within the end markers
¢ and $.
The above model of LBA can be represented by the block diagram of Fig. 9.11.
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.
QUESTIONS