code wiki / _hdl_build / nx_superopt_test.nx
nx_superopt_test.nx
buildroot/runtime/_hdl_build/nx_superopt_test.nx
about
nx_superopt_test.nx -- GATE + proof for the mechanized superoptimizer organ
(nx_superopt.nx, the AUTHOR leg of the Sovereign Invention Engine). Proves, with
NO LLM in the loop, one full PROPOSE/SCORE/VERIFY/EMIT invention tick on the
smallest end-to-end-provable example:
SEED (mul x 8) --> EMIT (shl x 3).
It self-asserts a known answer + sys_exit(0), establishing:
(1) the loop FOUND a cheaper equivalent of the seed (cand_count==3, root=SHL,
shift=3) -- PROPOSE via nx_eqsat saturation, EMIT via the extractor.
(2) the cheaper form is TRIANGULATED-EQUIVALENT to the seed over a
dense(exhaustive small-width) + random + edge battery via THREE genuinely
independent legs -- AND we prove the check would CATCH a non-equivalent
candidate (the (shl x 2) negative control is REJECTED by the same battery).
(3) the cost STRICTLY decreased on the honest metric, twice independently:
Tier-1 e-graph op-cost 3 -> 1, AND Tier-2 honest gate-level latency at
W=64: MUL = 2*ceil(log2 64) = 12 -> SHL = ceil(log2 64) = 6.
LEG INDEPENDENCE (the keystone honesty defense -- legs must not collude on the
same i64 instruction): LEG0 = candidate emit-DAG interp; LEG1 = candidate
lowered-NxGsim gate-sim (independent code path); LEG2 = the SEED's value via a
shift-FREE repeated-doubling multiply (never takes the candidate's `<<` path).
ORACLE = the SEED emit-DAG (mul x 8) interpreted directly. A wrong shift count
makes LEG2 (and the oracle) disagree with LEG0/LEG1 -- exactly what the negative
control demonstrates is CAUGHT.
KNOWN ANSWER (FAIL LOUD), one line:
"<found> <seed_cost> <cand_cost> <seed_lat> <cand_lat> <root_op> <cand_count>
<bpass> <btotal> <neg_rejected> <neg_first_bad_leg>"
= "1 3 1 12 6 11 3 <N> <N> 1 0 " where N = battery vector count, root_op 11 = SHL,
neg_rejected 1 = the (shl x 2) wrong candidate FAILED the battery,
neg_first_bad_leg 0 = leg 0 (emit-interp of the wrong candidate) first diverged.
Expected: "1 3 1 12 6 11 3 585 585 1 0 " run=0
dependencies 1 imports · 0 importers
imports: nx_superopt.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
| 37 | const SO_W: i64 = 64 // honest-metric datapath width for Tier-2 scoring |
functions
| 39 | func _emit_num(v: i64) -> i64 called by 1: main |
| 47 | func _nl() -> i64 { let z: *u8 = sys_mmap(2); z[0] = 10; sys_write(1, z, 1); return 0 } called by 1: main |
| 52 | func found_or(bpass: i64, btotal: i64, cand_cost: i64, seed_cost: i64) -> i64 called by 1: main |
| 58 | func main() -> i64 |