code wiki / _hdl_build / nx_ncf_quad_gate.nx

nx_ncf_quad_gate.nx source

↩ module page · 61 lines · 4491 B

1// nx_ncf_quad_gate.nx -- X-AUT-NCF-001 RUNG 3: SYNTHESIZE AN AFFINE-INDEX LOOP (acc += c1*i + c0), the 2// construct that covers x^2 and the quadratic/arithmetic-series family -- exactly the case rung 2's wiring 3// honestly REFUSED (T4 boundary). Escalation: rung 2 simple loop (acc+c/acc*c/acc+i/acc*i) PROVABLY FAILS on 4// x^2; the affine-index loop SUCCEEDS. Uses the shared lib nx_ncf_synth (the DRY core), so landing this rung 5// AUTO-WIDENS the wiring (nx_ncf_route_gate now routes x^2). Construct ladder: linear < conditional < 6// simple-loop < AFFINE-INDEX-LOOP, each with its own proving negative control. 7// T1 linear FAILS on x^2. T2 simple-loop (rung 2) FAILS on x^2 -> the new construct is necessary. 8// T3 affine-index loop SYNTHESIZES x^2 = acc=0; for i { acc += 2i-1 }. 9// T4 MATERIALIZE+GOD-BUILD+run HELD-OUT {5->25, 6->36} -> 25036. T5 unified ncf_synth routes x^2 (kind=3). 10// expect_exit: 0 license_tier: ORIGINAL 11import "nx_ncf_synth.nx" 12import "nx_syscalls.nx" 13 14func main() -> i64 { 15 ncf_w("=== nx_ncf_quad: SYNTHESIZE AN AFFINE-INDEX LOOP (X-AUT-NCF-001 rung 3) -- covers x^2, rung-2 cannot ===\n" as *u8) 16 var pass: i64=0; var total: i64=0 17 18 // SPEC = x^2: examples {0..4}, HELD-OUT {5->25, 6->36}. 19 let xs: *i64=sys_mmap(64) as *i64; let ys: *i64=sys_mmap(64) as *i64 20 xs[0]=0; xs[1]=1; xs[2]=2; xs[3]=3; xs[4]=4 21 ys[0]=0; ys[1]=1; ys[2]=4; ys[3]=9; ys[4]=16 22 let n: i64=5 23 24 let sp: *i64=sys_mmap(8) as *i64; sp[0]=0-1 25 let sfd: i64=sys_openat_wr(NCF_RESULT,420); if sfd>=0 { sys_write(sfd,sp as *u8,8); sys_close(sfd) } 26 27 // T1: linear FAILS. 28 let lin: i64=ncf_search_linear(xs,ys,n) 29 total=total+1; if lin==0 { pass=pass+1; ncf_w(" [PASS] " as *u8) } else { ncf_w(" [FAIL] " as *u8) } 30 ncf_w("T1 NEG-CONTROL: linear-only FAILS on x^2, lin_found=" as *u8); ncf_n(lin); ncf_w("\n" as *u8) 31 32 // T2: rung-2 SIMPLE loop FAILS (the escalation -- acc+c/acc*c/acc+i/acc*i cannot make x^2). 33 let lform: *i64=sys_mmap(64) as *i64 34 let simple: i64=ncf_search_loop(xs,ys,n,lform) 35 total=total+1; if simple==0 { pass=pass+1; ncf_w(" [PASS] " as *u8) } else { ncf_w(" [FAIL] " as *u8) } 36 ncf_w("T2 NEG-CONTROL: rung-2 SIMPLE loop FAILS on x^2 -> affine-index body NECESSARY, simple_found=" as *u8); ncf_n(simple); ncf_w("\n" as *u8) 37 38 // T3: affine-index loop SYNTHESIZES x^2. 39 let form: *i64=sys_mmap(64) as *i64 40 let q: i64=ncf_search_loop2(xs,ys,n,form) 41 total=total+1; if q==1 { pass=pass+1; ncf_w(" [PASS] " as *u8) } else { ncf_w(" [FAIL] " as *u8) } 42 ncf_w("T3 SYNTHESIS: affine-index loop FOUND acc=" as *u8); ncf_n(form[0]); ncf_w("; for i { acc += " as *u8); ncf_n(form[1]); ncf_w("*i + " as *u8); ncf_n(form[2]); ncf_w(" } for x^2\n" as *u8) 43 44 // T4: MATERIALIZE -> GOD-BUILD -> run HELD-OUT -> verify (x^2(5)=25, x^2(6)=36 -> 25036). 45 var emitted: i64=0; if q==1 { if ncf_emit(3,form,5,6,1000)==0 { emitted=1 } } 46 var built: i64=0; if emitted==1 { if ncf_god_build(NCF_NAME)==0 { built=1 } } 47 let produced: i64=ncf_read(NCF_RESULT) 48 total=total+1; if produced==25036 { pass=pass+1; ncf_w(" [PASS] " as *u8) } else { ncf_w(" [FAIL] " as *u8) } 49 ncf_w("T4 MATERIALIZE+GOD-BUILD: synthesized affine-index loop compiled (nx_cc->nxasm, no gcc) + ran HELD-OUT -> produced=" as *u8); ncf_n(produced); ncf_w(" (expect 25036)\n" as *u8) 50 51 // T5: the UNIFIED ncf_synth now routes x^2 to the affine-index construct (kind=3) = auto-widens the wiring. 52 let uform: *i64=sys_mmap(64) as *i64 53 let kind: i64=ncf_synth(xs,ys,n,uform) 54 total=total+1; if kind==3 { pass=pass+1; ncf_w(" [PASS] " as *u8) } else { ncf_w(" [FAIL] " as *u8) } 55 ncf_w("T5 UNIFIED: ncf_synth(x^2) -> kind=" as *u8); ncf_n(kind); ncf_w(" (3=affine-index loop) = the wiring now auto-routes x^2 (was the old NOVEL->tutor boundary)\n" as *u8) 56 57 ncf_w("\n HONEST SCOPE: covers quadratics/arithmetic-series of the form init + sum(c1*i + c0); x^3 (cubic) + non-polynomial still escalate = the next rungs. Construct ladder: linear < conditional < simple-loop < affine-index-loop.\n" as *u8) 58 ncf_w("NCF-QUAD verdict=" as *u8) 59 if pass==total { ncf_w("GREEN passes=" as *u8); ncf_n(pass); ncf_w("/" as *u8); ncf_n(total); ncf_w(" -- the team SYNTHESIZED + GOD-BUILT an affine-index loop (author-share>0): X-AUT-NCF-001 rung 3\n" as *u8); sys_exit(0); return 0 } 60 ncf_w("RED passes=" as *u8); ncf_n(pass); ncf_w("/" as *u8); ncf_n(total); ncf_w("\n" as *u8); sys_exit(1); return 1 61}