The abelian sandpile and its identity element
sandpilecellular-automatonself-organized-criticalitygroup-theorysimulation
The abelian sandpile (Bak, Tang and Wiesenfeld 1987; group structure by Dhar) is a grid where each cell holds grains; a cell with 4 or more grains topples, sending one grain to each of its four neighbors, and grains that fall off the edge are lost. The final stable board does not depend on the order of topplings (hence "abelian"). Built as "The Shape of Zero" at justinahampton.com/fun/freetime/sandpile/.
The group and its zero
- Recurrent boards (those reachable again after adding grains to any board) form a finite abelian group under "add cell by cell, then stabilize". Its size equals the number of spanning trees of the grid graph with the boundary collapsed to one sink: 192 for a 2x2 board and 100,352 for 3x3 (checked by the harness).
- The group has an identity, "zero", which is a striking fractal picture on a square. Compute it as
relax(6 - relax(6)): fill every cell with 6, stabilize, subtract that from 6 everywhere, stabilize again. Every board shape (disc, diamond, ring, heart) has its own zero. - Adding zero to a recurrent board returns it cell for cell; a non-recurrent board changes once and then never again. That is a nice visible proof that a board is recurrent.
- Burning test (Dhar): add to each cell the number of its neighbors that are sinks (edges or holes); the board is recurrent if and only if every cell then topples exactly once.
Implementation notes
- Store the board with a one-cell border; a mask marks sinks (border and holes in the shape).
- Sweep relaxation: topple every unstable cell q times at once (
q = floor(h/4)), alternating scan direction, and only rescan rows near the last topples. Much faster than one grain at a time for big piles. - Worklist relaxation for single drops, which also records which cells toppled (for an avalanche heat map).
- Cost: computing zero takes about 0.31 n² sweeps: 0.23 s at 128², 3.5 s at 256², 17.6 s at 384² in the browser. A speed slider should therefore be relative to board size.
Self-organized criticality
Dropping one grain at a time on a recurrent board produces avalanches whose sizes follow a power law. A log-log histogram with a fitted slope measured about -1.08 on a 64² board.