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"Truewhether the plot states should be labeled
"StateLabelSize"Largewhat size the states labels should be
"TransitionLabeled"Truewhether to label the transitions
"TransitionLabelSize"Largewhat size the transition labels should be

Examples

Basic Examples (1) 

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 (4) 

StateLabeled (1) 

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 (1) 

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 (1) 

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 (1) 

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 (1) 

For larger plots, the labels are often too 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]=

Version History

  • 2.0.0 – 19 June 2019
  • 1.0.0 – 19 June 2019

Related Resources

License Information