Martin

John C. Martin · Fourth edition

Kleene’s Theorem, Part 2

In this section we prove that if LL is accepted by a finite automaton, then LL is regular. The proof will provide an algorithm for starting with an FA that accepts LL and finding a regular expression that describes LL.

Theorem 3.30Kleene’s Theorem, Part 2

For every finite automaton M=(Q,Σ,q0,A,δ)M=(Q,\Sigma,q_0,A,\delta), the language L(M)L(M) is regular.

ProofTheorem 3.30

For states pp and qq, we introduce the notation L(p,q)L(p,q) for the language

L(p,q)={x∈Σ∗∣δ∗(p,x)=q}L(p,q)=\{x\in\Sigma^*\mid\delta^*(p,x)=q\}

If we can show that for every pp and qq in QQ, L(p,q)L(p,q) is regular, then it will follow that L(M)L(M) is, because

L(M)=⋃{L(q0,q)∣q∈A}L(M)=\bigcup\{L(q_0,q)\mid q\in A\}

and the union of a finite collection of regular languages is regular.

We will show that each language L(p,q)L(p,q) is regular by expressing it in terms of simpler languages that are regular. Strings in L(p,q)L(p,q) cause MM to move from pp to qq in any manner whatsoever. One way to think about simpler ways of moving from pp to qq 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 MM passes as it moves from pp to qq. We can start by considering how MM can go from pp to qq without going through any states, and at each step add one more state to the set through which MM is allowed to go. This procedure will terminate when we have enlarged the set to include all possible states.

If x∈L(p,q)x\in L(p,q), we say xx causes MM to go from pp to qq through a state rr if there are nonnull strings x1x_1 and x2x_2 such that x=x1x2x=x_1x_2, δ∗(p,x1)=r\delta^*(p,x_1)=r, and δ∗(r,x2)=q\delta^*(r,x_2)=q. In using a string of length 1 to go from pp to qq, MM does not go through any state. (If MM loops from pp back to pp on the symbol aa, it does not go through pp even though the string aa causes it to leave pp and enter pp.) In using a string of length n≥2n\ge2, it goes through a state n−1n-1 times, but if n>2n>2 these states may not be distinct.

Now we assume that QQ has nn elements and that they are numbered from 1 to nn. For p,q∈Qp,q\in Q and j≥0j\ge0, we let L(p,q,j)L(p,q,j) be the set of strings in L(p,q)L(p,q) that cause MM to go from pp to qq without going through any state numbered higher than jj.

The set L(p,q,0)L(p,q,0) is the set of strings that allow MM to go from pp to qq without going through any state at all. This includes the set of alphabet symbols σ\sigma for which δ(p,σ)=q\delta(p,\sigma)=q, and in the case when p=qp=q it also includes the string Λ\Lambda. In any case, L(p,q,0)L(p,q,0) is a finite set of strings and therefore regular.

Suppose that for some number k≥0k\ge0, L(p,q,k)L(p,q,k) is regular for every pp and every qq in QQ, and consider how a string can be in L(p,q,k+1)L(p,q,k+1). The easiest way is for it to be in L(p,q,k)L(p,q,k), because if MM goes through no state numbered higher than kk, it certainly goes through no state numbered higher than k+1k+1. The other strings in L(p,q,k+1)L(p,q,k+1) are those that cause MM to go from pp to qq by going through state k+1k+1 and no higher-numbered states. A path of this type goes from pp to k+1k+1; it may return to k+1k+1 one or more times; and it finishes by going from k+1k+1 to qq (see Figure 3.31). On each of these individual portions, the path starts or stops at state k+1k+1 but doesn’t go through any state numbered higher than kk.

Figure 3.31

Going from pp to qq by going through k+1k+1.

Every string in L(p,q,k+1)L(p,q,k+1) can be described in one of these two ways, and every string that has one of these two forms is in L(p,q,k+1)L(p,q,k+1). The resulting formula is

L(p,q,k+1)=L(p,q,k)∪L(p,k+1,k)L(k+1,k+1,k)∗L(k+1,q,k)\begin{aligned}L(p,q,k+1)={}&L(p,q,k)\\&\cup L(p,k+1,k)L(k+1,k+1,k)^*L(k+1,q,k)\end{aligned}

We have the ingredients, both for a proof by mathematical induction that L(p,q)L(p,q) is regular and for an algorithm to obtain a regular expression for this language. L(p,q,0)L(p,q,0) can be described by a regular expression; for each k<nk<n, L(p,q,k+1)L(p,q,k+1) is described by the formula above; and L(p,q,n)=L(p,q)L(p,q,n)=L(p,q), because the condition that the path go through no state numbered higher than nn is no restriction at all if there are no states numbered higher than nn. As we observed at the beginning of the proof, the last step in obtaining a regular expression for L(M)L(M) is to use the ++ operation to combine the expressions for the languages L(q0,q)L(q_0,q), where q∈Aq\in A.

Example 3.32Finding a Regular Expression Corresponding to an FA

Let MM be the finite automaton pictured in Figure 3.33.

Figure 3.33

An FA for which we want an equivalent regular expression.

If we let r(i,j,k)r(i,j,k) denote a regular expression corresponding to the language L(i,j,k)L(i,j,k) described in the proof of Theorem 3.30, then L(M)L(M) is described by the regular expression r(M)r(M), where

r(M)=r(1,1,3)+r(1,2,3)r(M)=r(1,1,3)+r(1,2,3)

We might try calculating this expression from the top down, at least until we can see how many of the terms r(i,j,k)r(i,j,k) we will need that involve smaller values of kk. The recursive formula in the proof of the theorem tells us that

r(1,1,3)=r(1,1,2)+r(1,3,2)r(3,3,2)∗r(3,1,2)r(1,2,3)=r(1,2,2)+r(1,3,2)r(3,3,2)∗r(3,2,2)\begin{aligned}r(1,1,3)&=r(1,1,2)+r(1,3,2)r(3,3,2)^*r(3,1,2)\\r(1,2,3)&=r(1,2,2)+r(1,3,2)r(3,3,2)^*r(3,2,2)\end{aligned}

Applying the formula to the expressions r(i,j,2)r(i,j,2) that we apparently need, we obtain

r(1,1,2)=r(1,1,1)+r(1,2,1)r(2,2,1)∗r(2,1,1)r(1,3,2)=r(1,3,1)+r(1,2,1)r(2,2,1)∗r(2,3,1)r(3,3,2)=r(3,3,1)+r(3,2,1)r(2,2,1)∗r(2,3,1)r(3,1,2)=r(3,1,1)+r(3,2,1)r(2,2,1)∗r(2,1,1)r(1,2,2)=r(1,2,1)+r(1,2,1)r(2,2,1)∗r(2,2,1)r(3,2,2)=r(3,2,1)+r(3,2,1)r(2,2,1)∗r(2,2,1)\begin{aligned}r(1,1,2)&=r(1,1,1)+r(1,2,1)r(2,2,1)^*r(2,1,1)\\r(1,3,2)&=r(1,3,1)+r(1,2,1)r(2,2,1)^*r(2,3,1)\\r(3,3,2)&=r(3,3,1)+r(3,2,1)r(2,2,1)^*r(2,3,1)\\r(3,1,2)&=r(3,1,1)+r(3,2,1)r(2,2,1)^*r(2,1,1)\\r(1,2,2)&=r(1,2,1)+r(1,2,1)r(2,2,1)^*r(2,2,1)\\r(3,2,2)&=r(3,2,1)+r(3,2,1)r(2,2,1)^*r(2,2,1)\end{aligned}

At this point it is clear that we need every one of the expressions r(i,j,1)r(i,j,1), and we now start at the bottom and work our way up. The three tables below show the expressions r(i,j,0)r(i,j,0), r(i,j,1)r(i,j,1), and r(i,j,2)r(i,j,2) for all combinations of ii and jj. (Only six of the nine entries in the last table are required.)

ppr(p,1,0)r(p,1,0)r(p,2,0)r(p,2,0)r(p,3,0)r(p,3,0)
1a+Λa+\Lambdabb∅\varnothing
2aaΛ\Lambdabb
3aabbΛ\Lambda

For example,

r(2,2,1)=r(2,2,0)+r(2,1,0)r(1,1,0)∗r(1,2,0)=Λ+(a)(a+Λ)∗(b)=Λ+aa∗b\begin{aligned}r(2,2,1)&=r(2,2,0)+r(2,1,0)r(1,1,0)^*r(1,2,0)\\&=\Lambda+(a)(a+\Lambda)^*(b)\\&=\Lambda+aa^*b\end{aligned}
r(3,1,2)=r(3,1,1)+r(3,2,1)r(2,2,1)∗r(2,1,1)=aa∗+(a∗b)(Λ+aa∗b)∗(aa∗)=aa∗+a∗b(aa∗b)∗aa∗=aa∗+a∗baa∗(baa∗)∗\begin{aligned}r(3,1,2)&=r(3,1,1)+r(3,2,1)r(2,2,1)^*r(2,1,1)\\&=aa^*+(a^*b)(\Lambda+aa^*b)^*(aa^*)\\&=aa^*+a^*b(aa^*b)^*aa^*\\&=aa^*+a^*baa^*(baa^*)^*\end{aligned}

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 L(M)L(M).