Languages and Finite Automata

Download Report

Transcript Languages and Finite Automata

More Applications
of
The Pumping Lemma
Prof. Busch - LSU
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,
for all i  0
Prof. Busch - LSU
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
{ww : w  {a, b}*}
R
Prof. Busch - LSU
3
Theorem: The language
L  {vv : v {a, b}*}
is not context free
Proof:
Use the Pumping Lemma
for context-free languages
Prof. Busch - LSU
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
Prof. Busch - LSU
5
L  {vv : v {a, b}*}
Pumping Lemma gives a magic number
such that:
Pick any string of
we pick:
m
L with length at least m
m m m m
a b a b
Prof. Busch - LSU
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
i
for all
Prof. Busch - LSU
i0
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
Prof. Busch - LSU
8
L  {vv : v {a, b}*}
| vxy | m
a b a b  uvxyz
m m m m
Case 1:
va
vxy is within the first a
k1
ya
k2
| vy | 1
m
k1  k2  1
m
m
m
m
a ...... a b ...... b a ...... a b ...... b
z
u vx y
Prof. Busch - LSU
9
L  {vv : v {a, b}*}
| vxy | m
a b a b  uvxyz
m m m m
Case 1:
va
vxy is within the first a
k1
ya
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
Prof. Busch - LSU
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
Prof. Busch - LSU
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!!!
Prof. Busch - LSU
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
va
k1
yb
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
Prof. Busch - LSU
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
va
k1
yb
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
Prof. Busch - LSU
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
Prof. Busch - LSU
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!!!
Prof. Busch - LSU
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
yb
k3
m
k1, k2  1
m
m
m
m
a ...... a b ...... b a ...... a b ...... b
u
v xy z
Prof. Busch - LSU
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
yb
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
Prof. Busch - LSU
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
Prof. Busch - LSU
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!!!
Prof. Busch - LSU
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
Prof. Busch - LSU
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
Prof. Busch - LSU
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
Prof. Busch - LSU
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
Prof. Busch - LSU
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:
L is not context-free
Prof. Busch - LSU
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
{ww : w  {a, b}*}
R
Prof. Busch - LSU
26
Theorem: The language
n!
L  {a : n  0}
is not context free
Proof:
Use the Pumping Lemma
for context-free languages
Prof. Busch - LSU
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
Prof. Busch - LSU
28
L  {a : n  0}
n!
Pumping Lemma gives a magic number
such that:
Pick any string of
we pick:
m
L with length at least m
a
m!
L
Prof. Busch - LSU
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
i
for all
Prof. Busch - LSU
i0
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
Prof. Busch - LSU
31
L  {a : n  0}
n!
a
m!
| vxy | m
 uvxyz
| vy | 1
m!
a ............... a
u v x y z
va
k1
ya
k2
Prof. Busch - LSU
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
va
k1
ya
k2
Prof. Busch - LSU
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
va
k1
ya
k2
Prof. Busch - LSU
| 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
Prof. Busch - LSU
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)!
Prof. Busch - LSU
36
L  {a : n  0}
n!
a
m!
 uvxyz
| vxy | m
| vy | 1
m! m! k  (m  1)!
a
m! k
 uv xy z  L
2
Prof. Busch - LSU
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!!!
Prof. Busch - LSU
38
We obtained a contradiction
Therefore: The original assumption that
L  {a : n  0}
n!
is context-free must be wrong
Conclusion:
L is not context-free
Prof. Busch - LSU
39
Non-context free languages
{ww : w {a, b}}
{a b c : n  0}
n n n
n2 n
{a b : n  0}
{a : n  0}
n!
Context-free languages
{a b : n  0}
n n
{ww : w  {a, b}*}
R
Prof. Busch - LSU
40
Theorem: The language
n2 n
L  {a b : n  0}
is not context free
Proof:
Use the Pumping Lemma
for context-free languages
Prof. Busch - LSU
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
Prof. Busch - LSU
42
2
L  {a b : n  0}
n
n
Pumping Lemma gives a magic number
such that:
Pick any string of
we pick:
m
L with length at least m
a
m
2
b
m
Prof. Busch - LSU
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
i
for all
Prof. Busch - LSU
i0
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
vxy in a
m2 m
Prof. Busch - LSU
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
Prof. Busch - LSU
46
2
L  {a b : n  0}
n
a
m
2
va
n
| vxy | m
b  uvxyz
k1
m
yb
k2
| vy | 1
1  k1  k2  m
2
m
m
a ..................... a b ...... b
u
v x y z
Prof. Busch - LSU
47
2
L  {a b : n  0}
n
a
m
2
n
| vxy | m
b  uvxyz
m
Most complicated sub-case:
va
k1
yb
k2
k1  0
and
| vy | 1
k2  0
1  k1  k2  m
2
m
m
a ..................... a b ...... b
u
v x y z
Prof. Busch - LSU
48
2
L  {a b : n  0}
n
a
m
2
n
| vxy | m
b  uvxyz
m
Most complicated sub-case:
va
k1
yb
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
Prof. Busch - LSU
y
49
2
L  {a b : n  0}
n
a
m
2
n
| vxy | m
b  uvxyz
m
Most complicated sub-case:
va
k1
yb
a
k2
m 2  k1 m  k2
b
k1  0
and
| vy | 1
k2  0
1  k1  k2  m
 uv xy z
Prof. Busch - LSU
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
Prof. Busch - LSU
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
| vy | 1
2
 uv xy z  L
Prof. Busch - LSU
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!!!
Prof. Busch - LSU
53
When we examine the rest of the cases
we also obtain a contradiction
Prof. Busch - LSU
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:
L is not context-free
Prof. Busch - LSU
55