Function Repository Resource:

SubstitutionSystemPlot

Source Notebook

Visualize the evolution of a one-dimensional neighbor-independent substitution system

Contributed by: Stephen Wolfram and Jan Mangaldan

ResourceFunction["SubstitutionSystemPlot"][rule,init,t]

visualizes the evolution of the list substitution system with the specified rule from initial condition init for t steps.

ResourceFunction["SubstitutionSystemPlot"][rule,init,{t1,t2}]

visualizes the evolution from steps t1 through t2.

Details and Options

In ResourceFunction["SubstitutionSystemPlot"][rule,], rule must be of the form {i1rhs1,i2rhs2,}, where the rhsi can be lists or strings of any length.
ResourceFunction["SubstitutionSystemPlot"] has the same options as Graphics, with the following additions:
AlignmentCenteralignment of the boxes used to visualize the steps
AppearanceAutomaticoverall appearance
ColorRulesAutomaticrules for determining colors from values
MeshAutomaticwhether to draw a mesh
MeshStyleAutomaticthe style to use for a mesh
OffsetAutomaticoffsets for the boxes used to visualize the steps
Possible settings for the Appearance option include "Array", "Boxes" and "Tree".

Examples

Basic Examples (6) 

Show five steps of a string substitution system:

In[1]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"A"}}, {"A"},
  5]
Out[1]=

Show as an array:

In[2]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"A"}}, {"A"}, 5, Appearance -> "Array"]
Out[2]=

Show only the second to fourth steps:

In[3]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"A"}}, {"A"}, {2, 4}]
Out[3]=

Show the second to fourth steps as an array:

In[4]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"A"}}, {"A"}, {2, 4}, Appearance -> "Array"]
Out[4]=

Show only the first step:

In[5]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"A"}}, {"A"}]
Out[5]=

Show the first step as an array:

In[6]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"A"}}, {"A"}, Appearance -> "Array"]
Out[6]=

Scope (5) 

Use any symbol:

In[7]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"\[FilledSquare]" -> {"\[FilledCircle]", "\[FilledSquare]"}, "\[FilledCircle]" -> {"\[FilledSquare]", "\[FilledCircle]"}}, {"\[FilledSquare]"}, 5]
Out[7]=
In[8]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"\[FilledSquare]" -> {"\[FilledCircle]", "\[FilledSquare]"}, "\[FilledCircle]" -> {"\[FilledSquare]", "\[FilledCircle]"}}, {"\[FilledSquare]"}, 5, Appearance -> "Array"]
Out[8]=

Lists do not have to be the same length:

In[9]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"B", "A"}, "B" -> {"A"}}, {"B"},
  5]
Out[9]=
In[10]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"B", "A"}, "B" -> {"A"}}, {"B"}, 5, Appearance -> "Array"]
Out[10]=

The initial condition can be of any length:

In[11]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"B"}, "B" -> {"B", "A"}}, {"B", "A", "B"}, 4]
Out[11]=
In[12]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"B"}, "B" -> {"B", "A"}}, {"B", "A", "B"}, 4, Appearance -> "Array"]
Out[12]=

Rules can involve patterns:

In[13]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{0 | 1 -> {1, 2}, 2 -> {0, 1}}, {0}, 3]
Out[13]=
In[14]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{0 | 1 -> {1, 2}, 2 -> {0, 1}}, {0}, 3, Appearance -> "Array"]
Out[14]=
In[15]:=
ResourceFunction["SubstitutionSystemPlot"][{n_ :> Range[n]}, {3}, 3]
Out[15]=
In[16]:=
ResourceFunction["SubstitutionSystemPlot"][{n_ :> Range[n]}, {3}, 3, Appearance -> "Array"]
Out[16]=

Use a string substitution system:

In[17]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"\[EmptyCircle]" -> "\[EmptyCircle]\[FilledSquare]", "\[FilledSquare]" -> "\[FilledSquare]\[EmptyCircle]"}, "\[FilledSquare]", 3]
Out[17]=
In[18]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"\[EmptyCircle]" -> "\[EmptyCircle]\[FilledSquare]", "\[FilledSquare]" -> "\[FilledSquare]\[EmptyCircle]"}, "\[FilledSquare]", 3, Appearance -> "Array"]
Out[18]=

Options (9) 

Alignment (1) 

Different alignment formats for SubstitutionSystemPlot:

In[19]:=
ResourceFunction[
   "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"A"}}, {"A"},
    5, Alignment -> #, PlotLabel -> #] & /@ {Left, Center, Right}
Out[19]=

Appearance (3) 

Show as boxes:

In[20]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"A"}}, {"A"}, 5, Appearance -> "Boxes"]
Out[20]=

Show as an array:

In[21]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"A"}}, {"A"}, 5, Appearance -> "Array"]
Out[21]=

Show as a tree:

In[22]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"A"}}, {"A"}, 5, Appearance -> "Tree", ColorRules -> {"A" -> Hue[0.62, 0.45, 0.87], "B" -> Hue[0.62, 1, 0.48]}]
Out[22]=

ColorRules (2) 

Specify color rules for explicit values or patterns:

In[23]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{0 | 1 -> {1, 2}, 2 -> {0, 1}}, {0}, 3, ColorRules -> {0 -> RGBColor[1., 0.843137, 0.6], 1 -> RGBColor[0.8505, 0.4275, 0.13185], 2 -> RGBColor[0.711529, 0.181058, 0.]}]
Out[23]=
In[24]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> "B", "B" -> "BA"}, "BAB", {2, 4}, Appearance -> "Array", ColorRules -> {"A" -> RGBColor[1., 0.843137, 0.6], "B" -> RGBColor[0.711529, 0.181058, 0.]}]
Out[24]=
In[25]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"B" -> "BAB", "A" -> "AAA"}, {"B"}, 4, Appearance -> "Tree", ColorRules -> {"A" -> RGBColor[1., 0.843137, 0.6], "B" -> RGBColor[0.711529, 0.181058, 0.]}]
Out[25]=

Implement a “default color” by adding a rule for _:

In[26]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{0 | 1 -> {1, 2}, 2 -> {0, 1}}, {0}, 3, ColorRules -> {0 -> Blue, _ -> Orange}]
Out[26]=
In[27]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> "B", "B" -> "BA"}, "BAB", {2, 4}, Appearance -> "Array", ColorRules -> {"A" -> RGBColor[1., 0.843137, 0.6], _ -> RGBColor[
    0.711529, 0.181058, 0.]}]
Out[27]=
In[28]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"B" -> "BAB", "A" -> "AAA"}, {"B"}, 4, Appearance -> "Tree", ColorRules -> {"A" -> RGBColor[1., 0.843137, 0.6], _ -> RGBColor[
    0.711529, 0.181058, 0.]}]
Out[28]=

Mesh (1) 

Show with and without the mesh:

In[29]:=
GraphicsRow[
 ResourceFunction[
    "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"A"}}, {"A"}, 5, Mesh -> #] & /@ {True, False}]
Out[29]=

MeshStyle (1) 

Make the mesh pink:

In[30]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"A"}}, {"A"}, 5, MeshStyle -> Pink]
Out[30]=
In[31]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"A"}}, {"A"}, 5, Appearance -> "Array", MeshStyle -> Pink]
Out[31]=

Offset (1) 

Different offsets for SubstitutionSystemPlot:

In[32]:=
GraphicsRow[
 ResourceFunction[
    "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"A"}}, {"A"}, 5, Offset -> #] & /@ {1/10, 1/8, 1/2}]
Out[32]=
In[33]:=
GraphicsRow[
 ResourceFunction[
    "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"A"}}, {"A"}, 5, Offset -> {1/5, #}] & /@ {6/5, 9/5, 2}]
Out[33]=

Applications (2) 

Illustrate the Thue-Morse substitution system:

In[34]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"B", "A"}}, {"A"}, 5]
Out[34]=
In[35]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"B", "A"}}, {"A"}, 5, Appearance -> "Array", ColorRules -> {"A" -> Hue[0.62, 1, 0.48], "B" -> Hue[0.62, 0.45, 0.87]}, MeshStyle -> GrayLevel[0.3]]
Out[35]=
In[36]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{"A" -> {"A", "B"}, "B" -> {"B", "A"}}, {"A"}, 5, Appearance -> "Tree", ColorRules -> {"A" -> Hue[0.62, 1, 0.48], "B" -> Hue[0.62, 0.45, 0.87]}]
Out[36]=

Illustrate the substitution system for the Cantor set:

In[37]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{1 -> {1, 0, 1}, 0 -> {0, 0, 0}}, {1}, 3]
Out[37]=
In[38]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{1 -> {1, 0, 1}, 0 -> {0, 0, 0}}, {1}, 5, Appearance -> "Array", ColorRules -> {1 -> Hue[0.62, 1, 0.48], 0 -> Hue[0.62, 0.45, 0.87]}, MeshStyle -> GrayLevel[0.3]]
Out[38]=
In[39]:=
ResourceFunction[
 "SubstitutionSystemPlot"][{1 -> {1, 0, 1}, 0 -> {0, 0, 0}}, {1}, 5, Appearance -> "Tree", ColorRules -> {1 -> Hue[0.62, 1, 0.48], 0 -> Hue[0.62, 0.45, 0.87]}]
Out[39]=

Version History

  • 3.1.0 – 17 May 2021
  • 3.0.0 – 16 March 2020
  • 2.0.0 – 09 March 2020
  • 1.0.0 – 14 February 2020

Related Resources

License Information