Section 6 · 9 min read
Pumping lemma and closure properties
The pumping lemmas for regular and context-free languages, how to use them correctly, and the closure properties of every language class from regular to recursively enumerable.
On this page
What the pumping lemmas are for
Both pumping lemmas describe a property that every language in a class has. They are used in one direction only: to show that a given language is not in the class. A language that passes the pumping test may still be outside the class, so the lemma can never prove that a language is regular or context-free.
In GATE the lemma itself is rarely asked as a proof. What is asked is the reasoning behind it ("which split is possible", "why does this choice of string work") and, much more often, closure properties, which are the fast route to the same conclusions.
Pumping lemma for regular languages
Statement. If is regular, there is a number (the pumping length) such that every with can be written as where
- for every .
Where it comes from. Take a DFA for with states. Reading the first symbols of visits states, so some state repeats. The part of the input read between the two visits is a loop, . Going round the loop any number of times, including zero, leads to the same state, so acceptance does not change.
Using it as a game
To prove is not regular, play against an opponent:
- The opponent picks . You must handle every , so keep it symbolic.
- You pick a string with . Choose it so that the first symbols are boring, for example all the same letter.
- The opponent picks any split obeying conditions 1 and 2. You must handle every such split.
- You pick so that .
The most common mistake is to choose the split yourself. You do not get to; you only know and .
Pumping down () is often the useful choice, for example when the language says "more 's than 's".
Pumping lemma for context-free languages
Statement. If is context-free, there is such that every with can be written where
- for every .
Where it comes from. A long enough string has a tall parse tree, and on a long root-to-leaf path some variable repeats. The subtree under the upper copy can be substituted for the lower one (pump up) or the lower one for the upper (pump down). and are what the upper copy adds on the left and right.
The key consequence. The window has length at most , so if your string has blocks of length , the window touches at most two adjacent blocks. Pumping can change at most two adjacent counts. This is why (three counts must move together) and (the and blocks are not adjacent) are not CFL.
Ogden's lemma
A stronger version lets you mark at least positions and guarantees that and together contain a marked position. It is needed for a few languages where plain pumping fails, such as some inherently ambiguous examples. GATE does not ask it directly; just know it exists.
Closure properties
This table is the single most useful thing to memorize for this section. Y means closed, N means not closed in general.
| Operation | Regular | DCFL | CFL | Recursive | RE |
|---|---|---|---|---|---|
| Union | Y | N | Y | Y | Y |
| Intersection | Y | N | N | Y | Y |
| Complement | Y | Y | N | Y | N |
| Concatenation | Y | N | Y | Y | Y |
| Kleene star | Y | N | Y | Y | Y |
| Reversal | Y | N | Y | Y | Y |
| Homomorphism | Y | N | Y | N | Y |
| Inverse homomorphism | Y | Y | Y | Y | Y |
| Intersection with a regular language | Y | Y | Y | Y | Y |
| Difference | Y | N | N | Y | N |
Notes on the less obvious entries:
- CFL, intersection: .
- CFL, complement: follows from intersection, because closure under union and complement would give intersection by De Morgan.
- DCFL, complement: a DPDA can be made to always read its whole input, then accepting and rejecting states can be swapped.
- DCFL, union and intersection: fail for the same reason as CFL intersection. and are both DCFL.
- Recursive, homomorphism: an erasing homomorphism can hide the "witness" part of a string, turning a decidable language into an RE-complete one.
- RE, complement: if both and are RE, then is recursive. The halting language is RE and not recursive, so its complement is not RE.
- Infinite union is not a closure property of any of these classes: every language is a union of singletons.
- Subsets: none of the classes is closed under taking subsets. is regular and contains every language.
Mixed-class rules
These come up in "which is necessarily..." questions. Let be regular, a CFL, a DCFL:
- , , are CFL. need not be.
- and are DCFL.
- RE minus recursive is RE; recursive minus RE need not be RE.
Proving non-membership with closure
The pattern: assume is in the class, apply operations the class is closed under, and land on a language known to be outside the class. Contradiction.
Typical moves:
- Intersect with a regular language such as to strip away unwanted strings.
- Complement (only for classes closed under it).
- Apply a homomorphism to rename or delete symbols.
- Use the fact that a unary CFL is regular.
Worked examples
Worked example 1: Pumping down
Show is not regular.
Let be the pumping length. Choose . Any split with puts inside the leading 's, so with . Pump down (): . Since , the number of 's is at most , so it is no longer greater than the number of 's. . So is not regular.
Pumping up would not work here: more 's keeps the string in .
Worked example 2: Growing gaps
Show is not regular.
Choose . Any split has . Pumping once more gives length . Also . So the length lies strictly between two consecutive squares and .
The same idea works for any language whose lengths have unbounded gaps (powers of 2, primes, factorials). Since unary CFLs are regular, these languages are not even context-free.
Worked example 3: Closure instead of pumping
Show is not regular.
If were regular, then would be regular (closure under intersection). But , which is not regular. So is not regular.
Same trick for : intersect with to get .
Worked example 4: CFL pumping on a copy language
Show is not context-free.
First simplify with closure: . If were CFL, so would this be. Now pump .
The window has length at most , so it lies inside one block or spans two adjacent blocks.
- Inside one block: pumping changes one count only, so the two -blocks (or the two -blocks) become unequal.
- Across two adjacent blocks (for example the first -block and the first -block): it changes those counts but not the matching blocks in the second half.
In every case is not of the form . So is not CFL.
Worked example 5: Passing the test is not enough
Let .
It satisfies the regular pumping lemma with :
- If starts with , take = the first . Pumping up keeps with . Pumping down either keeps or removes the only , leaving , which is in the second part.
- If has no , it is ; pump its first symbol and it stays in .
But is not regular: , which is not regular. This is the standard reason the lemma is only a one-way test.
Common traps
- Choosing the split. You choose and ; the opponent chooses and the split.
- Strings shorter than . The lemma says nothing about them; your must have length at least .
- CFL window misuse. can straddle two adjacent blocks; handle that case, not only "inside one block".
- Subset reasoning. " and regular, so is regular" is false.
- CFL intersection. Closed with a regular language, not with another CFL.
- DCFL complement. DCFLs are closed under complement even though CFLs are not.
- Homomorphism and recursive languages. Recursive is the one column in the table that fails homomorphism while RE passes it.
- regular does not mean regular: .
Quick revision
- Regular pumping: , , for all .
- CFL pumping: , , for all .
- Both are necessary conditions only; they prove non-membership.
- Pick strings whose first symbols are uniform; try and .
- CFL window touches at most two adjacent blocks.
- Regular: closed under everything in the table.
- CFL: not closed under intersection, complement, difference.
- DCFL: closed under complement, inverse homomorphism and intersection with regular; little else.
- Recursive: closed under all Boolean operations, not homomorphism.
- RE: closed under union, intersection, concatenation, star, homomorphism; not complement.
- Fastest non-regularity proof is often intersecting with to reach .