Tutorial 4 Yi Zhou (
[email protected])
1
Closu Closure re Prope Propert rtie iess of Regul Regular ar Lang Langua uage gess
Exercise 2(b), page 108. Use the construction in Theorem 4.1 to find NFA’s that accept L(ab∗ a∗ ) ∩ L(a∗ b∗ a).
Exercise 6, page 109. The symmetric difference of two sets S 1 and S 2 is defined as S 1 S 2 = {x : x ∈ S 1 or x ∈ S 2 , but x is not in both S 1 and S 2 }. Show that the family of regular language is closed under symmetric difference. Proof: We have S 1 S 2 = (S 1 ∩ S 2 ) ∪ (S 2 ∩ S 1 ). Since regular language is closed under union, intersection and complement, it is closed under symmetric difference (i.e. ) as well.
Exercise 9, page 109. Which of the following are true for all regular languages and all homomorphisms? (a) h(L1 ∪ L2 ) = h(L1 ) ∪ h(L2 ). (b) h(L1 ∩ L2 ) = h(L1 ) ∩ h(L2 ). (c) h(L1 L2 ) = h(L1 )h(L2 ). Answer: For (a), this is true. On one hand, for any s ∈ h(L1 ∪ L2 ), there exits w ∈ L1 ∪ L2 such that s = h(w ). Without loss of generality, we can assume that w ∈ L1 . In this this case case,, h(w) ∈ L(S 1 ). That That is, is, s ∈ L(S 1 ). On the the other other hand, for any s ∈ h(L1 ) ∪ h(L2 ). Withou Withoutt loss loss of generali generality ty,, we can assume assume that s ∈ L(S 1 ). Then, Then, there exist existss w ∈ L1 such that s = h(w). In this this case, case, w ∈ L1 ∪ L2 as well. Hence, s ∈ h(L1 ∪ L2 ). For (b), this is not the case. We can prove h(L1 ∩ L2 ) ⊆ h(L1 ) ∩ h(L2 ) but not the other way around. As a counterex counterexample ample,, let L1 = {a}, L2 = {b} and 1
h(a) = h(b) = c. Then, h(L1 ∩ L2 ) = L(∅) = ∅. However, h(L1 ) ∩ h(L2 ) = {c} ∩ {c} = {c}. This shows that h(L∩ L2 ) is not the same as h(L1 ) ∩ h(L2 ) for all regular languages L1 and L2 . For (c), this is true.
= = = = =
h(L1 L2 ) {h(w) : w ∈ L1 L2 } {h(w1 w2 ) : w1 ∈ L1 , w2 ∈ L2 } {h(w1 )h(w2 ) : w1 ∈ L1 , w2 ∈ L2 } {h(w1 ) : w1 ∈ L1 }{h(w2 ) : w2 ∈ L2 } h(L1 )h(L2 ).
Exercise 26, page 111. Let G1 and G2 be two regular grammars. Show how one can derive regular grammars for the languages (a) L(G1 ) ∪ L(G2 ). (b) L(G1 )L(G2 ). (c) L(G1 )∗ . Answer: Suppose G1 and G2 are right-linear grammars. Let G1 = (V 1 , T 1 , S 1 , P 1 ) and G2 = (V 2 , T 2 , S 2 , P 2 ). Without loss of generality, we can assume that V 1 and V 2 are disjoint and T 1 = T 2 . For (a), we construct G = (V , T , S , P ), where
• V = V 1 ∪ V 2 ∪ {S }, • T = T 1 = T 2 , • S is the start variable, • P = P 1 ∪ P 2 ∪ {S → S 1 |S 2 }. It can be checked that L(G) = L(G1 ) ∪ L(G2 ). For (b), we construct G = (V , T , S1 , P ), where
• V = V 1 ∪ V 2 , • T = T 1 = T 2 , • S 1 is the start variable,
2
• P = P 2 ∪ P 1 , where P 1 is obtained from P 1 by replacing every production of the form A → w (where A ∈ V 1 and w ∈ T 1∗ ) with A → wS 2 . It can be checked that L(G) = L(G1 )L(G2 ). For (c), we construct G = (V 1 , T 1 , S 1 , P ), where
• P = P 1 ∪ P 1 . Here, P 1 contain all productions of the form A → wS 1 , where A → w ∈ P (A ∈ V 1 and w ∈ T ∗ ). It can be checked that L(G) = L(G1 )∗ .
3
2
Elementary Questions about Regular Languages
Exercise 4, page 113. Show that for any regular L1 and L2 , there is an algorithm to determine whether or not L1 = L1 /L2 . Proof: We have L1 /L2 = {w : wu ∈ L1 for some u ∈ L2 }. Hence, L1 = L1 /L2 iff L1 L2 = L1 . Hence, we can construct a DFA for L1 L2 and L1 respectively. The only thing remaining is to check whether these two DFAs are equivalent. By Theorem 4.7, we can develop an algorithm for this purpose.
4
3
The Pumping Lemma
Exercise 4(b), page 122. Prove that the following language is not regular. L = {an bl ak : k = n + l}. Proof: We prove this by contradiction. Assume that L is regular. Then, so is L, i.e. {an bl ak : k = n + l} is also regular. By the Pumping Lemma, there exists m such that for any w ∈ L with |w | ≥ m can be decomposed as w = xyz such that |xy | ≤ m, |y| ≥ 1, and wi = xy i z is also in L for any i. Now consider the string s = am bm a2m . Applying the Pumping Lemma, we have s = xyz, where |xy | ≤ m. Hence, there exists p, r ≥ 0 and q ≥ 1 such that x = a p , y = aq and p + q + r = m. That is, s = (a p )(aq )(ar )bm a2m . Then, according to the Pumping Lemma, s2 = xy 2 z is also in L. That is, (a p )(a2q )(ar )bm a2m ∈ L. However, 2m = m + p + q + r < m + p + 2q + r, a contradiction. This shows that L is regular.
Exercise 5(c), page 122. Determine whether or not the following languages on Σ = {a} is regular L = {an :== k 3 for some k ≥ 0}. Answer: No, L is not regular. We prove this by contradiction. Assume that L is regular. Then, by the pumping lemma, there exists m such that for any w ∈ L with |w| ≥ m can be decomposed as w = xyz such that |xy | ≤ m, |y | ≥ 1, and wi = xy i z is also in L for any i. Now consider s = am . Applying the Pumping Lemma, we have s = xyz, where |xy | ≤ m. Hence, there exists p, r ≥ 0 and q ≥ 1 such that x = a p , y = aq and p + q + r = m. That is, s = (a p )(aq )(ar )am −m . Then, according to the Pumping Lemma, s2 = xy 2 z is also in L. That is, (a p )(a2q )(ar )am −m ∈ L. However, m3 = p + q + r + m3 − m < p + 2q + r + m3 − m but (m + 1) 3 > m3 + 3m > m 3 + q = p + 2q + r + m3 − m. This shows that p + 2q + r + m3 − m is a number between m3 and (m + 1)3 . Thus, s2 cannot be in L, a contradiction. Hence, we can conclude that L is regular. 3
3
3
5