1 / 94

CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University

CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010. Content The Pumping Lemma for CFL Applications of the Pumping Lemma for CFL Midterm Exam 2: Context-Free Languages. Pumping Lemma for CFL’s.

alma
Télécharger la présentation

CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010

  2. ContentThe Pumping Lemma for CFLApplications of the Pumping Lemma for CFLMidterm Exam 2: Context-Free Languages

  3. Pumping Lemma for CFL’s

  4. Comparison to Regular Language Pumping Lemma/Condition

  5. ...... ...... What’s Difference between CFL’s and Regular Languages? In regular languages, a single substring “pumps”

  6. What’s Difference between CFL’s and Regular Languages? In CFL’s, multiple substrings can be “pumped” • 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 Thus, a modified pumping lemma applies.

  7. A language L satisfies the RLpumping 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, wsuch that x = uvwand |uv| ≤ mand |v| ≥ 1and For all i ≥ 0, uviw is in L A language L satisfies theCFL pumping condition if: there exists an integer m > 0such 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 Pumping Conditions for RL and CFL

  8. CFL’s “Pumping Languages” All languages over {a,b} Pumping Lemma All CFL’s satisfy the CFL pumping condition

  9. 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 CFL • Showing L satisfies the pumping condition does not guarantee that L is context-free

  10. Pumping Lemma What does it mean?

  11. 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

  12. v and y can be pumped 1) 2) x = uvwyz3) For all i ≥ 0, uviwyiz is in L • Let x = abcdefg be in L • Then there exist substrings v and y in x such that v and y can be repeated (pumped) and the resulting string is still in L • uviwyiz is in L for all i ≥ 0

  13. For example x =abcdefg 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 …

  14. 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

  15. What the other parts mean • 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 λ, • One of them might be λ, but not both • For all i ≥ 0, uviwyiz is in L

  16. Pumping Lemma Applying it to prove a specific language L is not context-free

  17. 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

  18. 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”

  19. Example Languages • TWOCOPIES = {ww | w is in {a,b}* } • abbabbis in TWOCOPIES but abaabb is not • EQUAL3 = {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} • {ai bj ck | i < j < k}

  20. More Pumping Lemma Applications

  21. 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

  22. Let be a context free grammar. There exists an integer such that can be written with lengths and The Pumping Lemma for CFL

  23. Unrestricted grammarlanguages Non-regular languages Context-Free Languages Regular Languages

  24. Theorem The language is not context free Proof Use the Pumping Lemma for context-free languages

  25. Assume the contrary - that is context-free Since is context-free and infinite we can apply the pumping lemma

  26. Pumping Lemma gives a number such that: Pick any string of with length at least we pick:

  27. and with lengths We can write: Pumping Lemma says: for all

  28. We examine all the possible locations of string in

  29. Case 1: is within the first

  30. Case 1: is within the first

  31. Case 1: is within the first

  32. Case 1: is within the first However, from Pumping Lemma: Contradiction!

  33. Case 2: is in the first is in the first

  34. Case 2: is in the first is in the first

  35. Case 2: is in the first is in the first

  36. Case 2: is in the first is in the first However, from Pumping Lemma: Contradiction!

  37. Case 3: overlaps the first is in the first

  38. Case 3: overlaps the first is in the first

  39. Case 3: overlaps the first is in the first

  40. Case 3: overlaps the first is in the first However, from Pumping Lemma: Contradiction!

  41. Case 4: in the first Overlaps the first Analysis is similar to case 3

  42. or or Other cases: is within Analysis is similar to case 1:

  43. More cases: overlaps or Analysis is similar to cases 2,3,4:

  44. There are no other cases to consider Since , it is impossible for to overlap: neither nor nor

  45. 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

  46. Unrestricted grammarlanguages Non-regular languages Context-Free Languages Regular Languages

  47. Theorem The language is not context free Proof Use the Pumping Lemma for context-free languages

  48. Since is context-free and infinite we can apply the pumping lemma Assume to the contrary that is context-free

  49. Pumping Lemma gurantees a number such that: Pick any string of with length at least we pick:

  50. We can write: with lengths and Pumping Lemma says: for all

More Related