You are on page 1of 46

Non-regular languages

(Pumping Lemma)

Costas Busch - LSU 1


n n
{a b : n  0}
Non-regular languages
R
{vv : v {a, b}*}

Regular languages
a *b b*c  a
b  c ( a  b) *
etc...
Costas Busch - LSU 2
How can we prove that a language L
is not regular?

Prove that there is no DFA or NFA or RE


that accepts L

Difficulty: this is not easy to prove


(since there is an infinite number of them)

Solution: use the Pumping Lemma !!!


Costas Busch - LSU 3
The Pigeonhole Principle

Costas Busch - LSU 4


4 pigeons

3 pigeonholes

Costas Busch - LSU 5


A pigeonhole must
contain at least two pigeons

Costas Busch - LSU 6


n pigeons

...........

m pigeonholes nm

...........

Costas Busch - LSU 7


The Pigeonhole Principle

n pigeons
m pigeonholes
There is a pigeonhole
nm with at least 2 pigeons

...........

Costas Busch - LSU 8


The Pigeonhole Principle

and

DFAs

Costas Busch - LSU 9


Consider a DFA with 4 states

b
b b

a a b
q1 q2 q3 q4
a a
Costas Busch - LSU 10
Consider the walk of a “long’’ string: aaaab
(length at least 4)

A state is repeated in the walk of aaaab


q1 a q2 a q3 a q2 a q3 b q4

b
b b

a a b
q1 q2 q3 q4
a a
Costas Busch - LSU 11
The state is repeated as a result of
the pigeonhole principle

Walk of aaaab
Pigeons: q1 a q2 a q3 a q2 a q3 b q4
(walk states)

Are more than

Nests: q1 q2 q3 q4
(Automaton states) Repeated Repeated
state state
Costas Busch - LSU 12
Consider the walk of a “long’’ string: aabb
(length at least 4)

Due to the pigeonhole principle:


A state is repeated in the walk of aabb
q1 a q2 a q3 b q4 b q4

b
b b

a a b
q1 q2 q3 q4
a
Costas Busch - LSU
a 13
The state is repeated as a result of
the pigeonhole principle:

Walk of aabb
Pigeons: q1 a q2 a q3 b q4 b q4
(walk states)

Are more than

Nests: q1 q2 q3 q4
(Automaton states) Repeated
Automaton States
state
Costas Busch - LSU 14
In General: If | w |  # states of DFA ,
by the pigeonhole principle,
a state is repeated in the walk w

Walk of w  1 2  k
q1 1  2 ....  i q  i 1 .... j
qi
 j 1
.... k
qz
i

Arbitrary DFA
q1 1 2
...... ...... k
qi qz
Repeated state
Costas Busch - LSU 15
| w |  # states of DFA  p
Number of states in walk is at least p  1
Pigeons: Walk
(walk states)
of w
q1 .... qi .... qi .... qz

Are
more
than
q
Nests: 1 q2 .... qi .... q p 1 qp
(Automaton states) A state is
repeated
Costas Busch - LSU 16
The Pumping Lemma

Costas Busch - LSU 17


Take an infinite regular language L
(contains an infinite number of strings)

There exists a DFA that accepts L

p
states

Costas Busch - LSU 18


Take string w L with | w |  p
(number of
states of DFA)

then, at least one state is repeated


in the walk of w

Walk in DFA of
w  1 2  k
1  2 ...... q ......  k
Repeated state in DFA
Costas Busch - LSU 19
There could be many states repeated

Take q to be the first state repeated

One dimensional projection of walk w:


First Second
occurrence occurrence
 2 ....  i q i 1 .... j
1 q ....  k
 j 1

Unique states

Costas Busch - LSU 20


We can write w  xyz

One dimensional projection of walk w:


First Second
occurrence occurrence
 2 ....  i q i 1 .... j  j 1
1 q ....  k

x  1 i y   i 1 j z   j 1 k

Costas Busch - LSU 21


In DFA: w x y z
Where y
corresponds to substring
between first and second occurrence of q
y
...

j  i 1
1
... i
q  j 1
... ... k

x z
Costas Busch - LSU 22
Observation: length | x y |  p number
of states
of DFA

y
... Because of
unique states in xy
j  i 1
1
... i
q Since, in xy no
state is repeated
x Costas Busch - LSU
(except q) 23
Observation: length | y | 1
Since there is at least one transition in loop

y
...

j  i 1

Costas Busch - LSU 24


We do not care about the form of string z

z may actually overlap with the paths of x and y


y
...

z
... q

x Costas Busch - LSU 25


Additional string: The string xz
is accepted

Do not follow loop


y
...

j  i 1
1
... i
q  j 1
... ... k

x z
Costas Busch - LSU 26
Additional string: The string xyyz
is accepted

Follow loop y
2 times
...

j  i 1
1
... i
q  j 1
... ... k

x z
Costas Busch - LSU 27
Additional string: The string xyyyz
is accepted

Follow loop y
3 times
...

j  i 1
1
... i
q  j 1
... ... k

x z
Costas Busch - LSU 28
i
In General: The string xy z
is accepted i  0, 1, 2, ...

Follow loop y
i times
...

j  i 1
1
... i
q  j 1
... ... k

x z
Costas Busch - LSU 29
Therefore: x y z L
i
i  0, 1, 2, ...

Language accepted by the DFA


y
...

j  i 1
1
... i
q  j 1
... ... k

x z
Costas Busch - LSU 30
In other words, we described:

The Pumping Lemma !!!

Costas Busch - LSU 31


The Pumping Lemma:
• Given a infinite regular language L
• there exists an integer p (critical length)

• for any string w L with length | w |  p


• we can write w x y z

• with |x y|  p and | y | 1
i i  0, 1, 2, ...
• such that: xy z  L
Costas Busch - LSU 32
Applications

of

the Pumping Lemma

Costas Busch - LSU 33


Observation:
Every language of finite size has to be regular
(we can easily construct an NFA
that accepts every string in the language)

Therefore, every non-regular language


has to be of infinite size
(contains an infinite number of strings)

Costas Busch - LSU 34


Suppose you want to prove that
αn infinite language L is not regular

1. Assume the opposite: L is regular

2. The pumping lemma should hold for L


3. Use the pumping lemma to obtain a
contradiction

4. Therefore, L is not regular

Costas Busch - LSU 35


Explanation of Step 3: How to get a contradiction
1. Let pbe the critical length for L
. Choose a particular string w which
L satisfies
the length condition | w | p
3. Write w  xyz
4. Show that w  xy z  L
i
for some i 1

5. This gives a contradiction, since from


pumping lemma w  xy z  L i

Costas Busch - LSU 36


Note: It suffices to show that
only one string w L
gives a contradiction

You don’t need to obtain


contradiction for every w L

Costas Busch - LSU 37


Example of Pumping Lemma application

Theorem: The language L  {a nb n : n  0}


is not regular

Proof: Use the Pumping Lemma

Costas Busch - LSU 38


n n
L  {a b : n  0}

Assume for contradiction


that L is a regular language

Since L is infinite
we can apply the Pumping Lemma

Costas Busch - LSU 39


n n
L  {a b : n  0}

Let p be the critical length for L

Pick a string w such that: w  L


and length | w| p

We pick wa b p p

Costas Busch - LSU 40


From the Pumping Lemma:

we can write wa b  x y z p p

with lengths | x y |  p, | y | 1

p p
w  xyz  a b
p p
 a...aa...aa...ab...b
x y z

Thus: y  a , 1 k  p
k

Costas Busch - LSU 41


x y za b
p p
y  a , 1 k  p
k

i
From the Pumping Lemma: xy z  L
i  0, 1, 2, ...

2
Thus: xy z  L

Costas Busch - LSU 42


x y za bp p
y  a , 1 k  p
k

2
From the Pumping Lemma: xy z  L

pk p
2
xy z  a...aa...aa...aa...ab...b  L
x y y z

pk
Thus: a b L
p
Costas Busch - LSU 43
pk
a b L
p
k≥ 1

n n
BUT: L  {a b : n  0}

pk
a b Lp

CONTRADICTION!!!
Costas Busch - LSU 44
Therefore: Our assumption that L
is a regular language is not true

Conclusion: L is not a regular language

END OF PROOF
Costas Busch - LSU 45
n n
Non-regular language {a b : n  0}

Regular languages
* *
L(a b )

 *

Costas Busch - LSU 46

You might also like