Sub topic 9
From Automaton to Regular Expression
Prerequisites and goal
Assume you know the definitions of regular languages, deterministic finite automata (DFAs), nondeterministic finite automata (NFAs), and regular-expression operators such as union, concatenation, and Kleene star.
A regular expression describes exactly the strings accepted by a finite automaton. Converting an automaton to a regular expression is useful when a problem gives a state diagram but asks for a pattern or language description.
Generalized automata
The standard method is state elimination. First convert the automaton into a generalized finite automaton. A generalized automaton allows each edge to be labeled by a regular expression instead of one symbol.
Add:
- A new start state with an epsilon transition to the old start state.
- A new final state with epsilon transitions from every old accepting state.
- No edge entering the new start state.
- No edge leaving the new final state.
If several edges connect the same pair of states, replace them with one edge labeled by their union.
For example, edges labeled a and b become a|b.
State-elimination rule
Suppose state q is removed. For every remaining pair of states i and j, update the label from i to j as follows:
Rij = Rij | Riq(Rqq)*Rqj
Here:
Rijis the old path fromitoj.Riqis the path fromito the removed state.Rqqis the loop on the removed state.Rqjis the path from the removed state toj.
The new term describes every path that enters q, loops there zero or more times, and then leaves it.
Continue eliminating states until only the new start and new final states remain. The label on the remaining edge is the required regular expression.
Worked example
Consider a DFA over {a,b}:
q0is the start state.q1is accepting.q0has a loop labeleda.q0goes toq1onb.q1has a loop labeleda|b.
This automaton accepts strings containing at least one b.
After adding the new states, eliminate q0:
- The path from the new start to
q0isε. - The loop on
q0isa. - The path from
q0toq1isb.
Therefore, the new path from the start to q1 is:
εa*b = a*b
The loop on q1 remains (a|b). The resulting expression is:
a*b(a|b)*
This means: read zero or more a symbols, then read one b, then read any sequence of a and b symbols.
Common errors
| Error | Correction | Column |
|---|---|---|
| Forgetting the new final state | Add one final state even when the original automaton has one accepting state | |
| Omitting the self-loop term | Include `(Rqq)*` when eliminating a state | |
| Confusing union and concatenation | `R | S` chooses one path; `RS` follows both paths |
| Ignoring parentheses | Parenthesize unions before applying star or concatenation |
Exercise
What language does the expression a*b(a|b)* describe?
Show answer
All strings over {a,b} that contain at least one b.