code wiki / _hdl_build / nx_research_discover_chem_gate.nx
nx_research_discover_chem_gate.nx
buildroot/runtime/_hdl_build/nx_research_discover_chem_gate.nx
about
nx_research_discover_chem_gate.nx -- DISCOVERY in CHEMISTRY (operator: "discover new capabilities through
different math/chem/physics via simulations"). The chem reproduction gate (nx_research_chem_gate) replays
KNOWN molar masses. This gate DISCOVERS something it was never given: the stoichiometric coefficients that
BALANCE a chemical reaction.
A balanced reaction conserves every element: with reactants counted + and products counted -, the integer
coefficient vector x must satisfy A x = 0 for the element-count matrix A (rows=elements, cols=species).
That is an integer-nullspace problem. The TESTING-TEAM SEARCHES the small positive-integer lattice for the
fundamental solution, reduces it to the smallest whole-number ratio (gcd=1), and the VERIFIER independently
rechecks atom conservation per element. Liar-kill: the naive all-ones guess (and any unbalanced vector) is
REJECTED -- conservation can't be rubber-stamped. Discovered coefficients are compared to the textbook
canonical for three classic reactions. Pure integer, deterministic, reproducible. 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
| 16 | 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 } |
| 17 | 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 } |
| 18 | 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 } |
| 20 | func gcd(a: i64, b: i64) -> i64 { var x: i64=a; var y: i64=b; if x<0{x=0-x} if y<0{y=0-y} while y!=0 { let t: i64=x%y; x=y; y=t } return x } |
| 22 | func balanced_ok(A: *i64, E: i64, S: i64, x: *i64) -> i64 |
| 27 | func veq(a: *i64, b: *i64, n: i64) -> i64 { var i: i64=0; while i<n { if a[i]!=b[i] { return 0 } i=i+1 } return 1 } called by 1: main |
| 31 | func balance(A: *i64, E: i64, S: i64, B: i64, xout: *i64) -> i64 |
| 47 | func gcd_vec(x: *i64, n: i64) -> i64 { var g: i64=x[0]; var i: i64=1; while i<n { g=gcd(g,x[i]); i=i+1 } return g } |
| 49 | func main() -> i64 |