Title

ECS 120 Theory of Computation
Equivalence of Computational Models
Julian Panetta
University of California, Davis

Equivalence of Computational Models

  • We’ve shown how to prove closure of a class of languages decidable by a certain model under an operation \(\texttt{op}\):
    • Given instances \(M_1\) and \(M_2\) of the model, we can construct a new instance \(M\) of the same model such that: \[L(M) = L(M_1)\; \texttt{op}\; L(M_2)\]
    • We proved DFA-decidable languages are closed under complement, union, and intersection
    • We proved NFA-decidable languages are closed under union, concatenation, and Kleene star
  • We now turn to comparing the computational power of different models.
    • If any regex can be simulated by an NFA, then NFAs are at least as powerful as regexes. \[ \text{"For all regexes } R, \text{ there exists an NFA } N \text{ such that } L(R) = L(N)\text{"} \]
    • If any NFA can be simulated by a regex, then regexes are at least as powerful as NFAs.
    • If both of these are true (they are!), then NFAs and regexes have equivalent power.

Simple Example: NFAs Are at Least as Powerful as DFAs

  • NFAs are generalizations of DFAs, so any DFA can be trivially simulated by an NFA.
  • A DFA is just an NFA with:
    • no \(\emptystring\) transitions and
    • exactly one transition for each state and symbol pair.
  • To prove this formally:
    • Let \(D = (Q_D, \Sigma, \delta_D, s_D, F_D)\) be a DFA
    • We can construct an equivalent NFA \(N = (Q_N, \Sigma, \Delta_N, s_N, F_N)\) such that:
      • \(Q_N = Q_D\)
      • \(\Delta_N(q, a) = \fragment{\{\delta_D(q, a)\}}\) for all \(q \in Q_N\) and \(a \in \Sigma\)
      • \(s_N = s_D\)
      • \(F_N = F_D\)

Simulating NFAs

  • Trying to simulate an NFA with a DFA is less straight-forward.

  • Warm-up: which of the following are equivalent to plain NFAs?

    • MultistartNFA: an NFA allowing more than one start state
    • SingleAcceptNFA: an NFA allowing only a single accept state
    • InjectiveNFA: an NFA for which the destination of each transition rule is either \(\emptyset\) or a singleton \(\{q_i\}\)
    • NoLoopNFA: an NFA for which no transition rule is of the form \(q \stackrel{a}{\rightarrow} q\) for any \((q, a) \in Q \times \Sigma\)
    • NoEpsilonNFA: an NFA with no \(\emptystring\) transitions.

Recall: Operation of an NFA

data/images/nfa/n1/diagram.svg

Example processing the string 010110:

010110

  • Begin in the state(s) \(\{q_1\}\).

    data/images/nfa/n1/state_q1.svg
  • Read 0 and transition to state(s) \(\{q_1\}\).

    010110

    data/images/nfa/n1/state_q1.svg
  • Read 1 and transition to state(s) \(\{q_1, q_2, q_3\}\).

    010110

    data/images/nfa/n1/state_q1_q2_q3.svg
  • Read 0 and transition to state(s) \(\{q_1, q_3\}\).

    010110

    data/images/nfa/n1/state_q1_q3.svg
  • Read 1 and transition to state(s) \(\{q_1, q_2, q_3, q_4\}\).

    010110

    data/images/nfa/n1/state_q1_q2_q3_q4.svg
  • Read 1 and transition to state(s) \(\{q_1, q_2, q_3, q_4\}\).

    010110

  • Read 0 and transition to state(s) \(\{q_1, q_3, q_4\}\).

    010110

    data/images/nfa/n1/state_q1_q3_q4.svg
  • Since an accept state is highlighted, the NFA accepts the string.

What would a DFA need to keep track of in order to simulate this NFA?

Simulating NFAs

To simulate an NFA with \(|Q|\) states operating on a string \(w\), how many distinct sets of states must we keep track of in the worst case?

  • \(|Q|^2\)
  • \(2^{|Q|}\)
  • \(|w|^2\)
  • \(2^{|w|}\)

Example NFA to DFA Conversion

data/images/nfa/n4_simple.svg
Example NFA (no \(\emptystring\) transitions)
a,b a b a b a b a,b a b a b b a

Example NFA to DFA Conversion

data/images/nfa/n4.svg
Example NFA (with \(\emptystring\) transitions)
a,b a b a b a a b a,b a b a b b a a

  • This process usually does not generate “optimal” DFAs.
  • In this example, we can easily remove “dead” states.
  • For proving equivalence, we don’t care about optimality!

Example NFA to DFA Conversion

data/images/nfa/n4.svg
Example NFA (with \(\emptystring\) transitions)
a,b a b a b a b a,b b a b b a a

  • This process usually does not generate “optimal” DFAs.
  • In this example, we can easily remove “dead” states.
  • For proving equivalence, we don’t care about optimality!

There exist \(k\)-state NFAs for which the smallest equivalent DFA has \(2^k\) states!
Example near this bound:
\(k^\text{th}\)-to-last symbol NFA

NFA to DFA Conversion: “Subset Construction”

data/images/nfa/n4_dfa_nodeadstates.svg

Theorem: If a language is NFA-decidable, then it is also DFA-decidable.

Proof (no \(\emptystring\) transitions)

  • Let \(N = (Q_N, \Sigma, \Delta_N, s_N, F_N)\) be an NFA without \(\emptystring\) transitions.
  • Construct \(D = (Q_D, \Sigma, \delta_D, s_D, F_D)\) as follows:
    • \(Q_D = \powerset(Q_N)\)
    • \(s_D = \{s_N\}\)
    • \(F_D = \fragment{\setbuild{R \in Q_D}{\fragment{R \cap F_N \neq \emptyset}}}\)
    • For all \(R \in Q_D\) and \(b \in \Sigma\): \[\delta_D(R, b) = \bigcup_{q \in R} \Delta_N(q, b)\]
  • What about \(\emptystring\) transitions? Convention:
    • After reading each symbol, jump to all states reachable by any number of \(\emptystring\) transitions.
    • Also do this for the start state.

Following Epsilon Transitions

For any \(R \subseteq Q_N\), define: \[ E(R) = \setbuild{q \in Q_N}{q \text{ is reachable from some $r \in R$ by a sequence of 0 or more $\emptystring$ transitions}} \]

data/images/nfa/multiple-eps-transitions.svg
  • \(E(\{5\}) = \fragment{\{4, 5\}}\)
  • \(E(\{6\}) = \fragment{\{6\}}\)
  • \(E(\{1\}) = \fragment{\{1, 3, 4, 5, 6\}}\)
  • \(E(\{2\}) = \fragment{\{2\}}\)
  • \(E(\{3\}) = \fragment{\{3, 4, 5\}}\)
  • \(E(\{2, 5\}) = \fragment{\{2, 4, 5\}}\)

NFA to DFA Conversion: “Subset Construction”

data/images/nfa/n4_dfa_nodeadstates.svg

Theorem: If a language is NFA-decidable, then it is also DFA-decidable.

Proof

  • Let \(N = (Q_N, \Sigma, \Delta_N, s_N, F_N)\) be an NFA.
  • Construct \(D = (Q_D, \Sigma, \delta_D, s_D, F_D)\) as follows:
    • \(Q_D = \powerset(Q_N)\)
    • \(\color{red} s_D = \fragment{E(\{s_N\})}\)
    • \(F_D = \setbuild{R \in Q_D}{R \cap F_N \neq \emptyset}\)
    • For all \(R \in Q_D\) and \(b \in \Sigma\): \[\color{red} \delta_D(R, b) = \fragment{E\left(\bigcup_{q \in R} \Delta_N(q, b)\right)} \fragment{= \bigcup_{q \in R} E(\Delta_N(q, b))}\]

This convention for handling \(\emptystring\) transitions is not the only possible one!

Corollary: a language is DFA-decidable if and only if it is NFA-decidable.