Home›Journal›This post

Abelian Sandpile Art: Topple by Proof

Stabilize a finite open grid, prove conservation under two legal schedules, art-direct height and odometer layers, and export SVG with its receipt.

JP
JP Casabianca
AI Engineer and Product Designer · full-stack delivery · Bogotá

Abelian sandpile art is more than a pretty avalanche image; a valid edition must reach a stable state on its declared finite grid. This tutorial builds a conservation and schedule-independence receipt before it art-directs the result.

Define the finite Abelian sandpile art lattice

Abelian sandpile art is more than a pretty avalanche image: it is valid only when the declared finite grid actually stabilizes. This tutorial builds a conservation and schedule-independence receipt before treating the result as an edition.

Use an odd square lattice so the center is unambiguous, with width from 9 through 65. Each cell holds a nonnegative integer height. A cell is unstable at height four or more; one legal toppling removes four grains and sends one to each cardinal neighbor. A neighbor outside the grid is the sink. This chip-firing art rule is discrete and local.

Dhar's review of the Abelian sandpile and related models provides the mathematical setting and core properties. This browser study adopts one bounded square-grid, four-neighbor, open-boundary model. It does not simulate physical sand, measure a natural pile, or establish universal critical behavior.

The artwork keeps three layers: final height, per-cell odometer, and sink loss. Final height says where grains remain. The odometer counts how many legal topplings each cell performed. Sink loss closes conservation. Together they provide more original value than a screenshot alone. Abelian sandpile art is a mathematical image, not a physical sandpile simulation.

For a related rule-to-pattern practice, woven cellular automata patterns shows how a deterministic state can support artistic treatment without confusing style with simulation evidence. Abelian sandpile art uses the same separation: model first, edition second.

Open-boundary toppling stencilInterior, edge, and corner cells emit four grains; solid arrows stay on the grid and dashed arrows enter the sink.ONE LEGAL TOPPLE · FOUR CARDINAL GRAINS4 → 0INTERIOR4 in-grid · 0 sink4 → 0EDGE3 in-grid · 1 sinkSINK4 → 0CORNER2 in-grid · 2 sinkSINK
Open-boundary toppling stencil. The stencil makes sink accounting a local rule rather than a correction applied after stabilization.
Interior
Four solid arrows reach four in-grid neighbors; sink loss is zero.
Edge
Three solid arrows reach neighbors and one dashed arrow reaches the sink.
Corner
Two solid arrows reach neighbors and two grains enter the sink.
Legality
The source height must be at least four before any arrow fires.

Reading rule: labels, order, values, shapes, and line styles carry the conclusion; color is supplementary.

Choose open-boundary sink semantics

An open boundary means the lattice does not wrap. When a corner topples, two emitted grains remain in-grid and two enter the sink. An edge cell that is not a corner loses one grain; an interior cell loses none. The sink is not another drawable cell and never topples.

Record the convention in the recipe because different boundaries create different images. A torus conserves all grains inside the grid and can fail to stabilize for some additions. A closed reflecting border changes neighbor flow. Neither is interchangeable with the open-boundary Abelian sandpile art built here.

The original formulation in Dhar's paper on the self-organized critical state of sandpile automaton models supports the Abelian chip-firing context. Our receipt makes a smaller claim: two legal schedules on this finite open grid reach equal final states and odometers within the stated toppling cap.

The first figure marks interior, edge, and corner emissions with solid neighbor arrows and dashed sink arrows. Its text key repeats every movement without color. That is also the hand-checking rule for code review.

Initialize the grid explicitly, then add zero through 100,000 grains by center, ring, or seeded preset. Preserve initial total, added total, final total, and sink loss as integers. A conservation line should remain visible throughout the run, not calculated only after export.

Implement one legal toppling

A legal toppling begins only when a cell height is at least four. Subtract four, increment its odometer once, then visit the four cardinal directions in a fixed local order. Add one to an in-grid neighbor or increment sink loss for an out-of-grid neighbor. Never allow a negative cell.

Use integer arrays for heights and odometers. The maximum grid has 4,225 cells, so fixed-size typed arrays are modest. Validate every generated index before mutation. Inputs that are even, fractional, outside 9–65, nonfinite, or syntactically malformed are rejected rather than rounded.

One cell may remain unstable after a single toppling. A scheduler therefore returns it to the worklist when needed. Likewise, any neighbor that becomes unstable must enter the worklist. Duplicate queue entries are acceptable if the pop step rechecks legality; alternatively, track an in-queue bitset and clear it on pop.

The hand-checkable table in figure two starts with four grains at the center of a 3-by-3 explanatory crop. One legal toppling leaves center zero and each cardinal neighbor one, with no sink loss. A corner example loses two. These small examples kill omissions that a large sandpile fractal could visually conceal. Correctness lives in local transitions plus global invariants.

Stabilize under a hard work cap

Process unstable cells until the worklist is empty or one million topplings have occurred. The cap is a product and safety boundary, not a mathematical statement. If the cap is reached, return an explicit incomplete result, preserve the partial ledger, disable edition export, and invite a smaller grid or grain count.

Two schedulers make the Abelian property test visible. A queue chooses the oldest legal cell. A stack chooses the newest. Both apply identical local toppling rules but produce different histories. For a completed run, compare final heights, every odometer value, and sink loss byte for byte.

The queue history summary remains bounded: total pushes, pops, peak worklist size, topplings, and a small sample of early and late events. Do not retain one million full event objects. This is essential for a zero-network browser tool that must avoid unbounded allocation while still explaining its work.

Deterministic seeded presets use a small documented integer generator. The seed controls additions, never tie semantics inside a supposedly fixed schedule. A seed-dependent tie corruption mutant deliberately violates that boundary and must produce a mismatched receipt.

Abelian sandpile art is exportable only when the run is complete, stable, conserved, and schedule-independent. The empty worklist alone is insufficient if a bug failed to enqueue an unstable cell.

Hand-checkable avalanche and odometer ledger

Two tiny examples verify the local transition, odometer increment, stability, and sink conservation before a large edition is drawn.

FixtureBeforeAfter one toppleOdometerSinkResult
Centercenter 4; others 0center 0; N/E/S/W each 1center 10Pass: 4 = 4 + 0
Cornercorner 4; others 0corner 0; two neighbors 1corner 12Pass: 4 = 2 + 2
Illegalcenter 3unchangedall zero0Pass: no topple
Small integer examples expose missing neighbors and boundary loss that visual complexity might disguise.
  • Every legal toppling removes exactly four grains.
  • Each in-grid cardinal neighbor receives exactly one grain.
  • Every off-grid direction increments sink loss by one.
  • The source odometer increments once and no stable source topples.

Reading rule: the pass or fail words and numeric values carry the conclusion; color is supplementary.

Prove conservation and stability

After stabilization, scan every cell. Heights must be integers from zero through three, odometers must be nonnegative integers, and no unstable cell may remain. Then verify initial total plus added grains equals final total plus sink loss. Display both sides of the equation with their numeric values.

Conservation detects several useful failures. Emitting only three grains makes mass disappear. Omitting a neighbor also loses mass unless falsely credited to the sink. Failing to count a boundary grain makes the right side too small. A threshold-five mutant may conserve grains yet leave height four, so stability is a separate invariant.

The odometer adds a second proof surface. Every count corresponds to four grains removed from that cell. Independently reconstruct the net height from initial additions, four times the odometer, incoming neighbor odometers, and boundary loss. That equation catches a final state copied from the trusted path while its history ledger is wrong.

The studio's conservation table reports queue and stack results side by side. It uses words—pass, incomplete, mismatch—not only green and red. The exact canonical recipe includes model version, size, preset, seed, added grains, cap, palette, crop, final-state hash, odometer hash, and sink loss.

For another visual system built from local diffusion rules, see reaction-diffusion WebGPU art. Its numerical boundary differs; the shared lesson is to export parameters and validation beside the image.

Compare legal schedules

The Abelian property does not mean any broken implementation gives the same answer. It means legal topplings commute under the model's conditions. Queue and stack schedules must each topple only unstable cells and continue until stable. Their event order may differ while final state and odometer agree.

Compare arrays exactly because the model is integer-valued. Also compare sink loss, toppling count, conservation, and stable status. If either run hits the cap, schedule independence is unresolved rather than failed or passed. That distinction prevents an incomplete pair from becoming evidence.

The third figure turns three arrays into an artistic and diagnostic triptych: final height, odometer intensity, and schedule difference. The difference panel should be entirely zero for a passing receipt. Its semantic list states the hashes and maximum absolute difference so the conclusion survives without the graphic.

Mutation tests make the comparison harder to game: threshold five, emit only three grains, omit one neighbor, miss one boundary sink grain, stop with an unstable cell, and corrupt a tie from the seed. At least one declared invariant must reject every mutant.

A related diffusion-limited aggregation Canvas study grows branching forms with stochastic walkers. Do not merge its claims with Abelian sandpile art. Similar visual complexity can arise from very different mechanisms, which is exactly why receipts matter.

Height, odometer, and schedule-difference triptychThree panels show final heights as four mark types, toppling counts as nested rings, and an all-zero queue-versus-stack difference field.ONE STABILIZATION · THREE ACCOUNTABLE LAYERSFINAL HEIGHTmarks 0 · 1 · 2 · 3ODOMETERcount rings · log scaleSCHEDULE Δmax absolute difference = 0
Height, odometer, and schedule-difference triptych. The artwork and its proof share a frame: residual state, work history, and schedule agreement remain individually inspectable.
Final height
Every cell is an integer from zero through three, represented by both mark and tone.
Odometer
Every cell stores its nonnegative legal-toppling count.
Schedule difference
Queue and stack final states and odometers have maximum absolute difference zero.
Shared receipt
Conservation, hashes, recipe, palette, and crop remain attached.

Reading rule: labels, order, values, shapes, and line styles carry the conclusion; color is supplementary.

Art-direct odometer and final-state layers

Only after proof should the numerical arrays become visual material. Map final heights zero, one, two, and three to four distinguishable marks or tones. Map odometer counts through a logarithmic or percentile scale so the quiet boundary and active center both remain visible. Keep the mapping in the recipe.

Canvas is an immediate drawing surface defined by the WHATWG Canvas section. Use it for responsive preview, then generate the downloadable SVG directly from the arrays so the export remains inspectable and accessible. This Canvas generative art workflow keeps the numerical source beside the pixels. The SVG includes a title, description, legend, cell shapes, and the conservation statement.

Offer a small palette set with sufficient contrast: mineral, nocturne, and paper ink. Shapes or labels must carry the four final heights when color perception is limited. A reduced-motion preference disables any animated reveal and displays the stable state immediately. Forced colors keep controls, focus outlines, and proof text visible.

Crop and palette are artistic parameters, not simulation inputs. Changing them must preserve final-state and odometer hashes. That separation lets one stabilized sandpile support multiple editions without pretending the underlying experiment changed.

The Canvas dithering tutorial offers techniques for translating continuous tone into marks. Apply those ideas to the odometer layer while retaining exact data in JSON. Abelian sandpile art can be expressive and audit-friendly at once.

Export an honest Abelian sandpile art edition

The paired export contains an accessible SVG and a JSON receipt. JSON records validated inputs, initial and final totals, flattened final heights, odometer, queue summary, sink loss, schedule comparison, invariant results, mutation results, style parameters, hashes, and the truth boundary. SVG records the title, description, visual marks, legend, and recipe identifier.

Reparse JSON and verify lengths equal size squared, values are bounded integers, conservation closes, and hashes match. Parse the SVG with DOMParser, reject parser errors, confirm the declared viewBox and accessible names, and compare its embedded recipe identifier with JSON. File generation is not proof until a separate parser accepts it.

This bounded Bak–Tang–Wiesenfeld-style square-grid study says nothing about physical sand, universal critical exponents, or all sandpile variants. It demonstrates legal stabilization and schedule agreement only for its declared fixtures under the cap. Keep that sentence in the gallery caption.

An edition is strongest when the evidence is aesthetically integrated: conservation as a small typeset equation, the odometer as texture, the schedule-difference zero as negative space, and the recipe as a quiet footer. Open the studio, make one center, ring, or seeded work, and store its proof beside the image. Revisit the model when browser behavior, export rules, or the implementation changes.

Runnable local artifact — This is a bounded Bak–Tang–Wiesenfeld-style square-grid study, not a physical sand simulation, proof of universality, or empirical critical-exponent experiment.

Plain text1 line
Choose an odd grid, bounded grain count, deterministic preset, palette, and crop; stabilize under queue and stack schedules, inspect proof, and export the edition receipt.