You are on page 1of 38

Advanced Theory of Computation

Regular Languages: Pumping Lemma

Dr. Bakhtiar Kasi

May 15, 2019


Pumping Lemma
n Review: A language is regular, if
there is a DFA recognizing it, or
an NFA recognizing it, or a RE
describing it.
n The pumping lemma describes a
property of all regular languages.
n Why study the pumping lemma?
• The pumping lemma can be used
to prove that some language is not
regular.

2
Pigeonhole Principle
n Pigeonhole principle
• if more than p pigeons are placed into p holes, then some
hole must have more than one pigeon in it

4 pigeons

3 holes

3
Basic Idea of Pumping Lemma (1)
n Consider
• a regular language A
• a DFA for A
• A string s Î A with n symbols
s= s1 s2 s3 s4 s5 s6 … sn

DFA for A
4
Basic Idea of Pumping Lemma (2)
n Consider the path that the machine goes through when
reading input string s. The path starts with state 1 (the start
state), goes through some intermediate states (say 3, 20,
9, …), and finally ends at state 13 (which is a final state)

s= s1 s2 s3 s4 s5 s6 … sn

path = 1 3 20 9 17 9 6 35 13

1 13

DFA for A
5
Basic Idea of Pumping Lemma (3)
n Since the length of string s is n, so the path consists of
n+1 states.

s= s1 s2 s3 s4 s5 s6 … sn
n+1
path = 1 3 20 9 17 9 6 35 13 states

1 13

DFA for A
6
Basic Idea of Pumping Lemma (4)
n If n+1 is greater than the number of DFA states,
n then the path goes through some state at least
twice. (here is state 9)

s= s1 s2 s3 s4 s5 s6 … sn
n+1
path = 1 3 20 9 17 9 6 35 13 states

1 13

DFA for A
7
Basic Idea of Pumping Lemma (5)
n Since the path goes through state 9 twice, there is a loop in
the path. The loop starts from state 9 and ends at state 9

s= s1 s2 s3 s4 s5 s6 … sn
n+1
path = 1 3 20 9 17 9 6 35 13 states

1 13

9
DFA for A
8
Basic Idea of Pumping Lemma (6)
n Now we divide the string s into three pieces x, y, and z.

x y z
s= s1 s2 s3 s4 s5 s6 … sn
n+1
path = 1 3 20 9 17 9 6 35 13 states

y
1 13

x 9 z
DFA for A
9
Basic Idea of Pumping Lemma (7)
n Consider another string xz. x takes the machine from state 1 to
state 9, and then z takes the machine from state 9 to state 13
(a final state). So, xz is also accepted by the machine

x z

s1 s2 s3 s6 … sn

path = 1 3 20 9 6 35 13

1 13

x 9 z
DFA for A
10
Basic Idea of Pumping Lemma (8)
n String xyyz: x takes the machine from 1 to 9; first y takes the
machine from 9 back to 9, as does the second y; and z takes
the machine from 9 to 13 (final state). So, xyyz is also accepted
by the machine

x y y z

s1 s2 s3 s4 s5 s4 s5 s6 … sn

path = 1 3 20 9 17 9 17 9 6 35 13
y y
1 13

x 9 z
DFA for A
11
Basic Idea of Pumping Lemma (9)
n So, for any integer i ³ 0, we have
xyiz is accepted by the machine

x y z

s= s1 s2 s3 s4 s5 s6 … sn

path = 1 3 20 9 17 9 6 35 13

y
1 13

x 9 z
DFA for A
12
Pumping Lemma
n If A is a regular language,
n The pumping
then there is a number p lemma describes
(called the pumping length) a property of all
where, if s is any string in A regular languages.

with |s|³p, then s may be


divided into three pieces,
s=xyz, satisfying the following
conditions:
1. for each i ³ 0, xyiz ÎA
2. |y| > 0, and
3. |xy| £ p

13
Pumping Lemma
n If A is a regular language,
n Intuitively, we can
then there is a number p consider p as the
(called the pumping length) number of states of a
where, if s is any string in A DFA for A.

with |s|³p, then s may be


divided into three pieces,
s=xyz, satisfying the following
conditions:
1. for each i ³ 0, xyiz ÎA
2. |y| > 0, and
3. |xy| £ p

14
Pumping Lemma
n If A is a regular language,
then there is a number p
(called the pumping length)
n i could be any number
where, if s is any string in A greater than or equal to
with |s|³p, then s may be 0.
divided into three pieces, n If i=1, then xyiz is just
string s itself
s=xyz, satisfying the following
n If i>1, then it is
conditions: “pumping up string s”
1. for each i ³ 0, xyiz ÎA n If i=0, then it is
“pumping down string s”
2. |y| > 0, and
3. |xy| £ p

15
Pumping Lemma
n If A is a regular language,
then there is a number p
(called the pumping length)
where, if s is any string in A
with |s|³p, then s may be
divided into three pieces,
n Substring y (the
s=xyz, satisfying the following loop) cannot not
conditions: be empty, but x
and z could be
1. for each i ³ 0, xyiz ÎA empty
2. |y| > 0, and
3. |xy| £ p

16
Pumping Lemma
n If A is a regular language,
then there is a number p
(called the pumping length)
where, if s is any string in A
with |s|³p, then s may be nIn general, there
divided into three pieces, exists a loop for any
s=xyz, satisfying the following p symbols.
conditions: nThe pumping
lemma is interested
1. for each i ³ 0, xyiz ÎA only in the loop in
2. |y| > 0, and the first p symbols.
3. |xy| £ p

17
Intuitive Explanation
n If A is a regular language, Intuitive explanation:
then there is a number p § If A is regular,
(called the pumping length) then for any long
where, if s is any string in A enough string s
with |s|³p, then s may be in A, some part
divided into three pieces, of its first p
s=xyz, satisfying the following symbols can be
conditions: pumped.
1. for each i ³ 0, xyiz ÎA
2. |y| > 0, and
3. |xy| £ p

18
Outline
ü Pumping Lemma
Ø Examples of Pumping Lemma
n Contrapositive of Pumping Lemma
n Proof of Nonregular Languages

19
Example of Pumping Lemma
n Consider the regular language
L = { x over {0,1} | x is the binary representation of an
integer divisible by 5}

2 0
1
0 4 1
0 1
1 0
0 1 1 3
0

20
Example of Pumping Lemma
n The number of states of the finite automaton is 5.
So we set p = 5
n Consider string 11001
• 11001 Î L
• |11001| = 5 ³ p

2 0
1
0 4 1
0 1
1 0
0 1 1 3
0

21
Example of Pumping Lemma
n string 11001 could be divided into three pieces as
follows
• x=1
• y = 10
• z = 01
n Condition 1:
• i=0, xyiz = 101 Î L (1012=5)
• i=2, xyiz = 1101001 Î L (11010012=105)
• i=3, xyiz = 110101001 Î L (1101010012=425)
n Condition 2:
• |y| = |10| = 2 >0
n Condition 3:
• |xy| = |110| = 3 £ p

22
Example of Pumping Lemma
n Alternatively, string 11001 could be divided into three
pieces as follows
• x=e
• y = 11001
• z=e
n Condition 1:
• i=0, xyiz = e Î L (e = 0)
• i=2, xyiz = 1100111001 Î L (11001110012=825)
n Condition 2:
• |y| = |11001| = 5 >0
n Condition 3:
• |xy| = |11001| =5 £ p

23
Outline
ü Pumping Lemma
ü Examples of Pumping Lemma
Ø Contrapositive of Pumping Lemma
n Proof of Nonregular Languages

24
Intuitive Explanation

n Pumping Lemma: If A is regular, then for any


long enough string s in A, some part of its first
p symbols can be pumped.

n Contrapositive: If there exists a long enough


string s in A, and any part of its first p symbols
cannot be pumped, then A is not regular.

25
Contrapositive of Pumping Lemma

n Language A is not regular if, for every


number p, there exists a string s in A with
|s|³p having the following property:
For any decomposition of s=xyz, in which |y|>0
and |xy|£p, there is an i³0 for which xyizÏA

26
Outline
ü Pumping Lemma
ü Examples of Pumping Lemma
ü Contrapositive of Pumping Lemma
Ø Proof of Nonregular Languages

27
Proof of Nonregular Languages
n Prove that a language A is not regular
n The purpose of
• step 1: For the purpose of step 3 is to find a
contradiction, assume that A is regular string such that any
• step 2: Let p be the pumping length part of its first p
symbols cannot be
• step 3: Pick a string s in A with |s| ³ p pumped
• step 4: Identify all possible n Choose a string
decompositions of s into xyz, with |xy| whose first p
£ p and |y| > 0 symbols are as
simple as possible.
• step 5: Show that for each Otherwise, it may
decomposition, there exists an i ³ 0 be difficult to show
such that xyiz Ï A that any part of its
first p symbols
• step 6: Conclude that the assumption cannot be pumped.
is wrong
28
Proof of Nonregular Languages
n Prove that a language A is not regular n For different
decompositions,
• step 1: For the purpose of you may choose
contradiction, assume that A is regular different i‘s.
• step 2: Let p be the pumping length n If at step 5, you

• step 3: Pick a string s in A with |s| ³ p find that for some


decomposition,
• step 4: Identify all possible xyizÎA for any i³0,
decompositions of s into xyz, with |xy| then this means
£ p and |y| > 0 the string you
picked is not a
• step 5: Show that for each good choice. Do
decomposition, there exists an i ³ 0 not despair, just try
such that xyiz Ï A another one
• step 6: Conclude that the assumption
is wrong
29
Example 1

q L1 = { w | w has the same number of a’s and b’s}


• For the purpose of contradiction, assume that L1 is regular
• Let p be the pumping length
• Let s = (ab)p, and we have
(ab)p Î L1, and |(ab)p| = 2p ³ p
• We decompose s into xyz, with x = e, y = aba, z = b(ab)p-2
• Let i = 0, then xyiz = xz = b(ab)p-2 Ï L1
• Therefore, L1 is not regular

we must consider all possible


decompositions!
30
Example 1

qProve that the following language is not regular


L1 = { w | w has the same number of a’s and b’s}

• step 1: For the purpose of contradiction, assume that


L1 is regular
• step 2: Let p be the pumping length
• step 3: Pick a string s in L1 with |s| ³ p
§ Let s = (ab)p, and we have
(ab)p Î L1, and |(ab)p| = 2p ³ p

31
Example 1
• step 4: Identify all possible decompositions of s into
xyz, with |xy| £ p and |y| > 0
§ Since s = (ab)p, for any possible decomposition, y
may consist of some a’s and some b’s
• step 5: Show that for each decomposition, there exists
an i ³ 0 such that xyiz Ï L1
§ However, we can see that if x=e, y=ab, and
z= (ab)p-1, then xyiz =(ab)i(ab)p-1 = (ab)i+p-1ÎL1 for
any i.
§ So (ab)p is not a good choice for
this language, and we have to
find another one.

32
Example 1

qProve that the following language is not regular


L1 = { w | w has the same number of a’s and b’s}

• step 1: For the purpose of contradiction, assume that


L1 is regular
• step 2: Let p be the pumping length
• step 3: Pick a string s in L1 with |s| ³ p
§ Let s = apbp, and we have
apbp Î L1, and |apbp| = 2p ³ p

33
Example 1
• step 4: Identify all possible decompositions of s into
xyz, with |xy| £ p and |y| > 0
§ Since s = apbp, for any possible decomposition, y
must consist of one or more a’s but no b’s
• step 5: Show that for each decomposition, there exists
an i ³ 0 such that xyiz Ï L1
§ Let y = ak (p ³ k > 0), and let i = 2, we see that
xyiz = xy2z = ap+kbp Ï L1
• step 6: Conclude that the assumption is wrong. That is
L1 is not regular

34
Example 2

q Prove that the following language is not regular


L2 = { ww | w Î {a, b}*}

• step 1: For the purpose of contradiction, assume that


L2 is regular
• step 2: Let p be the pumping length
• step 3: Pick a string s in L2 with |s| ³ p
§ Let s = apbapb, and we have
apbapb Î L2, and |apbapb| = 2p+2 ³ p

35
Example 2
• step 4: Identify all possible decompositions of s into
xyz, with |xy| £ p and |y| > 0
§ Since s = apbapb, for any possible decomposition, y
must consist of one or more a’s but no b’s
• step 5: Show that for each decomposition, there exists
an i ³ 0 such that xyiz Ï L2
§ Let y = ak (p ³ k > 0), and let i = 2, we see that
xyiz = xy2z = ap+kbapb Ï L2
• step 6: Conclude that the assumption is wrong. That is
L2 is not regular

36
Example 3
q L3 = { ambn | m > n}
• step 1: For the purpose of contradiction, assume that
L3 is regular
• step 2: Let p be the pumping length
• step 3: Pick a string s in L3 with |s| ³ p
§ Let s = ap+1bp, and we have
ap+1bp Î L3, and |ap+1bp| = 2p+1 ³ p

37
Example 3
• step 4: Identify all possible decompositions of s into
xyz, with |xy| £ p and |y| > 0
§ Since s = ap+1bp, for any possible decomposition, y
must consist of one or more a’s but no b’s
• step 5: Show that for each decomposition, there exists
an i ³ 0 such that xyiz Ï L3
§ Let y = ak (p ³ k > 0), and let i = 0, we see that
xyiz = xz = ap+1-kbp
Because p+1-k £p, ap+1-kbp Ï L3
• step 6: Conclude that the assumption is wrong. That is
L3 is not regular

38

You might also like