Transcript
Page 1: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 1

Pumping Lemmafor

Context-free Languages

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

Costas Busch - LSU 2

Take an infinite context-free language

Example:

eeEEdDdDccbSDBaAaAbBdABES

|||

||

Generates an infinite numberof different strings

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

Costas Busch - LSU 3

aabbccddeeaabbccddeEaabbccddEaaabbccdDE

aabbBdDEaabSDEaaBEAaBEABES

A possible derivation:

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

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 6

B

Sb D

Bb d d

bbBddbbBdDbSDB

bbBddB*

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

Costas Busch - LSU 7

aaBeeaaBeEaaBEAaBEABES

aaBeeS*

B

S

A

A a

a

E

e E

e

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

Costas Busch - LSU 8

B

c c

ccB

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 11

eeddccbbaaaacceeaaBeeS 00**)()(

)()()( 00 GLeeddccbbaa

aaBeeS* bbBddB

* ccB

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 13

eeddccbbaaeeddBbbaa

aabbBddeeaaBeeS

22*22*

**

)()()()(

)()()( 22 GLeeddccbbaa

aaBeeS* bbBddB

* ccB

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 15

)()()( 33*GLeeddccbbaaS

aaBeeS* bbBddB

* ccB

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 17

)()()(*

GLeeddccbbaaS ii

0iFor any

aaBeeS* bbBddB

* ccB

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

Costas Busch - LSU 18

From Grammar

)(GLaabbccddee

and given string

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

)()()(*

GLeeddccbbaaS ii 0ifor any

eeEEdDdDccbSDBaAaAbBdABES

|||

||

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 20

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

eeEEdDdDccbSDBaAaAbBdABES

|||

||

5rExample:

3t

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 22

S

H

H

Derivation tree of w

some variableis repeated

We will show:rtw ||

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

Costas Busch - LSU 23

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

w2r

Suppose the opposite:

1rLevels

At most

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

Costas Busch - LSU 24

Level 0:

Level 1:

t nodes

Maximum number of nodes per level1nodes

t nodes

The maximum right-hand side of any production

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 30

Take now a string rtw ||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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 31

S

H

H

x

u z

v y

uvxyzw

:,,,, zyxvuStrings of terminals

yield yield

yieldyield

yield

We can write

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

Costas Busch - LSU 32

B

Sb D

Bb d d

S

c c

A

A a

a

E

e E

e

H toscorrespond Bx

u zv y

Example:

eezddyccxbbvaau

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

Costas Busch - LSU 33

uHzS

vHyH

xH

S

H

H

x

u z

v y

Possible derivations

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

Costas Busch - LSU 34

bbBddBaaBeeS

ccB

B

Sb D

Bb d d

S

c c

A

A a

a

E

e E

e

Example:

eezddyccxbbvaau

uHzS vHyH

xH

H toscorrespond B

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

Costas Busch - LSU 35

uHzS

xH

S

H

x

u z

Remove Middle Part

)(00*GLzxyuvuxzuHzS

Yield: zxyuvuxz 00

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 37

)(22*

**

GLzxyuvuvvxyyz

uvvHyyzuvHyzuHzS

uHzS vHyH

xH

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 39

L(G)zxyuv ii

zHyuv

uvvHyyzuvHyzuHzS

ii

uHzS vHyH

xH

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

Costas Busch - LSU 40

If we know that: )(GLuvxyzw

then we also know: )(GLzxyuv ii

Therefore,

Lzxyuv ii

}{)( LGL

For allsince

rtw ||

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 43

1

1||||

rrrk

jj ttttksvxy

H

1T2T

kT

1s2s

ks

subtree of H

Various yieldsksssvxy 21

rj ts || since no variable is repeated in jT

Maximum right-hand side of any production

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

Costas Busch - LSU 44

Thus, if we choose critical lengthrr ttm 1

then, we obtain the pumping lemma forcontext-free languages

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 46

Applicationsof

The Pumping Lemma

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

Costas Busch - LSU 47

Context-free languages

}0:{ nba nn

Non-context free languages

}0:{ ncba nnn

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

Costas Busch - LSU 48

Theorem:The language}0:{ ncbaL nnn

is not context free

Proof: Use the Pumping Lemmafor context-free languages

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

Costas Busch - LSU 49

}0:{ ncbaL nnn

Assume for contradiction thatis context-free

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

L

L

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 51

}0:{ ncbaL nnn

mmm cbaw

we can write: uvxyzw

with lengths andmvxy || 1|| vy

From pumping lemma:

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

Costas Busch - LSU 52

}0:{ ncbaL nnn

Pumping Lemma says:

Lzxyuv ii for all 0i

mmm cbawuvxyzw mvxy || 1|| vy

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

Costas Busch - LSU 53

}0:{ ncbaL nnn

We examine all the possible locationsof string in vxy w

mmm cbawuvxyzw mvxy || 1|| vy

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

Costas Busch - LSU 54

}0:{ ncbaL nnn

Case 1: vxy is in ma

mmm cbawuvxyzw mvxy || 1|| vy

ccccccbbbbbbaaaaaa ...............vxy

m m m

u z

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 59

}0:{ ncbaL nnn

Case 3: vxy is in mc

ccccccbbbbbbaaaaaa ...............vxy

m m m

u z

mmm cbawuvxyzw mvxy || 1|| vy

Similar to case 1

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 61

}0:{ ncbaL nnn

Sub-case 1: contains onlycontains onlyvy

a

mmm cbawuvxyzw mvxy || 1|| vy

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

u zv x y

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 64

}0:{ ncbaL nnn

From Pumping Lemma: Lzxyuv 22

Lcbazxyuv mkmkm 2122However:Contradiction!!!

mmm cbawuvxyzw mvxy || 1|| vy

121 kk

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas Busch - LSU 69

}0:{ ncbaL nnn

Sub-case 3: contains onlycontains andvy

ab

mmm cbawuvxyzw mvxy || 1|| vy

a

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

u zv x y

Similar to sub-case 2

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

Costas 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: Costas Busch - LSU1 Pumping Lemma for Context-free Languages

Costas 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

maImpossible!

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

Costas 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


Top Related