the pumping lemma
play

The Pumping Lemma of different strings for Context-Free Languages - PDF document

Review Languages and Grammars Alphabets, strings, languages Regular Languages CS 301 - Lecture 16 Deterministic Finite and Nondeterministic Automata Equivalence of NFA and DFA and Minimizing a DFA Pumping Lemma for


  1. Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages CS 301 - Lecture 16 – Deterministic Finite and Nondeterministic Automata – Equivalence of NFA and DFA and Minimizing a DFA Pumping Lemma for – Regular Expressions – Regular Grammars – Properties of Regular Languages Context Free Grammars – Languages that are not regular and the pumping lemma • Context Free Languages Fall 2008 – Context Free Grammars – Derivations: leftmost, rightmost and derivation trees – Parsing and ambiguity – Simplifications and Normal Forms – Nondeterministic Pushdown Automata – Pushdown Automata and Context Free Grammars – Deterministic Pushdown Automata • Today: – Pumping Lemma for context free grammars Take an infinite context-free language Generates an infinite number The Pumping Lemma of different strings for Context-Free Languages Example: S AB → A aBb → B Sb → B b → 1

  2. string abbabbbb Derivation tree S AB → S A aBb → A B B Sb → In a derivation of a long string, B b → a b b variables are repeated B S A derivation: b A B S AB aBbB abbB ⇒ ⇒ ⇒ a b b B abbSb abbABb abbaBbBb ⇒ ⇒ ⇒ ⇒ abbabbBb abbabbbb b ⇒ ⇒ string abbabbbb Derivation tree S B B Sb ABb ⇒ ⇒ ⇒ aBbBb aBbbb ⇒ ⇒ A B b S a b b B S A B b A B a b b B a b b B b * B ⇒ b B aBbbb repeated ⇒ b 2

  3. Repeated Part Another possible B B derivation from B b S b S * A B B aBbbb ⇒ a B b b A B b S a b b B A B a b b B * B aBbbb * * ⇒ B aBbbb aaBbbbbbb ⇒ ⇒ * * B S abbBb B aBbbb B ⇒ b ⇒ ⇒ b S * A B B aBbbb ⇒ a B b b * 2 2 b S ⇒ abb ( a ) b ( bbb ) S A B a b b B 2 2 * * abb ( a ) b ( bbb ) L ( G ) ∈ 2 2 B ( a ) B ( bbb ) ( a ) B ( bbb ) ⇒ ⇒ 3

  4. * * S abbBb B aBbbb B ⇒ b ⇒ ⇒ S * A B S abbBb ⇒ a b b B * B aBbbb ⇒ b * 0 0 S ⇒ abb ( a ) b ( bbb ) B ⇒ b * 0 0 0 0 S abbBb abbbb abb ( a ) b ( bbb ) ⇒ ⇒ abb ( a ) b ( bbb ) L ( G ) = ∈ * * S * A B S abbBb B aBbbb B ⇒ b ⇒ ⇒ S abbBb ⇒ a B b S b * b A B B aBbbb ⇒ a B b b b S B ⇒ b * A B 3 3 S ⇒ abb ( a ) b ( bbb ) a B b b b S A B a b b B b 3 3 abb ( a ) b ( bbb ) L ( G ) ∈ * 3 3 3 3 S abb ( a ) B ( bbb ) abb ( a ) b ( bbb ) ⇒ ⇒ 4

  5. In General: Consider now an infinite L context-free language * * S abbBb B aBbbb B ⇒ b ⇒ ⇒ L { λ } G Let be the grammar of − * i i S abb ( a ) b ( bbb ) ⇒ Take so that I has no unit-productions G i i no -productions abb ( a ) b ( bbb ) L ( G ) i 0 λ ∈ ≥ = (Number of productions) x p Let Take a string w ∈ L ( G ) (Largest right side of a production) with length | w ≥ | m m = p 1 Let + Example : G S AB We will show: → p 4 3 12 = × = w in the derivation of A aBb → m = p 1 = 13 + a variable of is repeated G B Sb → B b → 5

  6. * v v  v w ⇒ ⇒ ⇒ k ⇒ S w 1 2 ⇒ | v | | v + | f maximum right hand side < + i i 1 of any production v v  v w ⇒ ⇒ ⇒ k ⇒ 1 2 | w | k f < ⋅ S = v 1 m | w | k f p k f ≤ ≤ ⋅ < ⋅ v v  v w ⇒ ⇒ ⇒ k ⇒ v v  v w 1 2 ⇒ ⇒ ⇒ k ⇒ 1 2 k Number of productions > in grammar p k f < ⋅ Some production must be repeated v  a Aa  a Aa  w ⇒ ⇒ ⇒ ⇒ ⇒ ⇒ 1 1 2 3 4 p Number of productions k > S r → f in grammar 1 A r Repeated → 2 B r variable → 2  6

  7. w Derivation tree of string | w ≥ | m w ∈ L ( G ) S Derivation of string w u z    S a Aa a Aa w ⇒ ⇒ ⇒ ⇒ ⇒ ⇒ 1 2 3 4 Last repeated variable A Some variable is repeated y v w = uvxyz A repeated u , v , x , y , z : Strings of terminals x We know: S ∗ ∗ ∗ A vAy S uAz A x Possible ⇒ ⇒ ⇒ derivations: u z This string is also generated: ∗ A S uAz ⇒ * ∗ S uAz uxz ⇒ ⇒ y v ∗ A vAy ⇒ A ∗ 0 0 uv xy z A x ⇒ x 7

  8. We know: We know: ∗ ∗ ∗ ∗ ∗ ∗ S uAz A vAy S uAz A vAy A x A x ⇒ ⇒ ⇒ ⇒ ⇒ ⇒ This string is also generated: This string is also generated: * * * * * ∗ ∗ S uAz uvAyz uvxyz S uAz uvAyz uvvAyyz uvvxyyz ⇒ ⇒ ⇒ ⇒ ⇒ ⇒ ⇒ 1 1 2 2 w uv xy z The original uv xy z = We know: We know: ∗ ∗ ∗ ∗ ∗ ∗ A vAy A vAy S uAz A x S uAz A x ⇒ ⇒ ⇒ ⇒ ⇒ ⇒ This string is also generated: This string is also generated: * * * * S uAz uvAyz uvvAyyz ⇒ ⇒ ⇒ ⇒ * * ∗ * * uvvvAyyyz … ⇒ ⇒ S uAz uvAyz uvvAyyz ⇒ ⇒ ⇒ ⇒ * * uvvv  vAy  yyyz ⇒ ⇒ * * uvvvAyyyz uvvvxyyyz * uvvv  vxy  yyyz ⇒ ⇒ ⇒ 3 3 i i uv xy z uv xy z 8

  9. Therefore, Therefore, any string of the form knowing that uvxyz ∈ L ( G ) i i uv xy z i 0 ≥ i i we also know that uv xy z L ( G ) ∈ is generated by the grammar G L ( G ) = L { } − λ i i uv xy z L ∈ S S u z u z A A y y v v A A x x Observation: Observation: | vxy | m | vy | 1 ≤ ≥ A Since is the last repeated variable Since there are no unit or -productions λ 9

  10. The Pumping Lemma: What’s Next For infinite context-free language L • Read m there exists an integer such that – Linz Chapter 1,2.1, 2.2, 2.3, (skip 2.4), 3, 4, 5, 6.1, 6.2, (skip 6.3), 7.1, 7.2, 7.3, (skip 7.4), and 8.1 – JFLAP Chapter 1, 2.1, (skip 2.2), 3, 4, 5, 6, 7 for any string w L , | w | m ∈ ≥ • Next Lecture Topics – More Pumping Lemma for Context Free Grammars • Quiz 3 in Recitation on Wednesday 11/12 w = uvxyz we can write – Covers Linz 7.1, 7.2, 7.3, (skip 7.4), 8, and JFLAP 5,6,7 – Closed book, but you may bring one sheet of 8.5 x 11 inch paper with any notes you like. | vxy | m and | vy | 1 with lengths – Quiz will take the full hour ≤ ≥ • Homework – No homework today and it must be: – New Homework Available Friday Morning – New Homework Due Next Thursday i i uv xy z L , for all i 0 ∈ ≥ 10

Recommend


More recommend