There are at least two equivalent ways to describe the behavior of an NFA. The first way makes use of the nondeterminism in the name of an NFA. For each input symbol, the NFA transitions to a new state until all input symbols have been consumed. In each step, the automaton nondeterministically "chooses" one of the applicable transitions. If there exists at least one "lucky run", i.e. some sequence of choices leading to an accepting state after completely consuming the input, it is accepted. Otherwise, i.e. if no choice sequence at all can consume all the input3 and lead to an accepting state, the input is rejected.45: 319 6
In the second way, the NFA consumes a string of input symbols, one by one. In each step, whenever two or more transitions are applicable, it "clones" itself into appropriately many copies, each one following a different transition. If no transition is applicable, the current copy is in a dead end, and it "dies". If, after consuming the complete input, any of the copies is in an accept state, the input is accepted, else, it is rejected.789
For a more elementary introduction of the formal definition, see automata theory.
An NFA is represented formally by a 5-tuple, ( Q , Σ , δ , q 0 , F ) {\displaystyle (Q,\Sigma ,\delta ,q_{0},F)} , consisting of
Here, P ( Q ) {\displaystyle {\mathcal {P}}(Q)} denotes the power set of Q {\displaystyle Q} .
Given an NFA M = ( Q , Σ , δ , q 0 , F ) {\displaystyle M=(Q,\Sigma ,\delta ,q_{0},F)} , its recognized language is denoted by L ( M ) {\displaystyle L(M)} , and is defined as the set of all strings over the alphabet Σ {\displaystyle \Sigma } that are accepted by M {\displaystyle M} .
Loosely corresponding to the above informal explanations, there are several equivalent formal definitions of a string w = a 1 a 2 . . . a n {\displaystyle w=a_{1}a_{2}...a_{n}} being accepted by M {\displaystyle M} :
The above automaton definition uses a single initial state, which is not necessary. Sometimes, NFAs are defined with a set of initial states. There is an easy construction that translates an NFA with multiple initial states to an NFA with a single initial state, which provides a convenient notation.
The following automaton M, with a binary alphabet, determines if the input ends with a 1. Let M = ( { p , q } , { 0 , 1 } , δ , p , { q } ) {\displaystyle M=(\{p,q\},\{0,1\},\delta ,p,\{q\})} where the transition function δ {\displaystyle \delta } can be defined by this state transition table (cf. upper left picture):
Since the set δ ( p , 1 ) {\displaystyle \delta (p,1)} contains more than one state, M is nondeterministic. The language of M can be described by the regular language given by the regular expression (0|1)*1.
All possible state sequences for the input string "1011" are shown in the lower picture.
The string is accepted by M since one state sequence satisfies the above definition; it does not matter that other sequences fail to do so. The picture can be interpreted in a couple of ways:
The feasibility to read the same picture in two ways also indicates the equivalence of both above explanations.
In contrast, the string "10" is rejected by M (all possible state sequences for that input are shown in the upper right picture), since there is no way to reach the only accepting state, q, by reading the final 0 symbol. While q can be reached after consuming the initial "1", this does not mean that the input "10" is accepted; rather, it means that an input string "1" would be accepted.
A deterministic finite automaton (DFA) can be seen as a special kind of NFA, in which for each state and symbol, the transition function has exactly one state. Thus, it is clear that every formal language that can be recognized by a DFA can be recognized by an NFA.
Conversely, for each NFA, there is a DFA such that it recognizes the same formal language. The DFA can be constructed using the powerset construction.
This result shows that NFAs, despite their additional flexibility, are unable to recognize languages that cannot be recognized by some DFA. It is also important in practice for converting easier-to-construct NFAs into more efficiently executable DFAs. However, if the NFA has n states, the resulting DFA may have up to 2n states, which sometimes makes the construction impractical for large NFAs.
Nondeterministic finite automaton with ε-moves (NFA-ε) is a further generalization to NFA. In this kind of automaton, the transition function is additionally defined on the empty string ε. A transition without consuming an input symbol is called an ε-transition and is represented in state diagrams by an arrow labeled "ε". ε-transitions provide a convenient way of modeling systems whose current states are not precisely known: i.e., if we are modeling a system and it is not clear whether the current state (after processing some input string) should be q or q', then we can add an ε-transition between these two states, thus putting the automaton in both states simultaneously.
An NFA-ε is represented formally by a 5-tuple, ( Q , Σ , δ , q 0 , F ) {\displaystyle (Q,\Sigma ,\delta ,q_{0},F)} , consisting of
Here, P ( Q ) {\displaystyle {\mathcal {P}}(Q)} denotes the power set of Q {\displaystyle Q} and ϵ {\displaystyle \epsilon } denotes empty string.
For a state q ∈ Q {\displaystyle q\in Q} , let E ( q ) {\displaystyle E(q)} denote the set of states that are reachable from q {\displaystyle q} by following ε-transitions in the transition function δ {\displaystyle \delta } , i.e., p ∈ E ( q ) {\displaystyle p\in E(q)} if there is a sequence of states q 1 , . . . , q k {\displaystyle q_{1},...,q_{k}} such that
E ( q ) {\displaystyle E(q)} is known as the epsilon closure, (also ε-closure) of q {\displaystyle q} .
The ε-closure of a set P {\displaystyle P} of states of an NFA is defined as the set of states reachable from any state in P {\displaystyle P} following ε-transitions. Formally, for P ⊆ Q {\displaystyle P\subseteq Q} , define E ( P ) = ⋃ q ∈ P E ( q ) {\displaystyle E(P)=\bigcup \limits _{q\in P}E(q)} .
Similar to NFA without ε-moves, the transition function δ {\displaystyle \delta } of an NFA-ε can be extended to strings. Informally, δ ∗ ( q , w ) {\displaystyle \delta ^{*}(q,w)} denotes the set of all states the automaton may have reached when starting in state q ∈ Q {\displaystyle q\in Q} and reading the string w ∈ Σ ∗ . {\displaystyle w\in \Sigma ^{*}.} The function δ ∗ : Q × Σ ∗ → P ( Q ) {\displaystyle \delta ^{*}:Q\times \Sigma ^{*}\rightarrow {\mathcal {P}}(Q)} can be defined recursively as follows.
The automaton is said to accept a string w {\displaystyle w} if
that is, if reading w {\displaystyle w} may drive the automaton from its start state q 0 {\displaystyle q_{0}} to some accepting state in F . {\displaystyle F.} 14
Let M {\displaystyle M} be a NFA-ε, with a binary alphabet, that determines if the input contains an even number of 0s or an even number of 1s. Note that 0 occurrences is an even number of occurrences as well.
In formal notation, let M = ( { S 0 , S 1 , S 2 , S 3 , S 4 } , { 0 , 1 } , δ , S 0 , { S 1 , S 3 } ) {\displaystyle M=(\{S_{0},S_{1},S_{2},S_{3},S_{4}\},\{0,1\},\delta ,S_{0},\{S_{1},S_{3}\})} where the transition relation δ {\displaystyle \delta } can be defined by this state transition table:
M {\displaystyle M} can be viewed as the union of two DFAs: one with states { S 1 , S 2 } {\displaystyle \{S_{1},S_{2}\}} and the other with states { S 3 , S 4 } {\displaystyle \{S_{3},S_{4}\}} . The language of M {\displaystyle M} can be described by the regular language given by this regular expression ( 1 ∗ 01 ∗ 01 ∗ ) ∗ ∪ ( 0 ∗ 10 ∗ 10 ∗ ) ∗ {\displaystyle (1^{*}01^{*}01^{*})^{*}\cup (0^{*}10^{*}10^{*})^{*}} . We define M {\displaystyle M} using ε-moves but M {\displaystyle M} can be defined without using ε-moves.
To show NFA-ε is equivalent to NFA, first note that NFA is a special case of NFA-ε, so it remains to show for every NFA-ε, there exists an equivalent NFA.
Given an NFA with epsilon moves M = ( Q , Σ , δ , q 0 , F ) , {\displaystyle M=(Q,\Sigma ,\delta ,q_{0},F),} define an NFA M ′ = ( Q , Σ , δ ′ , q 0 , F ′ ) , {\displaystyle M'=(Q,\Sigma ,\delta ',q_{0},F'),} where
and
One has to distinguish the transition functions of M {\displaystyle M} and M ′ , {\displaystyle M',} viz. δ {\displaystyle \delta } and δ ′ , {\displaystyle \delta ',} and their extensions to strings, δ {\displaystyle \delta } and δ ′ ∗ , {\displaystyle \delta '^{*},} respectively. By construction, M ′ {\displaystyle M'} has no ε-transitions.
One can prove that δ ′ ∗ ( q 0 , w ) = δ ∗ ( q 0 , w ) {\displaystyle \delta '^{*}(q_{0},w)=\delta ^{*}(q_{0},w)} for each string w ≠ ε {\displaystyle w\neq \varepsilon } , by induction on the length of w . {\displaystyle w.}
Based on this, one can show that δ ′ ∗ ( q 0 , w ) ∩ F ′ ≠ { } {\displaystyle \delta '^{*}(q_{0},w)\cap F'\neq \{\}} if, and only if, δ ∗ ( q 0 , w ) ∩ F ≠ { } , {\displaystyle \delta ^{*}(q_{0},w)\cap F\neq \{\},} for each string w ∈ Σ ∗ : {\displaystyle w\in \Sigma ^{*}:}
Since NFA is equivalent to DFA, NFA-ε is also equivalent to DFA.
The set of languages recognized by NFAs is closed under the following operations. These closure operations are used in Thompson's construction algorithm, which constructs an NFA from any regular expression. They can also be used to prove that NFAs recognize exactly the regular languages.
Since NFAs are equivalent to nondeterministic finite automaton with ε-moves (NFA-ε), the above closures are proved using closure properties of NFA-ε.
The machine starts in the specified initial state and reads in a string of symbols from its alphabet. The automaton uses the state transition function Δ to determine the next state using the current state, and the symbol just read or the empty string. However, "the next state of an NFA depends not only on the current input event, but also on an arbitrary number of subsequent input events. Until these subsequent events occur it is not possible to determine which state the machine is in".16 If, when the automaton has finished reading, it is in an accepting state, the NFA is said to accept the string, otherwise it is said to reject the string.
The set of all strings accepted by an NFA is the language the NFA accepts. This language is a regular language.
For every NFA a deterministic finite automaton (DFA) can be found that accepts the same language. Therefore, it is possible to convert an existing NFA into a DFA for the purpose of implementing a (perhaps) simpler machine. This can be performed using the powerset construction, which may lead to an exponential rise in the number of necessary states. For a formal proof of the powerset construction, please see the Powerset construction article.
There are many ways to implement a NFA:
NFAs and DFAs are equivalent in that if a language is recognized by an NFA, it is also recognized by a DFA and vice versa. The establishment of such equivalence is important and useful. It is useful because constructing an NFA to recognize a given language is sometimes much easier than constructing a DFA for that language. It is important because NFAs can be used to reduce the complexity of the mathematical work required to establish many important properties in the theory of computation. For example, it is much easier to prove closure properties of regular languages using NFAs than DFAs.
Martin, John (2010). Introduction to Languages and the Theory of Computation. McGraw Hill. p. 108. ISBN 978-0071289429. 978-0071289429 ↩
Rabin & Scott 1959. - Rabin, M. O.; Scott, D. (April 1959). "Finite Automata and Their Decision Problems". IBM Journal of Research and Development. 3 (2): 114–125. doi:10.1147/rd.32.0114. https://doi.org/10.1147%2Frd.32.0114 ↩
A choice sequence may lead into a "dead end" where no transition is applicable for the current input symbol; in this case it is considered unsuccessful. ↩
Hopcroft & Ullman 1979, pp. 19–20. - Hopcroft, John E.; Ullman, Jeffrey D. (1979). Introduction to Automata Theory, Languages, and Computation (1st ed.). Addison-Wesley. ISBN 0-201-02988-X. ↩
Alfred V. Aho and John E. Hopcroft and Jeffrey D. Ullman (1974). The Design and Analysis of Computer Algorithms. Reading/MA: Addison-Wesley. ISBN 0-201-00029-6. 0-201-00029-6 ↩
Hopcroft, Motwani & Ullman 2006, pp. 55–6. - Hopcroft, John E.; Motwani, Rajeev; Ullman, Jeffrey D. (2006) [1979]. Introduction to Automata Theory, Languages, and Computation (3rd ed.). Addison-Wesley. ISBN 0-321-45536-3. ↩
Sipser 1997, p. 48. - Sipser, Michael (1997). Introduction to the Theory of Computation (1st ed.). PWS Publishing. ISBN 978-0-534-94728-6. ↩
Sipser 1997, p. 54. - Sipser, Michael (1997). Introduction to the Theory of Computation (1st ed.). PWS Publishing. ISBN 978-0-534-94728-6. ↩
Hopcroft & Ullman 1979, p. 21. - Hopcroft, John E.; Ullman, Jeffrey D. (1979). Introduction to Automata Theory, Languages, and Computation (1st ed.). Addison-Wesley. ISBN 0-201-02988-X. ↩
Hopcroft, Motwani & Ullman 2006, p. 59. - Hopcroft, John E.; Motwani, Rajeev; Ullman, Jeffrey D. (2006) [1979]. Introduction to Automata Theory, Languages, and Computation (3rd ed.). Addison-Wesley. ISBN 0-321-45536-3. ↩
Hopcroft & Ullman 1979, p. 25. - Hopcroft, John E.; Ullman, Jeffrey D. (1979). Introduction to Automata Theory, Languages, and Computation (1st ed.). Addison-Wesley. ISBN 0-201-02988-X. ↩
Hopcroft & Ullman 1979, pp. 26–27. - Hopcroft, John E.; Ullman, Jeffrey D. (1979). Introduction to Automata Theory, Languages, and Computation (1st ed.). Addison-Wesley. ISBN 0-201-02988-X. ↩
FOLDOC Free Online Dictionary of Computing, Finite-State Machine http://foldoc.org/nfa ↩
Chris Calabro (February 27, 2005). "NFA to DFA blowup" (PDF). cseweb.ucsd.edu. Retrieved 6 March 2023. https://cseweb.ucsd.edu//~ccalabro/essays/fsa.pdf ↩
Hopcroft, Motwani & Ullman 2006, pp. 154–5. - Hopcroft, John E.; Motwani, Rajeev; Ullman, Jeffrey D. (2006) [1979]. Introduction to Automata Theory, Languages, and Computation (3rd ed.). Addison-Wesley. ISBN 0-321-45536-3. ↩
Allan, C., Avgustinov, P., Christensen, A. S., Hendren, L., Kuzins, S., Lhoták, O., de Moor, O., Sereni, D., Sittampalam, G., and Tibble, J. 2005. Adding trace matching with free variables to AspectJ Archived 2009-09-18 at the Wayback Machine. In Proceedings of the 20th Annual ACM SIGPLAN Conference on Object Oriented Programming, Systems, Languages, and Applications (San Diego, CA, USA, October 16–20, 2005). OOPSLA '05. ACM, New York, NY, 345-364. http://abc.comlab.ox.ac.uk/papers#oopsla2005 ↩
Historically shown in: Meyer, A. R.; Stockmeyer, L. J. (1972-10-25). "The equivalence problem for regular expressions with squaring requires exponential space". Proceedings of the 13th Annual Symposium on Switching and Automata Theory (SWAT). USA: IEEE Computer Society: 125–129. doi:10.1109/SWAT.1972.29. For a modern presentation, see [1] /wiki/Doi_(identifier) ↩
Álvarez, Carme; Jenner, Birgit (1993-01-04). "A very hard log-space counting class". Theoretical Computer Science. 107 (1): 3–30. doi:10.1016/0304-3975(93)90252-O. ISSN 0304-3975. https://dx.doi.org/10.1016/0304-3975%2893%2990252-O ↩