answer to 3-color totalistic cellular automata in golly 02-26-2014d2010

2014-08-29

answer to 3-color totalistic cellular automata in golly 02-26-2014d2010

http://www.conwaylife.com/forums/viewtopic.php?f=3&t=1314&p=10994#p10994

1st post

As far as I know, no one has written a generalized rule-generator script for Wolfram's enumeration of 3-state totalistic CAs. Golly only natively supports even-numbered "elementary" 1-dimensional CA (with Wolfram numbers up to 255).

The standard way to trick Golly into supporting a new set of rules is to write a Python script that takes the rule specification as input. In this case the script would accept an integer and interpret it as Wolfram numbering for a 3-state totalistic CA.

You end up with a new .rule file for every number you run through the script, but otherwise this is a reasonably workable system. See Golly's Scripts/Python/RuleGenerators for examples.

There are only a few thousand (3^7) 1D 3-state totalistic rules, and the rule files are fairly trivial to generate. Here's a sample:

Rule table for 3-state totalistic CA, Wolfram rule #2007 --
copy to clipboard and choose File > Open Clipboard in Golly 2.4+

code
{
@RULE W2007T_k=3

Wolfram 3-state totalistic rule code 2007
A sample 3-state 1D CA using Wolfram's numbering system

@TABLE

n_states:3
neighborhood:Moore
symmetries:reflect_horizontal

var n={0,1,2


# Change just the numbers on the far right to adjust the Wolfram code.
# For a Wolfram totalistic 3-color CA, all the output state numbers under each
# sum must be the same. E.g., for code 2007, the numbers are 0, 0, 1, 2, 0, 2, 2.
#
# 2007 = 0*3^0 + 0*3^1 + 1*3^2 + 2*3^3 + 0*3^4 + 2*3^5 + 2*3^6.
# See http://www.wolframalpha.com/input/?i=3-color+code+2007
#
# To extend this to more colors, it would be necessary to list all possible partitions of
# each sum into integers 0..k, as has been done here for k=3. A few combinations
# were left out because they were horizontal reflections of listed combinations.

# sum=0
0,0,0,n,n,n,n,n,0,0

# sum=1
0,0,1,n,n,n,n,n,0,0
0,1,0,n,n,n,n,n,0,0

# sum=2
0,0,1,n,n,n,n,n,1,1
0,0,2,n,n,n,n,n,0,1
0,1,1,n,n,n,n,n,0,1
0,2,0,n,n,n,n,n,0,1

# sum=3
0,0,1,n,n,n,n,n,2,2
0,0,2,n,n,n,n,n,1,2
0,1,1,n,n,n,n,n,1,2
0,1,2,n,n,n,n,n,0,2
0,2,1,n,n,n,n,n,0,2

# sum=4
0,0,2,n,n,n,n,n,2,0
0,1,1,n,n,n,n,n,2,0
0,2,0,n,n,n,n,n,2,0
0,2,1,n,n,n,n,n,1,0

# sum=5
0,1,2,n,n,n,n,n,2,2
0,2,1,n,n,n,n,n,2,2

# sum=6
0,2,2,n,n,n,n,n,2,2

@COLORS
0 0 0 0
1 0 128 255 light blue
2 255 128 0 orange
}

As with Golly's support for Wolfram codes for elementary CA, the transition table assumes a starting state all on a single line; child states appear on successive lines. Really everything is happening on a two-dimensional grid -- but as you might expect, you'll get strange results if you start with a multi-line pattern, or if you go "back in time" and edit anything above the bottom line. No warranty express or implied, etc., etc.

A simple Python script could easily decode an input Wolfram number for any 3-state totalistic CA, and write out a very similar rule table. The only difference would be that the rightmost numbers under each "# sum=n" section would change to the appropriate base-3 digit.

A slightly bigger challenge would be a generalized script that could also handle four colors or more. It would probably just list all the possible partitions of each sum, without worrying about reflections... As you can see, rule-table format is not really designed to handle this type of totalistic rule -- but for a reasonable number of colors, a script could generate the correct rule table fairly easily.

...I'm hoping that Golly doesn't have some much simpler way of doing this, that I'm forgetting all about!
}

2nd post

The main thing that I was worried about was the "oneDimensional" neighborhood that Golly supports; I couldn't get it to work at first. Turned out the problem was between my keyboard and my chair -- I was listing the center state twice in each rule line.

The key difference is that the "oneDimensional" neighborhood really is one-dimensional -- all the action happens in a single line, instead of moving progressively down the screen. The Y dimension isn't used to show the progression of time; cells in different rows have no effect on each other, so you can run a different experiment in each horizontal row of cells.

On the other hand, you just see a single line for each experiment instead of a nice New Kind of Science-y picture of the evolution of the rule.

code
{
@RULE W2007T_1dim_k=3

Wolfram 3-state totalistic rule 2007,
using Golly's "oneDimensional" neighborhood.
All evolution occurs in a single line, instead of
future generations appearing below older generations
as in the previously posted W2007T_k=3 rule.

@TABLE

# sample totalistic 3-color Wolfram rule
n_states:3
neighborhood:oneDimensional
symmetries:reflect

# sum=0
0,0,0,0

# sum=1
0,0,1,0
1,0,0,0

# sum=2
0,1,1,1
1,0,1,1
0,0,2,1
2,0,0,1

# sum=3
0,1,2,2
1,0,2,2
2,0,1,2
1,1,1,2

# sum=4
0,2,2,0
2,0,2,0
1,1,2,0
2,1,1,0

# sum=5
1,2,2,2
2,1,2,2

# sum=6
2,2,2,2

@COLORS
0 0 0 0
1 0 128 255 light blue
2 255 128 0 orange


You can get a surprising-but-not-really effect by running the W2007T_k=3 rule on a starting pattern for a while, then switching to W2007T_1dim_k=3.

}