Deterministic finite automaton explained

In the theory of computation, a branch of theoretical computer science, a deterministic finite automaton (DFA)—also known as deterministic finite acceptor (DFA), deterministic finite-state machine (DFSM), or deterministic finite-state automaton (DFSA)—is a finite-state machine that accepts or rejects a given string of symbols, by running through a state sequence uniquely determined by the string.[1] Deterministic refers to the uniqueness of the computation run. In search of the simplest models to capture finite-state machines, Warren McCulloch and Walter Pitts were among the first researchers to introduce a concept similar to finite automata in 1943.[2] [3]

The figure illustrates a deterministic finite automaton using a state diagram. In this example automaton, there are three states: S0, S1, and S2 (denoted graphically by circles). The automaton takes a finite sequence of 0s and 1s as input. For each state, there is a transition arrow leading out to a next state for both 0 and 1. Upon reading a symbol, a DFA jumps deterministically from one state to another by following the transition arrow. For example, if the automaton is currently in state S0 and the current input symbol is 1, then it deterministically jumps to state S1. A DFA has a start state (denoted graphically by an arrow coming in from nowhere) where computations begin, and a set of accept states (denoted graphically by a double circle) which help define when a computation is successful.

A DFA is defined as an abstract mathematical concept, but is often implemented in hardware and software for solving various specific problems such as lexical analysis and pattern matching. For example, a DFA can model software that decides whether or not online user input such as email addresses are syntactically valid.

DFAs have been generalized to nondeterministic finite automata (NFA) which may have several arrows of the same label starting from a state. Using the powerset construction method, every NFA can be translated to a DFA that recognizes the same language. DFAs, and NFAs as well, recognize exactly the set of regular languages.[1]

Formal definition

A deterministic finite automaton is a 5-tuple,, consisting of

q0\inQ

F\subseteqQ

Let be a string over the alphabet . The automaton accepts the string if a sequence of states,, exists in with the following conditions:

    1. , for

rn\inF

.

In words, the first condition says that the machine starts in the start state . The second condition says that given each character of string, the machine will transition from state to state according to the transition function . The last condition says that the machine accepts if the last input of causes the machine to halt in one of the accepting states. Otherwise, it is said that the automaton rejects the string. The set of strings that accepts is the language recognized by and this language is denoted by .

A deterministic finite automaton without accept states and without a starting state is known as a transition system or semiautomaton.

For more comprehensive introduction of the formal definition see automata theory.

Example

The following example is of a DFA, with a binary alphabet, which requires that the input contains an even number of 0s.

where

S1 S2 S1
S2 S1 S2

The state represents that there has been an even number of 0s in the input so far, while signifies an odd number. A 1 in the input does not change the state of the automaton. When the input ends, the state will show whether the input contained an even number of 0s or not. If the input did contain an even number of 0s, will finish in state, an accepting state, so the input string will be accepted.

The language recognized by is the regular language given by the regular expression (1*) (0 (1*) 0 (1*))*, where * is the Kleene star, e.g., 1* denotes any number (possibly zero) of consecutive ones.

Variations

Complete and incomplete

According to the above definition, deterministic finite automata are always complete: they define from each state a transition for each input symbol.

While this is the most common definition, some authors use the term deterministic finite automaton for a slightly different notion: an automaton that defines at most one transition for each state and each input symbol; the transition function is allowed to be partial.[4] When no transition is defined, such an automaton halts.

Local automata

A local automaton is a DFA, not necessarily complete, for which all edges with the same label lead to a single vertex. Local automata accept the class of local languages, those for which membership of a word in the language is determined by a "sliding window" of length two on the word.[5] [6]

A Myhill graph over an alphabet A is a directed graph with vertex set A and subsets of vertices labelled "start" and "finish". The language accepted by a Myhill graph is the set of directed paths from a start vertex to a finish vertex: the graph thus acts as an automaton.[5] The class of languages accepted by Myhill graphs is the class of local languages.[7]

Randomness

When the start state and accept states are ignored, a DFA of states and an alphabet of size can be seen as a digraph of vertices in which all vertices have out-arcs labeled (a -out digraph). It is known that when is a fixed integer, with high probability, the largest strongly connected component (SCC) in such a -out digraph chosen uniformly at random is of linear size and it can be reached by all vertices.[8] It has also been proven that if is allowed to increase as increases, then the whole digraph has a phase transition for strong connectivity similar to Erdős–Rényi model for connectivity.[9]

In a random DFA, the maximum number of vertices reachable from one vertex is very close to the number of vertices in the largest SCC with high probability.[10] This is also true for the largest induced sub-digraph of minimum in-degree one, which can be seen as a directed version of -core.

Closure properties

If DFAs recognize the languages that are obtained by applying an operation on the DFA recognizable languages then DFAs are said to be closed under the operation. The DFAs are closed under the following operations.

For each operation, an optimal construction with respect to the number of states has been determined in state complexity research.Since DFAs are equivalent to nondeterministic finite automata (NFA), these closures may also be proved using closure properties of NFA.

As a transition monoid

A run of a given DFA can be seen as a sequence of compositions of a very general formulation of the transition function with itself. Here we construct that function.

For a given input symbol

a\in\Sigma

, one may construct a transition function

\deltaa:QQ

by defining

\deltaa(q)=\delta(q,a)

for all

q\inQ

. (This trick is called currying.) From this perspective,

\deltaa

"acts" on a state in Q to yield another state. One may then consider the result of function composition repeatedly applied to the various functions

\deltaa

,

\deltab

, and so on. Given a pair of letters

a,b\in\Sigma

, one may define a new function

\widehat\deltaab=\deltaa\circ\deltab

, where

\circ

denotes function composition.

Clearly, this process may be recursively continued, giving the following recursive definition of

\widehat\delta:Q x \Sigma\starQ

:

\widehat\delta(q,\epsilon)=q

, where

\epsilon

is the empty string and

\widehat\delta(q,wa)=\deltaa(\widehat\delta(q,w))

, where

w\in\Sigma*,a\in\Sigma

and

q\inQ

.

\widehat\delta

is defined for all words

w\in\Sigma*

. A run of the DFA is a sequence of compositions of

\widehat\delta

with itself.

Repeated function composition forms a monoid. For the transition functions, this monoid is known as the transition monoid, or sometimes the transformation semigroup. The construction can also be reversed: given a

\widehat\delta

, one can reconstruct a

\delta

, and so the two descriptions are equivalent.

Advantages and disadvantages

DFAs are one of the most practical models of computation, since there is a trivial linear time, constant-space, online algorithm to simulate a DFA on a stream of input. Also, there are efficient algorithms to find a DFA recognizing:

Because DFAs can be reduced to a canonical form (minimal DFAs), there are also efficient algorithms to determine:

DFAs are equivalent in computing power to nondeterministic finite automata (NFAs). This is because, firstly any DFA is also an NFA, so an NFA can do what a DFA can do. Also, given an NFA, using the powerset construction one can build a DFA that recognizes the same language as the NFA, although the DFA could have exponentially larger number of states than the NFA.[11] [12] However, even though NFAs are computationally equivalent to DFAs, the above-mentioned problems are not necessarily solved efficiently also for NFAs. The non-universality problem for NFAs is PSPACE complete since there are small NFAs with shortest rejecting word in exponential size. A DFA is universal if and only if all states are final states, but this does not hold for NFAs. The Equality, Inclusion and Minimization Problems are also PSPACE complete since they require forming the complement of an NFA which results in an exponential blow up of size.[13]

On the other hand, finite-state automata are of strictly limited power in the languages they can recognize; many simple languages, including any problem that requires more than constant space to solve, cannot be recognized by a DFA. The classic example of a simply described language that no DFA can recognize is bracket or Dyck language, i.e., the language that consists of properly paired brackets such as word "". Intuitively, no DFA can recognize the Dyck language because DFAs are not capable of counting: a DFA-like automaton needs to have a state to represent any possible number of "currently open" parentheses, meaning it would need an unbounded number of states. Another simpler example is the language consisting of strings of the form anbn for some finite but arbitrary number of as, followed by an equal number of bs.[14]

DFA identification from labeled words

See main article: Induction of regular languages. Given a set of positive words

S+\subset\Sigma*

and a set of negative words

S-\subset\Sigma*

one can construct a DFA that accepts all words from

S+

and rejects all words from

S-

: this problem is called DFA identification (synthesis, learning).While some DFA can be constructed in linear time, the problem of identifying a DFA with the minimal number of states is NP-complete.[15] The first algorithm for minimal DFA identification has been proposed by Trakhtenbrot and Barzdin[16] and is called the TB-algorithm.However, the TB-algorithm assumes that all words from

\Sigma

up to a given length are contained in either

S+\cupS-

.

Later, K. Lang proposed an extension of the TB-algorithm that does not use any assumptions about

S+

and

S-

, the Traxbar algorithm.[17] However, Traxbar does not guarantee the minimality of the constructed DFA.In his work[15] E.M. Gold also proposed a heuristic algorithm for minimal DFA identification.Gold's algorithm assumes that

S+

and

S-

contain a characteristic set of the regular language; otherwise, the constructed DFA will be inconsistent either with

S+

or

S-

.Other notable DFA identification algorithms include the RPNI algorithm,[18] the Blue-Fringe evidence-driven state-merging algorithm,[19] and Windowed-EDSM.[20] Another research direction is the application of evolutionary algorithms: the smart state labeling evolutionary algorithm[21] allowed to solve a modified DFA identification problem in which the training data (sets

S+

and

S-

) is noisy in the sense that some words are attributed to wrong classes.

Yet another step forward is due to application of SAT solvers by Marjin J. H. Heule and S. Verwer: the minimal DFA identification problem is reduced to deciding the satisfiability of a Boolean formula.[22] The main idea is to build an augmented prefix-tree acceptor (a trie containing all input words with corresponding labels) based on the input sets and reduce the problem of finding a DFA with

C

states to coloring the tree vertices with

C

states in such a way that when vertices with one color are merged to one state, the generated automaton is deterministic and complies with

S+

and

S-

.Though this approach allows finding the minimal DFA, it suffers from exponential blow-up of execution time when the size of input data increases.Therefore, Heule and Verwer's initial algorithm has later been augmented with making several steps of the EDSM algorithm prior to SAT solver execution: the DFASAT algorithm.[23] This allows reducing the search space of the problem, but leads to loss of the minimality guarantee.Another way of reducing the search space has been proposed by Ulyantsev et al.[24] by means of new symmetry breaking predicates based on the breadth-first search algorithm:the sought DFA's states are constrained to be numbered according to the BFS algorithm launched from the initial state. This approach reduces the search space by

C!

by eliminating isomorphic automata.

Equivalent models

Read-only right-moving Turing machines

Read-only right-moving Turing machines are a particular type of Turing machine that only moves right; theseare almost exactly equivalent to DFAs.[25] The definition based on a singly infinite tape is a 7-tuple

M=\langleQ,\Gamma,b,\Sigma,\delta,q0,F\rangle,

where

Q

is a finite set of states;

\Gamma

is a finite set of the tape alphabet/symbols;

b\in\Gamma

is the blank symbol (the only symbol allowed to occur on the tape infinitely often at any step during the computation);

\Sigma

, a subset of

\Gamma

not including b, is the set of input symbols;

\delta:Q x \Gamma\toQ x \Gamma x \{R\}

is a function called the transition function, R is a right movement (a right shift);

q0\inQ

is the initial state;

F\subseteqQ

is the set of final or accepting states.

The machine always accepts a regular language. There must exist at least one element of the set (a HALT state) for the language to be nonempty.

Example of a 3-state, 2-symbol read-only Turing machine

Current state ACurrent state BCurrent state C
tape symbol Write symbolMove tapeNext stateWrite symbolMove tapeNext stateWrite symbolMove tapeNext state
0 1 RB 1 RA 1 RB
1 1 RC 1 RB 1 N HALT

Q=\{A,B,C,HALT\};

\Gamma=\{0,1\};

b=0

, "blank";

\Sigma=\varnothing

, empty set;

\delta=

see state-table above;

q0=A

, initial state;

F=

the one element set of final states:

\{HALT\}

.

References

Notes and References

  1. [Deterministic finite automaton#HMU|Hopcroft 2001]
  2. [Deterministic finite automaton#MP43|McCulloch and Pitts (1943)]
  3. [Deterministic finite automaton#RS59|Rabin and Scott (1959)]
  4. Book: Mogensen, Torben Ægidius . Introduction to Compiler Design . Lexical Analysis . Undergraduate Topics in Computer Science . Springer . London . 2011 . 10.1007/978-0-85729-829-4_1 . 12. 978-0-85729-828-7 .
  5. Lawson (2004) p.129
  6. Sakarovitch (2009) p.228
  7. Lawson (2004) p.128
  8. Grusho. A. A.. Limit distributions of certain characteristics of random automaton graphs. Mathematical Notes of the Academy of Sciences of the USSR. 1973. 4. 633–637. 10.1007/BF01095785. 121723743. Grusho1973.
  9. Cai . Xing Shi . Devroye . Luc . The graph structure of a deterministic automaton chosen at random . Random Structures & Algorithms . October 2017 . 51 . 3 . 428–458 . 10.1002/rsa.20707. 1504.06238 . 13013344 .
  10. Carayol . Arnaud . Nicaud . Cyril . February 2012 . Distribution of the number of accessible states in a random deterministic automaton . 14 . 194–205 . STACS'12 (29th Symposium on Theoretical Aspects of Computer Science) . Paris, France .
  11. Sakarovitch (2009) p.105
  12. Lawson (2004) p.63
  13. Web site: Esparza Estaun . Francisco Javier . Sickert . Salomon . Blondin . Michael . 16 November 2016 . Operations and tests on sets: Implementation on DFAs . dead . https://web.archive.org/web/20180808171506/https://www7.in.tum.de/um/courses/auto/ws1718/slides1718/04-Implementations_sets.pdf . 8 August 2018 . Automata and Formal Languages 2017/18 .
  14. Lawson (2004) p.46
  15. Gold. E. M.. E. Mark Gold. Complexity of Automaton Identification from Given Data. Information and Control. 37. 3. 302–320. 1978. 10.1016/S0019-9958(78)90562-4. Gold78.
  16. Book: Finite Automata: Behavior and Synthesis. 9781483297293. De Vries. A.. 28 June 2014. Elsevier .
  17. Book: 10.1145/130385.130390. Random DFA's can be approximately learned from sparse uniform examples. Proceedings of the fifth annual workshop on Computational learning theory - COLT '92. 45–52. 1992. Lang. Kevin J.. 089791497X. 7480497.
  18. Book: 10.1142/9789812797902_0004. Inferring Regular Languages in Polynomial Updated Time. Pattern Recognition and Image Analysis. 1. 49–61. Series in Machine Perception and Artificial Intelligence. 1992. Oncina. J.. García. P.. 978-981-02-0881-3.
  19. Book: 10.1007/BFb0054059. Results of the Abbadingo one DFA learning competition and a new evidence-driven state merging algorithm. Grammatical Inference. 1433. 1–12. Lecture Notes in Computer Science. 1998. Lang. Kevin J.. Pearlmutter. Barak A.. Price. Rodney A.. 978-3-540-64776-8.
  20. Book: Beyond EDSM Proceedings of the 6th International Colloquium on Grammatical Inference: Algorithms and Applications. 23 September 2002. 37–48. 9783540442394.
  21. 10.1109/TPAMI.2005.143. 16013754. Learning deterministic finite automata with a smart state labeling evolutionary algorithm. IEEE Transactions on Pattern Analysis and Machine Intelligence. 27. 7. 1063–1074. 2005. Lucas. S.M.. Reynolds. T.J.. 14062047.
  22. Heule. M. J. H.. Grammatical Inference: Theoretical Results and Applications . Marijn Heule. Exact DFA Identification Using SAT Solvers. Lecture Notes in Computer Science . Grammatical Inference: Theoretical Results and Applications. ICGI 2010. Lecture Notes in Computer Science. 2010. 6339. 66–79. 10.1007/978-3-642-15488-1_7. 978-3-642-15487-4 . Heule2010.
  23. 10.1007/s10664-012-9222-z. Software model synthesis using satisfiability solvers. Empirical Software Engineering. 18. 4. 825–856. 2013. Heule. Marijn J. H.. Marijn Heule. Verwer. Sicco. 2066/103766. 17865020. free.
  24. Book: 10.1007/978-3-319-15579-1_48. BFS-Based Symmetry Breaking Predicates for DFA Identification. Language and Automata Theory and Applications. 8977. 611–622. Lecture Notes in Computer Science. 2015. Ulyantsev. Vladimir. Zakirzyanov. Ilya. Shalyto. Anatoly. 978-3-319-15578-4.
  25. Book: Davis, Martin . Ron Sigal . Elaine J. Weyuker . Second Edition: Computability, Complexity, and Languages and Logic: Fundamentals of Theoretical Computer Science . 2nd . Academic Press, Harcourt, Brace & Company. San Diego . 1994. 0-12-206382-1.