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 · 4 final · |Σ| = 10

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 17
  3. minimal 12
cantava× canti× parlo× parlava×
cantavacantiparloparlavaq0 · Sq0q1 · Aq1q2 · Bq2q3 · Cq3q4 · Dq4q5 · Eq5q6 · Fq6q7 · V · finalq7q8 · Gq8q9 · Hq9q10 · Iq10q11 · Jq11q12 · W · finalq12q13 · Kq13q14 · Lq14q15 · Mq15q16 · Nq16q17 · X · finalq17q18 · Oq18q19 · Pq19q20 · Qq20q21 · Rq21q22 · Tq22q23 · Uq23q24 · 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 acilnoprtv Nonterminal
→ q0 — {q1, q8} — — — — {q13, q18} — — — S
q1 q2 — — — — — — — — — A
q2 — — — — q3 — — — — — B
q3 — — — — — — — — q4 — C
q4 q5 — — — — — — — — — D
q5 — — — — — — — — — q6 E
q6 q7 — — — — — — — — — F
∗ q7 — — — — — — — — — — V
q8 q9 — — — — — — — — — G
q9 — — — — q10 — — — — — H
q10 — — — — — — — — q11 — I
q11 — — q12 — — — — — — — J
∗ q12 — — — — — — — — — — W
q13 q14 — — — — — — — — — K
q14 — — — — — — — q15 — — L
q15 — — — q16 — — — — — — M
q16 — — — — — q17 — — — — N
∗ q17 — — — — — — — — — — X
q18 q19 — — — — — — — — — O
q19 — — — — — — — q20 — — P
q20 — — — q21 — — — — — — Q
q21 q22 — — — — — — — — — R
q22 — — — — — — — — — q23 T
q23 q24 — — — — — — — — — U
∗ 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
cantava|canti|parlo|parlava
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 ca
  2. remove q2: q0 → q3 can
  3. remove q3: q0 → q4 cant
  4. remove q4: q0 → q5 canta
  5. remove q5: q0 → q6 cantav
  6. remove q6: q0 → q7 cantava
  7. remove q7: q0 → f cantava
  8. remove q8: q0 → q9 ca
  9. remove q9: q0 → q10 can
  10. remove q10: q0 → q11 cant
  11. remove q11: q0 → q12 canti
  12. remove q12: q0 → f cantava|canti
  13. remove q13: q0 → q14 pa
  14. remove q14: q0 → q15 par
  15. remove q15: q0 → q16 parl
  16. remove q16: q0 → q17 parlo
  17. remove q17: q0 → f cantava|canti|parlo
  18. remove q18: q0 → q19 pa
  19. remove q19: q0 → q20 par
  20. remove q20: q0 → q21 parl
  21. remove q21: q0 → q22 parla
  22. remove q22: q0 → q23 parlav
  23. remove q23: q0 → q24 parlava
  24. remove q24: q0 → f cantava|canti|parlo|parlava
  25. remove q0: s → f cantava|canti|parlo|parlava

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, U}, Σ = {a, c, i, l, n, o, p, r, t, v}, 24 rules.

S→ cA|cG|pK|pO
A→ aB
B→ nC
C→ tD
D→ aE
E→ vF
F→ a
G→ aH
H→ nI
I→ tJ
J→ i
K→ aL
L→ rM
M→ lN
N→ o
O→ aP
P→ rQ
Q→ lR
R→ aT
T→ vU
U→ a
Nonterminals and states

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