Automata
Last time, we saw that state diagrams were useful as compact representations of some top-down puzzle games like Sokoban and mazes. Our definition of "state diagram" was a bit informal, but that was actually for good reason: they are supposed to be useful pictures, not mathematical objects per-se. This section is about the formal definition of automaton and its consequences (first introduced by Stephen Cole Kleene in the 1950s while working at the RAND corporation).
What do you mean by formal? Well, I'm so glad you asked. A formal definition is really a precise, unambiguous description (as in it cannot be interpreted in more than one way) of a mathematical object. The data of a formal definition consists of all of the components of the object it is defining. In our case, the mathematical object in question is a mathematical model of a computer called an automaton, and the data of the definition is contained in the bullet points below it.
- A set \(Q\) of states, called the state space
- A finite set \(A\) of input letters, called the input alphabet
- A set \(\delta \subseteq Q \times A \times Q\) of transitions, called the transition relation
- A set \(F \subseteq Q\) of final (also called accepting) states
Recall that a relation is a set of tuples, which are immutable finite lists (just like in Python). In the definition of automaton, the transition relation is a ternary relation, which means it consists of a set of triples \((x, a, y)\), immutable lists of length \(3\). Every automaton can be drawn visually using a state diagram, just like the ones we drew in the previous section.
Just like with understanding any mathematical definition, it is important to start by considering its most trivial examples.
Just like before, an easy way to write down the transition relation of an automaton is using its transition table.
- Each row of the table corresponds to a state \(x \in Q\)
- The first column of the table records whether the row's state is accepting (\(=1\)) or not accepting (\(=0\))
- All columns but the first colum correspond to an input letter
- In the column corresponding to \(a\) and row corresponding to \(x\), we record the outgoing \(a\)-transitions from \(x\)
\(\to\) | \(F\) | \(\cdots\) | \(a\) |
\(\vdots\) | \(\vdots\) | \(\vdots\) | |
\(x\) | 1 or 0 | \(\cdots\) | \(\delta(x, a)\) |
Transition tables allow us to go back and forth between state diagrams and automata.
\(\textcolor{gray}{\rightarrow}\) | \(F\) | \(\Uparrow\) | \(\Rightarrow\) | \(\Downarrow\) | \(\Leftarrow\) |
\(s_1\) | 0 | \(s_2\) | |||
\(s_2\) | 1 | \(s_3\) | \(s_4\) | ||
\(s_3\) | 1 | \(s_2\) | |||
\(s_4\) | 1 | \(s_2\) |
One thing that we have not addressed at this point is that the definition of automaton that we have given above has a particular feature that games don't really have: a state can have multiple outgoing transitions labelled with the same input letter. When you encounter this kind of situation, you are going to have to write multiple state names into the corresponding item in the transition table.
The way you want to interpret this multiple-out-going-transitions situation is that the automaton "runs each outgoing transition in parallel". This kind of branching-into-threads is called nondeterminism.
Partial, Total, Deterministic, and Nondeterministic Automata
As we stated before, the puzzle game examples of automata have the property that each legal action transports you to at most one state. This is a special property of automata that will come up often throughout the course.
- \(\mathcal A\) is called deterministic if for any state \(x \in Q\) and any input letter \(a \in A\), \(\delta(x, a)\) has one or fewer elements. If \(\mathcal A\) is not deterministic, it is called nondeterministic.
- \(\mathcal A\) is called total if for any state \(x \in Q\) and any input letter \(a \in A\), \(\delta(x, a)\) has at least one element. If \(\mathcal A\) is not total, we say that it is partial.
- \(\mathcal A\) is deterministic and total
- \(\mathcal A\) is nondeterministic and total
- \(\mathcal A\) is nondeterministic and partial
- \(\mathcal A\) is deterministic and partial
- More than one entry in each row/column?
- Exactly one entry in each row/column?
- Less than one entry in each row/column?
Remember from your discrete math course that a function \(f \colon X \to Y\) between two sets \(X\) and \(Y\) is a binary relation \(f \subseteq X \times Y\) such that for any \(x \in X\), there is a unique (i.e., exactly one) \(y \in Y\) such that \((x, y) \in f\). And notationally, if \(f\) is a function and \((x,y) \in f\), then you can write \(f(x) = y\).
Note. Just to be clear: in the literature, "nondeterministic" usually means "not necessarily deterministic". Technically speaking, with the usual definition of "nondeterministic", every automaton is nondeterministic. There is a reason for this, but that reason is beyond the scope of the course. For us, "nondeterministic" means that some state has more than one outgoing transition.