code wiki / _hdl_build / nx_research_discover_phys_gate.nx
nx_research_discover_phys_gate.nx source
↩ module page · 99 lines · 6349 B
1// nx_research_discover_phys_gate.nx -- DISCOVERY in PHYSICS, completing the math+chem+physics symmetry
2// (operator: "discover new capabilities through different math/chem/physics via simulations"). The physics
3// reproduction gate (nx_research_phys_gate) replays elastic outcomes via the KNOWN closed-form swap formula.
4// This gate DISCOVERS the outcome the way physics actually derives it: from the CONSERVATION LAWS alone.
5//
6// An elastic 1-D collision must conserve BOTH momentum and kinetic energy:
7// m1*v1 + m2*v2 == m1*v1' + m2*v2' (momentum)
8// m1*v1^2 + m2*v2^2 == m1*v1'^2 + m2*v2'^2 (kinetic energy)
9// This 2-equation system has exactly two integer-velocity solutions: the TRIVIAL (no collision: v'=v) and the
10// real exchange. The testing-team SEARCHES the integer velocity lattice and DISCOVERS the non-trivial solution
11// -- never given the swap formula -- then an INDEPENDENT verifier rechecks both laws and confirms it equals the
12// closed form. LIAR-KILL: the perfectly-inelastic outcome (the blocks stick) conserves momentum but VIOLATES
13// kinetic energy, so it is REJECTED -- the verifier cannot be fooled. Exact integer, deterministic. GREEN iff 6/6.
14// license_tier: ORIGINAL
15import "nx_syscalls.nx"
16
17func 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 }
18func 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 }
19func 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 }
20
21// the dual-conservation verifier: does (v1p,v2p) conserve BOTH momentum and kinetic energy?
22func conserves_both(m1: i64, m2: i64, v1: i64, v2: i64, v1p: i64, v2p: i64) -> i64 {
23 let P0: i64=m1*v1+m2*v2; let K0: i64=m1*v1*v1+m2*v2*v2
24 let P1: i64=m1*v1p+m2*v2p; let K1: i64=m1*v1p*v1p+m2*v2p*v2p
25 if P0!=P1 { return 0 }
26 if K0!=K1 { return 0 }
27 return 1
28}
29// SEARCH the integer velocity lattice [-R..R]^2 for the NON-TRIVIAL outcome conserving both laws.
30func search_elastic(m1: i64, m2: i64, v1: i64, v2: i64, R: i64, out: *i64) -> i64 {
31 var a: i64=0-R
32 while a<=R { var b: i64=0-R
33 while b<=R {
34 if conserves_both(m1,m2,v1,v2,a,b)==1 {
35 var trivial: i64=0
36 if a==v1 { if b==v2 { trivial=1 } }
37 if trivial==0 { out[0]=a; out[1]=b; return 1 }
38 }
39 b=b+1 }
40 a=a+1 }
41 return 0
42}
43// the KNOWN closed-form elastic outcome (for cross-check only -- the search does NOT use it).
44func elastic_formula(m1: i64, m2: i64, v1: i64, v2: i64, out: *i64) -> i64 {
45 let d: i64=m1+m2
46 out[0]=((m1-m2)*v1 + 2*m2*v2)/d
47 out[1]=((m2-m1)*v2 + 2*m1*v1)/d
48 return 0
49}
50func veq2(a: *i64, b: *i64) -> i64 { if a[0]!=b[0] { return 0 } if a[1]!=b[1] { return 0 } return 1 }
51
52func main() -> i64 {
53 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0
54 g_w("=== NX-RESEARCH-DISCOVER-PHYS GATE (DISCOVERY: search the conservation laws -> elastic outcome, verified) ===\n")
55
56 let R: i64=12
57 // case 1: equal masses, v=(5,0) -> swap (0,5)
58 let o1: *i64=sys_mmap(16) as *i64; let f1: i64=search_elastic(1,1,5,0,R,o1)
59 let g1: *i64=sys_mmap(16) as *i64; elastic_formula(1,1,5,0,g1)
60 // case 2: unequal m=(1,3), v=(4,0) -> (-2,2)
61 let o2: *i64=sys_mmap(16) as *i64; let f2: i64=search_elastic(1,3,4,0,R,o2)
62 let g2: *i64=sys_mmap(16) as *i64; elastic_formula(1,3,4,0,g2)
63 // case 3: mirror m=(3,1), v=(0,4) -> (2,-2)
64 let o3: *i64=sys_mmap(16) as *i64; let f3: i64=search_elastic(3,1,0,4,R,o3)
65 let g3: *i64=sys_mmap(16) as *i64; elastic_formula(3,1,0,4,g3)
66
67 // independent conservation recheck of each discovered outcome
68 let c1: i64=conserves_both(1,1,5,0,o1[0],o1[1])
69 let c2: i64=conserves_both(1,3,4,0,o2[0],o2[1])
70 let c3: i64=conserves_both(3,1,0,4,o3[0],o3[1])
71 // discovered == closed form
72 let mok: i64 = veq2(o1,g1)*veq2(o2,g2)*veq2(o3,g3)
73 // LIAR-KILL: perfectly inelastic (stick) for case 2: v = P/(m1+m2) = 4/4 = 1 for both
74 let inel_bad: i64 = (conserves_both(1,3,4,0,1,1)==0) as i64
75 // and the trivial no-collision is NOT what we report (search returned the real exchange)
76 var nontriv: i64=0
77 if o1[0]!=5 { nontriv=1 } // case1 input v1=5; discovered v1'=0 != 5
78
79 g_w(" case1 m(1,1) v(5,0) -> discovered ("); g_n(o1[0]); g_w(","); g_n(o1[1]); g_w(") formula ("); g_n(g1[0]); g_w(","); g_n(g1[1]); g_w(")\n")
80 g_w(" case2 m(1,3) v(4,0) -> discovered ("); g_n(o2[0]); g_w(","); g_n(o2[1]); g_w(") formula ("); g_n(g2[0]); g_w(","); g_n(g2[1]); g_w(")\n")
81 g_w(" case3 m(3,1) v(0,4) -> discovered ("); g_n(o3[0]); g_w(","); g_n(o3[1]); g_w(") formula ("); g_n(g3[0]); g_w(","); g_n(g3[1]); g_w(")\n")
82 g_w(" conservation(all 3)="); g_n(c1*c2*c3); g_w(" matches-formula="); g_n(mok); g_w(" inelastic-rejected="); g_n(inel_bad); g_w("\n")
83
84 var d1: i64=0; if f1==1 { if o1[0]==0 { if o1[1]==5 { d1=1 } } }
85 g_row("DISCOVERY case1: search finds the equal-mass elastic swap (5,0)->(0,5) from the laws alone" as *u8, d1, pass)
86 var d2: i64=0; if f2==1 { if o2[0]==(0-2) { if o2[1]==2 { d2=1 } } }
87 g_row("DISCOVERY case2: search finds the unequal-mass outcome (1,3;4,0)->(-2,2)" as *u8, d2, pass)
88 var d3: i64=0; if f3==1 { if o3[0]==2 { if o3[1]==(0-2) { d3=1 } } }
89 g_row("DISCOVERY case3: search finds the mirror outcome (3,1;0,4)->(2,-2)" as *u8, d3, pass)
90 var cons: i64=0; if c1==1 { if c2==1 { if c3==1 { cons=1 } } }
91 g_row("CONSERVATION: independent verifier confirms momentum AND kinetic energy for all 3 discovered" as *u8, cons, pass)
92 var matchnt: i64=0; if mok==1 { if nontriv==1 { matchnt=1 } }
93 g_row("MATCHES-FORMULA + NON-TRIVIAL: discovered == closed-form elastic outcome, not the no-collision root" as *u8, matchnt, pass)
94 g_row("LIAR-KILL: the inelastic (stick) outcome conserves momentum but VIOLATES KE -> REJECTED" as *u8, inel_bad, pass)
95
96 g_w("RESEARCH-DISCOVER-PHYS-GATE rows=6 pass="); g_n(pass[0])
97 if pass[0]==6 { g_w(" verdict=GREEN\n"); sys_exit(0); return 0 }
98 g_w(" verdict=RED\n"); sys_exit(1); return 1
99}