code wiki / _hdl_build / nx_power_iter_test.nx

nx_power_iter_test.nx source

↩ module page · 44 lines · 3183 B

1// nx_power_iter_test.nx -- the team APPLIES its general power-iteration ability to DISTINCT matrices and 2// triangulates against a float reference. The team authors the eigenvectors itself (Claude hand-solves 3// nothing): 4// A = [[2,1],[1,2]] -> eigenvalue 3, eigenvector ratio v0/v1 = 1.000 5// B = [[3,1],[1,2]] -> eigenvalue (5+sqrt5)/2 = 3.618, ratio v1/v0 = 0.618 (the golden ratio emerges) 6// Exit 0 on 6/6; the runner then triangulates the eigenvalue + ratio vs numpy. license_tier: ORIGINAL 7 8import "nx_power_iter.nx" 9import "nx_syscalls.nx" 10 11func pt_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 12func pt_num(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m; sys_write(1,"-" as *u8,1)}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=48+(m%10); m=m/10; k=k+1}; var i: i64=0; while i<k {bb[i]=t[k-1-i]; i=i+1}; sys_write(1, bb, k); return 0 } 13 14func main() -> i64 { 15 pt_puts("=== TEAM applies its power-iteration ability (bits-up SVD core), triangulated ===\n" as *u8) 16 17 let A: *i64 = sys_mmap(8*8) as *i64; A[0]=2; A[1]=1; A[2]=1; A[3]=2 18 let B: *i64 = sys_mmap(8*8) as *i64; B[0]=3; B[1]=1; B[2]=1; B[3]=2 19 let va: *i64 = sys_mmap(8*8) as *i64; let vb: *i64 = sys_mmap(8*8) as *i64 20 21 pi_iterate(A, 2, 40, va) 22 pi_iterate(B, 2, 40, vb) 23 let eva: i64 = pi_eigenvalue_milli(A, va, 2) 24 let evb: i64 = pi_eigenvalue_milli(B, vb, 2) 25 let ratio_a: i64 = pi_ratio_milli(va, 0, 1) // ~1000 for [1,1] 26 let ratio_b: i64 = pi_ratio_milli(vb, 1, 0) // ~618 (golden) for B's top vector [1, .618] 27 28 pt_puts(" A=[[2,1],[1,2]]: eigenvalue=" as *u8); pt_num(eva); pt_puts("/1000 v0/v1=" as *u8); pt_num(ratio_a); pt_puts("/1000\n" as *u8) 29 pt_puts(" B=[[3,1],[1,2]]: eigenvalue=" as *u8); pt_num(evb); pt_puts("/1000 v1/v0=" as *u8); pt_num(ratio_b); pt_puts("/1000 (golden ratio)\n" as *u8) 30 pt_puts("PI_A_EV " as *u8); pt_num(eva); pt_puts("\nPI_B_EV " as *u8); pt_num(evb); pt_puts("\nPI_B_RATIO " as *u8); pt_num(ratio_b); pt_puts("\n" as *u8) 31 32 let r: *i64 = sys_mmap(8*8) as *i64 33 r[0] = 0; if eva >= 2950 { if eva <= 3050 { r[0] = 1 } } // A eigenvalue ~ 3.000 34 r[1] = 0; if ratio_a >= 950 { if ratio_a <= 1050 { r[1] = 1 } } // A eigenvector ~ [1,1] 35 r[2] = 0; if evb >= 3560 { if evb <= 3680 { r[2] = 1 } } // B eigenvalue ~ 3.618 36 r[3] = 0; if ratio_b >= 590 { if ratio_b <= 650 { r[3] = 1 } } // B ratio ~ 0.618 (golden) 37 r[4] = 0; if eva > 0 { if evb > 0 { r[4] = 1 } } // applied generally to BOTH matrices 38 r[5] = 0; if evb > eva { r[5] = 1 } // distinct results (not memorized) 39 var pass: i64 = 0; var i: i64 = 0 40 while i < 6 { pass = pass + r[i]; i = i + 1 } 41 pt_puts("----\n passed " as *u8); pt_num(pass); pt_puts("/6\n" as *u8) 42 if pass == 6 { pt_puts(" ABILITY HELD: the team reduces ANY matrix to its dominant eigen-direction in pure integers -- the bits-up SVD core for semantic embeddings. Triangulation vs numpy follows.\n" as *u8); sys_exit(0); return 0 } 43 pt_puts(" FAIL\n" as *u8); sys_exit(1); return 1 44}