From a Finite Automaton to a Regular Expression: Arden's Theorem and State Elimination
Chapter Thirty-Five
Syllabus topic Module 1, "Regular Languages: Finite automata and Regular Expressions"
Pages 171 to 176 of 438
In one line
Write one equation per state saying how that state is reached, solve them with Arden's rule, and the equation for the final state is the answer.
In the wording a student can write in an examination: for every finite automaton there is a regular expression denoting the language it accepts. One method writes a simultaneous equation for each state, whose unknown is the set of strings that take the machine from the initial state to that state, and solves the system using Arden's rule, that X equals RX plus S has the unique solution R star S when the language of R excludes the empty string. A second method deletes states one at a time, replacing the paths through each deleted state by labelled transitions carrying regular expressions.
Arden's theorem
Statement. Let R and S be regular expressions over an alphabet, and suppose the language of R does not contain the empty string. Then the equation
X = R X + S
has the unique solution
X = R star S
Proof that R star S is a solution. Substitute it into the right hand side:
R (R star S) + S = (R R star) S + S = (R plus) S + S = (R plus + ε) S = R star S
The first step is associativity of concatenation, the second is identity 9 of chapter 32, the third is distribution read right to left, and the fourth is identity 9 again. So R star S satisfies the equation.
Proof that it is the only solution. Suppose X is any solution. Substituting the equation into itself n times gives
X = S + R S + R squared S + ... + R to the n S + R to the (n plus 1) X
Now take any string w in X, of length k. Because the language of R excludes the empty string, every string in R to the m has length at least m. So for n greater than k the last term contributes nothing of length k, and w must come from one of the earlier terms, all of which are inside R star S. So X is contained in R star S, and the first half gave the other containment. Hence X equals R star S.
Where the condition bites. If the language of R does contain epsilon, the argument above fails at "every string in R to the m has length at least m", and the equation genuinely has more than one solution. Take R equal to epsilon and S equal to a. Then X equals X plus a is satisfied by {a} and by every larger language, so there is no unique answer.
From a Finite Automaton to a Regular Expression: Arden's Theorem and State Elimination
The mirror form, used when the equations are written the other way round:
X = X R + S has the unique solution X = S R star
Method 1: the equation method
The procedure.
- For each state q write an unknown X for the set of strings taking the machine from the start state to q.
- Write one equation per state: X for q equals the sum, over every transition into q, of the expression for the
source state concatenated with the symbol on that transition. For the start state, add epsilon, because the empty string reaches it.
- Solve the system by substitution, using Arden's rule whenever an unknown appears on both sides.
- The answer is the sum of the expressions for the final states.
Step 2 is where the direction has to be watched. The equation for q is about arrows into q, not out of it. A student who writes the equations from the outgoing arrows has written a different and wrong system.
Worked, in full
Take the machine for the strings over {a, b} ending in ab.
| P1 | State | a | b |
|---|---|---|---|
| start | s0 | s1 | s0 |
| s1 | s1 | s2 | |
| final | s2 | s1 | s0 |
Accepts: ab, aab, bab, abab, bbab
Rejects: ε, a, b, ba, abb, aa
Step 1 and 2. The equations. Write X0, X1, X2 for the three states, and read off the arrows into each.
Into s0: from s0 on b, and from s2 on b. And s0 is the start state, so epsilon is added.
Into s1: from s0 on a, from s1 on a, and from s2 on a.
Into s2: from s1 on b, and nothing else.
X0 = ε + X0 b + X2 b
X1 = X0 a + X1 a + X2 a
X2 = X1 b
Step 3. Solve. Take them in the easiest order, which is the one with the fewest unknowns on the right.
The third equation gives X2 directly in terms of X1, so substitute it into the second:
X1 = X0 a + X1 a + X1 b a
= X0 a + X1 (a + b a)
The second line factors X1 out by identity 6 read right to left. Now X1 appears on both sides in the mirror form, so Arden's rule gives
X1 = X0 a (a + b a) star
Substitute that into the first equation, remembering that X2 is X1 b:
X0 = ε + X0 b + X1 b b
= ε + X0 b + X0 a (a + b a) star b b
= ε + X0 ( b + a (a + b a) star b b )
From a Finite Automaton to a Regular Expression: Arden's Theorem and State Elimination
Arden's rule again, in the mirror form with S equal to epsilon:
X0 = ( b + a (a + b a) star b b ) star
and then working back:
X1 = ( b + a (a + b a) star b b ) star a (a + b a) star
X2 = ( b + a (a + b a) star b b ) star a (a + b a) star b
Step 4. The answer is X2, because s2 is the only final state.
(b + a (a + b a)* b b)* a (a + b a)* bL(P2) = L(P1)
The checker decides that equality exactly, so the solution is right and not merely plausible. And the two intermediate expressions are right too, which is worth checking separately because an error in X0 or X1 would usually still give a plausible looking X2.
(b + a (a + b a)* b b)*(b + a (a + b a)* b b)* a (a + b a)*| P5 | State | a | b |
|---|---|---|---|
| start final | s0 | s1 | s0 |
| s1 | s1 | s2 | |
| s2 | s1 | s0 |
Accepts: ε, b, abb, bb, babb
Rejects: a, ab, aab, ba, aa
| P6 | State | a | b |
|---|---|---|---|
| start | s0 | s1 | s0 |
| final | s1 | s1 | s2 |
| s2 | s1 | s0 |
Accepts: a, aa, ba, aba, abba
Rejects: ε, b, ab, bb, abb
L(P3) = L(P5)
L(P4) = L(P6)
P5 and P6 are the same machine with a different final state, so their languages are exactly the sets X0 and X1 were defined to be. Both expressions check out, so the whole solution is verified and not just its last line.
And the answer is not the shortest one. The machine plainly accepts (a + b)* a b, and so:
(a + b)* a bL(P7) = L(P1)
Both expressions are correct. Arden's method is mechanical and gives something correct; chapter 32's identities are what get it down to something short, and an examiner will accept either.
Method 2: state elimination
Often quicker by hand, and it is the method to use when the machine has more than three or four states.
The idea. Allow the arrows of the machine to carry whole regular expressions rather than single symbols. Then a state can be deleted by replacing every path through it with a single arrow carrying the expression for those paths.
The procedure.
- Add a new start state with an empty arrow to the old start state, and a new single final state with empty
arrows from every old final state. Neither new state is ever deleted. This is chapter 34's invariant again, and it is needed for the same reason.
From a Finite Automaton to a Regular Expression: Arden's Theorem and State Elimination
- Pick any state other than the two new ones and delete it. For every pair of a state p with an arrow in and a
state q with an arrow out, replace those by a single arrow from p to q carrying
(the arrow from p in) (the loop on the deleted state) star (the arrow out to q)
where the loop's star is epsilon if the deleted state has no loop. Where p already had an arrow to q, the two expressions are joined with a plus.
- Repeat until only the two new states remain.
- The single arrow between them carries the answer.
Worked, on the same machine
Take P1 again, and add the new start N and the new final F.
Arrows at the start. N to s0 on epsilon. s0 to s0 on b, s0 to s1 on a. s1 to s1 on a, s1 to s2 on b. s2 to s0 on b, s2 to s1 on a. s2 to F on epsilon.
Delete s1. Arrows in: from s0 on a, from s2 on a. Arrows out: to s2 on b. The loop on s1 is a, so its star is a star.
- s0 to s2 gains
a a star b. - s2 to s2 gains
a a star b.
Now the arrows are: N to s0 on epsilon; s0 to s0 on b; s0 to s2 on a a star b; s2 to s0 on b; s2 to s2 on a a star b; s2 to F on epsilon.
Delete s0. Arrows in: from N on epsilon, from s2 on b. Arrows out: to s2 on a a star b. Loop on s0 is b, so its star is b star.
- N to s2 gains
b star a a star b. - s2 to s2 gains
b b star a a star b, joined with thea a star bit already had.
Now: N to s2 on b star a a star b; s2 to s2 on a a star b + b b star a a star b; s2 to F on epsilon.
Delete s2. Arrows in: from N. Arrows out: to F. The loop on s2 is the union just written, so:
- N to F gains
b star a a star b ( a a star b + b b star a a star b ) star.
The answer:
b* a a* b (a a* b + b b* a a* b)*L(P8) = L(P1)
A third correct expression for the same language, arrived at by a different route, and checked. Which of P2, P7 and P8 a student produces depends on the method and the order of elimination, and all three earn the marks.
From a Finite Automaton to a Regular Expression: Arden's Theorem and State Elimination
The order matters for length, not for correctness. Deleting the most connected state last usually gives the shortest answer, and deleting in a different order here gives a different expression for the same language.
Distinctions
| The equation method | State elimination | |
|---|---|---|
| What you write | one equation per state | a diagram with expressions on the arrows |
| The tool | Arden's rule | the path replacement formula |
| Direction | equations are about arrows IN | arrows are followed forward |
| Best for | three or four states, and when Arden is asked for by name | larger machines |
| The answer's length | usually long | depends on the deletion order |
| X = RX + S | X = XR + S | |
|---|---|---|
| Solution | R star S | S R star |
| Which arises | when equations are written with the source on the right | when written with the source on the left, as here |
What it does NOT mean
Arden's rule does not need the machine to be deterministic. The equations can be written for any finite automaton, and an NFA gives a union of terms on the right hand side.
The equation for a state is not about its outgoing arrows. It is about the arrows into it. This is the error that produces a system with a plausible solution and the wrong language.
Epsilon is added only to the start state's equation. Adding it elsewhere claims the empty string reaches that state, which it does not.
The answer is not unique. Three correct expressions for one machine appear above. Only the language is determined.
Arden's condition is not a formality. Without epsilon being absent from R, the equation has many solutions and the rule picks the smallest, which may not be the one the machine denotes.
Quick revision
- Arden's theorem: X equals RX plus S has the unique solution R star S when the language of R excludes epsilon.
The mirror form X equals XR plus S has S R star.
- The uniqueness proof: substitute repeatedly, and use the fact that every string of R to the m has length at
least m, which is exactly what the condition guarantees.
- Equation method: one unknown per state, one equation per state written from the arrows IN, epsilon added to the
start state's equation, solved by substitution and Arden. The answer is the sum over the final states.
- State elimination: add a new start and a new single final state, then delete states one at a time, replacing
paths through a deleted state by an arrow carrying in, loop starred, out; join parallel arrows with a plus.
From a Finite Automaton to a Regular Expression: Arden's Theorem and State Elimination
- Both methods give correct expressions, usually different ones, and neither gives the shortest.
- Chapter 32's identities are what shorten the answer.
Test yourself
1. State Arden's theorem, both forms, with the condition. If the language of R does not contain epsilon, then X equals RX plus S has the unique solution R star S, and X equals XR plus S has the unique solution S R star.
2. Prove that R star S satisfies X equals RX plus S. Substitute: R R star S plus S is R plus S plus S, which is (R plus plus epsilon) S by distribution, which is R star S by identity 9.
3. Why does the uniqueness proof need epsilon to be absent from R? Because it relies on every string of R to the m having length at least m, so that for large enough n the term R to the n plus one X cannot contribute a string of a given length. If R contained epsilon that bound fails and the equation has many solutions.
4. In the equation method, which arrows does a state's equation use, and what extra term does the start state get? The arrows INTO that state, each contributing the source state's unknown concatenated with the transition's symbol. The start state's equation gains an epsilon term, because the empty string reaches it.
5. In state elimination, what expression replaces the paths through a deleted state? The expression on the incoming arrow, then the loop on the deleted state starred, then the expression on the outgoing arrow. Parallel arrows between the same pair are joined with a plus.
6. Two students produce different expressions for the same machine. Are both wrong? Neither need be. The language is determined but the expression is not, and the chapter gives three correct expressions for one machine, from Arden, from inspection and from state elimination.
The rest of this subject
These notes are cut from the University's printed syllabus. Open the syllabus itself, or the past papers, for the same subject.