Subjects formal languages and automata theory

Union Context Free

Step-by-step solutions with LaTeX - clean, fast, and student-friendly.

Search Solutions

Union Context Free


1. **Stating the problem:** We are given two context-free languages (CFLs) $L_1$ and $L_2$. We need to prove that their union $L_1 \cup L_2$ is also context-free. 2. **Recall the definition:** A language is context-free if there exists a context-free grammar (CFG) that generates it. 3. **Given:** $L_1$ and $L_2$ are context-free languages. Therefore, there exist CFGs $G_1 = (V_1, \Sigma, R_1, S_1)$ generating $L_1$ and $G_2 = (V_2, \Sigma, R_2, S_2)$ generating $L_2$. 4. **Constructing a CFG for $L_1 \cup L_2$:** We define a new grammar $G = (V, \Sigma, R, S)$ where: - $V = V_1 \cup V_2 \cup \{S\}$, adding a new start symbol $S$ not in $V_1$ or $V_2$. - $R = R_1 \cup R_2 \cup \{S \to S_1 | S_2\}$, that is, all the rules from both grammars plus a new rule that allows $S$ to derive either $S_1$ or $S_2$. 5. **Explanation:** By this construction, $G$ can generate all strings generated by either $G_1$ or $G_2$, so $L(G) = L_1 \cup L_2$. 6. **Conclusion:** Since $G$ is a context-free grammar generating $L_1 \cup L_2$, the union $L_1 \cup L_2$ is a context-free language. Hence, we have proven that the union of two context-free languages is context-free.