6. Dfa to Regex conversions
6.1. State elimination
Consider the following DFAs:
Convert the given DFAs to a Regex (using the state-elimination strategy). Hint: is it easier to apply conversion on another DFA?
6.2. Brzozowsky's algebraic method
Janusz Brzozowski worked out a very elegant (and more computationally efficient) way to convert Dfa's to Regexes. It relies on an observation called Arden's Lemma:
Arden's Lemma
Proposition (Arden's Lemma). Let $ X, A$ and $ B$ be languages, such that $ X = A\cdot X \cup B$ . Then $ X = A^*B$ .
- Note that we can apply Arden's lemma in various settings, for instance, let $ e_A, e_B$ be regexes such that $ X = L(e_A)\cdot X \cup L(e_B)$ . Then $ X = L(e_A^*e_B)$ .
Dfa to regex conversion
For each state $ q$ , build an equation of the form: $ q = c_1 q_1 \cup c_2 q_2 \ldots c_n q_n$ , such that: $ \delta(q,c_i) = q_i$ . Here $ c_i\in\Sigma$ , thus $ q_i$ are the $ c_i$ -successors of $ q$ . Additionally, if $ q$ is a final state, add an $ \epsilon$ : $ q = c_1 q_1 \cup c_2 q_2 \ldots c_n q_n \cup \epsilon$ .
Equations
Equations are expressions containing regexes together with state variables (like $ q_1$ ). Which are the unknowns. An equation of the form $ q = e\cdot q'$ signifies the fact that $ L(A_q) = L(e) L(A_{q'})$ , where $ L(A_q), L(A_{q'})$ are the languages accepted by our Dfa, starting from states $ q$ and $ q'$ , respectively.
Reducing the system of equations
We can choose any equation except that corresponding to the initial state, and eliminate it, by exploiting Arden's Lemma:
- the solution to any equation of the form $ q = e\cdot q \cup e'$ is $ q = e^*e'$ .
Example
Going back to the previous system of equations, we can find the solution to $ q_2$ which is: $ (A \cup B)^*$ . Next, we can replace the solution to $ q_2$ in $ q_1$ which yields:
- $ q_1 = A q_1 \cup B(A\cup B)^*$ .
- We apply Arden's Lemma one more time and yield: $ q_1 = A^*B(A \cup B)^*$ .
Another example
- We reduce the system by removing the second equation:
- $ q_2 = A^*(Bq_1\cup \epsilon)$
- We replace $ q_2$ into the first equation:
- $ q_1 = A q_1 \cup BA^*(B q_1 \cup \epsilon) = (A \cup BA^*B^*) q_1 \cup BA^*$
- and we apply Arden's lemma again: $ q_1 = (A \cup BA^*B)^*BA^*$