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

the pumping lemma
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

1

CS 301 - Lecture 16 Pumping Lemma for Context Free Grammars

Fall 2008

Review

  • Languages and Grammars

– Alphabets, strings, languages

  • Regular Languages

– Deterministic Finite and Nondeterministic Automata – Equivalence of NFA and DFA and Minimizing a DFA – Regular Expressions – Regular Grammars – Properties of Regular Languages – Languages that are not regular and the pumping lemma

  • Context Free Languages

– 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

The Pumping Lemma for Context-Free Languages

Take an infinite context-free language Example:

b B Sb B aBb A AB S → → → →

Generates an infinite number

  • f different strings
slide-2
SLIDE 2

2

abbabbbb abbabbBb abbaBbBb abbABb abbSb abbB aBbB AB S ⇒ ⇒ ⇒ ⇒ ⇒ ⇒ ⇒ ⇒ ⇒

b B Sb B aBb A AB S → → → →

A derivation:

In a derivation of a long string, variables are repeated

S A B b B a b b S A B b B a b b

Derivation tree string abbabbbb

S A B b B a b b S A B b B a b b

repeated Derivation tree string abbabbbb

B b S A B b B a b b

aBbbb aBbBb ABb Sb B ⇒ ⇒ ⇒ ⇒ ⇒

b B ⇒ aBbbb B

*

slide-3
SLIDE 3

3

B b S A B b B a b

Repeated Part

aBbbb B

*

B b S A B b a b B b S A B b B a b

aaBbbbbbb aBbbb B

* *

⇒ ⇒

Another possible derivation from

aBbbb B

*

⇒ B

B b S A B b a b B b S A B b B a b

2 2 * *

) ( ) ( ) ( ) ( bbb B a bbb B a B ⇒ ⇒

aBbbb B

*

2 2 *

) ( ) ( bbb b a abb S ⇒ ) ( ) ( ) (

2 2

G L bbb b a abb ∈

aBbbb B

*

⇒ b B ⇒

abbBb S

*

slide-4
SLIDE 4

4

S A B b B a b

aBbbb B

*

⇒ b B ⇒

abbBb S

*

⇒ abbbb abbBb S ⇒ ⇒

*

b

) ( ) ( bbb b a abb =

*

) ( ) ( bbb b a abb S ⇒ ) ( ) ( ) ( G L bbb b a abb ∈

aBbbb B

*

⇒ b B ⇒

abbBb S

*

3 3 3 3 *

) ( ) ( ) ( ) ( bbb b a abb bbb B a abb S ⇒ ⇒

S A B b B a b b S A B b a b B b S A B b B a b b S A B b B a b b

aBbbb B

*

⇒ b B ⇒ abbBb S

*

3 3 *

) ( ) ( bbb b a abb S ⇒ ) ( ) ( ) (

3 3

G L bbb b a abb ∈

aBbbb B

*

⇒ b B ⇒

abbBb S

*

slide-5
SLIDE 5

5

i i

bbb b a abb S ) ( ) (

*

⇒ ) ( ) ( ) ( G L bbb b a abb

i i

aBbbb B

*

⇒ b B ⇒

abbBb S

*

In General:

≥ i

Consider now an infinite context-free language

G

Take so that I has no unit-productions no -productions

G λ

L

Let be the grammar of

} {λ − L

(Number of productions) x (Largest right side of a production)

=

Let

b B Sb B aBb A AB S → → → →

Example :

13 1= + = p m G

p

Let

1 + = p m

12 3 4 = × = p

Take a string with length

) (G L w∈

m w ≥ | |

We will show: in the derivation of a variable of is repeated

w

G

slide-6
SLIDE 6

6

w v v v

k ⇒

⇒ ⇒ ⇒ 

2 1

w S

*

1

v S =

w v v v

k ⇒

⇒ ⇒ ⇒ 

2 1

f v v

i i

+ <

+ |

| | |

1

maximum right hand side

  • f any production

f k w ⋅ < | | f k w m ⋅ ≤ ≤ | | f k p ⋅ < w v v v

k ⇒

⇒ ⇒ ⇒ 

2 1

Number of productions in grammar

f k p ⋅ < f p k >

Number of productions in grammar

> k

Some production must be repeated

w v v v

k ⇒

⇒ ⇒ ⇒ 

2 1 

2 2 1

r B r A r S → → →

Repeated variable

w Aa a Aa a v ⇒ ⇒ ⇒ ⇒ ⇒ ⇒   

4 3 2 1 1

slide-7
SLIDE 7

7 ) (G L w∈

m w ≥ | | w Aa a Aa a S ⇒ ⇒ ⇒ ⇒ ⇒ ⇒   

4 3 2 1

Some variable is repeated Derivation of string w

S A A x

Last repeated variable

u z v y

uvxyz w =

: , , , , z y x v u

repeated Strings of terminals Derivation tree of string

w

S A A x u z v y

uAz S

⇒ vAy A

⇒ x A

Possible derivations:

uAz S

⇒ vAy A

⇒ x A

We know: This string is also generated:

uxz uAz S

*

⇒ ⇒

z xy uv

slide-8
SLIDE 8

8

This string is also generated:

uvxyz uvAyz uAz S

* *

⇒ ⇒ ⇒

∗ The original

z xy uv w

1 1

= uAz S

⇒ vAy A

⇒ x A

We know: This string is also generated:

uvvxyyz uvvAyyz uvAyz uAz S

* * *

⇒ ⇒ ⇒ ⇒

z xy uv

2 2

uAz S

⇒ vAy A

⇒ x A

We know: This string is also generated:

uvvvxyyyz uvvvAyyyz uvvAyyz uvAyz uAz S

* * * *

⇒ ⇒ ⇒ ⇒ ⇒ ⇒

z xy uv

3 3

uAz S

⇒ vAy A

⇒ x A

We know: This string is also generated:

yyyz vxy uvvv yyyz vAy uvvv uvvvAyyyz uvvAyyz uvAyz uAz S     … ⇒ ⇒ ⇒ ⇒ ⇒ ⇒ ⇒ ⇒ ⇒

z xy uv

i i

uAz S

⇒ vAy A

⇒ x A

We know:

* * * * * * * * *

slide-9
SLIDE 9

9

Therefore, any string of the form

z xy uv

i i is generated by the grammar G

≥ i

knowing that

) (G L uvxyz ∈

we also know that

) (G L z xy uv

i i

Therefore,

L z xy uv

i i

} { ) ( λ − = L G L

S A A x u z v y

m vxy ≤ | |

Observation: Since is the last repeated variable

A

S A A x u z v y

1 | | ≥ vy

Observation: Since there are no unit or -productions

λ

slide-10
SLIDE 10

10

The Pumping Lemma: there exists an integer such that

m

for any string

m w L w ≥ ∈ | | ,

we can write For infinite context-free language

L uvxyz w =

with lengths

1 | | and | | ≥ ≤ vy m vxy

and it must be:

all for , ≥ ∈ i L z xy uv

i i

What’s Next

  • Read

– 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

  • Next Lecture Topics

– More Pumping Lemma for Context Free Grammars

  • Quiz 3 in Recitation on Wednesday 11/12

– 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. – Quiz will take the full hour

  • Homework

– No homework today – New Homework Available Friday Morning – New Homework Due Next Thursday