Union of two regular languages
In formal language theory, and in particular the theory of nondeterministic finite state machines, it is known that the union of two regular languages is a regular language. This article provides a proof of that statement.
Theorem
For any regular languages L1 and L2, language L1 ∪ L2 is regular.''
Proof
Since L1 and L2 are regular, there exist NFA's N1, N2 that recognize
L1 and L2.
Let
N1 = (Q1, Σ, T1, q1, A1)
N2 = (Q2, Σ, T2, q2, A2)
Construct
-
- N = (Q, Σ, T, q0, A1∪A2)
where
Q = Q1 ∪ Q2 ∪ {q0}
$$T(q,x) = \left\{\begin{array}{lll} T_{1}(q,x) & \mbox{if} & q\in Q_{1} \\ T_{2}(q,x) & \mbox{if} & q\in Q_{2} \\ \{q_{1}, q_{2}\} & \mbox{if} & q = q_{0}\ and\ x =\epsilon\\ \phi & \mbox{if} & q = q_{0}\ and\ x\neq\epsilon \end{array}\right.$$
In the following, we shall use $p\stackrel{x,T}{\rightarrow}q$ to denote q ∈ E(T(p,x))
Let w be a string from L1 ∪ L2
w ∈ L1 or w ∈ L2
Assume w ∈ L1 (Proof would be similar if w ∈ L2)
Let w = x1x2⋯xm where m ≥ 0, xi ∈ Σ
Since N1 accepts x1x2⋯xm, there exist r0, r1, ⋯rm ∈ Q1 such that
$$q_{1}\stackrel{\epsilon , T_{1}}{\rightarrow}r_{0}\stackrel{x_{1} , T_{1}}{\rightarrow}r_{1}\stackrel{x_{2} , T_{1}}{\rightarrow}r_{2}\cdots r_{m-1}\stackrel{x_{m} , T_{1}}{\rightarrow}r_{m}, r_{m}\in A_{1}$$
Since T1(q,x) = T(q,x) ∀q ∈ Q1∀x ∈ Σ
-
- r0 ∈ E(T1(q1,ϵ)) ⇒ r0 ∈ E(T(q1,ϵ))
-
- r1 ∈ E(T1(r0,x1)) ⇒ r1 ∈ E(T(r0,x1))
-
- ⋮
-
- rm ∈ E(T1(rm − 1,xm)) ⇒ rm ∈ E(T(rm − 1,xm))
We can therefore substitute T for T1 and rewrite the above path as
$q_{1}\stackrel{\epsilon , T}{\rightarrow}r_{0}\stackrel{x_{1} , T}{\rightarrow}r_{1}\stackrel{x_{2} , T}{\rightarrow}r_{2}\cdots r_{m-1}\stackrel{x_{m} , T}{\rightarrow}r_{m}, r_{m}\in A_{1}\cup A_{2}, r_{0}, r_{1},\cdots r_{m}\in Q$
Furthermore,
\begin{array}{lcl} T(q_{0}, \epsilon) = \{q_{1}, q_{2}\} & \Rightarrow & q_{1}\in T(q_{0}, \epsilon)\\
\\ & \Rightarrow & q_{1}\in E(T(q_{0}, \epsilon))\\
\\ & \Rightarrow & q_{0}\stackrel{\epsilon , T}{\rightarrow}q_{1}
\end{array}
and
The above path can be rewritten as
$$q_{0}\stackrel{\epsilon , T}{\rightarrow}r_{0}\stackrel{x_{1} , T}{\rightarrow}r_{1}\stackrel{x_{2} , T}{\rightarrow}r_{2}\cdots r_{m-1}\stackrel{x_{m} , T}{\rightarrow}r_{m}, r_{m}\in A_{1}\cup A_{2}, r_{0}, r_{1},\cdots r_{m}\in Q$$
Therefore, N accepts x1x2⋯xm and the proof is complete.
Note: The idea drawn from this mathematical proof for constructing
a machine to recognize L1 ∪ L2 is to create an initial state and connect
it to the initial states of L1 and L2 using ϵ arrows.
References
- Michael Sipser, Introduction to the Theory of Computation ISBN 0-534-94728-X. (See . Theorem 1.22, section 1.2, pg. 59.)