code wiki / _hdl_build / nx_triangulate.nx

nx_triangulate.nx

buildroot/runtime/_hdl_build/nx_triangulate.nx

6728 B147 linesdepth 2pulls 2 transitivereach 14 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_triangulate.nx -- REUSABLE triangulation harness: a generic ">=K of N independent legs must agree with the oracle" checker the Engineer can point at ANY capability (divider, codec, crypto, search ranking, ...). WHY this organ exists: every proof in this codebase is some variant of "run M independent methods + an oracle over the same battery and assert they all agree" (nx_alu_divider_newton.nx hand-rolls exactly this: leg A Newton, leg B restoring, leg C `/` oracle). That pattern is the invention loop's VERIFIER step (memory: triangulation = math + independent-method + oracle, three legs that must agree). It was being copy-pasted per capability. This extracts it (Cardinal 15 DRY: a pattern in 3+ places -> shared/) so a new capability gets triangulated by FILLING IN its legs, not by re-deriving the agreement logic. CONTRACT (the generic checker): - You supply N independent method results for one input vector (an i64[]), plus the oracle value for that vector. - A leg AGREES iff its result == the oracle. (The oracle is ground truth; legs are independent estimators that must all land on it.) - The verdict reports: how many legs agreed, which leg index FIRST diverged (-1 if none), and PASS iff agree_count >= K AND agree_count == n_legs (i.e. the configurable consensus floor K is met AND no leg disagreed -- a divider proof wants ALL legs to agree; a fault-tolerant consensus wants >=K). Both knobs are exposed so the caller picks the regime. DESIGN: data-driven (legs + oracle + K are parameters, no hardcoded count -- Cardinal 11 no magic numbers / Cardinal 2 data-driven), single-responsibility (Cardinal 9: this ONLY judges agreement; it does not produce legs or oracles), and FAIL-LOUD by construction (the verdict is a value the caller asserts on a known answer; nothing is silently swallowed). Pure i64, no allocation inside the hot path -- the caller owns the leg buffer (Cardinal 12: trust internal callers, validate at the boundary = nx_tri_check's n_legs/K range guard). license_tier: ORIGINAL

dependencies 1 imports · 5 importers

nx_syscalls.nx nx_triangulate.nx nx_eqsat_membership_proof.nx nx_eqsat_rule_proof_test.nx nx_rule_soundness.nx nx_superopt.nx nx_triangulate_test.nx

imports: nx_syscalls.nx

imported by: nx_eqsat_membership_proof.nxnx_eqsat_rule_proof_test.nxnx_rule_soundness.nxnx_superopt.nxnx_triangulate_test.nx

structs

40struct NxTriVerdict
112struct NxTriTally

consts

49const NX_TRI_OK: i64 = 0
50const NX_TRI_BAD_ARGS: i64 = 1 // returned-in-pass=-1 sentinel on a boundary violation

functions

57func nx_tri_check(legs: *i64, n_legs: i64, oracle: i64, k_min: i64, v: *NxTriVerdict) -> i64
100func nx_tri_pass_strict(legs: *i64, n_legs: i64, oracle: i64, min_legs: i64, v: *NxTriVerdict) -> i64
121func nx_tri_tally_init(t: *NxTriTally) -> i64
133func nx_tri_tally_add(t: *NxTriTally, v: *NxTriVerdict, vec_idx: i64) -> i64