Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lfa:2024:lab11 [2025/01/08 22:45] cata_chiru |
lfa:2024:lab11 [2025/01/09 00:14] (current) cata_chiru [11.2. Closed under CFLs] |
||
---|---|---|---|
Line 97: | Line 97: | ||
**11.2.1.** Concat is a closure property. | **11.2.1.** Concat is a closure property. | ||
+ | |||
+ | <hidden Solution 11.2.1.> | ||
+ | Let \( A \) and \( B \) be context-free languages over an alphabet \( \Sigma \), and let \( G_A = (V_A, \Sigma, R_A, S_A) \) and \( G_B = (V_B, \Sigma, R_B, S_B) \) be context-free grammars that generate \( A \) and \( B \) respectively. By renaming the variables if necessary, we assume that \( V_A \) is disjoint from \( V_B \), and that neither variable set contains the variable \( S \). We now construct a new CFG by writing: | ||
+ | |||
+ | \[ | ||
+ | G = (V_A \cup V_B \cup \{S\}, \Sigma, R_A \cup R_B \cup \{S \to S_AS_B\}, S) | ||
+ | \] | ||
+ | |||
+ | </hidden> | ||
+ | |||
+ | |||
**11.2.2.** Union is a closure property. | **11.2.2.** Union is a closure property. | ||
+ | |||
+ | <hidden Solution 11.2.2.> | ||
+ | Let \( A \) and \( B \) be context-free languages over an alphabet \( \Sigma \), and let \( G_A = (V_A, \Sigma, R_A, S_A) \) and \( G_B = (V_B, \Sigma, R_B, S_B) \) be context-free grammars that generate \( A \) and \( B \) respectively. By renaming the variables if necessary, we assume that \( V_A \) is disjoint from \( V_B \), and that neither variable set contains the variable \( S \). We now construct a new CFG by writing: | ||
+ | |||
+ | \[ | ||
+ | G = (V_A \cup V_B \cup \{S\}, \Sigma, R_A \cup R_B \cup \{S \to S_A | S_B\}, S) | ||
+ | \] | ||
+ | |||
+ | </hidden> | ||
**11.2.3.** Kleene Star is a closure property. | **11.2.3.** Kleene Star is a closure property. | ||
+ | |||
+ | <hidden Solution 11.2.3.> | ||
+ | Let \( A \) be a context-free languages over an alphabet \( \Sigma \), and let \( G_A = (V_A, \Sigma, R_A, S_A) \) be the context-free grammar that generate \( A \). We now construct a new CFG by writing: | ||
+ | |||
+ | \[ | ||
+ | G = (V_A \cup \{S\}, \Sigma, R_A \cup \{S \to SS | S_A | \epsilon\}, S) | ||
+ | \] | ||
+ | |||
+ | </hidden> | ||
+ | |||
**11.2.4.** Reverse is a closure property. | **11.2.4.** Reverse is a closure property. | ||
Line 134: | Line 164: | ||
**11.2.5.** Intersection with a regular language is a closure property. | **11.2.5.** Intersection with a regular language is a closure property. | ||
+ | |||
+ | <hidden Solution 11.2.5.> | ||
+ | Let \( L_1 \) be a context-free language and \( P = (K_1, \Sigma, \Gamma, \Delta_1, q^{1}_{0}, F_1) \) | ||
+ | be its respective PDA. | ||
+ | |||
+ | Let \( L_2 \) be a regular language and \( A = (K_2, \Sigma, \delta, q_{20}, F_2) \) be its respective DFA. | ||
+ | |||
+ | We build the following PDA \( (K, \Sigma, \Gamma, \Delta, q_0, F) \) where: | ||
+ | |||
+ | - \( K = K_1 \times K_2 \) | ||
+ | |||
+ | - \( q_0 = (q^{1}_{0}, q^{2}_{0}) \) | ||
+ | |||
+ | Transition rules for \( \Delta \): | ||
+ | |||
+ | 1. \( ((q_1, q_2), c, \alpha, (q_1', q_2'), \beta) \in \Delta \) | ||
+ | iff \( (q_1, c, \alpha, q_1', \beta) \in \Delta_1 \) and \( \delta(q_2, c) = q_2' \). | ||
+ | |||
+ | 2. \( ((q_1, q_2), \epsilon, \alpha, (q_1', q_2), \beta) \in \Delta \) | ||
+ | iff \( (q_1, \epsilon, \alpha, q_1', \beta) \in \Delta_1 \). | ||
+ | |||
+ | - \( F = F_1 \times F_2 \) | ||
+ | |||
+ | The PDA accepts \( L(P) \cap L(A) \). | ||
+ | </hidden> | ||
**11.2.6.** Difference with a regular language is a closure property. | **11.2.6.** Difference with a regular language is a closure property. | ||
+ | <hidden Solution 11.2.6.> | ||
+ | Let \( L_1 \) be a context-free language and \( L_2 \) a regular language. | ||
+ | |||
+ | $ \overline{L_2} $ is regular, as complement is a closure property for regular languages. | ||
+ | |||
+ | From 11.2.5, we know that the intersection is closed between CFLs and Regular Languages, and write $ L_1 \setminus L_2 = L_1 \cap \overline{L_2} $. | ||
+ | |||
+ | </hidden> |