Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
lfa:2022:lab08-the-pumping-lemma [2022/11/26 23:03]
alexandra.udrescu01
lfa:2022:lab08-the-pumping-lemma [2022/12/09 08:55] (current)
pdmatei
Line 4: Line 4:
 ** Pumping Lemma ** ** Pumping Lemma **
  
-Let L be an infinite regular languageThen, for $\forall$\in$ L, $\exists$\in$ $\mathbf{N}$,​ |w| $\gen, w = xyz, |xy| $\le$ and y $\neq$ $\varepsilon$,​ such that $\forall$\gew_{k} xy^{k}z ​$ $\in$ L.+Let L be an infinite regular languageThen, for $\forall w \in L$, $\exists n \in \mathbf{N}$, ​|w| \ge n $w = xyz $|xy| \le $ and y \neq \varepsilon $, such that $ \forall k \ge 0w_{k} = xy^{k}z \in L$.
  
 </​note>​ </​note>​
  
 <note important>​ <note important>​
 +** 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.
  
 </​note>​ </​note>​
Line 15: Line 18:
  
 **8.1.1.** Show that the pumping lemma holds for finite languages. **8.1.1.** Show that the pumping lemma holds for finite languages.
 +
 +
 +<hidden Solution>​
 +
 +<​note>​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
 +
 +</​note>​
 +
 +</​hidden>​
 +
  
 **8.1.2.*** Find a language which is not regular for which the pumping lemma holds. **8.1.2.*** Find a language which is not regular for which the pumping lemma holds.
Line 24: Line 39:
 **8.2.1.** $  L = \{ \: A^n B^m \: | \: 0 \leq n \leq m \: \} $ **8.2.1.** $  L = \{ \: A^n B^m \: | \: 0 \leq n \leq m \: \} $
  
-**8.2.2.** $  L = \{ \: w \in \{A,B\}^* \: | \: \#A(w) = \#B(w) \: \} $+ 
 + 
 +<hidden Solution>​ <​note>​ 
 + 
 +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 
 +</​note>​ 
 + 
 +</​hidden>​ 
 + 
 + 
 +**8.2.2.** $  L = \{ \: w \in \{A,B\}^* \: | \: \#_A(w) = \#_B(w) \: \} $ 
 + 
 + 
 +<hidden Solution>​ <​note>​ 
 + 
 +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 
 +</​note>​ 
 + 
 +</​hidden>​ 
  
 **8.2.3.** $math[L = \{(01)^n(10)^n \mid n > 0 \} ] **8.2.3.** $math[L = \{(01)^n(10)^n \mid n > 0 \} ]
 +
 +
 +
 +<hidden Solution>​ <​note>​
 +$ 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
 +</​note>​
 +
 +</​hidden>​
 +
  
 **8.2.4.** $  L = \{ \: w \in \{A,B\}^* \: | \: \text{w is a palindrome} \: \} $ **8.2.4.** $  L = \{ \: w \in \{A,B\}^* \: | \: \text{w is a palindrome} \: \} $
 +
 +
 +
 +<hidden Solution>​ <​note>​
 +
 +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
 +</​note>​
 +
 +</​hidden>​
 +
  
 **8.2.5.** $  L = \{ \: w \in \{0\}^* \: | \: \text{the length of w is a prime number} \: \} $ **8.2.5.** $  L = \{ \: w \in \{0\}^* \: | \: \text{the length of w is a prime number} \: \} $
 +
 +
 +
 +
 +<hidden Solution>​ <​note>​
 +
 +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
 +</​note>​
 +
 +</​hidden>​
 +
 +
  
 **8.2.6.** $  L = \{ \: w \in \{0\}^* \: | \: \text{the length of w is a power of two} \: \} $ **8.2.6.** $  L = \{ \: w \in \{0\}^* \: | \: \text{the length of w is a power of two} \: \} $
  
-**8.2.7.** $  L = \{ \: ww^R  \: | \: w\in \{0,1\}^* \}  + 
-$+ 
 +<hidden Solution>​ <​note>​ 
 + 
 +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 => |y| \lt n \lt 2^p => 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 
 +</​note>​ 
 + 
 +</​hidden>​ 
 + 
 + 
 +**8.2.7.** $  L = \{ \: ww^R  \: | \: w\in \{0,1\}^* \} $ 
 + 
 + 
 + 
 +<hidden Solution>​ <​note>​ 
 + 
 +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 
 +</​note>​ 
 + 
 +</​hidden>​ 
  
  
Line 41: Line 271:
  
 **8.3.1.** Using the pumping lemma, prove that $  L = \{ \: A^nB^m \: | \: n \neq m \}$ 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.
 +
 +<hidden Solution>​
 +<​note>​
 +
 +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.
 +</​note>​
 +
 +</​hidden>​
  
 /* /*