Exercise

Does My Automaton Do What I Meant?

Build a deterministic finite automaton (DFA) with a drawing or with a table, and check it against a language or against another automaton: the tool returns a shortest word on which the answers differ, and the states the automaton visits while reading it.

Last updated:


Checking an automaton against a language

A hand-designed automaton looks right until one word shows otherwise.
This tool checks an automaton that you build against a language, or against another automaton of yours, and decides exactly whether they accept the same words, without trying words one by one.
When they do not, it returns a shortest counterexample: a word on which the answers differ, with no shorter word on which they differ, and the states that your automaton visits while reading it.

How to use the workbench
  1. Double-click an empty place to add a state, and drag a state to move it. Double-click a state to make it accepting, or not accepting.
  2. Hold Shift and drag from an empty place to a state to mark it as the start state (drag the tail of its arrow to move or resize it). Hold Shift and drag from a state to another state (or back to the same state) to draw an arrow, then type its letters, separated by commas, and press Enter. Drag an arrow to bend it, and press Delete or Backspace to remove the selected state or arrow.
  3. Everything the drawing can do can also be done in the list of states and the transition table, with a keyboard or on a touch screen.
  4. Choose what to check against, and press “Check”. A deterministic finite automaton (DFA) must have exactly one arrow from every state on every letter; the workbench lists what is missing.

The workbench needs JavaScript. Use the questions below on paper instead.

Questions

Question 1. In machine A, build a DFA over {a,b}\{a,b\} for the words that end with abab⁠.
Choose “Words that end with ab” in “Check against” and press “Check”.
If the workbench shows a word, find the arrow that gives the wrong answer on it and fix it.

Hint

Remember how many letters of abab the end of the word matches so far.
What happens after aa⁠, after abab⁠, and after a letter that breaks the match?

Answer

Three states: q0q_0 (the word does not end with aa or abab⁠, start), q1q_1 (ends with aa⁠) and q2q_2 (ends with abab⁠, accepting).
From q0q_0⁠: a→q1a\to q_1⁠, b→q0b\to q_0⁠. From q1q_1⁠: a→q1a\to q_1⁠, b→q2b\to q_2⁠. From q2q_2⁠:
a→q1a\to q_1⁠, b→q0b\to q_0⁠. The workbench then reports that the machine accepts exactly the words of the language.

Question 2. In machine A, build a DFA over {a,b}\{a,b\} for the words that contain abab⁠, and in machine B a DFA for the words that end with abab⁠.
Before pressing “Check”, predict the shortest word on which they differ.
Then check machine A against the other machine.

Hint

Look for a word that contains abab without ending with it.
Compare all words of length at most 33 in the alphabetical order of their letters.

Answer

The word is abaaba⁠: it contains abab but ends with aa⁠, so machine A accepts it and machine B rejects it.
Every shorter word gets the same verdict from both machines:
ε,a,b,aa,ba,bb\varepsilon,a,b,aa,ba,bb are rejected by both and abab is accepted by both. Among the words of length 33 that differ, abaaba comes before abbabb in alphabetical order.

Back to Designing a Deterministic Finite Automaton, or see the glossary.