You are on page 1of 45

Pumping Lemma for Regular

Languages
Regular Languages
Show a language is Regular by building one the following
• DFA
• NFA
• Regular Expression
• Example:

{0n1n | 0=<n} is not


regular, but

{0n1n | 0nk, for some fixed k} is regular, for any fixed k.

• For k=3:
0 0 0
q0 q
L = {ε, 01, 0011,
1 000111} q2 q3

1 1 1 1
0/1 1 1
0/1 q7 q6 q5 q4
0
0
0
3
Non-Regular Language?
• To understand the power of DFA, apart from knowing what it can do,
we need to know what it cannot do
• Let’s look at the language B = {0n 1n | n >=0}
• If we try to find a DFA to recognize B, the DFA needs to keep track of
the number of 0’s we have seen so far
• However, number of 0’s is unlimited…there are unlimited number of
possibilities
• So, it is NOT POSSIBLE because the DFA just has FINITE number of
states!
Pumping Lemma for Regular Languages
• Pumping Lemma relates the size of string accepted
with the number of states in a DFA

• For accepting a string of length m how many states do you need


on a path?
string a1a2a3a4 below
-->q1 – a1 –> q2 -- a2  q3 – a3  q4 – a4 --> qF*

• What is the largest possible string accepted by a DFA with n


states,
presuming there is NO loop?
5
Pumping Lemma for Regular Languages

• If there is a loop in the path for accepting a string,


what type of strings are accepted via the loop(s)?

• Think of a string in the language: 001 10 111, with middle 10 on a


loop
q0  001  q5  10 
q5  111
Now, what type of strings should also be accepted?

• What is the largest string accepted by a DFA with n states,


presuming there is a LOOP ?
6
Pumping Lemma for Regular Languages

• Pumping lemma quantifies two observations toward a path of accepting a


string by a DFA:

• 1. If the path is longer than the number of states available in the DFA, then
there is a repetition of some state in the path, or a ‘loop’

• 2. If there is such a loop in the path, then the substring on the loop may
appear 0 or more number of times for the corresponding string to be
accepted
• string: 001 10 111, with middle 10 on a loop
q0  001  q5  10  q5 
111
• Other corresponding accepted strings are: 7
Pumping Lemma for Regular Languages

• If L is a regular language, then there exists a number p


(called the pumping length) such that:
• if s is a string in L of length at least p (|s|>=p), then s can be
divided into three pieces, s = xyz, satisfying the following
three conditions::
• 1 |xy|  p
• |y| > 0
• AND, all the strings xykz are also in L, for all k  0

8
Use of Pumping Lemma (Example 1)
• Show that the language L1 = {0n1n | 0=<n} is not regular using
pumping lemma
• Proof (by contradiction)
• Assume that L1 is regular. Then let p be the pumping length
• We know that string s = 0p 1p is in L1, |s|>=p
• By pumping lemma, we know that s= 0p 1p can be divided into three
parts, xyz, such that |y|>0, |xy|  p
Use of Pumping Lemma (Example 1)
• Case-1: y is a substring of 0p
• x= 0j, for some j>0; z=1p
• y=0m, for some m>0
• j+m=p
• For k=2, xyyz  0j (0m)2 1p  0j+2m 1p  0p+m 1p
• xyyz has more 0’s than 1’s
• Contradiction
Use of Pumping Lemma (Example 1)
• Case-2: y is a substring of 1p
• xyyz has more 1’s than 0’s
• contradiction

• Case-3: y contains both 0s and 1s


• x= 0p-j, for some j>0
• y=0j 1m
• z=1p-m, for some m>0

• For k=2, xyyz  0p-j (0j 1m)2 1p-m  0p-j 0j 1m0j 1m 1p-m
• xyyz not in L1
• Contradiction
• So L1 is not Regular
Use of Pumping Lemma (Example 2)

L2 = {aibj : i > j}
L2 is not regular.
We prove it using the Pumping Lemma.
L2 = {aibj : i > j}
L2 is not regular.
• Fix an arbitrary pumping length n>0.
L2 = {aibj : i > j}
L2 is not regular.
• Fix an arbitrary pumping length n>0.
• Choose a proper string s in L2.
L2 = {a b : i > j}
i j

L2 is not regular.
• Fix an arbitrary pumping length n>0.
• Choose a proper string s in L2.

|s|≥ n
L2 = {a b : i > j}
i j

L2 is not regular.
• Fix an arbitrary pumping length n>0.
• Choose a proper string s in L2.
• s = an+1bn ϵ L2.

aaa…aabb…b
n+1 n
L2 = {a b : i > j}
i j

L2 is not regular.
• Fix an arbitrary pumping length n>0.
• Choose a proper string s in L2.
• s = an+1bn ϵ L2.
• Consider all possible splittings of s in x,y,z with the
desired properties.

aaa…aabb…b
n+1 n
L2 = {a b : i > j}
i j

L2 is not regular.
• Fix an arbitrary pumping length n>0.
• Choose a proper string s in L2.
|xy|≤ n
• s = an+1bn ϵ L2.
|y|≥ 1
• Consider all possible splittings of s in x,y,z with the
desired properties.

aaa…aabb…b
n+1 n
L2 = {a b : i > j}
i j

L2 is not regular.
• Fix an arbitrary pumping length n>0.
• Choose a proper string s in L2.
|xy|≤ n
• s = an+1bn ϵ L2.
|y|≥ 1
• Consider all possible splittings of s in x,y,z with the
desired properties.

aaa…aabb…b
n+1 n
L2 = {a b : i > j}
i j

L2 is not regular.
• Fix an arbitrary pumping length n>0.
• Choose a proper string s in L2.
|xy|≤ n
• s = an+1bn ϵ L2.
|y|≥ 1
• Consider all possible splittings of s in x,y,z with the
desired properties.

Y
aaa…aabb…b
n+1 n
L2 = {a b : i > j}
i j

L2 is not regular.
• Fix an arbitrary pumping length n>0.
• Choose a proper string s in L2.
• s = an+1bn ϵ L2.
• Consider all possible splittings of s in x,y,z with the
desired properties: y = am, 1 ≤ m ≤ n.

Y
aaa…aabb…b
n+1 n
L2 = {a b : i > j}
i j

• Fix an arbitrary pumping length n>0.


• Choose a proper string s in L2.
• s = an+1bn ϵ L2.
• Consider all possible splittings of s in x,y,z with the
desired properties: y = am, 1 ≤ m ≤ n.
• xz =an+1-mbn ∉ L2.
• So L2 is not regular!
L2 = {a b : i > j}
i j
Use of Pumping Lemma (Example 3)
i j k
L={a b c | i + j = k, i > 0, j > 0, k > 0 } is not regular.

Proof. For contradiction, suppose L is regular. Let p be the


pumping lemma constant.
p p
Consider b c .
p
By Pumping Lemma, b = xyz such that
y ≠ ε and for k > 0, bjbkbmcp in L, such that j+k+m=p

For k=2, bj+2k+mcp  bp+kcp  more b’s than c’s


contradiciton
L={ww : w in {a,b}*}
• First, figure out what this language is.
• A string in the language? aabaab
• Another string in the language? aaaaaa
• A string not in the language? abbb
• Is ε in the language? YES! (ε = εε)
• Is aa in the language? YES!
• Is a in the language? NO!
L={ww : w in {a,b}*}
• First, figure out what this language is.
L = {ε, aa, bb, aaaa, abab, baba, bbbb, aaaaaa …}

abaabba|abaabba
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping lemma.
• First fix an arbitrary number n>0 to be the pumping length.
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping lemma.
• Pumping length: n
• Choose a proper string in the language
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping lemma.
• Pumping length: n
• Choose a proper string in the language. Choose wisely!!!
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping lemma.
• Pumping length: n
• Choose a proper string in the language. Example: For s = a2n

aaa…aaa|aaa…aaa
n n
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping lemma.
• Pumping length: n
• Choose a proper string in the language. Example: For s = a2n
• For x = ε, y = a2, z = a2n-2

y z
aaa…aaa|aaa…aaa
n n
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping lemma.
• Pumping length: n
• Choose a proper string in the language. Example: For s = a2n
• For x = ε, y = a2, z = a2n-2

y y z
aaaaa…aa|aaaa…aaa ϵ L
n+1 n+1
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping lemma.
• Pumping length: n
• Choose a proper string in the language. Example: For s = a2n
• For x = ε, y = a2, z = a2n-2

y y y z
aaaaaaa…a|aaaaa…aaa ϵ L
n+2 n+2
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping lemma.
• Pumping length: n
• Choose a proper string in the language. Example: For s = a2n
• For x = ε, y = a2, z = a2n-2

z
a…aaaa|aa…aaa ϵ L
n-1 n-1
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping lemma.
• Pumping length: n
• Choose a proper string in the language. Example: For s = a2n
• For x = ε, y = a2, z = a2n-2, there is no i: xyiz ∉ L!
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping lemma.
• Pumping length: n
• Choose a proper string in the language. Example: For s = a2n
• For x = ε, y = a2, z = a2n-2, there is no i: xyiz ∉ L!
• s = a2n doesn’t work!!!
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping lemma.
• Pumping length: n
• Choose a proper string in the language. Example: For s = (ab)2n

abab…abab|abab…abab
n n
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping lemma.
• Pumping length: n
• Choose a proper string in the language. Example: For s = (ab)2n
• For x = ε, y = abab, z = (ab)2n-2

y z
abab…abab|abab…abab
n n
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping lemma.
• Pumping length: n
• Choose a proper string in the language. Example: For s = (ab)2n
• For x = ε, y = abab, z = (ab)2n-2

y y z
abababab…ab|ababab…abab ϵ L
n+1 n+1
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping lemma.
• Pumping length: n
• Choose a proper string in the language. Example: For s = (ab)2n
• For x = ε, y = abab, z = (ab)2n-2
• For any i, xyiz = (ab)2i(ab)2n-2 = (ab)2(i-n-2) ϵ L!
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping lemma.
• Pumping length: n
• Choose a proper string in the language. Example: For s = (ab)2n
• For x = ε, y = abab, z = (ab)2n-2
• For any i, xyiz = (ab)2i(ab)2n-2 = (ab)2(i-n-2) ϵ L!
• s = (ab)2n doesn’t work!
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping lemma.
• Pumping length: n
• Choose a proper string in the language.
• Use s = anbanb

aaaa…aab|aaaa...aab
n n
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping
lemma.
• Pumping length: n
• Choose a proper string in the language.
• Use s = anbanb
• For any splitting of s in x,y,z with the desired
properties:

Y
aaaa…aab|aaaa...aab
n n
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping
lemma.
• Pumping length: n
• Choose a proper string in the language
• Use s = anbanb
• For any splitting of s in x,y,z with the desired
properties: y = am with 1 ≤ m ≤ n.
L={ww : w in {a,b}*}
We prove that L is not regular by using the pumping
lemma.
• Pumping length: n
• Choose a proper string in the language
• Use s = anbanb
• For any splitting of s in x,y,z with the desired
properties: y = am with 1 ≤ m ≤ n.
• Observe that xy2z = am+nbanb is not in L

You might also like