Introduction

Regular languages are closed under a rich family of operations: Boolean operations, concatenation, star, reverse, homomorphisms and inverse homomorphisms. They also have decidable emptiness, membership, finiteness and equivalence. These facts let you build new regular languages from old ones and answer yes/no questions about DFAs and regular expressions algorithmically.

The skills are the constructions (especially product automata and complement by flipping finals) and knowing which properties remain decidable when you move to context-free languages (many do not).

Prerequisites

Core concepts

Closure properties (summary table)

If LL and MM are regular, so are:

OperationConstruction idea
L∪ML \cup MProduct with accept when either accepts; or NFA ε\varepsilon-union; or RE sum
L∩ML \cap MProduct with accept when both accept
L‾\overline{L}Same DFA, flip accepting/non-accepting (DFA must be complete)
LMLMNFA: link accepts of LL to start of MM by ε\varepsilon
L∗L^*NFA star construction (Thompson)
LRL^RReverse edges, swap start/accept (NFA; then determinize)
h(L)h(L)Homomorphism: replace each edge label aa by a path reading h(a)h(a)
h−1(L)h^{-1}(L)Inverse homomorphism: on aa follow the path that h(a)h(a) would take in the DFA for LL

Difference. L∖M=L∩M‾L \setminus M = L \cap \overline{M} is regular. Symmetric difference likewise.

Further operations that preserve regularity

OperationDefinitionWhy regular
Right quotient L/ML / M{x∣xy∈L for some y∈M}\{x \mid xy \in L \text{ for some } y \in M\}DFA for LL, accept at qq iff some y∈My \in M leads from qq to FF; true for any MM, even non-regular
Left quotient M\LM \backslash L{y∣xy∈L for some x∈M}\{y \mid xy \in L \text{ for some } x \in M\}reverse, take right quotient, reverse
Prefixes Pref(L)\mathrm{Pref}(L)all prefixes of strings in LLaccept every state that can reach FF
Suffixes, substringsall suffixes or factorsSuffixes: new epsilon-start to every reachable useful state, retaining original finals. Factors: additionally make every useful state accepting
Substitution by regular languagesreplace each aa by a regular LaL_asubstitute LaL_a for aa in the expression
half(L)\mathrm{half}(L){x∣xy∈L,∣x∣=∣y∣}\{x \mid xy \in L, \lvert x \rvert = \lvert y \rvert\}product of a forward and a guessed backward run
Finite union, finite intersectionrepeat the binary constructions

Operations that do not preserve regularity.

  • Infinite union. Each {anbn}\{a^n b^n\} is finite, hence regular, but ⋃n≥0{anbn}\bigcup_{n \ge 0} \{a^n b^n\} is not regular. Closure holds only for finitely many operands.
  • Subset. {anbn}⊆{a,b}∗\{a^n b^n\} \subseteq \{a,b\}^*; a subset of a regular language can be anything.
  • Going backwards. L1∪L2L_1 \cup L_2 regular does not make L1,L2L_1, L_2 regular (take L2=L1‾L_2 = \overline{L_1} for a non-regular L1L_1); L1L2L_1 L_2 regular does not either; L∗L^* can be regular when LL is not (for L={ap∣p prime}L = \{a^p \mid p \text{ prime}\}, L∗={ε}∪{an∣n≥2}L^* = \{\varepsilon\} \cup \{a^n \mid n \ge 2\}).
  • Regular with non-regular. R∩NR \cap N and R∪NR \cup N can go either way. ∅∩N=∅\emptyset \cap N = \emptyset is regular; Σ∗∩N=N\Sigma^* \cap N = N is not.

Using closure to prove non-regularity

If LL were regular, then L∩RL \cap R, L‾\overline{L} and h(L)h(L) would be regular for every regular RR and homomorphism hh. So reduce to a known non-regular language:

  • L=={w∈{a,b}∗∣#a(w)=#b(w)}L_{=} = \{ w \in \{a,b\}^* \mid \#_a(w) = \#_b(w) \}: L=∩a∗b∗={anbn}L_{=} \cap a^* b^* = \{a^n b^n\}, not regular, so L=L_{=} is not regular.
  • L≠={anbm∣n≠m}L_{\ne} = \{ a^n b^m \mid n \ne m \}: L≠‾∩a∗b∗={anbn}\overline{L_{\ne}} \cap a^* b^* = \{a^n b^n\}, so L≠L_{\ne} is not regular. This is far shorter than pumping L≠L_{\ne} directly, where every decomposition seems to survive.
  • By contrast {anbm∣n+m even}\{a^n b^m \mid n + m \text{ even}\} is a∗b∗a^* b^* intersected with the even-length strings, so it is regular. Counting two things against each other breaks regularity; checking a parity does not.

Decision properties

Given a DFA (or RE/NFA converted to DFA):

QuestionDecidable?Method
Is w∈Lw \in L?yesRun the DFA
Is L=∅L = \emptyset?yesReachability from start to some accept state
Is L=Σ∗L = \Sigma^*?yesEmptiness of the complement
Is LL finite?yesIn the DFA, after removing dead/unreachable states, check for a cycle on a path from start to an accept
Is L=ML = M?yesEmptiness of symmetric difference, or minimize both and compare
Is L⊆ML \subseteq M?yesEmptiness of L∖ML \setminus M

All of the above are decidable in time polynomial in the DFA size for standard formulations used in GATE.

How it works

Product construction for intersection

DFAs M1=(Q1,Σ,δ1,q1,F1)M_1 = (Q_1,\Sigma,\delta_1,q_1,F_1) and M2=(Q2,Σ,δ2,q2,F2)M_2 = (Q_2,\Sigma,\delta_2,q_2,F_2). Product:

Q=Q1×Q2,δ((p,r),a)=(δ1(p,a),δ2(r,a)),start (q1,q2),Q = Q_1 \times Q_2, \quad \delta((p,r),a) = (\delta_1(p,a),\delta_2(r,a)), \quad \text{start } (q_1,q_2),

accept F1×F2F_1 \times F_2 for intersection, or (F1×Q2)∪(Q1×F2)(F_1 \times Q_2) \cup (Q_1 \times F_2) for union.

Complement pitfall

Flipping finals works only on a total DFA. If you flip an NFA's finals, you do not get the complement. Always determinize (and complete) first.

Product automaton for intersection of even-length and ends-with-1
Figure 1. Product DFA for even-length strings intersected with strings ending in 1; states are pairs (parity, last-bit), and only (even,1) accepts.

Algorithms and pseudocode

Text
INTERSECT(M1, M2)
1  build product with F <- F1 x F2
2  return reachable component from (q1,q2)

EQUIVALENT(M1, M2)
1  M <- INTERSECT(M1, COMPLEMENT(M2)) union INTERSECT(COMPLEMENT(M1), M2)
2  return EMPTY(M)

FINITE(M)
1  remove unreachable states from start and states that cannot reach an accept
2  return whether the remaining graph is acyclic

Mathematical explanation

Why complement needs determinism

An NFA accepts if some path accepts. The language of paths that all reject is a universal condition, which an NFA (existential) cannot express by merely swapping finals. Example: NFA for strings ending with 0; flipping finals does not yield "does not end with 0".

Homomorphism

A homomorphism h:Σ∗→Γ∗h: \Sigma^* \to \Gamma^* is determined by h(a)h(a) for a∈Σa \in \Sigma and extended by h(uv)=h(u)h(v)h(uv)=h(u)h(v), h(ε)=εh(\varepsilon)=\varepsilon. Regular languages are closed under hh and under h−1h^{-1}. Inverse homomorphism is especially useful in proofs that a language is regular: express it as h−1h^{-1} of a known regular language.

Worked examples

Example 1: even length ∩\cap ends with 1

DFA even: states E/O. DFA ends-with-1: S/T. Product accept only (E,T). Strings: 01 length 2 ends with 1, accept; 1 length 1, reject; 11 length 2 ends with 1, accept; 0 reject.

Example 2: equivalence via minimization

Two DFAs for "ends with 0" that differ by unreachable states become identical after minimize; EQUIVALENT returns true.

Example 3: reverse of 0*1

L=L(0∗1)L = L(0^* 1). Then LR=L(10∗)L^R = L(1 0^*). Construction: reverse the obvious 2-state NFA and determinize.

Example 4: finiteness

L(a∗)L(a^*) has a cycle through an accept state: infinite. L(a+aa)L(a+aa) as a DFA has no cycle among useful states: finite (two nonempty strings plus optionally ε\varepsilon if present). Language {a,aa}\{a,aa\} is finite.

Example 5: quotient and inverse homomorphism

Quotient: L=(ab)∗L = (ab)^* and M={b}M = \{b\}. Then L/M={x∣xb∈(ab)∗}=(ab)∗aL / M = \{x \mid xb \in (ab)^*\} = (ab)^* a. With M=b∗M = b^* the quotient also contains LL itself (take y=εy = \varepsilon): L/b∗=(ab)∗+(ab)∗aL / b^* = (ab)^* + (ab)^* a.

Inverse homomorphism: let h(0)=abh(0) = ab, h(1)=εh(1) = \varepsilon and L=(ab)∗L = (ab)^*. Every h(w)h(w) is (ab)k(ab)^k with k=#0(w)k = \#_0(w), so h−1(L)={0,1}∗h^{-1}(L) = \{0,1\}^*. With L′=(ab)(ab)L' = (ab)(ab) (exactly two copies), h−1(L′)={w∣#0(w)=2}=1∗01∗01∗h^{-1}(L') = \{ w \mid \#_0(w) = 2 \} = 1^* 0 1^* 0 1^*.

Example 6: the finiteness test by lengths

For a DFA with nn states, LL is infinite iff LL contains a string ww with n≤∣w∣<2nn \le |w| < 2n. For the 2-state "even length" DFA, ab has length 2 in [2,4)[2, 4): infinite. For a minimal DFA of {a,aa}\{a, aa\} (4 states with the dead state), no accepted string has length in [4,8)[4, 8): finite. This turns the cycle test into a bounded membership search.

Example 7: non-closure red herrings

Regular languages are closed under the operations above. Do not confuse them with CFLs (not closed under intersection or complement). Keep the tables separate.

Important properties and observations

  • Closure under complement + union yields closure under all Boolean operations.
  • Decision procedures assume an effective representation (DFA/NFA/RE); an arbitrary set given only as a black box is a different story.
  • Product of nn-state and mm-state DFAs has at most nmnm states.
  • Completing a partial DFA adds at most one dead sink.

Common misconceptions.

  • Flipping NFA finals for complement.
  • Claiming equivalence of regular languages is undecidable (it is decidable; CFL equivalence is undecidable).
  • Thinking intersection of regular languages may leave the class (it does not).

GATE examination perspective

  • PRODUCT DRILLS. Draw both union and intersection accept conditions.
  • COMPLEMENT ON DFA ONLY. State the completeness assumption.
  • DECIDABILITY CONTRAST. Regular: equivalence decidable. CFL: equivalence undecidable. RE (r.e.): emptiness undecidable.
  • FINITE VS INFINITE. Look for cycles that can pump a nonempty string inside an accepting path, or use the length window [n,2n)[n, 2n).
  • FINITE OPERANDS ONLY. Closure under union and intersection is for finitely many languages; an infinite union of regular languages can be any language.
  • "IF L1∪L2L_1 \cup L_2 IS REGULAR THEN ...". Statements that infer regularity of the parts from the whole are false; look for a complement pair.
  • QUOTIENT. L/ML / M is regular for regular LL and any MM; the construction may not be effective when MM is not regular, but the language is still regular.
  • CLOSURE AS A PROOF TOOL. Intersect with a∗b∗a^* b^* or complement to reach anbna^n b^n; it is usually shorter than pumping.
  • FULL CROSS-CLASS TABLE. Closure across regular, DCFL, CFL, CSL, recursive and RE languages, with counterexamples, is collected in Closure and Decision Properties of CFLs.

Summary

Sources

  1. J. E. Hopcroft, R. Motwani, J. D. Ullman, Introduction to Automata Theory, Languages, and Computation, 3rd ed., Pearson Addison-Wesley, Section 4.2 (closure under Boolean operations, reversal, homomorphisms, inverse homomorphisms), Section 4.3 (decision properties: emptiness, membership), Section 4.4.2 (testing equivalence of regular languages).
  2. M. Sipser, Introduction to the Theory of Computation, 3rd ed., Cengage Learning: Section 1.1 (the regular operations), Section 1.2 (closure under the regular operations), Section 4.1 (decidable problems concerning regular languages).
  3. P. Linz, An Introduction to Formal Languages and Automata, 6th ed., Jones & Bartlett Learning: Section 4.1 (closure properties of regular languages, including closure under other operations), Section 4.2 (elementary questions about regular languages).

Next steps