Posts tagged code carry a specimen drawn from a cellular automaton: a grid of two-state cells and a local rule applied everywhere at once. For some rules, this minimal model of computation is enough to compute anything a computer can.
Elementary automata
An elementary automaton lives on a row of cells worth 0 or 1. At each step, the new value of a cell depends only on itself and its two neighbours:
Three bits give possible neighbourhoods, and a rule picks an output for each: there are therefore elementary rules. The evolution is drawn by stacking successive generations, with time running down from one row to the next.
Wolfram’s numbering
In 1983 Stephen Wolfram proposed naming each rule by an integer from 0 to 255. Write the eight neighbourhoods in decreasing order, from 111 to 000, and the output of each forms an eight-digit binary number. The bit of weight is the output of the neighbourhood that reads in binary:
| Neighbourhood | 111 | 110 | 101 | 100 | 011 | 010 | 001 | 000 |
|---|---|---|---|---|---|---|---|---|
| Weight | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Rule 30 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 |
| Rule 110 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 |
For rule 30, ; for rule 110, . The number is the table itself, compressed. Rule 30 also has a compact algebraic form, , where is exclusive or.
In code, applying a rule comes down to reading one bit of its number:
// l, row[x], r: the cell and its two neighbours; the neighbourhood is an integer from 0 to 7
next[x] = (rule >> ((l << 2) | (row[x] << 1) | r)) & 1;
The 256 rules are not all distinct: swapping left and right, or swapping 0 and 1, gives an equivalent rule. That leaves 88 equivalence classes.
# #
### ##
## # ###
## #### ## #
## # # #####
## #### ### ## #
## # # # ### ##
## #### ###### ## # ###
## # ### # ####### #
## #### ## # ### ## ###
## # # #### ## # ### ## #
## #### ## # # #### ## # #####
## # ### ## ## # # ##### ## #
## #### ## ### ### ## ### ## # ### ##
## # # ### # ### # # ### #### # ###
## #### ## # # ##### ###### # ## # ## ##### #Wolfram’s four classes
In 1984 Wolfram sorted the behaviour of automata started from random initial conditions into four qualitative families:
- Class 1: the evolution ends in a homogeneous state. Almost all the initial information is lost (rule 0, rule 32).
- Class 2: simple structures, stable or periodic, separated from one another (rule 4, rule 108).
- Class 3: chaotic, aperiodic behaviour that never settles; a small perturbation spreads without limit (rules 30, 22 or 150).
- Class 4: localised, long-lived structures that move and interact on a regular background (rule 110).
The classification is empirical: it describes what you see, and some rules only fall into place after long observation. Classes 1 and 2 forget, class 3 scrambles, class 4 carries information over long distances without destroying it. Wolfram conjectured that this is where to look for universal computation.
Rule 30 is so chaotic that the centre column of its evolution has been used as a pseudorandom generator, notably in Mathematica.
Rule 110 is universal
In 2004 Matthew Cook proved that rule 110 is Turing-complete. The proof shows that its moving structures, its “spaceships”, can simulate a cyclic tag system, a known universal model of computation: the periodic background serves as a medium, and collisions between spaceships read and write the symbols.
Two caveats. First, universality requires an initial condition that is infinite but regular: a periodic pattern on the left, the data in the middle, another periodic pattern on the right. Second, it says nothing about efficiency: Cook’s simulation goes through several successive encodings and takes exponential time; Neary and Woods brought that overhead down to a polynomial in 20061. With these caveats, an eight-bit rule is enough to express any computation.
In two dimensions: Life-like rules
John Conway’s Game of Life, popularised by Martin Gardner in Scientific American in 1970, lives on a square grid. Each cell counts its eight live neighbours (the Moore neighbourhood), and the rule depends only on that count and on the cell’s own state. It is written in B/S notation: after B, the neighbour counts that bring a dead cell to life; after S, those that keep a live cell alive. Life is B3/S23.
Any pair of subsets of defines a rule of this kind, which makes rules. A few of them have names:
| Rule | Notation | Behaviour |
|---|---|---|
| Life | B3/S23 | gliders, oscillators, guns; Turing-complete |
| HighLife | B36/S23 | close to Life, with a small self-replicating pattern (Nathan Thompson, 1994) |
| Day & Night | B3678/S34678 | symmetric under inversion: live and dead cells play the same role |
| Maze | B3/S12345 | very permissive survival freezes growth into maze corridors |
| Anneal | B4678/S35678 | a “twisted” majority rule, also symmetric under inversion |
A dead cell surrounded by live ones has dead neighbours, so inverting the whole grid swaps the roles of B and S. A rule is its own inverse when : this is the case for B3678/S34678. Every pattern then has an “anti-pattern” that evolves in exactly the same way on a full background. Anneal (B4678/S35678) meets the same condition; its boundaries between live and dead regions smooth out over time, like an interface being annealed.
How the engine uses it
The specimen of a code post draws one of the two families from its seed. Two times out of three, it is an elementary automaton, chosen among a dozen rules that make good pictures: 30 and 45 for chaos, 90 and 150 for the Sierpiński triangles of additive rules, 110 for complexity, and a few others. The banner is then the space-time diagram, revealed row by row when the page replays the growth. The initial condition is a single cell, three to six spaced-out cells, or a random row with a density drawn from the seed (between 4 and 16% live cells). From a single cell, the diagram starts at the first generation whose pattern covers, by the last row, a share of the width drawn from the seed; rules 169 and 225, which only draw one edge of a cone from it, always start from a random row. On the three-row strips of the post list, too short to show anything but the start, the engine first lets a few generations go by.
One time out of three, it is a Life-like rule, chosen among the five in table 2. The grid is a torus, seeded with a random soup whose density depends on the rule, and the simulation runs for sixty generations: in the browser you watch them go by one after another, then the picture stops on the sixtieth. It keeps a memory of its recent history: each cell that has just been born or died lights up, then dims by 15% per generation, while live cells that stay put remain in the light tone. Stable structures fade away and moving fronts stand out, with their wake. The B/S notation translates directly into two bit masks:
// born and survive: bit n set if n neighbours bring to life or keep alive
b[mid + x] = ((a[mid + x] ? survive : born) >> n) & 1;
The second specimen below is of this kind: Life, B3/S23, on a torus seeded at 38%.
Notes
-
Turlough Neary and Damien Woods, “P-completeness of Cellular Automaton Rule 110”, ICALP 2006. Cook’s exponential cost comes from a Turing machine whose tape is encoded in unary. ↩