72.1k views
5 votes
CFLs are closed under union

If L1 and L2 are CFLs, then L1 ∪ L2 is a CFL.
Proof
1. Let L1 and L2 be generated by the CFG, G1 = (V1, T1, P1, S1) and
G2 = (V2, T2, P2, S2), respectively.
2. Without loss of generality, subscript each nonterminal of G1 with a 1,
and each nonterminal of G2 with a 2 (so that V1 ∩ V2 = ∅).
3. Define the CFG, G, that generates L1 ∪ L2 as follows:
G = (V1 ∪ V2 ∪ {S}, T1 ∪ T2, P1 ∪ P2 ∪ S2, S).

User Giavac
by
7.5k points

1 Answer

1 vote

Final answer:

To prove that CFLs are closed under union, one can construct a new CFG G that combines the productions of two given CFGs G1 and G2, representing the CFLs L1 and L2, respectively, along with a new production for the start symbol S, demonstrating that the unified language L1 ∪ L2 is also a CFL.

Step-by-step explanation:

The question pertains to the concept that Context-Free Languages (CFLs) are closed under the operation of union. To prove this, if you have two CFLs, L1 and L2, generated by the context-free grammars (CFGs) G1 and G2 respectively, you can construct a new CFG, G, which generates the union of L1 and L2. Following the steps provided in the question:

  • Ensure that the nonterminals of G1 and G2 are distinct by subscripting them appropriately.
  • Create a new start symbol S that is not in V1 or V2.
  • Define CFG G to include all productions from G1 and G2, plus a new production S → S1 | S2, where S1 and S2 are the original start symbols of G1 and G2.
  • This new CFG G will generate all strings that either CFG G1 or CFG G2 would generate, hence generating L1 ∪ L2.

Thus, because you can explicitly construct a CFG for L1 ∪ L2, it follows that CFLs are indeed closed under the operation of union, which fulfills one of the properties of being a CFL.

User Geo Jacob
by
7.7k points