Title

ECS 120 Theory of Computation
Closure of NFA-decidable Languages, the Proofs
Julian Panetta
University of California, Davis

Closure of NFA-decidable Languages, the Proofs

  • Last lecture we gave example constructions showing the closure of NFA-decidable languages under:
  • Union: \(L_1 \cup L_2 = \setbuild{w \in \Sigma^*}{w \in L_1 \text{ or } w \in L_2}\)
  • Concatenation: \(L_1 L_2 = \setbuild{w_1 w_2}{w_1 \in L_1 \text{ and } w_2 \in L_2}\)
  • Kleene Star: \(L^* = \setbuild{w_1 w_2 \ldots w_k}{k \geq 0 \text{ and } w_i \in L}\)
  • Today we’ll give the general constructions and formally prove these closure properties.
  • We won’t prove closure under intersection or complement.
    • Intersection can be done using the product construction (no easier than for DFAs).
    • Complement is trickier than the DFA case.
    • Both of these follow immediately from the closure of DFA-decidable languages when we show equivalence of NFA- and DFA-decidability.

Closure of NFA-decidable Languages Under Union

Theorem: the NFA-decidable languages are closed under union:
If \(L_1 = L(N_1)\) and \(L_2 = L(N_2)\), then we can construct \(N\) such that \(L(N) = L_1 \cup L_2\).

Proof:

14ad971f-b692-4b7e-a4ad-820aa1632f9c q0 q0 14ad971f-b692-4b7e-a4ad-820aa1632f9c->q0 q1 q1 q0->q1 a q2 q2 q1->q2 a q2->q0 a 256017fc-a024-4432-b0d9-d583617d8e86 q0 q0 256017fc-a024-4432-b0d9-d583617d8e86->q0 q1 q1 q0->q1 a q2 q2 q1->q2 a q3 q3 q2->q3 a q4 q4 q3->q4 a q4->q0 a q0 q0 q1 q1 q0->q1 a q0->q1 q0->q1 q2 q2 q1->q2 a q2->q0 a 256017fc-a024-4432-b0d9-d583617d8e86 256017fc-a024-4432-b0d9-d583617d8e86->q0 q0->q1 a q1->q2 a q2->q3 a q3->q4 a q4->q0 a
  • Let \(N_1 = (Q_1, \Sigma, \Delta_1, s_1, F_1)\) and
    \(\phantom{Let }N_2 = (Q_2, \Sigma, \Delta_2, s_2, F_2)\) with \(Q_1 \cap Q_2 = \emptyset\)
  • Construct \(N = (Q, \Sigma, \Delta, s, F)\):
    • \(Q = \fragment{Q_1 \cup Q_2} \fragment{\cup \{s\}}\)
    • \(F = \fragment{F_1 \cup F_2}\)
    • For all \(q \in Q\) and \(a \in \Sigma_\emptystring\): \[ \Delta(q, a) = \begin{cases} \fragment{\Delta_1(q, a)} & \fragment{\text{if } q \in Q_1} \\ \fragment{\Delta_2(q, a)} & \fragment{\text{if } q \in Q_2} \\ \fragment{\{s_1, s_2\}} & \fragment{\text{if } q = s \text{ and } a = \emptystring} \\ \fragment{\emptyset} & \fragment{\text{otherwise}} \end{cases} \]

Alternatively: the set of transitions \(\Delta\) for \(N\) is the union \(\Delta_1 \cup \Delta_2 \cup \{s \stackrel{\emptystring}{\rightarrow} s_1, s \stackrel{\emptystring}{\rightarrow} s_2 \}\).

Closure of NFA-decidable Languages Under Union

Theorem: the NFA-decidable languages are closed under union:
If \(L_1 = L(N_1)\) and \(L_2 = L(N_2)\), then we can construct \(N\) such that \(L(N) = L_1 \cup L_2\).

Proof:

data/images/nfa/nfa_union.svg
  • We now formally prove \(L(N) = L_1 \cup L_2\).
    • \(L_1 \cup L_2 \subseteq L(N) \quad \quad \big(w \in L_1 \cup L_2 \implies w \in L(N)\big)\)
      • Suppose that \(w \in L_1\). Then there exists a computation sequence starting at \(s_1\) (\(q_0\) in example on right) and ending at an accept state in \(F_1\).
      • We extend this into a sequence for \(N\) by prepending the start state \(s\). Since \(F_1 \subseteq F\) this sequence shows \(N\) accepts \(w\).
      • Thus \(w \in L_1 \implies w \in L\).
      • The same argument works for \(w \in L_2\), so \(w \in L_2 \implies w \in L\).
      • Combining both, we have \(w \in L_1 \cup L_2 \implies w \in L(N)\).
    • \(L(N) \subseteq L_1 \cup L_2 \quad \quad \big(w \in L(N) \implies w \in L_1 \cup L_2\big)\)
      • When \(w \in L(N)\) there exists a computation sequence \(s, r_0, r_2, \ldots, r_n\) where either \((r_0 = s_1) \land (r_i \in Q_1) \land (r_n \in F_1)\) or \((r_0 = s_2) \land (r_i \in Q_2) \land (r_n \in F_2)\).
      • Then \(r_0, r_2, \ldots, r_n\) is a computational sequence accepting \(w\) for either \(N_1\) or \(N_2\).

Closure of NFA-decidable Languages Under Concatenation

Theorem: the NFA-decidable languages are closed under concatenation:
If \(L_1 = L(N_1)\) and \(L_2 = L(N_2)\), then we can construct \(N\) such that \(L(N) = L_1 \circ L_2\).

d26f7849-df09-4d93-91c3-925ca4118297 q0 q0 d26f7849-df09-4d93-91c3-925ca4118297->q0 q0->q0 0 q1 q1 q0->q1 1 q1->q0 1 q2 q2 q1->q2 0 q2->q1 0 q2->q2 1 ba978f6c-6209-416b-8526-f6d2876fc697 r0 r0 ba978f6c-6209-416b-8526-f6d2876fc697->r0 r0->r0 0 r1 r1 r0->r1 1 r1->r0 1 r2 r2 r1->r2 0 r2->r1 0 r2->r2 1 d26f7849-df09-4d93-91c3-925ca4118297 q0 d26f7849-df09-4d93-91c3-925ca4118297->q0 q0->q0 0 q1 q0->q1 1 q1->q0 1 q2 q2 q1->q2 0 q2->q1 0 q2->q2 1 r0 r0 ba978f6c-6209-416b-8526-f6d2876fc697 ba978f6c-6209-416b-8526-f6d2876fc697->r0 r0->r0 0 r1 r1 r0->r1 1 r1->r0 1 r2 r2 r1->r2 0 r2->r1 0 r2->r2 1 odd ->even odd ->even

Proof:

  • Let \(N_1 = (Q_1, \Sigma, \Delta_1, s_1, F_1)\) and
    \(\phantom{Let }N_2 = (Q_2, \Sigma, \Delta_2, s_2, F_2)\) with \(Q_1 \cap Q_2 = \emptyset\)
  • Construct \(N = (Q, \Sigma, \Delta, s, F)\):
    • \(Q = \fragment{Q_1 \cup Q_2}\)
    • \(s = \fragment{s_1}\)
    • \(F = \fragment{F_2}\)
    • For all \(q \in Q\) and \(a \in \Sigma_\emptystring\): \[ \Delta(q, a) = \begin{cases} \Delta_1(q, a) & \text{if } (q, a) \in Q_1 \times \Sigma_\emptystring \setminus F_1 \times \{\varepsilon\} \\ \Delta_2(q, a) & \text{if } q \in Q_2 \\ \Delta_1(q, a) \cup \{s_2\} & \text{if } q \in F_1 \text{ and } a = \emptystring \end{cases} \]

Alternatively: the set of transitions \(\Delta\) for \(N\) is the union \(\Delta_1 \cup \Delta_2 \cup \setbuild{q \stackrel{\emptystring}{\rightarrow} s_2}{q \in F_1}\).

Closure of NFA-decidable Languages Under Concatenation

Theorem: the NFA-decidable languages are closed under concatenation:
If \(L_1 = L(N_1)\) and \(L_2 = L(N_2)\), then we can construct \(N\) such that \(L(N) = L_1 \circ L_2\).

Proof:

data/images/nfa/concatenation_ex2.static.svg
  • We now formally prove \(L(N) = L_1 \circ L_2\).
    • \(L_1 \circ L_2 \subseteq L(N) \quad \big(w \in L_1 \circ L_2 \implies w \in L(N)\big)\)
      • Suppose that \(w \in L_1 \circ L_2\). Then \(w = x y\) where \(x \in L_1\) and \(y \in L_2\).
      • Then there are computation sequences:
        • \(s_1, r_2, \ldots, r_n\) for \(N_1\) accepting \(x\) (with \(r_n \in F_1)\)
        • \(s_2, t_2, \ldots, t_m\) for \(N_2\) accepting \(y\) (with \(t_m \in F_2)\)
      • We can combine these into the (accepting) computation sequence for \(N\) on \(w\) \[s_1, r_2, \ldots, r_n, s_2, t_2, \ldots, t_m\] using the transition \(r_n \stackrel{\emptystring}{\to} s_2\).
      • Since \(s = s_1\) and \(t_m \in F\), this sequence proves that \(N\) accepts \(w\).

Closure of NFA-decidable Languages Under Concatenation

Theorem: the NFA-decidable languages are closed under concatenation:
If \(L_1 = L(N_1)\) and \(L_2 = L(N_2)\), then we can construct \(N\) such that \(L(N) = L_1 \circ L_2\).

Proof:

data/images/nfa/concatenation_ex2.static.svg
  • \(L(N) \subseteq L_1 \circ L_2 \ \big(w \in L(N) \implies w \in L_1 \circ L_2\big)\)
    • Suppose \(w \in L(N)\). Then there exists a
      computational sequence \((r_0 = s), r_1,, r_2, \ldots, (r_n \in F)\)
    • By construction, all paths through \(N\) reaching a
      state in \(F\) must take an \(\varepsilon\) transition from \(r_k \in F_1\) to \(s_2\).
    • Thus, we can split the sequence into two parts: \((r_0 = s_1), \ldots, r_k\) and \((r_{k + 1} = s_2), \ldots, r_n\).
      • \(r_0, \ldots, r_k\) is an accepting sequence for \(N_1\) on \(x \prefix w\) \(\fragment{\implies x \in L_1}\)
      • \(r_{k + 1}, \ldots, r_n\) is an accepting sequence for \(N_2\) on the remaining part \(y\) of \(w\) \(\fragment{\implies y \in L_2}\)
    • Thus, \(w = x y\) where \(x \in L_1\) and \(y \in L_2\), meaning \(w \in L_1 \circ L_2\).

Closure of NFA-decidable Languages Under Kleene Star

Theorem: the NFA-decidable languages are closed under Kleene star:
If \(L_1 = L(N_1)\), then we can construct \(N\) such that \(L(N) = L_1^*\).

Proof:

13f23ebd-65b4-41b6-bdca-0764324b3c81 q0 q0 13f23ebd-65b4-41b6-bdca-0764324b3c81->q0 q1 q1 q0->q1 b q1->q0 b q2 q2 q1->q2 a q0 q0 q1 q1 q0->q1 b q1->q0 b q2->q0 ε q2 q2 q1->q2 a 13f23ebd-65b4-41b6-bdca-0764324b3c81 13f23ebd-65b4-41b6-bdca-0764324b3c81->q0 96bf7c3f-1030-438f-882c-cbe8f6a4b218 s s 96bf7c3f-1030-438f-882c-cbe8f6a4b218->s s->q0 ε

Let \(N_1 = (Q_1, \Sigma, \Delta_1, s_1, F_1)\) and construct
\(N = (Q, \Sigma, \Delta, s, F)\):

  • \(Q = Q_1 \cup \{s\}\)
  • \(F = F_1 \cup \{s\}\)
  • For all \(q \in Q\) and \(a \in \Sigma_\emptystring\): \[ \Delta(q, a) = \begin{cases} \Delta_1(q, a) & \text{if } (q, a) \in Q_1 \times \Sigma_\emptystring \setminus F_1 \times \{\varepsilon\} \\ \Delta_1(q, a) \cup \{s_1\} & \text{if } q \in F_1 \text{ and } a = \emptystring \\ \{s_1\} & \text{if } q = s \text{ and } a = \emptystring \\ \emptyset & \text{if } q = s \text{ and } a \ne \emptystring \end{cases} \]

Alternatively: the set of transitions for \(N\) is \(\Delta_1 \cup \{s \stackrel{\emptystring}{\rightarrow} s_1 \} \cup \setbuild{q \stackrel{\emptystring}{\rightarrow} s_1}{q \in F_1}\).

Closure of NFA-decidable Languages Under Kleene Star

Theorem: the NFA-decidable languages are closed under Kleene star:
If \(L_1 = L(N_1)\), then we can construct \(N\) such that \(L(N) = L_1^*\). (proof of \(L_1^* \subseteq L(N)\))

data/images/nfa/odd_b_a_star_construction.static.svg

  • Clearly \(\emptystring \in L(N)\) since \(s \in F\), so we only consider non-empty strings.

  • To show \(L_1^* \subseteq L(N)\), let \(x \in L_1^* \setminus \emptystring\).

  • Then \(x = x_1 x_2 \dots x_k\), where each \(x_j \in L(N) \setminus \varepsilon\).

  • For each \(1 \le j \le k\), there is a computation sequence \(q_{j,0}, q_{j,1}, \dots, q_{j,m_j} \in Q\), where each \(q_{j,m_j} \in F\), and a sequence \(y_{j,0}, y_{j,1}, \dots, y_{j,m_j} \in \Sigma_\varepsilon\), where \(x_j = y_{j,0} y_{j,1} \dots y_{j,m_j}\), and for each \(0 \le i < m\), a transition \(q_{j,i} \stackrel{y_{j,i}}{\to} q_{j,i+1}\).

  • Then is a computation sequence showing \(N\) accepts \(x\):

    \(s, \underbrace{s_1(=q_{1,0}), q_{1,1}, \dots, q_{1,m_1}}_{x_1}, \underbrace{s_1(=q_{2,0}), q_{2,1}, \dots, q_{2,m_1}}_{x_2}, \dots, \underbrace{s_1(=q_{k,0}), q_{k,1}, \dots, q_{k,m_k}}_{x_k}\).

Closure of NFA-decidable Languages Under Kleene Star

Theorem: the NFA-decidable languages are closed under Kleene star:
If \(L_1 = L(N_1)\), then we can construct \(N\) such that \(L(N) = L_1^*\). (proof of \(L(N) \subseteq L_1^*\))

data/images/nfa/odd_b_a_star_construction.static.svg

  • To show \(L(N) \subseteq L_1^*\), let \(x \in L(N) \setminus \emptystring\). (similar to before, clearly \(\emptystring \in L_1^*\), so we assume \(|x|>0\))
  • Then there are sequences \(q_0,\dots,q_m \in Q'\) and \(y_0,\dots,y_{m-1} \in \Sigma_\varepsilon\) such that \(q_m \in F'\),
    \(x = y_0 y_1 \dots y_{m-1}\), and for all \(0 \le i < m\), a transition \(q_i \stackrel{y_i}{\to} q_{i+1}\).
  • Since \(x \ne \varepsilon\), \(q_m \ne s\), so \(q_m \in F\).
  • Since the start state is \(s=q_0\), which has no outgoing non-\(\varepsilon\) transitions, the first transition from \(q_0\) to \(q_1\) is the \(\varepsilon\)-transition \(s' \stackrel{\varepsilon}{\to} s\).
  • Suppose there are \(k−1\) \(\varepsilon\)-transitions from a state in \(F\) to \(s_1\) in the computation sequence \(q_1,\dots,q_m\), then we can write the sequence as \(s_1,q_{1,1},\dots,q_{1,m_1},\) \(s_1,q_{2,1},\dots,q_{2,m_2},\) \(\dots,\) \(s_1,q_{k,1},\dots,q_{k,m_k},\) where each \(q_{j,m_j} \in F\).
  • Then each substring \(x_j\) taking \(N\) from \(s_1\) to \(q_{j,m_j}\) is in \(L_1 \setminus \emptystring\), i.e., \(x = x_1x_2\dots x_k \in L_1^*\).