In this section we prove that if is accepted by a finite automaton, then is regular. The proof will provide an algorithm for starting with an FA that accepts and finding a regular expression that describes .
Theorem 3.30Kleene’s Theorem, Part 2
For every finite automaton , the language is regular.
ProofTheorem 3.30
For states and , we introduce the notation for the language
If we can show that for every and in , is regular, then it will follow that is, because
and the union of a finite collection of regular languages is regular.
We will show that each language is regular by expressing it in terms of simpler languages that are regular. Strings in cause to move from to in any manner whatsoever. One way to think about simpler ways of moving from to is to think about the number of transitions involved; the problem with this approach is that there is no upper limit to this number, and so no obvious way to obtain a final regular expression. A similar approach that is more promising is to consider the distinct states through which passes as it moves from to . We can start by considering how can go from to without going through any states, and at each step add one more state to the set through which is allowed to go. This procedure will terminate when we have enlarged the set to include all possible states.
If , we say causes to go from to through a state if there are nonnull strings and such that , , and . In using a string of length 1 to go from to , does not go through any state. (If loops from back to on the symbol , it does not go through even though the string causes it to leave and enter .) In using a string of length , it goes through a state times, but if these states may not be distinct.
Now we assume that has elements and that they are numbered from 1 to . For and , we let be the set of strings in that cause to go from to without going through any state numbered higher than .
The set is the set of strings that allow to go from to without going through any state at all. This includes the set of alphabet symbols for which , and in the case when it also includes the string . In any case, is a finite set of strings and therefore regular.
Suppose that for some number , is regular for every and every in , and consider how a string can be in . The easiest way is for it to be in , because if goes through no state numbered higher than , it certainly goes through no state numbered higher than . The other strings in are those that cause to go from to by going through state and no higher-numbered states. A path of this type goes from to ; it may return to one or more times; and it finishes by going from to (see Figure 3.31). On each of these individual portions, the path starts or stops at state but doesn’t go through any state numbered higher than .
Going from to by going through .
Every string in can be described in one of these two ways, and every string that has one of these two forms is in . The resulting formula is
We have the ingredients, both for a proof by mathematical induction that is regular and for an algorithm to obtain a regular expression for this language. can be described by a regular expression; for each , is described by the formula above; and , because the condition that the path go through no state numbered higher than is no restriction at all if there are no states numbered higher than . As we observed at the beginning of the proof, the last step in obtaining a regular expression for is to use the operation to combine the expressions for the languages , where .
Example 3.32Finding a Regular Expression Corresponding to an FA
Let be the finite automaton pictured in Figure 3.33.
An FA for which we want an equivalent regular expression.
If we let denote a regular expression corresponding to the language described in the proof of Theorem 3.30, then is described by the regular expression , where
We might try calculating this expression from the top down, at least until we can see how many of the terms we will need that involve smaller values of . The recursive formula in the proof of the theorem tells us that
Applying the formula to the expressions that we apparently need, we obtain
At this point it is clear that we need every one of the expressions , and we now start at the bottom and work our way up. The three tables below show the expressions , , and for all combinations of and . (Only six of the nine entries in the last table are required.)
For example,
The terms required for the final regular expression can now be obtained from the last table. As you can see, these expressions get very involved, even though we have already made some attempts to simplify them. There is no guarantee that the final regular expression is the simplest possible (it seems clear in this case that it is not), but at least we have a systematic way of generating a regular expression corresponding to .