code wiki / _hdl_build / nx_research_phys_gate.nx

nx_research_phys_gate.nx source

↩ module page · 95 lines · 6207 B

1// nx_research_phys_gate.nx -- the research-engine reproducibility loop in the THIRD domain: PHYSICS (operator: 2// "discover new capabilities through different math/chemistry/physics via simulations... s class exceed on 3// research AND reproducibility"). RESEARCHER confirms the foundationed physics reference (CODATA Fundamental 4// Physical Constants) is in the no-link-rot library. TESTING-TEAM simulates classical-mechanics events and 5// REPRODUCES the known outcomes: elastic-collision velocities (incl. the Newton's-cradle equal-mass swap) and 6// projectile kinematics (range/height/flight-time closed forms). VERIFIER checks the conservation laws and a 7// liar-kill: an INELASTIC collision conserves momentum but VIOLATES kinetic-energy conservation -- which is 8// exactly what distinguishes elastic from inelastic, so the verifier can't be fooled. Exact integer (no float). 9// GREEN iff 6/6. license_tier: ORIGINAL 10import "nx_syscalls.nx" 11import "nx_library.nx" 12import "nx_gate_verdict.nx" 13 14func 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 } 15func 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 } 16func 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 } 17 18func rs_has(buf: *u8, n: i64, needle: *u8) -> i64 { 19 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} 20 if nl==0 { return 0 } 21 var i: i64=0 22 while i+nl<=n { var j: i64=0; var ok: i64=1; while j<nl { if buf[i+j]!=needle[j]{ok=0;j=nl}else{j=j+1} } if ok==1 {return 1} i=i+1 } 23 return 0 24} 25func rs_lib_contains(needle: *u8) -> i64 { 26 let cids: *i64 = sys_mmap(8*256) as *i64 27 let cnt: i64 = lib_list(cids, 256) 28 let pp: *i64 = sys_mmap(8) as *i64; let ll: *i64 = sys_mmap(8) as *i64 29 var d: i64 = 0 30 while d < cnt { if lib_get(cids[d] as *u8, pp, ll) == 1 { if rs_has(pp[0] as *u8, ll[0], needle) == 1 { return 1 } } d = d + 1 } 31 return 0 32} 33 34// elastic 1-D collision velocities (exact for chosen integer cases). 35func el_v1(m1: i64, m2: i64, u1: i64, u2: i64) -> i64 { return ((m1-m2)*u1 + 2*m2*u2) / (m1+m2) } 36func el_v2(m1: i64, m2: i64, u1: i64, u2: i64) -> i64 { return ((m2-m1)*u2 + 2*m1*u1) / (m1+m2) } 37func momentum(m1: i64, m2: i64, a: i64, b: i64) -> i64 { return m1*a + m2*b } 38func ke2(m1: i64, m2: i64, a: i64, b: i64) -> i64 { return m1*a*a + m2*b*b } // 2x kinetic energy (avoids the 1/2) 39 40func main() -> i64 { 41 let pass: *i64 = sys_mmap(8) as *i64; pass[0] = 0 42 g_w("=== NX-RESEARCH-PHYS GATE (reproduce classical mechanics; conservation-law verifier) ===\n") 43 44 let found: i64 = rs_lib_contains("Physical Constants" as *u8) 45 46 // --- elastic collisions: (m1,m2,u1,u2) -> known (v1,v2) --- 47 // A: equal-mass swap (Newton's cradle) B: unequal C: head-on equal 48 let a_v1: i64 = el_v1(1,1,5,0); let a_v2: i64 = el_v2(1,1,5,0) // -> (0,5) 49 let b_v1: i64 = el_v1(2,1,3,0); let b_v2: i64 = el_v2(2,1,3,0) // -> (1,4) 50 let c_v1: i64 = el_v1(1,1,4,0-4); let c_v2: i64 = el_v2(1,1,4,0-4) // -> (-4,4) 51 52 var known_ok: i64 = 0 53 if a_v1==0 { if a_v2==5 { if b_v1==1 { if b_v2==4 { if c_v1==(0-4) { if c_v2==4 { known_ok=1 } } } } } } 54 55 var mom_ok: i64 = 0 56 if momentum(1,1,5,0)==momentum(1,1,a_v1,a_v2) { if momentum(2,1,3,0)==momentum(2,1,b_v1,b_v2) { if momentum(1,1,4,0-4)==momentum(1,1,c_v1,c_v2) { mom_ok=1 } } } 57 var ke_ok: i64 = 0 58 if ke2(1,1,5,0)==ke2(1,1,a_v1,a_v2) { if ke2(2,1,3,0)==ke2(2,1,b_v1,b_v2) { if ke2(1,1,4,0-4)==ke2(1,1,c_v1,c_v2) { ke_ok=1 } } } 59 60 // --- projectile kinematics: vx=3, vy=4, g=2 -> t=4, R=12, H=4 (closed forms) --- 61 let vx: i64=3; let vy: i64=4; let gg: i64=2 62 let tf: i64 = 2*vy/gg 63 let R1: i64 = vx*tf 64 let R2: i64 = 2*vx*vy/gg 65 let Hh: i64 = vy*vy/(2*gg) 66 let apex_vy: i64 = vy - gg*(tf/2) 67 var proj_ok: i64 = 0 68 if tf==4 { if R1==12 { if R2==12 { if Hh==4 { if apex_vy==0 { proj_ok=1 } } } } } 69 70 // --- LIAR-KILL: inelastic collision (m1=2,m2=1,u1=3,u2=0 stick at v=2) --- 71 let in_v: i64 = momentum(2,1,3,0) / (2+1) // common velocity = 6/3 = 2 72 let in_mom_ok: i64 = (momentum(2,1,3,0) == momentum(2,1,in_v,in_v)) as i64 // momentum STILL conserved 73 let in_ke_violated: i64 = (ke2(2,1,3,0) != ke2(2,1,in_v,in_v)) as i64 // but KE is NOT -> not elastic 74 75 g_w(" researcher: physics reference (CODATA Fundamental Physical Constants) in library = "); g_n(found); g_w("\n") 76 g_w(" elastic A(1,1,5,0)->("); g_n(a_v1); g_w(","); g_n(a_v2); g_w(") B(2,1,3,0)->("); g_n(b_v1); g_w(","); g_n(b_v2); g_w(") C(1,1,4,-4)->("); g_n(c_v1); g_w(","); g_n(c_v2); g_w(")\n") 77 g_w(" projectile vx=3,vy=4,g=2 -> t="); g_n(tf); g_w(" R="); g_n(R1); g_w(" H="); g_n(Hh); g_w(" apex_vy="); g_n(apex_vy); g_w("\n") 78 g_w(" inelastic(2,1,3,0)->stick v="); g_n(in_v); g_w(" KE before="); g_n(ke2(2,1,3,0)); g_w(" after="); g_n(ke2(2,1,in_v,in_v)); g_w("\n") 79 80 g_row("RESEARCHER: foundationed physics reference present in library" as *u8, found, pass) 81 g_row("reproduce known elastic outcomes (swap, unequal, head-on)" as *u8, known_ok, pass) 82 g_row("CONSERVATION: momentum conserved across all elastic collisions" as *u8, mom_ok, pass) 83 g_row("CONSERVATION: kinetic energy conserved across all elastic collisions" as *u8, ke_ok, pass) 84 g_row("reproduce projectile kinematics (t=4, R=12, H=4 closed forms)" as *u8, proj_ok, pass) 85 var liar: i64 = 0 86 if in_mom_ok==1 { if in_ke_violated==1 { liar=1 } } 87 g_row("LIAR-KILL: inelastic keeps momentum but VIOLATES KE (verifier not fooled)" as *u8, liar, pass) 88 89 g_w("RESEARCH-PHYS-GATE rows=6 pass="); g_n(pass[0]) 90 if pass[0] == 6 { g_w(" verdict=GREEN\n") } else { g_w(" verdict=RED\n") } 91 let ctr: *i64 = gv_ctr() 92 ctr[0] = pass[0] 93 ctr[1] = 6 94 return gv_verdict("RESEARCH-PHYS-GATE" as *u8, ctr, "CODATA-anchored classical mechanics reproduced exactly, conservation liar-kill proven" as *u8) 95}