Function Repository Resource:

DynamicCASelector

Source Notebook

Dynamically select between cellular automata

Contributed by: Bradley Klee

ResourceFunction["DynamicCASelector"][codefun,init,steps,codemax]

creates an interface for viewing cellular automata and adding interesting codes to the system clipboard.

Details and Options

The first three arguments mimic those of CellularAutomaton, except that codefun must be a function.
Function codefun depends on one integer input between 0 and codemax.
List of initial values init and integer steps control image dimensions of the output.
Clicking the Next button will advance through the search space.
Clicking the Add button will add the current code to a cached list, then copy the cached list to the clipboard.
Clicking the Clear button will clear the selector cache and copy an empty list to the clipboard.
The following options can be given:
InitialCodeAutomaticinteger where to start searching
IteratorRandomfunction for stepping between data points
CodeMaskIdentityfunction gets composed into codefun
QualityTestNoneboolean function for filtering codes
ColorRulesAutomaticrules for coloring the ArrayPlot
Searching involves a variable subcode, such that the display code is calculated as code=(codefun@*mask)@subcode, and mask is supplied via CodeMask option.
If CodeMask option is set to reduce size of search space, then codemax should be reduced to the maximum subcode value.
If CodeMask option is set, option InitialCode expects a subcode value.
When iterating through subcode values, a candidate next value is always produced by iterator@subcode. The iterator may be supplied via the Iterator option.
When iterating through subcode values, a new value is only accepted only if (testQ@*mask)@subcode returns True. The testQ function may be supplied via the QualityTest option.

Examples

Basic Examples (3) 

In[1]:=
ResourceFunction["DynamicCASelector"][Identity, RandomInteger[1, 100], 100, 255]
Out[1]=

Search through the 16 totalistic elementary cellular automata:

In[2]:=
ResourceFunction["DynamicCASelector"][# &, RandomInteger[1, 300], 299,
  2^8 - 1,
 "Iterator" -> "Successor", "InitialCode" -> 126,
 ColorRules -> {1 -> Darker[Blue, .35], 0 -> Lighter[Green, .65]},
 "QualityTest" -> Function[{code}, With[
    {totals = Total /@ Tuples[Range[0, 2 - 1], 2*1 + 1]},
    And @@ (SameQ @@ IntegerDigits[code, 2, 2^(2*1 + 1)
           ][[Position[totals, #][[All, 1]]]] & /@ Union[totals])]]]
Out[2]=

Search through three-color cellular automata with simple quiescence:

In[3]:=
ResourceFunction["DynamicCASelector"][{#, 3} &, RandomInteger[2, 300], 299, 3^27 - 1,
 "InitialCode" -> 7093034993520,
 "QualityTest" -> Function[{code}, SameQ[
    IntegerDigits[code, 3, 27][[{1, 14, 27}]],
    {2, 1, 0}]],
 ColorRules -> {
   0 -> Lighter@Blend[{Red, Orange}, 0.6],
   1 -> Blend[{Green, Yellow}, 0.75],
   2 -> Lighter@Blend[{Blue, Cyan}, 0.6]}]
Out[3]=

Options (1) 

When a search function is passed via CodeMask, argument codemax must change accordingly:

In[4]:=
ResourceFunction["DynamicCASelector"][# &, RandomInteger[1, 300], 299,
  2^7 - 1,
 "Iterator" -> "Successor", "InitialCode" -> 126/2,
 ColorRules -> {1 -> Darker[Blue, .35], 0 -> Lighter[Green, .65]},
 "CodeMask" -> (2 # &),
 "QualityTest" -> Function[{code}, With[
    {totals = Total /@ Tuples[Range[0, 2 - 1], 2*1 + 1]},
    And @@ (SameQ @@ IntegerDigits[code, 2, 2^(2*1 + 1)
           ][[Position[totals, #][[All, 1]]]] & /@ Union[totals])]]]
Out[4]=

Possible Issues (3) 

Higher-dimensional cases are currently not supported:

In[5]:=
ResourceFunction[
 "DynamicCASelector"][{#, {2, {{2, 2, 2}, {2, 1, 2}, {2, 2, 2}}}, {1, 1}} &,
 {RandomInteger[1, {50, 50}], 0}, 100, 2^18 - 1,
 "Iterator" -> "Successor", "InitialCode" -> 224]
Out[5]=

RulePlot sometimes returns from kernel with missing data:

In[6]:=
ResourceFunction["DynamicCASelector"][{#, {4, 1},
   {{-1, 1}, {1, 1}, {-1, 0}, {1, 0}, {0, 0}, {0, -1}}} &,
 {RandomInteger[1, {50, 50}], 0}, 100, 2^18 - 1,
 "Iterator" -> "Successor", "InitialCode" -> 224]
Out[6]=

If QualityTest fails 105 times, an error is thrown:

In[7]:=
ResourceFunction["DynamicCASelector"][{#, 3} &, RandomInteger[1, 300], 299, 3^27 - 1,
 "QualityTest" -> (# == 7093034993520 &)]
Out[7]=

Neat Examples (2) 

Search for particles hiding in chaotic backgrounds using broken color symmetry:

In[8]:=
SpecialAlgebraicRules[subcode_] := With[{fun = Evaluate[Mod[Dot[
        Reverse[Times @@@ Subsets[Slot /@ Range[3]]],
        Function[{a, b, c, d},
          {0, a, 0, a /. {2 -> 1, 1 -> 2}, b, c, b /. {2 -> 1, 1 -> 2}, d}
          ] @@ IntegerDigits[subcode, 3, 4]], 3]] &},
  FromDigits[Apply[fun, #] & /@ Tuples[Reverse[Range[0, 2]], 3], 3]]
In[9]:=
ResourceFunction["DynamicCASelector"][{#, 3} &, RandomInteger[2, 300], 299, 3^4 - 1,
 "InitialCode" -> 34,
 "Iterator" -> "Successor",
 "CodeMask" -> (SpecialAlgebraicRules[#] &),
 ColorRules -> {0 -> LightBrown, 1 -> LightGreen, 2 -> Brown} ]
Out[9]=

Search for even weirder particles by combining elementary Rules 110 and 6:

In[10]:=
ProjectiveQ[code_] := SameQ[Length[Union[MapThread[(#1 /. {2 -> 1}) -> (#2 /. {2 -> 1}) &,
     {Tuples[{2, 1, 0}, 3], IntegerDigits[code, 3, 27]}]]], 8]
In[11]:=
PairMating[rule1_, rule2_, genome_] := With[{rep1 = Union[Join[
       MapThread[
        Rule, {Tuples[{1, 0}, 3], IntegerDigits[rule1, 2, 8]}],
       MapThread[Rule, 2 {Tuples[{1, 0}, 3], IntegerDigits[rule2, 2, 8]}]]]},
   FromDigits[Tuples[Reverse@Range[0, 2], {3}] /. MapThread[
      #1 -> (#1 /. Part[{1 -> 2, 2 -> 1}, #2 + 1] /. rep1) &,
      {Tuples[Reverse@Range[0, 2], {3}],
       IntegerDigits[genome, 2, 27]}] , 3]];
In[12]:=
ResourceFunction["DynamicCASelector"][{#, 3} &, RandomInteger[2, 300], 299, 2^27 - 1,
 "InitialCode" -> 38565869,
 "CodeMask" -> (PairMating[110, 6, #] &),
 "QualityTest" -> (Not[ProjectiveQ[#]] &),
 ColorRules -> MapIndexed[Rule[# - 1, Hue[(# + 1)/5, .75, 1]] &, Range[3]] ]
Out[12]=

Publisher

Brad Klee

Version History

  • 1.0.0 – 21 March 2022

Related Resources

License Information