You are on page 1of 45

Pumping Lemma for Regular languages

How can we prove that a language L


is not regular?

Prove that there is no DFA that accepts L

Problem: this is not easy to prove

Solution: the Pumping Lemma !!!


2
The Pigeonhole Principle

3
4 pigeons

3 pigeonholes

4
A pigeonhole must
contain at least two pigeons

5
n pigeons

...........

p pigeonholes n p

...........

6
The Pigeonhole Principle

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

...........

7
The Pigeonhole Principle

and

DFAs

8
DFA with 4 states

b
b b

a b b
q1 q2 q3 q4
a a
9
In walks of strings: a no state
aa is repeated

aab

b
b b

a a b
q1 q2 q3 q4
a a
10
In walks of strings: aabb a state
bbaa is repeated

abbabb
abbbabbabb...
b
b b

a a b
q1 q2 q3 q4
a a
11
If the walk of string w has length | w |  4

then a state is repeated

b
b b

a a b
q1 q2 q3 q4
a a
12
Pigeonhole principle for any DFA:

If in a walk of a string w
transitions  states of DFA
then a state is repeated

b
b b

a a b
q1 q2 q3 q4
a a 13
In other words for a string w:

a transitions are pigeons

q states are pigeonholes

b
b b

a a b
q1 q2 q3 q4
a a 14
In general:

A string w has length  number of states

A state q must be repeated in the walk w

walk of w
...... q ......
15
The Pumping Lemma

16
Take an infinite regular language L

DFA that accepts L

p
states

17
Basic Idea:
b a
a
q0 q1
b
a b

q2 q3
a,b

ababbaaab L(M )
a b a b b a a a b
q0  q1  q3  q2  q1  q3  q2  q0  q1  q3
Note,
a b a b b a a a b
q0  q1  q3  q2  q1  q3  q2  q0  q1  q3

So, ababb  L(M )


a b a b b a a a b
q0  q1  q3  q2  q1  q3  q2  q0  q1  q3
abaaab  L(M )

i, j   : ab(abb) ( aaab)  L( M )


i j
Take string w with w L

There is a walk with label w:

.........
walk w 20
If string w has length | w |  p number
of states

then, from the pigeonhole principle:

a state q is repeated in the walk w

...... q ......
walk w 21
Write w x y z

...... q ......

x z 22
Observations: length | x y |  p number
of states
length | y | 1

...... q ......

x z 23
Observation: The string x z is accepted

...... q ......

x z 24
Observation: The string xyyz
is accepted

...... q ......

x z 25
Observation: The string xyyyz
is accepted

...... q ......

x z 26
i
In General: The string xy z
is accepted i  0, 1, 2, ...

...... q ......

x z 27
In other words, we described:

The Pumping Lemma !!!

28
The Pumping Lemma:
• Given a infinite regular language L
• there exists an integer p

• 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
29
Applications

of

the Pumping Lemma

30
31
32
33
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

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

is not regular

Proof: Use the Pumping Lemma

35
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

Fall 2006 Costas Busch - RPI 36


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

Let p
be the integer in the Pumping Lemma

Pick a string w such that: w  L


length | w| p

Example: pick w  a pb p
37
38
39
Therefore: Our assumption that L
is a regular language is not true

Conclusion: L is not a regular language

40
Suppose that we consider the language B ={w|w has
an equal number of 0s and 1s} and want to know
whether it is regular at not. Suppose we choose the
string 0n1n and n is the pumping length in the
lemma. Then it would seem that we could apply the
pumping lemma because if we let x and z be the
empty string, then yk = (0n1n)k is still in B. But wait,
this would then violate |xy|≤ n. If |xy|≤ n, then y
must consist only of 0s, so xyyz is not in B. Thus 0n1n
cannot be pumped.
41
n n
Non-regular languages {a b : n  0}

Regular languages
a *b b*c  a
b  c ( a  b) *
etc...
42
Using pumping lemma to prove that the language A={yy|y
€{0,1} is not regular
Proof
Assume that A is regular
Then it must have a pumping length = p

You might also like