code wiki / _hdl_build / nx_ncf_cube_gate.nx
nx_ncf_cube_gate.nx source
↩ module page · 60 lines · 4557 B
1// nx_ncf_cube_gate.nx -- X-AUT-NCF-001 RUNG 4: SYNTHESIZE A QUADRATIC-INDEX LOOP (acc += c2*i*i + c1*i + c0),
2// covering x^3 and the cubic family -- exactly the case rung 3 (affine-index) honestly REFUSED. Escalation:
3// the rung-3 affine-index loop PROVABLY FAILS on x^3 (its sum is quadratic-in-x); the quadratic-index loop
4// SUCCEEDS (x^3 = sum(3i^2 - 3i + 1)). Uses the shared lib nx_ncf_synth, so the WIRING auto-widens (x^3 now
5// routes). Construct ladder: linear < conditional < simple-loop < affine-index-loop < QUADRATIC-INDEX-LOOP.
6// T1 linear FAILS. T2 affine-index loop (rung 3) FAILS on x^3 -> the quadratic-index body is necessary.
7// T3 quadratic-index loop SYNTHESIZES x^3 = acc=0; for i { acc += 3i^2 - 3i + 1 }.
8// T4 MATERIALIZE+GOD-BUILD+run HELD-OUT {5->125, 6->216} -> 125216. T5 unified ncf_synth routes x^3 (kind=4).
9// expect_exit: 0 license_tier: ORIGINAL
10import "nx_ncf_synth.nx"
11import "nx_syscalls.nx"
12
13func main() -> i64 {
14 ncf_w("=== nx_ncf_cube: SYNTHESIZE A QUADRATIC-INDEX LOOP (X-AUT-NCF-001 rung 4) -- covers x^3, rung-3 cannot ===\n" as *u8)
15 var pass: i64=0; var total: i64=0
16
17 // SPEC = x^3: examples {0..4}, HELD-OUT {5->125, 6->216}.
18 let xs: *i64=sys_mmap(64) as *i64; let ys: *i64=sys_mmap(64) as *i64
19 xs[0]=0; xs[1]=1; xs[2]=2; xs[3]=3; xs[4]=4
20 ys[0]=0; ys[1]=1; ys[2]=8; ys[3]=27; ys[4]=64
21 let n: i64=5
22
23 let sp: *i64=sys_mmap(8) as *i64; sp[0]=0-1
24 let sfd: i64=sys_openat_wr(NCF_RESULT,420); if sfd>=0 { sys_write(sfd,sp as *u8,8); sys_close(sfd) }
25
26 // T1: linear FAILS.
27 let lin: i64=ncf_search_linear(xs,ys,n)
28 total=total+1; if lin==0 { pass=pass+1; ncf_w(" [PASS] " as *u8) } else { ncf_w(" [FAIL] " as *u8) }
29 ncf_w("T1 NEG-CONTROL: linear-only FAILS on x^3, lin_found=" as *u8); ncf_n(lin); ncf_w("\n" as *u8)
30
31 // T2: rung-3 AFFINE-INDEX loop FAILS (the escalation -- affine-index sum is quadratic-in-x, x^3 is cubic).
32 let aform: *i64=sys_mmap(64) as *i64
33 let affine: i64=ncf_search_loop2(xs,ys,n,aform)
34 total=total+1; if affine==0 { pass=pass+1; ncf_w(" [PASS] " as *u8) } else { ncf_w(" [FAIL] " as *u8) }
35 ncf_w("T2 NEG-CONTROL: rung-3 AFFINE-INDEX loop FAILS on x^3 -> quadratic-index body NECESSARY, affine_found=" as *u8); ncf_n(affine); ncf_w("\n" as *u8)
36
37 // T3: quadratic-index loop SYNTHESIZES x^3.
38 let form: *i64=sys_mmap(64) as *i64
39 let q: i64=ncf_search_loop3(xs,ys,n,form)
40 total=total+1; if q==1 { pass=pass+1; ncf_w(" [PASS] " as *u8) } else { ncf_w(" [FAIL] " as *u8) }
41 ncf_w("T3 SYNTHESIS: quadratic-index loop FOUND acc=" as *u8); ncf_n(form[0]); ncf_w("; for i { acc += " as *u8); ncf_n(form[1]); ncf_w("*i*i + " as *u8); ncf_n(form[2]); ncf_w("*i + " as *u8); ncf_n(form[3]); ncf_w(" } for x^3\n" as *u8)
42
43 // T4: MATERIALIZE -> GOD-BUILD -> run HELD-OUT -> verify (x^3(5)=125, x^3(6)=216 -> 125216).
44 var emitted: i64=0; if q==1 { if ncf_emit(4,form,5,6,1000)==0 { emitted=1 } }
45 var built: i64=0; if emitted==1 { if ncf_god_build(NCF_NAME)==0 { built=1 } }
46 let produced: i64=ncf_read(NCF_RESULT)
47 total=total+1; if produced==125216 { pass=pass+1; ncf_w(" [PASS] " as *u8) } else { ncf_w(" [FAIL] " as *u8) }
48 ncf_w("T4 MATERIALIZE+GOD-BUILD: synthesized quadratic-index loop compiled (nx_cc->nxasm, no gcc) + ran HELD-OUT -> produced=" as *u8); ncf_n(produced); ncf_w(" (expect 125216)\n" as *u8)
49
50 // T5: the UNIFIED ncf_synth now routes x^3 to the quadratic-index construct (kind=4) = auto-widens the wiring.
51 let uform: *i64=sys_mmap(64) as *i64
52 let kind: i64=ncf_synth(xs,ys,n,uform)
53 total=total+1; if kind==4 { pass=pass+1; ncf_w(" [PASS] " as *u8) } else { ncf_w(" [FAIL] " as *u8) }
54 ncf_w("T5 UNIFIED: ncf_synth(x^3) -> kind=" as *u8); ncf_n(kind); ncf_w(" (4=quadratic-index loop) = the wiring now auto-routes x^3 (was the old NOVEL->tutor boundary)\n" as *u8)
55
56 ncf_w("\n HONEST SCOPE: covers cubics of the form init + sum(c2*i*i + c1*i + c0); x^4 (quartic) + non-polynomial (Fibonacci, needs two-state) still escalate = the next rungs. Ladder: linear < conditional < simple-loop < affine-index < quadratic-index.\n" as *u8)
57 ncf_w("NCF-CUBE verdict=" as *u8)
58 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 a quadratic-index loop (author-share>0): X-AUT-NCF-001 rung 4\n" as *u8); sys_exit(0); return 0 }
59 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
60}