FA to Regular Expression (GNFA State Elimination)
Context: FIT2014_MOC Β· legs 3β4 of the Kleeneβs Theorem cycle β the return journey from machine to expression Β· Assignment 1 hand skill Problem it solves: given an FA/NFA, produce a regular expression describing exactly the language it recognises.
Quick Revision
- π― Trigger: an automaton to convert into a regex β turn it into a standard GNFA, then rip out one state at a time until a single edge remains.
- β‘ Key Constraint: the elimination formula must be applied to every ordered pair before the state is deleted β missing a pair loses strings.
π GNFA β the bridging model
- Definition β a Generalised NFA is an NFA whose transitions may be labelled by regular expressions, not just single letters.
- Acceptance β is accepted if it splits as along a Start-to-Final sequence of transitions labelled with each matching .
- Standard GNFA β one Final state, distinct from the Start state; the Start state has no incoming transitions; the Final state has no outgoing transitions.
- (Sipser additionally demands an arc between every pair of states, using where no transition should occur β βspecial formβ. Not needed for this algorithm, but it simplifies proofs.)
βοΈ Step 1 β FA standard GNFA
- Single Final state with incoming arcs only β if necessary add a new Final state and -transitions from each old Final state to it; the old ones stop being Final.
- Single Start state with outgoing arcs only β if necessary add a new Start state with an -transition to the old Start state; the old one stops being Start.
- Letters are already regexes β every existing edge label is a valid one-letter regular expression, so nothing else changes.
- Language preserved β the resulting GNFA accepts exactly the original language.
βοΈ Step 2 β GNFA regular expression (state elimination)
Repeat until only the Start state, the Final state and one transition remain; that transitionβs label is the answer.
Notation for the state being removed:
| Symbol | Meaning |
|---|---|
| the state being eliminated (neither Start nor Final) | |
| any non-Final state (a predecessor) | |
| any non-Start state (a successor) | |
| label on | |
| label on (self-loop) | |
| label on | |
| existing label on |
The replacement rule β the new label on is
stateDiagram-v2 direction LR qin --> q: R_in q --> q: R_loop q --> qout: R_out qin --> qout: R_direct
- Reading the formula β either go straight from to (), or detour via : enter with , loop there any number of times (, possibly zero), then leave with .
- Do it for all pairs β apply the rule for every and every , then delete . The result is an equivalent GNFA with one fewer state.
π Worked elimination (4-state example)
Eliminating state 2 from a GNFA on states (Start), , , (Final):
| Pair rewritten | New label |
|---|---|
Then eliminating state 3 leaves the single Start-to-Final label:
- Shape of the answer β each elimination round wraps the previous labels in one more layer, which is why these expressions grow quickly and rarely look βsimplifiedβ.
βοΈ Practice
Practice: A GNFA has Start , one middle state and Final , with , , , and no direct edge. Eliminate .
Reference solution (no edge), , , :
- Key move: a missing direct edge contributes , and β so the union term simply disappears.
β οΈ Common Mistakes
- π‘ Eliminate every pair before deleting β the rule runs over all combinations, including (creating or extending a self-loop). Deleting early silently drops paths.
- π‘ Never eliminate the Start or Final state β they are the endpoints; only intermediate states get ripped out.
- π‘ covers zero loops β the star already includes βpass straight through β, so donβt add a separate case for it.
- π‘ No direct edge means , not β contributes nothing to the union; using would wrongly accept skipping the segment entirely.
- π‘ Expect ugly output β the expression is correct even if far from minimal; simplifying is a separate (optional) step.
π§ Active Recall
Explain each part of and why it preserves the language.
Answer
- Short answer: every path from to either avoids β captured by β or passes through it: enter via , take the self-loop any number of times (, including zero), and leave via . The union covers both cases exhaustively.
- Why: Path decomposition β since the two cases partition all routes, replacing them with this single label leaves the accepted string set unchanged; applying it to every pair before deleting ensures no route is lost.
Why must the FA first be converted into a standard GNFA?
Answer
- Short answer: state elimination terminates in a machine with one Start, one Final and one transition. That is only well-defined if there is a single Final state distinct from the Start, with no incoming arcs to Start and no outgoing arcs from Final β otherwise the final surviving edge would not describe the whole language.
- Why: Fresh endpoints via β adding a new Start (with to the old one) and a new Final (with from all old Finals) guarantees these properties without changing the language, since -moves consume no input.