Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 44

Proving Non-Context-Free Languages with the Pumping Lemma

Recommended resources

Hello! Let's dive into the practical application of the tool we studied in our last lesson.

In the previous session, we formally defined the Pumping Lemma for Context-Free Languages. We saw that any sufficiently long string w in a CFL can be decomposed into five parts, w = uvxyz, that must satisfy three conditions:

  1. uv^ixy^iz ∈ L for all i ≥ 0 (The pumping condition)
  2. |vy| > 0 (The pumped parts are not both empty)
  3. |vxy| ≤ p (The core pumpable section is of a constrained length)

Today, we'll put this lemma to work. Our goal is to apply the Pumping Lemma to prove that a given language is not context-free, focusing on the classic example L = {aⁿbⁿcⁿ | n ≥ 0}. We will use the lemma as the foundation for a formal proof by contradiction.

1. The Strategy: Proof by Contradiction

The Pumping Lemma states that if a language is context-free, then it must have the pumping property. Logically, this means that if we can show a language does not have the pumping property, then it cannot be context-free.

This leads to a powerful proof technique structured as an adversarial game. Here is the game plan:

  1. Assume the language L you want to test is context-free. This allows you to invoke the Pumping Lemma.
  2. The Pumping Lemma gives you a pumping length p. You have no control over p; it's just some positive integer.
  3. Your task is to choose a specific string w in L such that |w| ≥ p. The choice of w is the most crucial strategic step. A good choice will severely limit the possible ways w can be decomposed.
  4. Now, you must consider every possible decomposition of w into uvxyz that satisfies the lemma's constraints (|vy| > 0 and |vxy| ≤ p). This is where you play defense against all of the adversary's moves.
  5. For each and every case, you must find a single value of i (usually i=0 or i=2) such that the "pumped" string uv^ixy^iz is no longer in L.
  6. If you can successfully do this for all possible decompositions, you have shown that w cannot be pumped. This contradicts the initial assumption, proving that L is not context-free.

This process is systematic. Your experience in designing robust systems that handle all possible inputs and edge cases is analogous to this proof structure, where you must show that the argument holds for every valid decomposition.

The Pumping Lemma for Context-Free Languages

These presentation slides from Korea University provide a concise, formal summary of this 5-step proof methodology. It's a great reference for the logical structure we'll be using.

Please review slide 14, titled "Proving Languages are Not Context-Free". It lays out the five steps for using the Pumping Lemma to prove a language is not context-free. Pay attention to the logical negation of the lemma's properties.


2. Applying the Lemma: L = {aⁿbⁿcⁿ | n ≥ 0}

Let's apply this strategy to prove that L = {aⁿbⁿcⁿ | n ≥ 0} is not a CFL. This language requires matching counts across three different symbols, which, intuitively, feels like a task that a single stack cannot handle. The Pumping Lemma allows us to prove this intuition formally.

The following video provides an excellent, step-by-step walkthrough of this exact proof.

Pumping Lemma for Context-Free Languages: Four Examples

This video from Easy Theory demonstrates how to apply the pumping lemma to prove that aⁿbⁿcⁿ is not context-free. The presenter does a great job of explaining the choice of the string w and systematically analyzing the possible cases for the decomposition.

Watch the segment from 00:00 to 14:06. Focus on: The choice of the string w = a^p b^p c^p. The analysis of the possible locations of the vxy substring. How, in every case, pumping up (i=2) leads to a string that violates the language's rule.


3. Deconstructing the Proof

Let's formalize the arguments from the video.

1. Assumption: Assume L = {aⁿbⁿcⁿ | n ≥ 0} is a context-free language.
2. Pumping Length: By the Pumping Lemma, there exists a pumping length p for L.
3. String Choice: We choose the string w = a^p b^p c^p. This string is in L and its length is 3p, which is greater than or equal to p.
4. Case Analysis of the Decomposition w = uvxyz:
The lemma guarantees that |vxy| ≤ p. This is the key constraint. Our string w looks like this:

aaaa...aaaa bbbb...bbbb cccc...cccc
(p times)       (p times)       (p times)

The substring vxy must be "pulled" from w and can have a maximum length of p. This means vxy cannot span all three sections of symbols. For example, it can't contain both an a and a c, because the first c is at position 2p+1 and the first a is at position 1. The distance between them is 2p, which is greater than the max length of vxy.

This leaves us with the following exhaustive cases for the content of v and y:

  • Case A: v and y contain only a's.
    The substring vxy lies entirely within the a^p block. Since |vy| > 0, at least one of v or y is a non-empty string of a's. If we pump up to i=2, the string becomes uv^2xy^2z. We have added at least one a but no b's or c's. The resulting string has more a's than b's and c's, so it is not in L. Contradiction.

  • Case B: v and y contain only b's.
    Similarly, vxy lies in the b^p block. Pumping up to i=2 adds b's but no a's or c's. The counts are no longer equal. Contradiction.

  • Case C: v and y contain only c's.
    Similarly, vxy lies in the c^p block. Pumping up to i=2 adds c's but no a's or b's. The counts are unequal. Contradiction.

  • Case D: v and y contain a's and b's.
    The vxy substring straddles the boundary between a's and b's. v may contain a's, and y may contain b's. Since |vy| > 0, we add at least one a or one b (or both) when pumping up to i=2. However, we add zero c's because the c block is too far away. The number of c's will no longer match the number of a's and/or b's. Contradiction.

  • Case E: v and y contain b's and c's.
    The vxy substring straddles the boundary between b's and c's. Pumping up to i=2 adds b's and/or c's, but no a's. The number of a's will not match the others. Contradiction.

5. Conclusion:
In every single possible decomposition of w that respects the Pumping Lemma's conditions, we were able to find a value of i (i=2 in all our cases) that produces a string not in L. This contradicts the lemma. Therefore, our initial assumption must be false.

L = {aⁿbⁿcⁿ | n ≥ 0} is not a context-free language.

Test your understanding!

In the proof above, we always chose to pump up (i=2). Could we have used pumping down (i=0) in any of the cases?

Show answer

Yes. Pumping down would work just as well in every case. For instance, in Case A, where v and y contain only a's, the string uv^0xy^0z = uxz would have fewer a's than p, while still having p b's and p c's. The counts would be unequal, leading to the same contradiction. The choice of i is strategic; as long as you can find one value of i that breaks the language's rules for any given case, you succeed.


4. A More Complex Example: L = {ww | w ∈ {0,1}*}

Let's briefly look at another classic non-CFL: the language of repeated strings. Proving this requires a more clever choice of w. A naive choice like w = 0^p 0^p would fail because an adversary could choose v in the first half and y in the second half, allowing it to be pumped.

A better choice is w = 0^p 1^p 0^p 1^p. Here, the full string is the first half (0^p 1^p) repeated. The substring vxy has length at most p.

The case analysis becomes:

  1. vxy is entirely in the first 0^p 1^p half. Pumping changes the first half but leaves the second half untouched. The resulting string is no longer of the form ww.
  2. vxy is entirely in the second 0^p 1^p half. Symmetrically, pumping changes the second half but not the first.
  3. vxy straddles the midpoint. This is the most interesting case. The substring vxy must be some part of 1^p 0^p. Pumping up (i=2) adds 1s to the first half and/or 0s to the second. This changes the content of the two halves, so they are no longer identical.

This example shows how critical the choice of string w is to successfully cornering the "adversary" and proving the language is not context-free.


Conclusion

Today we transformed the Pumping Lemma from an abstract theorem into a concrete tool for proving that languages are not context-free.

Key Takeaways:

  • The Pumping Lemma for CFLs is used in a proof by contradiction.
  • The core of the proof is a systematic case analysis that must cover all possible ways a chosen string w can be decomposed according to the lemma's rules.
  • The strategy involves:
    1. Assuming the language is a CFL.
    2. Letting p be the pumping length.
    3. Choosing a clever string w of length at least p.
    4. Showing that for every valid decomposition uvxyz, pumping with some i (often 0 or 2) creates a string not in the language.
  • We successfully proved that L = {aⁿbⁿcⁿ | n ≥ 0} is not a context-free language.

Preview of the Next Lesson:
Now that we can identify languages that are not context-free, we can explore the "algebra" of this language class. In the next lesson, we will investigate the closure properties of CFLs. For example, are CFLs closed under operations like union, concatenation, intersection, and complement? Knowing that aⁿbⁿcⁿ is not a CFL will be a key piece of evidence in answering some of these questions.