# Lecture 21: deterministic finite automata

• We started with a second example proof by structural induction; this has been added to the end of the notes for lecture 20

• We defined deterministic finite automata, and the extended transition function

• Review exercises:
• Write the definition of $$\hat{δ}$$.
• Let $$M$$ be a machine with one final state $$q$$; and a transition function that takes $$q$$ back to $$q$$ on every character of $$Σ$$. Find $$L(M)$$
• If every $$x \in L$$ is accepted by $$M$$, is $$L$$ recognized by $$M$$?
• If $$L$$ is recognized by $$M$$, is every string in $$L$$ accepted by $$M$$?
• Draw an automaton that recognizes the set of even length strings, the set of all strings, the empty set, etc.

## Overview

An automaton is an extremely simple model of a computer or a program. The automata we will study examine an input string character by character and either say "yes" (accept the string) or "no" (reject the string).

Automata are defined by state transition diagrams. Here is one example:

This automaton processes strings containing the characters 0 and 1. It contains 4 states, $$q_{ee}$$, $$q_{eo}$$, $$q_{oe}$$ and $$q_{oo}$$.

While processing a string $$x$$, the machine starts at the beginning of $$x$$, and in the start state $$q_{ee}$$ (as indicated by the arrow pointing to $$q_{ee}$$). As it processes each character, it follows the corresponding transitions (arrows). When it has finished processing the string, if it is in a final state ($$q_{eo}$$ in this case, as indicated by the double circle), it accepts $$x$$; otherwise it rejects $$x$$.

For example, while processing $$1000110$$, the machine will start in state $$q_{ee}$$, then transition in order to states $$q_{eo}$$ (after processing the 1), $$q_{oo}$$ (after the first 0), then $$q_{eo}$$, $$q_{oo}$$, $$q_{eo}$$, $$q_{ee}$$, and finally end up in $$q_{eo}$$. Since $$q_{eo}$$ is an accepting state, the string $$1000110$$ is accepted.

Although this model of computation is very limited, it is sophisticated enough to demonstrate several kinds of analysis that apply to more sophisticated models:

• we'll talk about translating "programs" (automata) from one representation to another, and proving that those translations are correct. This is analagous to building and verifying compilers

• we'll show how to optimise automata, again proving that our optimizations don't change the behavior of the program

• we'll show that there are specifications (sets of strings) that can't be recognized by any automaton. Similar results apply to fully general models of computation, and have important practical implications.

• we'll talk about non-determinism, an important concept when reasoning about programs.

## Definitions

Before we do any of that, we need to formalize the informal definition of an automaton and its operation.

Definitions: A deterministic finite automaton $$M$$ is a 5-tuple $$M = (Q,Σ,δ,q_0,F)$$, where

• $$Q$$ is a finite set, called the set of states of $$M$$;
• $$Σ$$ is a finite set called the alphabet of $$M$$ (elements of $$Σ$$ are called characters)
• $$δ$$ is a function $$δ : Q \times Σ → Q$$, called the transition function. In the picture, there is a transition from $$q$$ to $$q'$$ on input $$a$$ if $$δ(q,a) = q'$$.
• $$q_0 \in Q$$ is the start state
• $$F \subseteq Q$$ is the set of final states

In the example diagram above,

• $$Q = \{q_{ee}, q_{eo}, q_{oe}, q_{oo}\}$$
• $$Σ = \{0,1\}$$
• $$δ$$ is given by the following table:
$$q$$ $$a$$ $$δ(q,a)$$
$$q_{ee}$$ 0 $$q_{oe}$$
$$q_{ee}$$ 1 $$q_{eo}$$
$$q_{eo}$$ 0 $$q_{oo}$$
$$q_{eo}$$ 1 $$q_{ee}$$
$$q_{oe}$$ 0 $$q_{ee}$$
$$q_{oe}$$ 1 $$q_{oo}$$
$$q_{oo}$$ 0 $$q_{eo}$$
$$q_{oo}$$ 1 $$q_{oe}$$
• $$q_0 = q_{ee}$$
• $$F = \{q_{eo}\}$$

Given an automaton $$M$$, we define the extended transition function $$\hat{δ} : Q \times \Sigma^{\bf *} → Q$$. Informally, $$\hat{δ}(q,x)$$ tells us where $$M$$ ends up after processing the entire string $$x$$; contrast the domain with that of $$δ$$, which processes only a single character. This distinction is important: since $$δ$$ only processes characters, its domain is finite, so the description of the machine is finite; but $$\hat{δ}$$ (which is not part of the description of the machine) can process an infinite number of strings.

Definition: Formally, we define the extended transition function $$\hat{δ} : Q \times Σ^* → Q$$ inductively by $$\hat{δ}(q,ε) = q$$, and $$\hat{δ}(q,xa) = δ(\hat{δ}(q,x), a)$$.

The first part of this definition says that processing the empty string doesn't move the machine; the second part says that to process $$xa$$, you first process $$x$$, and then take one more step using $$a$$ from wherever $$x$$ gets you.