Você está na página 1de 76

1

Non-regular languages
(Pumping Lemma)
2
Regular languages
b a*
a c b + *
... etc
* ) ( b a c b + +
Non-regular languages
} 0 : { > n b a
n n
}*} , { : { b a v vv
R
e
3
How can we prove that a language
is not regular?
L
Prove that there is no DFA or NFA or RE or
regular grammar that accepts
L
Difficulty: this is not easy to prove
(since there is an infinite number of them)
Solution: use the Pumping Lemma !!!
4

The Pigeonhole Principle
5

pigeons
pigeonholes
4
3
6

A pigeonhole must
contain at least two pigeons
7

...........
...........
pigeons
pigeonholes
n
m
m n >
8
The Pigeonhole Principle

...........
pigeons
pigeonholes
n
m
m n >
There is a pigeonhole
with at least 2 pigeons
9
The Pigeonhole Principle

and

DFAs

10

Consider a DFA with states
4
1
q
2
q
3
q
a
b
4
q
b
a
b
b
a
a
11
Consider the walk of a long string:
1
q
2
q
3
q
a
b
4
q
b
b
b
a
a
a
aaaab
1
q
2
q
3
q
2
q
3
q
4
q
a a a a
b
A state is repeated in the walk of
(length at least 4)
aaaab
12
aaaab
1
q
2
q
3
q
2
q
3
q
4
q
a a a a
b
1
q
2
q
3
q
4
q
Pigeons:
Nests:
(Automaton states)
Are more than
Walk of
The state is repeated as a result of
the pigeonhole principle
(walk states)
Repeated
state
13
Consider the walk of a long string:
1
q
2
q
3
q
a
b
4
q
b
b
b
a
a
a
aabb
1
q
2
q
3
q
4
q
4
q
a a
b
b
A state is repeated in the walk of
(length at least 4)
Due to the pigeonhole principle:
aabb
14
aabb
1
q
2
q
3
q
4
q
Automaton States
Pigeons:
Nests:
(Automaton states)
Are more than
Walk of
The state is repeated as a result of
the pigeonhole principle
(walk states)
1
q
2
q
3
q
4
q
4
q
a a
b
b
Repeated
state
15
i
q
...... ......
Repeated state
k
w o o o
2 1
=
1
o
2
o
k
o
Walk of
i
q
....
i
q
.... .... 1
o
2
o k
o
i
o j
o
1 + i
o
1 + j
o
Arbitrary DFA
DFA of states # | | > w If ,
by the pigeonhole principle,
a state is repeated in the walk
In General:
1
q
z
q
z
q
1
q
w
16
m DFA of states # | | = > w
1
q
2
q
1 m
q
m
q
Walk of w
Pigeons:
Nests:
(Automaton states)
Are
more
than
(walk states)
i
q
....
i
q
.... ....
1
q
i
q
.... ....
z
q
A state is
repeated
17
The Pumping Lemma
18
Take an infinite regular language
L
There exists a DFA that accepts L
m
states
(contains an infinite number of strings)
19
m w > | |
(number of
states of DFA)
then, at least one state is repeated
in the walk of w
q
...... ......
1
o
2
o
k
o
Take string with L we
k
w o o o
2 1
=
Walk in DFA of
Repeated state in DFA
20
Take to be the first state repeated q
q ....
w
There could be many states repeated
q
.... ....
Second
occurrence
First
occurrence
Unique states
One dimensional projection of walk :
1
o
2
o k
o
i
o
j
o
1 + i
o
1 + j
o
21
q .... q
.... ....
Second
occurrence
First
occurrence
1
o
2
o
k
o
i
o
j
o
1 + i
o
1 + j
o
w One dimensional projection of walk :
i
x o o
1
=
j i
y o o
1 +
=
k j
z o o
1 +
=
xyz w=
We can write
22
z y x w=
q
... ...
x
y
z
In DFA:
...
...
1
o
k
o
i
o
1 + i
o
j
o
1 + j
o
contains only
first occurrence of q
23
Observation:
m y x s | |
length number
of states
of DFA
Since, in no
state is repeated
(except q)
xy
Unique States
q
...
x
y
...
1
o
i
o
1 + i
o
j
o
24
Observation:
1 | | > y
length
Since there is at least one transition in loop
q
y
...
1 + i
o
j
o
25
We do not care about the form of string
z
q
...
x
y
z
...
z may actually overlap with the paths of and x y
26
The string
is accepted
z x
Additional string:
q
... ...
x
z
...
Do not follow loop
y
...
1
o
k
o
i
o
1 + i
o
j
o
1 + j
o
27
The string
is accepted
z y y x
q
... ... ...
x
z
Follow loop
2 times
Additional string:
y
...
1
o
k
o
i
o
1 + i
o
j
o
1 + j
o
28
The string
is accepted
z y y y x
q
... ... ...
x
z
Follow loop
3 times
Additional string:
y
...
1
o
k
o
i
o
1 + i
o
j
o
1 + j
o
29
The string
is accepted
z y x
i
In General:
... , 2 , 1 , 0 = i
q
... ... ...
x
z
Follow loop
times
i
y
...
1
o
k
o
i
o
1 + i
o
j
o
1 + j
o
30
L z y x
i
e
Therefore:
... , 2 , 1 , 0 = i
Language accepted by the DFA
q
... ... ...
x
z
y
...
1
o
k
o
i
o
1 + i
o
j
o
1 + j
o
31
The Pumping Lemma:
Given a infinite regular language L
there exists an integer m
for any string with length L we
m w > | |
we can write z y x w=
with and
m y x s | | 1 | | > y
such that:
L z y x
i
e
... , 2 , 1 , 0 = i
(critical length)
32
Critical length = Pumping length
m p
33
Applications

of

the Pumping Lemma
34
Observation:
Every language of finite size has to be regular
Therefore, every non-regular language
has to be of infinite size
(contains an infinite number of strings)
(we can easily construct an NFA
that accepts every string in the language)

35
Suppose you want to prove that
An infinite language is not regular
1. Assume the opposite: is regular
2. The pumping lemma should hold for
3. Use the pumping lemma to obtain a
contradiction
L
L
L
4. Therefore, is not regular
L
36
Explanation of Step 3: How to get a contradiction
2. Choose a particular string which satisfies
the length condition
L we
3. Write
xyz w=
4. Show that L z xy w
i
e =
'
for some
1 = i
5. This gives a contradiction, since from
pumping lemma
L z xy w
i
e =
'
m w > | |
1. Let be the critical length for m
L
37
Note:
It suffices to show that
only one string
gives a contradiction
L we
You dont need to obtain
contradiction for every L we
38
Theorem:
The language } 0 : { > = n b a L
n n
is not regular
Proof: Use the Pumping Lemma
Example of Pumping Lemma application
39
Assume for contradiction
that is a regular language L
Since is infinite
we can apply the Pumping Lemma
L
} 0 : { > = n b a L
n n
40
Let be the critical length for
Pick a string such that: w
L w e
m w > | |
and length
m m
b a w=
We pick
m
} 0 : { > = n b a L
n n
L
41
with lengths
From the Pumping Lemma:
1 | | , | | > s y m y x
b ab aa aa a b a xyz
m m
... ... ... ... = =
m k a y
k
s s = 1 ,
x y z
m m
we can write z y x b a w
m m
= =
Thus:
= w
42
From the Pumping Lemma:
L z y x
i
e
... , 2 , 1 , 0 = i
Thus:
m m
b a z y x =
L z y x e
2
m k a y
k
s s = 1 ,
43
From the Pumping Lemma:
L b ab aa aa aa a z xy e = ... ... ... ... ...
2
x y z
k m+
m
Thus:
L z y x e
2
m m
b a z y x =
y
L b a
m k m
e
+
m k a y
k
s s = 1 ,
44
L b a
m k m
e
+
} 0 : { > = n b a L
n n
BUT:
L b a
m k m
e
+
CONTRADICTION!!!
1 k
45
Our assumption that
is a regular language is not true
L
Conclusion: L is not a regular language
Therefore:
END OF PROOF
46
Regular languages
Non-regular language
} 0 : { > n b a
n n
) (
* *
b a L
47
Regular languages
Non-regular languages
*} : { E e = v vv L
R
48
Theorem: The language
is not regular
Proof: Use the Pumping Lemma
*} : { E e = v vv L
R
} , { b a = E
49
Assume for contradiction
that is a regular language L
Since is infinite
we can apply the Pumping Lemma
L
*} : { E e = v vv L
R
50
m m m m
a b b a w=
We pick
Let be the critical length for
Pick a string such that: w
L w e
m w > | |
length
m
and
*} : { E e = v vv L
R
L
51
we can write:
z y x a b b a w
m m m m
= =
with lengths:
From the Pumping Lemma:
a ba bb ab a aa a xyz ... ... ... ... ... ... =
x
y
z
m
m m m
1 | | , | | > s y m y x
m k a y
k
s s = 1 ,
Thus:
= w
52
From the Pumping Lemma:
L z y x
i
e
... , 2 , 1 , 0 = i
Thus:
L z y x e
2
m m m m
a b b a z y x =
m k a y
k
s s = 1 ,
53
From the Pumping Lemma:
L a ba bb ab a aa aa a z xy ... ... ... ... ... ... ... =
2
x
y
z
k m+
m m m
y
L z y x e
2
Thus:
m m m m
a b b a z y x =
L a b b a
m m m k m
e
+
m k a y
k
s s = 1 ,
54
L a b b a
m m m k m
e
+
L a b b a
m m m k m
e
+
BUT:
CONTRADICTION!!!
1 > k
*} : { E e = v vv L
R
55
Our assumption that
is a regular language is not true
L
Conclusion: L is not a regular language
Therefore:
END OF PROOF
56
Regular languages
Non-regular languages
} 0 , : { > =
+
l n c b a L
l n l n
57
Theorem: The language
is not regular
Proof: Use the Pumping Lemma
} 0 , : { > =
+
l n c b a L
l n l n
58
Assume for contradiction
that is a regular language L
Since is infinite
we can apply the Pumping Lemma
L
} 0 , : { > =
+
l n c b a L
l n l n
59
m m m
c b a w
2
=
We pick
Let be the critical length of
Pick a string such that: w
L w e
m w > | |
length
m
} 0 , : { > =
+
l n c b a L
l n l n
and
L
60
We can write
z y x c b a w
m m m
= =
2
With lengths
From the Pumping Lemma:
c cc bc ab aa aa a xyz ... ... ... ... ... ... =
x
y
z
m m
m 2
1 | | , | | > s y m y x
Thus:
= w
m k a y
k
s s = 1 ,
61
From the Pumping Lemma:
L z y x
i
e
... , 2 , 1 , 0 = i
Thus:
m m m
c b a z y x
2
=
L xz z y x =
0
m k a y
k
s s = 1 ,
62
From the Pumping Lemma:
L c cc bc ab aa a xz e = ... ... ... ... ...
x
z
k m
m
m 2
m m m
c b a z y x
2
=
L xz e
Thus:
L c b a
m m k m
e
2
m k a y
k
s s = 1 ,
63
L c b a
m m k m
e
2
L c b a
m m k m
e
2
BUT:
CONTRADICTION!!!
} 0 , : { > =
+
l n c b a L
l n l n
1 > k
64
Our assumption that
is a regular language is not true
L
Conclusion: L is not a regular language
Therefore:
END OF PROOF
65
Regular languages
Non-regular languages
} 0 : {
!
> = n a L
n
66
Theorem: The language
is not regular
Proof: Use the Pumping Lemma
} 0 : {
!
> = n a L
n
n n n = ) 1 ( 2 1 !
67
Assume for contradiction
that is a regular language L
Since is infinite
we can apply the Pumping Lemma
L
} 0 : {
!
> = n a L
n
68
! m
a w=
We pick
Let be the critical length of
Pick a string such that: w
L w e
m w > | |
length
m
} 0 : {
!
> = n a L
n
L
69
We can write
z y x a w
m
= =
!
With lengths
From the Pumping Lemma:
a aa aa aa aa a a xyz
m
... ... ... ... ...
!
= =
x y
z
m
m m !
1 | | , | | > s y m y x
m k a y
k
s s = 1 ,
Thus:
= w
70
From the Pumping Lemma:
L z y x
i
e
... , 2 , 1 , 0 = i
Thus:
! m
a z y x =
L z y x e
2
m k a y
k
s s = 1 ,
71
From the Pumping Lemma:
L a aa aa aa aa aa a z xy e = ... ... ... ... ... ...
2
x y
z
k m+ m m !
Thus:
! m
a z y x = m k a y
k
s s = 1 ,
L z y x e
2
y
L a
k m
e
+ !
72
L a
k m
e
+ !
! ! p k m = +
} 0 : {
!
> = n a L
n
Since:
m k s s 1
There must exist such that: p
73
However:
)! 1 (
) 1 ( !
! !
! !
!
+ =
+ =
+ <
+ s
+ s
m
m m
m m m
m m
m m k m+ !
for
1 > m
)! 1 ( ! + < + m k m
! ! p k m = +
for any p
74
L a
k m
e
+ !
L a
k m
e
+ !
BUT:
CONTRADICTION!!!
} 0 : {
!
> = n a L
n
m k s s 1
75
Our assumption that
is a regular language is not true
L
Conclusion: L is not a regular language
Therefore:
END OF PROOF
76
Assignment (10%)
From your textbook;
Introduction to Formal Languages and Automat, third
Edition, Peter Linz.
On pages 122 124, do the questions: 1, 3, 4, 7, and 9
(a, c, e)

Prepare a report and submit on May 15, 2012 during
class time.

Você também pode gostar