Skip to the passage panel
WikiLean · Articles Articles Brain Contribute About

Preliminary: these links have not yet had an independent audit.

Nondeterministic finite automaton

88 passages34 formalized14 partial40 not formalized

Statement only

More ways to filter
Library
Passages
About this page

This page

  • Wikipedia revision 1366106761, pinned: the text here is that revision, not today's article.
  • WikiProject Mathematics: B-class, High importance
  • Annotated article on WikiLean.
  • 88 passages checked, 66 Lean locations (and 40 related declarations).

Central statements: 33 of the 88 passages state the article's subject or a named result or definition; the other 55 are supporting (examples, setup). Of these 33: 16 formalized, 10 partial, 7 not formalized.

What the colours mean

  • Formalized a Lean declaration states it, proved, or a Lean definition defines it
  • Statement only Lean states it, but the proof is not finished
  • Partial Lean states part of it, or a more general or special form
  • Not formalized searched every library and not found

Libraries searched

Searched 48 Lean libraries, pinned 2026-10-17, 3 left out (library set u1).

How these links were made

  • Accuracy, from an audit of a sample of 224 items (blind, not independent): Strong links (exact, close or broad match) on supporting passages that have exactly the right relation: 92% (95% interval 49–99%), from 36 drawn of 1029, weighted by relation and library, an effective sample of 5.1; Links in a counting relation (exact, close, broad, narrow match or part) on supporting passages that have exactly the right relation: 73% (95% interval 40–92%), from 48 drawn of 1740, weighted by relation and library, an effective sample of 8.1; Central and subject passages whose formalization status is right: 86% (95% interval 73–94%), from 44 drawn of 1905, weighted by recorded status, an effective sample of 42; 'Not formalized' on supporting passages that is right (no declaration in the 48 libraries states it): 60% (95% interval 25–87%), from 12 drawn of 1236, weighted by article, an effective sample of 6.1.
  • Audit run tierA-batch1-audit, run by jack, 2 Nov 2026, 21:10 – 3 Nov 2026, 02:10 UTC: judged by Claude Opus 5.5 (claude-opus-5-5).
  • Record set tierA-b1b (cf-locate-recordset/2, statuses by status rule 3), exported 1 Nov 2026 by formal-companion at commit d85385a.
  • Seal sha256 23710337d053e8212378a9e580805628bcdfda61a6fc431e65f24a4a16c9e602.
  • Inventory run inv-tierA-b1r, run by jack, 30 Oct 2026, 07:23–20:00 UTC: worker Claude Opus 5 (claude-opus-5), reviewer Claude Opus 5 (claude-opus-5). It listed the formal passages, each with its kind and prominence, that the locate run then searched.
  • Locate run loc-tierA-b1b, run by jack, 31 Oct 2026, 04:59 – 1 Nov 2026, 03:06 UTC: worker Claude Opus 5 (claude-opus-5), reviewer Claude Opus 5 (claude-opus-5).
  • Challenge run chal-tierA-b1, run by jack, 1 Nov 2026, 03:19–14:25 UTC: worker Claude Opus 5 (claude-opus-5), reviewer Claude Opus 5 (claude-opus-5). In this article it re-checked every Lean location and absence on a central or subject passage (36 locations and 7 absences); on supporting passages, a seeded sample (seed 0; drawn at 0.5 for strong matches, 0.2 for weaker links and 0.25 for absences): 24 of 30 locations and 10 of 33 absences. In all, 60 of 66 Lean locations (91%) and 17 of 40 absences (43%) were re-checked.
  • Passage text: 88 of 88 passages shown in full, each the slice of the pinned revision's text that its record's span sha256 hashes, checked when the store was built.
  • Lean code: each declaration's type, from the declaration corpus of universe u1 (built 18 Oct 2026, sha256 a364fd6aede5), at the commit its card links.

How the text is shown

Each passage is shown in full, as revision 1366106761 states it (checked against its record's span hash when the store was built). Where a passage is only part of a sentence, it is highlighted and the rest of the sentence is shown in grey around it, from the same copy of the revision; a list item also shows the sentence that introduces it. Formulas are drawn from their TeX; hover one to see it.

Each card's Lean code is its declaration's type as Lean prints it, from the declaration corpus of library set u1 at the card's commit, laid out as a header: binders before the colon, then the hypotheses as arrows (the corpus keeps no hypothesis names) and the conclusion, in Mathlib's notation (𝓝, π, R[X], Type*). It is not the source text; Source opens that.

Select a highlighted passage to see where Lean formalizes it.

NFA for (0|1)* 1 (0|1)3.
A DFA for that language has at least 16 states.

In automata theory, a finite-state machine is called a deterministic finite automaton (DFA), if

  • each of its transitions is uniquely determined by its source state and input symbol, and
  • reading an input symbol is required for each state transition.

A nondeterministic finite automaton (NFA), or nondeterministic finite-state machine, does not need to obey these restrictions. In particular, every DFA is also an NFA. Sometimes the term NFA is used in a narrower sense, referring to an NFA that is not a DFA, but not in this article.

Using the subset construction algorithm, each NFA can be translated to an equivalent DFA; i.e., a DFA recognizing the same formal language.[1] Like DFAs, NFAs only recognize regular languages.

NFAs were introduced in 1959 by Michael O. Rabin and Dana Scott,[2] who also showed their equivalence to DFAs. NFAs are used in the implementation of regular expressions: Thompson's construction is an algorithm for compiling a regular expression to an NFA that can efficiently perform pattern matching on strings. Conversely, Kleene's algorithm can be used to convert an NFA into a regular expression (whose size is generally exponential in the input automaton).

NFAs have been generalized in multiple ways, e.g., nondeterministic finite automata with ε-moves, finite-state transducers, pushdown automata, alternating automata, ω-automata, and probabilistic automata. Besides the DFAs, other known special cases of NFAs are unambiguous finite automata (UFA) and self-verifying finite automata (SVFA).

Informal introduction

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 input[3] and lead to an accepting state, the input is rejected.[4][5]: 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.[4][7][6]

Formal definition

For a more elementary introduction of the formal definition, see automata theory.

Automaton

An NFA is represented formally by a 5-tuple, ( Q , Σ , δ , q 0 , F ) {\displaystyle (Q,\Sigma ,\delta ,q_{0},F)} , consisting of

  • a finite set of states Q {\displaystyle Q} ,
  • a finite set of input symbols called the alphabet Σ {\displaystyle \Sigma } ,
  • a transition function δ {\displaystyle \delta }  : Q × Σ → P ( Q ) {\displaystyle Q\times \Sigma \rightarrow {\mathcal {P}}(Q)} ,
  • an initial (or start) state q 0 ∈ Q {\displaystyle q_{0}\in Q} , and
  • a set of accepting (or final) states F ⊆ Q {\displaystyle F\subseteq Q} .

Here, P ( Q ) {\displaystyle {\mathcal {P}}(Q)} denotes the power set of Q {\displaystyle Q} .

Recognized language

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} :

  • w {\displaystyle w} is accepted if a sequence of states, r 0 , r 1 , . . . , r n {\displaystyle r_{0},r_{1},...,r_{n}} , exists in Q {\displaystyle Q} such that:
    1. r 0 = q 0 {\displaystyle r_{0}=q_{0}}
    2. r i + 1 ∈ δ ( r i , a i + 1 ) {\displaystyle r_{i+1}\in \delta (r_{i},a_{i+1})} , for i = 0 , … , n − 1 {\displaystyle i=0,\ldots ,n-1}
    3. r n ∈ F {\displaystyle r_{n}\in F} .
In words, the first condition says that the machine starts in the start state q 0 {\displaystyle q_{0}} . The second condition says that given each character of string w {\displaystyle w} , the machine will transition from state to state according to the transition function δ {\displaystyle \delta } . The last condition says that the machine accepts w {\displaystyle w} if the last input of w {\displaystyle w} causes the machine to halt in one of the accepting states. In order for w {\displaystyle w} to be accepted by M {\displaystyle M} , it is not required that every state sequence ends in an accepting state, it is sufficient if one does. Otherwise, i.e. if it is impossible at all to get from q 0 {\displaystyle q_{0}} to a state from F {\displaystyle F} by following w {\displaystyle w} , it is said that the automaton rejects the string. The set of strings M {\displaystyle M} accepts is the language recognized by M {\displaystyle M} and this language is denoted by L ( M ) {\displaystyle L(M)} .[5]: 320 [8]
  • Alternatively, w {\displaystyle w} is accepted if δ ∗ ( q 0 , w ) ∩ F ≠ ∅ {\displaystyle \delta ^{*}(q_{0},w)\cap F\not =\emptyset } , where δ ∗ : Q × Σ ∗ → P ( Q ) {\displaystyle \delta ^{*}:Q\times \Sigma ^{*}\rightarrow {\mathcal {P}}(Q)} is defined recursively by:
    1. δ ∗ ( r , ε ) = { r } {\displaystyle \delta ^{*}(r,\varepsilon )=\{r\}} where ε {\displaystyle \varepsilon } is the empty string, and
    2. δ ∗ ( r , x a ) = ⋃ r ′ ∈ δ ∗ ( r , x ) δ ( r ′ , a ) {\displaystyle \delta ^{*}(r,xa)=\bigcup _{r'\in \delta ^{*}(r,x)}\delta (r',a)} for all x ∈ Σ ∗ , a ∈ Σ {\displaystyle x\in \Sigma ^{*},a\in \Sigma } .
In words, δ ∗ ( r , x ) {\displaystyle \delta ^{*}(r,x)} is the set of all states reachable from state r {\displaystyle r} by consuming the string x {\displaystyle x} . The string w {\displaystyle w} is accepted if some accepting state in F {\displaystyle F} can be reached from the start state q 0 {\displaystyle q_{0}} by consuming w {\displaystyle w} .[9][10]

Initial state

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.

Isomorphism

An isomorphism φ {\displaystyle \varphi } from an automaton ( Q , Σ , δ , q 0 , F ) {\displaystyle (Q,\Sigma ,\delta ,q_{0},F)} to an automaton ( Q ′ , Σ , δ ′ , q 0 ′ , F ′ ) {\displaystyle (Q',\Sigma ,\delta ',q'_{0},F')} is a bijective mapping φ : Q → Q ′ {\displaystyle \varphi :Q\to Q'} such that

  • φ ( q 0 ) = q 0 ′ {\displaystyle \varphi (q_{0})=q'_{0}} ,
  • q ∈ F {\displaystyle q\in F} if, and only if, φ ( q ) ∈ F ′ {\displaystyle \varphi (q)\in F'} , for each q ∈ Q {\displaystyle q\in Q} , and
  • r ∈ δ ( q , a ) {\displaystyle r\in \delta (q,a)} if, and only if, φ ( r ) ∈ δ ′ ( φ ( q ) , a ) {\displaystyle \varphi (r)\in \delta '(\varphi (q),a)} , for each q , r ∈ Q {\displaystyle q,r\in Q} and a ∈ Σ {\displaystyle a\in \Sigma } .[citation needed]

Intuitively, two automata are isomorphic if they share the same alphabet and one can be obtained by systematically renaming the states of the other.

Example

The state diagram for M. It is not deterministic since in state p reading a 1 can lead to p or to q.
All possible runs of M on input string "10"
All possible runs of M on input string "1011".
Arc label: input symbol, node label: state, green: start state, red: accepting state(s).
Input
State sequence
1 0 1 1
1 p q ?
2 p p p q ?
3 p p p p q

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):

State Input 0 1 p { p } { p , q } q ∅ ∅ {\displaystyle {\begin{array}{|c|cc|}{\bcancel {{}_{\text{State}}\quad {}^{\text{Input}}}}&0&1\\\hline p&\{p\}&\{p,q\}\\q&\emptyset &\emptyset \end{array}}}

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:

  • In terms of the above "lucky-run" explanation, each path in the picture denotes a sequence of choices of M.
  • In terms of the "cloning" explanation, each vertical column shows all clones of M at a given point in time, multiple arrows emanating from a node indicate cloning, a node without emanating arrows indicating the "death" of a clone.

The feasibility to read the same picture in two ways also indicates the equivalence of both above explanations.

  • Considering the first of the above formal definitions, "1011" is accepted since when reading it M may traverse the state sequence ⟨ r 0 , r 1 , r 2 , r 3 , r 4 ⟩ = ⟨ p , p , p , p , q ⟩ {\displaystyle \langle r_{0},r_{1},r_{2},r_{3},r_{4}\rangle =\langle p,p,p,p,q\rangle } , which satisfies conditions 1 to 3.
  • Concerning the second formal definition, bottom-up computation shows that δ ∗ ( p , ε ) = { p } {\displaystyle \delta ^{*}(p,\varepsilon )=\{p\}} , hence δ ∗ ( p , 1 ) = δ ( p , 1 ) = { p , q } {\displaystyle \delta ^{*}(p,1)=\delta (p,1)=\{p,q\}} , hence δ ∗ ( p , 10 ) = δ ( p , 0 ) ∪ δ ( q , 0 ) = { p } ∪ { } {\displaystyle \delta ^{*}(p,10)=\delta (p,0)\cup \delta (q,0)=\{p\}\cup \{\}} , hence δ ∗ ( p , 101 ) = δ ( p , 1 ) = { p , q } {\displaystyle \delta ^{*}(p,101)=\delta (p,1)=\{p,q\}} , and hence δ ∗ ( p , 1011 ) = δ ( p , 1 ) ∪ δ ( q , 1 ) = { p , q } ∪ { } {\displaystyle \delta ^{*}(p,1011)=\delta (p,1)\cup \delta (q,1)=\{p,q\}\cup \{\}} ; since that set is not disjoint from { q } {\displaystyle \{q\}} , the string "1011" is accepted.

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.

Equivalence to DFA

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.

NFA with ε-moves

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.

Formal definition

An NFA-ε is represented formally by a 5-tuple, ( Q , Σ , δ , q 0 , F ) {\displaystyle (Q,\Sigma ,\delta ,q_{0},F)} , consisting of

  • a finite set of states Q {\displaystyle Q}
  • a finite set of input symbols called the alphabet Σ {\displaystyle \Sigma }
  • a transition function δ : Q × ( Σ ∪ { ε } ) → P ( Q ) {\displaystyle \delta :Q\times (\Sigma \cup \{\varepsilon \})\rightarrow {\mathcal {P}}(Q)}
  • an initial (or start) state q 0 ∈ Q {\displaystyle q_{0}\in Q}
  • a set of states F {\displaystyle F} distinguished as accepting (or final) states F ⊆ Q {\displaystyle F\subseteq Q} .

Here, P ( Q ) {\displaystyle {\mathcal {P}}(Q)} denotes the power set of Q {\displaystyle Q} and ε {\displaystyle \varepsilon } denotes empty string.

ε-closure of a state or set of states

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

  • q 1 = q {\displaystyle q_{1}=q} ,
  • q i + 1 ∈ δ ( q i , ε ) {\displaystyle q_{i+1}\in \delta (q_{i},\varepsilon )} for each 1 ≤ i < k {\displaystyle 1\leq i<k} , and
  • q k = p {\displaystyle q_{k}=p} .

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)} .

Extended transition function

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.

  • δ ∗ ( q , ε ) = E ( q ) {\displaystyle \delta ^{*}(q,\varepsilon )=E(q)} , for each state q ∈ Q , {\displaystyle q\in Q,} and where E {\displaystyle E} denotes the epsilon closure;
Informally: Reading the empty string may drive the automaton from state q {\displaystyle q} to any state of the epsilon closure of q . {\displaystyle q.}
  • δ ∗ ( q , w a ) = ⋃ r ∈ δ ∗ ( q , w ) E ( δ ( r , a ) ) , {\textstyle \delta ^{*}(q,wa)=\bigcup _{r\in \delta ^{*}(q,w)}E(\delta (r,a)),} for each state q ∈ Q , {\displaystyle q\in Q,} each string w ∈ Σ ∗ {\displaystyle w\in \Sigma ^{*}} and each symbol a ∈ Σ . {\displaystyle a\in \Sigma .}
Informally: Reading the string w {\displaystyle w} may drive the automaton from state q {\displaystyle q} to any state r {\displaystyle r} in the recursively computed set δ ∗ ( q , w ) {\displaystyle \delta ^{*}(q,w)} ; after that, reading the symbol a {\displaystyle a} may drive it from r {\displaystyle r} to any state in the epsilon closure of δ ( r , a ) . {\displaystyle \delta (r,a).}

The automaton is said to accept a string w {\displaystyle w} if

δ ∗ ( q 0 , w ) ∩ F ≠ ∅ , {\displaystyle \delta ^{*}(q_{0},w)\cap F\neq \emptyset ,}

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.} [11]

Example

The state diagram for M

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:

Input
State
0 1 ε
S0 {} {} {S1, S3}
S1 {S2} {S1} {}
S2 {S1} {S2} {}
S3 {S3} {S4} {}
S4 {S4} {S3} {}

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.

Equivalence to NFA

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

F ′ = { F ∪ { q 0 }  if  E ( q 0 ) ∩ F ≠ { } F  otherwise  {\displaystyle F'={\begin{cases}F\cup \{q_{0}\}&{\text{ if }}E(q_{0})\cap F\neq \{\}\\F&{\text{ otherwise }}\\\end{cases}}}

and

δ ′ ( q , a ) = δ ∗ ( q , a ) {\displaystyle \delta '(q,a)=\delta ^{*}(q,a)} for each state q ∈ Q {\displaystyle q\in Q} and each symbol a ∈ Σ , {\displaystyle a\in \Sigma ,} using the extended transition function δ ∗ {\displaystyle \delta ^{*}} defined above.

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 ^{*}:}

  • If w = ε , {\displaystyle w=\varepsilon ,} this follows from the definition of F ′ . {\displaystyle F'.}
  • Otherwise, let w = v a {\displaystyle w=va} with v ∈ Σ ∗ {\displaystyle v\in \Sigma ^{*}} and a ∈ Σ . {\displaystyle a\in \Sigma .}
From δ ′ ∗ ( q 0 , w ) = δ ∗ ( q 0 , w ) {\displaystyle \delta '^{*}(q_{0},w)=\delta ^{*}(q_{0},w)} and F ⊆ F ′ , {\displaystyle F\subseteq F',} we have δ ′ ∗ ( q 0 , w ) ∩ F ′ ≠ { } ⇐ δ ∗ ( q 0 , w ) ∩ F ≠ { } ; {\displaystyle \delta '^{*}(q_{0},w)\cap F'\neq \{\}\;\Leftarrow \;\delta ^{*}(q_{0},w)\cap F\neq \{\};} we still have to show the " ⇒ {\displaystyle \Rightarrow } " direction.
  • If δ ′ ∗ ( q 0 , w ) {\displaystyle \delta '^{*}(q_{0},w)} contains a state in F ′ ∖ { q 0 } , {\displaystyle F'\setminus \{q_{0}\},} then δ ∗ ( q 0 , w ) {\displaystyle \delta ^{*}(q_{0},w)} contains the same state, which lies in F {\displaystyle F} .
  • If δ ′ ∗ ( q 0 , w ) {\displaystyle \delta '^{*}(q_{0},w)} contains q 0 , {\displaystyle q_{0},} and q 0 ∈ F , {\displaystyle q_{0}\in F,} then δ ∗ ( q 0 , w ) {\displaystyle \delta ^{*}(q_{0},w)} also contains a state in F , {\displaystyle F,} viz. q 0 . {\displaystyle q_{0}.}
  • If δ ′ ∗ ( q 0 , w ) {\displaystyle \delta '^{*}(q_{0},w)} contains q 0 , {\displaystyle q_{0},} and q 0 ∉ F , {\displaystyle q_{0}\not \in F,} but q 0 ∈ F ′ , {\displaystyle q_{0}\in F',} then there exists a state in E ( q 0 ) ∩ F {\displaystyle E(q_{0})\cap F} , and the same state must be in δ ∗ ( q 0 , w ) = ⋃ r ∈ δ ∗ ( q , v ) E ( δ ( r , a ) ) . {\textstyle \delta ^{*}(q_{0},w)=\bigcup _{r\in \delta ^{*}(q,v)}E(\delta (r,a)).} [12]

Since NFA is equivalent to DFA, NFA-ε is also equivalent to DFA.

Closure properties

Composed NFA accepting the union of the languages of some given NFAs N(s) and N(t). For an input string w in the language union, the composed automaton follows an ε-transition from q to the start state (left colored circle) of an appropriate subautomaton — N(s) or N(t) — which, by following w, may reach an accepting state (right colored circle); from there, state f can be reached by another ε-transition. Due to the ε-transitions, the composed NFA is properly nondeterministic even if both N(s) and N(t) were DFAs; vice versa, constructing a DFA for the union language (even of two DFAs) is much more complicated.

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.

  • Union (cf. picture); that is, if the language L1 is accepted by some NFA A1 and L2 by some A2, then an NFA Au can be constructed that accepts the language L1∪L2.
  • Intersection; similarly, from A1 and A2 an NFA Ai can be constructed that accepts L1∩L2.
  • Concatenation
  • Negation; similarly, from A1 an NFA An can be constructed that accepts Σ*\L1.
  • Kleene closure

Since NFAs are equivalent to nondeterministic finite automata with ε-moves (NFA-ε), the above closures can be proved using closure properties of NFA-ε.

Properties

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".[13] 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.

Implementation

There are many ways to implement an NFA:

  • Convert to the equivalent DFA. In some cases this may cause exponential blowup in the number of states.[14]
  • Keep a set data structure of all states which the NFA might currently be in. On the consumption of an input symbol, unite the results of the transition function applied to all current states to get the set of next states; if ε-moves are allowed, include all states reachable by such a move (ε-closure). Each step requires at most s2 computations, where s is the number of states of the NFA. On the consumption of the last input symbol, if one of the current states is a final state, the machine accepts the string. A string of length n can be processed in time O(ns2),[15] and space O(s).
  • Create multiple copies. For each n way decision, the NFA creates up to n−1 copies of the machine. Each will enter a separate state. If, upon consuming the last input symbol, at least one copy of the NFA is in the accepting state, the NFA will accept. (This, too, requires linear storage with respect to the number of NFA states, as there can be one machine for every NFA state.)
  • Explicitly propagate tokens through the transition structure of the NFA and match whenever a token reaches the final state. This is sometimes useful when the NFA should encode additional context about the events that triggered the transition. (For an implementation that uses this technique to keep track of object references have a look at Tracematches.)[16]

Complexity

  • One can solve in linear time the emptiness problem for NFA, i.e., check whether the language of a given NFA is empty. To do this, we can simply perform a depth-first search from the initial state and check if some final state can be reached.
  • It is PSPACE-complete to test, given an NFA, whether it is universal, i.e., if there is a string that it does not accept.[17] As a consequence, the same is true of the inclusion problem, i.e., given two NFAs, is the language of one a subset of the language of the other.
  • Given as input an NFA A and an integer n, the counting problem of determining how many words of length n are accepted by A is intractable; it is #P-hard. In fact, this problem is complete (under parsimonious reductions) for the complexity class SpanL.[18]

Application of 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.

See also

Notes

  1. ^ Martin, John (2010). Introduction to Languages and the Theory of Computation. McGraw Hill. p. 108. ISBN 978-0071289429.
  2. ^ Rabin & Scott 1959.
  3. ^ 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.
  4. ^ a b Hopcroft & Ullman 1979, pp. 19–20.
  5. ^ a b 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.
  6. ^ a b Hopcroft, Motwani & Ullman 2006, pp. 55–6.
  7. ^ Sipser 1997, p. 48.
  8. ^ Sipser 1997, p. 54.
  9. ^ Hopcroft & Ullman 1979, p. 21.
  10. ^ Hopcroft, Motwani & Ullman 2006, p. 59.
  11. ^ Hopcroft & Ullman 1979, p. 25.
  12. ^ Hopcroft & Ullman 1979, pp. 26–27.
  13. ^ FOLDOC Free Online Dictionary of Computing, Finite-State Machine
  14. ^ Chris Calabro (February 27, 2005). "NFA to DFA blowup" (PDF). cseweb.ucsd.edu. Retrieved 6 March 2023.
  15. ^ Hopcroft, Motwani & Ullman 2006, pp. 154–5.
  16. ^ 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.
  17. ^ Historically shown in: Meyer, A. R.; Stockmeyer, L. J. (1972-10-25). "The equivalence problem for regular expressions with squaring requires exponential space". 13th Annual Symposium on Switching and Automata Theory (Swat 1972). USA: IEEE Computer Society. pp. 125–129. doi:10.1109/SWAT.1972.29. For a modern presentation, see [1]
  18. ^ Á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.

References