In the theory of computing, automata theory is central to understand and analyze the behaviour of discrete systems. Not only an automata can be used to process and analytically study languages, but they can be used as a way of programming, or modelling machines.
The subset construction method, is a universal method for converting a non-deterministic finite automata to a deterministic one. The method not only does the conversion, but it is the foundation of proving the equivalence of these two kinds of automata, that is, that there is an equivalent DFA to every NFA. I talk about non-deterministic automata on this post, and deterministic ones on this one.
On this post I focus on constructing functions in Mathematica to apply this method. I assume that you have already some knowledge in Automata Theory.
Subset Construction Method
Here I will give a not so rigorous description of the method, for complete details have a look at Hopcroft & Ullman’s book. You can also check Ullman himself explaining on this video.
Lets work with a simple (and classic) example. This is the same example that I used on this post.
Consider the following NFA, that accepts strings that end in 01 (initial state in white and final state in red),
Notice how, when in state 0 and receiving symbol “1”, the transition stays in state 0 but also goes to state 1. This is the transition table,
Out[]=
Q\Σ
0
1
0
{0,1}
{0}
1
-
{2}
2
-
-
Notice how, when in state 0 and receiving symbol “1”, the transition stays in state 0 but also goes to state 1. We define this NFA using the following association,
We can now use it to evaluate the string “00101” for example,
In[]:=
DeltaHatNFA[δ,{0},"00101"]
Out[]=
{{0},{0,1},{0,1},{0,2},{0,1},{0,2}}
It should be clear from the output that the NFA, starts in state 0, receives symbol “0”, and it then moves to state 0 and state 1 at the same time. Then every state has to be evaluated when the next symbol comes.
First we create the powerset using the Subsets function. For the example (3 states) we have,
In[]:=
S=Subsets[{0,1,2}]
Out[]=
{{},{0},{1},{2},{0,1},{0,2},{1,2},{0,1,2}}
Notice how the powerset has 8 combinations (
n
2
, where
n
is the number of states).
Now we have to calculate the transition for each element in
S
combined with each symbol (the union of each results). IN other words we have to create all the Keys we are going to evaluate in
δ
. We can use the Outer function to do this, the following way,
Not the most efficient since we are doing some things twice in the code (calculating keys), but I want to keep things in the functional domain, and for educational purposes. Let see if it works,
The code can certainly be improved. For example you could do a “lazy” construction of the powerset, that is, working only the states that area reached, instead of creating all states and then erasing.
In the future I hope to build more examples using this procedure, and focused more on the language of the automata, rather than on the automata itself.
The goal here is not to create the perfect or smallest code, but rather to build a code that is closer to the mathematical definition of the method, and to use it as an educational tool for teaching Mathematica and Automata Theory. Please feel free to improve! Will post in the future functions for creating nice graphs and transition tables for different types of automata like the ones used here.
References
◼
Hopcroft and Ullman, Introduction to Automata Theory, Languages and Computation, Addison Wesley.