Theory of Computation & Computer Graphics β Introduction to Finite Automata, NEC licence examination syllabus (Nepal Engineering Council).
Pumping Lemma for Regular Language
The standard tool for proving that a language is not regular β and the one students most often misuse.
π Where this lives: The pumping lemma is the formal answer to a question every programmer eventually hits: "why can't I just use a regular expression for this?" When someone tries to validate nested brackets, match HTML tags, or check that a configuration file's sections are balanced, they run into a wall β and this lemma is the proof that the wall is real rather than a limitation of their cleverness. Knowing it turns "regex isn't working for this" into "this language is provably not regular, so I need a parser". Search "pumping lemma proving language not regular".
Statement and the logic of its use
THE PUMPING LEMMA FOR REGULAR LANGUAGES:
IF L is a regular language,
THEN there exists a constant p β₯ 1 (the PUMPING LENGTH) such
that EVERY string w β L with |w| β₯ p can be written as
w = x y z
satisfying ALL THREE conditions:
(1) |y| β₯ 1 y is NOT empty
(2) |xy| β€ p x and y occur within the first p
symbols
(3) x yβ± z β L for ALL i β₯ 0
ββ WHY IT IS TRUE β THE PIGEONHOLE ARGUMENT ββββββββββββββββ
Let the minimal DFA for L have p states. Take any w β L with
|w| β₯ p. Reading w visits |w| + 1 states, and the first p+1 of
those are drawn from only p distinct states β SO BY THE
PIGEONHOLE PRINCIPLE SOME STATE IS VISITED TWICE within the
first p symbols.
Let x be the prefix read before the first visit, y the
portion read between the two visits (so y β Ξ΅, giving
condition 1, and both visits are within the first p symbols,
giving condition 2), and z the remainder.
READING y TAKES THE MACHINE FROM A STATE BACK TO ITSELF β IT
IS A LOOP. So the loop can be traversed any number of times,
including zero, and the machine still ends where it did.
Hence x yβ± z is accepted for every i β₯ 0, which is condition
3.
THAT IS THE WHOLE PROOF, AND IT IS WORTH REMEMBERING AS AN
ARGUMENT RATHER THAN A FORMULA: a finite machine reading a
long enough string must repeat a state, and a repeated state
is a loop that can be pumped.
ββ HOW IT IS USED β PROOF BY CONTRADICTION βββββββββββββββββ
THE LEMMA SAYS "REGULAR βΉ PUMPABLE". Its contrapositive is
"NOT PUMPABLE βΉ NOT REGULAR", and that is how it is applied.
THE PROOF IS A GAME AGAINST AN ADVERSARY, and framing it that
way prevents the standard errors:
1. THE ADVERSARY chooses p. You know nothing about it, so
your argument must work for EVERY p.
2. YOU choose w β L with |w| β₯ p. THIS IS YOUR ONLY FREE
CHOICE AND THE WHOLE PROOF DEPENDS ON MAKING IT WELL.
3. THE ADVERSARY splits w = xyz however they like, subject
to |y| β₯ 1 and |xy| β€ p. You must handle EVERY legal
split.
4. YOU choose i and show x yβ± z β L.
THE TWO ERRORS THAT INVALIDATE A PROOF:
Β· CHOOSING THE SPLIT YOURSELF. Writing "let y = a" is wrong
β the adversary chooses y, so you must argue about all
possible y. THE GOOD NEWS IS THAT CONDITION (2) USUALLY
CONSTRAINS THE ADVERSARY SO SEVERELY THAT ALL SPLITS LOOK
THE SAME, which is exactly what a well-chosen w achieves.
Β· CHOOSING w BADLY. A string that can be pumped proves
nothing, even if the language is genuinely non-regular.
ββ THE STANDARD WORKED PROOF βββββββββββββββββββββββββββββββ
CLAIM: L = { aβΏbβΏ : n β₯ 0 } is NOT regular.
PROOF. Suppose L is regular. Let p be the pumping length.
CHOOSE w = aα΅ bα΅.
Then w β L and |w| = 2p β₯ p, so the lemma applies.
By condition (2), |xy| β€ p. SINCE THE FIRST p SYMBOLS OF w
ARE ALL a's, BOTH x AND y CONSIST ENTIRELY OF a's.
So y = aα΅ for some k β₯ 1, by condition (1).
TAKE i = 2. Then
x yΒ² z = a^(p+k) bα΅
This has p + k a's and p b's, and k β₯ 1, so the counts
DIFFER. Therefore x yΒ² z β L, contradicting condition (3).
Hence L is not regular. β
CONCRETELY, with p = 3 and k = 1: w = aaabbb, and pumping
gives aaaabbb β four a's and three b's, which is not in L.
i = 0 works equally well, giving aabbb.
NOTICE WHAT MADE THE CHOICE OF w GOOD: putting all the a's
first meant condition (2) FORCED y into the a-block,
eliminating every other case. A LAZIER CHOICE SUCH AS
w = (ab)α΅ WOULD HAVE LEFT THE ADVERSARY FREE TO PUT y
ANYWHERE and the proof would have been far messier.
ββ MORE NON-REGULAR LANGUAGES AND THE w TO CHOOSE ββββββββββ
{ aβΏbβΏ } w = aα΅bα΅
{ ww : w β Ξ£* } w = aα΅baα΅b
{ aβΏbα΅ : n > m } w = a^(p+1)bα΅
palindromes over {a,b} w = aα΅baα΅
{ aβΏ : n is prime } w = a^q for a prime q > p
{ aβΏ : n is a perfect square } w = a^(pΒ²)
{ aβΏbα΅cβΏβΊα΅ } w = aα΅bα΅cΒ²α΅
balanced parentheses w = (α΅)α΅
FOR { aβΏ : n PRIME } the argument needs one extra step: after
pumping, the length becomes q + (iβ1)k, and CHOOSING
i = q + 1 GIVES LENGTH q + qk = q(1 + k), which is composite
since both factors exceed 1. A NEAT TRICK WORTH REMEMBERING.
The limits of the lemma, and the alternative
ββ THE CRITICAL LOGICAL POINT ββββββββββββββββββββββββββββββ
THE PUMPING LEMMA IS A NECESSARY CONDITION, NOT A SUFFICIENT
ONE.
REGULAR βΉ PUMPABLE.
PUMPABLE βΉ REGULAR IS **FALSE**.
So the lemma can PROVE a language is NOT regular, and can
NEVER PROVE that one IS regular. A student who "verifies the
pumping lemma holds" and concludes the language is regular has
committed the converse error.
A CONCRETE COUNTEREXAMPLE, worth knowing because it is the
standard one:
L = { aβ±bΚ²cΚ² : i β₯ 1, j β₯ 0 } βͺ { bΚ²cα΅ : j, k β₯ 0 }
THIS LANGUAGE SATISFIES THE PUMPING LEMMA AND IS NOT
REGULAR, and the mechanism is worth following because it
shows exactly how the lemma can be evaded.
TAKE y TO BE A SINGLE LEADING SYMBOL.
Β· If w = aβ±bΚ²cΚ² with i β₯ 1, let y be one a. Pumping UP
gives a^(i+1)bΚ²cΚ², still in the first set since j = j is
unaffected. Pumping DOWN to i = 0 gives bΚ²cΚ² β WHICH
LANDS IN THE SECOND SET b*c*, and is therefore still in
L even though nothing now constrains the counts.
Β· If w β b*c*, pumping the first symbol keeps it in b*c*.
SO EVERY STRING IN L CAN BE PUMPED, and the lemma is
satisfied.
THE SECOND SET IS A TRAPDOOR: it absorbs exactly the strings
that pumping would otherwise push out of the language.
YET L IS NOT REGULAR, which Myhill-Nerode shows at once: the
strings ab, abb, abbb, β¦ are pairwise distinguishable,
because abΚ² followed by cΚ² is in L while abΚ² followed by
c^(j+1) is not. Infinitely many equivalence classes, hence
no DFA.
CHECK IT CONCRETELY: abc β L and abcc β L; abbcc β L and
abbccc β L.
THE RELIABLE ALTERNATIVE IS THE MYHILL-NERODE THEOREM:
Exhibit an INFINITE SET of strings that are PAIRWISE
DISTINGUISHABLE β for each pair x, y there is a z with
exactly one of xz, yz in L. Then L has infinitely many
equivalence classes and CANNOT be regular.
FOR { aβΏbβΏ }: take { a, aa, aaa, β¦ }. For i β j, the string
bβ± distinguishes aβ± from aΚ², since aβ±bβ± β L but aΚ²bβ± β L.
Infinitely many classes, so not regular.
MYHILL-NERODE IS BOTH NECESSARY AND SUFFICIENT, so it can
prove regularity as well as non-regularity β which is why it
is the stronger tool, even though the pumping lemma is the
one usually taught first.
ββ PRACTICAL GUIDANCE FOR THE EXAM βββββββββββββββββββββββββ
THE TEMPLATE, which should be written out in full:
1. "Assume, for contradiction, that L is regular."
2. "Let p be the pumping length given by the lemma."
3. "Consider w = β¦, which is in L and has |w| β₯ p."
4. "By condition (2), |xy| β€ p, so y consists only of β¦"
β THIS IS THE STEP THAT EARNS THE MARKS; state explicitly
why the constraint pins down y.
5. "Write y = β¦ with k β₯ 1 by condition (1)."
6. "Take i = β¦. Then xyβ±z = β¦, which is not in L because β¦"
7. "This contradicts condition (3), so L is not regular." β
CHOOSING w β THE PRACTICAL RULES:
Β· make it long enough that |w| β₯ p is automatic
Β· ARRANGE IT SO THE FIRST p SYMBOLS ARE UNIFORM, so
condition (2) forces y into one block
Β· the standard choice is the "extreme" member of the
language for the given p
CHOOSING i:
Β· i = 2 (pumping up) works in most counting arguments
Β· i = 0 (pumping DOWN) is often cleaner when the language
requires a MINIMUM count, since deleting y breaks it
immediately
Β· for arithmetic properties such as primality, choose i to
force a composite or otherwise disallowed value
ββ THE PLACE OF THE RESULT βββββββββββββββββββββββββββββββββ
The pumping lemma completes the picture of regular languages
begun in this section:
Β· FINITE AUTOMATA say what CAN be recognised.
Β· REGULAR EXPRESSIONS give an equivalent notation.
Β· MINIMIZATION gives a canonical form.
Β· THE PUMPING LEMMA MARKS THE BOUNDARY β it tells us where
the class ENDS.
AND THE BOUNDARY IS EXACTLY WHERE UNBOUNDED MEMORY BECOMES
NECESSARY, which is precisely the capability added by the
stack of a pushdown automaton in the next section. THERE IS A
CORRESPONDING PUMPING LEMMA FOR CONTEXT-FREE LANGUAGES, with
the string split into FIVE parts instead of three, marking
that class's boundary in the same way.
Frame the proof as a game and the standard errors disappear: the adversary picks p and picks the split; you pick only w and i. Writing "let y = a" is the commonest invalid step, because choosing the split is not yours to do β a well-chosen w instead makes condition (2) force the split for you.
π Go further: The pumping lemma is not the strongest tool available, and it is worth knowing why. MyhillβNerode is both necessary and sufficient β it characterises regularity exactly, so it can prove a language is regular as well as that it is not, and it never fails on a genuinely non-regular language. The pumping lemma can fail: there exist non-regular languages that satisfy it, so a failed pumping argument proves nothing either way. It is taught first because the proof technique is mechanical and the intuition (a loop can be repeated) is vivid, but for a language where pumping proves stubborn, switching to distinguishable-strings is usually the faster route. Search "Myhill-Nerode versus pumping lemma non-regularity proof".
π‘ Exam angle: state the lemma with all three conditions and give the pigeonhole justification β a machine with p states reading p or more symbols must revisit a state, and that repeat is a pumpable loop. The guaranteed question is a proof that a given language is not regular: use the seven-step template, and make the key step explicit β "by |xy| β€ p, y lies entirely within the a's". Choose w so the first p symbols are uniform, and pick i = 2 or i = 0 as convenient. State clearly that the lemma is necessary but not sufficient and that MyhillβNerode is the complete characterisation.
Syllabus points
Statement of the lemma
Proving a language is not regular
Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.