# More Applications of The Pumping Lemma

Fall 2003

Costas Busch

1

The Pumping Lemma: For infinite context-free language there exists an integer for any string we can write with lengths

L

m such that
| w |u m

w  L,

! uvxyz
| vxy |e m and | vy |u 1

and it must be: i i
Fall 2003

uv xy z  L,

Costas Busch

for all i u 0

2

Non-context free languages

{a b c : n u 0}

n n n

{vv : v {a, b}}

Context-free languages

{a b : n u 0}

n n

{ww : w  {a, b}*}

R

Fall 2003

Costas Busch

3

Theorem: The language

L ! {vv : v  {a, b}*}
is not context free

Proof:

Use the Pumping Lemma for context-free languages

Fall 2003

Costas Busch

4

L ! {vv : v {a, b}*}
Assume for contradiction that is context-free

L

Since L is context-free and infinite we can apply the pumping lemma

Fall 2003

Costas Busch

5

L ! {vv : v {a, b}*}
Pumping Lemma gives a magic number such that:

m

Pick any string of

L with length at least m
m m m m

we pick:

a b a b
Costas Busch

L
6

Fall 2003

L ! {vv : v {a, b}*}
We can write: with lengths

a b a b ! uvxyz | vxy |e m and | vy |u 1

m m m m

Pumping Lemma says:

uv xy z  L
Fall 2003

i

i

for all
Costas Busch

iu0
7

L ! {vv : v {a, b}*}
a b a b ! uvxyz
m m m m

| vxy |e m

| vy |u 1

We examine all the possible locations m m m m of string vxy in a b a b

Fall 2003

Costas Busch

8

L ! {vv : v {a, b}*}
a b a b ! uvxyz
Case 1:
m m m m

| vxy |e m

| vy |u 1
m

vxy is within the first a
k1

v!a

y!a

k2

k1  k 2 u 1

m m m m a ...... a b ...... b a ...... a b ...... b z u vx y
Fall 2003 Costas Busch 9

L ! {vv : v {a, b}*}
a b a b ! uvxyz
Case 1:
m m m m

| vxy |e m

| vy |u 1
m

vxy is within the first a
k1

v!a

y!a

k2

k1  k 2 u 1

m m m  k1  k 2 m a ................ a b ...... b a ...... a b ...... b z u v2 x y2
Fall 2003 Costas Busch 10

L ! {vv : v {a, b}*}
a b a b ! uvxyz
Case 1:
m m m m

| vxy |e m

| vy |u 1
m

vxy is within the first a
2 2

a

m  k1  k 2 m m m

b a b ! uv xy z  L

k1  k 2 u 1
Fall 2003 Costas Busch 11

L ! {vv : v {a, b}*}
a b a b ! uvxyz
Case 1:
m m m m

| vxy |e m

| vy |u 1
m

vxy is within the first a
2 2

a

m  k1  k 2 m m m

b a b ! uv xy z  L uv xy z  L
12

Fall 2003 Costas Busch

2

2

L ! {vv : v {a, b}*} m m m m | vxy |e m a b a b ! uvxyz
Case 2: v

| vy |u 1

y v!a

m is in the first a m is in the first b

k1

y !b

k2

k1  k 2 u 1

m m m m a ...... a b ...... b a ...... a b ...... b z u v x y
Fall 2003 Costas Busch 13

L ! {vv : v {a, b}*} m m m m | vxy |e m a b a b ! uvxyz
Case 2: v

| vy |u 1

y v!a

m is in the first a m is in the first b

k1

y !b

k2

k1  k 2 u 1

Fall 2003

m m m  k1 m  k2 a ............ a b ............ b a ...... a b ...... b 2 2 x z u y v
Costas Busch

14

L ! {vv : v {a, b}*} m m m m | vxy |e m a b a b ! uvxyz
Case 2: v is in the first a
m m 2

| vy |u 1

y is in the first b a
m  k1 m  k2 m m

b

a b ! uv xy z  L

2

k1  k 2 u 1
Fall 2003 Costas Busch 15

L ! {vv : v {a, b}*} m m m m | vxy |e m a b a b ! uvxyz
Case 2: v is in the first a
m m 2

| vy |u 1

y is in the first b a
m  k1 m  k2 m m

b

a b ! uv xy z  L
uv xy z  L
16

2

Fall 2003 Costas Busch

2

2

L ! {vv : v {a, b}*} m m m m | vxy |e m a b a b ! uvxyz
Case 3: v overlaps the first a b
m m

| vy |u 1

y is in the first b v
k1 k2 !a b

m

y !b

k3

k1, k 2 u 1

m m m m a ...... a b ...... b a ...... a b ...... b u v xy z
Fall 2003 Costas Busch 17

L ! {vv : v {a, b}*} m m m m | vxy |e m a b a b ! uvxyz
Case 3: v overlaps the first a b
m m

| vy |u 1

y is in the first b v
k1 k2 !a b

m

y !b

k3

k1, k 2 u 1

k1 m  k3 k2 m m m a ...... a b ... b a ... a b ......... b a ...... a b ...... b 2 u z x y2 v
Fall 2003 Costas Busch 18

L ! {vv : v {a, b}*} m m m m | vxy |e m a b a b ! uvxyz
Case 3: v overlaps the first a b
m m

| vy |u 1

y is in the first b
m k2 k1 m  k3 m m a b a b a b

m 2

! uv xy z  L

2

k1, k 2 u 1
Fall 2003 Costas Busch 19

L ! {vv : v {a, b}*} m m m m | vxy |e m a b a b ! uvxyz
Case 3: v overlaps the first a b
m m

| vy |u 1

y is in the first b
m k2 k1 k3 m m a b a b a b 2

m

! uv xy z  L
uv xy z  L
20

2

Fall 2003 Costas Busch

2

2

L ! {vv : v {a, b}*} m m m m | vxy |e m a b a b ! uvxyz
Case 4: v in the first a
m m m

| vy |u 1

y Overlaps the first a b
Analysis is similar to case 3

m m m m a ...... a b ...... b a ...... a b ...... b z uv x y
Fall 2003 Costas Busch 21

Other cases:

vxy is within a b a b
or

m m m m

a b a b
or

m m m m

a b a b
Analysis is similar to case 1:

m m m m

a b a b
Fall 2003

m m m m
Costas Busch 22

More cases:

vxy overlaps a b a b
or

m m m m

a b a b

m m m m

Analysis is similar to cases 2,3,4:

a b a b
Fall 2003

m m m m
Costas Busch 23

There are no other cases to consider Since | vxy |e m, it is impossible vxy to overlap: m m m m

a b a b
nor

a b a b
nor

m m m m

a b a b
Fall 2003 Costas Busch

m m m m
24

In all cases we obtained a contradiction Therefore: The original assumption that

L ! {vv : v {a, b}*}
is context-free must be wrong

Conclusion:
Fall 2003

L is not context-free
Costas Busch 25

Non-context free languages

{a b c : n u 0}
n!

n n n

{ww : w  {a, b}}

{a : n u 0}
Context-free languages

{a b : n u 0}

n n

{ww : w  {a, b}*}

R

Fall 2003

Costas Busch

26

Theorem: The language n!

L ! {a : n u 0}

is not context free

Proof:

Use the Pumping Lemma for context-free languages

Fall 2003

Costas Busch

27

L ! {a : n u 0}
Assume for contradiction that is context-free

n!

L

Since L is context-free and infinite we can apply the pumping lemma

Fall 2003

Costas Busch

28

L ! {a : n u 0}
Pumping Lemma gives a magic number such that:

n!

m

Pick any string of

L with length at least m
m!

we pick:

a

L
29

Fall 2003

Costas Busch

L ! {a : n u 0}
We can write: with lengths

n!

a

m!

! uvxyz

| vxy |e m and | vy |u 1

Pumping Lemma says:

uv xy z  L
Fall 2003

i

i

for all
Costas Busch

iu0
30

L ! {a : n u 0} a
m!

n!

! uvxyz

| vxy |e m

| vy |u 1

We examine all the possible locations m! of string vxy in a

There is only one case to consider
Fall 2003 Costas Busch 31

L ! {a : n u 0} a
m!

n!

! uvxyz

| vxy |e m
m! a ............... a u v x y z

| vy |u 1

v!a
Fall 2003

k1

y!a

k2

1 e k1  k 2 e m
32

Costas Busch

L ! {a : n u 0} a
m!

n!

! uvxyz

| vxy |e m

| vy |u 1

m! k1  k 2 a ........................... a u v2 x y2 z v!a
Fall 2003

k1

y!a

k2

1 e k1  k 2 e m
33

Costas Busch

L ! {a : n u 0} a
m!

n!

! uvxyz

| vxy |e m

| vy |u 1 k ! k1  k 2

m! k a ........................... a u v2 x y2 z v!a
Fall 2003

k1

y!a

k2

1e k e m
34

Costas Busch

L ! {a : n u 0} a
m!

n!

! uvxyz
m! k

| vxy |e m
2 2

| vy |u 1

a

! uv xy z

1e k e m
Fall 2003 Costas Busch 35

Since

1 e k e m , for m u 2 we have: m! k e m! m m! m!m ! m!(1  m) ! (m  1)!

m! m! k
Fall 2003 Costas Busch

(m  1)!
36

L ! {a : n u 0} a
m!

n!

! uvxyz

| vxy |e m
(m  1)!

| vy |u 1

m! m! k

a
Fall 2003

m! k

! uv xy z  L
Costas Busch 37

2

2

L ! {a : n u 0} a
m!

n!

! uvxyz

| vxy |e m
2

| vy |u 1
2

However, from Pumping Lemma:

uv xy z  L

a
Fall 2003

m! k

! uv xy z  L
Costas Busch 38

2

2

We obtained a contradiction Therefore: The original assumption that

L ! {a : n u 0}
is context-free must be wrong

n!

Conclusion:
Fall 2003

L is not context-free
Costas Busch 39

Non-context free languages

{a b c : n u 0}
{a b : n u 0}
n
2

n n n

{ww : w  {a, b}}

n

{a : n u 0}

n!

Context-free languages

{a b : n u 0}

n n

{ww : w  {a, b}*}

R

Fall 2003

Costas Busch

40

Theorem: The language n2 n

L ! {a b : n u 0}

is not context free

Proof:

Use the Pumping Lemma for context-free languages

Fall 2003

Costas Busch

41

L ! {a b : n u 0}
Assume for contradiction that is context-free

n

2

n

L

Since L is context-free and infinite we can apply the pumping lemma

Fall 2003

Costas Busch

42

L ! {a b : n u 0}
Pumping Lemma gives a magic number such that:

n

2

n

m

Pick any string of

L with length at least m
m2 m

we pick:

a

b

L
43

Fall 2003

Costas Busch

L ! {a b : n u 0}
We can write: with lengths

n

2

n

a

m2 m

b ! uvxyz

| vxy |e m and | vy |u 1

Pumping Lemma says:

uv xy z  L
Fall 2003

i

i

for all
Costas Busch

iu0
44

L ! {a b : n u 0} a
m
2

n

2

n

b ! uvxyz

m

| vxy |e m

| vy |u 1

We examine all the possible locations

vxy in a m b m of string

2

Fall 2003

Costas Busch

45

L ! {a b : n u 0} a
m
2

n

2

n

b ! uvxyz

m

| vxy |e m v y
m is in a m is in b

| vy |u 1

Most complicated case:

m m a ..................... a b ...... b v x y z u
Fall 2003 Costas Busch 46

2

L ! {a b : n u 0} a
m
2

n

2

n

b ! uvxyz

m

| vxy |e m

| vy |u 1

v!a

k1

y!b

k2

1 e k1  k 2 e m

m m a ..................... a b ...... b v x y z u
Fall 2003 Costas Busch 47

2

L ! {a b : n u 0} a
m
2

n

2

n

b ! uvxyz

m

| vxy |e m

| vy |u 1

Most complicated sub-case:

k1 { 0 and k 2 { 0 1 e k1  k 2 e m

v!a

k1

y!b

k2

m m a ..................... a b ...... b v x y z u
Fall 2003 Costas Busch 48

2

L ! {a b : n u 0} a
m
2

n

2

n

b ! uvxyz

m

| vxy |e m

| vy |u 1

Most complicated sub-case:

k1 { 0 and k 2 { 0 1 e k1  k 2 e m

v!a

k1

y!b
2

k2

m  k1 m  k 2 a ............... a b ... b u 0 x 0z
v
y
Fall 2003 Costas Busch 49

L ! {a b : n u 0} a
m
2

n

2

n

b ! uvxyz

m

| vxy |e m

| vy |u 1

Most complicated sub-case:

k1 { 0 and k 2 { 0 1 e k1  k 2 e m

v!a

k1
2

y!b

k2

m  k1 m  k 2 a b

! uv xy z
50

0

0

Fall 2003

Costas Busch

k1 { 0 and k 2 { 0
2

1 e k1  k 2 e m
2

(m  k 2 ) e ( m  1)
2 2

! m  2m  1 m  k1 m  k1 { (m  k 2 )
Fall 2003 Costas Busch

2

2
51

L ! {a b : n u 0} a
m
2

n

2

n

b ! uvxyz
2

m

| vxy |e m
2

| vy |u 1

m  k1 { (m  k 2 )
m  k1 m  k2 a b
2

! uv xy z  L
52

0

0

Fall 2003

Costas Busch

L ! {a b : n u 0} a
m
2

n

2

n

b ! uvxyz

m

| vxy |e m
0

| vy |u 1
0

However, from Pumping Lemma:

uv xy z  L
0

m  k1 m  k2 a b

2

! uv xy z  L
53

0

Fall 2003 Costas Busch

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

Fall 2003

Costas Busch

54

In all cases we obtained a contradiction Therefore: The original assumption that

L ! {a b : n u 0}
is context-free must be wrong

n

2

n

Conclusion:
Fall 2003

L is not context-free
Costas Busch 55