Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lfa:2022:lab08-the-pumping-lemma [2022/11/26 23:57] alexandra.udrescu01 |
lfa:2022:lab08-the-pumping-lemma [2022/12/09 08:55] (current) pdmatei |
||
---|---|---|---|
Line 18: | 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> | <hidden Solution> | ||
Line 28: | Line 29: | ||
</hidden> | </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 36: | Line 38: | ||
**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 \: \} $ | ||
+ | |||
+ | |||
<hidden Solution> <note> | <hidden Solution> <note> | ||
Line 41: | Line 45: | ||
For a fixed n, pick a word $ w_n \in L $ and $ w_n = xyz $: | For a fixed n, pick a word $ w_n \in L $ and $ w_n = xyz $: | ||
- | $ w_n = A^nB^{n+1} | + | $ w_n = A^nB^{n+1} $ |
$ x = A^a $ | $ x = A^a $ | ||
Line 47: | Line 51: | ||
$ y = A^b, b \ge 1 $ | $ y = A^b, b \ge 1 $ | ||
- | $ z = A^{n-b-a}B^{n-1} $ | + | $ z = A^{n-b-a}B^{n+1} $ |
Find k such that $ xy^kz \notin L $: | Find k such that $ xy^kz \notin L $: | ||
Line 54: | Line 58: | ||
Pick k = 3 => $ w_3 = A^{n+2b}B^{n+1} \notin L $ because $ b \ge 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> | </note> | ||
</hidden> | </hidden> | ||
- | **8.2.2.** $ L = \{ \: w \in \{A,B\}^* \: | \: \#A(w) = \#B(w) \: \} $ | ||
**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> | ||