Wolfram Research

Function Repository Resource:

NFAPlot

Source Notebook

Plot a nondeterministic finite automaton

Contributed by: Katja Della Libera

ResourceFunction["NFAPlot"][rules,start,accept]

plots the NFA described by rules, with the starting state start and the accept state(s) accept.

Details and Options

rules and accept should be given in list format
Similarly to TuringMachine, rules can be specified in the format {currentstate,input} {newstate}
ResourceFunction["NFAPlot"] accepts the following options:
"StateLabeled" True whether the plot states should be labeled
“StateLabelSize” Large what size the states labels should be
“TransitionLabeled” True whether to label the transitions
“TransitionLabelSize” Large what size the transition labels should be

Examples

Basic Examples

Plot a simple NFA with six rules and one accept state:

In[1]:=
ResourceFunction[
 "NFAPlot"][{{0, 1} -> {1}, {1, 1} -> {2}, {2, 1} -> {0}, {1, 0} -> {0}, {2, 0} -> {1}, {0, 0} -> {2}}, 0, {1}]
Out[1]=

Options

StateLabeled

Remove all state labels:

In[2]:=
ResourceFunction[
 "NFAPlot"][{{0, 1} -> {1}, {1, 1} -> {2}, {2, 1} -> {0}, {1, 0} -> {0}, {2, 0} -> {1}, {0, 0} -> {2}}, 0, {1}, "StateLabeled" -> False]
Out[2]=

StateLabelSize

Reduce the size of the labels:

In[3]:=
ResourceFunction[
 "NFAPlot"][{{0, 1} -> {1}, {1, 1} -> {2}, {2, 1} -> {0}, {1, 0} -> {0}, {2, 0} -> {1}, {0, 0} -> {2}}, 0, {1}, "StateLabelSize" -> Medium]
Out[3]=

TransitionLabeled

Specify whether the transitions should be labeled:

In[4]:=
ResourceFunction[
 "NFAPlot"][{{0, 1} -> {1}, {1, 1} -> {2}, {2, 1} -> {0}, {1, 0} -> {0}, {2, 0} -> {1}, {0, 0} -> {2}}, 0, {1}, "TransitionLabeled" -> False]
Out[4]=

TransitionLabelSize

Decrease the transition label size:

In[5]:=
ResourceFunction[
 "NFAPlot"][{{0, 1} -> {1}, {1, 1} -> {2}, {2, 1} -> {0}, {1, 0} -> {0}, {2, 0} -> {1}, {0, 0} -> {2}}, 0, {1}, "TransitionLabelSize" -> Small]
Out[5]=

Possible Issues

For larger plots, the labels are often to big, this can simply be adjusted using "StateLabelSize":

In[6]:=
ResourceFunction[
 "NFAPlot"][{{0, "1"} -> {1}, {0, "0"} -> {4}, {1, "1"} -> {1}, {1, "0"} -> {2}, {2, "0"} -> {2}, {2, "1"} -> {3}, {3, "0,1"} -> {4}, {4, "0,1"} -> {4}}, 0, {4}]
Out[6]=
In[7]:=
ResourceFunction[
 "NFAPlot"][{{0, "1"} -> {1}, {0, "0"} -> {4}, {1, "1"} -> {1}, {1, "0"} -> {2}, {2, "0"} -> {2}, {2, "1"} -> {3}, {3, "0,1"} -> {4}, {4, "0,1"} -> {4}}, 0, {4}, "StateLabelSize" -> Medium]
Out[7]=

Resource History

License Information