Does that mean only non deterministic context free languages are closed under union? Then why is it mentioned in almost all text books and sites that CFLs in general are closed under Union? An intuitive explanation will suffice. Detailed proof not necessary.
-
For the general term "closed under union" it is always important to state: closed for which set. A set X (having sets as elements) is closed under union if for every element A in X and for every B in X, A U B is also in X. So: Taking two languages L1, L2 from the set of all CF languages, the language L1 U L2 is ALSO CF language. However, if you take two languages L1, L2 that are in the set of det. CF languages, L1 U L2 does not necessarily have to be in the set of det. CF languages, since the set of det. CF languages is not closed underunion. However, L1 U L2 is context-free. – Pachelbel Apr 10 '16 at 10:33
1 Answers
Deterministic context-free languages (DCFLs), defined as those languages that are recognizable by deterministic pushdown automata, are a proper subset of CFLs (even more, DFCLs are a proper subset of CFLs with unambiguous grammars). In other words every DCFL admits an unambiguous context-free grammar.
This means that the union of two DFCLs need not be a DFCL; my intuition is that the deterministic pushdown automaton becomes unable to choose between alternative state transitions when faced with a union of two DFCLs; that is, while two DCFLs admit an unambiguous grammar, their union need not.
CFLs are closed under union which follows from a powerful result, called the substitution theorem, which, roughly speaking, says that given a context-free language L we can replace each symbol of the strings of L by an entire context-free language, and end up with a context-free languge. (See Chapter 7 of Introduction to the theory of languages, automata, and computation by John Hopcroft, Jeff Ullman, and the late Rajeev Motwani.)

- 4,705
- 24
- 38