More Applications of The Pumping Lemma Fall 2003 Costas Busch The Pumping Lemma: For infinite context-free language there exists an integer m such that w L, for any.
Download
Report
Transcript More Applications of The Pumping Lemma Fall 2003 Costas Busch The Pumping Lemma: For infinite context-free language there exists an integer m such that w L, for any.
More Applications
of
The Pumping Lemma
Fall 2003
Costas Busch
1
The Pumping Lemma:
For infinite context-free language
there exists an integer
m such that
w L,
for any string
L
| w | m
we can write
w uvxyz
with lengths
| vxy | m and | vy | 1
and it must be:
i i
uv xy z L,
Fall 2003
Costas Busch
for all i 0
2
Non-context free languages
{a b c : n 0}
n n n
{vv : v {a, b}}
Context-free languages
{a b : n 0}
n n
Fall 2003
{ww : w {a, b}*}
R
Costas Busch
3
Theorem: The language
L {vv : v {a, b}*}
is not context free
Proof:
Fall 2003
Use the Pumping Lemma
for context-free languages
Costas Busch
4
L {vv : v {a, b}*}
Assume for contradiction that
L
is context-free
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:
Pick any string of
we pick:
Fall 2003
m
L with length at least m
m m m m
a b a b
Costas Busch
L
6
L {vv : v {a, b}*}
We can write:
a b a b uvxyz
with lengths
| vxy | m and | vy | 1
m m m m
Pumping Lemma says:
uv xy z L
i
Fall 2003
i
for all
Costas Busch
i0
7
L {vv : v {a, b}*}
a b a b uvxyz
m m m m
| vxy | m
| vy | 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}*}
| vxy | m
a b a b uvxyz
m m m m
Case 1:
va
vxy is within the first a
k1
ya
k2
| vy | 1
m
k1 k2 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}*}
| vxy | m
a b a b uvxyz
m m m m
Case 1:
va
vxy is within the first a
k1
ya
k2
| vy | 1
m
k1 k2 1
m
m
m k1 k2 m
a ................ a b ...... b a ...... a b ...... b
z
u v2 x y 2
Fall 2003
Costas Busch
10
L {vv : v {a, b}*}
a b a b uvxyz
m m m m
Case 1:
a
| vxy | m
vxy is within the first a
m k1 k2 m m m
| vy | 1
m
b a b uv xy z L
2
2
k1 k2 1
Fall 2003
Costas Busch
11
L {vv : v {a, b}*}
a b a b uvxyz
m m m m
Case 1:
a
| vxy | m
| vy | 1
vxy is within the first a
m k1 k2 m m m
m
b a b uv xy z L
2
However, from Pumping Lemma:
2
uv xy z L
2
2
Contradiction!!!
Fall 2003
Costas Busch
12
L {vv : v {a, b}*}
m m m m
| vxy | m
a b a b uvxyz
Case 2: v is in the first a
y is in the first b
va
k1
yb
k2
| vy | 1
m
m
k1 k2 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 | m
a b a b uvxyz
Case 2: v is in the first a
y is in the first b
va
k1
yb
k2
| vy | 1
m
m
k1 k2 1
m
m
m k2
m k1
a ............ a b ............ b a ...... a b ...... b
2 x
2
z
u
v
y
Fall 2003
Costas Busch
14
L {vv : v {a, b}*}
m m m m
| vxy | m
a b a b uvxyz
Case 2: v is in the first a
y is in the first b
a
m k1 m k2 m m
b
| vy | 1
m
m
a b uv xy z L
2
2
k1 k2 1
Fall 2003
Costas Busch
15
L {vv : v {a, b}*}
m m m m
| vxy | m
a b a b uvxyz
Case 2: v is in the first a
y is in the first b
a
m k1 m k2 m m
b
| vy | 1
m
m
a b uv xy z L
2
However, from Pumping Lemma:
2
uv xy z L
2
2
Contradiction!!!
Fall 2003
Costas Busch
16
L {vv : v {a, b}*}
m m m m
| vxy | m
a b a b uvxyz
| vy | 1
m m
Case 3: v overlaps the first a b
y is in the first b
v
k1 k 2
a b
yb
k3
m
k1, k2 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 | m
a b a b uvxyz
| vy | 1
m m
Case 3: v overlaps the first a b
y is in the first b
v
k1 k 2
a b
yb
k3
m
k1, k2 1
k2
k1 m k3
m
m
m
a ...... a b ... b a ... a b ......... b a ...... a b ...... b
2
2
u
z
x
v
y
Fall 2003
Costas Busch
18
L {vv : v {a, b}*}
m m m m
| vxy | m
a b a b uvxyz
| vy | 1
m m
Case 3: v overlaps the first a b
y is in the first b
m k2 k1 m k3 m m
a b a b
a b
m
uv xy z L
2
2
k1, k2 1
Fall 2003
Costas Busch
19
L {vv : v {a, b}*}
m m m m
| vxy | m
a b a b uvxyz
| vy | 1
m m
Case 3: v overlaps the first a b
y is in the first b
m k2 k1 k3 m m
a b a b a b
m
uv xy z L
2
However, from Pumping Lemma:
2
uv xy z L
2
2
Contradiction!!!
Fall 2003
Costas Busch
20
L {vv : v {a, b}*}
m m m m
| vxy | m
a b a b uvxyz
Case 4: v in the first a
| vy | 1
m
m m
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:
m m m m
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
Costas Busch
22
More cases:
m m m m
vxy overlaps a b a b
or
m m m m
a b a b
Analysis is similar to cases 2,3,4:
m m m m
a b a b
Fall 2003
Costas Busch
23
There are no other cases to consider
Since | vxy | m, it is impossible
vxy to overlap:
m m m m
a b a b
nor
m m m m
a b a b
nor
m m m m
a b a b
Fall 2003
Costas Busch
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
{ww : w {a, b}}
{a b c : n 0}
n n n
{a : n 0}
n!
Context-free languages
{a b : n 0}
n n
Fall 2003
{ww : w {a, b}*}
R
Costas Busch
26
Theorem: The language
n!
L {a : n 0}
is not context free
Proof:
Fall 2003
Use the Pumping Lemma
for context-free languages
Costas Busch
27
L {a : n 0}
n!
Assume for contradiction that
L
is context-free
Since L is context-free and infinite
we can apply the pumping lemma
Fall 2003
Costas Busch
28
L {a : n 0}
n!
Pumping Lemma gives a magic number
such that:
Pick any string of
we pick:
Fall 2003
m
L with length at least m
a
m!
L
Costas Busch
29
L {a : n 0}
n!
We can write:
with lengths
a
m!
uvxyz
| vxy | m and | vy | 1
Pumping Lemma says:
uv xy z L
i
Fall 2003
i
for all
Costas Busch
i0
30
L {a : n 0}
n!
a
m!
uvxyz
| vxy | m
| vy | 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 0}
n!
a
m!
| vxy | m
uvxyz
| vy | 1
m!
a ............... a
u v x y z
va
Fall 2003
k1
ya
k2
Costas Busch
1 k1 k2 m
32
L {a : n 0}
n!
a
m!
| vxy | m
uvxyz
| vy | 1
m!k1 k2
a ........................... a
u v2 x y 2 z
va
Fall 2003
k1
ya
k2
Costas Busch
1 k1 k2 m
33
L {a : n 0}
n!
a
m!
| vxy | m
uvxyz
m! k
a ........................... a
u v2 x y 2 z
va
Fall 2003
k1
ya
k2
Costas Busch
| vy | 1
k k1 k2
1 k m
34
L {a : n 0}
n!
a
m!
| vxy | m
uvxyz
a
m! k
| vy | 1
uv xy z
2
2
1 k m
Fall 2003
Costas Busch
35
Since
1 k m , for m 2 we have:
m! k m! m
m! m!m
m!(1 m)
(m 1)!
m! m! k (m 1)!
Fall 2003
Costas Busch
36
L {a : n 0}
n!
a
m!
uvxyz
| vxy | m
| vy | 1
m! m! k (m 1)!
a
Fall 2003
m! k
uv xy z L
2
Costas Busch
2
37
L {a : n 0}
n!
a
m!
uvxyz
| vxy | m
However, from Pumping Lemma:
a
m! k
| vy | 1
uv xy z L
2
2
uv xy z L
2
2
Contradiction!!!
Fall 2003
Costas Busch
38
We obtained a contradiction
Therefore: The original assumption that
L {a : n 0}
n!
is context-free must be wrong
Conclusion:
Fall 2003
L is not context-free
Costas Busch
39
Non-context free languages
{ww : w {a, b}}
{a b c : n 0}
n n n
n2 n
{a : n 0}
n!
{a b : n 0}
Context-free languages
{a b : n 0}
n n
Fall 2003
{ww : w {a, b}*}
R
Costas Busch
40
Theorem: The language
n2 n
L {a b : n 0}
is not context free
Proof:
Fall 2003
Use the Pumping Lemma
for context-free languages
Costas Busch
41
2
L {a b : n 0}
n
n
Assume for contradiction that
L
is context-free
Since L is context-free and infinite
we can apply the pumping lemma
Fall 2003
Costas Busch
42
2
L {a b : n 0}
n
n
Pumping Lemma gives a magic number
such that:
Pick any string of
we pick:
Fall 2003
m
L with length at least m
a
m
2
b
m
Costas Busch
L
43
2
L {a b : n 0}
n
We can write:
with lengths
a
m
2
n
b uvxyz
m
| vxy | m and | vy | 1
Pumping Lemma says:
uv xy z L
i
Fall 2003
i
for all
Costas Busch
i0
44
2
L {a b : n 0}
n
a
m
2
n
| vxy | m
b uvxyz
m
| vy | 1
We examine all the possible locations
of string
Fall 2003
vxy in a
Costas Busch
m2 m
b
45
2
L {a b : n 0}
n
a
m
2
n
| vxy | m
b uvxyz
m
Most complicated case:
| vy | 1
m
v is in a
m
y is in b
2
m
m
a ..................... a b ...... b
u
v x y z
Fall 2003
Costas Busch
46
2
L {a b : n 0}
n
a
m
2
va
n
| vxy | m
b uvxyz
k1
m
yb
k2
| vy | 1
1 k1 k2 m
2
m
m
a ..................... a b ...... b
u
v x y z
Fall 2003
Costas Busch
47
2
L {a b : n 0}
n
a
m
2
n
| vxy | m
b uvxyz
m
Most complicated sub-case:
va
k1
yb
k2
k1 0
and
| vy | 1
k2 0
1 k1 k2 m
2
m
m
a ..................... a b ...... b
u
v x y z
Fall 2003
Costas Busch
48
2
L {a b : n 0}
n
a
m
2
n
| vxy | m
b uvxyz
m
Most complicated sub-case:
va
k1
yb
k1 0
k2
and
| vy | 1
k2 0
1 k1 k2 m
m k1 m k2
a ............... a b ... b
u
0 x 0z
2
v
Fall 2003
Costas Busch
y
49
2
L {a b : n 0}
n
a
m
2
n
| vxy | m
b uvxyz
m
Most complicated sub-case:
va
k1
yb
a
Fall 2003
k2
m 2 k1 m k2
b
k1 0
and
| vy | 1
k2 0
1 k1 k2 m
uv xy z
Costas Busch
0
0
50
k1 0
and
k2 0
1 k1 k2 m
(m k 2 ) (m 1)
2
2
m 2m 1
2
m k1
2
m k1 (m k2 )
2
Fall 2003
Costas Busch
2
51
2
L {a b : n 0}
n
a
m
2
n
| vxy | m
b uvxyz
m
m k1 (m k2 )
2
2
m k1 m k2
a
b
Fall 2003
| vy | 1
2
uv xy z L
Costas Busch
0
0
52
2
L {a b : n 0}
n
a
m
2
n
| vxy | m
b uvxyz
m
uv xy z L
0
However, from Pumping Lemma:
2
m k1 m k2
a
b
| vy | 1
0
uv xy z L
0
0
Contradiction!!!
Fall 2003
Costas Busch
53
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
n2 n
L {a b : n 0}
is context-free must be wrong
Conclusion:
Fall 2003
L is not context-free
Costas Busch
55