940 likes | 1.12k Views
CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 10 Mälardalen University 2011. Content The Pumping Lemma for CFL Applications of the Pumping Lemma for CFL Midterm Exam 2: Context-Free Languages. The Pumping Lemma for CFL’s.
E N D
CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 10 Mälardalen University 2011
ContentThe Pumping Lemma for CFLApplications of the Pumping Lemma for CFLMidterm Exam 2: Context-Free Languages
...... ...... What is the difference between Context Free Languages and Regular Languages? In regular languages, a single substring “pumps”
What is the difference between Context Free Languages and Regular Languages? In CFL’s, multiple substrings can be “pumped” • Consider the language {an bn | n > 0} • No single substring can be pumped and allow us to stay in the language • However, there do exist pairs of substrings which can be pumped resulting in strings which stay in the language Thus, a modified pumping lemma applies.
stringsof terminals String Last repeated variable repeated
A language L satisfies the RLpumping condition if: there exists an integer m > 0 such that for all strings w in L of length at least m there exist strings x, y, zsuch that w = xyzand |xy| ≤ mand |y| ≥ 1and For all i ≥ 0, uvizis in L A language L satisfies theCFLpumping condition if: there exists an integer m > 0such that for all strings w in L of length at least m there exist strings u, v, x, y, z such that w = uvxyzand |vxy| ≤ mand |vy| ≥ 1and For all i ≥ 0, uvixyiz is in L Pumping Conditions for RL and CFL
CFL’s “Pumping Languages” All languages over {a,b} Pumping Lemma All CFL’s satisfy the CFL pumping condition
Implications CFL’s “Pumping Languages” All languages over {a,b} • We can use the pumping lemma to prove a language Lis not a CFL • Show that L does not satisfy the CFL pumping condition • We cannot use the pumping lemma to prove a language is CFL • Showing L satisfies the pumping condition does not guarantee that L is context-free
Pumping Lemma What does it mean?
Pumping Condition • A language L satisfies the CFL pumping condition if: • there exists an integer m > 0such that • for all strings w in L of length at least m • there exist strings u, v, x, y, zsuch that • w = uvxyzand • |vxy| ≤ m and • |vy| ≥ 1 and Then for all i ≥ 0, uviwyizis in L
v and y can be pumped 1) w in L2) w = uvxyz3) For all i ≥ 0, uvixyiz is in L • Let w = abcdefgbe in L • Then there exist substrings v and y in w such that v and y can be repeated (pumped) and the resulting string is still in L • uvixyiz is in L for all i ≥ 0
For example w =abcdefg v = cdand y = f uv0xy0z = uxz =abegis in L uv1xy1z = uvxyz = abcdefgis in L uv2xy2z = uvvxyyz = abcdcdeffgis in L uv3xy3z = uvvvxyyyz = abcdcdcdefffg is in L …
What the other parts mean A language L satisfies the CFL pumping condition if: • there exists an integer m > 0 such that • for all strings w in L of length at least m • w must be in L and have sufficient length
What the other parts mean • There exist strings u, v, x, y, z such that • w = uvxyz and • |vxy| ≤ m and • v and y are contained within m characters of w • Note: these are NOT necessarily the first m characters of w • |vy| ≥ 1 and • v and y cannot both be 1, • One of them might be 1, but not both • For all i ≥ 0, uvixyiz is in L
Pumping Lemma Applying CFL pumping lemma to prove that a specific language L is not context-free
How we use the Pumping Lemma • We choose a specific language L For example {aj bj cj | j > 0} • We show that L does not satisfy the pumping condition • We conclude that L is not context-free
A language L satisfies the CFL pumping condition if: there exists an integer m > 0 such that for all strings w in L of length at least m there exist strings u, v, x, y, z such that w = uvxyz and |vxy| ≤ m and |vy| ≥ 1 and For all i ≥ 0, uvixyiz is in L A language L does not satisfy the CFL pumping condition if: for all integers m of sufficient size there exists a string w in L of length at least m such that for all strings u, v, x, y, z where w = uvxyz and |vxy| ≤ m and |vy| ≥ 1 There exists a i ≥ 0 such that uvixyiz is not in L Showing that L “does not pump”
Example Languages • L = {the set of strings over {a, b, c} such that the number of a’s equals the number of b’s equals the number of c’s} • L ={aibjck | i < j < k}
For infinite context-free language there exists an integer such that for any string we can write with lengths and The Pumping Lemma for CFL
Let be a context free grammar. There exists an integer such that can be written with lengths and The Pumping Lemma for CFL
Unrestricted grammarlanguages Non-regular languages Context-Free Languages Regular Languages
Theorem The language is not context free Proof Use the Pumping Lemma for context-free languages
Assume the contrary - that is context-free Since is context-free and infinite we can apply the pumping lemma
Pumping Lemma gives a number such that: Pick any string of with length at least we pick:
and with lengths We can write: Pumping Lemma says: for all
We examine all the possible locations of string in
Case 1: is within the first
Case 1: is within the first
Case 1: is within the first
Case 1: is within the first However, from Pumping Lemma: Contradiction!
Case 2: is in the first is in the first
Case 2: is in the first is in the first
Case 2: is in the first is in the first
Case 2: is in the first is in the first However, from Pumping Lemma: Contradiction!
Case 3: overlaps the first is in the first
Case 3: overlaps the first is in the first
Case 3: overlaps the first is in the first
Case 3: overlaps the first is in the first However, from Pumping Lemma: Contradiction!
Case 4: in the first Overlaps the first Analysis is similar to case 3
or or Other cases: is within Analysis is similar to case 1:
More cases: overlaps or Analysis is similar to cases 2,3,4:
There are no other cases to consider. Since , it is impossible for to overlap: neither nor nor
is not context-free In all cases we obtained a contradiction. Therefore: The original assumption that is context-free must be wrong Conclusion: END OF PROOF
Unrestricted grammarlanguages Non-regular languages Context-Free Languages Regular Languages
Theorem The language is not context free Proof Use the Pumping Lemma for context-free languages
Since is context-free and infinite we can apply the pumping lemma Assume to the contrary that is context-free