Proofs: Pumping lemma for context-free languages
These are the human proofs of Pumping lemma for context-free languages, at full length.
Proof of the pumping lemma for context-free languages full
This proof shows: statement.
Let be a context-free language. By the Chomsky normal form theorem there is a grammar with whose productions all have the form with or with . Let and . In a parse tree of , every inner node is labelled by a nonterminal and has two inner children () or one leaf child (); the leaves are terminals. The height of a tree is the number of edges of its longest root-to-leaf path.
Lemma 1. A parse tree of of height has a yield of length at most .
Proof. By induction on . A tree of height 1 is a root with one leaf , of yield length . A tree of height has a root that uses , with two subtrees of height at most , whose yields have length at most each by induction. The yield of the tree is their concatenation, of length at most .
Lemma 2. Every nonterminal with derives only nonempty strings .
Proof. No production has an empty right side, and every derivation step replaces a nonterminal by one or two symbols, so the length of a sentential form never decreases and starts at 1.
Lemma 3 (cut and paste). Let be a parse tree with root label and yield , let be a node of and a proper descendant of , both labelled , and write where is the yield of and is the yield of . Then for every .
Proof. Let and be the subtrees at and . Both have root label , so either can stand at any node labelled and the result is still a parse tree: the production used at the parent of that node does not change. Replacing in by gives a tree with yield , which is the case . For , let , and let be with its subtree replaced by ; then has root and yield , by induction on , since has yield with the yield of the replaced subtree. Replacing in by gives a tree with yield .
Theorem. Every with can be written as with , , and for every .
Proof. If is empty there is nothing to prove, so let . Since , , so and has a parse tree with root . Let be its height. By Lemma 1, , so .
Fix a longest root-to-leaf path of . It has edges and nodes; the last one is a leaf and the other are inner nodes labelled by nonterminals. Look at the lowest inner nodes of . There are only nonterminals, so two of them have the same label . Let be the upper one and the lower one. Let be the yield of and the yield of , which is a factor of the yield of because is a descendant of , and write accordingly.
Condition . The part of from to the leaf has at most edges, because is one of the lowest inner nodes of . It is a longest path in the subtree at : a longer path from down, together with the part of above , would be a root-to-leaf path longer than . So the subtree at has height at most , and by Lemma 1 its yield has length .
Condition . is an inner node with a proper descendant that is inner, so it uses a production . Its children and have yields and with , and both are nonempty by Lemma 2. lies in one of the two subtrees. If it lies below , then is a factor of , so ends with all of , and . If it lies below , then is a factor of , so starts with all of , and .
Condition . By Lemma 3 with , for every , so .