The Pumping Lemma for CFLs

Lesson 18 supplies the tool for proving that a language has no context-free grammar. It shows how Chomsky normal form bounds the height of a parse tree, so that a long string forces a repeated variable somewhere on a root-to-leaf path, then gives the five-piece statement with its three conditions and the crucial difference from the regular case: the short window may sit anywhere rather than at the front. It proves the lemma and points out where minimality of the parse tree is used, then works proofs for three matched counts, a block written twice, and nested inequalities, with explicit case analysis over the window positions. It covers closure arguments using a regular helper and why a context-free helper proves nothing, and ends by comparing the two pumping lemmas.

Subject: Theory of Computation · 114 slides · symbolic lesson

Open the interactive version of this deck · Homework for this lesson

What this lesson covers

The lesson, slide by slide

1. The Pumping Lemma for Context-Free Languages

Title

Theory of Computation · Lesson 18

A long string forces a tall parse tree, a tall tree repeats a variable, and a repeated variable can be pumped — in two places at once.

2. What you will be able to do

Objectives

Lessons 13 to 17 built two equivalent ways to show a language is context-free. Neither can show one is not. This lesson supplies the missing tool. By the end you can:

  1. Explain why a long string forces a repeated variable on some root-to-leaf path.
  2. State the lemma with its five pieces and three conditions.
  1. Prove the lemma from the tree-height bound of Lesson 15.
  2. Run the adversary game, which now has an extra case analysis.
  1. Prove the standard languages non-context-free, including three matched counts and a repeated block.
  2. Use closure arguments as a shorter alternative, and say when the lemma is silent.

3. What survived from Equivalence of PDAs & CFGs?

Warm-up

Discussion prompt

Before we open The Pumping Lemma for CFLs: without looking back, what was the main idea of Equivalence of PDAs & CFGs, and what could you do by the end of it that you could not do before?

Hint: One sentence for the idea, one for the skill. If the second one is blank, that is the part to revisit.

Answer:

Lesson 17 proves that the generator and the recognizer describe the same class. It starts from the key observation that a leftmost sentential form splits into matched input and stack contents, then gives the three-state grammar-to-machine construction with its expansion and matching transitions and the push-order trap, the correctness proof by invariant, and why the stack forces leftmost derivations. It shows how to recover a parse tree from a computation, then gives the triple-variable encoding for the reverse direction with its never-dips-below condition, machine normalization, and the three rule schemas. It ends with the consequences: choosing whichever formalism makes a closure proof easier, cubic-time parsing via Chomsky normal form, and what is still missing before Lesson 18.

4. Why a New Tool

Section

Section 1

5. The same gap, one level up

Concept

Two formalisms now prove membership by exhibition: write a grammar, or build a machine. Neither can prove non-membership.

Showing no grammar exists means ruling out infinitely many grammars, and no amount of failed attempts settles it. A universal claim needs a property forced on every context-free language.

\[ \text{not context-free} : \lnot\exists G \equiv \forall G \lnot(\cdots) \]

This is exactly the situation Lesson 10 faced for the regular languages, and the solution has the same shape — but the mechanism forcing the property is different.

6. Break it if you can: The same gap, one level up

Counterexample

Discussion prompt

Two formalisms now prove membership by exhibition: write a grammar, or build a machine. Neither can prove non-membership.

That is stated as though it always holds. Do one of two things: produce a case where it fails, or say precisely what rules such a case out. "It just does" is not on the menu.

Hint: Hunt at the extremes first — zero, one, negative, empty, equal. If every extreme survives, the reason they survive is the proof.

Answer:

Showing no grammar exists means ruling out infinitely many grammars, and no amount of failed attempts settles it. A universal claim needs a property forced on every context-free language.

7. Where the forced property comes from now

Intuition

For finite automata the pigeonhole applied to states along a run. Here there are no states to count, so something else must be bounded.

Chomsky normal form supplies it. Every rule has at most two symbols on the right, so a parse tree is binary — and a binary tree with many leaves must be tall.

\[ |w| \le 2^{h} \;\Rightarrow\; h \ge \log_2|w| \]

A tall tree has a long root-to-leaf path, and a long path through finitely many variables must repeat one. That repetition is what gets pumped.

8. By analogy: Where the forced property comes from now

Analogy

Discussion prompt

Explain Where the forced property comes from now by analogy to something with no Theory of Computation in it at all — a queue, a recipe, a map, a bank balance, whatever fits. Then say where your analogy breaks.

Hint: An analogy that never breaks is not an analogy, it is the same idea wearing a hat. Find the seam — that is the part that is actually new.

Answer:

For finite automata the pigeonhole applied to states along a run. Here there are no states to count, so something else must be bounded.

9. What a repeated variable gives you

Concept

Suppose some variable appears twice on one root-to-leaf path. Then one occurrence sits inside the subtree of the other.

The outer subtree derives some string; the inner subtree derives a shorter one. Because both are rooted at the same variable, either subtree may be substituted for the other.

\[ A \Longrightarrow^{*} vAy \qquad\text{and}\qquad A \Longrightarrow^{*} x \]

Repeating the outer derivation any number of times gives a family of strings, all in the language. That is the pumping, and note it inserts material in two places at once — which is the essential difference from Lesson 10.

\[ A \Longrightarrow^{*} v^{i}xy^{i} \]

10. Teach it back: What a repeated variable gives you

Explain it

Discussion prompt

Explain What a repeated variable gives you to a student a year behind you. No notation, no jargon they have not met — and it still has to be true.

Hint: If your explanation needs a symbol they have never seen, you are describing the notation rather than the idea.

Answer:

Suppose some variable appears twice on one root-to-leaf path. Then one occurrence sits inside the subtree of the other.

11. What has to happen first: Watch a repeated variable pump

Ranking

Put in order

Put the moves of Watch a repeated variable pump into the order they have to happen.

  1. Derive a string with a repeated variable
  2. Identify the two occurrences
  3. Substitute the inner subtree for the outer
  4. Substitute the outer for the inner
  5. Verify every substitution stays in the language

Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. Applying the recursive rule twice puts the start variable inside its own subtree.

12. Watch a repeated variable pump

Worked example

Make the mechanism concrete on a grammar where the repetition is visible.

\[ S \to aSb \;\mid\; ab \]

Derive a string with a repeated variable

Why: Applying the recursive rule twice puts the start variable inside its own subtree.

\[ S \Longrightarrow aSb \Longrightarrow aaSbb \Longrightarrow aaabbb \]

Identify the two occurrences

Why: The outer one is the root; the inner one is two levels down. Between them the derivation produced one a on the left and one b on the right.

\[ S \Longrightarrow^{*} a\,S\,b \]

Substitute the inner subtree for the outer

Why: Replacing the outer occurrence's subtree by the inner one removes one a and one b, giving a shorter member.

\[ aabb \in L \]

Substitute the outer for the inner

Why: Repeating the outer stretch inside itself adds one a and one b, giving a longer member.

\[ aaaabbbb \in L \]

Verify every substitution stays in the language

Why: Each repetition adds exactly one a on the left and one b on the right, so the counts stay equal and every result is a member. The two insertion points move together, which is precisely the structure the lemma will describe.

\[ a^{n}b^{n} \in L \;\text{ for every } n \ge 1 \ \checkmark \]

13. Watch a repeated variable pump — line by line

Picture it

Animation

Shows: Each line of the worked example "Watch a repeated variable pump", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Each repetition adds exactly one a on the left and one b on the right, so the counts stay equal and every result is a member. The two insertion points move together, which is precisely the structure the lemma will describe.

14. Two insertion points, not one

Concept

The single most important structural difference from the regular case, and the source of every complication ahead.

RegularContext-free
string splits intothree piecesfive pieces
pumped piecesone, in the middletwo, on either side of a centre
what forces the repeata repeated state in a runa repeated variable on a path
case analysis neededusually noneusually two or three cases

The two pumped pieces must be inserted together and in matching numbers. That coupling is exactly what a stack can enforce, and it is why the lemma cannot rule out matched counts.

15. Fill in: Regular for Two insertion points, not one

Comparison

Comparison matrix

From Two insertion points, not one: refill the Regular column from what you know. The rest of the table is as it appeared.

RegularContext-free
string splits intothree piecesfive pieces
pumped piecesone, in the middletwo, on either side of a centre
what forces the repeata repeated state in a runa repeated variable on a path
case analysis neededusually noneusually two or three cases

16. What the lemma can and cannot rule out

Intuition

Knowing in advance which languages are vulnerable saves a great deal of wasted effort.

Pumping inserts material at two points. A language whose condition ties two positions together survives, because the two insertions can maintain the tie. A language tying three positions together does not.

LanguagePositions tiedContext-free?
matched countstwoyes
palindromestwoyes
three matched countsthreeno
a block written twicetwo, but in the same orderno

17. Which is which, by Positions tied

Discrimination

Sort into buckets

Sort these by Positions tied, from memory, without looking back at What the lemma can and cannot rule out. Telling them apart on the spot is the skill; the table is only where the answer happens to be written down.

two
matched counts; palindromes
three
three matched counts
two, but in the same order
a block written twice
g1
Positions tied is "two" for matched counts, palindromes — that is what the table on "What the lemma can and cannot rule out" records, and it is the single property separating this group from the rest.
g2
Positions tied is "three" for three matched counts — that is what the table on "What the lemma can and cannot rule out" records, and it is the single property separating this group from the rest.
g3
Positions tied is "two, but in the same order" for a block written twice — that is what the table on "What the lemma can and cannot rule out" records, and it is the single property separating this group from the rest.

18. The tree-height bound, restated

Concept

The bound from Lesson 15 is the engine of this lemma, so it is worth having in front of you in the form the proof uses.

In Chomsky normal form every internal node has at most two children, so a tree of height h yields at most two to the h symbols.

\[ |\mathrm{yield}(T)| \le 2^{h} \]

Contrapositively, a long yield forces a tall tree. And a tall tree has a long root-to-leaf path, which is where the pigeonhole is applied.

\[ |w| > 2^{h} \;\Rightarrow\; \text{height} > h \]

19. Plan first: Trace the bound from string length to repeated variable

Step zero

Discussion prompt

Trace the bound from string length to repeated variable — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Fix a grammar in normal form

Answer:

  1. Fix a grammar in normal form
  2. Choose a string long enough
  3. Force the height
  4. Apply the pigeonhole to a longest path
  5. Verify the choice of pumping length was forced

20. Trace the bound from string length to repeated variable

Worked example

Follow the chain of implications once, so the choice of pumping length later makes sense.

Fix a grammar in normal form

Why: Say it has four variables. Every parse tree it produces is binary.

\[ |V| = 4 \]

Choose a string long enough

Why: Take a string of at least thirty-two symbols, which exceeds two raised to the variable count.

\[ |w| \ge 2^{5} = 32 \]

Force the height

Why: A binary tree of height four yields at most sixteen symbols, so this tree has height at least five.

Apply the pigeonhole to a longest path

Why: That path has at least five internal nodes, each labelled by one of four variables, so some variable appears twice.

\[ 5 > 4 \;\Rightarrow\; \text{a variable repeats} \]

Verify the choice of pumping length was forced

Why: The argument needed the yield to exceed two raised to the variable count, which is exactly why the proof sets the pumping length to two raised to the variable count plus one. Any smaller value would leave short trees possible and no repeat guaranteed.

\[ p = 2^{|V|+1} \ \checkmark \]

21. Trace the bound from string length to repeated… — line by line

Picture it

Animation

Shows: Each line of the worked example "Trace the bound from string length to repeated variable", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The argument needed the yield to exceed two raised to the variable count, which is exactly why the proof sets the pumping length to two raised to the variable count plus one. Any smaller value would leave short trees possible and no repeat guaranteed.

22. Why the repetition must be on one path

Intuition

A variable appearing twice in a tree is not enough. The two occurrences must lie on a single root-to-leaf path, and that requirement does real work.

Only then does one occurrence sit inside the other's subtree, so that one subtree can be substituted for the other. Two occurrences in sibling subtrees are unrelated and nothing can be swapped.

\[ \text{one inside the other} \;\Rightarrow\; \text{substitutable} \]

That is why the proof examines a longest path rather than counting occurrences across the whole tree. The pigeonhole is applied along the path, not to the tree.

23. Rebuild the recipe: Deciding whether this tool applies

Ranking

Put in order

These are the steps of Deciding whether this tool applies, scrambled. Put them back in order before the next slide shows you.

  1. Ask what a stack would have to store, and whether it is consumed once or twice.
  2. If a count must be checked against two later counts, the language is probably beyond the class.
  3. If a block must be compared in the same order rather than reversed, likewise.
  4. If only one pairing is needed, build a grammar instead — the language is probably in the class.
  5. If a closure argument reaches a known non-context-free language, use that instead of pumping.

Why: This is the order the recipe itself gives. Recalling the sequence without the slide in front of you is the difference between recognising the method and being able to run it — most of what goes wrong in practice is a step done out of turn.

24. Deciding whether this tool applies

Pattern

Classify before proving, exactly as in Lesson 11.

  1. Ask what a stack would have to store, and whether it is consumed once or twice.
  2. If a count must be checked against two later counts, the language is probably beyond the class.
  3. If a block must be compared in the same order rather than reversed, likewise.
  4. If only one pairing is needed, build a grammar instead — the language is probably in the class.
  5. If a closure argument reaches a known non-context-free language, use that instead of pumping.

The second and third lines cover almost every standard example, and both are visible from the language's description without any proof.

25. Rule out three: Check yourself: where the property comes from

Elimination

Eliminate the wrong options

Why does a sufficiently long string force a repeated variable on some root-to-leaf path?

3 of these 4 are wrong. Strike them one at a time, and say what rules each one out before you strike the next. The survivor is the answer.

  • A. The tree is binary, so many leaves force great height, and a long path must reuse a variable
  • B. Every grammar has finitely many rules
  • C. The string itself must contain a repeated symbol
  • D. Derivations in normal form always have the same length

Survives elimination: A

Why: Chomsky normal form makes every internal node have at most two children, so a tree with many leaves cannot be short. A path longer than the number of variables must visit some variable twice, by the pigeonhole principle.

26. Check yourself: where the property comes from

Check

Think about what bounds the tree.

Check your understanding

Why does a sufficiently long string force a repeated variable on some root-to-leaf path?

  • A. The tree is binary, so many leaves force great height, and a long path must reuse a variable (correct)
  • B. Every grammar has finitely many rules
  • C. The string itself must contain a repeated symbol
  • D. Derivations in normal form always have the same length

Answer: A

Why: Chomsky normal form makes every internal node have at most two children, so a tree with many leaves cannot be short. A path longer than the number of variables must visit some variable twice, by the pigeonhole principle.

Why B tempts people
Finitely many rules alone says nothing about paths. It is the finite number of variables along a long path that forces the repeat.
Why C tempts people
Repeated input symbols are irrelevant. A string over a large alphabet with all distinct symbols still forces a repeated variable if it is long enough.
Why D tempts people
Derivation length is determined by string length in normal form, but that is a statement about the number of steps, not about the height of any single path.

27. The Statement

Section

Section 2

28. The lemma

Concept

The five-piece version, with the quantifiers in the order that matters.

pumping lemma for context-free languages — If a language is context-free, then there is a length p such that every string in the language of length at least p can be split into five parts, with the two pumped parts not both empty and the middle three parts short, so that repeating the two pumped parts together any number of times keeps the string in the language.

\[ L \text{ context-free} \;\Longrightarrow\; \exists p \; \forall s \in L, |s| \ge p \; \exists u,v,x,y,z \]

The three conditions on the split come next, and each does specific work in the proofs.

29. The three conditions

Concept

Given the split into five parts, the lemma guarantees all three of these.

\[ s = u\,v\,x\,y\,z \]

ConditionWrittenWhy it holds
pumping worksevery joint repetition stays in the languagethe repeated variable's derivation can be reused
the pumped parts are not both emptythe two together have positive lengththe two occurrences are distinct nodes
the middle is shortthe three central parts total at most pthe repeat is found near the bottom of the tree

\[ u\,v^{i}\,x\,y^{i}\,z \in L \;\forall i \ge 0, \qquad |vy| > 0, \qquad |vxy| \le p \]

30. What each one costs: The three conditions

Trade off

Comparison matrix

From The three conditions: every row here is a choice with a cost. Fill the Why it holds column, then say which row you would actually pick and what you give up for it.

ConditionWrittenWhy it holds
pumping worksevery joint repetition stays in the languagethe repeated variable's derivation can be reused
the pumped parts are not both emptythe two together have positive lengththe two occurrences are distinct nodes
the middle is shortthe three central parts total at most pthe repeat is found near the bottom of the tree

31. What each condition buys in a proof

Intuition

The two side conditions are what make proofs possible, and each is used differently from its Lesson 10 counterpart.

Not both empty stops the adversary offering a split that pumps nothing. Note it permits one of the two to be empty, which is a case the proofs must handle.

The middle is short confines the three central parts to a window of length at most p. So the two pumped parts sit close together, and a string designed with widely separated blocks forces them into at most two adjacent blocks.

\[ |vxy| \le p \;\Rightarrow\; v \text{ and } y \text{ lie within a window of length } p \]

That window condition replaces the early-split condition of Lesson 10, and it is what every proof in Section 4 exploits.

32. Which of the two pumped parts may be empty

Concept

The condition says the two pumped parts are not both empty. That permits one of them to be empty, and proofs must allow for it.

CaseEffect of pumping
both nonemptymaterial inserted at two separate points
only the first nonemptymaterial inserted at one point, to the left of the centre
only the second nonemptymaterial inserted at one point, to the right of the centre
both emptyforbidden by the condition

The middle two rows behave much like the regular pumping lemma, inserting at a single point. A proof that assumes both parts are nonempty has an unhandled case, though in practice it is usually the easy one.

33. Guess the shape of the answer: Handle the case where one pumped part is…

Estimation

Predict first

Check the easy case explicitly, on the three-matched-counts proof.

Commit before you compute: what does Handle the case where one pumped part is empty come out to? A rough magnitude and the right form is enough — the point is to have something concrete to be wrong about.

Correct: Verify the case genuinely needed no new idea

Why: A prediction you can defend turns the computation into a check rather than a leap of faith — and an answer that contradicts it is caught on the spot. One insertion point is a special case of two, with the second contributing nothing.

34. Handle the case where one pumped part is empty

Worked example

Check the easy case explicitly, on the three-matched-counts proof.

\[ s = a^{p}b^{p}c^{p} \]

Suppose the second pumped part is empty

Why: Then all the inserted material comes from the first, at a single position within the window.

Ask which blocks that position can lie in

Why: The window is at most p long and each block is exactly p long, so the single insertion point lies within one block, or straddles two adjacent ones.

Pump up

Why: The count of one or two symbols increases; the remaining count is untouched, since the window cannot reach all three blocks.

\[ \#_a \text{ or } \#_b \text{ grows}, \quad \#_c \text{ fixed} \]

Read off the contradiction

Why: The three counts are no longer equal, so the pumped string leaves the language — the same conclusion as the general case.

Verify the case genuinely needed no new idea

Why: One insertion point is a special case of two, with the second contributing nothing. The block argument bounds the reach identically, so the same contradiction follows. That is why proofs usually treat the cases together, but naming them shows the gap has been considered.

\[ |y| = 0 \;\Rightarrow\; \text{same contradiction} \ \checkmark \]

35. Handle the case where one pumped part is empty — line by line

Picture it

Animation

Shows: Each line of the worked example "Handle the case where one pumped part is empty", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: One insertion point is a special case of two, with the second contributing nothing. The block argument bounds the reach identically, so the same contradiction follows. That is why proofs usually treat the cases together, but naming them shows the gap has been considered.

36. The window can be anywhere

Concept

One difference from the regular case is easy to miss and causes most incorrect proofs.

In Lesson 10 the pumped part was confined to the first p symbols of the string. Here the window of length p may sit anywhere in the string — the lemma says only that it is short, not where it is.

\[ \text{regular: } |xy| \le p \;\text{ (a prefix)} \qquad \text{context-free: } |vxy| \le p \;\text{ (anywhere)} \]

So a proof cannot assume the pumped parts lie in the first block. It must consider every position the window could occupy, which is why case analysis is unavoidable here.

37. What has to be given first: Read the statement on a context-free language

Missing information

Discussion prompt

Check the lemma holds somewhere it must, before turning it against a language.

What do you need to know — or decide — before the first line can be written? List everything the problem has to hand you.

Hint: Anything you would have to invent to get started is a thing the problem must supply.

Answer:

Use the matched-counts language with its two-rule grammar.

38. Read the statement on a context-free language

Worked example

Check the lemma holds somewhere it must, before turning it against a language.

Take a context-free language and a grammar

Why: Use the matched-counts language with its two-rule grammar.

\[ S \to aSb \;\mid\; \varepsilon \]

Take a long string and find a repeated variable

Why: Any string with enough symbols has a derivation using the recursive rule twice, so the start variable repeats on the path.

\[ s = a^{3}b^{3} \]

Read off the five pieces

Why: The outer stretch contributes one a before and one b after; the inner subtree contributes the rest.

\[ u = aa, \; v = a, \; x = \varepsilon, \; y = b, \; z = bb \]

Check the three conditions

Why: The two pumped parts are one symbol each, so not both empty. The three central parts total two symbols, comfortably short.

Verify pumping keeps every result in the language

Why: Taking zero copies gives the two-symbol member, one copy gives the original, and two copies give the four-symbol member. Each adds one a and one b together, so the counts stay equal and every result is a member — as the lemma promises for a context-free language.

\[ a^{2}b^{2},\ a^{3}b^{3},\ a^{4}b^{4} \in L \ \checkmark \]

39. Read the statement on a context-free language — line by line

Picture it

Animation

Shows: Each line of the worked example "Read the statement on a context-free language", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The two pumped parts are one symbol each, so not both empty. The three central parts total two symbols, comfortably short.

40. Something is wrong here: assuming the pumped parts are adjacent to the string's…

Anomaly

Predict first

A student writes this, and it looks reasonable:

Prove that the language of three matched counts is not context-free.

It is wrong. Say what breaks — and say it before you turn the page.

Correct: Take p of each symbol. Since the window has length at most p, assume it lies inside the leading block of a's.

Prove that the language of three matched counts is not context-free.

Why: Take p of each symbol. Since the window has length at most p, assume it lies inside the leading block of a's.

41. Trap: assuming the pumped parts are adjacent to the string's start

Trap

The trap

Prove that the language of three matched counts is not context-free.

Choose a string and assume the window is at the front

Why: Take p of each symbol. Since the window has length at most p, assume it lies inside the leading block of a's.

\[ s = a^{p}b^{p}c^{p}, \quad v,y \text{ assumed inside } a^{p} \]

Pump and declare the contradiction

Why: Pumping adds a's only, so the counts differ and the string leaves the language.

Notice the gap

Why: Nothing forces the window to the front. The adversary may place it straddling the b's and c's, and that case has not been handled.

\[ |vxy| \le p \;\text{ says short, not leading} \]

The fix

Prove that the language of three matched counts is not context-free.

Choose the string and enumerate the window's possible positions

Why: The window has length at most p and the string has three blocks of length p, so it can meet at most two adjacent blocks — never all three.

\[ |vxy| \le p \;\Rightarrow\; vxy \text{ meets at most two blocks} \]

Handle each case

Why: If the window misses the c's, pumping changes the a or b counts and leaves the c count alone. If it misses the a's, pumping leaves the a count alone. Either way some count changes and another does not.

Conclude

Why: In every case the three counts can no longer be equal, so the pumped string leaves the language. The proof now covers every position the adversary could choose.

\[ \text{some count changes, another does not} \;\Rightarrow\; \text{not in } L \ \checkmark \]

42. Decode the notation: Trap: assuming the pumped parts are adjacent to the…

Notation

Annotate

From Trap: assuming the pumped parts are adjacent to the… — read this one piece at a time. What is each part doing?

On: \( s = a^{p}b^{p}c^{p}, \quad v,y \text{ assumed inside } a^{p} \)

  • Take p of each symbol. Since the window has length at most p, assume it lies inside the leading block of a's.
  • Pumping adds a's only, so the counts differ and the string leaves the language.
  • Nothing forces the window to the front. The adversary may place it straddling the b's and c's, and that case has not been handled.

43. The adversary game, updated

Pattern

The same four moves as Lesson 10, with one extra obligation on your final move.

  1. The adversary names the pumping length.
  2. You choose a string in the language, built from that length.
  3. The adversary splits it into five parts, subject to the two side conditions.
  4. You choose a repetition count — and you must handle every legal window position.
  5. You win if the pumped string leaves the language in every case.

Step four is where the extra work lives. Designing the string so that only two or three window positions are possible is the whole skill.

44. Answer it before you see the options: Check yourself: the conditions

Prediction

Predict first

What does the condition bounding the middle three parts by p tell you?

Answer it in your own words, now, with nothing to choose from. The options are on the next slide — and picking the right one off a list is an easier skill than producing it.

Correct: The two pumped parts lie within a window of length at most p, positioned anywhere

Why: The bound is on the total length of the three central parts, which contain both pumped parts and everything between them. It constrains how far apart they can be, but says nothing about where in the string that window sits.

45. Check yourself: the conditions

Check

Compare the window condition with its regular-language counterpart.

Check your understanding

What does the condition bounding the middle three parts by p tell you?

  • A. The two pumped parts lie within a window of length at most p, positioned anywhere (correct)
  • B. The two pumped parts lie within the first p symbols
  • C. The two pumped parts each have length at most p over two
  • D. The whole string has length at most p

Answer: A

Why: The bound is on the total length of the three central parts, which contain both pumped parts and everything between them. It constrains how far apart they can be, but says nothing about where in the string that window sits.

Why B tempts people
That is the regular-language condition from Lesson 10. Assuming it here is the standard error, and the trap on the previous slides shows what it misses.
Why C tempts people
Individual bounds on each pumped part do not follow. One could have length p minus one while the other is empty.
Why D tempts people
The string was chosen with length at least p, and is usually much longer. Only the central window is bounded.

46. Proving the Lemma

Section

Section 3

47. Setting the pumping length

Concept

The proof begins by choosing p from the grammar, and the choice is what makes everything else work.

Convert the grammar to Chomsky normal form, so every tree is binary. Let the number of variables be some count, and set the pumping length to two raised to that count plus one.

\[ p = 2^{|V|+1} \]

The exponent is chosen so that a string of length at least p forces a path longer than the number of variables — which is exactly what the pigeonhole needs.

48. Plan first: Prove the lemma

Step zero

Discussion prompt

Prove the lemma — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Take a long string and its smallest parse tree

Answer:

  1. Take a long string and its smallest parse tree
  2. Force a tall tree
  3. Find a repeated variable
  4. Read off the five pieces
  5. Verify the three conditions and conclude

49. Prove the lemma

Worked example

The full argument, in five steps.

Take a long string and its smallest parse tree

Why: Let the string be in the language with length at least p, and take a parse tree for it with as few nodes as possible.

Force a tall tree

Why: A binary tree of height h yields at most two to the h symbols. Since the string is longer than that bound allows for short trees, the height exceeds the number of variables.

\[ |s| \ge p = 2^{|V|+1} \;\Rightarrow\; h \ge |V|+1 \]

Find a repeated variable

Why: Take a longest root-to-leaf path. It has more than the number of variables among its internal nodes, so some variable appears twice. Choose the two lowest such occurrences.

Read off the five pieces

Why: The upper occurrence's subtree yields the middle three parts; the lower occurrence's subtree yields the centre. What lies outside the upper subtree gives the first and last parts.

\[ A \Longrightarrow^{*} vAy, \qquad A \Longrightarrow^{*} x \]

Verify the three conditions and conclude

Why: Substituting the upper derivation into itself any number of times gives the pumped strings, all derivable. The two pumped parts cannot both be empty, or replacing the upper subtree by the lower would give a smaller tree for the same string, contradicting minimality. And choosing the two lowest occurrences bounds the upper subtree's height, hence the length of the middle three parts.

\[ u\,v^{i}\,x\,y^{i}\,z \in L \;\forall i, \quad |vy|>0, \quad |vxy| \le p \ \checkmark \]

50. Prove the lemma — line by line

Picture it

Animation

Shows: Each line of the worked example "Prove the lemma", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Substituting the upper derivation into itself any number of times gives the pumped strings, all derivable. The two pumped parts cannot both be empty, or replacing the upper subtree by the lower would give a smaller tree for the same string, contradicting minimality. And choosing the two lowest occurrences bounds the upper subtree's height, hence the length of the middle three parts.

51. Where minimality was needed

Intuition

The proof used a smallest tree, and that hypothesis did exactly one job.

It ruled out the degenerate case where both pumped parts are empty. If they were, the upper subtree and the lower would yield the same string, so the lower could replace the upper — giving a strictly smaller tree for the same string.

\[ |vy| = 0 \;\Rightarrow\; \text{a smaller tree exists} \]

Choosing the tree minimal in advance makes that impossible, so the condition holds. Without minimality the lemma would be true but vacuous, since an empty pumping changes nothing.

52. Where does each piece belong: The Pumping Lemma for CFLs

Sorting

Sort into buckets

These are the pieces of The Pumping Lemma for CFLs, out of order. Put each one back under the part of the lesson it belongs to.

Why a New Tool
The same gap, one level up; Where the forced property comes from now; What a repeated variable gives you
The Statement
The lemma; The three conditions; What each condition buys in a proof
Proving the Lemma
Setting the pumping length; Prove the lemma; Where minimality was needed
s1
Why a New Tool is where The Pumping Lemma for CFLs puts The same gap, one level up, Where the forced property comes from now, What a repeated variable gives you. Knowing which part of the lesson a problem belongs to is most of knowing which method to reach for.
s2
The Statement is where The Pumping Lemma for CFLs puts The lemma, The three conditions, What each condition buys in a proof. Knowing which part of the lesson a problem belongs to is most of knowing which method to reach for.
s3
Proving the Lemma is where The Pumping Lemma for CFLs puts Setting the pumping length, Prove the lemma, Where minimality was needed. Knowing which part of the lesson a problem belongs to is most of knowing which method to reach for.

53. Why the two lowest occurrences are chosen

Concept

The proof picked a specific pair of occurrences, and that choice is what delivers the third condition.

Taking the two lowest repeated occurrences on the path bounds the height of the upper subtree: below the upper occurrence there is no further repetition, so that stretch of path is at most as long as the variable count.

\[ \text{height of the upper subtree} \le |V|+1 \]

A bounded height bounds the yield, and the upper subtree's yield is exactly the three central parts. So those parts total at most the pumping length.

\[ |vxy| \le 2^{|V|+1} = p \]

54. Guess the shape of the answer: Show a different choice loses the third…

Estimation

Predict first

See what breaks if the highest repeated pair is taken instead of the lowest.

Commit before you compute: what does Show a different choice loses the third condition come out to? A rough magnitude and the right form is enough — the point is to have something concrete to be wrong about.

Correct: Verify the condition is restored

Why: A prediction you can defend turns the computation into a check rather than a leap of faith — and an answer that contradicts it is caught on the spot. With the bounded yield, the three central parts total at most p, which is exactly the third condition.

55. Show a different choice loses the third condition

Worked example

See what breaks if the highest repeated pair is taken instead of the lowest.

Take a tall tree with several repetitions

Why: Suppose a variable appears at the root and again near the leaves, with other repetitions in between.

Choose the highest pair

Why: The upper occurrence is the root, so its subtree is the whole tree and its yield is the entire string.

See the third condition fail

Why: The three central parts would then be the whole string, whose length is unbounded — so no useful window bound is available.

\[ |vxy| = |s| \;\;\text{— no bound} \]

Choose the lowest pair instead

Why: Now the upper subtree contains no further repetition below it, so its height is bounded by the variable count and its yield by the pumping length.

Verify the condition is restored

Why: With the bounded yield, the three central parts total at most p, which is exactly the third condition. The choice of the lowest pair is therefore not a stylistic preference but the source of the condition every proof relies on.

\[ \text{lowest pair} \;\Rightarrow\; |vxy| \le p \ \checkmark \]

56. Decode the notation: Show a different choice loses the third condition

Notation

Annotate

From Show a different choice loses the third condition — read this one piece at a time. What is each part doing?

On: \( \text{lowest pair} \;\Rightarrow\; |vxy| \le p \ \checkmark \)

  • Suppose a variable appears at the root and again near the leaves, with other repetitions in between.
  • The upper occurrence is the root, so its subtree is the whole tree and its yield is the entire string.
  • The three central parts would then be the whole string, whose length is unbounded — so no useful window bound is available.

57. Where each condition came from

Concept

Tracing the three conditions back to the proof makes them memorable and shows why none can be strengthened.

ConditionSource
pumping preserves membershipboth occurrences are the same variable, so their subtrees are interchangeable
the pumped parts are not both emptyminimality of the chosen tree
the middle three parts are shortthe two occurrences chosen are the lowest on the path

Notice what is not claimed: nothing says both pumped parts are nonempty, nothing says they are adjacent, and nothing locates the window in the string. All three would be false.

58. Check yourself: the proof

Check

Recall which hypothesis rules out the degenerate split.

Check your understanding

In the proof, why is the parse tree chosen to be as small as possible?

  • A. To guarantee the two pumped parts are not both empty (correct)
  • B. To make the tree binary
  • C. To bound the pumping length
  • D. To ensure the string is in the language

Answer: A

Why: If both pumped parts were empty, the lower occurrence's subtree would yield the same string as the upper one, so substituting it would give a strictly smaller tree for the same string — contradicting minimality. That is the only place the hypothesis is used.

Why B tempts people
The tree is binary because the grammar is in Chomsky normal form, which is arranged before any tree is chosen.
Why C tempts people
The pumping length is set from the variable count, independently of any particular string or tree.
Why D tempts people
The string was assumed to be in the language at the outset, so its membership needs no further argument.

59. Applications

Section

Section 4

60. What has to happen first: Three matched counts

Ranking

Put in order

Put the moves of Three matched counts into the order they have to happen.

  1. Assume context-freeness and take the pumping length
  2. Choose the string
  3. Bound where the window can be
  4. Handle the two cases
  5. Verify the contradiction covers every legal split

Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. Suppose the language were context-free; the lemma provides a length p whose value is unknown.

61. Three matched counts

Worked example

The canonical example, and the one every later proof imitates.

\[ L = \{\, a^{n}b^{n}c^{n} : n \ge 0 \,\} \]

Assume context-freeness and take the pumping length

Why: Suppose the language were context-free; the lemma provides a length p whose value is unknown.

Choose the string

Why: Take p of each symbol, in order. It is in the language and its length exceeds p.

\[ s = a^{p}b^{p}c^{p} \]

Bound where the window can be

Why: The three central parts total at most p symbols, and each block has length p. So the window meets at most two adjacent blocks and never all three.

Handle the two cases

Why: If the window avoids the c's, pumping changes the a or b count while the c count is fixed. If it avoids the a's, pumping leaves the a count fixed while another changes.

\[ \text{some count changes, at least one does not} \]

Verify the contradiction covers every legal split

Why: Since the two pumped parts are not both empty, at least one count strictly changes; and since the window misses at least one block, at least one count is unchanged. The three can no longer be equal, whatever split the adversary chose.

\[ a^{p}b^{p}c^{p} \text{ pumped} \notin L \ \checkmark \]

62. Three matched counts — line by line

Picture it

Animation

Shows: Each line of the worked example "Three matched counts", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Since the two pumped parts are not both empty, at least one count strictly changes; and since the window misses at least one block, at least one count is unchanged. The three can no longer be equal, whatever split the adversary chose.

63. State the rule before it runs: A block written twice

Hypothesis

Predict first

A block written twice is about to be worked. State your hypothesis first: which rule or definition decides this one, and what is the first move it forces? Then watch whether the example agrees with you.

Correct: Choose the string carefully

Why: A naive choice fails. Take p a's, p b's, then p a's, p b's again — so the string is a block written twice, with four blocks of length p.

A hypothesis you wrote down is falsifiable; a vague sense of how it will go is not. If the example opens somewhere else, that gap is the thing worth chasing.

64. A block written twice

Worked example

The language a stack cannot handle because the comparison is in the same order, not reversed.

\[ L = \{\, ww : w \in \{a,b\}^{*} \,\} \]

Choose the string carefully

Why: A naive choice fails. Take p a's, p b's, then p a's, p b's again — so the string is a block written twice, with four blocks of length p.

\[ s = a^{p}b^{p}a^{p}b^{p} \]

Bound the window

Why: It has length at most p, so it meets at most two adjacent blocks out of the four.

See what pumping does

Why: Pumping changes the length of one or two adjacent blocks while leaving the others alone. The string's two halves then have different block structures.

Check the halves can no longer match

Why: For the result to be in the language its first half must equal its second. Changing one block's length in only one half breaks that equality, and the window cannot reach the corresponding block in the other half.

Verify the string choice was necessary

Why: Had the string been p a's followed by p a's, pumping inside the a's would give a longer run of a's — still a block written twice, and no contradiction. The four-block choice is what makes every window position fatal.

\[ a^{p}b^{p}a^{p}b^{p} \text{ pumped} \notin L \ \checkmark \]

65. A block written twice — line by line

Picture it

Animation

Shows: Each line of the worked example "A block written twice", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: For the result to be in the language its first half must equal its second. Changing one block's length in only one half breaks that equality, and the window cannot reach the corresponding block in the other half.

66. Why the string choice matters even more here

Intuition

In Lesson 10 a uniform prefix sufficed. Here the string must also control where the window can be, which takes more design.

The technique is to build the string from several equal blocks, long enough that a window of length p cannot span more than two of them. Then every window position leaves some block untouched, and the untouched block is the contradiction.

\[ \text{blocks of length } p \;+\; |vxy| \le p \;\Rightarrow\; \text{at most two blocks touched} \]

Getting this wrong produces a proof that handles one case and silently ignores the others — the commonest error in these arguments, and the subject of the trap in Section 2.

67. Plan first: Equal counts in the same positions

Step zero

Discussion prompt

Equal counts in the same positions — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Choose the string on the boundary

Answer:

  1. Choose the string on the boundary
  2. Bound the window and enumerate cases
  3. Handle the case where the window misses the c's
  4. Handle the case where the window misses the a's
  5. Verify both cases needed a different repetition count

68. Equal counts in the same positions

Worked example

A variant showing the technique transfers to conditions other than counting.

\[ L = \{\, a^{i}b^{j}c^{k} : i \le j \le k \,\} \]

Choose the string on the boundary

Why: Take p of each, so both inequalities hold with equality — the tightest possible margin.

\[ s = a^{p}b^{p}c^{p} \]

Bound the window and enumerate cases

Why: As before it meets at most two adjacent blocks, so at most two of the three counts can change.

Handle the case where the window misses the c's

Why: Pumping up increases the a count or the b count without increasing the c count. If the a count grows past the b count, or the b count past the c count, an inequality fails.

Handle the case where the window misses the a's

Why: Pumping down, taking zero copies, decreases the b count or the c count while the a count is fixed. Either the first or the second inequality then fails.

Verify both cases needed a different repetition count

Why: The first case used two copies and the second used zero. That is normal here: unlike Lesson 10, different window positions often need different pumping directions, and a complete proof must say which is used in each case.

\[ \text{case 1: } i = 2; \quad \text{case 2: } i = 0 \ \checkmark \]

69. Equal counts in the same positions — line by line

Picture it

Animation

Shows: Each line of the worked example "Equal counts in the same positions", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The first case used two copies and the second used zero. That is normal here: unlike Lesson 10, different window positions often need different pumping directions, and a complete proof must say which is used in each case.

70. What has to be given first: A language of matched exponents

Missing information

Discussion prompt

A fourth application, where the condition is arithmetic rather than a plain count.

What do you need to know — or decide — before the first line can be written? List everything the problem has to hand you.

Hint: Anything you would have to invent to get started is a thing the problem must supply.

Answer:

Take p a's and p squared b's, so the relationship holds exactly.

71. A language of matched exponents

Worked example

A fourth application, where the condition is arithmetic rather than a plain count.

\[ L = \{\, a^{n}b^{m} : m = n^{2} \,\} \]

Choose the string on the condition

Why: Take p a's and p squared b's, so the relationship holds exactly.

\[ s = a^{p}b^{p^{2}} \]

Bound the window

Why: It has length at most p, so it lies inside the a-block, inside the b-block, or straddles the boundary.

Handle the case inside the a-block

Why: Pumping changes the a count by at least one while the b count is fixed. The required square then changes by at least twice p plus one, but the b count did not move.

\[ (p+k)^{2} \ge p^{2} + 2p + 1 > p^{2} \]

Handle the remaining cases

Why: If the window touches only b's, the b count changes while the a count is fixed, so the square no longer matches. If it straddles, both change, but the a count changes by at most p while the b count changes by at most p — far too little to keep pace with the square.

Verify the arithmetic gap in the straddling case

Why: Increasing the a count by k requires the b count to increase by at least twice p, since consecutive squares differ by that much. But the window contributes at most p symbols in total, so the b count cannot keep up and the condition fails.

\[ 2p+1 > p \;\Rightarrow\; \text{the square outruns the window} \ \checkmark \]

72. A language of matched exponents — line by line

Picture it

Animation

Shows: Each line of the worked example "A language of matched exponents", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Increasing the a count by k requires the b count to increase by at least twice p, since consecutive squares differ by that much. But the window contributes at most p symbols in total, so the b count cannot keep up and the condition fails.

73. Arithmetic conditions need a gap argument here too

Intuition

The last proof reused the technique from Lesson 11's perfect-squares example, and the reuse is not a coincidence.

When the condition relates two quantities by a fast-growing function, pumping changes both by a bounded amount, while the function's required change grows without bound. The gap between them is the contradiction.

\[ \text{window contributes} \le p \quad\text{but the condition demands} \ge 2p+1 \]

So the same three arithmetic tools transfer: land in a gap between consecutive values, force a factorization, or show one side outgrows the other. Only the string design changes, because the window may now sit anywhere.

74. Without one step: Writing a non-context-free proof

Constraint

Discussion prompt

Run Writing a non-context-free proof with this step confiscated:

Invoke the lemma to get a five-part split with the two side conditions.

Is it still possible? If it is, say what takes its place and what it costs you. If it is not, say exactly what that step was providing that nothing else does.

Hint: A step you can drop for free was never load-bearing. If you cannot drop it, name the thing that goes wrong the moment it is gone.

Answer:

  1. Suppose the language is context-free; let p be the pumping length.
  2. Choose a string built from p, made of equal blocks longer than any window can span.
  3. Invoke the lemma to get a five-part split with the two side conditions.
  4. Enumerate every position the window of length at most p could occupy.
  5. For each, give a repetition count and show the result leaves the language.

75. Writing a non-context-free proof

Pattern

The template, with the extra obligation the five-piece split imposes.

  1. Suppose the language is context-free; let p be the pumping length.
  2. Choose a string built from p, made of equal blocks longer than any window can span.
  3. Invoke the lemma to get a five-part split with the two side conditions.
  4. Enumerate every position the window of length at most p could occupy.
  5. For each, give a repetition count and show the result leaves the language.

Step four is the one that distinguishes a complete proof from a plausible one. Naming the cases explicitly — 'the window meets only the first two blocks', and so on — is what makes it checkable.

76. Where does it stop working: Writing a non-context-free proof

Edge cases

Discussion prompt

Writing a non-context-free proof works on the cases you have just seen. Push it to the edge: what is the most degenerate input it still handles — empty, zero, one item, everything equal — and what is the first case where it stops being true? Name the case, not just "it breaks".

Hint: Try the smallest legal input, then the largest, then the one where two things collide. Methods are specified at their edges; the middle takes care of itself.

Answer:

The template, with the extra obligation the five-piece split imposes.

77. How sure are you: Check yourself: applications

Commit first

Predict first

Why is the string with p of each of three symbols a good choice for proving three matched counts is not context-free?

Commit to an answer, then rate it — certain, fairly sure, or guessing — and write the rating down before you turn the page.

Correct: A window of length at most p cannot meet all three blocks, so one count is always untouched

Why: Each block has length p and the window is at most p long, so it can straddle at most two adjacent blocks. Whatever position it takes, some block is untouched, and pumping then breaks the equality between that count and the ones that changed.

The rating matters as much as the answer: confident-and-wrong is the combination that survives revision, because nothing about it feels like it needs revisiting.

78. Check yourself: applications

Check

Think about how many blocks a window of length p can span.

Check your understanding

Why is the string with p of each of three symbols a good choice for proving three matched counts is not context-free?

  • A. A window of length at most p cannot meet all three blocks, so one count is always untouched (correct)
  • B. It is the shortest string in the language
  • C. It forces the two pumped parts to be adjacent
  • D. It guarantees the window lies in the first block

Answer: A

Why: Each block has length p and the window is at most p long, so it can straddle at most two adjacent blocks. Whatever position it takes, some block is untouched, and pumping then breaks the equality between that count and the ones that changed.

Why B tempts people
The shortest string is the empty string, which has length zero and to which the lemma does not apply at all.
Why C tempts people
The two pumped parts may be separated by the central part. Nothing makes them adjacent, and the proof does not need them to be.
Why D tempts people
Nothing forces the window to the front — that is precisely the assumption the trap in Section 2 warns against.

79. Alternatives and Limits

Section

Section 5

80. Closure arguments, again

Concept

As in Lesson 11, once one non-context-free language is known, closure properties multiply it cheaply.

The context-free languages are not closed under intersection, but they are closed under intersection with a regular language — a fact Lesson 19 proves. That mixed closure is exactly what these arguments use.

\[ L \text{ context-free}, \; R \text{ regular} \;\Rightarrow\; L \cap R \text{ context-free} \]

So assuming a candidate is context-free and intersecting it with a simple regular pattern must yield a context-free language. Exhibiting a known non-context-free result gives the contradiction.

81. Guess the shape of the answer: Prove a language non-context-free by closure

Estimation

Predict first

A candidate where a direct pumping proof is fiddly and a closure argument is three lines.

Commit before you compute: what does Prove a language non-context-free by closure come out to? A rough magnitude and the right form is enough — the point is to have something concrete to be wrong about.

Correct: Verify the intersection equality in both directions

Why: A prediction you can defend turns the computation into a check rather than a leap of faith — and an answer that contradicts it is caught on the spot. Every string in the intersection has equal counts and the right order, so it has the matched form; and every matched string has equal counts and the right order.

82. Prove a language non-context-free by closure

Worked example

A candidate where a direct pumping proof is fiddly and a closure argument is three lines.

\[ L = \{\, w : \#_a(w) = \#_b(w) = \#_c(w) \,\} \]

Assume the candidate is context-free

Why: For contradiction, suppose some grammar generates it.

Choose a regular helper

Why: Take the strings with all a's, then all b's, then all c's. A four-state machine recognizes it, so it is regular.

\[ R = a^{*}b^{*}c^{*} \]

Compute the intersection

Why: A string with all three counts equal whose symbols appear in that order is exactly a three-matched-counts string.

\[ L \cap R = \{\, a^{n}b^{n}c^{n} \,\} \]

Invoke the mixed closure and conclude

Why: Intersecting a context-free language with a regular one gives a context-free language. But the result is not context-free, by Section 4. Contradiction.

Verify the intersection equality in both directions

Why: Every string in the intersection has equal counts and the right order, so it has the matched form; and every matched string has equal counts and the right order. Both inclusions hold, so the identification is exact and the argument closes.

\[ L \cap R = \{a^{n}b^{n}c^{n}\} \;\Rightarrow\; L \text{ not context-free} \ \checkmark \]

83. Prove a language non-context-free by closure — line by line

Picture it

Animation

Shows: Each line of the worked example "Prove a language non-context-free by closure", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Every string in the intersection has equal counts and the right order, so it has the matched form; and every matched string has equal counts and the right order. Both inclusions hold, so the identification is exact and the argument closes.

84. Why plain intersection is unavailable

Concept

A crucial difference from Lesson 11, and forgetting it invalidates the argument.

The regular languages were closed under intersection outright, so any regular helper could be used. The context-free languages are not closed under intersection with another context-free language, so the helper must be regular.

\[ L_1, L_2 \text{ context-free} \;\not\Rightarrow\; L_1 \cap L_2 \text{ context-free} \]

Using a context-free helper produces an argument that proves nothing, since the intersection need not be context-free whether or not the candidate is. Lesson 19 gives the counterexample.

85. The lemma is one-way here too

Concept

Exactly as in Lesson 10, the implication runs in one direction only.

Context-free implies pumpable. Pumpable does not imply context-free — there are non-context-free languages satisfying the condition, so exhibiting a valid split proves nothing.

\[ \text{context-free} \;\Rightarrow\; \text{pumpable}, \quad \text{not conversely} \]

When the lemma is silent, stronger tools exist: Ogden's lemma, which lets you mark positions the window must include, and the interchange lemma. Both are beyond this course, but knowing they exist explains why a failed pumping proof is not a dead end.

86. Teach it back: The lemma is one-way here too

Explain it

Discussion prompt

Explain The lemma is one-way here too to a student a year behind you. No notation, no jargon they have not met — and it still has to be true.

Hint: If your explanation needs a symbol they have never seen, you are describing the notation rather than the idea.

Answer:

Exactly as in Lesson 10, the implication runs in one direction only.

87. Three tools, in order of preference

Intuition

Collected, so the choice is automatic — and note the middle row differs from Lesson 11.

ToolUse whenCost
closure with a regular helpera known non-context-free language is one intersection awaythree lines
the pumping lemmaa fresh case with blocks you can controla template plus case analysis
Ogden's lemmapumping is silent because the window keeps landing harmlesslybeyond this course

Try them in that order. The closure route is shortest whenever it applies, and after Section 4 there are several known non-context-free languages to reach for.

88. Fill in: Cost for Three tools, in order of preference

Comparison

Comparison matrix

From Three tools, in order of preference: refill the Cost column from what you know. The rest of the table is as it appeared.

ToolUse whenCost
closure with a regular helpera known non-context-free language is one intersection awaythree lines
the pumping lemmaa fresh case with blocks you can controla template plus case analysis
Ogden's lemmapumping is silent because the window keeps landing harmlesslybeyond this course

89. Plan first: Diagnose a failed attempt

Step zero

Discussion prompt

Diagnose a failed attempt — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Try a poor string

Answer:

  1. Try a poor string
  2. Watch it fail
  3. Repair with blocks
  4. Verify the repaired string engages the condition

90. Diagnose a failed attempt

Worked example

Repair a proof that will not close, using the diagnostic habits from Lesson 11.

Try a poor string

Why: To prove a block written twice is not context-free, take p a's followed by p a's. It is in the language.

\[ s = a^{p}a^{p} \]

Watch it fail

Why: Pumping inside the a's gives a longer run of a's. Any even-length run of a's is a block written twice, so the result is still in the language.

Diagnose

Why: The string is too uniform: its structure is invisible, so changing lengths cannot break the condition. The same failure as Lesson 11's uniform-string trap.

Repair with blocks

Why: Use four alternating blocks of length p, so that changing one block's length is visible and unmatched in the other half.

\[ s = a^{p}b^{p}a^{p}b^{p} \]

Verify the repaired string engages the condition

Why: Now every window position touches at most two adjacent blocks, and the corresponding block in the other half is out of reach. So the two halves must differ after pumping, and the proof closes for every case.

\[ \text{four blocks} \;\Rightarrow\; \text{every window leaves a half unmatched} \ \checkmark \]

91. Diagnose a failed attempt — line by line

Picture it

Animation

Shows: Each line of the worked example "Diagnose a failed attempt", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Now every window position touches at most two adjacent blocks, and the corresponding block in the other half is out of reach. So the two halves must differ after pumping, and the proof closes for every case.

92. Answer it before you see the options: Check yourself: closure arguments

Prediction

Predict first

In a closure argument showing a language is not context-free, what must the helper language be?

Answer it in your own words, now, with nothing to choose from. The options are on the next slide — and picking the right one off a list is an easier skill than producing it.

Correct: Regular — the class is closed under intersection with a regular language only

Why: The context-free languages are not closed under intersection with each other, so a context-free helper licenses no conclusion. They are closed under intersection with a regular language, which is exactly the closure these arguments invoke.

93. Check yourself: closure arguments

Check

Recall which intersection is available for this class.

Check your understanding

In a closure argument showing a language is not context-free, what must the helper language be?

  • A. Regular — the class is closed under intersection with a regular language only (correct)
  • B. Context-free — any context-free helper will do
  • C. Finite, so the intersection can be checked by hand
  • D. Non-context-free, so the intersection cannot be context-free

Answer: A

Why: The context-free languages are not closed under intersection with each other, so a context-free helper licenses no conclusion. They are closed under intersection with a regular language, which is exactly the closure these arguments invoke.

Why B tempts people
This is the error that invalidates the argument. Lesson 19 exhibits two context-free languages whose intersection is not context-free.
Why C tempts people
A finite helper is regular but almost always too weak — the intersection would be finite, hence context-free, and nothing would follow.
Why D tempts people
A non-context-free helper gives no closure theorem to invoke, so the argument could not even begin.

94. Perspective

Section

Section 6

95. The two pumping lemmas side by side

Concept

Both lessons proved a property forced by finiteness. Comparing them makes each easier to recall.

Lesson 10This lesson
forced byfinitely many statesfinitely many variables
mechanisma repeated state in a runa repeated variable on a path
piecesthreefive
pumpedone piecetwo, jointly
window conditionwithin the first p symbolsany window of length p
typical proofone casetwo or three cases

The last two rows are where the extra difficulty lives, and both come from the same source: the pumped material is inserted in two places that must move together.

96. What each one costs: The two pumping lemmas side by side

Trade off

Comparison matrix

From The two pumping lemmas side by side: every row here is a choice with a cost. Fill the This lesson column, then say which row you would actually pick and what you give up for it.

Lesson 10This lesson
forced byfinitely many statesfinitely many variables
mechanisma repeated state in a runa repeated variable on a path
piecesthreefive
pumpedone piecetwo, jointly
window conditionwithin the first p symbolsany window of length p
typical proofone casetwo or three cases

97. Why the hierarchy keeps going

Intuition

Each class so far has been defeated by a language needing one more simultaneous pairing than the model can maintain.

The answer is the machine of Lesson 20, which has unrestricted read-write memory and no such limitation. That model turns out to be the last one — and the rest of the course is about what even it cannot do.

\[ \text{regular} \subsetneq \text{context-free} \subsetneq \cdots \]

98. By analogy: Why the hierarchy keeps going

Analogy

Discussion prompt

Explain Why the hierarchy keeps going by analogy to something with no Theory of Computation in it at all — a queue, a recipe, a map, a bank balance, whatever fits. Then say where your analogy breaks.

Hint: An analogy that never breaks is not an analogy, it is the same idea wearing a hat. Find the seam — that is the part that is actually new.

Answer:

Each class so far has been defeated by a language needing one more simultaneous pairing than the model can maintain.

99. What the class can and cannot pair

Concept

Collecting the examples gives a rule of thumb that predicts most classifications without any proof.

RequirementContext-free?Reason
one count matched against one otheryesone stack suffices
one count matched against two othersnothe count is consumed by the first check
a block compared with its reversalyesa stack returns symbols reversed
a block compared with a copynothe order is wrong for a stack
nesting to any depthyesthe stack depth tracks it
two independent nestingsnoone stack cannot interleave them

Every row follows from the stack's discipline described in Lesson 16. The pumping lemma is how those intuitions are turned into proofs.

100. Which is which, by Context-free?

Discrimination

Sort into buckets

Sort these by Context-free?, from memory, without looking back at What the class can and cannot pair. Telling them apart on the spot is the skill; the table is only where the answer happens to be written down.

yes
one count matched against one other; a block compared with its reversal; nesting to any depth
no
one count matched against two others; a block compared with a copy; two independent nestings
g1
Context-free? is "yes" for one count matched against one other, a block compared with its reversal, nesting to any depth — that is what the table on "What the class can and cannot pair" records, and it is the single property separating this group from the rest.
g2
Context-free? is "no" for one count matched against two others, a block compared with a copy, two independent nestings — that is what the table on "What the class can and cannot pair" records, and it is the single property separating this group from the rest.

101. What has to happen first: Classify four languages by inspection

Ranking

Put in order

Put the moves of Classify four languages by inspection into the order they have to happen.

  1. Take the strings of equal a's and b's followed by any c's
  2. Take the strings of a's, b's and c's with the a's matching the c's
  3. Take the strings where the a's match the b's and the b's match the c's
  4. Take the strings that are some block followed by the same block
  5. Verify the classifications against the proofs

Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. One pairing, between the a's and the b's; the c's are unconstrained.

102. Classify four languages by inspection

Worked example

Practise the rule of thumb before reaching for any proof.

Take the strings of equal a's and b's followed by any c's

Why: One pairing, between the a's and the b's; the c's are unconstrained. One stack suffices, so this is context-free.

\[ \{a^{n}b^{n}c^{m}\} \;: \text{ context-free} \]

Take the strings of a's, b's and c's with the a's matching the c's

Why: Still one pairing, though the paired blocks are separated. A stack can push through the b's without consuming anything, so this is context-free too.

\[ \{a^{n}b^{m}c^{n}\} \;: \text{ context-free} \]

Take the strings where the a's match the b's and the b's match the c's

Why: Two pairings sharing the middle block. The b count would have to be checked twice, which one stack cannot do, so this is not context-free.

\[ \{a^{n}b^{n}c^{n}\} \;: \text{ not context-free} \]

Take the strings that are some block followed by the same block

Why: One pairing, but in the same order rather than reversed. A stack returns symbols backwards, so this is not context-free.

\[ \{ww\} \;: \text{ not context-free} \]

Verify the classifications against the proofs

Why: The first two have easy grammars, which settles them positively. The last two were proved negatively in this section, by exactly the block-and-window technique. The rule of thumb predicted all four correctly.

\[ \text{count the pairings, check the order} \ \checkmark \]

103. Classify four languages by inspection — line by line

Picture it

Animation

Shows: Each line of the worked example "Classify four languages by inspection", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The first two have easy grammars, which settles them positively. The last two were proved negatively in this section, by exactly the block-and-window technique. The rule of thumb predicted all four correctly.

104. Rule out three: Check yourself: classification

Elimination

Eliminate the wrong options

Which of these languages is context-free?

3 of these 4 are wrong. Strike them one at a time, and say what rules each one out before you strike the next. The survivor is the answer.

  • A. Strings of a's, then b's, then c's, where the a count equals the c count
  • B. Strings of a's, then b's, then c's, with all three counts equal
  • C. Strings consisting of some block written twice
  • D. Strings with equal numbers of a's, b's and c's in any order

Survives elimination: A

Why: Only one pairing is required, between the first and last blocks. A machine pushes for each a, ignores the b's without touching the stack, then pops for each c — one stack, one comparison.

105. Check yourself: classification

Check

Count the simultaneous pairings each language demands.

Check your understanding

Which of these languages is context-free?

  • A. Strings of a's, then b's, then c's, where the a count equals the c count (correct)
  • B. Strings of a's, then b's, then c's, with all three counts equal
  • C. Strings consisting of some block written twice
  • D. Strings with equal numbers of a's, b's and c's in any order

Answer: A

Why: Only one pairing is required, between the first and last blocks. A machine pushes for each a, ignores the b's without touching the stack, then pops for each c — one stack, one comparison.

Why B tempts people
Two pairings share the middle block, so its count must be checked twice. One stack consumes the count on the first check, and Section 4 proves this language is beyond the class.
Why C tempts people
The comparison is between a block and a copy in the same order. A stack returns symbols reversed, so it cannot perform it.
Why D tempts people
Intersecting with the ordered regular pattern gives the three-matched-counts language, so a closure argument places this outside the class too.

106. The catalogue

Concept

The standard non-context-free languages, with the string that proves each.

LanguageString to chooseWhy it works
three matched countsp of each symbolthe window misses a block
a block written twicefour alternating blocks of length pthe matching block is out of reach
equal counts, any orderclosure with an ordered regular helperreduces to three matched counts
nested inequalitiesp of each, on the boundarytwo cases, pumping up and down

Every entry uses blocks of length p, so that the window's reach is bounded by construction. That single design principle covers the whole catalogue.

107. Fill in: String to choose for The catalogue

Comparison

Comparison matrix

From The catalogue: refill the String to choose column from what you know. The rest of the table is as it appeared.

LanguageString to chooseWhy it works
three matched countsp of each symbolthe window misses a block
a block written twicefour alternating blocks of length pthe matching block is out of reach
equal counts, any orderclosure with an ordered regular helperreduces to three matched counts
nested inequalitiesp of each, on the boundarytwo cases, pumping up and down

108. What the lemma does not settle

Intuition

Two questions look as though this lemma should answer them, and it answers neither.

It cannot show a language is context-free, since the implication runs one way. And it cannot distinguish the deterministic subclass of Lesson 16, because deterministic and general context-free languages satisfy the same pumping condition.

\[ \text{pumpable} \;\not\Rightarrow\; \text{context-free} \;\not\Rightarrow\; \text{deterministic} \]

For the first, exhibit a grammar. For the second, the standard route is the complement closure from Lesson 16: a language whose complement is not context-free cannot be deterministic.

109. Break it if you can: What the lemma does not settle

Counterexample

Discussion prompt

Two questions look as though this lemma should answer them, and it answers neither.

That is stated as though it always holds. Do one of two things: produce a case where it fails, or say precisely what rules such a case out. "It just does" is not on the menu.

Hint: Hunt at the extremes first — zero, one, negative, empty, equal. If every extreme survives, the reason they survive is the proof.

Answer:

For the first, exhibit a grammar. For the second, the standard route is the complement closure from Lesson 16: a language whose complement is not context-free cannot be deterministic.

110. Rebuild the recipe: The complete procedure

Ranking

Put in order

These are the steps of The complete procedure, scrambled. Put them back in order before the next slide shows you.

  1. Classify: count the simultaneous pairings the language demands. One is fine; two is not.
  2. Look for a closure argument with a regular helper against a known case.
  3. Otherwise choose a string of equal blocks, each of length p, arranged so every window leaves something untouched.
  4. Enumerate the window positions and name each case explicitly.
  5. Give a repetition count per case — pumping up and down may both be needed.

Why: This is the order the recipe itself gives. Recalling the sequence without the slide in front of you is the difference between recognising the method and being able to run it — most of what goes wrong in practice is a step done out of turn.

111. The complete procedure

Pattern

Everything from this lesson, collected as one routine.

  1. Classify: count the simultaneous pairings the language demands. One is fine; two is not.
  2. Look for a closure argument with a regular helper against a known case.
  3. Otherwise choose a string of equal blocks, each of length p, arranged so every window leaves something untouched.
  4. Enumerate the window positions and name each case explicitly.
  5. Give a repetition count per case — pumping up and down may both be needed.

If no string can be found where every window position is fatal, the language may pump despite being outside the class, and a stronger lemma is needed.

112. Where this shows up: The Pumping Lemma for CFLs

Real world

Discussion prompt

Outside this lesson: where does The Pumping Lemma for CFLs actually turn up? Name one concrete situation — a job, a piece of software someone ships, a decision somebody has to make — and say which part of The complete procedure is doing the work in it.

Hint: Vague is the failure mode here. "Engineering" is not a situation; "deciding whether this build is fast enough to ship" is.

Answer:

Lesson 18 supplies the tool for proving that a language has no context-free grammar. It shows how Chomsky normal form bounds the height of a parse tree, so that a long string forces a repeated variable somewhere on a root-to-leaf path, then gives the five-piece statement with its three conditions and the crucial difference from the regular case: the short window may sit anywhere rather than at the front. It proves the lemma and points out where minimality of the parse tree is used, then works proofs for three matched counts, a block written twice, and nested inequalities, with explicit case analysis over the window positions. It covers closure arguments using a regular helper and why a context-free helper proves nothing, and ends by comparing the two pumping lemmas.

113. Connect it up: The Pumping Lemma for CFLs

Connect it up

Draw it

One page, no notation unless you need it: draw how these connect — Why a New Tool · The Statement · Proving the Lemma · Applications · Alternatives and Limits · Perspective. Put an arrow wherever one of them is what makes another possible, and label the arrow with why.

114. What you can do now

Recap

You can prove languages beyond the context-free class, completing the picture for the second level of the hierarchy.

SituationMove
three quantities must matchp of each, enumerate the window positions
a block must repeat in the same orderfour alternating blocks of length p
a known case is one intersection awayclosure with a regular helper
the window keeps landing harmlesslyredesign the string with more blocks
nothing worksthe language may pump anyway — a stronger lemma is needed

Lesson 19 works out the closure properties of this class, including the failures of intersection and complement that this lesson has already leaned on.

Sources

  1. Sipser, Introduction to the Theory of Computation, 3rd ed., Ch. 2.3, Theorem 2.34 (The pumping lemma for context-free languages) — Cengage, 2013.
  2. Hopcroft, Motwani & Ullman, Introduction to Automata Theory, Languages, and Computation, 3rd ed., Ch. 7.2 (The pumping lemma for CFLs) — Pearson, 2007.
  3. Bar-Hillel, Perles & Shamir, 'On formal properties of simple phrase structure grammars', Zeitschrift fur Phonetik 14 — 1961.
  4. Ogden, 'A helpful result for proving inherent ambiguity', Mathematical Systems Theory 2(3) — Springer, 1968.
  5. Every string choice, window case analysis and pumped result in this deck was checked by hand, including the pump-down cases. — Verified 2026-08-08.

Want this taught 1-on-1? Alexander tutors Theory of Computation — $55/session, free consultation.

Book on Wyzant · Text (657) 465-8108