THEORY Lecture Mon Nov 9th

Foundations and Mechanics of the Context-Free Pumping Lemma

  • The Context-Free Pumping Lemma provides a necessary condition that must hold for all context-free languages (CFL\text{CFL}s). If a language fails to satisfy this property, it is proven not to be context-free via proof by contradiction (A  ⟹  B≡¬B  ⟹  ¬AA \implies B \equiv \neg B \implies \neg A).

  • The lemma cannot be used to prove that a language is context-free; it functions solely as an adversarial tool to disprove context-freeness.

  • Structural Comparison with the Regular Pumping Lemma:

    • Both lemmas begin with an existential pumping length pp, such that every word ww in the language with length ∣w∣≥p|w| \ge p must have a valid decomposition.

    • Decomposition cardinality: Regular languages decompose into 3 segments (w=xyzw = x y z), whereas context-free languages decompose into 5 segments (w=xuyvzw = x u y v z).

    • Non-emptiness constraint: In the regular lemma, ∣y∣≥1|y| \ge 1. In the context-free lemma, the pumped strings are uu and vv, and the requirement is that their combination is non-empty: ∣uv∣≥1|uv| \ge 1 (equivalently, u≠ε∨v≠εu \neq \varepsilon \lor v \neq \varepsilon; uu and vv cannot both be empty simultaneously).

    • Sliding window location: In the regular lemma, the length bound applies to the prefix (∣xy∣≤p|xy| \le p). In the context-free lemma, the bound applies to the middle segment: ∣uyv∣≤p|uyv| \le p. This acts as a sliding window of length at most pp anywhere in the word.

    • Pumping condition: In the regular lemma, the single middle segment is pumped (xyiz∈Lx y^i z \in L). In the context-free lemma, the second and fourth pieces are pumped simultaneously by the exact same exponent: xuiyviz∈Lx u^i y v^i z \in L for all integers i≥0i \ge 0. Segments uu and vv cannot be pumped independently or by different counts.

  • Grammatical and Tree Derivation Foundation:

    • The pumping length pp depends entirely on the underlying Context-Free Grammar (CFG\text{CFG}), specifically its total number of nonterminal variables and the maximal branching factor of the production rules.

    • The branching factor must be at least 2; consequently, p>1p > 1.

    • If a word ww has length ∣w∣≥p|w| \ge p, its derivation tree is sufficiently tall that, by the Pigeonhole Principle, at least one path from the start symbol to a leaf must encounter the same nonterminal variable AA more than once (AA appears at least twice along a single branch).

    • Leaf Factorization from the Parse Tree:

    • xx represents the terminal yield to the left of the subtree rooted at the first occurrence of AA.

    • uu represents the terminal yield between the left border of the first AA subtree and the left border of the second AA subtree.

    • yy represents the terminal yield generated directly beneath the second occurrence of AA.

    • vv represents the terminal yield between the right border of the second AA subtree and the right border of the first AA subtree.

    • zz represents the terminal yield to the right of the subtree rooted at the first occurrence of AA.

    • Grafting Operation:

    • Because AA derives both uAvu A v and yy, the derivation sequence can be represented as:       S⇒∗xAz⇒∗xuAvz⇒∗xuyvzS \Rightarrow^* x A z \Rightarrow^* x u A v z \Rightarrow^* x u y v z

    • Instead of terminating the second AA with yy, one can repeatedly graft copies of the larger subtree rooted at AA that derives uAvu A v. Repeating this ii times yields xuiyvizx u^i y v^i z.

    • Alternatively, one can cut out the recursive loop entirely by grafting the derivation of yy directly at the first occurrence of AA. This corresponds to pumping zero times (i=0i = 0), producing xu0yv0z=xyzx u^0 y v^0 z = x y z.

  • Rules of the Adversarial Game:

    1. The adversary chooses the pumping length pp.

    2. You choose a specific word w∈Lw \in L such that ∣w∣≥p|w| \ge p.

    3. The adversary selects a factorization w=xuyvzw = x u y v z subject to ∣uyv∣≤p|uyv| \le p and ∣uv∣≥1|uv| \ge 1.

    4. You select an integer i≥0i \ge 0 such that xuiyviz∉Lx u^i y v^i z \notin L, establishing a contradiction.

Language Classification and Memory Sanity Checks

  • Memory Sanity Checks:

    • For regular languages, the intuitive test is whether the language requires infinite memory. A finite automaton has only finite state memory.

    • For context-free languages, the intuitive test is whether the memory needs to be reused. A pushdown automaton (PDA\text{PDA}) has a single stack. It can store clues in memory and consume each clue once (as in anbna^n b^n, where nn symbols are pushed during the aa segment and popped during the bb segment).

    • If a language requires clues to be consumed multiple times (such as consuming a counter of length nn a total of nn times to verify n2n^2), the memory must be reused. A single pushdown stack cannot duplicate or reread its memory, indicating that the language is not context-free.

  • Unary Alphabet Equivalence:

    • For any language defined over a single-letter alphabet (∣Σ∣=1|\Sigma| = 1), regular languages and context-free languages are mathematically equivalent.

    • Proving that a unary language is not context-free is equivalent to proving that it is not regular. The context-free pumping proof on a unary language mirrors the regular pumping proof, expanded from a 3-part factorization to a 5-part factorization.

Non-Context-Free Proof: Languages with Non-Linear Exponents (L={an2bn∣n≥0}L = \{ a^{n^2} b^n \mid n \ge 0 \})

  • Language Definition: L={an2bn∣n≥0}L = \{ a^{n^2} b^n \mid n \ge 0 \}.

  • Intuition: The relationship between exponents is non-linear (n2=n×nn^2 = n \times n). Checking that the number of aa symbols is the exact square of the number of bb symbols requires consuming the memory nn times, which a single stack cannot execute.

  • Selection of Test Word:

    • Given pp, select w=ap2bpw = a^{p^2} b^p.

    • Because p≥1p \ge 1, ∣w∣=p2+p≥p|w| = p^2 + p \ge p, and w∈Lw \in L.

  • Adversarial Factorization:

    • The adversary factorizes w=xuyvzw = x u y v z such that ∣uyv∣≤p|uyv| \le p and ∣uv∣≥1|uv| \ge 1.

  • Strategic Pumping (i=0i = 0):

    • Pumping down with i=0i = 0 removes all characters in uu and vv. The resulting word is w′=xu0yv0z=xyzw' = x u^0 y v^0 z = x y z.

    • Removing segments uu and vv does not introduce out-of-order characters, ensuring the string remains of the general form a∗b∗a^* b^*.

    • Let kk denote the number of aa symbols in uvuv, and let ll denote the number of bb symbols in uvuv.

    • Then w′=ap2−kbp−lw' = a^{p^2 - k} b^{p - l}.

    • Size Restrictions on Parameters:

    • k+l=∣uv∣≥1k + l = |uv| \ge 1, meaning kk and ll cannot both be zero.

    • k+l≤∣uyv∣≤pk + l \le |uyv| \le p.

    • Thus, 0≤k≤p0 \le k \le p and 0≤l≤p0 \le l \le p.

    • For w′w' to belong to LL, the remaining exponents must satisfy:     p2−k=(p−l)2p^2 - k = (p - l)^2

  • Case-by-Case Arithmetic Contradiction:

    • Case 1: l=0l = 0

    • If l=0l = 0, then all characters removed came from the aa block, so k=∣uv∣≥1k = |uv| \ge 1.

    • The expected number of aa symbols is (p−0)2=p2(p - 0)^2 = p^2.

    • However, the actual number of aa symbols is p2−k<p2p^2 - k < p^2.

    • Thus, p2−k≠(p−l)2p^2 - k \neq (p - l)^2, so w′∉Lw' \notin L.

  • Case 2: l≥1l \ge 1

    • If l≥1l \ge 1, then at least one bb was removed.

    • Since k+l≤pk + l \le p and l≥1l \ge 1, it follows that k≤p−l≤p−1k \le p - l \le p - 1.

    • Evaluating the left-hand side (p2−kp^2 - k):     p2−k≥p2−(p−1)=p2−p+1p^2 - k \ge p^2 - (p - 1) = p^2 - p + 1

    • Evaluating the right-hand side ((p−l)2(p - l)^2):

    • Because l≥1l \ge 1, the maximum possible value of p−lp - l is p−1p - 1.

    • Therefore, (p−l)2≤(p−1)2=p2−2p+1(p - l)^2 \le (p - 1)^2 = p^2 - 2p + 1.

    • Comparing both sides:     p2−k≥p2−p+1>p2−2p+1≥(p−l)2p^2 - k \ge p^2 - p + 1 > p^2 - 2p + 1 \ge (p - l)^2

    • This inequality holds strictly for all p≥1p \ge 1, proving that p2−k>(p−l)2p^2 - k > (p - l)^2.

    • Thus, p2−k≠(p−l)2p^2 - k \neq (p - l)^2, so w′∉Lw' \notin L.

  • Conclusion: In all cases, pumping zero times yields w′∉Lw' \notin L, proving that LL is not context-free.

Non-Context-Free Proof: Unary Languages with Prime Exponents (L={aq∣q is prime}L = \{ a^q \mid q \text{ is prime} \})

  • Language Definition: L={aq∣q is prime}L = \{ a^q \mid q \text{ is prime} \}.

  • Selection of Test Word:

    • Given pp, select a prime number qq such that q>pq > p.

    • Define w=aq∈Lw = a^q \in L. Note that setting w=apw = a^p is a common mistake because pp is not guaranteed to be prime.

  • Adversarial Factorization:

    • The word is factorized as w=xuyvzw = x u y v z with ∣uyv∣≤p|uyv| \le p and ∣uv∣≥1|uv| \ge 1.

    • Because the alphabet consists only of the single terminal aa, all segments x,u,y,v,zx, u, y, v, z consist exclusively of aa symbols.

    • Let ∣u∣=k|u| = k and ∣v∣=l|v| = l. By the lemma conditions, 1≤k+l≤p1 \le k + l \le p.

  • General Pumping Formula:

    • Pumping ii times yields the length:     ∣xuiyviz∣=∣xuyvz∣+(i−1)(∣u∣+∣v∣)=q+(i−1)(k+l)|x u^i y v^i z| = |x u y v z| + (i - 1)(|u| + |v|) = q + (i - 1)(k + l)

  • Strategic Choice of Exponent:

    • To force the exponent to become a composite number, choose i=q+1i = q + 1.

    • Then i−1=qi - 1 = q, and the length formula simplifies to:     ∣xuq+1yvq+1z∣=q+q(k+l)=q(1+k+l)|x u^{q+1} y v^{q+1} z| = q + q(k + l) = q(1 + k + l)

  • Proof of Compositeness:

    • Factor 1: qq is prime, so q≥2q \ge 2.

    • Factor 2: Since k+l≥1k + l \ge 1, it follows that 1+k+l≥21 + k + l \ge 2.

    • The total exponent q(1+k+l)q(1 + k + l) is the product of two natural numbers strictly greater than 1, making it strictly composite and not prime.

    • Therefore, xuq+1yvq+1z∉Lx u^{q+1} y v^{q+1} z \notin L, disproving context-freeness.

Non-Context-Free Proof: Equal Multi-Symbol Distributions (L={w∈{a,b,c}∗∣∣w∣a=∣w∣b=∣w∣c}L = \{ w \in \{a, b, c\}^* \mid |w|_a = |w|_b = |w|_c \})

  • Language Definition: L={w∈{a,b,c}∗∣∣w∣a=∣w∣b=∣w∣c}L = \{ w \in \{a, b, c\}^* \mid |w|_a = |w|_b = |w|_c \}.

  • Intuition: A pushdown automaton can match two symbol counts against each other, but verifying three simultaneous counts requires duplicating the memory content, which exceeds context-free capability.

  • Direct Proof via Pumping Lemma:

    • Test Word: Select w=apbpcp∈Lw = a^p b^p c^p \in L. The total length is 3p≥p3p \ge p.

    • Window Confinement: The sliding window condition specifies ∣uyv∣≤p|uyv| \le p.

    • Because each block of identical letters has length pp, the segment uyvuyv can span at most two distinct symbols.

    • Specifically, uyvuyv can consist of only aa's, aa's and bb's, only bb's, bb's and cc's, or only cc's.

    • The segment uyvuyv can never contain both aa's and cc's.

    • Pumping Down (i=0i = 0):

    • Because ∣uv∣≥1|uv| \ge 1, pumping down (w′=xu0yv0zw' = x u^0 y v^0 z) strictly decreases the occurrences of at least one symbol type.

    • Because uvuv spans at most two symbol types, at least one of the three symbols (aa, bb, or cc) is completely outside the sliding window and is left untouched, retaining exactly pp occurrences.

    • The symbol(s) contained in uvuv will have their counts reduced to strictly less than pp.

    • Consequently, the counts cannot remain equal (∣w′∣a=∣w′∣b=∣w′∣c|w'|_a = |w'|_b = |w'|_c is violated).

    • Thus, w′∉Lw' \notin L, proving LL is not context-free.

  • Alternative Proof via Intersection with a Regular Language:

    • Closure Property: Context-free languages are not closed under intersection with other context-free languages, but they are closed under intersection with regular languages (LCFL∩Lreg∈CFLL_{\text{CFL}} \cap L_{\text{reg}} \in \text{CFL}.

    • This closure is implemented computationally via a parallel product construction of a PDA\text{PDA} and a DFA\text{DFA}, where the DFA\text{DFA} uses finite states and does not interfere with the PDA\text{PDA} stack.

    • Define the regular language R=L(a∗b∗c∗)R = \mathcal{L}(a^* b^* c^*).

    • Compute the intersection:     L∩R={anbncn∣n≥0}L \cap R = \{ a^n b^n c^n \mid n \ge 0 \}

    • If LL were context-free, then L∩RL \cap R would necessarily be context-free.

    • Because anbncna^n b^n c^n is known to be non-context-free, LL cannot be context-free.

Non-Context-Free Proof: Strict Inequality Constraints (L={aibjck∣i<j<k}L = \{ a^i b^j c^k \mid i < j < k \})

  • Language Definition: L={aibjck∣i<j<k}L = \{ a^i b^j c^k \mid i < j < k \}.

  • Intuition: The language involves a hidden conjunction: i<ji < j and j<kj < k. The middle exponent jj must be evaluated twice, necessitating memory reuse.

  • Selection of Test Word:

    • Given pp, select w=apbp+1cp+2∈Lw = a^p b^{p+1} c^{p+2} \in L, which satisfies the length requirement and the strict inequalities.

  • Factorization Analysis:

    • The adversary factorizes w=xuyvzw = x u y v z with ∣uyv∣≤p|uyv| \le p and ∣uv∣≥1|uv| \ge 1.

    • Because ∣uyv∣≤p|uyv| \le p, uyvuyv can span at most two consecutive symbol types (either within a∗b∗a^* b^* or within b∗c∗b^* c^*; it cannot span from aa to cc).

  • Why Uniform Pumping Fails:

    • Pumping down (i=0i = 0) fails uniformly because reducing aa and bb while leaving cc unchanged preserves the condition that cc is larger than aa and bb.

    • Pumping up (i≥2i \ge 2) fails uniformly because increasing bb and cc while leaving aa unchanged preserves the condition that bb and cc are larger than aa.

    • Hence, the proof requires a non-uniform case-by-case choice of ii.

  • Case-by-Case Pumping Strategy:

    • Case 1: Segment uvuv contains at least one aa

    • Because ∣uyv∣≤p|uyv| \le p and uvuv contains an aa, the window cannot reach the cc block. Thus, uvuv contains zero cc symbols.

    • Strategy: Pump up by choosing i=2i = 2.

    • Pumping up increases the number of aa's and/or bb's while leaving the count of cc's fixed at p+2p+2.

    • By pumping up, either the number of aa's increases to at least p+(p+1)>p+2p + (p+1) > p+2 (violating i<ki < k), or the number of bb's increases to at least (p+1)+1=p+2(p+1) + 1 = p+2 (violating j<kj < k).

    • In either case, the strict inequality condition is broken, so xu2yv2z∉Lx u^2 y v^2 z \notin L.

  • Case 2: Segment uvuv contains no aa

    • If uvuv contains no aa, it is confined entirely to the b∗c∗b^* c^* suffix of the word.

    • Strategy: Pump down by choosing i=0i = 0.

    • Pumping down leaves the number of aa symbols completely unchanged at pp.

    • Because ∣uv∣≥1|uv| \ge 1, pumping down strictly decreases the count of bb's, the count of cc's, or both.

    • If the number of bb's decreases, its count drops from p+1p+1 to at most pp, violating i<ji < j (since i=pi = p and j≤pj \le p).

    • If the number of cc's decreases, its count drops to at most p+1p+1, which fails the condition j<kj < k if bb was not decreased, or fails i<ki < k if both drop.

    • In either case, the pumped word falls out of LL.

  • Conclusion: Because an adversary's factorization must fall into either Case 1 or Case 2, and an exponent ii exists for each case that exits LL, the language is not context-free.

Strategic Guidelines and Proof Methodologies for Context-Free Languages

  • Standard Step-by-Step Proof Outline:

    1. Assume the target language LL is context-free.

    2. Let pp be the pumping length provided by the lemma.

    3. Construct a specific word w∈Lw \in L with ∣w∣≥p|w| \ge p, parameterized by pp.

    4. Consider an arbitrary factorization w=xuyvzw = x u y v z obeying ∣uyv∣≤p|uyv| \le p and ∣uv∣≥1|uv| \ge 1.

    5. Determine an exponent i≥0i \ge 0 (either a single uniform value or split into exhaustive cases) such that xuiyviz∉Lx u^i y v^i z \notin L.

    6. Conclude that LL is not context-free by contradiction.

  • Block-Sizing Heuristic:

    • Choosing words with homogeneous symbol blocks of size at least pp (e.g., apbpcpa^p b^p c^p) prevents the sliding window of length at most pp from spanning across three symbol blocks simultaneously.

    • This simplifies the analysis by restricting the window to at most two adjacent blocks.

  • Prioritizing i=0i = 0 (Pumping Down):

    • Always test i=0i = 0 first. Pumping down deletes substrings rather than repeating them, preventing character interleaving and maintaining string structure while uniformly reducing letter counts.

  • Closure Properties vs. Direct Pumping:

    • Valid Operations: Context-free languages are closed under union (L1∪L2L_1 \cup L_2), concatenation (L1L2L_1 L_2), Kleene star (L∗L^*), and intersection with regular languages (LCFL∩LregL_{\text{CFL}} \cap L_{\text{reg}}).

    • Invalid Operations: Context-free languages are not closed under general intersection (LCFL1∩LCFL2L_{\text{CFL}_1} \cap L_{\text{CFL}_2}) or complementation (LCFL‾\overline{L_{\text{CFL}}}).

    • When dealing with languages involving mixed character orderings, intersect with a regular expression (e.g., a∗b∗c∗a^* b^* c^*) to isolate structural patterns rather than re-proving standard results from scratch.

Questions & Discussion

  • Question: Is proving that a language is not context-free the same as proving it is not regular?

    • Answer: For languages over an alphabet containing only a single letter (∣Σ∣=1|\Sigma| = 1), regular and context-free languages are identical. Therefore, proving a unary language is not regular is equivalent to proving it is not context-free. In such cases, one can adapt the regular pumping lemma proof into a 5-part context-free factorization.

  • Question: What word should be selected for the language L={w∈{a,b,c}∗∣∣w∣a=∣w∣b=∣w∣c}L = \{ w \in \{a,b,c\}^* \mid |w|_a = |w|_b = |w|_c \}?

    • Answer: The word w=apbpcpw = a^p b^p c^p is an appropriate choice. It belongs to LL and has length 3p≥p3p \ge p.

  • Question: Can intersection be used to simplify the proof for L={w∈{a,b,c}∗∣∣w∣a=∣w∣b=∣w∣c}L = \{ w \in \{a,b,c\}^* \mid |w|_a = |w|_b = |w|_c \} instead of carrying out the full pumping lemma derivation?

    • Answer: Yes. Intersecting LL with the language requiring all aa's before bb's before cc's (a∗b∗c∗a^* b^* c^*) yields anbncna^n b^n c^n.

  • Question: Why does intersecting LL with a∗b∗c∗a^* b^* c^* guarantee that the result is context-free if LL is context-free?

    • Answer: Because a∗b∗c∗a^* b^* c^* is regular. While context-free languages are not closed under intersection with other context-free languages, they are closed under intersection with regular languages. A pushdown automaton running in parallel with a deterministic finite automaton can accept the intersection without incurring memory-sharing conflicts.