Augustin Grudet

Cellular automata: 256 rules, four classes, one universal machine

The generator behind the specimens of the code tag: elementary automata and Wolfram's numbering, the four classes, the universality of rule 110 and Life-like rules.

  • 7 min read
  • #specimens
  • #code

This post was machine-translated from the original version.

Contents

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.

specimen 0x657a · automaton · rule 54 random
Interactive specimen, here an elementary automaton: the sliders pick the rule among the engine's twelve and the starting condition. The reseed button can land on a Life-like rule, which then comes with rule and density sliders.

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:

xit+1=f(xi−1t,  xit,  xi+1t)x_i^{t+1} = f\big(x_{i-1}^t,\; x_i^t,\; x_{i+1}^t\big)

Three bits give 23=82^3 = 8 possible neighbourhoods, and a rule picks an output for each: there are therefore 28=2562^8 = 256 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 2k2^k is the output of the neighbourhood that reads kk in binary:

rule=∑k=07f(k) 2k,k=4 xi−1+2 xi+xi+1\text{rule} = \sum_{k=0}^{7} f(k)\, 2^k, \qquad k = 4\,x_{i-1} + 2\,x_i + x_{i+1}
Transition tables of rules 30 and 110. Read from left to right, the output row is the binary form of the rule number.
Neighbourhood111110101100011010001000
Weight1286432168421
Rule 3000011110
Rule 11001101110

For rule 30, 16+8+4+2=3016 + 8 + 4 + 2 = 30; for rule 110, 64+32+8+4+2=11064 + 32 + 8 + 4 + 2 = 110. The number is the table itself, compressed. Rule 30 also has a compact algebraic form, xit+1=xi−1t⊕(xit∨xi+1t)x_i^{t+1} = x_{i-1}^t \oplus (x_i^t \lor x_{i+1}^t), where ⊕\oplus 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.

               #                                             #
              ###                                           ##
             ##  #                                         ###
            ## ####                                       ## #
           ##  #   #                                     #####
          ## #### ###                                   ##   #
         ##  #    #  #                                 ###  ##
        ## ####  ######                               ## # ###
       ##  #   ###     #                             ####### #
      ## #### ##  #   ###                           ##     ###
     ##  #    # #### ##  #                         ###    ## #
    ## ####  ## #    # ####                       ## #   #####
   ##  #   ###  ##  ## #   #                     #####  ##   #
  ## #### ##  ### ###  ## ###                   ##   # ###  ##
 ##  #    # ###   #  ###  #  #                 ###  #### # ###
## ####  ## #  # #####  ###### #              ## # ##  ##### #
Sixteen generations from a single cell. On the left, rule 30: a triangle whose inside looks random. On the right, rule 110: a pattern that only grows to the left, mixing regular areas and localised structures.

Wolfram’s four classes

In 1984 Wolfram sorted the behaviour of automata started from random initial conditions into four qualitative families:

  1. Class 1: the evolution ends in a homogeneous state. Almost all the initial information is lost (rule 0, rule 32).
  2. Class 2: simple structures, stable or periodic, separated from one another (rule 4, rule 108).
  3. Class 3: chaotic, aperiodic behaviour that never settles; a small perturbation spreads without limit (rules 30, 22 or 150).
  4. 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 {0,…,8}\{0, \dots, 8\} defines a rule of this kind, which makes 218=262,1442^{18} = 262{,}144 rules. A few of them have names:

A few Life-like rules in B/S notation.
RuleNotationBehaviour
LifeB3/S23gliders, oscillators, guns; Turing-complete
HighLifeB36/S23close to Life, with a small self-replicating pattern (Nathan Thompson, 1994)
Day & NightB3678/S34678symmetric under inversion: live and dead cells play the same role
MazeB3/S12345very permissive survival freezes growth into maze corridors
AnnealB4678/S35678a “twisted” majority rule, also symmetric under inversion

A dead cell surrounded by nn live ones has 8−n8 - n dead neighbours, so inverting the whole grid swaps the roles of B and S. A rule is its own inverse when n∈B  ⟺  8−n∉Sn \in B \iff 8 - n \notin S: 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%.

specimen 0x0003 · automaton · B3/S23 life d=0.38
A Life-like rule: sixty generations replayed, with the trace of the cells that change. The sliders pick the rule and the density of the initial soup.

Notes

  1. 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. ↩

Sources

  1. Stephen Wolfram, "Statistical mechanics of cellular automata", Reviews of Modern Physics 55(3), 1983, pp. 601-644 (Nov 25, 2026)
  2. Stephen Wolfram, "Universality and complexity in cellular automata", Physica D 10(1-2), 1984, pp. 1-35 (Nov 25, 2026)
  3. Matthew Cook, "Universality in Elementary Cellular Automata", Complex Systems 15(1), 2004, pp. 1-40 (Nov 25, 2026)
  4. Turlough Neary, Damien Woods, "P-completeness of Cellular Automaton Rule 110", ICALP 2006, LNCS 4051 (Nov 25, 2026)
  5. Martin Gardner, "Mathematical Games: The fantastic combinations of John Conway's new solitaire game 'life'", Scientific American 223(4), 1970, pp. 120-123 (Nov 25, 2026)
  6. Eric W. Weisstein, "Elementary Cellular Automaton", MathWorld (Nov 25, 2026)
  7. "Life-like cellular automaton", Wikipedia (catalogue of B/S rules) (Nov 25, 2026)
  8. "Highlife (cellular automaton)", Wikipedia (Nov 25, 2026)
  9. "Day and Night (cellular automaton)", Wikipedia (Nov 25, 2026)