Decompiling NFA to Regular Expressions
Goal
Given an NFA , construct a regular expression with .
The State Elimination Method
Setup
Given NFA , we compute a regex for paths through .
Normalisation
First, transform to have:
- A single start state (with no incoming edges)
- A single accepting state (with no outgoing edges)
Add new start with -edge to .
Add new accept with -edges from all states in .
Regional Languages
Definition
A region specifies:
- Source state
- Target state
- Set of states allowed as intermediate
The regional language is the set of strings labelling paths from to using only states in as intermediate nodes.
Base Case:
Where label the direct edges from to .
Inductive Step
For where :
Interpretation
Paths from to through either:
- Don’t visit at all (stay in ):
- Visit at least once:
- Go staying in :
- Loop at zero or more times:
- Go staying in :
Algorithm
- Normalise: single start , single accept
- Compute by eliminating states one by one
- The result is
Order of Elimination
The order in which states are eliminated does not affect correctness, but can affect the size of the resulting regex.
Common strategies:
- Eliminate states with few transitions first
- Eliminate “middle” states before endpoints
Example
Automaton
Two-state NFA: , with accepting.
Computation
We want .
Let .
Eliminate in some order. Suppose we eliminate first.
Actually, with normalisation, we have start and accept . The internal states are .
Compute :
- Paths: , or
- , etc.
After elimination: the language is plus accounting for -transitions.
Size Considerations
Worst Case
The regex may grow exponentially as states are eliminated due to the union and concatenation operations.
Optimisation
- Factor common subexpressions
- Use algebraic simplifications (e.g., , )
- Choose good elimination order
Closure under Complement
Using automaton-to-regex conversion:
- Convert regex to DFA (via NFA)
- Swap accepting and non-accepting states
- Convert back to regex
This shows regular languages are closed under complement.
Summary
- Compute regex for paths through region
- Base case: direct transitions
- Inductive step:
- Eliminate all internal states to get the full language