Theory of Computation & Computer Graphics β Introduction to Context Free Language, NEC licence examination syllabus (Nepal Engineering Council).
Pumping Lemma for CFL
Five parts instead of three β the tool that marks the boundary of the context-free languages.
π Where this lives: This lemma is the formal reason a compiler cannot check everything during parsing. "Every variable must be declared before use" and "the argument count must match the declaration" are both provably beyond context-free grammars by exactly this argument β they reduce to matching three or more things at once, which a single stack cannot do. That is why every compiler has a separate semantic analysis phase with a symbol table, rather than folding those checks into the parser. Search "context free pumping lemma programming language type checking limits".
Statement and the proof idea
THE PUMPING LEMMA FOR CONTEXT-FREE LANGUAGES:
IF L is context free,
THEN there exists a constant p β₯ 1 such that EVERY string
w β L with |w| β₯ p can be written as
w = u v x y z
satisfying ALL THREE conditions:
(1) |v y| β₯ 1 v and y are not BOTH empty
(2) |v x y| β€ p the pumped parts and what lies
between them fit in a window of
width p
(3) u vβ± x yβ± z β L for ALL i β₯ 0
ββ COMPARE THE REGULAR VERSION βββββββββββββββββββββββββββββ
REGULAR CONTEXT FREE
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
split into THREE: x y z FIVE: u v x y z
what pumps ONE piece (y) TWO pieces, v and y,
IN LOCKSTEP
constraint |xy| β€ p β the |vxy| β€ p β the pumped
pumped part is parts are CLOSE
near the START TOGETHER, but may be
anywhere in the string
underlying a repeated STATE a repeated VARIABLE on a
reason in the DFA root-to-leaf path of the
parse tree
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
THE TWO PUMPED PIECES ARE THE ESSENTIAL DIFFERENCE. A
context-free language CAN maintain one matched pair of counts
β v and y grow together β WHICH IS EXACTLY WHY aβΏbβΏ IS
CONTEXT FREE while it was not regular.
ββ WHY IT IS TRUE ββββββββββββββββββββββββββββββββββββββββββ
Take a grammar for L in CHOMSKY NORMAL FORM, so every parse
tree is BINARY. A binary tree of height h has at most 2^h
leaves, so a string of length greater than 2^h forces a tree
of height greater than h.
Let the grammar have m variables and set p = 2^m + 1. Any
w β L with |w| β₯ p has a parse tree of height at least m + 1,
so SOME ROOT-TO-LEAF PATH CONTAINS MORE THAN m INTERNAL NODES
β and by the PIGEONHOLE PRINCIPLE, two of them carry the SAME
VARIABLE A.
S
/ \
/ \
u A β the upper occurrence
/ \
v \
A β the lower occurrence
/ \
x y
\
z
THE SUBTREE ROOTED AT THE UPPER A DERIVES v x y.
THE SUBTREE ROOTED AT THE LOWER A DERIVES x.
So A β* v A y and A β* x.
THEREFORE A β* vβ± x yβ± FOR EVERY i β₯ 0, by repeating or
skipping the section between the two occurrences β WHICH IS
EXACTLY CONDITION (3).
Β· Condition (1) holds because CNF has no Ξ΅-productions, so
the extra subtree cannot be empty.
Β· Condition (2) holds because the repetition can be found
within the bottom m+1 levels of the tree, bounding the
yield of the upper A.
THE PARALLEL WITH THE REGULAR CASE IS EXACT: THERE, A LONG
STRING FORCED A REPEATED STATE, GIVING A LOOP THAT COULD BE
TRAVERSED ANY NUMBER OF TIMES. HERE, A LONG STRING FORCES A
REPEATED VARIABLE, GIVING A SUBTREE THAT CAN BE NESTED ANY
NUMBER OF TIMES.
ββ THE WORKED PROOF: aβΏbβΏcβΏ IS NOT CONTEXT FREE ββββββββββββ
THE STANDARD EXAMPLE, and the one to be able to reproduce.
CLAIM: L = { aβΏbβΏcβΏ : n β₯ 1 } is not context free.
PROOF. Suppose it is. Let p be the pumping length.
CHOOSE w = aα΅ bα΅ cα΅.
Then w β L and |w| = 3p β₯ p.
By condition (2), |vxy| β€ p. THE STRING CONSISTS OF THREE
BLOCKS EACH OF LENGTH p, SO A WINDOW OF WIDTH AT MOST p CAN
TOUCH AT MOST TWO ADJACENT BLOCKS β it can never contain
both an a and a c, because those are at least p symbols
apart.
TWO CASES, and both fail:
CASE 1 β vxy lies within a SINGLE block.
Then pumping with i = 2 increases the count of exactly ONE
symbol and leaves the other two unchanged. The three
counts no longer agree, so u vΒ² x yΒ² z β L.
CASE 2 β vxy SPANS TWO ADJACENT BLOCKS (a's and b's, or b's
and c's).
Then pumping affects at most those two symbols, and THE
THIRD BLOCK IS UNTOUCHED. Again the counts disagree.
Since |vy| β₯ 1 guarantees at least one symbol really is
pumped, every case gives a contradiction with condition (3).
Hence L is not context free. β
CONCRETELY, with p = 3 and w = aaabbbccc:
Β· v = a, y = b β i = 2 gives aaaa bbbb ccc, counts
4, 4, 3 β
Β· v = b, y = c β i = 2 gives aaa bbbb cccc, counts
3, 4, 4 β
THE THIRD COUNT ALWAYS BETRAYS IT β which is precisely the
"a stack compares two things, not three" limitation stated
in the PDA topic, now proved.
The parallel with the regular case is exact: there, a long string forced a repeated state, giving a loop that could be traversed any number of times. Here, a long string forces a repeated variable on a root-to-leaf path, giving a subtree that can be nested any number of times.
π Go further:Crossed dependencies are why this lemma matters to linguistics as well as compilers. The language {aβΏbα΅cβΏdα΅} β where the a's match the c's and the b's match the d's, interleaved β is not context free, while the nested version {aβΏbα΅dα΅cβΏ} is. A stack can nest dependencies but cannot cross them. Swiss German famously contains genuine crossed dependencies in subordinate clauses, and this observation was used in the 1980s to argue that natural language is not context free β one of the few times a pumping-lemma argument settled a debate about human languages rather than formal ones. Search "Swiss German cross-serial dependencies not context free Shieber".
π‘ Exam angle: state the lemma with the five-part split and all three conditions, and be able to compare it with the regular version β three parts versus five, one pumped piece versus two. Give the parse tree justification: CNF makes trees binary, a long string forces a deep tree, and pigeonhole forces a repeated variable. The guaranteed question is proving aβΏbβΏcβΏ is not context free β choose w = aα΅bα΅cα΅, argue that |vxy| β€ p confines the window to at most two adjacent blocks, then give both cases. Know that the lemma is necessary but not sufficient, mention Ogden's lemma, and be ready to use intersection with a regular language as a shortcut.
Syllabus points
Statement of the lemma
Proving a language is not context-free
Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.
Related topics in Introduction to Context Free Language