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:2024:lab11 [2025/01/09 00:14]
cata_chiru [11.2. Closed under CFLs]
lfa:2024:lab11 [2026/01/18 17:55] (current)
cata_chiru
Line 135: Line 135:
  
 <hidden Solution 11.2.4> <hidden Solution 11.2.4>
 +
 +__**Intuition**__
  
 Reverse each production rule in the grammar for L, with $ L \in CFL $. Reverse each production rule in the grammar for L, with $ L \in CFL $.
  
-</​hidden>​+__**Formal solution - induction**__
  
-<hidden Debug visual Solution 11.2.4>​ +If \( G \) is a grammar, let \( H \)  be its reverse, so for production ​  ​\( A \to w \) in \( G \) we have  \( A \to w^R \)  in \( H \).
-If \( G \) is a grammar, let \( H \) be its reverse, so for production \( A \to w \) in \( G \) we have \( A \to w^R \) in \( H \).+
  
-Then by induction we show that the original grammar \( G \) generates a string iff the reverse grammar \( H \) generates the reverse of the string. Formally: ​  +Then by induction we show that the original grammar ​ \( G \) generates a string iff the reverse grammar \( H \) generates the reverse of the string. Formally: ​  
-\( A \xRightarrow{*}_G w \iff A \Rightarrow{*}_H w^R \).+ \( A \to^{*}_G w \iff A \to^{*}_H w^R \).
  
 1. **Basis**:  ​ 1. **Basis**:  ​
  
-In zero steps, we have \( A \Rightarrow{0}_G A \iff A \Rightarrow{0}_H A \) $.+In zero steps, we have \( A \to^{0}_G A \iff A \to^{0}_H A \).
  
 2. **Induction**:  ​ 2. **Induction**:  ​
-Assuming ​\( A \Rightarrow{*}_G w_1 B w_2 \iff A \Rightarrow{*}_H w_2^R B w_1^R \) $,  ​+Assuming \( A \to^{*}_G w_1 B w_2 \iff A \to^{*}_H w_2^R B w_1^R \),  ​
  
-we can apply any production ​\( B \to u \) in \( G \) (and in \( H \) in reverse) and obtain:  ​+we can apply any production \( B \to u \) in \( G \) (and in \( H \) in reverse) and obtain:  ​
  
-\( A \rightarrow^{*}_G w_1 u w_2 \) +\( A \to^{*}_G w_1 u w_2 \)  
 + 
 +\( A \to^{*}_H w_2^R u^R w_1^R \),   where indeed \( w_2^R u^R w_1^R \) is the reverse of \( w_1 u w_2 \).
  
-$ \( A \rightarrow^{*}_H w_2^R u^R w_1^R \) $,   where indeed $ \( w_2^R u^R w_1^R \) $ is the reverse of $ \( w_1 u w_2 \) $. 
 </​hidden>​ </​hidden>​
  
Line 192: Line 194:
 **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.> <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} $.+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>​ </​hidden>​