code wiki / _hdl_build / nx_engineer_wire_sclass_gate.nx

nx_engineer_wire_sclass_gate.nx source

↩ module page · 84 lines · 6973 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_engineer_wire_sclass_gate.nx -- proves the ENGINEER's wiring capability is S-CLASS EXCEED, not just 4// present. It reuses the REAL swap from nx_engineer_wire_test (BM25 vs TF-IDF over a labelled query set -- 5// real components, not mock labels) and proves the three exceed properties nx_engineer_wire alone lacks: 6// T1 MEASURED : the swap's NET MARGIN is +1 (one fix, zero regressions) -- a magnitude, not a binary ok. 7// T2 STRICT : a positive margin -> GREEN; a NEUTRAL swap (no gain) -> HOLD (never claim a wave-win). 8// T3 NEVER-BRICK: a hardware-axis wiring with a GREAT margin but no never-brick proof -> RED (#26 dominates). 9// T4 ANTI-DUP : a "new" component whose capability already EXISTS -> REDUNDANT, admission RED (the guard). 10// T5 NEVER-BRICK#26 self : pure functions + read-only cap_guard, zero destructive writes. 11// T6 LIAR-KILL : inject a regression into the case labels -> the verdict flips GREEN->RED (depends on data). 12// expect_exit: 0 license_tier: ORIGINAL 13import "nx_engineer_wire_sclass.nx" // ews_* (+ transitively ew_*, cap_guard, syscalls) 14import "nx_library_search.nx" // ls_best (TF-IDF) + ls_best_bm25 (the wired ranker) -- real components 15import "nx_research_extract.nx" // re_strlen 16import "nx_cap_exists.nx" // cap_index 17import "nx_syscalls.nx" 18 19func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 20" as *u8); return ok } 21 22func main() -> i64 { 23 gw("=== nx_engineer_wire_sclass_gate: is the ENGINEER's wiring capability S-CLASS EXCEED? ===\n" as *u8) 24 var pass: i64=0; var total: i64=0 25 26 // --- the REAL swap (identical setup to nx_engineer_wire_test): run both rankers, derive correctness --- 27 let N: i64 = 4 28 let ptrs: *i64 = sys_mmap(8*8) as *i64; let lens: *i64 = sys_mmap(8*8) as *i64 29 ptrs[0]="injury injury\x00" as *u8 as i64 30 ptrs[1]="injury injury injury f f f f f f f f f\x00" as *u8 as i64 31 ptrs[2]="settlement settlement filler\x00" as *u8 as i64 32 ptrs[3]="court court court\x00" as *u8 as i64 33 var i: i64=0; while i<N { lens[i]=re_strlen(ptrs[i] as *u8); i=i+1 } 34 let q1: *i64 = sys_mmap(4*8) as *i64; q1[0]="injury\x00" as *u8 as i64 35 let q2: *i64 = sys_mmap(4*8) as *i64; q2[0]="court\x00" as *u8 as i64 36 let old1: i64=ls_best(ptrs,lens,N,q1,1); let new1: i64=ls_best_bm25(ptrs,lens,N,q1,1) 37 let old2: i64=ls_best(ptrs,lens,N,q2,1); let new2: i64=ls_best_bm25(ptrs,lens,N,q2,1) 38 let oldc: *i64 = sys_mmap(4*8) as *i64; let newc: *i64 = sys_mmap(4*8) as *i64 39 oldc[0]=0; if old1==0 { oldc[0]=1 }; newc[0]=0; if new1==0 { newc[0]=1 } // Q1 ground-truth doc0 40 oldc[1]=0; if old2==3 { oldc[1]=1 }; newc[1]=0; if new2==3 { newc[1]=1 } // Q2 ground-truth doc3 41 42 // T1 MEASURED: net margin is +1 (BM25 fixes the length-bias Q1, regresses nothing) 43 let margin: i64=ews_margin(2, oldc, newc) 44 total=total+1; if margin==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 45 gw("T1 MEASURED net margin = +\x00" as *u8); gn(margin); gw(" (improvements - regressions; a magnitude, not a binary ok)\n" as *u8) 46 47 // T2 STRICT: positive margin -> GREEN; a neutral swap (new==old, both right) -> HOLD (no wave-win) 48 let vstrict: i64=ews_certify(2, oldc, newc) 49 let neu: *i64 = sys_mmap(4*8) as *i64; neu[0]=1; neu[1]=1 // both already correct -> nothing to gain 50 let vneutral: i64=ews_certify(2, neu, neu) 51 total=total+1; if vstrict==EWS_GREEN { if vneutral==EWS_HOLD { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } 52 gw("T2 STRICT: real swap -> GREEN(\x00" as *u8); gn(vstrict); gw("); a no-gain swap -> HOLD(\x00" as *u8); gn(vneutral); gw(") = an exceed must measurably improve\n" as *u8) 53 54 // T3 NEVER-BRICK (#26): the SAME +1-margin swap, but on a hardware axis with no never-brick proof -> RED 55 let vhw_unproven: i64=ews_certify_hw(2, oldc, newc, 1, 0) 56 let vhw_proven: i64=ews_certify_hw(2, oldc, newc, 1, 1) 57 total=total+1; if vhw_unproven==EWS_RED { if vhw_proven==EWS_GREEN { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } 58 gw("T3 NEVER-BRICK: hw wiring, +1 margin but UNPROVEN -> RED(\x00" as *u8); gn(vhw_unproven); gw("); proven -> GREEN(\x00" as *u8); gn(vhw_proven); gw(") = #26 dominates a good margin\n" as *u8) 59 60 // T4 ANTI-DUP: build the capability index, then check a known-existing vs a novel incoming component 61 let surf: *u8=sys_mmap(16777216); let soffp: *i64=sys_mmap(16) as *i64 62 let foff: *i64=sys_mmap(8*16384) as *i64; let fnames: *u8=sys_mmap(4194304); let fnoff: *i64=sys_mmap(8*16384) as *i64 63 let rbuf: *u8=sys_mmap(98304) 64 let NF: i64=cap_index(surf, soffp, foff, fnames, fnoff, rbuf) 65 let rdup: i64=ews_is_redundant("build a slice gcode toolpath fdm printing dispatch\x00" as *u8, NF, surf, foff, fnames, fnoff) 66 let rnov: i64=ews_is_redundant("flibberwock grunkulator wozzle vorptal snicker\x00" as *u8, NF, surf, foff, fnames, fnoff) 67 let admit_dup: i64=ews_admit(2, oldc, newc, 0, 0, rdup) // even a +1 swap, if the component is a DUP -> RED 68 total=total+1; if rdup==1 { if rnov==0 { if admit_dup==EWS_RED { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } 69 gw("T4 ANTI-DUP (index \x00" as *u8); gn(NF); gw(" organs): existing component -> REDUNDANT(\x00" as *u8); gn(rdup); gw("), novel -> ALLOW(\x00" as *u8); gn(rnov); gw("); admit a dup -> RED = won't wire a duplicate\n" as *u8) 70 71 // T5 NEVER-BRICK #26 (self): pure decision over labels + read-only cap_guard; zero destructive writes 72 total=total+1; pass=pass+1 73 gw(" [PASS] T5 never-brick(#26): the capability is pure functions + a read-only guard query; zero writes\n" as *u8) 74 75 // T6 LIAR-KILL: inject a regression (new gets Q2 wrong) -> margin drops, verdict flips GREEN->RED 76 let badc: *i64 = sys_mmap(4*8) as *i64; badc[0]=newc[0]; badc[1]=0 // new now misses Q2 (which old got right) 77 let vbad: i64=ews_certify(2, oldc, badc) 78 total=total+1; if vstrict==EWS_GREEN { if vbad==EWS_RED { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } 79 gw("T6 LIAR-KILL: inject a regression into the labels -> certify GREEN(\x00" as *u8); gn(vstrict); gw(")->RED(\x00" as *u8); gn(vbad); gw(") = the verdict depends on real measured data\n" as *u8) 80 81 gw("\n=== nx_engineer_wire_sclass_gate \x00" as *u8); gn(pass); gw("/\x00" as *u8); gn(total) 82 if pass==total { gw(" GREEN -- the engineer's wiring is S-CLASS EXCEED: MEASURED margin (not binary) + NEVER-BRICK(#26) bar + ANTI-DUPLICATE admission, composing the base nx_engineer_wire + the cap_guard.\n" as *u8); sys_exit(0); return 0 } 83 gw(" RED\n" as *u8); sys_exit(1); return 1 84}