Module 4 Notes
Module 4 Notes
The goal of this section is to show that every CFL, without ϵ is generated by a
CFG in which all productions are of the form A→BC or A→a, where A, B, and
C are variables, and a is a terminal. This form is called Chomsky Normal Form.
To get there, we need to make a number of preliminary simplications, which are
themselves useful in various ways.
2. Eliminating ϵ-Productions:
Ex : A→B
B-> a | ab
Can be rewritten as, A→a | ab, by eliminating the unit production A→B.
Consider the context free grammar given below and remove unit production
for the same.
S->0A|1B|C
A->0S|00
B->1|A
C->01
Step 1:
S->C is unit production but while removing S->C we have to consider what C
gives so we can add a rule to S.
S->0A|1B|01
Step 2:
B->1|0S|00
S->0A|1B|01
A->0S|00
B->1|0S|00
C->01
1. Eliminate ϵ-productions
2. Eliminate unit productions
3. Eliminate useless symbols
Every nonempty CFL without ϵ has a grammar G in which all productions are in
one of the two simple forms, either:
1. Eliminate ϵ-productions
2. Eliminate unit productions
3. Eliminate useless symbols
4. Put the resulting grammar to CNF
• Arrange all the bodies of length 2 or more consist only variables.
• Break bodies of length 3 or more into a cascade of productions, each
with a body consisting of two variables.
Example :
Convert the following grammar to CNF.
S→ABa
A→aab
B→Ac
Ans:
Ta→a Ta→a
Tb→b Tb→b
Tc→c Tc→c
Where V’={S, A, B}
T’={a, b}
The pumping lemma for CFL’s is used to prove that certain languages are not
context free languages.
The general strategy used to prove that a given language is not context free is as
follows:
Example:
Show that L={ anbncn :n>=1} is not context free.
Ans:
Let L is context free. Let z= anbncn ϵ L
Since |z|=3n>=n, we can split z into uvwxy such that,
|vwx|≤ & vx≠ϵ such that uvi wxi y ∉ L for all i=0,1,2,3…
uvwx y
For i=2, z=uv2wx2y ϵ L
ic, z =an+j+k bn cn
but since an+j+k bn cn ≠ϵ L, our assumption is wrong. Thus, given language is not
Context-free.
u vwx y
For i=2, z=uv2wx2y ϵ L
ic, z = an bn+j+k cn
but since an bn+j+k cn ≠ϵ L, our assumption is wrong. Thus, given language is not
Context-free.
(Note: More examples refer class work)
1. Substitution
2. Union, concatenation and star closure
3. Reverse
4. Homomorphism and inverse homomorphism
1. Intersection
2. Complement
CFLs are under Union, Concatenation and Star-closure:
Union
Let L1 and L2 be two context free languages. Then we can prove that L1 ∪ L2 is
also context free.
Example
Let L1 = { anbn , n > 0}. Corresponding grammar G1 will have P: S1 → aAb|ab
Let L2 = { cmdm , m ≥ 0}. Corresponding grammar G2 will have P: S2 → cBb| ε
Union of L1 and L2, L = L1 ∪ L2 = { anbn } ∪ { cmdm }
The corresponding grammar G will have the additional production S → S1 | S2.
Thus, CFLs are closed under Union.
Concatenation:
If L1 and L2 are context free languages, then L1L2 is also context free.
Example
Union of the languages L1 and L2, L = L1L2 = { anbncmdm }
The corresponding grammar G will have the additional production S → S1 S2
Thus, CFLs are closed under concatenation.