Sunteți pe pagina 1din 5

Tutorial 4

Yi Zhou (yzhou@scm.uws.edu.au)

Closure Properties of Regular Languages

Exercise 2(b), page 108. Use the construction in Theorem 4.1 to nd NFAs that accept L(ab a ) L(a b a).

Exercise 6, page 109. The symmetric dierence of two sets S1 and S2 is dened as S1 S2 = {x : x S1 or x S2 , but x is not in both S1 and S2 }.

Show that the family of regular language is closed under symmetric dierence. Proof: We have S1 S2 = (S1 S2 ) (S2 S1 ). Since regular language is closed under union, intersection and complement, it is closed under symmetric dierence (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 case, h(w) L(S1 ). That is, s L(S1 ). On the other hand, for any s h(L1 ) h(L2 ). Without loss of generality, we can assume that s L(S1 ). Then, there exists w L1 such that s = h(w). In this 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 counterexample, 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 = (V1 , T1 , S1 , P1 ) and G2 = (V2 , T2 , S2 , P2 ). Without loss of generality, we can assume that V1 and V2 are disjoint and T1 = T2 . For (a), we construct G = (V, T, S, P ), where V = V1 V2 {S}, T = T1 = T2 , S is the start variable, P = P1 P2 {S S1 |S2 }. It can be checked that L(G) = L(G1 ) L(G2 ). For (b), we construct G = (V, T, S1 , P ), where V = V1 V2 , T = T1 = T2 , S1 is the start variable,

P = P2 P1 , where P1 is obtained from P1 by replacing every production of the form A w (where A V1 and w T1 ) with A wS2 . It can be checked that L(G) = L(G1 )L(G2 ). For (c), we construct G = (V1 , T1 , S1 , P ), where P = P1 P1 . Here, P1 contain all productions of the form A wS1 , where A w P (A V1 and w T ). It can be checked that L(G) = L(G1 ) .

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 i 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.

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 = ap , y = aq and p + q + r = m. That is, s = (ap )(aq )(ar )bm a2m . Then, according to the Pumping Lemma, s2 = xy 2 z is also in L. That is, (ap )(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. 3 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 = ap , y = aq 3 and p + q + r = m. That is, s = (ap )(aq )(ar )am m . Then, according to the 3 Pumping Lemma, s2 = xy 2 z is also in L. That is, (ap )(a2q )(ar )am m L. However, m3 = p + q + r + m3 m < p + 2q + r + m3 m but (m + 1)3 > m3 + 3m > m3 + 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.

S-ar putea să vă placă și