Pumping Lemma for Regular Languages



Pumping Lemma provides a method to prove that certain languages are not regular. The Pumping Lemma states that for any regular language, there exists a length such that any string longer than this length can be divided into three parts, and by repeating or removing the middle part, the resulting string will also be in the language.

In this chapter, we will see a very basic recap of pumping lemma for regular languages and see different examples for a better understanding.

Basics of Pumping Lemma

The Pumping Lemma can be formally stated as follows −

If L is a regular language, then there exists an integer n (the pumping length) such that any string w in L with | w | ≥ n can be decomposed into three parts, w = xyz, satisfying the following conditions −

$$\mathrm{|xy| \:\le \: n\:|xy|\:,}$$

$$\mathrm{|y| \:\gt \:0\:,}$$

$$\mathrm{xy^{i} \: z \:\in \:L \:\:for \:\: all \:\:i\: \ge\: 0}$$

These conditions states that for any sufficiently long string in a regular language, there is a section of the string that can be "pumped" (repeated or removed) to produce new strings that also belong to the language.

Examples of Pumping Lemma for Regular Languages

Let us see some examples for a better understanding.

Example 1

Prove that L = {ai2 | i ≥ 1} is not regular.

Solution

Assume the set L is regular. Let n be the number of states of the FA accepting the set L.

Let w = an2. The length of w is n2, which is greater than n, the number of states of the FA accepting L. By using the Pumping Lemma, we can write w = xyz with |x|y| ≤ n and |y| > 0.

Take i = 2, so the string will become xy2z.

$$\mathrm{|xy^{2}z| \:=\: |x|\:+\:2|y|\:+\:|z|}$$

$$\mathrm{=\:|x| \:+\: |y|\:+\:|z|\:+\:|y|}$$

$$\mathrm{= \:n^{2} \:+\: |y|}$$

Since |xy| n, |y| n, therefore |xy2z| n2 + n

From the previous derivations, we can write −

$$\mathrm{n^{2} \:\lt\: |xy^{2}z| \:\le\: n^{2} \:+\: n \: \lt\: (n \:+\: 1)^{2}}$$

Hence, |xy2z| lies between n2 and (n + 1)2. They are the squares of two consecutive positive integers. In between the squares of two consecutive positive integers, no square of a positive integer belongs.

But ai2, where i ≥ 1, is a perfect square of an integer. So, the string derived from it, i.e., |xy2z| is also a square of an integer, which lies between the squares of two consecutive positive integers. This is not possible.

So, xy2z ∈ L. This is a contradiction and L is not regular.

Example 2

Prove that L = { ap | p is prime } is not regular.

Solution

Assume the set L is regular. Let n be the number of states of the FA accepting the set L.

Let p be a prime number greater than n. Let the string w = ap, w ∈ L. By using the Pumping Lemma, we can write w = xyz with |xy| ≤ n and |y| > 0. As the string w consists of only 'a's, x, y, and z are also strings of 'a's. Let us assume that y = am for some m with 1 ≤ m ≤ n.

Let us take, i = p + 1.

$$\mathrm{|xy^{i}z| \:=\: |xyz| \:+\: |y^{(i\:-\:1)}|}$$

$$\mathrm{p \:+\: (i \:-\: 1)\: |y|}$$

$$\mathrm{( p \:+\: (p \:+\: 1 \:-\: 1)m )}$$

$$\mathrm{= \:p \:+\: pm}$$

$$\mathrm{p(1 \:+\: m)}$$

p(1 + m) is not a prime number as it has factors p and (1 + m), including 1 and p(1 + m). So, xy(p + 1)z ∉ L. This is a contradiction.

Example 3

Prove that L = {an bn | n ≥ 1} is not regular.

Solution

Assume the set L is regular. Let n be the number of states of the FA accepting the set L.

Let w = an bn, where |w| = 2n. By the Pumping Lemma, we can write w = xyz with |xy| ≤ n and |y| > 0.

We want to find a suitable i so that xyiz ∉ L.

The string y can be one of the following −

  • y is a string of only 'a's, so y = ak for some k ≥ 1.
  • y is a string of only 'b's, so y = bk for some k ≥ 1.
  • y is a string of both 'a's and 'b's, so, y = ak bl for some k, l ≥ 1.

For case (i), take i = 0. As xyz = an bn, xy0 z = xz will be an-k bn.

$$\mathrm{As \:k\: \ge \:1, \:(n \:-\: k) \:\neq \:n,\: so\: xy^{0}z \: \notin\: L}$$

For case (ii), take i = 0. As xyz = an bn, xy0 z = xz will be an bn-k.

$$\mathrm{As \:k\: \ge \:1, \:(n \:-\: k) \:\neq\: n,\: so\: xy^{0}z \:\notin\: L}$$

For case (iii), take i = 2. As xyz = an bn,

$$\mathrm{xy^{2}z \:=\: xyyz'}$$

We know,

$$\mathrm{xyz \:=\: a^{n}\:b^{n} \:=\: a^{n\:-\:k}\: a^{k}\: b^{l}\: b^{n\:-\:l}}$$

So, xyyz will be,

$$\mathrm{a^{n\:-\:k}\: a^{k}\: b^{l}\: a^{k}\: b^{l}\: b^{n\:-\:l} \:=\: a^{n}\: b^{l} \:a^{k}\: b^{n}}$$

Which is not in the form an bn, so xy2 z ∉ L.

For all three cases, we find a contradiction. Therefore, L is not regular.

Conclusion

The Pumping Lemma is a powerful tool in automata theory and formal languages. It provides a systematic method to prove that certain languages are not regular by demonstrating that they do not satisfy the properties required by the lemma.

In this chapter, we used a set of examples to illustrate how the Pumping Lemma can be applied to various languages to show that they are not regular.

Advertisements