Recall that we say the natural numbers are closed under addition because for all \(a, b \in \mathbb{N}\), also \(a + b \in \mathbb{N}\) (i.e., the sum of two natural numbers is also a natural number).
For languages, we will consider the operations:
Practically, if a class of languages is closed under \(\cup\), then knowing \(A\) and \(B\) are both in the class immediately proves \(A \cup B\) is too.
Or if you want to prove \(L\) is not DFA decidable, it might be easier to prove \(\overline{L}\) is not DFA decidable.
Strategy for proving closure: build constructions!
In general, we prove the language class decidable by a certain model is closed under an operation “\(\texttt{op}\)” by specifying algorithms for converting instances of the model into a new instance of the same model deciding a new language. \[ L(D_1)\; \texttt{op}\; L(D_2) = L(\texttt{dfa\_op\_construction}(D_1, D_2)) \]
Later on, we will relate DFA-, NFA-, regex-, and CFG-decidable languages by showing how an instance from one model can be transformed into an instance of another model deciding the same language. Example: \[ L(N) = L(D) \quad \text{where} \quad D = \texttt{nfa\_to\_dfa\_construction}(N) \hspace{5em} \]
Theorem: The class of DFA-decidable languages is closed under complement.
Proof: For any language \(A\) in this class, there is a DFA \(\, D = (Q, \Sigma, \delta, s, F)\) such that \(A = L(D)\).
We can therefore construct the DFA \(\,D_c = (Q, \Sigma, \delta, s, \fragment{Q \setminus F})\) that decides \(\overline{A}\). Upon processing a string \(x\), both DFAs end in state \(q_x \in Q\). So \({x \in \overline{A} \fragment{\iff x \notin A} \fragment{\iff q_x \notin F} \fragment{\iff q_x \in Q \setminus F.}}\)
What about closure under complement of:
True or False: Taking the complement of an NFA’s set of accept states makes it decide the complement of its original language.
\(\Longrightarrow\)
\(L(N) = \{\emptystring\}\) \(L(N_c) = \emptyset\) but \(\overline{L(N)} = \{0, 1\}^* \setminus \{\emptystring\}\)
\(\Longrightarrow\)
\(0 \in L(N)\) via \(s \transition{0} s\) \(0 \in L(N_c)\) via \(s \transition{\emptystring} q \transition{0} q\) but \(0 \notin \overline{L(N)}\)
What about closure under complement of:
How can we prove that the class of regex-decidable languages is closed under:
This is actually trivial due to the recursive regex definition!
What about intersection?
There’s no obvious algorithm to compute \(R_3\), given arbitrary regex’s \(R_1\) and \(R_2\).
Certain closure properties will be easy or hard to prove for DFAs, regexes, or NFAs. But we will show the languages decided by each model are equivalent!
To gain practice with designing constructions, let’s prove the following
Theorem: the class of DFA-decidable languages is closed under union.
In other words, if \(A = L(D_1)\) and \(B = L(D_2)\), then we must prove the existence of a DFA \(D\) such that \(A \cup B = L(D)\).
Idea: simulate \(D_1\) and \(D_2\) in parallel, and accept if either \(D_1\) or \(D_2\) accepts.
\(L(D_1) = \setbuild{a^n}{n \equiv 2 \mod 3}\)
\(L(D_2) = \setbuild{a^n}{n \equiv 1 \mod 5 \; \text{ or } \; n \equiv 4 \mod 5}\)
What do we need to keep track of to execute this simulation?
Which pair of states are the machines in?
Formally:
Let \(D_1 = (Q_1, \Sigma, \delta_1, s_1, F_1)\) and \(D_2 = (Q_2, \Sigma, \delta_2, s_2, F_2)\) be two DFAs.
We construct a new DFA \(D = (Q, \Sigma, \delta, s, F)\) to decide \(L(D_1) \cup L(D_2)\)
by simulating \(D_1\) and \(D_2\) in parallel:
Then after reading a string \(x\) that puts \(D_1\) in state \(p_1\) and \(D_2\) in state \(p_2\),
the new DFA \(D\) will be in state \((p_1, p_2)\).
We already showed that the DFA-decidable languages are closed under union:
If \(A = L(D_1)\) and \(B = L(D_2)\), then we can construct \(D\) such that \(L(D) = A \cup B\).
Formally:
What about intersection?
Theorem: the DFA-decidable languages are closed under intersection:
If \(A = L(D_1)\) and \(B = L(D_2)\), then we can construct \(D\) such that \(L(D) = A \color{red} \cap \color{black} B\).
Formally:
Just update the accept states! (Note now \(F = F_1 \times F_2\))
Theorem: the DFA-decidable languages are closed under intersection:
Under which of the following operations are DFA-decidable languages closed?
True or False: If \(A \cup B\) is DFA-decidable, then \(A\) and \(B\) are both DFA-decidable.
If \(A\) and \(B\) are DFA-decidable, then \(A \cup B\) is DFA-decidable, but the converse is not true.
\[\begin{align*} A, B \text{ are DFA-decidable} \; &\Longrightarrow \; A \cup B \text{ is DFA-decidable} \\ &\cancel{\Longleftarrow} \end{align*}\]
Let’s consider naïvely attempting concatenation for these two DFAs:
\(D_1\) \(D_2\)
If we immediately “jump” from even to q0 by redirecting the transition \(\texttt{even} \stackrel{1}{\to} \texttt{odd}\) instead to \(\texttt{even} \stackrel{1}{\to} \texttt{q0}\), then \(1111 = 111 \circ 1\) is rejected despite \(111 \in L(D_1)\) and \(1 \in L(D_2)\).
We don’t know when to transition to q0, and even if we did, we don’t know how to avoid doing it the very first time we encounter a state with a transition to q0.
The same “where and how to split?” difficulty is encountered for Kleene star.