Homework 3

DCP3122 Introduction to Formal Languages, Spring 2015
9-Apr-2015
Homework 3 - Solution
Instructor: Prof. Wen-Guey Tzeng
1. Show that the family of regular languages is closed under finite union and intersection, that
is, if L1 , L2 , . . ., Ln are regular, then
\
[
Li
Li and LI =
LU =
i={1,2,...,n}
i={1,2,...,n}
are also regular.
Ans. The following shows that LU and LI are regular if L1 , L2 , . . ., Ln are regular.
• For LU , if L1 , L2 , . . ., Ln are regular, there exists regular expressions r1 , r2 , . . ., rn
such that L1 = L(r1 ), L2 = L(r2 ), . . ., Ln = L(rn ). By definition, r1 + r2 + . . . + rn is
the regular expression denoting L1 ∪ L2 ∪ . . . ∪ Ln . Thus, closure under finite union is
immediate.
• For LI , let L1 = L(M1 ), L2 = L(M2 ), . . ., Ln = L(Mn ), where M1 = (Q1 , Σ, δ1 , q1,0 , F1 ),
M2 = (Q2 , Σ, δ2 , q2,0 , F2 ), . . ., Mn = (Qn , Σ, δn , qn,0 , Fn ) are DFAs. We construct from
M1 , M2 , . . ., Mn a combined automaton M = (Q, Σ, δ, q0 = (q1,0 , q2,0 , . . . , qn,0 ), F ),
whose state set Q = Q1 × Q2 × . . . × Qn consists of tuples (q1,i1 , q2,i2 , . . . , qn,in ) whenever
Mk is in state qk,ik , 1 ≤ k ≤ n. This is achieved by taking δ((q1,i1 , q2,i2 , . . . , qn,in ), a) =
(q1,j1 , q2,j2 , . . . , qn,jn ), whenever δ1 (q1,i1 , a) = q1,j1 , δ2 (q2,i2 , a) = q2,j2 , . . ., and δn (qn,in , a) =
qn,jn for all a ∈ Σ. F is defined a s the set of all (q1,i1 , q2,i2 , . . . , qn,in ) such that q1,i1 ∈ F1 ,
q2,i2 ∈ F2 , . . ., and qn,in ∈ Fn . Now we have that w ∈ L1 ∩ L2 ∩ . . . ∩ Ln if and only if it
is accepted by M . Consequently, LI is regular.
2. Define the complementary (or cor) of two languages by
cor(L1 , L2 ) = {w : w ∈ L1 or w ∈ L2 }.
Show that the family of regular languages is closed under the cor operation.
Ans. cor(L1 , L2 ) = {w : w ∈ L1 or w ∈ L2 } = {w : w ∈ L1 } ∪ {w : w ∈ L2 }. If
L1 and L2 are regular, let M1 = (Q1 , Σ, δ1 , q0 , F1 ) and M2 = (Q2 , Σ, δ2 , p0 , F2 ) be DFAs
that accept L1 and L1 , respectively. Then the DFAs M 1 = (Q1 , Σ, δ1 , q0 , Q1 − F1 ) and
M 2 = (Q2 , Σ, δ2 , p0 , Q2 − F2 ) accept L1 and L2 . Thus, {w : w ∈ L1 } and {w : w ∈ L2 } are
regular. Then by the results of the last problem, we know that the family of regular languages
is closed under finite union. Therefore, we conclude that cor(L1 , L2 ) is regular.
3. Let L1 = L(a∗ baa∗ ) and L2 = L(aba∗ ). Find L1 /L2 .
Ans. We first construct a DFA that accepts L1 as follows. We check each state q0 , q1 , q2 ,
and q3 to see whether there is a walk labeled aba∗ to the final state q2 . We see that only q0
qualifies. Thus, the result L1 /L2 = L(a∗ ) clearly.
1-1
4. The left quotient of a language L1 with respect to L2 is defined as
L2 /L1 = {y : x ∈ L2 , xy ∈ L1 }.
Show that the family of regular languages is closed under the left quotient with a regular
language.
Ans. We have that the reverse language of L2 /L1 is
R
R
R
R
(L2 /L1 )R = {y R : y R xR ∈ LR
1 , x ∈ L2 } = L1 /L2 .
R
If L1 and L2 are regular, from the result of homework 1-(12), we have that LR
1 and L2
R
R
R
are regular. Now, because the right-quotient of LR
1 with L2 , i.e., L1 /L2 , is regular (from
R
Theorem 4.4 in the textbook), we have that (L2 /L1 ) is regular. Again, from the result of
homework 1-(12), we have that ((L2 /L1 )R )R = L2 /L1 is regular.
5. Show that there exists an algorithm for determining if λ ∈ L, for any regular language L.
Ans. We represent the language L by some DFA, then test λ to see if it is accepted by this
automaton.
6. Exhibit an algorithm for determining whether or not a regular language L contains any string
w such that wR ∈ L.
Ans. The language that contains any string w such that wR ∈ L can be defined as L ∩ LR .
By closure, we know that L ∩ LR is regular. Thus we represent the language L ∩ LR by some
DFA, then test w to see if it is accepted by this automaton .
7. Prove that L = {an bl ak : k 6= n + l} is not regular.
Ans. Assume that L is regular, so that the pumping lemma must hold. Given some positive
integer m, we pick a string w = am bm a2m+1 ∈ L. Because of the constraint |xy| ≤ m and
|y| ≥ 1, y must be all b’s, that is, y = bz , 1 ≤ z ≤ m. We now pump up, using i = 2.
The result string w2 = am+z bm a2m+1 is not in L when z = 1. This contradicts the pumping
lemma and thereby indicates that the assumption that L is regular must be false.
8. Prove that L = {ww : w ∈ {a, b}∗ } is not regular.
Ans. Assume that L is regular, so that the pumping lemma must hold. Given some positive
integer m, we pick a string ww ∈ L with |w| = m. Because of the constraint |xy| ≤ m and
|y| ≥ 1, y must be a substring of w in the tail. We now pump up, using i = 0. The result
string is not in L clearly. This contradicts the pumping lemma and thereby indicates that
the assumption that L is regular must be false.
9. For Σ = {a}, determine whether or not L = {an : n = k 3 for some k ≥ 0} is regular.
Ans. Assume that L is regular, so that the pumping lemma must hold. Given some positive
3
integer m, we pick a string w = am ∈ L. Because of the constraint |xy| ≤ m and |y| ≥ 1, y
must be all a’s, that is, y = az , 1 ≤ z ≤ m. We now pump up, using i = 2. The result string
1-2
3
w0 = am +z is not in L because m3 < m3 + z < (m + 1)3 . This contradicts the pumping
lemma and thereby indicates that the assumption that L is regular must be false.
10. For each of the following languages, make a conjecture whether to not it is regular. Then
prove your conjecture.
(a) L = {an bl : n/l is an integer}.
(b) L = {an bl : n ≤ l ≤ 2n}.
(c) L = {an bl : n > 100, l ≤ 100}.
Ans. The language in (a) and (b) are not regular and the language in (c) is regular, we prove
our conjecture as follows.
(a) Assume that L is regular, so that the pumping lemma must hold. Given some positive
integer m, we pick a string w = am bm ∈ L. Because of the constraint |xy| ≤ m and
|y| ≥ 1, y must be all a’s, that is, y = az , 1 ≤ z ≤ m. We now pump up, using i = 0.
The result string w0 = am−z bm is not in L when z = 1, 2, . . . , m − 1. This contradicts
the pumping lemma and thereby indicates that the assumption that L is regular must
be false.
(b) Assume that L is regular, so that the pumping lemma must hold. Given some positive
integer m, we pick a string w = am bm ∈ L. Because of the constraint |xy| ≤ m and
|y| ≥ 1, y must be all a’s, that is, y = az , 1 ≤ z ≤ m. We now pump up, using i = 2.
The result string w2 = am+z bm is not in L when z = 1, 2, . . . , m. This contradicts the
pumping lemma and thereby indicates that the assumption that L is regular must be
false.
(c) The regular expression of L is a101 a∗ (λ + b + b2 + . . . + b100 ).
1-3