Compiling a regular expression to an NFA [0184]
- February 14, 2025
- Jon Sterling
We aim to show that every regular language is automatical. The rule induction principle for regular expressions implies that the regular languages are the smallest class of formal languages closed under unions, concatenation, repetition, single symbols, the empty string, and the empty language. Therefore, to prove our desired theorem it will suffice to show that the automatical languages are closed under the same constructions.
Lemma Automaticality of basic regular languages [0186]
- February 14, 2025
- Jon Sterling
Let \Sigma be an alphabet. Then the basic regular languages {\mathopen {}\left \{a\right \}\mathclose {}} = \mathcal {L}{\mathopen {}\left (a\right )\mathclose {}} for a:\Sigma , and {\mathopen {}\left \{\epsilon \right \}\mathclose {}} = \mathcal {L}{\mathopen {}\left (\underline {\epsilon }\right )\mathclose {}}, and \varnothing = \mathcal {L}{\mathopen {}\left (\varnothing \right )\mathclose {}} are all automatical.
Proof.
- February 14, 2025
- Jon Sterling
Lemma Closure of automaticality under union [0187]
- February 14, 2025
- Jon Sterling
If L_1 and L_2 are automatical languages over a common alphabet \Sigma , then so is their union L_1\cup L_2.
Proof.
- February 14, 2025
- Jon Sterling
Let M_1 and M_2 be finite automata with \mathcal {L}{\mathopen {}\left (M_i\right )\mathclose {}}=L_i; without loss of generality, we assume these have disjoint sets of states. We shall describe an NFA\varepsilon M with \mathcal {L}{\mathopen {}\left (M\right )\mathclose {}}=\mathcal {L}{\mathopen {}\left (M_1\right )\mathclose {}}\cup \mathcal {L}{\mathopen {}\left (M_2\right )\mathclose {}}.
We define an accepting state of M above to be either an accepting state of M_1 or of M_2. F_{M} = F_{M_1}\cup F_{M_2}
That \mathcal {L}{\mathopen {}\left (M\right )\mathclose {}}=\mathcal {L}{\mathopen {}\left (M_1\right )\mathclose {}}\cup \mathcal {L}{\mathopen {}\left (M_2\right )\mathclose {}} holds follows by a quick inspection: indeed, if u\in \mathcal {L}{\mathopen {}\left (M_i\right )\mathclose {}} then we have a path in M_i from \star {M_i} to an accepting state in M_i, which we can extend by means of either \varepsilon -transition to a path in M. Conversely, any from q_0 to an accepting state of M must either be a path to an accepting state of some M_i and must therefore pass through one of the two \varepsilon -transitions. Chop off that transition to get a valid path in either M_1 or M_2.
That \mathcal {L}{\mathopen {}\left (M\right )\mathclose {}}=\mathcal {L}{\mathopen {}\left (M_1\right )\mathclose {}}\mathcal {L}{\mathopen {}\left (M_2\right )\mathclose {}} holds by inspection.
Lemma Closure of automaticality under concatenation [0188]
- February 14, 2025
- Jon Sterling
If L_1 and L_2 are automatical languages over a common alphabet \Sigma , then so is their concatenation L_1L_2, which we defined below:
L_1L_2 = {\mathopen {}\left \{uv :\Sigma ^\star \,\middle \vert \,u\in L_1, v\in L_2\right \}\mathclose {}}Proof.
- February 14, 2025
- Jon Sterling
Let M_1 and M_2 be finite automata with \mathcal {L}{\mathopen {}\left (M_i\right )\mathclose {}}=L_i; without loss of generality, we assume that these have disjoint sets of states. We shall describe an NFA\varepsilon M with \mathcal {L}{\mathopen {}\left (M\right )\mathclose {}}=\mathcal {L}{\mathopen {}\left (M_1\right )\mathclose {}}\mathcal {L}{\mathopen {}\left (M_2\right )\mathclose {}}; in particular, we lay out M_1 and M_2 side by side and draw an \varepsilon -transition from every accepting node of M_1 to the staring node of M_2.
The starting node of M is that of M_1 and the accepting nodes of M are those of M_2.
That \mathcal {L}{\mathopen {}\left (M\right )\mathclose {}}=\mathcal {L}{\mathopen {}\left (M_1\right )\mathclose {}}\mathcal {L}{\mathopen {}\left (M_2\right )\mathclose {}} holds by inspection.
Lemma Closure of automaticality under repetition [0189]
- February 14, 2025
- Jon Sterling
If L is an automatical language over a given alphabet \Sigma , then so is the repetition L^\star of L, which we define below in terms of concatenation:
L^\star = {\mathopen {}\left \{\epsilon \right \}\mathclose {}} \cup L \cup LL \cup \ldots = \bigcup _{n:\mathbb {N}} {\mathopen {}\left \{u_1\ldots u_n\,\middle \vert \,u_i\in L\right \}\mathclose {}}Proof.
- February 14, 2025
- Jon Sterling
Let M be a finite automaton with \mathcal {L}{\mathopen {}\left (M\right )\mathclose {}}=L. We shall describe an NFA\varepsilon M^\star satisfying \mathcal {L}{\mathopen {}\left (M^\star \right )\mathclose {}}=L^\star ; we take M and add a new starting state q_0 with an \varepsilon -transition to the old starting state, and then we make an \epsilon -transition from every old accepting state back to q_0.
The only accepting state of M^\star is q_0.
It holds by inspection that \mathcal {L}{\mathopen {}\left (M^\star \right )\mathclose {}}=\mathcal {L}{\mathopen {}\left (M\right )\mathclose {}}^\star .
Corollary All regular languages are automatical [018A]
- February 16, 2025
- Jon Sterling
If a language L is regular, then it is automatical.
Proof.
- February 16, 2025
- Jon Sterling
Let U be the set of all regular expressions R over a fixed alphabet \Sigma such that \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}} is automatical. We wish to show that the set of all regular expressions over \Sigma is contained in U. By rule induction it suffices to check the following cases:
- We need to know that \texttt {Sym}_{a},\texttt {Null}, \texttt {Never} \in U, which is the same as to say that the languages {\mathopen {}\left \{a\right \}\mathclose {}}, {\mathopen {}\left \{\epsilon \right \}\mathclose {}}, \varnothing are all automatical. This is Lemma [0186].
- We need to show that if R,S\in U then \texttt {Union}{\mathopen {}\left (R,S\right )\mathclose {}}\in U, which is to say that the language \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}}\cup \mathcal {L}{\mathopen {}\left (S\right )\mathclose {}} is automatical assuming that \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}} and \mathcal {L}{\mathopen {}\left (S\right )\mathclose {}} are. This is Lemma [0187].
- We need to show that if R,S\in U then \texttt {Concat}{\mathopen {}\left (R,S\right )\mathclose {}}\in U, which is to say that the language \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}}\mathcal {L}{\mathopen {}\left (S\right )\mathclose {}} = {\mathopen {}\left \{uv\,\middle \vert \,u\in \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}},v\in \mathcal {L}{\mathopen {}\left (S\right )\mathclose {}}\right \}\mathclose {}} is automatical assuming that \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}} and \mathcal {L}{\mathopen {}\left (S\right )\mathclose {}} are. This is Lemma [0188].
- We need to show that if R\in U then so is \texttt {Star}{\mathopen {}\left (R\right )\mathclose {}}\in U, which is to say that if \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}} is automatical then so is \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}}^\star . This is Lemma [0189].
We are done.