Closure Property of Context-Free Languages

 

Theorem 8.3 — Closure Properties of CFLs

The family of context-free languages is closed under union, concatenation, and star-closure.

That is,
If L1and L2L_2 are context-free languages, then

  1. L1L2L_1 \cup L_2 is context-free.

  2. L1L2={xy  xL1,yL2} is context-free.

  3. L1={x1x2...xn  xiL1,n0}L_1^* = \{ x_1x_2...x_n \ | \ x_i \in L_1, n \ge 0 \} is context-free.


Proof

Let

G1=(V1,T1,S1,P1)andG2=(V2,T2,S2,P2)G_1 = (V_1, T_1, S_1, P_1) \quad \text{and} \quad G_2 = (V_2, T_2, S_2, P_2)

be two context-free grammars generating L1L_1and L2L_2respectively.

Without loss of generality, assume that

V1V2=V_1 \cap V_2 = \emptyset

—that is, the two grammars use disjoint sets of variables.


1. Closure under Union

Construct a new grammar

G3=(V3,T3,S3,P3)G_3 = (V_3, T_3, S_3, P_3)

where

  • V3=V1V2{S3}V_3 = V_1 \cup V_2 \cup \{ S_3 \}

  • T3=T1T2T_3 = T_1 \cup T_2

  • P3=P1P2{S3S1  S2}P_3 = P_1 \cup P_2 \cup \{ S_3 \rightarrow S_1 \ | \ S_2 \}

That is, S3S_3 is a new start variable not in V1V2V_1 \cup V_2

So, G3G_3 contains all the productions of both grammars plus one extra production:

S3S1  S2S_3 \rightarrow S_1 \ | \ S_2

Now, any derivation in G3G_3 begins with either S3S1S_3 \Rightarrow S_1 or S3S2S_3 \Rightarrow S_2.

  • If S3S1wS_3 \Rightarrow S_1 \Rightarrow^* w, then wL1w \in L_1

  • If S3S2wS_3 \Rightarrow S_2 \Rightarrow^* w, then wL2w \in L_2

Hence,

L(G3)=L1L2L(G_3) = L_1 \cup L_2

Since G3G_3 is a CFG, the union of two CFLs is a CFL.


2. Closure under Concatenation

Construct

G4=(V4,T4,S4,P4)G_4 = (V_4, T_4, S_4, P_4)

where

  • V4=V1V2{S4}V_4 = V_1 \cup V_2 \cup \{ S_4 \}

  • T4=T1T2T_4 = T_1 \cup T_2

  • P4=P1P2{S4S1S2}

Thus, G4G_4 generates strings where something from L1L_1 is followed by something from L2L_2:

S4S1S2w1S2w1w2S_4 \Rightarrow S_1S_2 \Rightarrow^* w_1S_2 \Rightarrow^* w_1w_2

with w1L1w_1 \in L_1 and w2L2

Hence,

L(G4)=L1L2L(G_4) = L_1L_2

So, CFLs are closed under concatenation.


3. Closure under Kleene Star

Let

G5=(V5,T5,S5,P5)G_5 = (V_5, T_5, S_5, P_5)

where

  • V5=V1{S5}V_5 = V_1 \cup \{ S_5 \}

  • T5=T1T_5 = T_1

  • P5=P1{S5S1S5  ϵ}P_5 = P_1 \cup \{ S_5 \rightarrow S_1S_5 \ | \ \epsilon \}

Now the grammar can either:

  • Produce a string from L1L_1 and then repeat the process (S5S1S5S_5 \rightarrow S_1S_5), or

  • Stop (S5ϵS_5 \rightarrow \epsilon).

Thus, it generates any finite concatenation of strings from L1L_1:

L(G5)=L1L(G_5) = L_1^*

Therefore, CFLs are closed under the Kleene star operation.


Conclusion

We have constructed context-free grammars for each of the three operations. Therefore:

The family of context-free languages is closed under union, concatenation, and star-closure.\boxed{\text{The family of context-free languages is closed under union, concatenation, and star-closure.}}

🧩 Additional Note

CFLs are not closed under certain operations such as:

  • Intersection

  • Complement

  • Difference

This is an important distinction—while regular languages are closed under all Boolean operations, context-free languages are not.

Comments

Popular posts from this blog

Theory Of Computation PCCST302 KTU Semester 3 BTech 2024 Scheme

Non deterministic Finite Automata NFA

Formal Definition - Turing Machine