There are several algorithms for performing this task: the “method of eliminating states” from Brzozowski and Mac Klaski, resolving the linear equation system, the Macnaughton and Yamada method, etc. They are very well described in Automatons and rational expressions of Jacques Sakarovich.
The method of eliminating states in particular is easy to understand. The basic idea is that you are going to create an automaton marked with rational (aka regular) expressions, not letters. First, make sure that you have one initial state and one final state (if necessary, you can add new states and spontaneous transitions). Then select state s to eliminate, say, state 1 in the following figure.

Then we consider all pairs (p, q), where p is the predecessor (states from which the transition reaches s, 0 in the figure) and q is the successor (state 2). For each such pair (p, q), add the transition from p to q, which is labeled E (p, q) + E (p, s) E (s, s) * E (s, q), where E (p, s) means "expression that indicates the transition from p to S. After you have processed all the pairs (p, q), delete the state s. In the previous example:

Do this until you eliminate all the internal states (i.e., save the initial state and final state), and simply read the result when switching from the initial state to the final state (here d + ab * c).
You can play with this algorithm using Vcsn , a tool for rational expressions and automata. Here is a complete example that you can reproduce on Vcsn Sandbox .

source share