The other direction seems to be more tedious, though, and sometimes the resulting expressions are messy. Now, we will show the equivalence of regular expression and DFA/NFA/ε-NFA by converting regular expression to its equivalent NFA. And we can see that the strings generated by the language defined a regular expression are exactly the strings accepted its equivalent NFA.

A generalized NFA is allowed to have transitions that are labelled by a regular expression (instead of just a single character). Thought of another way, while processing a string, you can follow a transition from q to qʹ labeled r by consuming characters of x that match r. This method is easy to write in a form of an algorithm, but generates absurdly large regular expressions and is impractical if you do it by hand, mostly because this is too systematic. It is a good and simple solution for an algorithm though. All the images above were generated using an online tool for automatically converting regular expressions to non-deterministic finite automata. You can find its source code for the Thompson-McNaughton-Yamada Construction algorithm online.

## Answers

We also established the equivalence of DFA and NFA/ε-NFA by showing an algorithmic approach to convert it into its equivalent DFA. We noted that it is easier to specify a NFA/ε-NFA compared to DFA. And it is even easier to specify a regular expression compared to NFA. The solution is a set of regular expressions $Q_i$, one for every state $q_i$. $Q_i$ describes exactly those words that can be accepted by $A$ when started in $q_i$; therefore $Q_0$ (if $q_0$ is the initial state) is the desired expression. Converting regular expressions into (minimal) NFA that accept the same language is easy with standard algorithms, e.g.

- You should not remove final or initial states lightly, otherwise you will miss parts of the language.
- By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
- I do not recommend implementing the algorithm, but using the method to do that by hand is a good idea.
- DFA, NFA, ε-NFA and regular expressions are equivalent in power in describing regular languages.
- Arden’s Method is not capable of converting Ɛ-NFA.
- If you understand this Concept try finding RE for Even 0’s and Odd 1’s, very tricky question I’ll be posting an article about it too.

At first, you can only use the direct transitions. I won’t describe how it works since it is well done in Raphael’s answer which I suggest to read before. Instead, I focus on in which order you should solve the equations without doing too many extra computations or extra cases. This algorithm is about handling the graph of the automaton and is thus not very suitable for algorithms since it needs graph primitives such as … Step 2 Remove Null transition from the NFA and convert it into its equivalent DFA.

## Not the answer you’re looking for? Browse other questions tagged theorycompiler-theorynfa or ask your own question.

Here I will describe the one usually taught in school which is very visual. However, writing the algorithm is not such a good idea. Convert simple regular expressions to nondeterministic finite automaton.

I do not recommend implementing the algorithm, but using the method to do that by hand is a good idea. By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Even if it may seems a system of equations that seems too symbolic for an algorithm, this one is well-suited for an implementation. Here is an implementation of this algorithm in Ocaml. Note that apart from the function brzozowski, everything is to print or to use for Raphael’s example. Note that there is a surprisingly efficient function of simplification of regular expressions simple_re. There are several methods to do the conversion from finite automata to regular expressions.

## Algorithm

Check out this repo, it translates your regular expression to an NFA and visually shows you the state transitions of an NFA. Now Rule 1, 2 is violated to satisfy them to make a new final state and new initial state with incoming Ɛ-transition and outgoing Ɛ-transition respectively. Given the complexity of the file – even with the expression sharing – you can begin to see why I never (yet) got around to writing a reverse convertor.

In NDFA, for a particular input symbol, the machine can move to any combination of the states in the machine. In other words, the exact state to which the machine moves cannot be determined. As it has finite number of states, the machine is called Non-deterministic Finite Machine or Non-deterministic Finite Automaton. Arden’s Method is not capable of converting Ɛ-NFA. By state elimination method you can conveniently and quickly find RE without writing anything just by imagination.

## Formal Languages and Automata

To convert an NFA to a regular expression, we first think of the NFA as a generalized NFA. We then transform it so that it has a single final state by adding epsilon transitions (we can do this, because ε is a regular expression). To convert a regular expression r to an NFA, we induct on the structure of r. For each kind of regular expressions, we build a machine that recognizes the same language as the expression. To make the construction easier, we produce machines that have only a single accept state. We have seen how to construct DFAs, NFAs, ε-NFAS and regular expressions for various problems so far.

You should not remove final or initial states lightly, otherwise you will miss parts of the language. Step 1 Construct an NFA with Null moves from the given regular expression. Can anyone clear up how to ‘describe what is responsibility accounting each step clearly’?

It just seems like a set of basic rules rather than an algorithm with steps to follow. If you want to try your hand at AI, this is a good case to work on it with. One application (of many) is control-flow-structure synthesis, because that’s what this really is, in disguise.

DFA, NFA, ε-NFA and regular expressions are equivalent in power in describing regular languages. An ε-NFA is like an NFA, except that we are allowed to include “epsilon transitions”. In a normal NFA or DFA, every character in the string causes a single transition in the machine, and each transition in the machine “consumes” one character. Epsilon transitions allow the machine to transition without consuming a character. The main pattern can be seen in the following to figures. The first has labels between $p,q,r$ that are regular expressions $e,f,g,h,i$ and we want to remove $q$.

## Non-deterministic Finite Automaton

One way to implement regular expressions is to convert them into a finite automaton, known as an ∈-NFA (epsilon-NFA). An ∈-NFA is a type of automaton that allows for the use of “epsilon” transitions, which do not consume any input. This means that the automaton can move from one state to another without consuming any characters from the input string. To convert an NFA to a regular expression, we introduced the concept of a “generalized NFA”.

This is the same method as the one described in Raphael’s answer, but from a point of view of a systematic algorithm, and then, indeed, the algorithm. It turns out to be easy and natural to implement once you know where to begin. Also it may be easier by hand if drawing all the automata is impractical for some reason.