Atc Notes
Atc Notes
Theorem: The regular languages are a proper subset of the context-free languages.
Proof: We first show that every regular language is context-free. We then show that there
exists at least one context-free language that is not regular.
There cannot be more CFLs than CFGs. So there are at most a countably infinite number of
context-free languages. There is not a one-to-one relationship between CFLs and CFGs, since
there are an infinite number of grammars that generate any given language. But we know that,
every regular language is context free and there is a countably infinite number of regular
languages.
Theorem: The length of the yield of any tree T with height h and
branching factor b is <= bh.
Proof:
If h is 1, then a single rule applies. So the longest yield is of length less than or equal to b.
Assume the claim is true for h=n. We show that it is true for h=n+1.
Consider any tree with h=n+1. It consists of a root, and some number of subtrees, each of height
<=n. By the induction hypothesis, the length of the yield of each of those subtrees is <= bn . So the
length of the yield must be <=b.(bn )=bn+1 =bh .
The tree rooted at [1] has height at most n+1.Thus its yield, vxy, has length less than or equal
to bn+1 ,which is k. Further, vy≠Ɛ .Since if vy were Ɛ then there would be a smaller parse tree for w
and we choose T so that h at wasn't so.
Finally, v and y can be pumped: uxz must be in L because rule2 could have been used immediately
at[1]. And, for any q≥1, uvqxyqz must be in L because rule1 could have been used q times before
finally using rule2.
Call the part before the c the leftside and the part after the c the right side. We consider all the
cases for where v and y could fall and show that in none of them are all the condition so f the theorem met:
• If either v or y overlaps region 3, set q to 0. The resulting string will no longer contain a c and so is
not in WcW.
• If both v and y occur before region 3 or they both occur after region 3, then set q to 2. One side will
be longer than the other and so the resulting string is not in WcW.
• If either v or y overlaps region1 ,then set q to 2. In order to make the right side match. Something
would have to be pumped into region 4. But any v,y pair that did that would violate the requirement
that lvxyl ≤ k.
• If either v or y overlaps region2, then set q to 2. In order to make the right side match, something
would have to be pumped into region 5. But any v,y pair that did that would violate the requirement
that lvxyl ≤ k.
• There is no way to divide w into uvxyz such that all the conditions of the Pumping Theorem
are met . So WcW is not context-free.
• If L1 and L2 are context free languages then there exists a context-free grammar G 1 = (V1 ,Σ1 , R1 ,S1 )
and G2 =(V2 ,Σ2 ,R2 ,S2 ) such that L1 =L(G1 ) and L2 =L(G2 ).
• We will build a new grammar G such that L(G)=L(G1 )UL(G2 ). G will contain all the rules of both
G1 and G2 .
• We add to G a new start symbol S and two new rules. S→S 1 and S→S2 . The two new rules allow G
to generate a string iff at least one of G1 or G2 generates it.
So, G = ( V1 U V2 U {S}, Σ1 U Σ2 , R1 U R2 U {S→ S1 ,S→S2 }, S )
• Every rule in G is of the form X→BC or X→a, where X, B, and C are elements of (V-Σ) and a ϵΣ
• So construct, from G, a new grammar G1 , Such that L(G1 )= LR .
• G1 = (VG, ΣG, R', SG) , Where R' is constructed as follows:
For every rule in G of the form X→BC, add to R' the rule X→CB
For every rule in G of the form X→ a then add to R' the rule X→ a
• If L2 is regular then there exists a DFSM M2 = (K 2 ,Σ,𝛿,S2 ,A2 ) that accepts it.
• We construct a new PDA, M3 that accepts L1 ∩ L2 . M3 will work by simulating the parallel
execution of M1 and M2 .
•For each transition ((q1 , a, 𝛃) ,(p1 , 𝛄)) in 𝚫1 and each transition ((q2 , a ) ,p2 ) in 𝛿, add 𝚫3 the
transition: (((q1 ,q2 ),a,𝛃) ,((p1 ,p2 ), 𝛄)).
•For each transition ((q1 ,ℇ,𝛃) ,(p1 , 𝛄)) in 𝚫1 and each state q2 in k2 , add to 𝚫3 the transition:
(((q1 ,q2 ),ℇ,𝛃) ,((p1 ,p2 ), 𝛄)).
For example, the PDA accepts L, but it is nondeterministic because the transition to state3 (where the
a's will be popped) can compete with both of the other transitions from state1.
With an end-of-string marker, we can build the deterministic PDA, which can only take the transition
to state3, the a-popping state. When it sees the $:
NOTE: Adding the end-of-string marker cannot convert a language that was not
context-free into one that is.
•There exist languages that are in the outer donut because they are inherently ambiguous. Two
examples are:
{aibjck |i,j,k ≥ 0 and ((i≠j)or(j≠k))}
{aibjck |i,j,k ≥ 0 and ((i=j) or (j=k))}
Regular Language is Deterministic Context-Free
Theorem: Every regular language is deterministic context-free.
Proof: The proof is by construction. {$} is regular. So, if L is regular then so is L$ (since the
regular languages are closed under concatenation).So there is a DFSM M that accepts it. Using the
construction to show that every regular language is context-free Construct, from M a PDA P that
accepts L$. P will be deterministic.
buildunambiggrammar(M:deterministicPDA)=
1. Let G=buildgrammar(convertPDAtodetnormalform(M)).
2. Let G' be the result of substituting ε for $ in each rule in which $ occurs.
3. Return G'.
NOTE: The algorithm convertPDAtodetnormalform, is described in the theorem that proves the
deterministic context-free languages are closed under complement.
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:
● Use a grammar: Using facts about every derivation that is produced by a grammar in
Chomsky normal form, we can construct an algorithm that explores a finite number of
derivation paths and finds one that derives a particular string w iff such a path exists.
● Use a PDA : While not all PDAs halt, it is possible, for any context-free language L, to
craft a PDA M that is guaranteed to halt on all inputs and that accepts all strings in L and
rejects all strings that are not in L.
1. If L is specified as a PDA, use PDA to CFG, to construct a grammar G such that L(G) =L (M).
4. If w ≠ ε then:
4.1. From G, construct G' such that L (G') = L(G)-{ε} and G' is in Chomsky normal form.
4.2. If G derives to, it does so in (2 • |w| - 1) steps. Try all derivations in G of that number
Elimination of ε-Transitions
Theorem: Given any context-free grammar G=(V,Σ,R,S), there exists a PDA M
such that L(M)=L(G)-{ε} and M contains no transitions of the form
((q1,ε,α),(q2,𝜷)). In other words, every transition reads exactly one input
character.
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→s1 s2 ...sn , in R, the transition ((q,ε,X),(q,s1 s2 ...sn )), which replaces X by
s1 s2 ...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→cs2 ...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:
1. The start-up transitions: For each rule S→cs2 ...sn the transition ((p,c,ε),(q,s2 ...sn )).
2. For each rule X→cs2 ...sn (where c∈Σ and s2 through sn , are elements of V-Σ), the
transition ((q,c,X),(q,s2 ...sn )).
cfgtoPDAnoeps(G:context-freegrammar)=
1. Convert G to Greibach normal form, producing G'.
2. From G' build the PDA M described above.
TURING MACHINE
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.
Turing assumed that while computing, a person writes symbols on a one-dimensional paper (instead
of a two dimensional paper as is usually done) which can be viewed as a tape divided into cells. In
Turing machine one scans the cells one at a time and usually performs one of the three simple
operations, namely:
(i) Writing a new symbol in the cell being currently scanned,
(ii) Moving to the cell left of the present cell, and
(iii) Moving to the cell right of the present cell.
REPRESENTATION OF TURINGMACHINES
We can describe a Turing machine employing
(i) Instantaneous descriptions using move-relations.
(ii) Transition table, and
(iii) Transition diagram (Transition graph).
REPRESENTATION BY INSTANTANEOUS DESCRIPTIONS
Definition: An ID of a Turing machine M is a string 𝛼𝛽𝛾, where 𝛽 is the present state of M, the
entire input string is split as 𝛼𝛾, the first symbol of 𝛾 is the current symbol a under the R/W head and
𝛾 has all the subsequent symbols of the input string, and the string 𝛼 is the substring of the input
string formed by all the symbols to the left of a.
EXAMPLE: A snapshot of Turing machine is shown in below Fig. Obtain the instantaneous
description.
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 𝛅:
As (q5,1) is not defined, M halts; so the input string 011 is not accepted
The Turing machine M has the initial state q 0. The initial ID for M is q0 0m10n . On seeing 0,the
following moves take place
q1 is the initial state of COPY. The following moves take place for M1 :
After exhausting 0s, q1 encounters 1. M1 moves to state q4 . All 2's are converted back to 0's
and M1 halts in q5 . The TM M picks up the computation by starting from q5 The q0 and q6 are the
states of M. Additional states are created to check whether reach 0 in 0m gives rise to 0m at the end of
the rightmost 1 in the input string. Once this is over, M erases 10n 1 and finds 0mn in the input tape.
M can be defined by M=({q0 ,q1 ,....q12 }{0,1},{0,,2,b},𝛅,q0 ,b,{q12 }) where 𝛅 is defined by table given
below:
ADDITIONAL PROBLEMS
1. Design a Turing machine to obtain complement of a binary number.
IDEA OF CONSTRUCTION:
1) If symbol is 0 change it to 1, move read write head to RIGHT
2) If symbol is 1 change it to 0, move read write head to RIGHT
3) Symbol is b (blank) don’t change, move read write head to RIGHT, and HALT.
The construction is made by defining moves in the following manner:
(a) ql is the initial state. On scanning 1, no change in state and write 0 and move head to RIGHT.
(c) If M is in state q1 and scans blank, it enters q2 and writes b move to right.
(d) q2 is the only accepting state.
Symbolically, M=({ql,q2 },{1,0,b},{1,0,b},𝛅,ql,b,{q2 }) Where 𝛅 is defined by:
2. Design a TM that converts binary number into its 2’s complement representation.
IDEA OF CONSTRUCTION:
Read input from left to right until right end blank is scanned.
Begin scan from right to left keep symbols as it is until 1 found on input file.
If 1 found on input file, move head to left one cell without changing input.
Now until left end blank is scanned, change all 1’s to 0 and 0’s to 1.
We require the following moves:
(a) Let q1 be initial state, until blank is scanned, move head to RIGHT without changing
anything. On scanning blank, move head to RIGHT change state to q2 without changing the
content of input.
(b) If q2 is the state, until 1 is scanned, move head to LEFT without changing anything. On
reading 1, change state to q3 , move head to LEFT without changing input.
(c) If q3 is the state, until blank is scanned, move head to LEFT, if symbol is 0 change to 1,
otherwise if symbol is 1 change to 0.On finding blank change state to q4 , move head to LEFT
without Changing input.
(d) q4 is the only accepting state.
We construct a TM M as follows:
M = (Q, Σ,, 𝛅, q0 ,b, F)
Q = {q1 ,q2 ,q3 ,q4 }
F = {q4 }
Σ = {0,1}
𝚪= {0,1,b}
PRACTICE PROBLEMS
1. Design a Turing machine to replace all a’s with X and all b’s with Y.
2. Design a Turing machine to accept an bm n>m.
3. Design a Turing machine to accept an bn n<m.
4. Design a Turing machine to accept (0+1)*00(0+1)* .
5. Design a Turing machine to increment a given input.
6. Design a Turing machine to decrement a given input.
7. Design a Turing machine to subtract two unary numbers.
8. Design a Turing machine to multiply two unary numbers.
9. Design a Turing machine to accept a string 0’s followed by a 1.
10. Design a Turing machine to verify if the given binary number is an even number or not.
11. Design a Turing machine to shift the given input by one cell to left.
12. Design a Turing machine to shift the given input to the right by one cell .
13. Design a Turing machine to rotate a given input by one cell.
14. Design a Turing machine to erase the tape.
15. Design a Turing machine to accept an bn cn .
16. Design a Turing machine to accept any string of a’s & b’s with equal number of a’s & b’s.
17. Design a Turing machine to accept an b2n.
18. Design a Turing machine to accept an bk cm : where n=m+k.
19. Design a Turing machine to accept an bk cm : where m=n+k.
20. Design a Turing machine to accept an bk cm : where k=m+n.