920 likes | 1.06k Views
CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2005. Content The Pumping Lemma for CFL Applications of the Pumping Lemma for CFL Midterm Exam 2: Context-Free Languages. Pumping Lemma for CFL’s.
E N D
CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2005
ContentThe Pumping Lemma for CFLApplications of the Pumping Lemma for CFLMidterm Exam 2: Context-Free Languages
What’s Difference between CFL’s and Regular Languages? • In regular languages, a single substring “pumps” • Consider the language of even length strings over {a,b} • We can identify a single substring which can be pumped • In CFL’s, multiple substrings can “pump” • Consider the language {anbn | 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 • This results in a modified pumping condition
A language L satisfies the regular language pumping condition if: there exists an integer m > 0 such that for all strings x in L of length at least m there exist strings u, v, w such that x = uvw and |uv| ≤ m and |v| ≥ 1 and For all i ≥ 0, uviw is in L A language L satisfies the CFL pumping condition if: there exists an integer m > 0 such that for all strings x in L of length at least n there exist strings u, v, w, y, z such that x = uvwyz and |vwy| ≤ m and |vy| ≥ 1 and For all i ≥ 0, uviwyiz is in L Modified Pumping Condition
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 L is not a CFL • Show L does not satisfy the CFL pumping condition • We cannot use the pumping lemma to prove a language is context-free • 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 > 0 such that • for all strings x in L of length at least m • there exist strings u, v, w, y, z such that • x = uvwyz and • |vwy| ≤ m and • |vy| ≥ 1 and • For all i ≥ 0, uviwyiz is in L
v and y can be pumped 1) x in L2) x = uvwyz3) For all i ≥ 0, uviwyiz is in L • Let x = abcdefg be in L • Then there exist 2 substrings v and y in x such that v and y can be repeated (pumped) in place any number of times and the resulting string is still in L • uviwyiz is in L for all i ≥ 0 • For example • v = cd and y = f • uv0wy0z = uwz =abeg is in L • uv1wy1z = uvwyz = abcdefgis in L • uv2wy2z = uvvwyyz = abcdcdeffgis in L • uv3wy3z = uvvvwyyyz = 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 x in L of length at least m • x must be in L and have sufficient length • there exist strings u, v, w, y, z such that • x = uvwyz and • |vwy| ≤ m and • v and y are contained within m characters of x • Note: these are NOT necessarily the first m characters of x • |vy| ≥ 1 and • v and y cannot both be l, • One of them might be l, but not both • For all i ≥ 0, uviwyiz is in L
How we use the Pumping Lemma • We choose a specific language L • For example, {anbncn | n > 0} • We have shown that L does not satisfy the pumping condition and • concluded 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 x in L of length at least m there exist strings u, v, w, y, z such that x = uvwyz and |vwy| ≤ m and |vy| ≥ 1 and For all i ≥ 0, uviwyiz 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 x in L of length at least m such that for all strings u, v, w, y, z such that x = uvwyz and |vwy| ≤ m and |vy| ≥ 1 There exists a i ≥ 0 such that uviwyiz is not in L Showing L “does not pump”
Two Rules of Thumb • Try to use blocks of at least m characters in x • For TWOCOPIES, choose x = ambmambm rather than ambamb • Guarantees v and y cannot be in more than 2 blocks of x • Try i=0 or i=2 • i=0 • This reduces number of occurrences of v and y • i=2 • This increases number of occurrences of v and y
Summary • We use the Pumping Lemma to prove a language is not a CFL • Note, does not work for all non CFL languages • Can be strengthened to Ogden’s Lemma • Choosing a good string x is first key step • Choosing a good i is second key step • Typically have several cases for v, w, y
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
Pumping Lemma gives a magic number such that: Pick any string of with length at least we pick:
We can write: with lengths and Pumping Lemma says: for all
We examine all the possible locations of string in There is only one case to consider