The subset construction: equivalence of NFA\varepsilon s with DFAs [017G]
- February 11, 2025
- Jon Sterling, with contributions from Andrew Pitts, Frank Stajano
Although very few NFA\varepsilon s are NFAs and very few of those are DFAs, all these kinds of automata nonetheless generate the same classes of formal languages. In the upward direction, it is easy to see that any DFA is also an NFA with a deterministic and total transition relation, and moreover any NFA is an NFA\varepsilon with an empty \varepsilon -transition relation, and that the formal languages induced by all these agree. Conversely, it is much less obvious that we can go the other direction, i.e. that we can associate to a given NFA\varepsilon an NFA or a DFA that accepts the same formal language. That is the purpose of the subset construction which we shall study in this section.
Definition Subset construction [017T]
- February 12, 2025
- Jon Sterling
Let M be an NFA\varepsilon over an alphabet \Sigma ; we define an DFA \mathcal {P}{\mathopen {}\left (M\right )\mathclose {}} over \Sigma called the subset construction of M as follows:
- We define the set of states of \mathcal {P}{\mathopen {}\left (M\right )\mathclose {}} to be the powerset of the set of states of M. Q_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}} = \mathcal {P}{\mathopen {}\left (Q_{M}\right )\mathclose {}} = {\mathopen {}\left \{S\,\middle \vert \,S\subseteq Q_{M}\right \}\mathclose {}}
- The transition function \delta _{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}\colon \mathcal {P}{\mathopen {}\left (Q_{M}\right )\mathclose {}} \times \Sigma \to \mathcal {P}{\mathopen {}\left (Q_{M}\right )\mathclose {}} is so that a set of states S transitions along the symbol a\in \Sigma to the set of states reachable via a from some element of S: \delta _{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}{\mathopen {}\left (S,a\right )\mathclose {}} = {\mathopen {}\left \{ q':Q_{M} \,\middle \vert \, \exists q\in S\mathpunct {.} q\mathrel {\xRightarrow {a}} q' \text { in } M \right \}\mathclose {}} (Optional observation: this is a relational direct image.)
- The starting state of \mathcal {P}{\mathopen {}\left (M\right )\mathclose {}} is the set of states reachable by any number of \varepsilon -transitions from the starting state of M, i.e. the set of states reachable from s_{M} via the empty string: s_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}} = {\mathopen {}\left \{q: Q\,\middle \vert \,s_{M}\mathrel {\xRightarrow {\epsilon }}q\right \}\mathclose {}}
- An accepting set of states is one that contains an accepting state from M: F_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}} = {\mathopen {}\left \{S\subseteq Q_{M}\,\middle \vert \, \exists q\in S\mathpunct {.} q\in F_{M} \right \}\mathclose {}}
Example Example of the subset construction [017V]
- February 12, 2025
- Jon Sterling
In order to get a thorough intuition for the subset construction we will see how it acts on a sample NFA\varepsilon M over \Sigma ={\mathopen {}\left \{a,b\right \}\mathclose {}} which we draw below:
The states of \mathcal {P}{\mathopen {}\left (M\right )\mathclose {}} are all the subsets of Q_{M}:
Q_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}} = {\mathopen {}\left \{ \varnothing , {\mathopen {}\left \{q_0\right \}\mathclose {}}, {\mathopen {}\left \{q_1\right \}\mathclose {}}, {\mathopen {}\left \{q_2\right \}\mathclose {}}, {\mathopen {}\left \{q_0,q_1\right \}\mathclose {}}, {\mathopen {}\left \{q_0,q_2\right \}\mathclose {}}, {\mathopen {}\left \{q_1,q_2\right \}\mathclose {}}, {\mathopen {}\left \{q_0,q_1,q_2\right \}\mathclose {}} \right \}\mathclose {}}The starting state of \mathcal {P}{\mathopen {}\left (M\right )\mathclose {}} is the set of states reachable from q_0 via the empty string:
s_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}} = {\mathopen {}\left \{q_0,q_1,q_2\right \}\mathclose {}}The accepting states of \mathcal {P}{\mathopen {}\left (M\right )\mathclose {}} are all the sets of states containing an accepting state of M:
F_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}} = {\mathopen {}\left \{ {\mathopen {}\left \{q_2\right \}\mathclose {}}, {\mathopen {}\left \{q_2,q_0\right \}\mathclose {}}, {\mathopen {}\left \{q_2,q_1\right \}\mathclose {}}, {\mathopen {}\left \{q_2,q_1,q_0\right \}\mathclose {}} \right \}\mathclose {}}We then describe the transition function of \mathcal {P}{\mathopen {}\left (M\right )\mathclose {}} by means of a table:
| S | \delta _{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}{\mathopen {}\left (S,a\right )\mathclose {}} | \delta _{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}{\mathopen {}\left (S,b\right )\mathclose {}} |
|---|---|---|
| \varnothing | \varnothing | \varnothing |
| {\mathopen {}\left \{q_0\right \}\mathclose {}} | {\mathopen {}\left \{q_0,q_1,q_2\right \}\mathclose {}} | {\mathopen {}\left \{q_2\right \}\mathclose {}} |
| {\mathopen {}\left \{q_1\right \}\mathclose {}} | {\mathopen {}\left \{q_1\right \}\mathclose {}} | \varnothing |
| {\mathopen {}\left \{q_2\right \}\mathclose {}} | \varnothing | {\mathopen {}\left \{q_2\right \}\mathclose {}} |
| {\mathopen {}\left \{q_0,q_1\right \}\mathclose {}} | {\mathopen {}\left \{q_0,q_1,q_2\right \}\mathclose {}} | {\mathopen {}\left \{q_2\right \}\mathclose {}} |
| {\mathopen {}\left \{q_0,q_2\right \}\mathclose {}} | {\mathopen {}\left \{q_0,q_1,q_2\right \}\mathclose {}} | {\mathopen {}\left \{q_2\right \}\mathclose {}} |
| {\mathopen {}\left \{q_1,q_2\right \}\mathclose {}} | {\mathopen {}\left \{q_1\right \}\mathclose {}} | {\mathopen {}\left \{q_2\right \}\mathclose {}} |
| {\mathopen {}\left \{q_0,q_1,q_2\right \}\mathclose {}} | {\mathopen {}\left \{q_0,q_1,q_2\right \}\mathclose {}} | {\mathopen {}\left \{q_2\right \}\mathclose {}} |
All in all, we have the following DFA:
As you can see, the resulting DFA is kind of strange and has many redundant states. But it does accept the desired language.
The goal of Definition [017T] is to transform an NFA\varepsilon M into a DFA \mathcal {P}{\mathopen {}\left (M\right )\mathclose {}} that accepts the same language, i.e. that \mathcal {L}{\mathopen {}\left (\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}\right )\mathclose {}}=\mathcal {L}{\mathopen {}\left (M\right )\mathclose {}}. We prove this in two steps below.
Lemma Soundness of the subset construction [00OD]
- February 9, 2024
- Jon Sterling, with contributions from Frank Stajano, Andrew Pitts
Let M be an NFA\varepsilon ; then \mathcal {L}{\mathopen {}\left (\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}\right )\mathclose {}}\subseteq \mathcal {L}{\mathopen {}\left (M\right )\mathclose {}}.
Proof.
- February 9, 2024
- Jon Sterling
We must show that any string u\in \mathcal {L}{\mathopen {}\left (\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}\right )\mathclose {}} lies in \mathcal {L}{\mathopen {}\left (M\right )\mathclose {}}.
Case. Empty string
- February 9, 2024
- Jon Sterling
If u=\epsilon , then by definition we have s_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}\in F_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}} and so by definition, there exists q\in s_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}} such that q\in F_{M}. By definition of s_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}, we therefore have s\mathrel {\xRightarrow {\epsilon }}q; because q\in F_{M}, we have \epsilon \in \mathcal {L}{\mathopen {}\left (M\right )\mathclose {}}.
Case. Non-empty string
- February 9, 2024
- Jon Sterling
Suppose on the other hand that u=a_1\cdots a_n, and so we therefore have transitions s_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}\mathrel {\xrightarrow {a_1}}S_1\mathrel {\xrightarrow {\ldots }}S_{n-1}\mathrel {\xrightarrow {a_n}}S_n with S_n\in F_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}, and so there exists some q_n\in S_n\cap F_{M}. Define S_0 = s_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}.
By definition of \mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}, from the transition S_{n-1}\mathrel {\xrightarrow {a_n}}S_n we may find some q_{n-1}\in S_{n-1} such that q_{n-1}\mathrel {\xRightarrow {a_n}}q_n. Iterating this process, we may find states q_i\in S_{i} such that we have a sequence of transitions q_{i-1}\mathrel {\xRightarrow {a_i}}q_i in M; thus we have a sequence of transitions q_0\mathrel {\xRightarrow {u}}q_n. Because q_0\in S_0=s_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}, we have s_{M}\mathrel {\xRightarrow {\epsilon }}q_0 and thus s_{M}\mathrel {\xRightarrow {\epsilon }}q_0\mathrel {\xRightarrow {u}}q_n and therefore s_{M}\mathrel {\xRightarrow {u}} q_n. Because q_n\in F_{M}, we are done.
Lemma Completeness of the subset construction [00OE]
- February 9, 2024
- Jon Sterling
Let M be an NFA\varepsilon ; then \mathcal {L}{\mathopen {}\left (M\right )\mathclose {}}\subseteq \mathcal {L}{\mathopen {}\left (\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}\right )\mathclose {}}.
Proof.
- February 9, 2024
- Jon Sterling
We must show that any string u\in \mathcal {L}{\mathopen {}\left (M\right )\mathclose {}} lies in \mathcal {L}{\mathopen {}\left (\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}\right )\mathclose {}}.
Case. Empty string
- February 9, 2024
- Jon Sterling
If u=\epsilon , then we have assumed that s_{M}\xRightarrow {\epsilon }q such that q\in F_{M}; therefore, by definition, we have q\in s_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}. Thus we have q\in s_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}\cap F_{M} and so it follows by definition that s_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}\in F_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}.
Case. Non-empty string
- February 9, 2024
- Jon Sterling
Suppose that u=a_1\cdots a_n, and so we have transitions s_{M}\xRightarrow {a_1}q_1\xRightarrow {\cdots } q_{n-1}\xRightarrow {a_n}q_n with q_n\in F_{M}.
We inductively define a sequence of states S_i in \mathcal {P}{\mathopen {}\left (M\right )\mathclose {}} as follows:
\begin {aligned} S_0 &= s_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}\\ S_{k+1} &= \delta _{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}{\mathopen {}\left (S_k,a_{k+1}\right )\mathclose {}} \end {aligned}Define q_0=s_{M}. Then for all 0\leq i \leq n, we observe that we have q_i\in S_i.
Subproof.
- February 9, 2024
- Jon Sterling
We proceed by induction on i. For i=0, we need s_{M}\in s_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}; but this holds by definition. Next, assuming q_i\in S_i we must show that q_{i+1}\in S_{i+1} = \delta _{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}{\mathopen {}\left (S_i,a_{i+1}\right )\mathclose {}}. Unfolding definitions, this follows from the transition q_i\xRightarrow {a_{i+1}} q_{i+1} that we have assumed, as our inductive hypothesis ensures q_i\in S_i.
It follows from the above that we have transitions S_0=s_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}\xrightarrow {a_1}S_1\xrightarrow {\cdots }S_{n-1}\xrightarrow {a_n}S_n. Because we have shown q_n\in S_n and we have assumed q_n\in F_{M}, we have S_n\in F_{\mathcal {P}{\mathopen {}\left (M\right )\mathclose {}}}. Thus it follows that \mathcal {P}{\mathopen {}\left (M\right )\mathclose {}} accepts u.
Corollary Equivalence between NFA\varepsilon s, NFAs, and DFAs [017U]
- February 12, 2025
- Jon Sterling
NFA\varepsilon s, NFAs, and DFAs all generate the same class of languages.
Proof.
- February 12, 2025
- Jon Sterling
In Lemma [00OD] and Lemma [00OE], we have proved that NFA\varepsilon s and DFAs generate the same class of language as any NFA\varepsilon can be converted into a DFA recognising the same language. As any NFA is in particular an NFA\varepsilon , we see that NFAs are equivalent to DFAs in the same sense.