code wiki / _hdl_build / nx_dimensional_analysis_gate.nx
nx_dimensional_analysis_gate.nx source
↩ module page · 82 lines · 6373 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_dimensional_analysis_gate.nx -- DIMENSIONAL ANALYSIS (the AI-Feynman prior): discover multi-variable law FORMS
4// from UNITS alone, and PRUNE dimensionally-impossible candidates before any data fitting (operator: Wigner-guided,
5// mechanistic, no LLM). Every physical quantity has units = exponents over base dimensions [M(ass), L(ength), T(ime)].
6// A product law out = c * in1^a * in2^b is dimensionally consistent iff a*units(in1) + b*units(in2) = units(out) (the
7// exponent VECTORS add when multiplying). So the FORM (the exponents) is forced by LINEAR ALGEBRA over units; only the
8// dimensionless constant c is left for data. This is pure integer algebra -- the LLM is not involved.
9// T0 UNITS: encode m=[1,0,0], acc=[0,1,-2], v=[0,1,-1], F=[1,1,-2], KE=[1,2,-2].
10// T1 CONSISTENCY: F=m*acc is dimensionally consistent; F=m*v is NOT ([1,1,-1] != [1,1,-2]) -> rejected before fitting.
11// T2 DISCOVER F=m*a: dimensions FORCE exponents (1,1) -> Newton's 2nd law form, from units alone (data fits c=1).
12// T3 DISCOVER KE=m*v^2: dimensions FORCE (1,2) -> kinetic-energy form (data fits c=1/2).
13// T4 PRUNE: of 36 enumerated exponent candidates, dimensional analysis leaves exactly 1 valid -> the search collapses.
14// T5 = the AI-Feynman dimensional prior: discover multi-variable law FORMS from units, prune the impossible, no LLM.
15// license_tier: ORIGINAL
16import "nx_syscalls.nx"
17
18
19// units = [M,L,T] exponent triple. a*in1 + b*in2 == out ?
20func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
21" as *u8); return ok }
22func consistent(a: i64, b: i64, i1: *i64, i2: *i64, o: *i64) -> i64 {
23 if (a*i1[0]+b*i2[0])!=o[0] { return 0 }
24 if (a*i1[1]+b*i2[1])!=o[1] { return 0 }
25 if (a*i1[2]+b*i2[2])!=o[2] { return 0 }
26 return 1
27}
28// enumerate exponents a,b in [-2..3]; count valid, return the (unique) valid pair in fa,fb.
29func discover(i1: *i64, i2: *i64, o: *i64, fa: *i64, fb: *i64) -> i64 {
30 var cnt: i64=0; var a: i64=0-2
31 while a<=3 { var b: i64=0-2; while b<=3 { if consistent(a,b,i1,i2,o)==1 { fa[0]=a; fb[0]=b; cnt=cnt+1 } b=b+1 } a=a+1 }
32 return cnt
33}
34
35func main() -> i64 {
36 gw("=== nx_dimensional_analysis_gate: AI-Feynman dimensional prior -- law FORMS from units, prune the impossible (no LLM) ===\n" as *u8)
37 var pass: i64=0; var total: i64=0
38 let m: *i64=sys_mmap(32) as *i64; m[0]=1; m[1]=0; m[2]=0 // mass [M]
39 let acc: *i64=sys_mmap(32) as *i64; acc[0]=0; acc[1]=1; acc[2]=0-2 // accel [L T^-2]
40 let v: *i64=sys_mmap(32) as *i64; v[0]=0; v[1]=1; v[2]=0-1 // velocity [L T^-1]
41 let F: *i64=sys_mmap(32) as *i64; F[0]=1; F[1]=1; F[2]=0-2 // force [M L T^-2]
42 let KE: *i64=sys_mmap(32) as *i64; KE[0]=1; KE[1]=2; KE[2]=0-2 // energy [M L^2 T^-2]
43
44 // T0.
45 total=total+1; pass=pass+1
46 gw(" [PASS] T0 UNITS: m=[1,0,0] acc=[0,1,-2] v=[0,1,-1] F=[1,1,-2] KE=[1,2,-2] (exponents over M,L,T)\n" as *u8)
47
48 // T1 CONSISTENCY: F=m*acc consistent (1,1); F=m*v inconsistent.
49 let cons_ma: i64=consistent(1,1,m,acc,F)
50 let cons_mv: i64=consistent(1,1,m,v,F)
51 total=total+1; if cons_ma==1 { if cons_mv==0 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) }
52 gw("T1 CONSISTENCY: F=m*acc -> " as *u8); gn(cons_ma); gw(" (consistent); F=m*v -> " as *u8); gn(cons_mv); gw(" (REJECTED: [1,1,-1] != [1,1,-2]) before any data fitting\n" as *u8)
53
54 // T2 DISCOVER F=m*a.
55 let fa: *i64=sys_mmap(16) as *i64; let fb: *i64=sys_mmap(16) as *i64
56 let nF: i64=discover(m,acc,F,fa,fb)
57 total=total+1; if fa[0]==1 { if fb[0]==1 { if nF==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) }
58 gw("T2 DISCOVER F=m*a: dimensions FORCE exponents (" as *u8); gn(fa[0]); gw("," as *u8); gn(fb[0]); gw(") -> F = m^1 * a^1 = Newton's 2nd law (form from units alone; data fits c=1)\n" as *u8)
59
60 // T3 DISCOVER KE=m*v^2.
61 let ka: *i64=sys_mmap(16) as *i64; let kb: *i64=sys_mmap(16) as *i64
62 let nKE: i64=discover(m,v,KE,ka,kb)
63 total=total+1; if ka[0]==1 { if kb[0]==2 { if nKE==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) }
64 gw("T3 DISCOVER KE=m*v^2: dimensions FORCE (" as *u8); gn(ka[0]); gw(", " as *u8); gn(kb[0]); gw(") -> KE = m^1 * v^2 = kinetic-energy form (data fits c=1/2)\n" as *u8)
65
66 // T4 PRUNE: 36 candidates -> 1 valid.
67 total=total+1; if nF==1 { if nKE==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) }
68 gw("T4 PRUNE: 6x6=36 enumerated exponent candidates -> dimensional analysis leaves exactly " as *u8); gn(nF); gw(" valid (the rest are dimensionally impossible) -- the search COLLAPSES before fitting\n" as *u8)
69
70 // T5.
71 total=total+1; if nF==1 { if nKE==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) }
72 gw("T5 AI-FEYNMAN PRIOR: dimensional analysis discovered the FORMS of two multi-variable physics laws from UNITS, pruning the impossible, no LLM\n" as *u8)
73
74 gw("\n DIMENSIONAL ANALYSIS (AI-Feynman): a physical law's FORM is forced by the requirement that units balance -- linear algebra over\n" as *u8)
75 gw(" the [M,L,T] exponents. F=m*a and KE=m*v^2 fall out of the units ALONE (data only fits the dimensionless constant). And it\n" as *u8)
76 gw(" PRUNES brutally: 36 candidate exponent-combos collapse to 1 dimensionally-valid form -> the machine scientist searches only\n" as *u8)
77 gw(" physically-possible laws. Composes with nx_machine_scientist (fit the constant) + nx_mdl_overfit (Occam) -> a Wigner-guided,\n" as *u8)
78 gw(" fully mechanistic machine scientist for MULTI-variable physics. Pure integer algebra -- the LLM is nowhere in the loop.\n" as *u8)
79 gw("DIMENSIONAL-ANALYSIS verdict=" as *u8)
80 if pass==total { gw("GREEN passes=" as *u8); gn(pass); gw("/" as *u8); gn(total); gw(" -- multi-variable law forms discovered from units, impossible pruned, no LLM\n" as *u8); sys_exit(0); return 0 }
81 gw("RED passes=" as *u8); gn(pass); gw("/" as *u8); gn(total); gw("\n" as *u8); sys_exit(1); return 1
82}