grammars and the pumping lemma
play

Grammars and the Pumping Lemma 10/2/19 (Using slides adapted from - PowerPoint PPT Presentation

Grammars and the Pumping Lemma 10/2/19 (Using slides adapted from the book) Administrivia No class Friday A Little English An article can be the word a or the : A a A the A noun can be the word dog , cat or rat : N dog N


  1. Grammars and the Pumping Lemma 10/2/19 (Using slides adapted from the book)

  2. Administrivia • No class Friday

  3. A Little English • An article can be the word a or the : A → a A → the • A noun can be the word dog , cat or rat : N → dog N → cat N → rat A noun phrase is an article followed by a noun: P → AN

  4. A Little English • An verb can be the word loves, hates or eats : V → loves V → hates V → eats A sentence can be a noun phrase, followed by a verb, followed by another noun phrase: S → PVP

  5. The Little English Grammar • Taken all together, a grammar G 1 for a small subset of unpunctuated English: S → PVP A → a P → AN A → the V → loves N → dog V → hates N → cat V → eats N → rat • Each production says how to modify strings by substitution • x → y says, substring x may be replaced by y

  6. S → PVP A → a P → AN A → the V → loves N → dog V → hates N → cat V → eats N → rat • Often there is more than one place in a string where a production could be applied • For example, P loves P : – P loves P ⇒ AN loves P – P loves P ⇒ P loves AN • The derivations on the previous slide chose the leftmost substitution at every step, but that is not a requirement • The language defined by a grammar is the set of lowercase strings that have at least one derivation from the start symbol S

  7. S → PVP P → AN V → loves | hates | eats A → a | the N → dog | cat | rat • Often, a grammar contains more than one production with the same left- hand side • Those productions can be written in a compressed form • The grammar is not changed by this • This example still has ten productions

  8. Complaint letter generator https://www.pakin.org/complaint/

  9. 4-Tuple Definition • A grammar G is a 4-tuple G = ( V , Σ , S , P ), where: – V is an alphabet, the nonterminal alphabet – Σ is another alphabet, the terminal alphabet , disjoint from V – S ∈ V is the start symbol – P is a finite set of productions, each of the form x → y , where x and y are strings over Σ ∪ V and x ≠ ε

  10. Chapter 11: Non-regular languages 11.1 The Language { a n b n } • • 11.2 The Languages { xx R } • 11.3 Pumping • 11.4 Pumping-Lemma Proofs • 11.5 Strategies • 11.6 Pumping And Finite Languages

  11. Lemma 11.3: The Pumping Lemma for Regular Languages For all regular languages L there exists some integer k such that for all xyz ∈ L with | y | ≥ k , there exist uvw = y with | v | >0, such that for all i ≥ 0, xuv i wz ∈ L. • Let M = ( Q , Σ , δ , q 0 , F ) be any DFA with L ( M ) = L • Choose k = | Q| • Consider any x , y , and z with xyz ∈ L and | y | ≥ k • Let r be a state that repeats during the y part of xyz – We know such a state exists because we have | y | ≥ |Q|… In state r here And again here x y z

  12. Lemma 11.3: The Pumping Lemma for Regular Languages For all regular languages L there exists some integer k such that for all xyz ∈ L with | y | ≥ k , there exist uvw = y with | v | >0, such that for all i ≥ 0, xuv i wz ∈ L. • Let M = ( Q , Σ , δ , q 0 , F ) be any DFA with L ( M ) = L • Choose k = | Q| • Consider any x , y , and z with xyz ∈ L and | y | ≥ k • Let r be a state that repeats during the y part of xyz • Choose uvw = y so that δ *( q 0 , xu ) = δ *( q 0 , xuv ) = r • Now v is pumpable: for all i ≥ 0, δ *( q 0 , xuv i ) = r… In state r here And again here x u v w z

  13. Lemma 11.3: The Pumping Lemma for Regular Languages For all regular languages L there exists some integer k such that for all xyz ∈ L with | y | ≥ k , there exist uvw = y with | v | >0, such that for all i ≥ 0, xuv i wz ∈ L. • Let M = ( Q , Σ , δ , q 0 , F ) be any DFA with L ( M ) = L • Choose k = | Q| • Consider any x , y , and z with xyz ∈ L and | y | ≥ k • Let r be a state that repeats during the y part of xyz • Choose uvw = y so that δ *( q 0 , xu ) = δ *( q 0 , xuv ) = r • Now v is pumpable: for all i ≥ 0, δ *( q 0 , xuv i ) = r • Then for all i ≥ 0, δ *( q 0 , xuv i wz ) = δ *( q 0 , xuvwz ) = δ *( q 0 , xyz ) ∈ F • Therefore, for all i ≥ 0, xuv i wz ∈ L … x u v v v w z

  14. Pumping Lemma Structure For all regular languages L there exists some integer k such that for all xyz ∈ L with | y | ≥ k , there exist uvw = y with | v | >0, such that for all i ≥ 0, xuv i wz ∈ L. • Notice the alternating "for all" and "there exist" clauses: 1. ∀ L … 2. ∃ k … 3. ∀ xyz … 4. ∃ uvw … 5. ∀ i … Our proof showed how to construct the ∃ parts • • But that isn't part of the lemma: it's a black box • The lemma says only that k and uvw exist

  15. Pumping-Lemma Proofs • The pumping lemma is very useful for proving that languages are not regular • For example, { a n b n }…

  16. { a n b n } Is Not Regular 1. Proof is by contradiction using the pumping lemma for regular languages. Assume that L = { a n b n } is regular, so the pumping lemma holds for L . Let k be as given by the pumping lemma. 2. Choose x , y, and z as follows: x = a k y = b k z = ε Now xyz = a k b k ∈ L and | y | ≥ k as required. 3 Let u , v , and w be as given by the pumping lemma, so that uvw = y , | v | > 0, and for all i ≥ 0, xuv i wz ∈ L. 4 Choose i = 2. Since v contains at least one b and nothing but b s, uv 2 w has more b s than uvw . So xuv 2 wz has more b s than a s, and so xuv 2 wz ∉ L . 5 By contradiction, L = { a n b n } is not regular.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend