code wiki / _hdl_build / nx_research_orbit_gate.nx

nx_research_orbit_gate.nx

buildroot/runtime/_hdl_build/nx_research_orbit_gate.nx

6081 B98 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind gate/prooftopic research
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_research_orbit_gate.nx

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

main sys_mmap g_w sys_write orbit_E2 isqrt iabs sim_lf_orbit orbit_E2 ↻ sys_mmap ↻ isqrt ↻ accel isqrt ↻ iabs ↻ sim_eu_orbit orbit_E2 ↻ sys_mmap ↻ isqrt ↻ accel ↻ iabs ↻ g_n g_w ↻ sys_mmap ↻ sys_write ↻ g_row g_w ↻ isqrt ↻ sys_exit

structs

none

consts

none

functions

11func 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 }
called by 3: g_ng_rowmain calls 1: sys_write
12func 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 }
called by 1: main calls 3: g_wsys_mmapsys_write
13func 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 }
called by 1: main calls 1: g_w
14func iabs(x: i64) -> i64 { if x<0 { return 0-x } return x }
15func 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 }
17func accel(x: i64, y: i64, GM: i64, out: *i64) -> i64
called by 2: sim_lf_orbitsim_eu_orbit calls 1: isqrt
26func 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 }
called by 3: sim_lf_orbitsim_eu_orbitmain calls 1: isqrt
29func sim_lf_orbit(x0: i64, y0: i64, vx0: i64, vy0: i64, GM: i64, D: i64, N: i64, out: *i64) -> i64
called by 1: main calls 5: orbit_E2sys_mmapisqrtacceliabs
50func sim_eu_orbit(x0: i64, y0: i64, vx0: i64, vy0: i64, GM: i64, D: i64, N: i64, out: *i64) -> i64
called by 1: main calls 5: orbit_E2sys_mmapisqrtacceliabs
70func main() -> i64