Algorithm Search⌘K

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 LL be a context-free language. By the Chomsky normal form theorem there is a grammar G=(V,Σ,R,S)G = (V, \Sigma, R, S) with L(G)=L∖{ε}L(G) = L \setminus \{\varepsilon\} whose productions all have the form A→BCA \to B C with B,C∈VB, C \in V or A→aA \to a with a∈Σa \in \Sigma. Let k=∣V∣k = |V| and p=2kp = 2^k. In a parse tree of GG, every inner node is labelled by a nonterminal and has two inner children (A→BCA \to B C) or one leaf child (A→aA \to a); 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 GG of height hh has a yield of length at most 2h−12^{h-1}.

Proof. By induction on hh. A tree of height 1 is a root AA with one leaf aa, of yield length 1=201 = 2^0. A tree of height h≥2h \ge 2 has a root that uses A→BCA \to B C, with two subtrees of height at most h−1h - 1, whose yields have length at most 2h−22^{h-2} each by induction. The yield of the tree is their concatenation, of length at most 2⋅2h−2=2h−12 \cdot 2^{h-2} = 2^{h-1}. □\square

Lemma 2. Every nonterminal AA with A⇒∗wA \Rightarrow^* w derives only nonempty strings ww.

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. □\square

Lemma 3 (cut and paste). Let TT be a parse tree with root label XX and yield ss, let N1N_1 be a node of TT and N2N_2 a proper descendant of N1N_1, both labelled AA, and write s=uvxyzs = u v x y z where vxyv x y is the yield of N1N_1 and xx is the yield of N2N_2. Then X⇒∗uvixyizX \Rightarrow^* u v^i x y^i z for every i≥0i \ge 0.

Proof. Let T1T_1 and T2T_2 be the subtrees at N1N_1 and N2N_2. Both have root label AA, so either can stand at any node labelled AA and the result is still a parse tree: the production used at the parent of that node does not change. Replacing T1T_1 in TT by T2T_2 gives a tree with yield uxzu x z, which is the case i=0i = 0. For i≥1i \ge 1, let T(1)=T1T^{(1)} = T_1, and let T(j+1)T^{(j+1)} be T1T_1 with its subtree T2T_2 replaced by T(j)T^{(j)}; then T(j)T^{(j)} has root AA and yield vjxyjv^j x y^j, by induction on jj, since T1T_1 has yield vxyv x y with xx the yield of the replaced subtree. Replacing T1T_1 in TT by T(i)T^{(i)} gives a tree with yield uvixyizu v^i x y^i z. □\square

Theorem. Every s∈Ls \in L with ∣s∣≥p|s| \ge p can be written as s=uvxyzs = u v x y z with ∣vy∣≥1|v y| \ge 1, ∣vxy∣≤p|v x y| \le p, and uvixyiz∈Lu v^i x y^i z \in L for every i≥0i \ge 0.

Proof. If L(G)L(G) is empty there is nothing to prove, so let k≥1k \ge 1. Since ∣s∣≥p≥1|s| \ge p \ge 1, s≠εs \ne \varepsilon, so s∈L(G)s \in L(G) and ss has a parse tree TT with root SS. Let hh be its height. By Lemma 1, 2k≤∣s∣≤2h−12^k \le |s| \le 2^{h-1}, so h≥k+1h \ge k + 1.

Fix a longest root-to-leaf path PP of TT. It has hh edges and h+1h + 1 nodes; the last one is a leaf and the other hh are inner nodes labelled by nonterminals. Look at the lowest k+1k + 1 inner nodes of PP. There are only kk nonterminals, so two of them have the same label AA. Let N1N_1 be the upper one and N2N_2 the lower one. Let vxyv x y be the yield of N1N_1 and xx the yield of N2N_2, which is a factor of the yield of N1N_1 because N2N_2 is a descendant of N1N_1, and write s=uvxyzs = u v x y z accordingly.

Condition ∣vxy∣≤p|v x y| \le p. The part of PP from N1N_1 to the leaf has at most k+1k + 1 edges, because N1N_1 is one of the lowest k+1k + 1 inner nodes of PP. It is a longest path in the subtree at N1N_1: a longer path from N1N_1 down, together with the part of PP above N1N_1, would be a root-to-leaf path longer than PP. So the subtree at N1N_1 has height at most k+1k + 1, and by Lemma 1 its yield has length ∣vxy∣≤2k=p|v x y| \le 2^k = p.

Condition ∣vy∣≥1|v y| \ge 1. N1N_1 is an inner node with a proper descendant that is inner, so it uses a production A→BCA \to B C. Its children MBM_B and MCM_C have yields sBs_B and sCs_C with vxy=sBsCv x y = s_B s_C, and both are nonempty by Lemma 2. N2N_2 lies in one of the two subtrees. If it lies below MBM_B, then xx is a factor of sBs_B, so yy ends with all of sCs_C, and ∣y∣≥∣sC∣≥1|y| \ge |s_C| \ge 1. If it lies below MCM_C, then xx is a factor of sCs_C, so vv starts with all of sBs_B, and ∣v∣≥1|v| \ge 1.

Condition uvixyiz∈Lu v^i x y^i z \in L. By Lemma 3 with X=SX = S, S⇒∗uvixyizS \Rightarrow^* u v^i x y^i z for every i≥0i \ge 0, so uvixyiz∈L(G)⊆Lu v^i x y^i z \in L(G) \subseteq L. ■\blacksquare

Back to Pumping lemma for context-free languages