The Timpson Lyceum · Computation Theory
Lecture 7 (Computation Theory) Regular Expressions and the Pumping Lemma
Overview
This lecture closes out regular expressions and opens the study of non-regular languages. First we prove the converse of last time's result: every regular language is generated by some regular expression. The proof introduces a temporary tool, the generalized NFA (GNFA), and a "state-ripping" procedure that collapses any NFA down to a two-state machine whose single edge is the desired regular expression. This completes the chain showing regular expressions, NFAs, and DFAs are all logically equivalent. We then turn to the pumping lemma, the standard tool for proving a language is not regular, and use it to prove that is non-regular.
Key Concepts
Goal of the section. Last time: if is a regular expression, then is regular. This time: the converse — if is regular, some regular expression generates it. Together these make regular expressions equivalent in power to NFAs and DFAs.
Regular expression (recap). Built from three base cases — a single symbol (shorthand for the set ), the empty string (the set ), and the empty set — closed under union, concatenation, and star. Every symbol stands for a one-element set; all operations are set operations.
Generalized NFA (GNFA). An NFA whose edges are labeled with regular expressions rather than single symbols. By convention a GNFA has:
- exactly one accept state, distinct from the start state;
- an arrow from every state (except the accept state) to every state (except the start state) — so the start state has no incoming edges and the accept state has no outgoing edges.
Formal definition. Let be the set of all regular expressions over . A GNFA is a 5-tuple where the transition function
takes a pair of states (from-state, to-state) and outputs the regular expression labeling that edge. Unlike a DFA/NFA, the output is the edge label, not the next state.
Converting an NFA to a GNFA. Add a new start state with an -arrow into the old start, and a new single accept state with -arrows from all old accept states. Then fill in every missing edge with the label (an -edge can never be taken, so the language is unchanged). Every label is now a regular expression.
When a GNFA accepts. accepts if can be split as and there is a sequence of states with , , and each piece — i.e. each piece is generated by the regular expression on the edge it traverses.
State-ripping. To remove an interior state , for every pair (any non-accept state) and (any non-start state) update the edge to account for paths that detoured through :
where , , , and (the old direct edge). Because -labels simplify away (, ), many of these collapse to a single term.
Conversion theorem. If is regular, some regular expression generates it. Proof idea: take an NFA for , convert to a GNFA with states. If , the single edge's label satisfies . If , rip out any interior state to get an equivalent with one fewer state, and repeat. Since is finite, ripping terminates at , leaving a regular expression with .
Pumping lemma (statement). If is regular, there is a pumping length (you may take = number of states in a DFA for ) such that every with can be written with:
- already, and for all , ;
- (the loop reads at least one symbol);
- (the loop occurs within the first symbols).
Why it holds. Reading symbols visits states; with only states some state repeats, forcing a loop. Let be read up to the first visit of , the loop , and the rest. Traversing the loop times (or skipping it, ) keeps the string in the language.
Using it (contrapositive). To prove is not regular, show lacks the pumping property: for every , there exists a string with such that for every split satisfying and , some makes .
Worked Example
Claim. is not regular.
Assume for contradiction is regular, so the pumping lemma applies with some pumping length . Choose the string , which lies in and has . The lemma gives a split with and . Since is the first symbols of and those are all s, both and consist only of s, so with . Pump up with :
This string has zeros but only ones, and since the counts differ, so . But the pumping lemma guaranteed — a contradiction. Hence the assumption fails and is not regular.
Summary
- Every regular language is generated by some regular expression — the converse needed to make regular expressions, NFAs, and DFAs all equivalent.
- The proof uses a GNFA: an NFA with regular-expression edge labels, one accept state, and edges between all permitted state pairs; its transition function maps a pair of states to a regular expression.
- State-ripping removes interior states one at a time via , shrinking any GNFA to two states whose single edge is the regular expression for the language.
- The pumping lemma says long strings () in a regular language contain a loop and split as with , , and for all .
- It holds because reading symbols forces a repeated state (a loop) in a -state machine, which can be traversed any number of times.
- To prove non-regularity, apply the contrapositive: pick a hard string and show no valid split survives pumping — as with , where pumping the all-zero loop breaks the equal-count condition.