8. Proving languages are not regular

Pumping Lemma

Let L be an infinite regular language. Then, for $\forall w \in L$, $\exists n \in \mathbf{N}$, $ |w| \ge n $, $ w = xyz $, $ |xy| \le n $ and $ y \neq \varepsilon $, such that $ \forall k \ge 0, w_{k} = xy^{k}z \in L$.

Complement of Pumping Lemma

Let L be an infinite language. If $\forall n \in \mathbf{N}$, $\exists w_{n} \in L $ with $ |w| \ge n $ such that regardless of how $ w_{n} $ is split into $ w_{n} = xyz $ with $ |xy| \le n $ and $ y \neq \varepsilon $, $\exists k \ge 0 $ such that $ w_{n} = xy^{k}z \notin L $, then L in not a regular language.

8.1.1. Show that the pumping lemma holds for finite languages.

Solution

Solution

Let L be a finite language.

Pick $ n \gt max_{w \in L} |w| $ ⇒ $ \nexists w \in L $ with $ |w| \ge n $ ⇒ Pumping Lemma holds

8.1.2.* Find a language which is not regular for which the pumping lemma holds.

Show that each of the languages from the list below is not regular.

8.2.1. $ L = \{ \: A^n B^m \: | \: 0 \leq n \leq m \: \} $

Solution

Solution

For a fixed n, pick a word $ w_n \in L $ and $ w_n = xyz $:

$ w_n = A^nB^{n+1} $

$ x = A^a $

$ y = A^b, b \ge 1 $

$ z = A^{n-b-a}B^{n+1} $

Find k such that $ xy^kz \notin L $:

$ w_k = A^{a+b*k+n-b-a}B^{n+1} = A^{n+(k-1)b}B^{n+1} $

Pick k = 3 ⇒ $ w_3 = A^{n+2b}B^{n+1} \notin L $ because $ b \ge 1 $

⇒ Complement of Pumping Lemma holds ⇒ L is not a regular language

8.2.2. $ L = \{ \: w \in \{A,B\}^* \: | \: \#_A(w) = \#_B(w) \: \} $

Solution

Solution

For a fixed n, pick a word $ w_n \in L $ and $ w_n = xyz $:

$ w_n = A^nB^n $

$ x = A^a $

$ y = A^b, b \ge 1 $

$ z = A^{n-b-a}B^n $

Find k such that $ xy^kz \notin L $:

$ w_k = A^{a+b*k+n-b-a}B^n = A^{n+(k-1)b}B^n $

Pick k = 2 ⇒ $ w_2 = A^{n+b}B^n \notin L $ because $ b \ge 1 $

⇒ Complement of Pumping Lemma holds ⇒ L is not a regular language

8.2.3. $ L = \{(01)^n(10)^n \mid n > 0 \} $

Solution

Solution

$ w_n = (01)^n(10)^n $

Case 1:

$ x = (01)^a $

$ y = (01)^b, b \ge 1 $

$ z = (01)^{n-b-a}(10)^n $

Pick k = 2 ⇒ $ w_2 = (01)^{n+b}(10)^n \notin L $

Case 2:

$ x = (01)^a $

$ y = (01)^b0, b \ge 0 $

$ z = 1(01)^{n-b-a-1}(10)^n $

$ w_k = (01)^a((01)^b0)^k1(01)^{n-b-a-1}(10)^n $

Pick k = 2 ⇒ $ w_2 = (01)^a(01)^b0(01)^b01(01)^{n-b-a-1}(10)^n \notin L $ because it has 2 conseccutive “0”

Case 3:

$ x = (01)^a0 $

$ y = 1(01)^b, b \ge 0 $

$ z = (01)^{n-b-a-1}(10)^n $

$ w_k = (01)^a0(1(01)^b)^k(01)^{n-b-a-1}(10)^n $

Pick k = 3 ⇒ $ w_3 = (01)^a01(01)^b1(01)^b1(01)^b(01)^{n-b-a-1}(10)^n $

  • b = 0 ⇒ $ w_3 = (01)^a0111(01)^{n-b-a-1}(10)^n \notin L $
  • b > 0 ⇒ $ w_3 = (01)^a01(01)^b1(01)^b1(01)^b(01)^{n-b-a-1}(10)^n \notin L $ because there are 2 sets of consecutive “1”

Case 4:

$ x = (01)^a0 $

$ y = 1(01)^b0, b \ge 0 $

$ z = 1(01)^{n-b-a-2}(10)^n $

$ w_k = (01)^a0(1(01)^b0)^k1(01)^{n-b-a-2}(10)^n $

Pick k = 0 ⇒ $ w_0 = (01)^a01(01)^{n-b-a-2}(10)^n = (01)^{n-b-1}(10)^n \notin L$

⇒ Complement of Pumping Lemma holds ⇒ L is not a regular language

8.2.4. $ L = \{ \: w \in \{A,B\}^* \: | \: \text{w is a palindrome} \: \} $

Solution

Solution

For a fixed n, pick a word $ w_n \in L $ and $ w_n = xyz $:

$ w_n = A^nBA^n $

$ x = A^a $

$ y = A^b, b \ge 1 $

$ z = A^{n-b-a}BA^n $

Find k such that $ xy^kz \notin L $:

Pick k = 2 ⇒ $ w_2 = A^{n+b}BA^n \notin L $ because $ b \ge 1 $

⇒ Complement of Pumping Lemma holds ⇒ L is not a regular language

8.2.5. $ L = \{ \: w \in \{0\}^* \: | \: \text{the length of w is a prime number} \: \} $

Solution

Solution

For a fixed n, pick a word $ w_n \in L $ and $ w_n = xyz $:

$ w_n = 0^p, p \gt n $, p prime

$ x = 0^a $

$ y = 0^b, b \ge 1 $

$ z = 0^{p-b-a} $

Find k such that $ xy^kz \notin L $:

$ w_k = 0^{p+(k-1)b} $

Pick $ k = p+1 $ ⇒ $ w_{p+1} = 0^{p+cp} = 0^{(p+1)c} \notin L $ because $ (p+1)c $ is not a prime number

⇒ Complement of Pumping Lemma holds ⇒ L is not a regular language

8.2.6. $ L = \{ \: w \in \{0\}^* \: | \: \text{the length of w is a power of two} \: \} $

Solution

Solution

For a fixed n, pick a word $ w_n \in L $ and $ w_n = xyz $:

$ w_n = 0^{2^p}, 2^p \gt n $

$ x = 0^a $

$ y = 0^b, b \ge 1 $

$ |xy| \le n \Rightarrow |y| \lt n \lt 2^p \Rightarrow 0 < b < 2^p $

$ z = 0^{2^p-b-a} $

Find k such that $ xy^kz \notin L $:

$ w_k = 0^{2^p+(k-1)b} $

Pick $ k = 2 $ ⇒ $ w_2 = 0^{2^p+b} \notin L $ because $ 2^p < 2^p + b < 2^p + 2^p = 2^{p+1} $

⇒ Complement of Pumping Lemma holds ⇒ L is not a regular language

8.2.7. $ L = \{ \: ww^R \: | \: w\in \{0,1\}^* \} $

Solution

Solution

For a fixed n, pick a word $ w_n \in L $ and $ w_n = xyz $:

$ w_n = 0^n110^n $

$ x = 0^a $

$ y = 0^b, b \ge 1 $

$ z = 0^{n-a-b}10^n $

Find k such that $ xy^kz \notin L $:

$ w_k = 0^{n+(k-1)b}110^n $

Pick $ k = 2 $ ⇒ $ w_2 = 0^{n+b}110^n \notin L $ because $ b \ge 1 $

⇒ Complement of Pumping Lemma holds ⇒ L is not a regular language

8.3.1. Using the pumping lemma, prove that $ L = \{ \: A^nB^m \: | \: n \neq m \}$ is not a regular language.

Solution

Solution

Assume that L is a regular language.

⇒ $ L(A^*B^*) \backslash L = \{ \: A^nB^n \: | \: n \in \mathbf{N} \} $ is a regular language because set difference is a closure property.

But we have previously proved that $ \{ \: A^nB^n \: | \: n \in \mathbf{N} \} $ is not regular.

⇒ Our assumtion was wrong ⇒ L is not a regular language.