code wiki / _hdl_build / nx_research_orbit_gate.nx
nx_research_orbit_gate.nx
buildroot/runtime/_hdl_build/nx_research_orbit_gate.nx
about
nx_research_orbit_gate.nx -- the capstone of the dynamics thread: a 2-D gravitational orbit (inverse-square
central force, a = -GM r / |r|^3) integrated in sovereign fixed-point (using our isqrt for |r|). THE canonical
reason symplectic integrators exist: over many orbits the SYMPLECTIC leapfrog keeps the orbit BOUNDED and energy
conserved, while naive forward-EULER pumps energy in and the orbit SPIRALS OUTWARD.
Fixed-point precision trick: store velocity scaled by VS=2D, so the leapfrog half-kick v += a*dt/2 = a/(2D)
becomes v_scaled += a EXACTLY (no truncation -- the dominant error source). Position step then divides by 2D*D.
Verifier = energy conservation + orbit-radius bound; liar-kill = Euler's plausible orbit fails the bound the
symplectic orbit holds. No float, deterministic. GREEN iff 6/6. license_tier: ORIGINAL
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| none |
functions
| 11 | func g_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 12 | func g_n(v: i64) -> i64 { var m: i64=v; if m<0{g_w("-");m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i:i64=0; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1}; sys_write(1,o,k); return 0 } |
| 13 | func g_row(id: *u8, ok: i64, pass: *i64) -> i64 { g_w(" "); g_w(id); g_w(": "); if ok==1 { g_w("OK\n"); pass[0]=pass[0]+1 } else { g_w("FAIL\n") } return 0 } |
| 14 | func iabs(x: i64) -> i64 { if x<0 { return 0-x } return x } |
| 15 | func isqrt(N: i64) -> i64 { if N<2 { return N } var x: i64=N; var y: i64=(x+1)/2; while y<x { x=y; y=(x + N/x)/2 } return x } |
| 17 | func accel(x: i64, y: i64, GM: i64, out: *i64) -> i64 |
| 26 | func orbit_E2(x: i64, y: i64, vsx: i64, vsy: i64, GM: i64, VS: i64) -> i64 { let r: i64=isqrt(x*x+y*y); let vrx: i64=vsx/VS; let vry: i64=vsy/VS; return vrx*vrx+vry*vry - 2*GM/r } |
| 29 | func sim_lf_orbit(x0: i64, y0: i64, vx0: i64, vy0: i64, GM: i64, D: i64, N: i64, out: *i64) -> i64 |
| 50 | func sim_eu_orbit(x0: i64, y0: i64, vx0: i64, vy0: i64, GM: i64, D: i64, N: i64, out: *i64) -> i64 |
| 70 | func main() -> i64 |