\documentstyle[11pt,twoside,psfig]{article}
\input{defs-6045}
\begin{document}

\handout{dfa-to-regexp}{Class Notes}{February 12, 1992}

\section*{Example: Translating a DFA to a Regular Expression}

This example illustrates the algorithm that performs a general
translation from a deterministic finite automaton to a regular
expression.  The general construction described in class yields a very
long, redundant expression.  It is not clear how to generate
automatically an expression that is in a ``nicely reduced'' form.  In
order to avoid writing out the expressions in their full length in
this handout, we carry out some obvious simplifications, but we
emphasize that the general procedure does not do this simplification.

\begin{figure}[h]
\center\mbox{\psfig{figure=dfa-to-regexp-pic.ps,bbllx=60pt,bblly=480pt,bburx=480pt,bbury=720pt,height=2in}}
\caption{Sample DFA}
\end{figure}

This DFA accepts the language $(a + ba^*ca^*b)^*$.  (Note that
technically, this is not a DFA, since it has some missing arrows.  You
can imagine there is another trap state, state $4$, to which all the
nonexistent arrows go.  We will not carry out any calculations
involving the trap state, because they do not affect the final
results.  You should make sure you believe this.)

If $i, j \in \{ 1,2,3 \}$ and $k \in \{ 0,1,2,3 \}$, then
$E(i,j,k)$ will be a regular expression denoting the set of strings
that can move the automaton from state $i$ to state $j$, with
intermediate states having numbers at most equal to $k$.

We work ``bottom-up'', generating the expressions first for $k = 0$,
then $k = 1, 2,$ and $3$.
The final result we want is the expression we obtain for $E(1,1,3)$.

\begin{itemize}

\item $k = 0$
\begin{eqnarray}
E(1,1,0) & = & a + \Lambda \nonumber \\
E(1,2,0) & = & b \nonumber \\
E(1,3,0) & = & \emptyset \nonumber \\
E(2,1,0) & = & \emptyset \nonumber \\
E(2,2,0) & = & a + \Lambda \nonumber \\
E(2,3,0) & = & c \nonumber \\
E(3,1,0) & = & b \nonumber \\
E(3,2,0) & = & \emptyset \nonumber \\
E(3,3,0) & = & a + \Lambda \nonumber 
\end{eqnarray}

\item $k = 1$
\begin{eqnarray}
E(1,1,1) & = & E(1,1,0) + E(1,1,0) E(1,1,0)^* E(1,1,0) \nonumber \\
         & = & a + \Lambda + (a + \Lambda) (a + \Lambda)^* (a + \Lambda) \nonumber \\
         & = & a^* \nonumber 
\end{eqnarray}
\noindent (This last simplification is not done by the algorithm.)
\begin{eqnarray}
E(1,2,1) & = & E(1,2,0) + E(1,1,0) E(1,1,0)^* E(1,2,0) \nonumber \\
         & = & b + (a + \Lambda) (a + \Lambda)^* b \nonumber \\
         & = & a^*b \nonumber \\
E(1,3,1) & = & E(1,3,0) + E(1,1,0) E(1,1,0)^* E(1,3,0) \nonumber \\
         & = & \emptyset + E(1,1,0) E(1,1,0)^* \emptyset \nonumber \\
         & = & \emptyset \nonumber \\
E(2,1,1) & = & E(2,1,0) + E(2,1,0) E(1,1,0)^* E(1,1,0) \nonumber \\
         & = & \emptyset + \emptyset E(1,1,0)^* E(1,1,0) \nonumber \\
         & = & \emptyset \nonumber \\
E(2,2,1) & = & E(2,2,0) + E(2,1,0) E(1,1,0)^* E(1,2,0) \nonumber \\
         & = & a + \Lambda + \emptyset E(1,1,0)^* E(1,2,0) \nonumber \\
         & = & a + \Lambda \nonumber \\
E(2,3,1) & = & E(2,3,0) + E(2,1,0) E(1,1,0)^* E(1,3,0) \nonumber \\
         & = & c + \emptyset E(1,1,0)^* E(1,3,0) \nonumber \\
         & = & c \nonumber \\
E(3,1,1) & = & E(3,1,0) + E(3,1,0) E(1,1,0)^* E(1,1,0) \nonumber \\
         & = & b + b (a + \Lambda)^* (a + \Lambda) \nonumber \\
         & = & ba^* \nonumber \\
E(3,2,1) & = & E(3,2,0) + E(3,1,0) E(1,1,0)^* E(1,2,0) \nonumber \\
         & = & \emptyset + b (a + \Lambda)^* b \nonumber \\
         & = & ba^*b \nonumber \\
E(3,3,1) & = & E(3,3,0) + E(3,1,0) E(1,1,0)^* E(1,3,0) \nonumber \\
         & = & a + \Lambda + E(3,1,0) E(1,1,0)^* \emptyset \nonumber \\
         & = & a + \Lambda \nonumber 
\end{eqnarray}

\item Continuing in this way, we obtain, for $k = 2$,
\begin{eqnarray}
E(1,1,2) & = & E(1,1,1) + E(1,2,1) E(2,2,1)^* E(2,1,1) \nonumber \\
         & = & a^* + E(1,2,1) E(2,2,1)^* \emptyset \nonumber \\
         & = & a^* \nonumber \\
E(1,2,2) & = & E(1,2,1) + E(1,2,1) E(2,2,1)^* E(2,2,1) \nonumber \\
         & = & a^*b + a^*b (a + \Lambda)^* (a + \Lambda) \nonumber \\
         & = & a^*ba^* \nonumber \\
E(1,3,2) & = & E(1,3,1) + E(1,2,1) E(2,2,1)^* E(2,3,1) \nonumber \\
         & = & \emptyset + a^*b (a + \Lambda)^* c \nonumber \\
         & = & a^*ba^*c \nonumber \\
E(2,1,2) & = & E(2,1,1) + E(2,2,1) E(2,2,1)^* E(2,1,1) \nonumber \\
         & = & \emptyset + E(2,2,1) E(2,2,1)^* \emptyset \nonumber \\
         & = & \emptyset \nonumber \\
E(2,2,2) & = & E(2,2,1) + E(2,2,1) E(2,2,1)^* E(2,2,1) \nonumber \\
         & = & a + \Lambda + (a + \Lambda) (a + \Lambda)^* (a + \Lambda) \nonumber \\
         & = & a^* \nonumber \\
E(2,3,2) & = & E(2,3,1) + E(2,2,1) E(2,2,1)^* E(2,3,1) \nonumber \\
         & = & c + (a + \Lambda)(a + \Lambda)^* c \nonumber \\
         & = & a^*c \nonumber \\
E(3,1,2) & = & E(3,1,1) + E(3,2,1) E(2,2,1)^* E(2,1,1) \nonumber \\
         & = & ba^* + E(3,2,1) E(2,2,1)^* \emptyset \nonumber \\
         & = & ba^* \nonumber \\
E(3,2,2) & = & E(3,2,1) + E(3,2,1) E(2,2,1)^* E(2,2,1) \nonumber \\
         & = & ba^*b + ba^*b (a + \Lambda)^* (a + \Lambda) \nonumber \\
         & = & ba^*ba^* \nonumber \\
E(3,3,2) & = & E(3,3,1) + E(3,2,1) E(2,2,1)^* E(2,3,1) \nonumber \\
         & = & a + \Lambda + ba^*b (a + \Lambda)^* c \nonumber \\
         & = & a + \Lambda + ba^*ba^*c \nonumber 
\end{eqnarray}

\item Finally, $k = 3$.
\begin{eqnarray}
E(1,1,3) & = & E(1,1,2) + E(1,3,2) E(3,3,2)^* E(3,1,2) \nonumber \\
         & = & a^* + a^*ba^*c ( a + \Lambda + ba^*ba^*c)^* ba^* \nonumber
\end{eqnarray}
\noindent etc.
\end{itemize}

Believe it or not, this last expression is equivalent to the original
expression, $(a + ba^*ca^*b)^*$, although it is not so straightforward
to prove this.

\end{document}
