Kleene’s theorem and its consequences [018D]
- February 16, 2025
- Jon Sterling
We now come to the main result of this lecture.
Theorem Kleene’s theorem [018B]
- February 16, 2025
- Jon Sterling
A formal language is regular if and only if it is automatical.
Proof.
- February 16, 2025
- Jon Sterling
In light of the above, we will from now on refer mainly to regular languages, and leave behind the non-standard terminology of “automatical languages”. Several questions that we left unanswered (see Discussion [017F]) can now be addressed in light of Kleene’s theorem.
Corollary Decidability of regular expression matching [018E]
- February 16, 2025
- Jon Sterling
Let R be a regular expression over an alphabet \Sigma . Then there exists an algorithm to compute whether a given string u:\Sigma ^\star matches R.
Proof.
- February 16, 2025
- Jon Sterling
The idea of the proof is to find a DFA M satisfying \mathcal {L}{\mathopen {}\left (M\right )\mathclose {}}=\mathcal {L}{\mathopen {}\left (R\right )\mathclose {}}; so for this we need only Corollary [018A] rather than the full Kleene’s theorem. Then our algorithm is to feed the given string u through M and check whether the final state is accepting or not.
There is a subtlety in the argument above: we need the DFA M to have computably decidable equality of states. The way to deal with this is that M has a finite set of states, and so isomorphic to a standard finite set of the form \mathbb {N}_{<n}, which has computably decidable equality. A more important subtlety is that we need it to be computably decidable whether a given state is an accepting state, and we also need the transition function to be computable; any subset of a finite set is going to be decidable for roughly the same reason—ahead of time, we can enumerate it as a list of numbers in \mathbb {N}_{<n}.
Corollary Closure of regular languages under complementation [018F]
- February 16, 2025
- Jon Sterling
If L is a regular language over an alphabet \Sigma , then so is its complement \Sigma ^\star \setminus L.
Proof.
- February 16, 2025
- Jon Sterling
Let L be a regular language, and so by Kleene’s theorem we have some DFA M satisfying L=\mathcal {L}{\mathopen {}\left (M\right )\mathclose {}}. We define a new DFA \lnot {M} satisfying \mathcal {L}{\mathopen {}\left (\lnot {M}\right )\mathclose {}} = \Sigma ^\star \setminus L by setting \lnot {M} to have the same states, transition function, and starting state as M but with the opposite set of accepting states:
F_{\lnot {M}} = Q_{M}\setminus F_{M}The desired property of \lnot {M} is immediate.
Corollary Closure of regular languages under intersection [018G]
- February 16, 2025
- Jon Sterling
The intersection of two regular languages over a fixed alphabet \Sigma is regular.
Proof.
- February 16, 2025
- Jon Sterling
We fix regular languages L_1,L_2\subseteq \Sigma ^\star and consider the intersection L_1\cap L_2. By De Morgan’s laws, we have:
L_1\cap L_2 = \Sigma ^\star \setminus {\mathopen {}\left ( {\mathopen {}\left ( \Sigma ^\star \setminus L_1 \right )\mathclose {}}\cup {\mathopen {}\left ( \Sigma ^\star \setminus L_2 \right )\mathclose {}} \right )\mathclose {}}Because regular languages are closed under complementation, it suffices to check that {\mathopen {}\left ( \Sigma ^\star \setminus L_1 \right )\mathclose {}}\cup {\mathopen {}\left ( \Sigma ^\star \setminus L_2 \right )\mathclose {}} is regular. Regular languages are, by definition, closed under finite unions, so it remains to check that the complements \Sigma ^\star \setminus L_1 and \Sigma ^\star \setminus L_2 are regular. This follows from our assumption that L_1 and L_2 are regular via closure under complements.
Corollary Decidability of regular expression equivalence [018H]
- February 16, 2025
- Jon Sterling
It is decidable whether two regular expressions R,S over a fixed alphabet \Sigma are equivalent in the sense that \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}}=\mathcal {L}{\mathopen {}\left (S\right )\mathclose {}}.
Proof.
- February 16, 2025
- Jon Sterling
We note that two subsets are equal if and only if the intersection of one with the complement of the other is empty, and vice versa:
\begin {aligned} & \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}}=\mathcal {L}{\mathopen {}\left (S\right )\mathclose {}} \\ &\quad \Leftrightarrow \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}}\subseteq \mathcal {L}{\mathopen {}\left (S\right )\mathclose {}}\land \mathcal {L}{\mathopen {}\left (S\right )\mathclose {}}\subseteq \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}} \\ &\quad \Leftrightarrow {\mathopen {}\left ({\mathopen {}\left (\Sigma ^\star \setminus \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}}\right )\mathclose {}}\cap \mathcal {L}{\mathopen {}\left (S\right )\mathclose {}}\right )\mathclose {}} =\varnothing = {\mathopen {}\left ({\mathopen {}\left (\Sigma ^\star \setminus \mathcal {L}{\mathopen {}\left (S\right )\mathclose {}}\right )\mathclose {}}\cap \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}}\right )\mathclose {}} \end {aligned}We therefore let M and N be two DFAs recognising the language {\mathopen {}\left (\Sigma ^\star \setminus \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}}\right )\mathclose {}}\cap \mathcal {L}{\mathopen {}\left (S\right )\mathclose {}} and {\mathopen {}\left (\Sigma ^\star \setminus \mathcal {L}{\mathopen {}\left (S\right )\mathclose {}}\right )\mathclose {}}\cap \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}} respectively. (These DFAs can be obtained computably using the compilation procedure by which we proved Corollary [018A].) It follows then that \mathcal {L}{\mathopen {}\left (R\right )\mathclose {}}=\mathcal {L}{\mathopen {}\left (S\right )\mathclose {}} if and only if \mathcal {L}{\mathopen {}\left (M\right )\mathclose {}}=\varnothing =\mathcal {L}{\mathopen {}\left (N\right )\mathclose {}}.
So it now remains to check whether there exists any string at all that is accepted by M and likewise for N. We do not have to check all strings over \Sigma , which would be impossible: we observe that the number of states in M bounds the number of transitions required to reach an accepting state, because any loops about a state q can be excised from the path without changing the result. This is a special property of the finite automata that we have studied so far, corresponding to the fact that they have no memory.