Thus - Suraj @ LUMS

Non-regular languages
Courtesy Costas Busch - RPI
1
{a b : n  0}
n n
Non-regular languages
{vv : v {a, b}*}
R
Regular languages
a *b
b*c  a
b  c ( a  b) *
etc...
Courtesy Costas Busch - RPI
2
How can we prove that a language
is not regular?
L
Prove that there is no DFA that accepts
L
Problem: this is not easy to prove
Solution: the Pumping Lemma !!!
Courtesy Costas Busch - RPI
3
The Pigeonhole Principle
Courtesy Costas Busch - RPI
4
4 pigeons
3 pigeonholes
Courtesy Costas Busch - RPI
5
A pigeonhole must
contain at least two pigeons
Courtesy Costas Busch - RPI
6
n pigeons
...........
m
pigeonholes
nm
...........
Courtesy Costas Busch - RPI
7
The Pigeonhole Principle
n pigeons
m
pigeonholes
nm
There is a pigeonhole
with at least 2 pigeons
...........
Courtesy Costas Busch - RPI
8
The Pigeonhole Principle
and
DFAs
Courtesy Costas Busch - RPI
9
DFA with
b
q1
4
states
b
b
a
q2
b
q3
a
Courtesy Costas Busch - RPI
b
q4
a
10
In walks of strings:
no state
is repeated
a
aa
aab
b
q1
b
b
a
q2
a
q3
a
Courtesy Costas Busch - RPI
b
q4
a
11
In walks of strings:
a state
is repeated
aabb
bbaa
abbabb
abbbabbabb...
b
q1
b
b
a
q2
a
q3
a
Courtesy Costas Busch - RPI
b
q4
a
12
If string
w has length | w |  4 :
Then the transitions of string w
are more than the states of the DFA
Thus, a state must be repeated
b
q1
b
b
a
q2
a
q3
a
Courtesy Costas Busch - RPI
b
q4
a
13
In general, for any DFA:
String
A state
w has length  number of states
q
walk of
must be repeated in the walk of
w
w
......
q
......
Repeated state
Courtesy Costas Busch - RPI
14
In other words for a string
w:
a
transitions are pigeons
q
states are pigeonholes
walk of
w
......
q
......
Repeated state
Courtesy Costas Busch - RPI
15
The Pumping Lemma
Courtesy Costas Busch - RPI
16
Take an infinite regular language L
There exists a DFA that accepts
L
m
states
Courtesy Costas Busch - RPI
17
Take string
w with w L
There is a walk with label
w:
.........
walk
w
Courtesy Costas Busch - RPI
18
If string
w has length | w |  m
(number
of states
of DFA)
then, from the pigeonhole principle:
a state is repeated in the walk
......
walk
q
w
......
w
Courtesy Costas Busch - RPI
19
Let q be the first state repeated in the
walk of w
......
walk
q
......
w
Courtesy Costas Busch - RPI
20
Write
w x y z
y
......
x
q
Courtesy Costas Busch - RPI
......
z
21
Observations:
length
length
| x y |  m number
of states
of DFA
| y | 1
y
......
x
q
Courtesy Costas Busch - RPI
......
z
22
Observation:
The string
is accepted
xz
y
......
x
q
Courtesy Costas Busch - RPI
......
z
23
Observation:
The string
is accepted
xyyz
y
......
x
q
Courtesy Costas Busch - RPI
......
z
24
Observation:
The string
is accepted
xyyyz
y
......
x
q
Courtesy Costas Busch - RPI
......
z
25
In General:
The string
is accepted
i
xy z
i  0, 1, 2, ...
y
......
x
q
Courtesy Costas Busch - RPI
......
z
26
In General:
i
x y z ∈L
i  0, 1, 2, ...
Language accepted by the DFA
y
......
x
q
Courtesy Costas Busch - RPI
......
z
27
In other words, we described:
The Pumping Lemma !!!
Courtesy Costas Busch - RPI
28
The Pumping Lemma:
• Given a infinite regular language
• there exists an integer
• for any string
• we can write
• with
w L
L
m
with length
| w| m
w x y z
| x y |  m and | y |  1
• such that:
xy z  L
i
Courtesy Costas Busch - RPI
i  0, 1, 2, ...
29
Applications
of
the Pumping Lemma
Courtesy Costas Busch - RPI
30
Theorem: The language L  {a nb n : n  0}
is not regular
Proof:
Use the Pumping Lemma
Courtesy Costas Busch - RPI
31
L  {a b : n  0}
n n
Assume for contradiction
that L is a regular language
Since L is infinite
we can apply the Pumping Lemma
Courtesy Costas Busch - RPI
32
L  {a b : n  0}
n n
Let
m
be the integer in the Pumping Lemma
Pick a string
w such that: w  L
length
We pick
| w| m
wa b
m m
Courtesy Costas Busch - RPI
33
Write:
a b xyz
m m
From the Pumping Lemma
it must be that length | x
y |  m, | y | 1
m
xyz  a b
m m
 a...aa...aa...ab...b
x
Thus:
m
y
z
y  a , k 1
k
Courtesy Costas Busch - RPI
34
x y za b
y  a , k 1
m m
k
From the Pumping Lemma:
xy z  L
i
i  0, 1, 2, ...
Thus:
xy z  L
2
Courtesy Costas Busch - RPI
35
x y za b
y  a , k 1
m m
k
From the Pumping Lemma:
xy z  L
2
mk
m
xy z  a...aa...aa...aa...ab...b  L
2
x
Thus:
a
y
y
z
m k m
b L
Courtesy Costas Busch - RPI
36
a
BUT:
m k m
b L
k ≥1
L  {a b : n  0}
n n
a
m k m
b L
CONTRADICTION!!!
Courtesy Costas Busch - RPI
37
Therefore:
Our assumption that L
is a regular language is not true
Conclusion: L is not a regular language
Courtesy Costas Busch - RPI
38
Non-regular languages
{a b : n  0}
n n
Regular languages
Courtesy Costas Busch - RPI
39
Non-regular languages
L  {vv : v  *}
R
Regular languages
Courtesy Costas Busch - RPI
40
Theorem: The language
L  {vv : v  *}
R
  {a, b}
is not regular
Proof:
Use the Pumping Lemma
Courtesy Costas Busch - RPI
41
L  {vv : v  *}
R
Assume for contradiction
that L is a regular language
Since L is infinite
we can apply the Pumping Lemma
Courtesy Costas Busch - RPI
42
L  {vv : v  *}
R
Let
m
be the integer in the Pumping Lemma
Pick a string
w such that: w  L
length
We pick
and
| w| m
wa b b a
m m m m
Courtesy Costas Busch - RPI
43
Write
a b b a xyz
m m m m
From the Pumping Lemma
it must be that length | x
m
y |  m, | y | 1
m m m
xyz  a...aa...a...ab...bb...ba...a
x
Thus:
y
z
y  a , k 1
k
Courtesy Costas Busch - RPI
44
x y za b b a
y  a , k 1
m m m m
k
From the Pumping Lemma:
xy z  L
i
i  0, 1, 2, ...
Thus:
xy z  L
2
Courtesy Costas Busch - RPI
45
x y za b b a
y  a , k 1
m m m m
k
From the Pumping Lemma:
xy z  L
2
m m m
m+k
2
xy z = a...aa...aa...a...ab...bb...ba...a ∈L
x
Thus:
y
a
y
m k m m m
b b a
Courtesy Costas Busch - RPI
z
L
46
a
BUT:
m k m m m
L
b b a
k 1
L  {vv : v  *}
R
a
m k m m m
b b a
L
CONTRADICTION!!!
Courtesy Costas Busch - RPI
47
Therefore:
Our assumption that L
is a regular language is not true
Conclusion: L is not a regular language
Courtesy Costas Busch - RPI
48
Non-regular languages
n l n l
L  {a b c
: n, l  0}
Regular languages
Courtesy Costas Busch - RPI
49
Theorem: The language
n l n l
L  {a b c
: n, l  0}
is not regular
Proof:
Use the Pumping Lemma
Courtesy Costas Busch - RPI
50
n l n l
L  {a b c
: n, l  0}
Assume for contradiction
that L is a regular language
Since L is infinite
we can apply the Pumping Lemma
Courtesy Costas Busch - RPI
51
n l n l
L  {a b c
Let
m
: n, l  0}
be the integer in the Pumping Lemma
Pick a string
w such that: w  L
length
We pick
and
| w| m
wa b c
m m 2m
Courtesy Costas Busch - RPI
52
Write
m m 2m
a b c
xyz
From the Pumping Lemma
it must be that length | x
y |  m, | y | 1
m
m
2m
xyz  a...aa...aa...ab...bc...cc...c
x
Thus:
y
z
y  a , k 1
k
Courtesy Costas Busch - RPI
53
x y za b c
m m 2m
y  a , k 1
From the Pumping Lemma:
k
xy z  L
i
i  0, 1, 2, ...
Thus:
0
x y z = xz ∈ L
Courtesy Costas Busch - RPI
54
x y za b c
y  a , k 1
m m 2m
k
xz  L
From the Pumping Lemma:
mk
m
2m
xz  a...aa...ab...bc...cc...c  L
x
Thus:
z
a
mk m 2 m
b c
Courtesy Costas Busch - RPI
L
55
a
BUT:
mk m 2 m
b c
n l n l
L  {a b c
a
mk m 2 m
b c
L
k 1
: n, l  0}
L
CONTRADICTION!!!
Courtesy Costas Busch - RPI
56
Therefore:
Our assumption that L
is a regular language is not true
Conclusion: L is not a regular language
Courtesy Costas Busch - RPI
57
Non-regular languages
L  {a : n  0}
n!
Regular languages
Courtesy Costas Busch - RPI
58
Theorem: The language
L  {a : n  0}
n!
is not regular
n!  1  2  (n  1)  n
Proof:
Use the Pumping Lemma
Courtesy Costas Busch - RPI
59
L  {a : n  0}
n!
Assume for contradiction
that L is a regular language
Since L is infinite
we can apply the Pumping Lemma
Courtesy Costas Busch - RPI
60
L  {a : n  0}
n!
Let
m
be the integer in the Pumping Lemma
Pick a string
w such that: w  L
length
We pick
wa
| w| m
m!
Courtesy Costas Busch - RPI
61
Write
a
m!
xyz
From the Pumping Lemma
it must be that length | x
y |  m, | y | 1
m
xyz  a
m!
m!m
 a...aa...aa...aa...aa...a
x
Thus:
y
z
y  a , 1 k  m
k
Courtesy Costas Busch - RPI
62
x y za
y  a , 1 k  m
m!
k
From the Pumping Lemma:
xy z  L
i
i  0, 1, 2, ...
Thus:
xy z  L
2
Courtesy Costas Busch - RPI
63
x y za
y  a , 1 k  m
m!
k
From the Pumping Lemma:
xy z  L
2
m!m
mk
xy z  a...aa...aa...aa...aa...aa...a  L
2
x
Thus:
y
y
a
m! k
z
L
Courtesy Costas Busch - RPI
64
a
Since:
m! k
L
1 k  m
L  {a : n  0}
n!
There must exist
p
such that:
m! k  p!
Courtesy Costas Busch - RPI
65
However:
m! k  m! m
 m! m!
for
m 1
 m!m  m!
 m!(m  1)
 (m  1)!
m! k  (m  1)!
m! k  p!
Courtesy Costas Busch - RPI
for any
p
66
a
BUT:
m! k
L
1 k  m
L  {a : n  0}
n!
a
m! k
L
CONTRADICTION!!!
Courtesy Costas Busch - RPI
67
Therefore:
Our assumption that L
is a regular language is not true
Conclusion: L is not a regular language
Courtesy Costas Busch - RPI
68
Summary
Showing regular
construct DFA, NFA
construct regular expression
show L is the union, concatenation, intersection
(regular operations) of regular languages.
Showing non-regular
pumping lemma
assume regular, apply closure properties of
regular languages and obtain a known non-regular
language.
69