The Timpson Lyceum seal

The Timpson Lyceum · Computation Theory

Lecture 11 (Computation Theory) Pumping Lemma, Non-Context-Free Languages, and Review

Overview

This lecture develops the pumping lemma for context-free languages (CFLs) and shows how to use it to prove that a given language is not context-free. It is the CFL analogue of the pumping lemma for regular languages, but the string is divided into five pieces instead of three, and two of those pieces get pumped together. The technique is a proof by contradiction: assume the language is context-free, invoke the pumping property, and then exhibit a string and a pumped variant that escapes the language. We work three representative proofs — anbncna^n b^n c^n, the ordered language aibjcka^i b^j c^k with i≤j≤ki \le j \le k, and the copy language wwww — to build fluency with the method, especially the crucial step of choosing the right string.

Key Concepts

Worked Example

Claim. A={ anbncn∣n∈N }A = \{\, a^n b^n c^n \mid n \in \mathbb{N} \,\} is not context-free.

Setup (contradiction). Assume AA is context-free; let pp be its pumping length. Choose the string

s=apbpcp,s = a^p b^p c^p,

which is in AA and has length 3p≥p3p \ge p. By the pumping lemma, s=uvxyzs = uvxyz with ∣vy∣≥1|vy| \ge 1 and ∣vxy∣≤p|vxy| \le p.

Key restriction. Since ∣vxy∣≤p|vxy| \le p, the substring vxyvxy cannot stretch across all three blocks — it lies within the aa's, within the bb's, within the cc's, or straddles only one boundary (a/ba/b or b/cb/c). Hence vyvy contains at most two of the three letters, and (by ∣vy∣≥1|vy| \ge 1) at least one. Pump up with i=2i = 2:

uv2xy2z  adds letters drawn from at most two of {a,b,c}, leaving the third count unchanged⇒    #a, #b, #c are no longer all equal    ⇒    uv2xy2z∉A.\begin{aligned} u v^2 x y^2 z &\;\text{adds letters drawn from at most two of } \{a, b, c\}, \text{ leaving the third count unchanged}\\ \Rightarrow\;\; &\#a,\ \#b,\ \#c \text{ are no longer all equal} \;\;\Rightarrow\;\; u v^2 x y^2 z \notin A. \end{aligned}

For instance, if vyvy contains only aa's and/or bb's, pumping increases the count of aa's and/or bb's while the cc count stays at pp, so #c<#a\#c < \#a or #c<#b\#c < \#b; symmetrically if vyvy contains bb's and/or cc's.

Contradiction. Every case yields uv2xy2z∉Au v^2 x y^2 z \notin A, contradicting condition 3, which demanded it stay in AA. Therefore AA is not context-free. ■\blacksquare

Second example (sketch): the copy language C={ ww∣w∈{0,1}∗ }C = \{\, ww \mid w \in \{0,1\}^* \,\}. Choose s=0p1p 0p1ps = 0^p 1^p\, 0^p 1^p (a convenient w=0p1pw = 0^p 1^p). With ∣vxy∣≤p|vxy| \le p, the window vxyvxy lies entirely in the first half, entirely in the second half, or straddles the center boundary. In each case pumping to i=2i = 2 lengthens one half differently from the other (or breaks the 0p1p0p1p0^p1^p0^p1^p pattern), so the two halves no longer match and uv2xy2z∉Cu v^2 x y^2 z \notin C — contradiction. The same recipe handles { aibjck∣i≤j≤k }\{\, a^i b^j c^k \mid i \le j \le k \,\} with s=apbpcps = a^p b^p c^p: pump up to over-supply aa's or bb's, or pump down (i=0i=0) to under-supply bb's or cc's, violating an inequality.

Summary