The Timpson Lyceum seal

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 {0n1n:n≥0}\{0^n 1^n : n \ge 0\} is non-regular.

Key Concepts

Goal of the section. Last time: if RR is a regular expression, then L(R)L(R) is regular. This time: the converse — if AA is regular, some regular expression RR 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 aa (shorthand for the set {a}\{a\}), the empty string ε\varepsilon (the set {ε}\{\varepsilon\}), and the empty set ∅\emptyset — 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:

Formal definition. Let R\mathcal{R} be the set of all regular expressions over Σ\Sigma. A GNFA is a 5-tuple G=(Q,Σ,δ,qstart,qaccept)G = (Q, \Sigma, \delta, q_{\text{start}}, q_{\text{accept}}) where the transition function

δ:(Q∖{qaccept})×(Q∖{qstart})→R\delta : (Q \setminus \{q_{\text{accept}}\}) \times (Q \setminus \{q_{\text{start}}\}) \to \mathcal{R}

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 ε\varepsilon-arrow into the old start, and a new single accept state with ε\varepsilon-arrows from all old accept states. Then fill in every missing edge with the label ∅\emptyset (an ∅\emptyset-edge can never be taken, so the language is unchanged). Every label is now a regular expression.

When a GNFA accepts. GG accepts ww if ww can be split as w=w1w2⋯wkw = w_1 w_2 \cdots w_k and there is a sequence of states r0,r1,…,rkr_0, r_1, \ldots, r_k with r0=qstartr_0 = q_{\text{start}}, rk=qacceptr_k = q_{\text{accept}}, and each piece wi∈L(δ(ri−1,ri))w_i \in L\big(\delta(r_{i-1}, r_i)\big) — i.e. each piece is generated by the regular expression on the edge it traverses.

State-ripping. To remove an interior state qripq_{\text{rip}}, for every pair qiq_i (any non-accept state) and qjq_j (any non-start state) update the edge qi→qjq_i \to q_j to account for paths that detoured through qripq_{\text{rip}}:

δ′(qi,qj)=R1R2∗R3∪R4,\delta'(q_i, q_j) = R_1 R_2^{*} R_3 \cup R_4,

where R1=δ(qi,qrip)R_1 = \delta(q_i, q_{\text{rip}}), R2=δ(qrip,qrip)R_2 = \delta(q_{\text{rip}}, q_{\text{rip}}), R3=δ(qrip,qj)R_3 = \delta(q_{\text{rip}}, q_j), and R4=δ(qi,qj)R_4 = \delta(q_i, q_j) (the old direct edge). Because ∅\emptyset-labels simplify away (∅R=∅\emptyset R = \emptyset, R∪∅=RR \cup \emptyset = R), many of these collapse to a single term.

Conversion theorem. If AA is regular, some regular expression generates it. Proof idea: take an NFA for AA, convert to a GNFA GG with kk states. If k=2k = 2, the single edge's label RR satisfies L(R)=AL(R) = A. If k>2k > 2, rip out any interior state to get an equivalent G′G' with one fewer state, and repeat. Since GG is finite, ripping terminates at k=2k = 2, leaving a regular expression RR with L(R)=AL(R) = A.

Pumping lemma (statement). If AA is regular, there is a pumping length pp (you may take pp = number of states in a DFA for AA) such that every s∈As \in A with ∣s∣≥p|s| \ge p can be written s=xyzs = xyz with:

  1. xyz∈Axy z \in A already, and for all i≥0i \ge 0, xyiz∈Ax y^{i} z \in A;
  2. ∣y∣≥1|y| \ge 1 (the loop reads at least one symbol);
  3. ∣xy∣≤p|xy| \le p (the loop occurs within the first pp symbols).

Why it holds. Reading pp symbols visits p+1p+1 states; with only pp states some state qrq_r repeats, forcing a loop. Let xx be read up to the first visit of qrq_r, yy the loop qr→qrq_r \to q_r, and zz the rest. Traversing the loop ii times (or skipping it, i=0i=0) keeps the string in the language.

Using it (contrapositive). To prove AA is not regular, show AA lacks the pumping property: for every pp, there exists a string s∈As \in A with ∣s∣≥p|s| \ge p such that for every split s=xyzs = xyz satisfying ∣xy∣≤p|xy| \le p and ∣y∣≥1|y| \ge 1, some ii makes xyiz∉Ax y^{i} z \notin A.

Worked Example

Claim. A={0n1n:n≥0}A = \{0^{n} 1^{n} : n \ge 0\} is not regular.

Assume for contradiction AA is regular, so the pumping lemma applies with some pumping length pp. Choose the string s=0p1ps = 0^{p} 1^{p}, which lies in AA and has ∣s∣=2p≥p|s| = 2p \ge p. The lemma gives a split s=xyzs = xyz with ∣xy∣≤p|xy| \le p and ∣y∣≥1|y| \ge 1. Since xyxy is the first ≤p\le p symbols of ss and those are all 00s, both xx and yy consist only of 00s, so y=0my = 0^{m} with m≥1m \ge 1. Pump up with i=2i = 2:

x yi z∈?A,with x=0a,  y=0m (m≥1),  z=0 p−a−m1px y2 z=0a (0m)2 0 p−a−m 1p=0 p+m 1p.\begin{aligned} x\,y^{i}\,z &\overset{?}{\in} A, \qquad \text{with } x = 0^{a},\; y = 0^{m}\ (m \ge 1),\; z = 0^{\,p-a-m}1^{p} \\ x\,y^{2}\,z &= 0^{a}\,(0^{m})^{2}\,0^{\,p-a-m}\,1^{p} = 0^{\,p+m}\,1^{p}. \end{aligned}

This string has p+mp+m zeros but only pp ones, and since m≥1m \ge 1 the counts differ, so 0p+m1p∉A0^{p+m}1^{p} \notin A. But the pumping lemma guaranteed xy2z∈Ax y^{2} z \in A — a contradiction. Hence the assumption fails and AA is not regular. ■\blacksquare

Summary