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

grammars and the pumping lemma
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Grammars and the Pumping Lemma

10/2/19 (Using slides adapted from the book)

slide-2
SLIDE 2

Administrivia

  • No class Friday
slide-3
SLIDE 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

slide-4
SLIDE 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

slide-5
SLIDE 5

The Little English Grammar

  • Taken all together, a grammar G1 for a small subset of

unpunctuated English:

  • Each production says how to modify strings by

substitution

  • x → y says, substring x may be replaced by y

S → PVP A → a P → AN A → the V → loves N → dog V → hates N → cat V → eats N → rat

slide-6
SLIDE 6
  • 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

S → PVP A → a P → AN A → the V → loves N → dog V → hates N → cat V → eats N → rat

slide-7
SLIDE 7
  • 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

S → PVP P → AN V → loves | hates | eats A → a | the N → dog | cat | rat

slide-8
SLIDE 8

Complaint letter generator

https://www.pakin.org/complaint/

slide-9
SLIDE 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 ≠ ε

slide-10
SLIDE 10

Chapter 11: Non-regular languages

  • 11.1 The Language {anbn}
  • 11.2 The Languages {xxR}
  • 11.3 Pumping
  • 11.4 Pumping-Lemma Proofs
  • 11.5 Strategies
  • 11.6 Pumping And Finite Languages
slide-11
SLIDE 11

Lemma 11.3: The Pumping Lemma for Regular Languages

  • Let M = (Q, Σ, δ, q0, 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|…

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, xuviwz ∈ L. x y z

In state r here

And again here

slide-12
SLIDE 12

Lemma 11.3: The Pumping Lemma for Regular Languages

  • Let M = (Q, Σ, δ, q0, 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 δ*(q0,xu) = δ*(q0,xuv) = r
  • Now v is pumpable: for all i ≥ 0, δ*(q0,xuvi) = r…

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, xuviwz ∈ L. x z

In state r here

And again here

u v w

slide-13
SLIDE 13

Lemma 11.3: The Pumping Lemma for Regular Languages

  • Let M = (Q, Σ, δ, q0, 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 δ*(q0,xu) = δ*(q0,xuv) = r
  • Now v is pumpable: for all i ≥ 0, δ*(q0,xuvi) = r
  • Then for all i ≥ 0, δ*(q0,xuviwz) = δ*(q0,xuvwz) = δ*(q0,xyz) ∈ F
  • Therefore, for all i ≥ 0, xuviwz ∈ L

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, xuviwz ∈ L. x z u v w v v …

slide-14
SLIDE 14

Pumping Lemma Structure

  • 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

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, xuviwz ∈ L.

slide-15
SLIDE 15

Pumping-Lemma Proofs

  • The pumping lemma is very useful for proving that

languages are not regular

  • For example, {anbn}…
slide-16
SLIDE 16

{anbn} Is Not Regular

  • 1. Proof is by contradiction using the pumping lemma for regular
  • languages. Assume that L = {anbn} 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 = ak y = bk z = ε Now xyz = akbk ∈ 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, xuviwz ∈ L. 4 Choose i = 2. Since v contains at least one b and nothing but bs, uv2w has more bs than uvw. So xuv2wz has more bs than as, and so xuv2wz ∉ L. 5 By contradiction, L = {anbn} is not regular.