MIT 18.404 — Lecture 3
Regular Expressions, The Pumping Lemma
§ Generalized NFAs
Recall that we proved in Lecture 2 the following theorem by introducing a new kind of FA (the NFA).
Theorem. (Regularness) Every regular expression is a regular language.
In this lecture, we'll introduce another kind of FA—the generalized NFA (GNFA)—to prove the reverse direction.
Theorem. (Regularness) Every regular language is a regular expression.
Definition. A generalized NFA is an NFA in which edges may be labeled with any regular expression (not just atoms!). We say a GNFA is good if it satisfies the following properties:
There is a single accept state distinct from the start state.
There exists a transition between every pair of states and a self-loop at every state (possibly with label ) …
… except the start state must have indegree zero …
… and the accept state must have outdegree zero.
Evidently, every GNFA can be easily translated into a good GNFA by adding edges and some additional states.

Expectedly, good GNFAs are equally as representative of regular languages as ordinary NFAs (or DFAs) are.
Theorem. (GNFA Implies NFA) A language is recognized by some NFA if and only if is recognized by some GNFA.
Proof: The NFA GNFA direction is trivial, so we only show the GNFA NFA direction.
Simply apply the fact from Lecture 2 that every regular expression is the language of some NFA. That is, for each edge with regular expression , replace that edge with the NFA whose language is , linking into and out of the NFA using -edges.

If this new NFA accepts a string , then the original GNFA must also accept ; to see why, consider breaking up the computation path of into sub-paths where and are states of the original GNFA, and so…
§ Regular Languages are Regular Expressions
We now prove the following theorem.
Theorem. (GNFA Regularness) Every good GNFA regular language is a regular expression.
Proof: Proof by induction on the number of states. The base case is trivial.
For the inductive step, remove a state from the GNFA that is not the start or accept state.

Furthermore, for every ordered pair of states , update the label of the edge as shown above. This leaves the language of unchanged, so we can induct down successfully.
Remark. CYU: Where, in the proof, does the “goodness” of the GNFA get used?
And of course, by combining this theorem with the “GNFA Implies NFA” theorem preceding it, we get:
Theorem. (DFA Regularness) Every (DFA) regular language is a regular expression.
§ Proving Nonregularity
All of our work so far has gone toward proving the regularity of languages. What about nonregularity?
Example. Consider the following languages with alphabet .
As we'll see, is nonregular. But is regular—consider a five-state FA that tracks .
Theorem. (Pumping Lemma) For every regular language , there must be some pumping length such that:
For all with , we may write with such that and for all .
Proof: The pumping length of is the number of states in the FA .
Consider some string with . Suppose it begins at and ends at through some path . Since , the path must land on some state twice. Say this happens for the first time at state .

Then taking just works.
Remark. All finite languages are regular. And this is trivially consistent with the pumping lemma—why?
Problem. Prove that the language is not regular.
Solution: Argue by contradiction. If the pumping length were , then would contradict the pumping lemma.
Problem. Prove that the language is not regular.
Solution: The point is that if is regular, then so is (by closure). Contradiction by the previous problem.
Unfortunately, there exist nonregular languages that satisfy the pumping lemma; take with pumping length , say.