Beruflich Dokumente
Kultur Dokumente
ba(a b)
, L
2
= a
i
b
j
, i > j and L
3
= a
i
b
j
, i < j. It is
not hard to see that L
c
= L
1
L
2
L
3
, so it suces to show that these three
are CF. L
1
is regular so certainly CF. L
2
is the concatenation of a
+
(which is
regular, thus CF) with L itself, so L
2
is CF. Finally, L
3
is the concatenation of
L with b
+
.
8 CFLs and intersection (A)
Use the fact that the language L = {w | w = a
n
b
n
a
n
} is not context-free to
prove that the class of CFLs is not closed under intersection. (Hint: nd two
CFLs whose intersection is L)
Solution:
Let L
1
= a
n
b
n
a
i
and L
2
= a
i
b
n
a
n
. It is not hard to see that both are CF as
the concatenation of CF languages. Also L = L
1
L
2
, so if CFLs were closed
under intersection, L would be CF.
9 CFLs playing with regular languages (A)
Show that if a language L
1
is context-free and a language L
2
is regular, then
L
1
L
2
and L
1
\ L
2
are also context-free. Is L
2
\ L
1
also context-free? Why?
(Hint: remember that A \ B = A B
c
for any sets A, B)
Solution:
Since L
1
is CF, there exists a PDA for it. We will combine this PDA with the
DFA that exists for L
2
to build a PDA for L
1
L
2
. The idea is again to create
a machine that keeps track of the states of both machines at the same time. If
Q
1
, Q
2
are the sets of states of the two machines then Q
1
Q
2
will be the set
of states of the new one. Suppose that the rst machine allows the transition
4
1
(q, a, b) = (q
. Then
in the new machine include the transition ((q, r), a, b) = ((q
, r
), c). Repeat
this for all pairs of transitions and set the accepting states to be F
1
F
2
, where
F
1
, F
2
are the accepting states of the two machines.
The fact that L
1
\ L
2
is CF follows immediately from the above since L
c
2
is
also regular and L
1
\ L
2
= L
1
L
c
2
.
Finally, L
2
\ L
1
is not necessarily CF. Suppose that we could prove the
contrary. Then for the special case L
2
=
\L
1
is CF, but this is equal to L
c
1
, so we would
have shown that CF languages are closed under complement, a contradiction.
5