FSA from words to automata

finite-state automata · regular expressions · type-3 grammars

Separate words with spaces, commas or new lines. Each character is one symbol; type ε for the empty word.

Automaton

8states 7 transitions · 1 final · |Σ| = 5

Non-deterministic: one path per word, all leaving q0. No two words share their first symbol, so this NFA happens to be deterministic.

  1. NFA 8
  2. subset construction 8
  3. minimal 8
cantava
cantavaq0 · Sq0q1 · Aq1q2 · Bq2q3 · Cq3q4 · Dq4q5 · Eq5q6 · Fq6q7 · G · finalq7

Hover or tap a word to trace its path. Double circles are final states.

Transition table
State acntv Nonterminal
→ q0 — q1 — — — S
q1 q2 — — — — A
q2 — — q3 — — B
q3 — — — q4 — C
q4 q5 — — — — D
q5 — — — — q6 E
q6 q7 — — — — F
∗ q7 — — — — — G

→ initial, ∗ final. Empty cells (—) lead to rejection.

Regular expression

Equivalent to the NFA shown, by state elimination. Each automaton gives a different but equivalent expression: compare NFA, DFA and minimal DFA.

Notation
cantava
Elimination steps (8)

A new initial state s and final state f are linked by ε to the automaton; then each state is removed, and every path through it becomes one edge labelled with the concatenation. States with one way in and one way out go first.

  1. remove q0: s → q1 c
  2. remove q1: s → q2 ca
  3. remove q2: s → q3 can
  4. remove q3: s → q4 cant
  5. remove q4: s → q5 canta
  6. remove q5: s → q6 cantav
  7. remove q6: s → q7 cantava
  8. remove q7: s → f cantava

Regular grammar

Right-linear rewriting rules read off the NFA: one nonterminal per state, S for q0.

Form

Chomsky type-3 form: p —a→ q gives P → a Q when q has a way out, and P → a when q is final; S → ε only if ε is a word.

G = ⟨N, Σ, P, S⟩ with N = {S, A, B, C, D, E, F}, Σ = {a, c, n, t, v}, 7 rules.

S→ cA
A→ aB
B→ nC
C→ tD
D→ aE
E→ vF
F→ a
Nonterminals and states

S = q0, A = q1, B = q2, C = q3, D = q4, E = q5, F = q6, G = q7