7.2. Closure Properties for CFLs¶
7.2.1. Closure Properties¶
L={anbn|n>0}, LL={anbnambm|n>0,m>0}
Theorem: CFL’s are closed under union, concatenation, and star-closure.
Given: 2 CFGs G1=(V1,T1,S1,P1) and G2=(V2,T2,S2,P2)
7.2.2. Union¶
Construct G3 such that L(G3)=L(G1)∪L(G2).G3=(V3,T3,S3,P3)V3=V1∪V2∪{S3},T3=T1∪T2, and P3=P1∪P2∪{S3→S1|S2}.
7.2.3. Concatenation¶
Construct G3 such that L(G3)=L(G1)L(G2).G3=(V3,T3,S3,P3)V3=V1∪V2∪{S3},T3=T1∪T2, and P3=P1∪P2∪{S3→S1S2}.
7.2.4. Star-Closure¶
Construct G3 such that L(G3)=L(G1)∗G3=(V3,T3,S3,P3)V3=V1∪{S3},T3=T1, and P3=P1∪P2∪{S3→S1S3|λ}.
7.2.5. Intersection¶
Theorem: CFL’s are NOT closed under intersectionLet L1={anbncm|n,m>0} and L2={anbmcm|n,m>0}L1 and L2 are CFLsThen L1∩L2={anbncn|n>0} is not CFL.
7.2.6. Complementation¶
Theorem: CFL’s are NOT closed under complementation.Set identity:L1∩L2=¯¯L1∪¯L2Thus, CFLs are not closed under complementation.
7.2.7. Example for theorem below:¶
L1={anbman∣m>0,n>0}L2={w∣w∈Σ∗ and w has an even number of b’s}, Σ={a,b},L1∩L2={anbmbman} is a CFL.
7.2.8. Regular Intersection (1)¶
CFL’s are closed under regular intersection. If L1 is CFL and L2 is regular, then L1∩L2 is CFL.
7.2.9. Some Decision Problems for CFGs¶
For a given CFG G, is L(G) empty?A: Remove useless productions. Then, is S useless?For a given CFG G, is L(G) infinite?A: Is there a repeating variable?For two given CFGs G1 and G2, does L(G1)=L(G2)?A: There is no general algorithm that can always deterimine if two CFG generate the same language!
7.2.10. A Richer Grammar¶
Here is a grammar for L={anbncn∣n≥1}.S→abc∣aAbcAb→bAAc→BbccbB→BbaB→aa∣aaAConsider how to derive a3b3c3
This is called a Context Sensitive Grammar