prof. busch - lsu1 pumping lemma for context-free languages

72
Prof. Busch - LSU 1 Pumping Lemma for Context-free Languages

Upload: clara-elliott

Post on 22-Dec-2015

221 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 1

Pumping Lemmafor

Context-free Languages

Page 2: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 2

Take an infinite context-free language

Example:

eeEE

dDdD

ccbSDB

aAaA

bBdABES

|

|

|

|

|

Generates an infinite numberof different strings

Page 3: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 3

aabbccddeeaabbccddeE

aabbccddEaaabbccdDE

aabbBdDEaabSDE

aaBEAaBEABES

A possible derivation:

In a derivation of a “long” enoughstring, variables are repeated

Page 4: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 4

A

A a

a

E

e E

e

B

Sb D

Bb d d

S

c c

Derivation Tree

Repeatedvariable

aabbccddee

Page 5: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 5

B

Sb D

Bb d d

S

c c

Derivation Tree

Repeatedvariable

aabbccddee

A

A a

a

E

e E

e

Page 6: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 6

B

Sb D

Bb d d

bbBddbbBdDbSDB

bbBddB*

Page 7: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 7

aaBeeaaBeEaaBEAaBEABES

aaBeeS*

B

S

A

A a

a

E

e E

e

Page 8: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 8

B

c c

ccB

Page 9: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 9

Putting all together

bbBddB*aaBeeS

* ccB

B

Sb D

Bb d d

S

c c

A

A a

a

E

e E

e

Page 10: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 10

We can remove the middle part

eeddccbbaaS 00*

)()(

B

S

c c

A

A a

a

E

e E

e

Page 11: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 11

eeddccbbaaaacceeaaBeeS 00**

)()(

)()()( 00 GLeeddccbbaa

aaBeeS* bbBddB

* ccB

Page 12: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 12

We can repeated middle part two times

eeddccbbaaS 22*

)()(

1

2

B

Sb D

b d d

S

A

A a

a

E

e E

e

B

c c

B

Sb D

b d d

Page 13: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 13

eeddccbbaaeeddBbbaa

aabbBddeeaaBeeS

22*

22*

**

)()()()(

)()()( 22 GLeeddccbbaa

aaBeeS* bbBddB

* ccB

Page 14: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 14

We can repeat middle part three times

eeddccbbaaS 33*

)()(

1

2

B

Sb D

b d d

S

A

A a

a

E

e E

eB

Sb D

b d d

B

c c

B

Sb D

b d d3

Page 15: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 15

)()()( 33*

GLeeddccbbaaS

aaBeeS* bbBddB

* ccB

Page 16: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 16

B

Sb D

Bb d d

c c

eeddccbbaaS ii )()(*

Repeat middle part timesi

i

1

B

Sb D

b d d

S

A

A a

a

E

e E

eB

Page 17: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 17

)()()(*

GLeeddccbbaaS ii

0iFor any

aaBeeS* bbBddB

* ccB

Page 18: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 18

From Grammar

)(GLaabbccddee

and given string

We inferred that a family of strings is in )(GL

)()()(*

GLeeddccbbaaS ii 0ifor any

eeEE

dDdD

ccbSDB

aAaA

bBdABES

|

|

|

|

|

Page 19: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 19

Arbitrary Grammars

Consider now an arbitrary infinite context-free language

G

Take so that it has no unit-productions and no -productions

G

L

Let be the grammar of }{L

(remove them)

Page 20: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 20

Let be the number of variables rLet be the maximum right-hand size of any productiont

eeEE

dDdD

ccbSDB

aAaA

bBdABES

|

|

|

|

|

5rExample:

3t

Page 21: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 21

Take string with . Then in the derivation tree ofthere is a path from the root to a leaf where a variable of is repeated

)(GLw

G

rtw ||w

Claim:

Proof:

Proof by contradiction

Page 22: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 22

S

H

H

mw ||

Derivation tree of w

some variableis repeated

We will show:

Page 23: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 23

First we show that the tree ofhas at least levels of nodes

w2r

Suppose the opposite:

1rLevels

At most

Page 24: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 24

Level 0:

Level 1:

t nodes

Maximum number of nodes per level

1nodes

t nodes

The maximum right-hand side of any production

Page 25: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 25

Level 0:

Level 1:

t nodes t nodes

2t nodes

1nodes

t nodes

2t nodesLevel 2:

Maximum number of nodes per level

Page 26: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 26

it nodesLevel : i1r

Levels

rt nodesLevel : r

Maximum possible string length = max nodes at level = rtr

Maximum number of nodes per levelLevel 0: 1nodes

At most

Page 27: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 27

Therefore,maximum length of string :

rtw ||w

rtw ||However we took,

Contradiction!!!

Therefore, the tree must have at least levels 2r

Page 28: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 28

Thus, there is a path from the root to a leaf with at least nodes2r

1V

2rLevels

At least

2V

3V

1rV

symbol

Variables

SV 1

1r

(root)

(leaf)

Page 29: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 29

1V

2V

3V

1rV

Since there are at most different variables,some variable is repeated

r

Pigeonholeprinciple

S

H

H

END OF CLAIM PROOF

Page 30: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 30

Take now a stringrtw ||w with

some variable is repeated

H

Take to be the deepest, so thatonly is repeated in subtree

H

S

H

H

subtree of H

From claim:

H

Page 31: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 31

S

H

H

x

u z

v y

uvxyzw

:,,,, zyxvuStrings of terminals

yield yield

yieldyield

yield

We can write

Page 32: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 32

B

Sb D

Bb d d

S

c c

A

A a

a

E

e E

e

H toscorrespond B

x

u zv y

Example:

eez

ddy

ccx

bbv

aau

Page 33: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 33

uHzS

vHyH

xH

S

H

H

x

u z

v y

Possible derivations

Page 34: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 34

bbBddBaaBeeS

ccB

B

Sb D

Bb d d

S

c c

A

A a

a

E

e E

e

Example:

eez

ddy

ccx

bbv

aau

uHzS vHyH

xH

H toscorrespond B

Page 35: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 35

uHzS

xH

S

H

x

u z

Remove Middle Part

)(00*

GLzxyuvuxzuHzS

Yield: zxyuvuxz 00

Page 36: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 36

uHzS

vHyH

xH

S

u zH

v y

H

x

Repeat Middle part two times

H

v yvHyH

1

2

Yield: zxyuvuvvxyyz 22

Page 37: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 37

)(22*

**

GLzxyuvuvvxyyz

uvvHyyzuvHyzuHzS

uHzS vHyH

xH

Page 38: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 38

uHzS

vHyH

xH

Repeat Middle part times

vHyH

iS

u zH

v y

H

x

H

v y

H1

i

Yield: zxyuv ii

Page 39: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 39

L(G)zxyuv ii

zHyuv

uvvHyyzuvHyzuHzS

ii

uHzS vHyH

xH

Page 40: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 40

If we know that: )(GLuvxyzw

then we also know: )(GLzxyuv ii

Therefore,

Lzxyuv ii

}{)( LGL

For all

since

rtw ||

Page 41: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 41

Observation 1: S

H

H

x

u z

v y

1|| vySince has no unit and -productions

v y

G

At least one of or is not

Page 42: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 42

1|| rtvxyObservation 2:

since in subtree only variable is repeated

S

H

H

x

u z

v y

subtree of

H

HExplanation follows….

Page 43: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 43

1

1

||||

rrrk

jj ttttksvxy

H

1T2T

kT

1s2s

ks

subtree of H

Various yields

ksssvxy 21

rj ts || since no variable is repeated in jT

Maximum right-hand side of any production

Page 44: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 44

Thus, if we choose critical length

rr ttm 1

then, we obtain the pumping lemma forcontext-free languages

Page 45: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 45

The Pumping Lemma:

there exists an integer such that m

for any string mwLw || ,

we can write

For any infinite context-free language L

uvxyzw

with lengths 1||and || vymvxy

and it must be that:

0 allfor , iLzxyuv ii

Page 46: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 46

Applicationsof

The Pumping Lemma

Page 47: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 47

Context-free languages

}0:{ nba nn

Non-context free languages

}0:{ ncba nnn

Page 48: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 48

Theorem:The language

}0:{ ncbaL nnn

is not context free

Proof: Use the Pumping Lemmafor context-free languages

Page 49: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 49

}0:{ ncbaL nnn

Assume for contradiction that

is context-free

Since is context-free and infinitewe can apply the pumping lemma

L

L

Page 50: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 50

Let be the critical length of the pumping lemma

m

Pick any string with length Lw mw ||

We pick:mmm cbaw

}0:{ ncbaL nnn

Page 51: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 51

}0:{ ncbaL nnn

mmm cbaw

we can write: uvxyzw

with lengths andmvxy || 1|| vy

From pumping lemma:

Page 52: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 52

}0:{ ncbaL nnn

Pumping Lemma says:

Lzxyuv ii for all 0i

mmm cbawuvxyzw mvxy || 1|| vy

Page 53: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 53

}0:{ ncbaL nnn

We examine all the possible locationsof string in vxy w

mmm cbawuvxyzw mvxy || 1|| vy

Page 54: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 54

}0:{ ncbaL nnn

Case 1: vxy is inma

mmm cbawuvxyzw mvxy || 1|| vy

ccccccbbbbbbaaaaaa ...............

vxy

m m m

u z

Page 55: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 55

}0:{ ncbaL nnn

ccccccbbbbbbaaaaaaaaaa .....................

v

m m m

u z

mmm cbawuvxyzw mvxy || 1|| vy

x y

1kav 2kay 121 kk

Page 56: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 56

}0:{ ncbaL nnn

ccccccbbbbbbaaaaaaaaaa .....................

2v

21 kkm m m

u z

mmm cbawuvxyzw mvxy || 1|| vy

x 2y

1kav 2kay 121 kk

Page 57: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 57

}0:{ ncbaL nnn

Lcbazxyuv mmkkm 2122

From Pumping Lemma: Lzxyuv 22

However:

Contradiction!!!

mmm cbawuvxyzw mvxy || 1|| vy

121 kk

Page 58: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 58

}0:{ ncbaL nnn

Case 2: vxy is in mb

ccccccbbbbbbaaaaaa ...............

vxy

m m m

u z

mmm cbawuvxyzw mvxy || 1|| vy

Similar to case 1

Page 59: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 59

}0:{ ncbaL nnn

Case 3: vxy is inmc

ccccccbbbbbbaaaaaa ...............

vxy

m m m

u z

mmm cbawuvxyzw mvxy || 1|| vy

Similar to case 1

Page 60: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 60

}0:{ ncbaL nnn

Case 4: vxy overlaps and ma

ccccccbbbbbbaaaaa ...............

vxy

m m m

u z

mb

mmm cbawuvxyzw mvxy || 1|| vy

Page 61: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 61

}0:{ ncbaL nnn

Sub-case 1: contains onlycontains onlyvy

ab

mmm cbawuvxyzw mvxy || 1|| vy

ccccccbbbbbbaaaaaa .....................m m m

u zv x y

Page 62: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 62

}0:{ ncbaL nnn

mmm cbawuvxyzw mvxy || 1|| vy

ccccccbbbbbbaaaaaa .....................m m m

u zv x y

1kav 2kby 121 kk

Page 63: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 63

}0:{ ncbaL nnn

mmm cbawuvxyzw mvxy || 1|| vy

ccccccbbbbbbaaaaaa .....................1km 2km m

u z2v x 2y

1kav 2kby 121 kk

Page 64: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 64

}0:{ ncbaL nnn

From Pumping Lemma: Lzxyuv 22

Lcbazxyuv mkmkm 2122However:

Contradiction!!!

mmm cbawuvxyzw mvxy || 1|| vy

121 kk

Page 65: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 65

}0:{ ncbaL nnn

Sub-case 2: contains andcontains onlyvy

ab

mmm cbawuvxyzw mvxy || 1|| vy

b

ccccccbbbbbbbbaaaa .....................m m m

u zv x y

Page 66: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 66

}0:{ ncbaL nnn

mmm cbawuvxyzw mvxy || 1|| vy

ccccccbbbbbbbbaaaa .....................1k 2k

u zv x y

21 kkbav 3kby 1, 21 kk

m m m

By assumption

3k

Page 67: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 67

}0:{ ncbaL nnn

mmm cbawuvxyzw mvxy || 1|| vy

ccccccbbbbbbbabbaabaaa ...........................

u z2v x 2y

21 kkbav 3kby 1, 21 kk

1k 2k 1k 2km 3km m

32k

Page 68: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 68

}0:{ ncbaL nnn

mmm cbawuvxyzw mvxy || 1|| vy

From Pumping Lemma: Lzxyuv 22

Lcbabazxyuv mkmkkm 31222However:

Contradiction!!!

1, 21 kk

Page 69: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 69

}0:{ ncbaL nnn

Sub-case 3: contains onlycontains andvy

ab

mmm cbawuvxyzw mvxy || 1|| vy

a

ccccccbbbbaaaaaaaa .....................m m m

u zv x y

Similar to sub-case 2

Page 70: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 70

}0:{ ncbaL nnn

Case 5: vxy overlaps and mb

ccccccbbbbbbaaaaaa .........

vxy

m m m

u z

mc

mmm cbawuvxyzw mvxy || 1|| vy

Similar to case 4

Page 71: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 71

}0:{ ncbaL nnn

Case 6: vxy overlaps , and mb

ccccccbbbbbbaaaaaa .........

vxy

m m m

u z

mc

mmm cbawuvxyzw mvxy || 1|| vy

ma

Impossible!

Page 72: Prof. Busch - LSU1 Pumping Lemma for Context-free Languages

Prof. Busch - LSU 72

In all cases we obtained a contradiction

Therefore: the original assumption that

}0:{ ncbaL nnn

is context-free must be wrong

Conclusion: is not context-freeL