code wiki / _hdl_build / nx_research_discover_matmul_gate.nx
nx_research_discover_matmul_gate.nx
buildroot/runtime/_hdl_build/nx_research_discover_matmul_gate.nx
about
nx_research_discover_matmul_gate.nx -- DISCOVERY widened to the matrix-multiplication family, the direct
AlphaTensor analog (operator: "widen discovery ... search candidate low-mult MATMUL schemes a la AlphaTensor").
A fast matmul = a LOW-RANK BILINEAR TENSOR DECOMPOSITION. For an R-term scheme {(u_r,v_r,w_r)}:
m_r = (u_r . a)(v_r . b) (R scalar multiplications)
c_k = sum_r w_r[k] * m_r (only +/- of the m_r when coeffs are in {-1,0,1})
It computes the bilinear map exactly <=> Brent's equations hold:
for all i,j,k: sum_r u_r[i] v_r[j] w_r[k] == T[i][j][k] (T = the problem's tensor)
R = the multiplication count. Naive 2x2 matmul is rank 8; Strassen is rank 7.
This gate:
SUBSTRATE : a sovereign Brent-equation VERIFIER -- the exact certifier a discovery search rides on.
MATMUL : the verifier certifies naive 2x2 (rank 8) AND Strassen (rank 7) as correct <2,2,2> schemes,
and REJECTS a broken Strassen (liar-kill). Ties the substrate to real matrix multiplication.
DISCOVERY : on a TRACTABLE bilinear problem -- complex multiplication, tensor (a+bi)(c+di) -- an
EXHAUSTIVE {-1,0,1} search DISCOVERS a rank-3 scheme (3 mults < naive 4: the Gauss/Karatsuba
speedup) it was never given, proves it MINIMAL (no rank-2 exists), and the same verifier +
random-input check certify it exact. A broken rank-3 is rejected.
HONEST SCOPE: the SEARCH discovers on the small problem; for <2,2,2> matmul we CERTIFY the known rank-7
via the same verifier -- we do NOT claim a blind AlphaTensor-scale rank-7 search.
Pure integer, no float, deterministic, reproducible. GREEN iff 8/8. license_tier: ORIGINAL
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_library.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
| 25 | 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 } |
| 26 | 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 } |
| 27 | 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 } |
| 30 | func rs_has(buf: *u8, n: i64, needle: *u8) -> i64 called by 1: rs_lib_contains |
| 37 | func rs_lib_contains(needle: *u8) -> i64 |
| 48 | func rs_rng(state: *i64) -> i64 { var x: i64 = state[0]; x = x ^ (x << 13); x = x ^ (x >> 7); x = x ^ (x << 17); state[0] = x; return x } called by 1: verify_cm |
| 49 | func pow3(n: i64) -> i64 { var p: i64=1; var i: i64=0; while i<n { p=p*3; i=i+1 } return p } |
| 51 | func decode_vec(code: i64, len: i64, out: *i64) -> i64 { var c: i64=code; var i: i64=0; while i<len { out[i]=(c%3)-1; c=c/3; i=i+1 } return 0 } |
| 54 | func brent_check(u: *i64, v: *i64, w: *i64, R: i64, na: i64, nb: i64, nc: i64, t: *i64) -> i64 called by 1: main |
| 70 | func solve_wcol(P: *i64, R: i64, tcol: *i64, wout: *i64, wc: *i64) -> i64 |
| 89 | func search222(R: i64, t: *i64, fu: *i64, fv: *i64, fw: *i64, recordFirst: i64) -> i64 |
| 120 | func cm_eval(u: *i64, v: *i64, w: *i64, R: i64, a0: i64, a1: i64, b0: i64, b1: i64, out: *i64) -> i64 called by 1: verify_cm |
| 132 | func verify_cm(u: *i64, v: *i64, w: *i64, R: i64) -> i64 |
| 149 | func build_t_complex(t: *i64) -> i64 { var z: i64=0; while z<8 { t[z]=0; z=z+1 } t[(0*2+0)*2+0]=1; t[(1*2+1)*2+0]=-1; t[(0*2+1)*2+1]=1; t[(1*2+0)*2+1]=1; return 0 } called by 1: main |
| 150 | func build_naive_complex(u: *i64, v: *i64, w: *i64) -> i64 called by 1: main |
| 158 | func build_t222(t: *i64) -> i64 called by 1: main |
| 169 | func build_naive222(u: *i64, v: *i64, w: *i64) -> i64 called by 1: main |
| 179 | func set4(arr: *i64, row: i64, a: i64, b: i64, c: i64, d: i64) -> i64 { arr[row*4+0]=a; arr[row*4+1]=b; arr[row*4+2]=c; arr[row*4+3]=d; return 0 } called by 1: build_strassen |
| 181 | func build_strassen(u: *i64, v: *i64, w: *i64) -> i64 |
| 188 | func main() -> i64 |