4.6.12Theory of Computation

Pumping lemma for CFLs

2,649 words12 min readdifficulty · medium5 backlinks

WHAT it says


WHY it is true (derivation from first principles)

Step-by-step derivation.

  1. Convert the CFG to CNF with bb variables. Choose pumping length p=2b+1p = 2^{b}+1. Why this step? CNF makes the parse tree binary, so we can bound leaf count by tree height cleanly. Taking pp strictly greater than 2b2^{b} guarantees the strict inequality we need in Step 2.

  2. Take wLw \in L with wp=2b+1|w| \ge p = 2^{b}+1, so w>2b|w| > 2^{b}. A binary parse tree with more than 2b2^{b} leaves must have height >b> b (since height b\le b allows at most 2b2^{b} leaves). Hence some root-to-leaf path passes through at least b+1b+1 variable nodes. Why this step? Long string ⇒ more than 2b2^{b} leaves ⇒ strictly tall tree. The strict ">2b>2^b" is exactly why we set p=2b+1p=2^b+1.

  3. That path has b+1\ge b+1 variable nodes but only bb distinct variables exist, so by pigeonhole two nodes on the path carry the same variable AA. Pick the two lowest such occurrences. Why this step? Picking the lowest pair keeps the lower subtree small — this gives condition vxyp|vxy| \le p.

  4. Let the upper AA derive substring vxyvxy and the lower AA derive substring xx. Then the whole string splits as w=u(vxy)z=uvxyzw = u\,(vxy)\,z = uvxyz, where the upper AA gives AvAyvxyA \Rightarrow^* vAy \Rightarrow^* vxy. Why this step? The recursive structure AvAyA \Rightarrow^* vAy is exactly the loop we can repeat.

Justifying the three conditions:

  • vy1|vy|\ge 1: in CNF a node ABCA \to BC produces two children, so the upper AA's subtree is strictly larger than the lower AA's subtree; the extra symbols are exactly vv and yy, so they can't both be empty. (CNF has no unit/epsilon rules causing AAA\Rightarrow A.)
  • vxyp|vxy|\le p: we picked the two lowest repeated variables, so the subtree rooted at the upper AA has height b+1\le b+1, hence at most 2b+12^{b+1} leaves; choosing the lowest repeat keeps this within the bound used to set pp (standard treatments take p=2b+1p=2^{b+1} to make vxyp|vxy|\le p exact — the key point is the lower subtree is bounded by a constant depending only on bb).
  • uvixyizLuv^i xy^i z \in L: by repeating/removing the loop subtree as shown.
Figure — Pumping lemma for CFLs

HOW to use it (to prove a language is NOT a CFL)

It's a game / proof by contradiction:


Comparison map


Flashcards

What does the CFL pumping lemma split a long string into?
w=uvxyzw=uvxyz with two pump pieces vv and yy.
What are the three conditions of the CFL pumping lemma?
(1) vy1|vy|\ge1, (2) vxyp|vxy|\le p, (3) uvixyizLuv^ixy^iz\in L for all i0i\ge0.
Why are there TWO pumped pieces v,yv,y in CFL PL but one in regular PL?
A repeated variable derives AvAyA\Rightarrow^* vAy, adding symbols on both sides of the subtree; a DFA cycle adds one contiguous segment. :::
What normal form is used to prove the CFL pumping lemma and why?
Chomsky Normal Form — it makes the parse tree binary so leaf-count vs height bounds work cleanly. :::
What principle forces a variable to repeat on a path?
Pigeonhole: a long string ⇒ tall binary parse tree ⇒ path with more variable nodes than there are distinct variables. :::
Why must the chosen string length exceed 2b2^{b} (not just equal it)?
A binary tree of height b\le b holds at most 2b2^{b} leaves; only w>2b|w|>2^{b} forces height >b>b and hence a repeated variable, so we set p=2b+1p=2^b+1. :::
In the proof game, who chooses pp, ww, the split, and ii?
Adversary chooses pp and the split; you choose ww and ii. :::
Why does vxyp|vxy|\le p matter for proving anbncna^nb^nc^n is not a CFL?
It forces vxyvxy to touch at most two letter blocks, so pumping unbalances the counts. :::
Can the pumping lemma prove a language IS context-free?
No — it only proves a language is NOT context-free (necessary, not sufficient). :::
Good witness string for showing L={anbncn}L=\{a^nb^nc^n\} not CFL?
w=apbpcpw=a^pb^pc^p, then pump i=2i=2. :::
Good witness string for {ww}\{ww\} not CFL?
0p1p0p1p0^p1^p0^p1^p. :::
Why pick the two LOWEST repeated variables on the path?
To bound the lower subtree size, guaranteeing vxyp|vxy|\le p. :::

Recall Feynman: explain to a 12-year-old

Imagine a family tree that makes words. If the word is really long, the tree is really tall, and somewhere on the way down a name has to repeat (there are only so many names!). Wherever a name repeats, you've found a loop — like a verse you can sing 0, 1, 2, or 100 times. So every super-long word in the language has a part you can repeat, and the repeat adds stuff on the left AND right at the same time (because the tree branches). If you find a long word where no repeat can be added without breaking the rules, the language is too clever to be made by such a tree — it's not context-free.


Connections

  • Context-Free Grammars — the loop AvAyA\Rightarrow^* vAy comes from grammar recursion.
  • Chomsky Normal Form — the binary-tree machinery behind the proof.
  • Pumping lemma for regular languages — single-piece analogue; same pigeonhole spirit.
  • Parse Trees and Derivations — pumping = duplicating a subtree.
  • Closure properties of CFLs — combine with closure to extend non-CFL proofs.
  • Pushdown Automata — equivalent machine model; stack ↔ recursion.
  • Pigeonhole Principle — the core counting argument.

Concept Map

generated by

converted to

makes parse tree

height h leaves

exceeds 2^b leaves

path has b+1 variables

forces

creates loop

pumps subtree

two pieces v and y

fails for some string

CFL

CFG

Chomsky Normal Form

Binary parse tree

at most 2^b leaves

Long string w >= p

Tree height > b

Pigeonhole

Repeated variable A

Split w = uvxyz

uv^i x y^i z in L

Conditions vy>=1, vxy<=p

Not context-free

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, CFL pumping lemma ka core idea bahut simple hai. Har context-free language ke peeche ek grammar (CFG) hoti hai. Jab string bahut lambi ho jaati hai, to uska parse tree itna tall ho jaata hai ki kisi ek path par koi variable (non-terminal) repeat zaroor karega — pigeonhole principle ki wajah se, kyunki variables to limited (sirf bb) hain. Important detail: agar string ki length 2b2^b se strictly zyada ho, tabhi tree itna tall banega; isliye p=2b+1p=2^b+1 lete hain. Yahi repeat ek loop hai: AvAyA \Rightarrow^* vAy. Is loop ko hum 0, 1, 2, ya jitni baar chaaho pump kar sakte hain, aur string language mein hi rahegi.

Yaad rakhna sabse important difference: regular languages mein ek hi piece pump hota tha (xyizxy^iz), lekin CFL mein do pieces vv aur yy ek saath, same exponent ii ke saath pump hote hain (uvixyizuv^ixy^iz). Iska reason yeh hai ki parse tree branch karta hai — repeating variable ke neeche ka material left side (vv) aur right side (yy) dono par aata hai. Conditions yaad rakho: vy1|vy|\ge1 (dono khaali nahi), vxyp|vxy|\le p (window chhoti), aur pump sab i0i\ge0 ke liye chale.

Yeh lemma kis kaam aata hai? Kisi language ko NOT context-free prove karne ke liye — contradiction se. Yeh ek game hai: adversary tumhe pp deta hai, tum ek smart string ww (length p\ge p) choose karte ho, adversary koi bhi valid split deta hai, aur tum aisa ii (aksar 00 ya 22) choose karte ho ki string language se bahar nikal jaaye. Classic example anbncna^nb^nc^n hai: w=apbpcpw=a^pb^pc^p lo, vxyp|vxy|\le p ki wajah se window sirf do blocks ko touch kar sakti hai, pump karo to teen counts barabar nahi rahenge — contradiction! Dhyaan rahe: {aibjck:ijk}\{a^ib^jc^k: i\le j\le k\} wale example mein "ii" do matlab rakhta hai — ek pump exponent, ek aa ka count; in dono ko mat mila dena.

Ek warning: pumping lemma se tum kabhi yeh prove nahi kar sakte ki language CFL hai (yeh sirf necessary condition hai). CFL prove karne ke liye grammar ya PDA banao. Aur string choose karte waqt sabse tough, sabse constrained string lo, warna adversary aaram se pump kar lega aur tumhara proof fail ho jaayega.

Go deeper — visual, from zero

Test yourself — Theory of Computation

Connections