Cellular automata
Cells that are 0 or 1, updated by a local rule: the discrete end of dynamics, where everything is exact and yet rule 30 looks random and Life can compute anything.
elementary(90).fromCell(15); // rows of Pascal's triangle mod 2
elementary(110).equivalents; // [110, 124, 137, 193]
elementary(184).cycle("10101010"); // { transient: 0, period: 2 }
life(patterns.glider).classify(); // { kind: "spaceship", period: 4, speed: "c/4", … }
life("OOO\nO..\nO..", { rule: "B36/S23" }); // HighLife
Elementary rules
A row of cells, each new cell determined by itself and its two neighbours. There are neighbourhoods and so rules, numbered by Wolfram: bit n of the rule number is the new cell for the neighbourhood whose binary value is n. Reflecting left and right, or swapping 0 and 1, turns one rule into another that behaves the same way, which cuts 256 rules to 88 classes; equivalents lists a rule's class.
Rule 90 is additive: the new cell is the sum mod 2 of the two neighbours. From one live cell, row t is then the binomial coefficients mod 2, which is Sierpinski's triangle again, and by Lucas's theorem is odd exactly when the binary digits of k are a subset of those of t. additive tests the linearity condition directly and finds exactly the eight rules 0, 60, 90, 102, 150, 170, 204, 240.
On a ring of n cells there are rows, so every orbit eventually repeats; cycle finds when and with what period. Rule 30 from one cell looks random enough that its centre column was used as a random number generator, and rule 110 was proved capable of universal computation.
Life
Conway's Game of Life on the unbounded plane: a dead cell with exactly 3 live neighbours is born, a live one with 2 or 3 survives. Other rules are written the same way, as "B3/S23". Only live cells are stored, so a glider can travel forever.
classify runs a pattern and compares each generation's shape, moved to the origin, with all earlier ones, cell by cell. A repeat in the same place is a still life or an oscillator with that period; a repeat that has moved is a spaceship, with its speed in cells per generation as a fraction of c, the speed of light (one cell per step). The glider moves one cell diagonally every 4 generations, c/4; the lightweight spaceship moves 2 cells in 4, c/2. Patterns that grow forever, like the Gosper glider gun, never repeat and come back as "unknown" within the limit.
| call | returns |
|---|---|
| elementary(rule) | Elementary: table, mirror, complement, equivalents, additive |
| step(row, { boundary }), run(initial, steps), fromCell(steps) | Uint8Array rows |
| cycle(initial, { limit }) | { transient, period } |
| showRows(rows, on, off) | Rows as text |
| life(cells, { rule }) | Life: population, step(), run(n), bounds(), classify(), toString() |
| patterns | block, blinker, toad, beacon, glider, lwss, pulsar, rpentomino, gosperGun |
@ratmath/chaos and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.