Deterministic Finite Automaton
A DFA is tuple
( the language we want to build) (states) (final sates) (alphabet) (transfer function)

Relation to Moore FSM
DFA \subset FSM
## Step relation and computations A **configuration** $(q,w)$ consists of the current state $q\in Q$ and the unread input $w\in\Sigma^{*}$. The one-step relation consumes one symbol:(q,aw)\vdash_M(\delta(q,a),w), \qquad a\in\Sigma,\ w\in\Sigma
Its reflexive and [[Relation#Transitive Closure|transitive closure]] $\vdash_M^{*}$ describes zero or more steps. Thus(q,w)\vdash_M
means that the automaton starts in state $q$ with unread input $w$ and reaches state $p$ with unread input $u$. Equivalently, there exists $v\in\Sigma^{*}$ such thatw=vu\quad\text{and}\quad\hat{\delta}(q,v)=p.
The case $v=\lambda$ represents zero steps: $(q,w)\vdash_M^{*}(q,w)$. ## Extended transition function The transition function $\delta:Q\times\Sigma\to Q$ reads one symbol. Its extension\hat{\delta}:Q\times\Sigma^{*}\to Q
\hat{\delta}(q,\lambda)=q,
\hat{\delta}(q,wa)=\delta(\hat{\delta}(q,w),a), \qquad q\in Q,\ w\in\Sigma^{*},\ a\in\Sigma.
Here $w$ may be empty. In particular, $\hat{\delta}(q,a)=\delta(q,a)$. Reading a concatenation is equivalent to reading its parts in sequence:\hat{\delta}(q,uv)=\hat{\delta}(\hat{\delta}(q,u),v).
## Accepted language A word is accepted if the automaton reaches an accepting state after consuming the entire input:L(M)={w\in\Sigma^{*}\mid\hat{\delta}(q_0,w)\in F}.
L(M)={w\in\Sigma^{}\mid\exists p\in F:\ (q_0,w)\vdash_M^{}(p,\lambda)}.
In particular, $\lambda\in L(M)$ if and only if $q_0\in F$. > [!note] Regular languages > > The languages recognized by DFAs are exactly the [[Regular Language|regular languages]]. ## Classes of words induced by states For each $p\in Q$, defineKl[p]={w\in\Sigma
This is the set of words that lead from the initial state to $p$. Every word reaches exactly one state, so\Sigma^{*}=\bigcup_{p\in Q}Kl[p], \qquad Kl[p]\cap Kl[r]=\emptyset\quad\text{for }p\neq r.
The non-empty classes form a partition of $\Sigma^{*}$ into at most $|Q|$ classes. An unreachable state has an empty class. The accepted language is the union of the classes associated with accepting states:L(M)=\bigcup_{p\in F}Kl[p].
By [[Regular Language#Lemmas|Lemma 3.3]], words in the same class have the same acceptance outcome after any common suffix is appended. ## Example: tracking the parity of symbol counts Consider a DFA over $\Sigma=\{0,1\}$ with states $Q=\{q_0,q_1,q_2,q_3\}$, initial state $q_0$, and accepting states $F=\{q_0,q_3\}$. Each state records the parity of the number of zeros and ones read so far: | State | Number of zeros | Number of ones | On `0` | On `1` | Accepting? | | --- | --- | --- | --- | --- | --- | | $q_0$ | Even | Even | $q_2$ | $q_1$ | Yes | | $q_1$ | Even | Odd | $q_3$ | $q_0$ | No | | $q_2$ | Odd | Even | $q_0$ | $q_3$ | No | | $q_3$ | Odd | Odd | $q_1$ | $q_2$ | Yes | Reading `0` toggles the parity of the zero count; reading `1` toggles the parity of the one count. Therefore,\begin{aligned} Kl[q_0]&={w\mid |w|_0\text{ and }|w|_1\text{ are even}},\ Kl[q_1]&={w\mid |w|_0\text{ is even and }|w|_1\text{ is odd}},\ Kl[q_2]&={w\mid |w|_0\text{ is odd and }|w|_1\text{ is even}},\ Kl[q_3]&={w\mid |w|_0\text{ and }|w|_1\text{ are odd}}, \end{aligned} \qquad w\in{0,1}
\begin{aligned} L(M)&=Kl[q_0]\cup Kl[q_3]\ &={w\in{0,1}^{}\mid |w|_0+|w|_1\equiv0\pmod2}\ &={w\in{0,1}^{}\mid |w|\text{ is even}}. \end{aligned}
For example, $\lambda$, `00`, `01`, and `11` are accepted, while `0`, `1`, and `010` are rejected. > [!tip] A smaller DFA for the same language > > This four-state DFA remembers both parities separately. To recognize even-length words, only the parity of the total length is needed, so a two-state DFA suffices: each symbol toggles between an accepting even state and a rejecting odd state. Distinct states of a DFA need not represent distinguishable classes of words.