# Cellular Automata

Cellular automata provide a convenient way to represent many kinds of systems in which the values of cells in an array are updated in discrete steps according to a local rule.

CellularAutomaton[rnum,init,t] | evolve rule rnum from init for t steps |

Generating a cellular automaton evolution.

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

{a_{1},a_{2},…} | explicit list of values |

{{a_{1},a_{2},…},b} | values superimposed on a b background |

{{a_{1},a_{2},…},blist} | values superimposed on a background of repetitions of blist |

{{{{a_{11},a_{12},…},{d_{1}}},…},blist} | values at offsets |

Ways of specifying initial conditions for one‐dimensional cellular automata.

If you give an explicit list of initial values, CellularAutomaton will take the elements in this list to correspond to all the cells in the system, arranged cyclically.

In[3]:= |

Out[3]= |

It is often convenient to set up initial conditions in which there is a small "seed" region, superimposed on a constant "background". By default, CellularAutomaton automatically fills in enough background to cover the size of the pattern that can be produced in the number of steps of evolution you specify.

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]= |

Particularly in studying interactions between structures, you may sometimes want to specify initial conditions for cellular automata in which certain blocks are placed at particular offsets.

In[6]:= |

Out[6]= |

n | , , elementary rule |

{n,k} | general nearest‐neighbor rule with k colors |

{n,k,r} | general rule with k colors and range r |

{n,{k,1}} | k‐color nearest‐neighbor totalistic rule |

{n,{k,1},r} | k‐color range-r totalistic rule |

{n,{k,{wt_{1},wt_{2},…}},r} | rule in which neighbor i is assigned weight |

{n,kspec,{{off_{1}},{off_{2}},…,{off_{s}}}} | rule with neighbors at specified offsets |

{lhs_{1}->rhs_{1},lhs_{2}->rhs_{2},…} | explicit replacements for lists of neighbors |

{fun,{},rspec} | rule obtained by applying function fun to each neighbor list |

Specifying rules for one‐dimensional cellular automata.

In the simplest cases, a cellular automaton allows k possible values or "colors" for each cell, and has rules that involve up to r neighbors on each side. The digits of the "rule number" n then specify what the color of a new cell should be for each possible configuration of the neighborhood.

In[7]:= |

Out[7]= |

In[8]:= |

Out[8]= |

In[9]:= |

Out[9]= |

In[10]:= |

Out[10]= |

In[11]:= |

Out[11]= |

For a general cellular automaton rule, each digit of the rule number specifies what color a different possible neighborhood of cells should yield. To find out which digit corresponds to which neighborhood, one effectively treats the cells in a neighborhood as digits in a number. For an cellular automaton, the number is obtained from the list of elements neig in the neighborhood by .

It is sometimes convenient to consider *totalistic* cellular automata, in which the new value of a cell depends only on the total of the values in its neighborhood. One can specify totalistic cellular automata by rule numbers or "codes" in which each digit refers to neighborhoods with a given total value, obtained for example from .

In general, CellularAutomaton allows one to specify rules using any sequence of weights. Another choice sometimes convenient is , which yields outer totalistic rules.

In[12]:= |

Out[12]= |

Rules with range involve all cells with offsets through . Sometimes it is convenient to think about rules that involve only cells with specific offsets. You can do this by replacing a single with a list of offsets.

Any cellular automaton rule can be thought of as corresponding to a Boolean function. In the simplest case, basic Boolean functions like And or Nor take two arguments. These are conveniently specified in a cellular automaton rule as being at offsets . Note that for compatibility with handling higher‐dimensional cellular automata, offsets must always be given in lists, even for one‐dimensional cellular automata.

In[13]:= |

Out[13]= |

Rule numbers provide a highly compact way to specify cellular automaton rules. But sometimes it is more convenient to specify rules by giving an explicit function that should be applied to each possible neighborhood.

In[14]:= |

Out[14]= |

In[15]:= |

Out[15]= |

In[16]:= |

Out[16]= |

In[17]:= |

Out[17]= |

CellularAutomaton[rnum,init,t] | evolve for t steps, keeping all steps |

CellularAutomaton[rnum,init,{{t}}] | evolve for t steps, keeping only the last step |

CellularAutomaton[rnum,init,{spec_{t}}] | keep only steps specified by |

CellularAutomaton[rnum,init] | evolve rule for one step, giving only the last step |

Selecting which steps to keep.

In[18]:= |

Out[18]= |

In[19]:= |

Out[19]= |

In[20]:= |

Out[20]= |

The step specification works very much like taking elements from a list with Take. One difference, though, is that the initial condition for the cellular automaton is considered to be step . Note that any step specification of the form {…} must be enclosed in an additional list.

Cellular automaton step specifications.

In[21]:= |

Out[21]= |

CellularAutomaton[rnum,init,t] | keep all steps, and all relevant cells |

CellularAutomaton[rnum,init,{spec_{t},spec_{x}}] | |

keep only specified steps and cells |

Selecting steps and cells to keep.

Much as you can specify which steps to keep in a cellular automaton evolution, so also you can specify which cells to keep. If you give an initial condition such as , then r_{d} is taken to have offset 0 for the purpose of specifying which cells to keep.

All | all cells that can be affected by the specified initial condition |

Automatic | all cells in the region that differs from the background (default) |

0 | cell aligned with beginning of aspec |

x | cells at offsets up to x on the right |

-x | cells at offsets up to x on the left |

{x} | cell at offset x to the right |

{-x} | cell at offset x to the left |

{x_{1},x_{2}} | cells at offsets through |

{x_{1},x_{2},dx} | cells , , … |

Cellular automaton cell specifications.

In[22]:= |

Out[22]= |

In[23]:= |

Out[23]= |

If you give an initial condition such as , then CellularAutomaton will always effectively do the cellular automaton as if there were an infinite number of cells. By using a such as you can tell CellularAutomaton to include only cells at specific offsets through in its output. CellularAutomaton by default includes cells out just far enough that their values never simply stay the same as in the background blist.

In general, given a cellular automaton rule with range , cells out to distance on each side could in principle be affected in the evolution of the system. With being All, all these cells are included; with the default setting of Automatic, cells whose values effectively stay the same as in blist are trimmed off.

In[24]:= |

Out[24]= |

In[25]:= |

Out[25]= |

CellularAutomaton generalizes quite directly to any number of dimensions. Above two dimensions, however, totalistic and other special types of rules tend to be more useful, since the number of entries in the rule table for a general rule rapidly becomes astronomical.

{n,k,{r_{1},r_{2},…,r_{d}}} | ‐dimensional rule with neighborhood |

{n,{k,1},{1,1}} | two‐dimensional 9‐neighbor totalistic rule |

{n,{k,{{0,1,0},{1,1,1},{0,1,0}}},{1,1}} | |

two‐dimensional 5‐neighbor totalistic rule | |

{n,{k,{{0,k,0},{k,1,k},{0,k,0}}},{1,1}} | |

two‐dimensional 5‐neighbor outer totalistic rule |

Higher‐dimensional rule specifications.

In[26]:= |

In[27]:= |

Out[27]= |

In[28]:= |

Out[28]= |

In[29]:= |

Out[29]= |