cint

demos / avalanche / classic

Avalanche in a Rocking Box

A cint program breaks a dam of 1,024 water particles in a box that rocks back and forth, in whole-number arithmetic, three times over. One run leads, and in two twins a single particle starts one and two position units higher, a 65,536th of a cell. The sloshing water is chaotic, so the twins part. The consensus tether pulls them back, and the particles can be added to the grid in any order without changing a bit.

shell
$ cint run avalanche.ci
after 200 steps, dam break:
leader digest=16068736196783105470
twin 1 digest=9361378684162781723
twin 2 digest=14018043164987798962
spread twin 1=1567 Q, twin 2=2068 Q
grid forward=16664651050221779481
grid backward=16664651050221779481
grid jumping=16664651050221779481
grid mass=1024 particles
avalanche.ci

Leader A: drawn on top
Twin B: particle 0 +1 unit up
Twin C: particle 0 +2 units up
0 / 0 · step 0

What the Page Runs

The page runs avalanche.c, the C that cintc 0.2.0 emits from avalanche.ci, compiled to 64-bit WebAssembly in a background worker. A second worker runs a JavaScript port of the same integer steps, rounding and faults over the same frames, and compares the three digests of every frame with the WebAssembly run's. The line under the view counts the frames it has checked. Where 64-bit WebAssembly is not available, as on iPhone and iPad today, the JavaScript port runs instead.

  • The water is MLS-MPM, the moving least squares material point method of Hu et al. (2018), as a weakly compressible fluid: 1,024 particles per copy on a grid of 16 by 16 by 16 cells. Each step scatters mass and momentum to the grid, moves the grid under gravity and the walls, and gathers the grid back into the particles.
  • Positions are integers in 65,536ths of a cell. The box rocks: sideways gravity sweeps up to about 28 and 21 degrees on two periods, so the water never settles.
  • The weights are powers of two and every sum stays below 253, so the grid is exact. The scatter adds the same grid, node by node, in any particle order; the tests check three orders bit for bit, and the Particle Order card lets a run switch order as it goes.
  • The grid holds the mass of exactly 1,024 particles, not close to it; main and a test check it.

The Consensus Tether

The tether acts on each twin particle's velocity, toward the leader's same particle.

  • Pulling, it is a critically damped spring whose stiffness grows as the fourth power of the setting. At full strength it settles in about 60 steps.
  • Pushing, it is a weak spring away from the leader's particle, with no damping, that lets go one cell out. The sloshing carries the split from there.
  • A tether change takes hold at the frame on screen, as the slider moves. Copy link records each change, so the link it copies replays the same run.

The Receipt

outcome value
run.program avalanche.ci
run.steps 200
fuel-consumed 28590894
stdout-sha256 17922499edef4b1f8949dea38007edc39f5b71b591d4484a6a07128d230a41b2
tests 3/3

The file's tests check that the scatter gives the same grid in order, backward and jumping; that the grid's mass is exactly the particle count; and that a run in the jumping order gives the same digests as one in order.

The emitted C is the output of cint emit-c on the same file.