code wiki / (root) / nx_rigor_envelope_gate.nx

nx_rigor_envelope_gate.nx source

↩ module page · 155 lines · 10635 B

1// nx_rigor_envelope_gate.nx -- TEETH FOR THE RIGOR ENVELOPE (AD1, 2026-08-27). 2// 3// SUBJECT: nx_gate_verdict.gv_envelope / gv_wilson_permil / gv_boot_hier / gv_bare_rate / 4// gv_envelope_comparable, driven IN-PROCESS (they are pure functions of their arguments), plus the 5// conf half in nx_stage_path.sp_rigor_params (a precondition: knowledge/rigor.conf must resolve). 6// 7// WHY THESE TEETH: /compare/autograde published "92 percent" with no denominator; the plan's AD1 8// done rule says the row publishes through the envelope or reads REFUSED, the hand-typed percent is 9// refused BY NAME, and the interval width target is a conf row. Every tooth below is one of those 10// clauses made mechanical, and the anti-vacuity tooth (T9) is the one a plain bootstrap cannot pass. 11// 12// TEETH 13// T1-T5 Wilson known-answer values, checked by hand against the closed form before shipping 14// T6 n=0 is UNMEASURED, never a rate, and the JSON says so 15// T7 the bootstrap is seed-deterministic (two runs, identical bounds) 16// T8 a single-cluster bootstrap interval contains the point rate 17// T9 ANTI-VACUITY: two heterogeneous clusters (10 of 10, 0 of 10) WIDEN the envelope beyond 18// Wilson on both sides -- a flat bootstrap over the 20 outcomes cannot do this 19// T10 neg-control-partition-mismatch-refused: clusters that do not sum to (k,n) are refused 20// T11 BITE: gv_bare_rate FIRES on a hand-typed "92 percent" object and is SILENT on gv_envelope_json 21// T12 the refusal names the offender by byte offset, and "%" is caught as well as " percent" 22// T13 precondition: knowledge/rigor.conf resolves (gv_need -> SKIP, never a false RED) 23// T14 the conf z equals the base-class default (the same quantile spelled once in each place) 24// T15 the July batch (13 of 14) reads width_ok=0 against the conf target -- n=14 cannot resolve 25// a ten-point difference, and the gate says so rather than flattering the number 26// T16 neg-control-harness-mismatch-refuses-comparison (equal hashes compare; different, empty and 27// UNDECLARED refuse) 28// license_tier: ORIGINAL No fixtures on disk. No hw writes (Rule 26). expect_exit: 0 29import "nx_syscalls.nx" 30import "nx_gate_verdict.nx" 31import "nx_stage_path.nx" 32 33const RG_JULY_K: i64 = 13 34const RG_JULY_N: i64 = 14 35const RG_BUF: i64 = 4096 36// the two-cluster anti-vacuity fixture: one cluster all-pass, one all-fail, ten outcomes each 37const RG_FX_CLUSTER_N: i64 = 10 38 39func rg_kat(name: *u8, k: i64, n: i64, want_lo: i64, want_hi: i64, ctr: *i64) -> i64 { 40 let w: *i64 = sys_mmap(16) as *i64 41 let r: i64 = gv_wilson_permil(k, n, GV_Z95_MICRO, w) 42 gv_puts(" wilson " as *u8); gv_num(k); gv_puts("/" as *u8); gv_num(n); gv_puts(" -> [" as *u8); gv_num(w[0]); gv_puts("," as *u8); gv_num(w[1]); gv_puts("] want [" as *u8); gv_num(want_lo); gv_puts("," as *u8); gv_num(want_hi); gv_puts("]\n" as *u8) 43 var ok: i64 = 0 44 if r == 1 { if w[0] == want_lo { if w[1] == want_hi { ok = 1 } } } 45 return gv_check(name, ok, ctr) 46} 47 48func main() -> i64 { 49 let ctr: *i64 = gv_ctr() 50 gv_head("nx_rigor_envelope_gate -- a published number is a struct: n, a Wilson interval widened by a hierarchical bootstrap, a seed, a harness -- and a bare percent is refused by name" as *u8) 51 52 rg_kat("T1 wilson 7/14 -> [268,732] permil" as *u8, 7, 14, 268, 732, ctr) 53 rg_kat("T2 wilson 13/14 -> [685,987] permil (the July batch)" as *u8, 13, 14, 685, 987, ctr) 54 rg_kat("T3 wilson 0/14 -> [0,215] permil (Wald would collapse to [0,0])" as *u8, 0, 14, 0, 215, ctr) 55 rg_kat("T4 wilson 14/14 -> [785,1000] permil (Wald would collapse to [1000,1000])" as *u8, 14, 14, 785, 1000, ctr) 56 rg_kat("T5 wilson 1/1 -> [207,1000] permil (one success is not a certainty)" as *u8, 1, 1, 207, 1000, ctr) 57 58 // T6 UNMEASURED 59 let e0: *i64 = sys_mmap(GV_ENV_BYTES) as *i64 60 let r0: i64 = gv_envelope(0, 0, 0 as *i64, 0 as *i64, 0, GV_Z95_MICRO, GV_BOOT_B_DEFAULT, GV_BOOT_SEED_DEFAULT, 0, e0) 61 let jb: *u8 = sys_mmap(RG_BUF) 62 let jl: i64 = gv_envelope_json(jb, 0, e0, "" as *u8) 63 jb[jl] = 0 as u8 64 var t6: i64 = 0 65 if r0 == 0 { if e0[GV_ENV_MEASURED] == 0 { if gv_at(jb, jl, 0, "{\"k\":0,\"n\":0,\"rate_permil\":null" as *u8) == 1 { t6 = 1 } } } 66 gv_envelope_print("T6-fixture" as *u8, e0, "" as *u8) 67 gv_check("T6 n=0 is UNMEASURED: no rate, null interval, the JSON says UNMEASURED and still carries n" as *u8, t6, ctr) 68 69 // T7 determinism + T8 containment on the July batch, single cluster 70 let e1: *i64 = sys_mmap(GV_ENV_BYTES) as *i64 71 let e2: *i64 = sys_mmap(GV_ENV_BYTES) as *i64 72 gv_envelope(RG_JULY_K, RG_JULY_N, 0 as *i64, 0 as *i64, 0, GV_Z95_MICRO, GV_BOOT_B_DEFAULT, GV_BOOT_SEED_DEFAULT, 0, e1) 73 gv_envelope(RG_JULY_K, RG_JULY_N, 0 as *i64, 0 as *i64, 0, GV_Z95_MICRO, GV_BOOT_B_DEFAULT, GV_BOOT_SEED_DEFAULT, 0, e2) 74 gv_envelope_print("T7-run-a" as *u8, e1, "" as *u8) 75 gv_envelope_print("T7-run-b" as *u8, e2, "" as *u8) 76 var t7: i64 = 0 77 if e1[GV_ENV_BLO] == e2[GV_ENV_BLO] { if e1[GV_ENV_BHI] == e2[GV_ENV_BHI] { if e1[GV_ENV_MEASURED] == 1 { t7 = 1 } } } 78 gv_check("T7 the bootstrap is seed-deterministic: two envelopes of the same ledger carry identical bounds" as *u8, t7, ctr) 79 var t8: i64 = 0 80 if e1[GV_ENV_BLO] <= e1[GV_ENV_RATE] { if e1[GV_ENV_BHI] >= e1[GV_ENV_RATE] { if e1[GV_ENV_CLUSTERS] == 1 { t8 = 1 } } } 81 gv_check("T8 a single-cluster bootstrap contains the point rate and reports clusters=1 (no nesting known is said, not hidden)" as *u8, t8, ctr) 82 83 // T9 ANTI-VACUITY: heterogeneous clusters widen beyond Wilson on BOTH sides 84 let ck: *i64 = sys_mmap(16) as *i64 85 let cn: *i64 = sys_mmap(16) as *i64 86 ck[0] = RG_FX_CLUSTER_N; cn[0] = RG_FX_CLUSTER_N 87 ck[1] = 0; cn[1] = RG_FX_CLUSTER_N 88 let e3: *i64 = sys_mmap(GV_ENV_BYTES) as *i64 89 let r3: i64 = gv_envelope(RG_FX_CLUSTER_N, 2 * RG_FX_CLUSTER_N, ck, cn, 2, GV_Z95_MICRO, GV_BOOT_B_DEFAULT, GV_BOOT_SEED_DEFAULT, 0, e3) 90 gv_envelope_print("T9-two-clusters" as *u8, e3, "" as *u8) 91 var t9: i64 = 0 92 if r3 == 1 { if e3[GV_ENV_LO] < e3[GV_ENV_WLO] { if e3[GV_ENV_HI] > e3[GV_ENV_WHI] { if e3[GV_ENV_CLUSTERS] == 2 { t9 = 1 } } } } 93 gv_check("T9 ANTI-VACUITY: two heterogeneous clusters (10 of 10, 0 of 10) widen the envelope beyond Wilson on BOTH sides -- a flat bootstrap over 20 outcomes cannot produce this" as *u8, t9, ctr) 94 95 // T10 partition mismatch refused 96 cn[1] = RG_FX_CLUSTER_N - 1 97 let e4: *i64 = sys_mmap(GV_ENV_BYTES) as *i64 98 let r4: i64 = gv_envelope(RG_FX_CLUSTER_N, 2 * RG_FX_CLUSTER_N, ck, cn, 2, GV_Z95_MICRO, GV_BOOT_B_DEFAULT, GV_BOOT_SEED_DEFAULT, 0, e4) 99 var t10: i64 = 0 100 if r4 == GV_ENV_REFUSED_PARTITION { if e4[GV_ENV_MEASURED] == 0 { t10 = 1 } } 101 gv_check("T10 neg-control-partition-mismatch-refused: clusters summing to 19 for n=20 are refused, not silently rescaled" as *u8, t10, ctr) 102 103 // T11 BITE the refusal; T12 the offender is named by offset and the % form is caught 104 let bad: *u8 = "{\"question\":\"resolve rate\",\"answer\":\"92 percent of our instances resolved\"}" as *u8 105 var bl: i64 = 0 106 while bad[bl] != (0 as u8) { bl = bl + 1 } 107 let bad_off: i64 = gv_bare_rate(bad, bl) 108 let good: *u8 = sys_mmap(RG_BUF) 109 let gl: i64 = gv_envelope_json(good, 0, e1, "h0123456789abcdef" as *u8) 110 let good_off: i64 = gv_bare_rate(good, gl) 111 var fires: i64 = 0 112 if bad_off >= 0 { fires = 1 } 113 var silent: i64 = 0 114 if good_off < 0 { silent = 1 } 115 gv_puts(" bare_rate(bad)=" as *u8); gv_num(bad_off); gv_puts(" bare_rate(envelope_json)=" as *u8); gv_num(good_off); gv_puts("\n" as *u8) 116 gv_bite("T11 BITE-bare-percent: gv_bare_rate fires on a hand-typed \"92 percent\" object and is silent on gv_envelope_json" as *u8, fires, 1 - silent, ctr) 117 let bad2: *u8 = "{\"chip\":\"92% RESOLVED\"}" as *u8 118 var bl2: i64 = 0 119 while bad2[bl2] != (0 as u8) { bl2 = bl2 + 1 } 120 let off2: i64 = gv_bare_rate(bad2, bl2) 121 var t12: i64 = 0 122 if bad_off == 37 { if off2 == 9 { t12 = 1 } } 123 gv_puts(" offender offsets: percent-form=" as *u8); gv_num(bad_off); gv_puts(" (want 37) percent-sign-form=" as *u8); gv_num(off2); gv_puts(" (want 9)\n" as *u8) 124 gv_check("T12 neg-control-bare-percent-refused-by-name: the offender is named by byte offset, in both the \" percent\" and the \"%\" spelling" as *u8, t12, ctr) 125 126 // T13 precondition: the conf resolves on this host 127 let present: i64 = sp_rigor_present() 128 gv_need("knowledge/rigor.conf (z_micro, boot_reps, boot_seed, width_target_permil)" as *u8, present, ctr) 129 if present == 1 { 130 let p: *i64 = sys_mmap(32) as *i64 131 sp_rigor_params(p) 132 gv_puts(" rigor.conf: z_micro=" as *u8); gv_num(p[0]); gv_puts(" boot_reps=" as *u8); gv_num(p[1]); gv_puts(" boot_seed=" as *u8); gv_num(p[2]); gv_puts(" width_target_permil=" as *u8); gv_num(p[3]); gv_puts("\n" as *u8) 133 var t14: i64 = 0 134 if p[0] == GV_Z95_MICRO { if p[1] >= GV_BOOT_B_DEFAULT { if p[3] > 0 { t14 = 1 } } } 135 gv_check("T14 the conf's z equals the base-class quantile, B is at least the textbook floor, and a width target is declared" as *u8, t14, ctr) 136 let e5: *i64 = sys_mmap(GV_ENV_BYTES) as *i64 137 gv_envelope(RG_JULY_K, RG_JULY_N, 0 as *i64, 0 as *i64, 0, p[0], p[1], p[2], p[3], e5) 138 gv_envelope_print("T15-july-13-of-14" as *u8, e5, "" as *u8) 139 var t15: i64 = 0 140 if e5[GV_ENV_MEASURED] == 1 { if gv_envelope_width_ok(e5) == 0 { if e5[GV_ENV_WIDTH] > p[3] { t15 = 1 } } } 141 gv_check("T15 the July batch (13 of 14) reads width_ok=0 against the conf target: fourteen instances cannot resolve a ten-point difference, and the envelope says so" as *u8, t15, ctr) 142 } 143 144 // T16 comparability 145 var t16: i64 = 1 146 if gv_envelope_comparable("h0123456789abcdef" as *u8, "h0123456789abcdef" as *u8) != 1 { t16 = 0 } 147 if gv_envelope_comparable("h0123456789abcdef" as *u8, "hfedcba9876543210" as *u8) != 0 { t16 = 0 } 148 if gv_envelope_comparable("h0123456789abcdef" as *u8, "" as *u8) != 0 { t16 = 0 } 149 if gv_envelope_comparable("UNDECLARED" as *u8, "UNDECLARED" as *u8) != 0 { t16 = 0 } 150 gv_check("T16 neg-control-harness-mismatch-refuses-comparison: equal declared hashes compare, a different, an empty and an UNDECLARED harness each refuse" as *u8, t16, ctr) 151 152 let rc: i64 = gv_verdict("RIGOR-ENVELOPE-GATE" as *u8, ctr, "every published rate carries n, a Wilson interval widened by a hierarchical bootstrap, a seed and a harness, and a bare percent is refused by name" as *u8) 153 sys_exit(rc) 154 return rc 155}