demos / orbits
Three Bodies, There and Back
A cint program runs three bodies under gravity in whole-number arithmetic, three times over. One run leads, and two twins start one and two millionths of a unit from it. The motion is chaotic, so the twins part. The consensus tether pulls them back, and a reversed run retraces its path to the starting bits.
$ cint run orbits.ci after 20000 ticks (2.0 time units), Pythagorean problem: leader digest=15110298595637020077 twin 1 digest=9072904302982474941 twin 2 digest=13663343393609666067 spread twin 1=179 u, twin 2=176 u momentum x=0, y=0 20000 ticks out and 20000 back, largest miss: 0 P
What the Page Runs
The page runs orbits.c, the C that cintc 0.2.0 emits from orbits.ci, compiled to 64-bit WebAssembly in a background worker. Its main prints the same bytes in your browser as cint run does natively.
- Positions are integers in trillionths of a length unit, with G = 1 and a tick of 10-4 time units. Forces use a softening length of 0.01, so close passes stay finite.
- Each tick is position Verlet: half kick, drift, half kick. A half kick depends only on positions, so flipping every velocity retraces the path exactly (Levesque and Verlet, 1993). Rounding in doubles does not undo itself, so a float run misses its start.
- Each pair force is applied as equal and opposite integers, so total momentum never changes, not even in the last bit.
- The Pythagorean start puts masses 3, 4 and 5 at rest on a 3-4-5 triangle. The figure eight of Chenciner and Montgomery is the ordered start.
The Consensus Tether
The tether acts on the twins' velocities, body by body, toward the leader's.
- Pulling, it is a critically damped spring toward the leader's body whose stiffness grows as the fourth power of the setting. Low settings draw the twins in slowly; at full strength it settles in about 150 ticks, strong enough to pull apart two bodies that a close pass has bound together.
- Pushing, it is a weak spring away from the leader, with no damping. It lets go once a twin's body is one length unit from the leader's, and gravity 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 orbits.ci run.ticks 20000 fuel-consumed 5400184 stdout-sha256 5e085c48022436a975ebbde9e1a5309598f09983c87adbc375969dc0554ccbe9 tests 4/4
The reference interpreter and cintc 0.2.0 print the same bytes with the same fuel. The file's tests check that 3,000 ticks out and 3,000 back return to the starting bits from both starts, that momentum is conserved exactly, that the tether pulls diverged twins back to within 1% of their spread, and pin the three digests at tick 20000.
The emitted C is the output of cint emit-c on the same file.