cint

demos / pendulum

A Double Pendulum Swinging in 3D

A cint program swings three double pendulums under gravity in whole-number arithmetic. One leads, and two twins start one and two millionths of a radian from it, yet they still drift away. The consensus tether pulls them back or pushes them apart.

shell
$ cint run pendulum.ci
after 500 steps (5.0 seconds):
pendulum 0: digest=14995127728425866399
pendulum 1: digest=8897290559184475167
pendulum 2: digest=11575834901304267551
divergence A to B: 1519 um
pendulum.ci
Pendulum A (Leader): Baseline
Pendulum B (Twin 1): +1 μrad Azimuth
Pendulum C (Twin 2): +2 μrad Azimuth
Space Play/Pause · Shift+R Restart Sim · R Reset View
0 / endless · 0.000s

What the Page Runs

The page runs pendulum.c, the C that cintc 0.2.0 emits from pendulum.ci, compiled to 64-bit WebAssembly in a background worker. A browser without 64-bit WebAssembly runs the same arithmetic rewritten in JavaScript integers, and the two agree on every value of 3,500 ticks at five tether settings.

  • Sines come from a seventh-order series and lengths from an integer square root, in millionths.
  • Every tick folds each pendulum's angles and tip position into a 64-bit digest. At tick 500 the page shows the digests that cint run prints.
  • Above 10 rad/s an angular speed loses 0.5% a tick, and it never passes 12 rad/s. The program and the page both apply this governor.

The Consensus Tether

The tether acts on each of the four angles of the two twins, toward the leader.

  • Pulling, the tether is a spring toward the leader. At full strength it is as stiff as gravity's own restoring pull, and it is damped so it settles without overshoot.
  • Pushing, the tether is a weak spring away from the leader with negative damping. The separation grows slowly until the speed governor holds it.
  • A change takes hold at the tick on screen, as the slider moves, and every earlier tick stays as it was. Copy link records each change, so the link it copies replays the same run.
Tip distance between the leader and the first twin after 500 ticks, in micrometers, from cint run
TetherPush 100Push 50OffPull 25Pull 50Pull 100
Distance416,04511,4021,5192536316

The Receipt

outcome value
run.program pendulum.ci
run.steps 500
fuel-consumed 41509
stdout-sha256 ebe8373adc18ed8e0b6e6246d295bc15900aec02f393e777011c7977c5ae7683
tests 5/5

The reference interpreter and cintc 0.2.0 print the same bytes. The file's tests pin the three digests at tick 500 and check that the tether pulls and pushes. Two more stop on a negative square root and on an overflowing speed.

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