More Applications for any string w L , | w | m of The - - PDF document

more applications
SMART_READER_LITE
LIVE PREVIEW

More Applications for any string w L , | w | m of The - - PDF document

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


slide-1
SLIDE 1

1

CS 301 - Lecture 17 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 – 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

More Applications

  • f

The Pumping Lemma

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

slide-2
SLIDE 2

2

Context-free languages

} : { ≥ n b a

n n Non-context free languages

} : { ≥ n c b a

n n n

}*} , { : { b a w wwR ∈

}} , { : { b a v vv ∈

Theorem: The language

}*} , { : { b a v vv L ∈ =

is not context free Proof: Use the Pumping Lemma for context-free languages Assume for contradiction that is context-free Since is context-free and infinite we can apply the pumping lemma

L L }*} , { : { b a v vv L ∈ =

Pumping Lemma gives a magic number such that:

m

Pick any string of with length at least

m

we pick:

L b a b a

m m m m

∈ L }*} , { : { b a v vv L ∈ =

slide-3
SLIDE 3

3

We can write: with lengths and

m vxy ≤ | | 1 | | ≥ vy uvxyz b a b a

m m m m

=

Pumping Lemma says:

L z xy uv

i i

for all

≥ i }*} , { : { b a v vv L ∈ =

We examine all the possible locations

  • f string in

vxy m vxy ≤ | | 1 | | ≥ vy uvxyz b a b a

m m m m

=

m m m m

b a b a }*} , { : { b a v vv L ∈ =

Case 1: vxy

is within the first m

a b b a a b b a a ...... ...... ...... ...... v m m m u z m vxy ≤ | | 1 | | ≥ vy uvxyz b a b a

m m m m

= x y m

1

k

a v =

2

k

a y = 1

2 1

≥ + k k }*} , { : { b a v vv L ∈ = b b a a b b a a ...... ...... ...... ...... ..........

2

v

2 1

k k m + + m m u z m vxy ≤ | | 1 | | ≥ vy uvxyz b a b a

m m m m

= x

2

y m

Case 1: vxy

is within the first m

a

1

k

a v =

2

k

a y = 1

2 1

≥ + k k }*} , { : { b a v vv L ∈ =

slide-4
SLIDE 4

4 m vxy ≤ | | 1 | | ≥ vy uvxyz b a b a

m m m m

=

Case 1: vxy

is within the first m

a

1

2 1

≥ + k k

L z xy uv b a b a

m m m k k m

∉ =

+ + 2 2

2 1

}*} , { : { b a v vv L ∈ = m vxy ≤ | | 1 | | ≥ vy uvxyz b a b a

m m m m

=

Case 1: vxy

is within the first m

a L z xy uv ∈

2 2 Contradiction!!!

L z xy uv b a b a

m m m k k m

∉ =

+ + 2 2

2 1

However, from Pumping Lemma:

}*} , { : { b a v vv L ∈ =

is in the first is in the first

Case 2:

b b a a b b a a ...... ...... ...... ...... v m m m u z m vxy ≤ | | 1 | | ≥ vy uvxyz b a b a

m m m m

= x y m

m

a

m

b v y

1

k

a v =

2

k

b y = 1

2 1

≥ + k k }*} , { : { b a v vv L ∈ =

is in the first is in the first

Case 2:

b b a a b b a a ...... ...... .. .......... .. ..........

2

v

1

k m +

2

k m + m u z m vxy ≤ | | 1 | | ≥ vy uvxyz b a b a

m m m m

= x

2

y m

m

a

m

b v y

1

k

a v =

2

k

b y = 1

2 1

≥ + k k }*} , { : { b a v vv L ∈ =

slide-5
SLIDE 5

5

is in the first is in the first

Case 2:

m vxy ≤ | | 1 | | ≥ vy uvxyz b a b a

m m m m

=

m

a

m

b v y

1

2 1

≥ + k k

L z xy uv b a b a

m m k m k m

∉ =

+ + 2 2

2 1

}*} , { : { b a v vv L ∈ =

is in the first is in the first

Case 2:

m vxy ≤ | | 1 | | ≥ vy uvxyz b a b a

m m m m

=

m

a

m

b v y L z xy uv b a b a

m m k m k m

∉ =

+ + 2 2

2 1

L z xy uv ∈

2 2 Contradiction!!! However, from Pumping Lemma:

}*} , { : { b a v vv L ∈ =

is in the first

  • verlaps the first

Case 3:

b b a a b b a a ...... ...... ...... ...... v m m m u z m vxy ≤ | | 1 | | ≥ vy uvxyz b a b a

m m m m

= x y m

m mb

a

m

b v y

2 1 k

k b

a v =

3

k

b y = 1 , 2

1

≥ k k }*} , { : { b a v vv L ∈ =

is in the first

  • verlaps the first

Case 3:

b b a a b b a a b b a a ...... ...... ......... ... ... ......

2

v m

2

k

3

k m + u z m vxy ≤ | | 1 | | ≥ vy uvxyz b a b a

m m m m

= x

2

y m

m mb

a

m

b v y

2 1 k

k b

a v =

3

k

b y = 1 , 2

1

≥ k k

1

k m }*} , { : { b a v vv L ∈ =

slide-6
SLIDE 6

6

is in the first

  • verlaps the first

Case 3:

m vxy ≤ | | 1 | | ≥ vy uvxyz b a b a

m m m m

=

m mb

a

m

b v y L z xy uv b a b a b a

m m k m k k m

∉ =

+ 2 2

3 1 2

1 , 2

1

≥ k k }*} , { : { b a v vv L ∈ =

is in the first

  • verlaps the first

Case 3:

m vxy ≤ | | 1 | | ≥ vy uvxyz b a b a

m m m m

=

m mb

a

m

b v y L z xy uv b a b a b a

m m k k k m

∉ =

2 2

3 1 2

L z xy uv ∈

2 2 Contradiction!!! However, from Pumping Lemma:

}*} , { : { b a v vv L ∈ =

Overlaps the first in the first

Case 4:

b b a a b b a a ...... ...... ...... ...... v m m m u z m vxy ≤ | | 1 | | ≥ vy uvxyz b a b a

m m m m

= x y m

m

a

m mb

a v y

Analysis is similar to case 3

}*} , { : { b a v vv L ∈ =

Other cases:

vxy

is within m m m m

b a b a

  • r
  • r

m m m m

b a b a

m m m m

b a b a

Analysis is similar to case 1: m m m m

b a b a

slide-7
SLIDE 7

7

More cases:

vxy

  • verlaps

m m m m

b a b a

  • r

m m m m

b a b a

Analysis is similar to cases 2,3,4: m m m m

b a b a

Since , it is impossible to overlap: There are no other cases to consider

m vxy ≤ | | vxy

m m m m

b a b a

nor nor m m m m

b a b a

m m m m

b a b a

In all cases we obtained a contradiction Therefore: The original assumption that is context-free must be wrong Conclusion: is not context-free

L }*} , { : { b a v vv L ∈ =

Context-free languages

} : { ≥ n b a

n n Non-context free languages

} : { ≥ n c b a

n n n

}*} , { : { b a w wwR ∈ }} , { : { b a w ww ∈ } : {

!

≥ n an

slide-8
SLIDE 8

8

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

} : {

!

≥ = n a L

n Assume for contradiction that is context-free Since is context-free and infinite we can apply the pumping lemma

L L } : {

!

≥ = n a L

n Pumping Lemma gives a magic number such that:

m

Pick any string of with length at least

m

we pick:

L am ∈

!

L } : {

!

≥ = n a L

n We can write: with lengths and

m vxy ≤ | | 1 | | ≥ vy uvxyz am =

! Pumping Lemma says:

L z xy uv

i i

for all

≥ i } : {

!

≥ = n a L

n

slide-9
SLIDE 9

9

We examine all the possible locations

  • f string in

vxy m vxy ≤ | | 1 | | ≥ vy

! m

a uvxyz am =

! There is only one case to consider

} : {

!

≥ = n a L

n

v ! m u z x y

1

k

a v =

2

k

a y = m k k ≤ + ≤

2 1

1 a a ..... .......... m vxy ≤ | | 1 | | ≥ vy uvxyz am =

!

} : {

!

≥ = n a L

n 2

v

2 1

! k k m + + u z x

2

y

1

k

a v =

2

k

a y = a a ....... .......... .......... m vxy ≤ | | 1 | | ≥ vy uvxyz am =

!

} : {

!

≥ = n a L

n

m k k ≤ + ≤

2 1

1

2

v k m + ! u z x

2

y

1

k

a v =

2

k

a y = a a ....... .......... .......... m vxy ≤ | | 1 | | ≥ vy uvxyz am =

!

} : {

!

≥ = n a L

n

m k ≤ ≤ 1

2 1

k k k + =

slide-10
SLIDE 10

10 m vxy ≤ | | 1 | | ≥ vy uvxyz am =

!

} : {

!

≥ = n a L

n

m k ≤ ≤ 1 z xy uv a

k m 2 2 !

=

+

)! 1 ( ) 1 ( ! ! ! ! ! + = + = + < + ≤ + m m m m m m m m k m m k ≤ ≤ 1

Since , for we have:

2 ≥ m )! 1 ( ! ! + < + < m k m m m vxy ≤ | | 1 | | ≥ vy uvxyz am =

!

} : {

!

≥ = n a L

n

L z xy uv a

k m

∉ =

+ 2 2 !

)! 1 ( ! ! + < + < m k m m m vxy ≤ | | 1 | | ≥ vy uvxyz am =

!

} : {

!

≥ = n a L

n

L z xy uv a

k m

∉ =

+ 2 2 !

L z xy uv ∈

2 2 Contradiction!!! However, from Pumping Lemma:

slide-11
SLIDE 11

11

We obtained a contradiction Therefore: The original assumption that is context-free must be wrong Conclusion: is not context-free

L } : {

!

≥ = n a L

n Context-free languages

} : { ≥ n b a

n n Non-context free languages

} : { ≥ n c b a

n n n

}*} , { : { b a w wwR ∈ }} , { : { b a w ww ∈ } : {

!

≥ n an } : {

2

≥ n b a

n n Theorem: The language is not context free Proof: Use the Pumping Lemma for context-free languages

} : {

2

≥ = n b a L

n n Assume for contradiction that is context-free Since is context-free and infinite we can apply the pumping lemma

L L } : {

2

≥ = n b a L

n n

slide-12
SLIDE 12

12

Pumping Lemma gives a magic number such that:

m

Pick any string of with length at least

m

we pick:

L b a

m m

2

L } : {

2

≥ = n b a L

n n We can write: with lengths and

m vxy ≤ | | 1 | | ≥ vy uvxyz b a

m m

=

2

Pumping Lemma says:

L z xy uv

i i

for all

≥ i } : {

2

≥ = n b a L

n n We examine all the possible locations

  • f string in

vxy m vxy ≤ | | 1 | | ≥ vy uvxyz b a

m m

=

2

m m b

a

2

} : {

2

≥ = n b a L

n n Most complicated case:

b b a a ...... . .......... .......... v

2

m m u z x y

is in is in m

a

m

b v y m vxy ≤ | | 1 | | ≥ vy uvxyz b a

m m

=

2

} : {

2

≥ = n b a L

n n

slide-13
SLIDE 13

13 b b a a ...... . .......... .......... v

2

m m u z x y

1

k

a v =

2

k

b y = m vxy ≤ | | 1 | | ≥ vy uvxyz b a

m m

=

2

} : {

2

≥ = n b a L

n n

m k k ≤ + ≤

2 1

1 b b a a ...... . .......... .......... v

2

m m u z x y

1

k

a v =

2

k

b y =

Most complicated sub-case: 1 ≠

k

2 ≠

k m vxy ≤ | | 1 | | ≥ vy uvxyz b a

m m

=

2

} : {

2

≥ = n b a L

n n

m k k ≤ + ≤

2 1

1

and

v

1 2

k m −

2

k m − u z x

y

b b a a ... ..... .......... } : {

2

≥ = n b a L

n n

m vxy ≤ | | 1 | | ≥ vy uvxyz b a

m m

=

2 1

k

a v =

2

k

b y =

Most complicated sub-case: 1 ≠

k

2 ≠

k m k k ≤ + ≤

2 1

1

and

} : {

2

≥ = n b a L

n n

m vxy ≤ | | 1 | | ≥ vy uvxyz b a

m m

=

2 1

k

a v =

2

k

b y =

Most complicated sub-case: 1 ≠

k

2 ≠

k m k k ≤ + ≤

2 1

1

and

z xy uv b a

k m k m

2 1 2

=

− −

slide-14
SLIDE 14

14

1 2 2 2 2 2

1 2 ) 1 ( ) ( k m m m m k m − < + − = − ≤ −

1 ≠

k

2 ≠

k m k k ≤ + ≤

2 1

1

and 2 2 1 2

) ( k m k m − ≠ − } : {

2

≥ = n b a L

n n

m vxy ≤ | | 1 | | ≥ vy uvxyz b a

m m

=

2

2 2 1 2

) ( k m k m − ≠ − L z xy uv b a

k m k m

∉ =

− −

2 1 2

} : {

2

≥ = n b a L

n n

m vxy ≤ | | 1 | | ≥ vy uvxyz b a

m m

=

2

L z xy uv b a

k m k m

∉ =

− −

2 1 2

However, from Pumping Lemma:

L z xy uv ∈

Contradiction!!! When we examine the rest of the cases we also obtain a contradiction

slide-15
SLIDE 15

15

In all cases we obtained a contradiction Therefore: The original assumption that is context-free must be wrong Conclusion: is not context-free

L } : {

2

≥ = n b a L

n n

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 – JFLAP Chapter 1, 2.1, (skip 2.2), 3, 4, 5, 6, 7

  • Next Lecture Topics From 8.2

– Closure and Decidable Properties for Context Free Languages

  • 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

– Homework Due Thursday