Closure and Decision Properties of CFL

 

Closure properties of CFLs

Closed under — you can always build a grammar/PDA from the given ones.

  1. Union: If L1,L2 are CFLs, then L1L2L_1\cup L_2 is a CFL.
    Construction sketch: Given grammars G1,G2G_1,G_2 with disjoint nonterminals, add a new start symbol SS and rule SS1S2S\to S_1 \mid S_2. (Or for PDAs, nondeterministically choose which PDA to simulate.)

  2. Concatenation: If L1,L2L_1,L_2 are CFLs then L1L2L_1L_2is a CFL.
    Construction sketch: New start SS1S2S\to S_1 S_2 (or make the PDA simulate the first then the second).

  3. Kleene star: If LL is CFL then LL^*is CFL.
    Construction sketch: Grammar rule SS1SεS\to S_1 S \mid \varepsilon

  4. Reversal: If LL is CFL then LRL^R is CFL.
    Construction sketch: Reverse each right-hand side in the grammar (or run the PDA backwards with stack actions reversed).

  5. Homomorphism: If hh is a homomorphism and LL is CFL, then h(L) is CFL. Sketch: Apply hh to terminals in productions (or have PDA output mapped symbols).

  6. Inverse homomorphism: If hh is a homomorphism and LL is CFL, then h1(L)h^{-1}(L)is CFL.
    Sketch: Build a PDA that, on input ww, simulates the PDA for LL on h(w)h(w) (or use grammar constructions).

  7. Intersection with regular languages: If LL is CFL and RR is regular, then LRL \cap R is CFL.
    Construction sketch: Product construction: simulate the PDA for LL and the DFA for RR in parallel (PDA keeps its stack and the DFA state in its control).

  8. (Substitution by regular languages): Replacing each terminal by a regular language yields a CFL. (This is a generalization of homomorphism and inverse homomorphism.)


Not closed under — there exist CFLs L1,L2L_1,L_2 with an operation producing a non-CFL:

  1. Intersection (general): CFLs are not closed under intersection.
    Counterexample:

    L1={aibicji,j0},L2={aibjcji,j0}L_1=\{a^i b^i c^j \mid i,j\ge0\},\quad L_2=\{a^i b^j c^j \mid i,j\ge0\}

    Both L1L_1 and L2L_2 are CFLs, but
    L1L2={anbncnn0}L_1\cap L_2=\{a^n b^n c^n \mid n\ge0\}, which is not context-free.

  2. Complement: CFLs are not closed under complement.
    Reason: If CFLs were closed under complement, then closure under union + De Morgan would imply closure under intersection — contradiction (see previous point).

  3. Difference: Not closed (difference can be expressed with complement + intersection).


Deterministic CFLs (DCFLs) — note the contrast: DCFLs (languages of deterministic PDAs) enjoy some different properties: DCFLs are closed under complement (a classic result) but not closed under union or general intersection. I’ll mention DCFLs further if you want.


Decision properties (which questions about CFLs are decidable?)

Below is a list of common decision problems, with status and why (short):

Decidable problems

  1. Membership (word problem)
    Problem: Given CFG GG and string ww, is wL(G)w\in L(G)?
    Status: Decidable.
    How: Convert GG to Chomsky Normal Form (CNF) and use CYK dynamic programming: O(w3|w|^3) time classically. There are faster algorithms for special cases, but CYK is standard and effective for proofs.

  2. Emptiness of a CFG
    Problem: Given CFG GG, is L(G)=L(G)=\varnothing?
    Status: Decidable.
    How: Compute generating variables (those that derive some terminal string) by fixed-point marking; then check if start symbol is generating. This runs in linear time in the grammar size.

  3. Finiteness
    Problem: Given CFG GG, is L(G)finite?

    Status: Decidable.

    How (sketch): Remove useless symbols first (non-generating/non-reachable). If the dependency graph (variables with edges when one can derive the other) contains a cycle reachable from SS and that cycle can produce at least one terminal, you can pump to obtain arbitrarily long strings → infinite. Otherwise finite. So check for reachable cycles in the generating subgraph: decidable (graph algorithms).

  4. Emptiness of L(G)RL(G)\cap R where RR is regular
    Problem: Given CFG GGand regular RR, is L(G)R=L(G)\cap R=\varnothing?
    Status: Decidable.
    How: Build PDA for L(G)L(G) × DFA for RR (PDA for intersection) and check emptiness (emptiness for PDA/CFG is decidable).

  5. Membership for PDAs / equivalently CFGs (same as 1): decidable.


Undecidable problems

  1. Universality
    Problem: Given CFG GG over alphabet Σ\Sigma, is L(G)=ΣL(G)=\Sigma^*?
    Status: Undecidable.

  2. Equivalence
    Problem: Given CFGs G1,G2G_1, G_2 is L(G1)=L(G2)L(G_1)=L(G_2)?
    Status: Undecidable.

  3. Inclusion
    Problem: Given CFGs G1,G2G_1,G_2, is L(G1)L(G2)L(G_1)\subseteq L(G_2)?
    Status: Undecidable. (Equivalence reduces to mutual inclusion, so inclusion undecidable.)

  4. Emptiness of intersection of two CFLs
    Problem: Given CFGs G1,G2G_1,G_2, is L(G1)L(G2)=∅? Status: Undecidable.
    Consequence: This is consistent with non-closure under intersection and with undecidability results (standard reductions show undecidability).

  5. Ambiguity of a CFG
    Problem: Given a CFG GG, is GG ambiguous? (i.e., does some string have ≥2 distinct parse trees?)
    Status: Undecidable.

  6. Inherent ambiguity
    Problem: Given a CFL LL, is LL inherently ambiguous? (i.e., every grammar for LL is ambiguous)
    Status: Undecidable.


Quick reference table (summary)

Property / problemCFLs: status    Notes / sketch
Union    Closed                            SS1S2S\to S_1\mid S_2
Concatenation    ClosedSS1S2S\to S_1 S_2
Kleene star    ClosedSS1SεS\to S_1 S \mid \varepsilon
Reversal    ClosedReverse RHSs
Homomorphism    ClosedReplace terminals
Inverse homomorphism    ClosedPDA/transducer construction
Intersection (general)    Not closedExample → anbncna^n b^n c^n
Complement    Not closedIf closed → intersection closed (contradiction)
Intersection w/ regular    ClosedProduct PDA+DFA
Membership (G,w)    DecidableCYK (O(n³))
Emptiness (G)    DecidableMark generating variables
Finiteness (G)    Decidabledetect reachable cycles in generating graph
Universality    Undecidablereduction proofs
Equivalence (G1,G2)    Undecidablereduction proofs
Inclusion (G1⊆G2)    Undecidablereduction proofs
Ambiguity (G)    Undecidableclassic result

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