Consider the following non-deterministic finite automaton (NFA):

NFA with two states

From formal language theory, we know that NFAs are equivalent to regular expressions, in the sense that for every NFA there is a regular expression that recognizes the same set of strings as the NFA. So, what is an equivalent regular expression for the NFA above?

In this post, I’d like to share a rather peculiar method to answer such questions by solving a system of linear equations over regular expressions1. Then, in order to justify this method rigorously, I’ll discuss two different approaches to put an algebraic structure on regular expressions—namely, Kleene algebras and non-commutative power series.

A suspicious question

To the question, let r0r_0 be a regular expression that matches strings that end in state Q0Q_0 when you run them through the automaton, and similarly let r1r_1 be a regular expression that matches strings ending in state Q1Q_1. Although we don’t know what r0r_0 and r1r_1 are yet—if we did, we’d be done!—we can write down some constraints that they ought to satisfy. For instance, from the NFA diagram, the only way to get to state Q0Q_0 is if we haven’t seen any characters yet (an empty string), or if we were previously in state Q1Q_1 and saw the character bb. In other words, the regular expression r0r_0 should match either the empty string, or r1r_1 followed by the character bb.

Let’s now agree on two conventions for writing regular expressions: instead of using | to denote alternation as in r1∣r2r_1 |r_2, we will instead write r1+r2r_1 + r_2, and additionally we’ll use 1\mathbf{1} to denote the regular expression matching the empty string. We’ll also agree that two regular expressions are equal if they match the same set of strings. Using these strange conventions, we get

r0=1+r1b(1) r_0 = \mathbf{1} + r_1 b \tag{1}

which says that r0r_0 matches either the empty string, or r1r_1 followed by the character bb, as required. Similarly, for r1r_1, we have the equation

r1=r1a+r0a.(2) r_1 = r_1 a + r_0 a. \tag{2}

We now throw caution to the wind completely and attempt to solve these equations algebraically, ignoring that we haven’t the faintest clue what manipulations on these “regular expression equations” are legal or what laws they obey, if any.

By manipulating equation (2), we get

r1−r1a=r0a  ⟹  r1(1−a)=r0a  ⟹  r1=r0a(1−a)−1. r_1 - r_1 a = r_0 a \implies r_1(\mathbf{1} - a) = r_0 a \implies r_1 = r_0 a ({\mathbf{1} - a})^{-1}.

Everyone and their mother knows that (1−a)−1(\mathbf{1} - a)^{-1} is just the sum of the infinite geometric series 1+a+a2+⋯\mathbf{1} + a + a^2 + \cdots. Alas, we can’t have a regular expression of infinite length, but recalling that ++ means alternation, the expression 1+a+a2+⋯\mathbf{1} + a + a^2 + \cdots seems like it matches all the strings that are the character aa repeated. But that’s just the regular expression a∗a^*! So:

r1=r0aa∗.(3) r_1 = r_0 a a^*. \tag{3}

Now substitute (3) into (1) to get r0=1+r0aa∗br_0 = \mathbf{1} + r_0 a a^* b. By applying our questionable geometric series trick again,

r0=(aa∗b)∗. r_0 = (a a^* b)^*.

Substituting into (3) yields

r1=(aa∗b)∗aa∗ r_1 = \boxed{(a a^* b)^* a a^*}

and since Q1Q_1 is the only accepting state of the automaton, this regexp should match exactly the strings that are accepted by the NFA. And it truly does! This is the right answer to the original problem (!)

What the hell just happened?


Somewhat surprisingly, it turns out that this method does work in general! However, to understand what’s going on beneath the surface, we clearly first need to put some kind of algebraic structure on regular expressions that allows us to manipulate them formally. The goal of the rest of this post is to build up to two sensible algebraic interpretations of regular expressions.

Regular expressions revisited

To start, we should clarify what we mean by a regular expression: only basic features such as sequencing, alternation, and repetition (∗*) are permitted; fancy stuff like capturing groups, backreferences, and the like are all out of scope. Formally:

Definition (regular expression). A regular expression (regexp) is a recursive datatype given by one of the following cases:

  • 1\mathbf{1}, matching the empty string
  • a literal symbol c∈Σc \in \Sigma, where Σ\Sigma is a fixed alphabet of valid symbols
  • a sequence r1⋅r2r_1 \cdot r_2 of two smaller regexps r1,r2r_1, r_2; often we will omit the ⋅\cdot symbol and just juxtapose the regexps
  • an alternation r1+r2r_1 + r_2
  • or a repetition r∗r^*.

(There’s in fact one more case, which we’ll get to later—in particular there is also such as a thing as 0\mathbf{0}; see the first paragraph of the next section.)

We declare two regexps to be equal when they match the same set of strings. Formally, we define recursively a function L(r)\mathcal{L}(r) that returns the set of strings that rr matches: L(1)={ϵ}\mathcal{L}(\mathbf{1}) = \{\epsilon\}, L(r1+r2)=L(r1)∪L(r2)\mathcal{L}(r_1 + r_2) = \mathcal{L}(r_1) \cup \mathcal{L(r_2)}, etc. (What should the definition for L(r1⋅r2)\mathcal{L}(r_1 \cdot r_2) be?2) Two regexps are then equal if L(r1)=L(r2)\mathcal{L}(r_1) = \mathcal{L}(r_2).

As you have probably inferred, the object 1\mathbf{1} and the operations ++, ⋅\cdot behave somewhat like their real number counterparts. Here’s a non-exhaustive list of nice properties:

  • addition is commutative: a+b=b+aa + b = b + a, since both match either bb or aa.
  • 1\mathbf{1} is the identity with respect to multiplication: 1⋅a=a\mathbf{1} \cdot a = a, since the left side means “match 1\mathbf{1}, then match aa”, and 1\mathbf{1} matches the empty string.
  • multiplication distributes over a sum: a⋅(b+c)=ab+aca\cdot (b + c) = ab + ac, since the left side means “match aa, then either bb or cc, which is the same as matching either abab or acac”.

There are some oddities, of course. For instance:

  • everything is idempotent with respect to ++: we have r+r=rr + r = r for all regexps rr.
  • we do not have multiplicative inverses in general.3
  • multiplication is not commutative: in general r1⋅r2≠r2⋅r1r_1 \cdot r_2 \ne r_2 \cdot r_1, since r1⋅r2r_1 \cdot r_2 means to match r1r_1 followed by r2r_2 and the order matters.

Rings, semirings, and Kleene algebras

Perhaps you suspect at this point that the set of regular expressions (R,+,⋅)(R, +, \cdot) forms a (non-commutative) ring. One obvious issue is that we don’t have an identity for addition; note that 1\mathbf{1} is not neutral with respect to addition, since 1+a\mathbf{1} + a matches both the empty string and aa, not just aa. This issue is easily remedied by adding a new object 0\mathbf{0} that matches no strings at all to the definition of regular expression. One can check that 0\mathbf{0} is indeed neutral with respect to addition and possesses various properties that something called zero ought to.

Unfortunately, even with 0\mathbf{0} the regular expressions do not have a ring structure for entirely trivial reasons. Indeed, additive inverses do not exist in general: given a regular expression rr, what is −r-r? (One might be tempted to define it as the regular expression matching the complement of the language matched by rr, but unfortunately this does not play well with our existing definitions.4)

Thus (R,+,⋅)(R, +, \cdot) is not a ring. However, one can actually check that the lack of additive inverses is the sole obstruction to (R,+,⋅)(R, +, \cdot) being a ring. There is a name for structures that are almost rings but lack only additive inverses: semirings.

Definition (semiring). A semiring (R,+,⋅)(R, +, \cdot) satisfies all the ring axioms, except that additive inverses need not exist.

Proposition. The set of regular expressions RR equipped with alternation as addition ++ and sequencing as multiplication ⋅\cdot forms a semiring.

Proof. All the proofs in this post are left as exercises, partly because I am lazy :-) and partly because I think that the definitions and statements of results are more important than the proofs. □\square

But this does not explain everything. In particular, we have not said how the star operation r∗r^* fits into the algebraic structure. If you recall how we “solved” the equation r1=r1a+r0ar_1 = r_1 a + r_0 a by heuristically writing “r1(1−a)=r0ar_1 (1 - a) = r_0 a” and then using a “geometric series expansion” to get r1=r0aa∗r_1 = r_0 a a^*, it seems that the star operation acts as a kind of pseudoinverse.

The notion of a Kleene algebra extends the notion of a semiring to include the ∗* operation.

Definition (Kleene algebra). A Kleene algebra (K,+,⋅,∗)(K, +, \cdot, *) is an idempotent semiring (K,+,⋅)(K, +, \cdot) with a unary operation ∗* such that

  • for all a∈Ka \in K, we have 1+a(a∗)≤a∗1 + a(a^*) \le a^* and 1+(a∗)a≤a∗1 + (a^*)a \le a^*,
  • for all a,x∈Ka, x \in K, if ax≤xax \le x then a∗x≤xa^*x \le x, and if xa≤xxa \le x then x(a∗)≤xx(a^*) \le x,

where x≤yx \le y means x+y=yx + y = y.

For intuition about the definition of ≤\le, observe that generally we may interpret ++ in a semiring as a kind of union operation, and so x+y=yx + y = y is equivalent to yy “including” xx. In the setting of regular expressions, we see that r1+r2=r2r_1 + r_2 = r_2 implies that r2r_2 matches all the strings that r1r_1 does (and potentially more).

Proposition. The set of regular expressions (R,+,⋅,∗)(R, +, \cdot, *) is a Kleene algebra.

In fact, regular expressions are the prototypical example of a Kleene algebra; that is, Kleene algebras were introduced to study regular expressions!

In any case, from the defining axioms of a Kleene algebra, we can deduce the following

Lemma (Arden’s lemma). In a Kleene algebra, ba∗ba^* is the least solution of x=xa+bx = xa + b with respect to ≤\le.

which (under a mild technical condition) validates our original rule r=p+rs  ⟹  r=ps∗r = p + rs \implies r = ps^* used to solve the system of regular expressions at the start of the post.

The end of the story?

Kleene algebras are a cromulent and classical interpretation of regular expressions. Yet, one element of the Kleene algebra viewpoint that I personally find unsatisfying is that we originally “derived” the rule r=p+rs  ⟹  r=ps∗r = p + r s \implies r = ps^* by heuristically manipulating r−rs=r(1−s)=pr - rs = r(1 - s) = p, then multiplying by the inverse of 1−s1-s and using a geometric series expansion to get

r=p(1−s)−1=p(1+s+s2+⋯ )=ps∗.r = p(1-s)^{-1} = p(1 + s + s^2 + \cdots) = ps^*.

From the viewpoint of Kleene algebras, even though the end result is justified by Arden’s lemma and ∗* can be understood as a kind of pseudoinverse, the intermediate steps are nothing more than a heuristic and cannot be justified formally.

One would be excused for dismissing the argument above as nothing more than wishful thinking that chances upon the right answer—but in fact we can make this argument fully rigorous in the right setting. In particular, by interpreting regular expressions as formal noncommutative power series or formal power series over words, the “inverse” of a regular expression exists in a larger ring. In the last section of this post I will outline this viewpoint and sketch nice proofs of existence and uniqueness of solutions.

Formal power series over words

The motivation for this section is as follows: if you squint at a regular expression such as xy+yxx y + y x, it looks uncannily like a power series in two variables xx and yy. In fact, I claim this intuition is perfectly valid, and moreover it lets us subtract and invert things formally! The only sublety is that we need to work with a slightly exotic type of noncommutative power series5. To this end, let’s properly define what we mean by a noncommutative power series, also known as a formal power series over words.

Some definitions

We build up to the notion of a formal noncommutative power series from more familiar definitions.

Definition (formal power series in one variable). Let RR be a ring. Then R[[X]]R[[X]] denotes the ring of formal power series ∑n=0∞anXn\sum_{n=0}^\infty a_n X^n in the indeterminate XX with coefficients in RR.

Definition (formal power series in multiple commuting variables). Let RR be a ring. Then R[[X1,...,Xr]]R[[X_1, ..., X_r]] denotes the ring of formal power series ∑k1,…,kr≥0akX1k1⋯Xrkr\sum_{k_1, \dots, k_r \ge 0} a_\mathbf{k} X_1^{k_1} \cdots X_r^{k_r} in rr commuting indeterminates X1,...,XrX_1, ..., X_r with coefficients in RR.

By commuting indeterminates, we mean that we can freely interchange the order in a product: X1X2X1=X1X1X2=X12X2X_1 X_2 X_1 = X_1 X_1 X_2 = X_1^2 X_2. This allows us to rewrite any product of indeterminates in the canonical form X1k1⋯XrkrX_1^{k_1} \cdots X_r^{k_r}.

If we drop this condition, and instead adjoin non-commutative indeterminates, we naturally obtain the definition of formal noncommutative power series. We indicate noncommutativity by using angled brackets instead of square brackets: that is, in R[[X1,X2]]R[[X_1, X_2]] the indeterminates X1X_1 and X2X_2 commute, whereas in R⟨⟨X1,X2⟩⟩R\langle\langle X_1, X_2\rangle\rangle they do not.

Let’s think about what the power series living in R⟨⟨X1,X2⟩⟩R\langle\langle X_1, X_2\rangle\rangle look like. In particular, what form do individual terms take? In the commutative case each term had the form cX1k1X2k2c X_1^{k_1}X_2^{k_2}, which does not distinguish between (say) 5x1x2x1x15 x_1 x_2 x_1 x_1 and 5x13x25 x_1^3 x_2. In the noncommutative case these terms are distinct, so we should instead think about terms having the form

cXw1Xw2⋯Xwm c X_{w_1} X_{w_2} \cdots X_{w_m}

where w1,…,wmw_1, \dots, w_m is a finite sequence of 1s and 2s. The term x1x2x1x1x_1 x_2 x_1 x_1 corresponds to (1,2,1,1)(1, 2, 1, 1), whereas x13x2x_1^3 x_2 corresponds to (1,1,1,2)(1, 1, 1, 2), which is a different sequence.

In this way, we see that the power series living in R⟨⟨X1,…,Xm⟩⟩R\langle\langle X_1, \dots, X_m\rangle\rangle are naturally indexed by words (finite sequences) where each symbol is in {1,...,m}=:Σ\{1,...,m\} =: \Sigma, of the form ∑ω∈Σ∗aωXω\sum_{\omega \in \Sigma^*} a_\omega X_\omega. This leads us to the definition

Definition (formal power series on words). Let RR be a ring and Σ\Sigma be a finite alphabet of symbols. Then R⟨⟨Σ⟩⟩R\langle\langle \Sigma \rangle\rangle denotes the ring of formal noncommutative power series ∑ω∈Σ∗aωXω\sum_{\omega \in \Sigma^*} a_\omega X_\omega.

and as a special case

Definition (formal power series in multiple noncommuting variables). Let RR be a ring. Then R⟨⟨X1,…,Xn⟩⟩R\langle\langle X_1, \dots, X_n \rangle \rangle denotes the ring of formal power series ∑ω∈{1,…,n}∗aωXω\sum_{\omega \in \{1,\dots,n\}^*} a_\omega X_\omega.

It took us a bit to arrive at the right definitions, but I hope that the scenic route we took above gives some intuition for why power series on words is a natural non-commutative generalization of regular power series.

Remark. We can also see R⟨⟨Σ⟩⟩R\langle\langle \Sigma \rangle\rangle as the set of functions f:Σ∗→Rf : \Sigma^* \to R assigning each word a value in RR. (Why is this equivalent?)

Regular expressions are just power series

As alluded to earlier, regular expressions map to noncommutative power series over words in a natural way: for instance, we can think of

r=a(ab+ac)=aab+aac r = a(a b + a c) = a a b+ a a c

as a noncommutative power series in indeterminates aa, bb, cc over Z\mathbb{Z}, where the coefficient on aaba a b is 11 and the coefficient on aaca a c is also 11. Note that the coefficients need not always be 0/1 in general: consider ab+(c+a)ba b + (c + a)b, which expands to ab+cb+ab=2ab+cba b + c b + a b = 2 a b + cb. The coefficient 22 on abab counts the number of ways for the regular expression to match abab: see ab+(c+a)b{\color{red}ab} + (c + {\color{red}a}){\color{red}b}. More generally, the coefficient on a word ω\omega counts the number of distinct parse trees for ω\omega (the number of different ‘ways’ for the regular expression to match ω\omega).

What is the analogue of the star operation in Z⟨⟨Σ⟩⟩\mathbb{Z}\langle\langle \Sigma\rangle\rangle? It seems that we’re a bit stuck now, but let’s try the most naive definition possible: define r∗r^* as shorthand for the infinite sum 1+r+r2+r3+⋯1 + r + r^2 + r^3 + \cdots. The beauty is that this sum really does exist under some assumptions on rr!

Theorem. Let RR be a ring and suppose that r∈R⟨⟨Σ⟩⟩r \in R\langle\langle \Sigma \rangle\rangle has no constant term. Then 1−r1 - r is invertible and moreover its inverse is 1+r+r2+⋯1 + r + r^2 + \cdots.

With this in hand, we can define the correspondence between regular expressions and formal power series formally.

Definition (power series interpretation of regexp). Let RR denote the semiring of regular expressions over Σ\Sigma. Recall that Z⟨⟨Σ⟩⟩\mathbb{Z}\langle\langle \Sigma \rangle\rangle denotes the ring of formal power series on words over Σ\Sigma.

Define the power series interpretation of a regular expression rr, denoted [r][r], by

  • [0]=0[\mathbf{0}] = 0
  • [1]=1[\mathbf{1}] = 1
  • [r1+r2]=[r1]+[r2][r_1 + r_2] = [r_1] + [r_2]
  • [r1r2]=[r1][r2][r_1 r_2] = [r_1] [r_2]
  • [r∗]=(1−[r])−1[r^*] = (1 - [r])^{-1} whenever rr does not match the empty string.

Here [⋅][\cdot] is a partial function R→Z⟨⟨Σ⟩⟩R \to \mathbb{Z}\langle\langle \Sigma \rangle\rangle.

Theorem. Let rr be a regular expression and suppose [r][r] exists. Then the coefficient on each word ω∈Σ∗\omega \in \Sigma^* in [r][r] counts the number of ways that rr matches ω\omega.

Corollary. Let rr be a regular expression and suppose [r][r] exists. Then the set of strings matched by rr is exactly the set of words with nonzero coefficient in the power series [r][r].

The condition rr does not match the empty string in [r∗][r^*] guarantees that [r][r] has no constant term and hence 1−[r]1 - [r] is invertible. Intuitively, when rr matches the empty string, we should not expect r∗r^* to have a well-defined power series interpretation since there are infinitely many ways for r∗r^* match the empty string, hence the constant term of [r∗][r^*] must be ∞\infty, which is not in Z\mathbb{Z}.


In the power series interpretation of regular expressions, the heuristic argument that we originally made has a completely rigorous interpretation in Z⟨⟨Σ⟩⟩\mathbb{Z}\langle\langle \Sigma \rangle\rangle, since subtraction is well-defined and the geometric series expansion (1−r)−1=1+r+r2+⋯(1-r)^{-1} = 1 + r + r^2 + \cdots is valid whenever rr has no constant term!

Working in Z⟨⟨Σ⟩⟩\mathbb{Z}\langle\langle \Sigma \rangle\rangle also permits us to prove that the system of linear equations arising from NFA to regexp conversion has a solution. Indeed, take a ϵ\epsilon-free NFA with states Q1,…,QnQ_1, \dots, Q_n, initial states II and accepting states FF. Define a row vector u\mathbf{u} by ui=1u_i = 1 if Qi∈IQ_i \in I and ui=0u_i = 0 otherwise. Also define a n×nn \times n matrix by

Aji=∑c∈Σ : exists transition Qj→cQic. \textstyle A_{ji} = \sum_{c \in \Sigma\ : \ \text{exists transition } Q_j \xrightarrow{c} Q_i} c.

For instance, if the alphabet is {a,b}\{a, b\} and the NFA contains transitions Q1→aQ2Q_1 \xrightarrow{a} Q_2 and Q2→bQ2Q_2 \xrightarrow{b} Q_2, then A12=a+bA_{12} = a + b.

Each entry of AA is a nonempty sum of literal symbols (as there are no ϵ\epsilon-transitions), so AA has no constant term. Writing r=(r1,…,rn)\mathbf{r} = (r_1, \dots, r_n), the equations ri=ui+∑jrjAjir_i = u_i + \sum_j r_j A_{ji} produced by our method become the single matrix equation

r=u+rA. \mathbf{r} = \mathbf{u} + \mathbf{r} A.

We can then prove

Theorem (existence and uniqueness). Let AA and u\mathbf{u} be as above. Then the system r=u+rA\mathbf{r} = \mathbf{u} + \mathbf{r}A has a unique solution r∈Z⟨⟨Σ⟩⟩n\mathbf{r} \in \mathbb{Z}\langle\langle \Sigma \rangle\rangle^n, given by

r=u(In×n−A)−1=u(Id+A+A2+⋯ ). \mathbf{r} = \mathbf{u}(I_{n \times n} - A)^{-1} = \mathbf{u}(\mathrm{Id} + A + A^2 + \cdots).

Moreover, the coefficient of a word ww in rir_i is the number of paths in the NFA that start in a state of II, read ww, and end in QiQ_i. In particular, the words with nonzero coefficient in ∑Qi∈Fri\sum_{Q_i \in F} r_i are exactly the words accepted by the NFA.

The above result is not entirely complete, in the sense that it only guarantees a solution in Z⟨⟨Σ⟩⟩\mathbb{Z}\langle\langle \Sigma \rangle\rangle, which may not correspond to a valid regular expression. Indeed, since the interpretation of a regular expression [r][r] is the power series in which the coefficient on each word records the number of ways for rr to match the word, no power series with negative coefficients corresponds to a regular expression. One might then hope that every power series with non-negative coefficients corresponds to a regular expression, but this is not true either.6

In other words, only certain power series in Z⟨⟨Σ⟩⟩\mathbb{Z}\langle\langle \Sigma \rangle\rangle can be converted back into valid regular expressions. Let Nrat⟨⟨Σ⟩⟩\mathbb{N}^\text{rat} \langle\langle \Sigma \rangle\rangle denote the subsemiring of power series corresponding to valid regular expressions. It turns out that one can prove that the Gaussian elimination-like process we used to solve the original example problem stays in Nrat⟨⟨Σ⟩⟩\mathbb{N}^\text{rat} \langle\langle \Sigma \rangle\rangle, which fills the gap in the result.

Conclusion

There’s lots more interesting things to say on this topic, but for now I will leave this post here—I hope it was a fun introduction to some more mathematical aspects of regular expressions. The ideas here are all quite classic, so let me conclude with a brief chronology:

  • Kleene invented regular expressions in 1951;
  • Schützenberger made the connection between automata and noncommutative power series in 1961;
  • Arden proved that x=xa+bx = xa + b has solution x=ba∗x = ba^*, also in 1961;
  • Brzozowski popularized the linear system method to convert NFAs to regexps in his seminal 1964 paper on derivatives of regular expressions;
  • and Kozen introduced the modern definition of Kleene algebra used in this post in 1991, though similar ideas were around earlier.

  1. I first learnt this method from Dr. Christian Urban’s course on compilers and formal languages at KCL on exchange. ↩︎

  2. After a bit of pondering one arrives at the definition {s1s2:s1∈L(r1),s2∈L(r2)}\{s_1 s_2 : s_1 \in \mathcal{L}(r_1), s_2 \in \mathcal{L}(r_2)\}, where s1s2s_1 s_2 denotes the concatenation of strings s1s_1 and s2s_2. ↩︎

  3. Consider the regexp aa matching the literal character aa. Then, if a−1a^{-1} is a multiplicative inverse of aa, we must have

    L(aa−1)={s1s2:s1∈L(a),s2∈L(a−1)}\mathcal{L}(aa^{-1}) = \{s_1 s_2 : s_1 \in \mathcal{L}(a), s_2 \in \mathcal{L}(a^{-1})\}

    and in particular this set cannot equal L(1)={ϵ}\mathcal{L}(\mathbf{1}) = \{\epsilon\}: the displayed set is either empty, or contains one or more strings starting with character aa. ↩︎

  4. Every regular expression rr is idempotent with respect to ++, since matching either rr or rr is the same as matching rr; that is, r+r=rr + r = r. If additive inverses exist, adding −r-r then gives r=0r = \mathbf{0}. But rr was arbitrary, so this says that the only regular expression is 0\mathbf{0}—no good! ↩︎

  5. Or maybe noncommutative power series are a triviality to you. Who knows? ↩︎

  6. Indeed, taking Σ={a,b}\Sigma = \{a,b\}, suppose that the power series ∑n≥01⋅anbn∈Z⟨⟨Σ⟩⟩\sum_{n\ge 0} 1 \cdot a^nb^n \in \mathbb{Z}\langle\langle\Sigma\rangle\rangle corresponds to a regular expression rr. The set of strings matched by rr must then be the set of words with nonzero coefficient in [r][r], so that rr matches the language {anbn:n≥0}\{a^nb^n : n\ge 0\}—but this language is not regular. ↩︎