Proof of the closure properties of regular languages full
This proof shows: statement.
Fix finite alphabets Σ and Δ. Let L1=L(M1) and L2=L(M2) with complete DFAs Mi=(Qi,Σ,δi,qi,Fi), where δi:Qi×Σ→Qi and there are no ε-moves. We use the lemma δ∗(q,xy)=δ∗(δ∗(q,x),y) of the DFA page, and we use Kleene's theorem: a language is regular if and only if a complete DFA, an NFA, an epsilon-NFA or a regular expression describes it. For an NFA or an epsilon-NFA we write p⇝wr when some path from p to r has the label w, as in the proof of Kleene's theorem.
Part 1: complement
Claim. L1=Σ∗∖L1 is regular.
Proof. Let M′=(Q1,Σ,δ1,q1,Q1∖F1). The machines M1 and M′ have the same transition function, so they reach the same state δ1∗(q1,w) on each w∈Σ∗. This state is defined because δ1 is complete. So w∈L(M′) if and only if δ1∗(q1,w)∈/F1, if and only if w∈/L1. □
The proof uses both determinism and completeness. Each string has exactly one run, so "the run does not end in F1" is the same as "no run ends in F1".
Part 2: the product and the Boolean operations
Let P=(Q1×Q2,Σ,δ,(q1,q2),F) with δ((p,r),a)=(δ1(p,a),δ2(r,a)), where F is chosen below. This is the product construction. It is a complete DFA.
Lemma 1. For all p∈Q1, r∈Q2 and w∈Σ∗, δ∗((p,r),w)=(δ1∗(p,w),δ2∗(r,w)).
Proof. By induction on ∣w∣. For w=ε both sides are (p,r). For w=va, by the induction hypothesis and the definition of δ,
δ∗((p,r),va)=δ(δ∗((p,r),v),a)=δ((δ1∗(p,v),δ2∗(r,v)),a)=(δ1∗(p,va),δ2∗(r,va)).□ Claim. L1∩L2, L1∪L2, L1∖L2 and L1△L2 are regular.
Proof. By Lemma 1, w∈L(P) if and only if (δ1∗(q1,w),δ2∗(q2,w))∈F. Take
- F=F1×F2: then w∈L(P) if and only if w∈L1 and w∈L2;
- F=(F1×Q2)∪(Q1×F2): then w∈L(P) if and only if w∈L1 or w∈L2;
- F=F1×(Q2∖F2): then w∈L(P) if and only if w∈L1 and w∈/L2;
- F=(F1×(Q2∖F2))∪((Q1∖F1)×F2): then w∈L(P) if and only if exactly one of w∈L1, w∈L2 holds. □
The same argument works for each Boolean function β of two arguments, with F={(p,r):β([p∈F1],[r∈F2])}. It also works for k DFAs at once, with ∏i∣Qi∣ states. For the union, both DFAs must be complete: if δ1∗(q1,w) were undefined, the product would have no state for w even when w∈L2.
Part 3: concatenation
Claim. L1L2={xy:x∈L1,y∈L2} is regular.
Proof. Assume Q1∩Q2=∅. Let N be the epsilon-NFA with the states Q1∪Q2, the start state q1, the accepting states F2, the transitions δ1(p,a)∈δN(p,a) for p∈Q1 and δ2(r,a)∈δN(r,a) for r∈Q2, and one ε-move f→q2 for each f∈F1.
Let w∈L(N), with a path from q1 to some g∈F2. The path starts in Q1 and ends in Q2. The only transitions from a state of Q1 to a state of Q2 are the ε-moves f→q2 with f∈F1, and no transition leads from Q2 to Q1. So the path uses exactly one of these moves. Before it, the path follows δ1 from q1 to f with some label x, so δ1∗(q1,x)=f∈F1 and x∈L1. After it, the path follows δ2 from q2 to g with some label y, so y∈L2. Hence w=xy∈L1L2.
Conversely, let x∈L1 and y∈L2. The run of M1 on x is a path of N from q1 to f=δ1∗(q1,x)∈F1. Follow it by the move f→q2 and by the run of M2 on y, which ends in F2. This is a path with the label xy, so xy∈L(N). By Kleene's theorem L(N) is regular. □
Part 4: Kleene star
Claim. L1∗=⋃k≥0L1k is regular.
Proof. Let s∈/Q1 be a new state. Let N be the epsilon-NFA with the states Q1∪{s}, the start state s, the accepting states {s}, the transitions of M1, an ε-move s→q1, and an ε-move f→s for each f∈F1.
Let w∈L(N), with a path from s to s. Cut the path at each visit to s. The path with zero transitions gives w=ε∈L10. Otherwise each piece goes from s to s without visiting s in between. The only move out of s is s→q1, and the only moves into s are f→s with f∈F1. So a piece is s→q1, then a path that follows δ1 from q1 to some f∈F1 with some label xj, then f→s. Hence δ1∗(q1,xj)∈F1, each xj∈L1, and w=x1⋯xk∈L1k.
Conversely, ε∈L(N) by the path with zero transitions. For x1,…,xk∈L1 with k≥1, join the pieces s→q1, the run of M1 on xj, and the move from its last state, which is in F1, to s. This is a path from s to s with the label x1⋯xk. So L(N)=L1∗, and it is regular by Kleene's theorem. □
The new state s is necessary. If we made q1 accepting and added ε-moves f→q1 instead, a path could return to q1 along a transition of M1 and stop there, in the middle of a word of L1.
Part 5: reversal
Claim. L1R={wR:w∈L1} is regular, where (a1⋯am)R=am⋯a1.
Proof. Let N be the epsilon-NFA with the states Q1∪{s}, where s is new, the start state s, the accepting states {q1}, an ε-move s→f for each f∈F1, and a transition p∈δN(r,a) for each transition δ1(p,a)=r of M1. So the arrows of M1 are reversed.
A sequence r0,r1,…,rm with rt=δ1(rt−1,at) is a path of M1 with the label a1⋯am if and only if rm,rm−1,…,r0 is a path of the reversed transitions with the label am⋯a1. So w∈L1, which means that some path of M1 leads from q1 to some f∈F1 with the label w, holds if and only if the path s→f followed by a reversed path from f to q1 with the label wR exists, which means wR∈L(N). So L(N)=L1R. □
The reversed machine is nondeterministic: a state can have several incoming transitions on one symbol in M1, and F1 can have several states.
Part 6: homomorphism
A homomorphism is a map h:Σ∗→Δ∗ with h(xy)=h(x)h(y) for all x,y. It is fixed by the strings h(a) for a∈Σ, since h(a1⋯am)=h(a1)⋯h(am) and h(ε)=ε. For a language L, h(L)={h(w):w∈L}.
Claim. If L⊆Σ∗ is regular, then h(L)⊆Δ∗ is regular.
Proof. By Kleene's theorem L=L(E) for a regular expression E over Σ. Let h(E) be the expression over Δ obtained by replacing each occurrence of a symbol a with an expression for the one string h(a): the concatenation of its symbols, or ε if h(a)=ε. We show L(h(E))=h(L(E)) by structural induction on E.
- E=∅: h(∅)=∅. E=ε: h({ε})={ε}. E=a: L(h(a))={h(a)}=h({a}).
- E=E1+E2: h(A∪B)=h(A)∪h(B) for all languages A,B, by the definition of the image.
- E=E1E2: h(AB)={h(xy):x∈A,y∈B}={h(x)h(y)}=h(A)h(B).
- E=E1∗: h(Ak)=h(A)k for each k, by the previous case and induction on k, and so h(A∗)=⋃kh(Ak)=⋃kh(A)k=h(A)∗.
In each case the induction hypothesis gives the expressions for the parts. So h(L)=L(h(E)) is regular. □
Part 7: inverse homomorphism
For L⊆Δ∗, let h−1(L)={w∈Σ∗:h(w)∈L}.
Claim. If L⊆Δ∗ is regular, then h−1(L)⊆Σ∗ is regular.
Proof. Let M=(Q,Δ,δ,q0,F) be a complete DFA for L. Define M′=(Q,Σ,δ′,q0,F) with δ′(q,a)=δ∗(q,h(a)) for a∈Σ. It is a complete DFA over Σ, since δ∗ is defined for each string.
We show δ′∗(q,w)=δ∗(q,h(w)) by induction on ∣w∣. For w=ε both sides are q. For w=va, by the induction hypothesis and the lemma δ∗(q,xy)=δ∗(δ∗(q,x),y),
δ′∗(q,va)=δ′(δ∗(q,h(v)),a)=δ∗(δ∗(q,h(v)),h(a))=δ∗(q,h(v)h(a))=δ∗(q,h(va)). So w∈L(M′) if and only if δ∗(q0,h(w))∈F, if and only if h(w)∈L. □
Part 8: right quotient
For languages L and K over Σ, let L/K={x:xy∈L for some y∈K}.
Claim. If L is regular, then L/K is regular for each language K, regular or not.
Proof. Let M=(Q,Σ,δ,q0,F) be a complete DFA for L, and let F′={q∈Q:δ∗(q,y)∈F for some y∈K}. By the lemma δ∗(q0,xy)=δ∗(δ∗(q0,x),y), the DFA (Q,Σ,δ,q0,F′) accepts x if and only if some y∈K has xy∈L. □
The set F′ exists for every K, but a program can compute it only when it can decide, for each q, whether K meets {y:δ∗(q,y)∈F}. For a regular K this is an emptiness test of a product.
All eight parts together prove the theorem. ■