Identify Non Context-free Language using Pumping Lemma
1. Context-Free Grammar (CFG)
A Context-Free Grammar (CFG) is a formal grammar that generates strings belonging to a context-free language.
It is defined as a 4-tuple:
G = (V, Σ, P, S)
where:
- V → Finite set of variables (nonterminals)
- Σ → Finite set of terminals, with
V ∩ Σ = ∅ - P → Finite set of productions of the form
A → α, whereA ∈ Vandα ∈ (V ∪ Σ)* - S → Start symbol,
S ∈ V
A string w ∈ Σ* belongs to the language L(G) if and only if
S ⇒* w
(i.e., w can be derived from S using the productions).
2. Pumping Lemma for Context-Free Languages (CFLs)
The Pumping Lemma for CFLs is used to prove that certain languages are not context-free.
Theorem (CFL Pumping Lemma):
If L is a context-free language, then there exists a pumping length p ≥ 1 such that every string s ∈ L with |s| ≥ p can be written as:
s = u v x y z
satisfying:
v y ≠ ε(at least one ofvoryis nonempty),|v x y| ≤ p,- For all
i ≥ 0, the stringu v^i x y^i z ∈ L.
Important clarifications:
vandyare not required to be identical.xis not a “separator”; any ofu, x, zmay be empty.- Only the constraints
v y ≠ εand|v x y| ≤ pare guaranteed.
3. Why the Pumping Lemma Holds (Proof Sketch)
Convert the grammar of
Linto Chomsky Normal Form (CNF).Let the number of variables be
k.Any parse tree deriving a sufficiently long string (
|s| ≥ p) must contain a long path from root to leaf.By the pigeonhole principle, some variable
Arepeats along this path:S ⇒* u A z ⇒* u v A y z ⇒* u v x y zThe repeated variable
Aallows pumping: replacing the subtree derived from the secondAby more/fewer copies gives valid derivations.This proves
u v^i x y^i z ∈ Lfor alli ≥ 0.The structure of the parse tree ensures that
|v x y| ≤ pandv y ≠ ε.
4. Using the Pumping Lemma to Show a Language is Not Context-Free
To prove a language L is not context-free, proceed by contradiction:
Assume
Lis context-free.Let
pbe the pumping length from the lemma.Choose a specific string
s ∈ Lwith|s| ≥ p.For every valid decomposition
s = u v x y zsatisfying|v x y| ≤ pandv y ≠ ε,
show there exists somei ≥ 0(ofteni = 0ori = 2) such that:u v^i x y^i z ∉ Lwhich contradicts the lemma.
Therefore,
Lis not context-free.