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

25states 24 transitions · 5 final · |Σ| = 8

Non-deterministic: one path per word, all leaving q0. One state has more than one transition on the same symbol (in red).

  1. NFA 25
  2. subset construction 13
  3. minimal 11
walk× walks× walked× talk× talks×
walkwalkswalkedtalktalksq0 · Sq0q1 · Aq1q2 · Bq2q3 · Cq3q4 · U · finalq4q5 · Dq5q6 · Eq6q7 · Fq7q8 · Gq8q9 · V · finalq9q10 · Hq10q11 · Iq11q12 · Jq12q13 · Kq13q14 · Lq14q15 · W · finalq15q16 · Mq16q17 · Nq17q18 · Oq18q19 · X · finalq19q20 · Pq20q21 · Qq21q22 · Rq22q23 · Tq23q24 · Y · finalq24

Hover or tap a word to trace its path. Double circles are final states. Red symbols leave a state on more than one transition.

Transition table
State adeklstw Nonterminal
→ q0 — — — — — — {q16, q20} {q1, q5, q10} S
q1 q2 — — — — — — — A
q2 — — — — q3 — — — B
q3 — — — q4 — — — — C
∗ q4 — — — — — — — — U
q5 q6 — — — — — — — D
q6 — — — — q7 — — — E
q7 — — — q8 — — — — F
q8 — — — — — q9 — — G
∗ q9 — — — — — — — — V
q10 q11 — — — — — — — H
q11 — — — — q12 — — — I
q12 — — — q13 — — — — J
q13 — — q14 — — — — — K
q14 — q15 — — — — — — L
∗ q15 — — — — — — — — W
q16 q17 — — — — — — — M
q17 — — — — q18 — — — N
q18 — — — q19 — — — — O
∗ q19 — — — — — — — — X
q20 q21 — — — — — — — P
q21 — — — — q22 — — — Q
q22 — — — q23 — — — — R
q23 — — — — — q24 — — T
∗ q24 — — — — — — — — Y

→ 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
walk|walks|walked|talk|talks
Elimination steps (25)

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 q1: q0 → q2 wa
  2. remove q2: q0 → q3 wal
  3. remove q3: q0 → q4 walk
  4. remove q4: q0 → f walk
  5. remove q5: q0 → q6 wa
  6. remove q6: q0 → q7 wal
  7. remove q7: q0 → q8 walk
  8. remove q8: q0 → q9 walks
  9. remove q9: q0 → f walk|walks
  10. remove q10: q0 → q11 wa
  11. remove q11: q0 → q12 wal
  12. remove q12: q0 → q13 walk
  13. remove q13: q0 → q14 walke
  14. remove q14: q0 → q15 walked
  15. remove q15: q0 → f walk|walks|walked
  16. remove q16: q0 → q17 ta
  17. remove q17: q0 → q18 tal
  18. remove q18: q0 → q19 talk
  19. remove q19: q0 → f walk|walks|walked|talk
  20. remove q20: q0 → q21 ta
  21. remove q21: q0 → q22 tal
  22. remove q22: q0 → q23 talk
  23. remove q23: q0 → q24 talks
  24. remove q24: q0 → f walk|walks|walked|talk|talks
  25. remove q0: s → f walk|walks|walked|talk|talks

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, G, H, I, J, K, L, M, N, O, P, Q, R, T}, Σ = {a, d, e, k, l, s, t, w}, 24 rules.

S→ wA|wD|wH|tM|tP
A→ aB
B→ lC
C→ k
D→ aE
E→ lF
F→ kG
G→ s
H→ aI
I→ lJ
J→ kK
K→ eL
L→ d
M→ aN
N→ lO
O→ k
P→ aQ
Q→ lR
R→ kT
T→ s
Nonterminals and states

S = q0, A = q1, B = q2, C = q3, D = q5, E = q6, F = q7, G = q8, H = q10, I = q11, J = q12, K = q13, L = q14, M = q16, N = q17, O = q18, P = q20, Q = q21, R = q22, T = q23, U = q4, V = q9, W = q15, X = q19, Y = q24