Martin

John C. Martin · Fourth edition

Kleene’s Theorem, Part 1

If we are trying to construct a device that accepts a regular language LL, we can proceed one state at a time, as in Example 2.22, deciding at each step which strings it is necessary to distinguish. Adding each additional state may get harder as the number of states grows, but if we know somehow that there is an FA accepting LL, we can be sure that the procedure will eventually terminate and produce one.

We have examples to show that for certain regular expressions, nondeterminism simplifies the problem of drawing an accepting device. In this section we will use nondeterminism to show that we can do this for every regular expression. Furthermore, we now have algorithms to convert the resulting NFA to an FA. The conclusion will be that on the one hand, the state-by-state approach will always work; and on the other hand, there is a systematic procedure that is also guaranteed to work and may be more straightforward.

The general result is one half of Kleene’s theorem, which says that regular languages are the languages that can be accepted by finite automata. We will discuss the first half in this section and the second in Section 3.5.

Theorem 3.25Kleene’s Theorem, Part 1

For every alphabet Σ\Sigma, every regular language over Σ\Sigma can be accepted by a finite automaton.

ProofTheorem 3.25

Because of Theorems 3.17 and 3.18, it’s enough to show that every regular language over Σ\Sigma can be accepted by an NFA. The set of regular languages over Σ\Sigma is defined recursively in Definition 3.1, and we will prove the theorem by structural induction.

The languages ∅\varnothing and {σ}\{\sigma\} (where σ∈Σ\sigma\in\Sigma) can be accepted by the two NFAs in Figure 3.26, respectively. The induction hypothesis is that L1L_1 and L2L_2 are both regular languages over Σ\Sigma and that for both i=1i=1 and i=2i=2, LiL_i can be accepted by an NFA Mi=(Qi,Σ,qi,Ai,δi)M_i=(Q_i,\Sigma,q_i,A_i,\delta_i). We can assume, by renaming states if necessary, that Q1Q_1 and Q2Q_2 are disjoint. In the induction step we must show that there are NFAs accepting the three languages L(M1)∪L(M2)L(M_1)\cup L(M_2), L(M1)L(M2)L(M_1)L(M_2), and L(M1)∗L(M_1)^*.

In each case we will give an informal definition and a diagram showing the idea of the construction. For simplicity, each diagram shows the two NFAs M1M_1 and M2M_2 as having two accepting states, both distinct from the initial state.

An NFA MuM_u accepting L(M1)∪L(M2)L(M_1)\cup L(M_2) is shown in Figure 3.27a. Its states are those of M1M_1 and M2M_2 and one additional state quq_u that is the initial state. The transitions include all the ones in M1M_1 and M2M_2 as well as Λ\Lambda-transitions from quq_u to q1q_1 and q2q_2, the initial states of M1M_1 and M2M_2. Finally, the accepting states are simply the states in A1∪A2A_1\cup A_2.

If x∈L(M1)x\in L(M_1), for example, MuM_u can accept xx by taking the Λ\Lambda-transition from quq_u to q1q_1 and then executing the moves that would allow M1M_1 to accept xx. On the other hand, if xx is any string accepted by MuM_u, there is a path from quq_u to an element of A1A_1 or A2A_2. The first transition in the path must be a Λ\Lambda-transition, which takes MuM_u to q1q_1 or q2q_2. Because Q1∩Q2=∅Q_1\cap Q_2=\varnothing, the remainder of the path causes xx to be accepted either by M1M_1 or by M2M_2.

An NFA McM_c accepting L(M1)L(M2)L(M_1)L(M_2) is shown in Figure 3.27b. No new states need to be added to those of M1M_1 and M2M_2. The initial state is q1q_1, and the accepting states are the elements of A2A_2. The transitions include all those of M1M_1 and M2M_2 and a new Λ\Lambda-transition from every element of A1A_1 to q2q_2. If xx is the string x1x2x_1x_2, where xix_i is accepted by MiM_i for each ii, then McM_c can process xx by moving from q1q_1 to a state in A1A_1 using Λ\Lambda’s and the symbols of x1x_1, taking the Λ\Lambda-transition to q2q_2, and moving to a state in A2A_2 using Λ\Lambda’s and the symbols of x2x_2. Conversely, if xx is a string accepted by McM_c, then at some point during the computation, McM_c must execute the Λ\Lambda-transition from an element of A1A_1 to q2q_2. If x1x_1 is the prefix of xx whose symbols have been processed at that point, then x1x_1 must be accepted by M1M_1; the remaining suffix of xx is accepted by M2M_2, because it corresponds to a path from q2q_2 to an element of A2A_2 that cannot involve any transitions other than those of M2M_2.

(a)

(b)

(c)

Figure 3.27

Schematic diagram for Kleene’s theorem, Part 1.

Finally, an NFA MkM_k accepting L(M1)∗L(M_1)^* is shown in Figure 3.27c. Its states are the elements of Q1Q_1 and a new initial state qkq_k that is also the only accepting state. The transitions are those of M1M_1, a Λ\Lambda-transition from qkq_k to q1q_1, and a Λ\Lambda-transition from every element of A1A_1 to qkq_k. We can see by structural induction that every element of L(M1)∗L(M_1)^* is accepted. The null string is, because qkq_k is an accepting state. Now suppose that x∈L(M1)∗x\in L(M_1)^* is accepted and that y∈L(M1)y\in L(M_1). When M∗M^* is in a state in A1A_1 after processing xx, it can take a Λ\Lambda-transition to qkq_k and another to q1q_1, process yy so as to end up in an element of A1A_1, and finish up by returning to qkq_k with a Λ\Lambda-transition. Therefore, xyxy is accepted by M∗M^*.

We can argue in the opposite direction by using mathematical induction on the number of times M∗M^* enters the state qkq_k in the process of accepting a string. If M∗M^* visits qkq_k only once in accepting xx, then x=Λx=\Lambda, which is an element of L(M1)∗L(M_1)^*. If we assume that n≥1n\ge1 and that every string accepted by M∗M^* that causes M∗M^* to enter qkq_k nn or fewer times is in L(M1)∗L(M_1)^*, then consider a string xx that causes M∗M^* to enter qkq_k n+1n+1 times and is accepted. Let x1x_1 be the prefix of xx that is accepted when M∗M^* enters qkq_k the nnth time, and let x2x_2 be the remaining part of xx. By the induction hypothesis, x1∈L(M1)∗x_1\in L(M_1)^*. In processing x2x_2, M∗M^* moves to q1q_1 on a Λ\Lambda-transition and then from q1q_1 to an element of A1A_1 using Λ\Lambda-transitions in addition to the symbols of x2x_2. Therefore, x2∈L(M1)x_2\in L(M_1), and it follows that x∈L(M1)∗x\in L(M_1)^*.

Example 3.28An NFA Corresponding to ((aa+b)∗(aba)∗bab)∗((aa+b)^*(aba)^*bab)^*

The three portions of the induction step in the proof of Theorem 3.25 provide algorithms for constructing an NFA corresponding to an arbitrary regular expression. These can be combined into a general algorithm that could be used to automate the process.

The transition diagram in Figure 3.29a shows a literal application of the three algorithms in the case of the regular expression ((aa+b)∗(aba)∗bab)∗((aa+b)^*(aba)^*bab)^*. In this case there is no need for all the Λ\Lambda-transitions that are called for by the algorithms, and a simplified NFA is shown in Figure 3.29b. At least two Λ\Lambda-transitions are still helpful in order to preserve the resemblance between the transition diagram and the regular expression. The algorithms can often be shortened in examples, but for each step where one of them calls for an extra state and/or a Λ\Lambda-transition, there are examples to show that dispensing with the extra state or the transition doesn’t always work (see Exercises 3.45–3.48).

Figure 3.29

Constructing an NFA for the regular expression ((aa+b)∗(aba)∗bab)∗((aa+b)^*(aba)^*bab)^*.