Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
lfa:2025:lab10 [2026/01/18 17:57]
cata_chiru
lfa:2025:lab10 [2026/01/20 11:49] (current)
cata_chiru
Line 1: Line 1:
-====== ​11. Closure properties for Context-Free Languages ======+====== ​10. Closure properties for Context-Free Languages ======
  
-Analogy with Subtraction between $ \mathbb{Z} $ and $ \mathbb{N} $.+Analogy with Subtraction, Division ​between $ \mathbb{Z} $ and $ \mathbb{N} $.
  
-===== 11.0. Lexer Spec =====+===== 10.0. Lexer Spec =====
 Given the following specs, construct the lexer DFA as presented in Lecture 14: Given the following specs, construct the lexer DFA as presented in Lecture 14:
   * PAIRS: $ (10 | 01)* $   * PAIRS: $ (10 | 01)* $
Line 54: Line 54:
  
  
-===== 11.1. Not Closed under CFLs =====+===== 10.1. Not Closed under CFLs =====
  
-**11.1.1.** Intersection is not a closure property.+**10.1.1.** Intersection is not a closure property.
  
 <hidden Solution 11.1.1 > <hidden Solution 11.1.1 >
Line 69: Line 69:
 </​hidden>​ </​hidden>​
  
-**11.1.2.** Complement is not a closure property.+**10.1.2.** Complement is not a closure property.
  
-<hidden Solution ​11.1.2 >+<hidden Solution ​10.1.2 >
  ​Suppose Complement is a closure property $\Rightarrow$ complements of CFLs are CFLs, we will prove in 11.2.2 that Union is a closure property.  ​Suppose Complement is a closure property $\Rightarrow$ complements of CFLs are CFLs, we will prove in 11.2.2 that Union is a closure property.
  
Line 82: Line 82:
 </​hidden>​ </​hidden>​
  
-**11.1.3.** Difference is not a closure property.+**10.1.3.** Difference is not a closure property.
  
-<hidden Solution ​11.1.3 >+<hidden Solution ​10.1.3 >
  ​Suppose Difference is a closure property.  ​Suppose Difference is a closure property.
  
Line 96: Line 96:
  
  
-===== 11.2. Closed under CFLs =====+===== 10.2. Closed under CFLs =====
  
-**11.2.1.** Concat is a closure property.+**10.2.1.** Concat is a closure property.
  
-<hidden Solution ​11.2.1.>+<hidden Solution ​10.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: 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:
  
Line 111: Line 111:
  
  
-**11.2.2.** Union is a closure property.+**10.2.2.** Union is a closure property.
  
-<hidden Solution ​11.2.2.>+<hidden Solution ​10.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: 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:
  
Line 122: Line 122:
 </​hidden>​ </​hidden>​
  
-**11.2.3.** Kleene Star is a closure property.+**10.2.3.** Kleene Star is a closure property.
  
-<hidden Solution ​11.2.3.>+<hidden Solution ​10.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: 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:
  
Line 134: Line 134:
  
  
-**11.2.4.** Reverse is a closure property.+**10.2.4.** Reverse is a closure property.
  
-<hidden Solution ​11.2.4>+<hidden Solution ​10.2.4>
  
 __**Intuition**__ __**Intuition**__
Line 164: Line 164:
 </​hidden>​ </​hidden>​
  
-**11.2.5.** Intersection with a regular language is a closure property.+**10.2.5.** Intersection with a regular language is a closure property.
  
-<hidden Solution ​11.2.5.>+<hidden Solution ​10.2.5.>
 Let \( L_1 \) be a context-free language and \( P = (K_1, \Sigma, \Gamma, \Delta_1, q^{1}_{0}, F_1) \)  ​ 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.  ​ be its respective PDA.  ​
Line 191: Line 191:
 </​hidden>​ </​hidden>​
  
-**11.2.6.** Difference with a regular language is a closure property. +**10.2.6.** Difference with a regular language is a closure property. 
-<hidden Solution ​11.2.6.>+<hidden Solution ​10.2.6.>
 Let \( L_1 \) be a context-free language and \( L_2 \) a regular language. 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. $ \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} $.+From 10.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>​ </​hidden>​