code wiki / _hdl_build / nx_deltaclass_gate.nx

nx_deltaclass_gate.nx source

↩ module page · 155 lines · 6485 B

1// nx_deltaclass_gate.nx -- teeth for the scope-vs-execution decomposition. 2// 3// The fixtures are NOT synthetic: E_* are the REAL ecomat ledger endpoints two weeks apart 4// (2026-07-18 sum_cur=34 sum_bar=68 domains=15 -> 2026-08-01 sum_cur=51 sum_bar=122 domains=26, 5// published headline 500 -> 418 permil). Grading the instrument against the very numbers it must 6// explain is the point: a decomposition that cannot reproduce the published delta explains nothing. 7// 8// expect_exit: 0 license_tier: ORIGINAL No hw writes (Rule 26). 9import "nx_gate_verdict.nx" 10import "nx_deltaclass_lib.nx" 11 12const E_CUR0: i64 = 34 13const E_BAR0: i64 = 68 14const E_DOM0: i64 = 15 15const E_CUR1: i64 = 51 16const E_BAR1: i64 = 122 17const E_DOM1: i64 = 26 18const E_P0: i64 = 500 19const E_P1: i64 = 418 20const E_EXEC: i64 = 250 21const C_CUR0: i64 = 10 22const C_CUR1: i64 = 20 23const C_BAR: i64 = 100 24const C_ETA: i64 = 8 25 26func main(argc: i64, argv: *i64) -> i64 { 27 let ctr: *i64 = gv_ctr() 28 gv_head("nx_deltaclass_gate -- scope vs execution, decomposed exactly, on the REAL ledger window" as *u8) 29 30 var ok: i64 = 0 31 if dc_permil(E_CUR0, E_BAR0) == E_P0 { ok = 1 } 32 gv_check("T1 permil(34,68) reproduces the published 500" as *u8, ok, ctr) 33 34 ok = 0 35 if dc_permil(E_CUR1, E_BAR1) == E_P1 { ok = 1 } 36 gv_check("T2 permil(51,122) reproduces the published 418" as *u8, ok, ctr) 37 38 let ex: i64 = dc_exec_effect(E_CUR0, E_CUR1, E_BAR0) 39 ok = 0 40 if ex == E_EXEC { ok = 1 } 41 gv_check("T3 execution effect is +250 (delivery 34->51 at a FIXED bar)" as *u8, ok, ctr) 42 43 let sc: i64 = dc_scope_effect(E_CUR1, E_BAR0, E_BAR1) 44 ok = 0 45 if sc == 0 - 332 { ok = 1 } 46 gv_check("T4 scope effect is -332 (bar 68->122 alone)" as *u8, ok, ctr) 47 48 let tt: i64 = dc_total(E_CUR0, E_BAR0, E_CUR1, E_BAR1) 49 ok = 0 50 if tt == 0 - 82 { ok = 1 } 51 gv_check("T5 total is -82, matching the observed headline drop" as *u8, ok, ctr) 52 53 let rs: i64 = dc_residual(E_CUR0, E_BAR0, E_CUR1, E_BAR1) 54 ok = 0 55 if rs == 0 { ok = 1 } 56 gv_check("T6 residual is 0 -- exec + scope ACCOUNT FOR the entire published delta" as *u8, ok, ctr) 57 58 ok = 0 59 if ex + sc + rs == tt { ok = 1 } 60 gv_check("T7 identity exec+scope+residual == total holds on real data" as *u8, ok, ctr) 61 62 let ex2: i64 = dc_exec_effect(7, 9, 13) 63 let sc2: i64 = dc_scope_effect(9, 13, 31) 64 let tt2: i64 = dc_total(7, 13, 9, 31) 65 let rs2: i64 = dc_residual(7, 13, 9, 31) 66 ok = 0 67 if ex2 + sc2 + rs2 == tt2 { ok = 1 } 68 gv_check("T8 the identity also closes on an unrelated ragged window" as *u8, ok, ctr) 69 70 ok = 0 71 if dc_scope_class(E_BAR0, E_BAR1, E_DOM0, E_DOM1) == DCS_ADMIT { ok = 1 } 72 gv_check("T9 bar up WITH domains up classifies as ADMIT (new territory)" as *u8, ok, ctr) 73 74 ok = 0 75 if dc_scope_class(E_BAR0, E_BAR1, E_DOM0, E_DOM0) == DCS_RAISE { ok = 1 } 76 gv_check("T10 bar up with domains FLAT classifies as RAISE (tighter target)" as *u8, ok, ctr) 77 78 ok = 0 79 if dc_exec_class(E_CUR0, E_CUR1) == DCE_GAIN { ok = 1 } 80 gv_check("T11 delivery 34->51 reads as GAIN even though the headline FELL" as *u8, ok, ctr) 81 82 ok = 0 83 if dc_diverging(E_CUR0, E_BAR0, E_CUR1, E_BAR1) == 1 { ok = 1 } 84 gv_check("T12 DIVERGING: bar grew +54 while delivery grew +17" as *u8, ok, ctr) 85 86 ok = 0 87 if dc_verdict(E_CUR0, E_BAR0, E_CUR1, E_BAR1, 0) == DCV_DIVERGING { ok = 1 } 88 gv_check("T13 the real window verdicts DIVERGING, not STALLED and not THRASH" as *u8, ok, ctr) 89 90 ok = 0 91 if dc_eta(E_CUR0, E_BAR0, E_CUR1, E_BAR1) == dc_unmeasured() { ok = 1 } 92 gv_check("T14 a diverging run reports NO eta -- it must not invent one" as *u8, ok, ctr) 93 94 ok = 0 95 if dc_eta(C_CUR0, C_BAR, C_CUR1, C_BAR) == C_ETA { ok = 1 } 96 gv_check("T15 a converging run DOES yield a finite eta (8 windows)" as *u8, ok, ctr) 97 98 ok = 0 99 if dc_verdict(C_CUR0, C_BAR, C_CUR1, C_BAR, 0) == DCV_CONVERGING { ok = 1 } 100 gv_check("T16 bar flat + delivery up verdicts CONVERGING" as *u8, ok, ctr) 101 102 ok = 0 103 if dc_permil(5, 0) == dc_unmeasured() { ok = 1 } 104 gv_check("T17 a zero bar is UNMEASURED, never a silent 0 permil" as *u8, ok, ctr) 105 106 var bad1: i64 = 0 107 if sc < 0 { if dc_abs(sc) > dc_abs(ex) { if ex > 0 { bad1 = 1 } } } 108 var good1: i64 = 0 109 if dc_scope_effect(20, E_BAR0, E_BAR0) != 0 { good1 = 1 } 110 gv_bite("B1 scope attribution" as *u8, bad1, good1, ctr) 111 112 var bad2: i64 = 0 113 if dc_verdict(E_CUR1, E_BAR1, E_CUR1, E_BAR1, 1) == DCV_THRASH { bad2 = 1 } 114 var good2: i64 = 0 115 if dc_verdict(E_CUR1, E_BAR1, E_CUR1, E_BAR1, 0) == DCV_THRASH { good2 = 1 } 116 gv_bite("B2 thrash needs real movement" as *u8, bad2, good2, ctr) 117 118 var bad3: i64 = 0 119 if dc_verdict(E_CUR0, 0, E_CUR1, E_BAR1, 0) == dc_unmeasured() { bad3 = 1 } 120 var good3: i64 = 0 121 if dc_verdict(E_CUR0, E_BAR0, E_CUR1, E_BAR1, 0) == dc_unmeasured() { good3 = 1 } 122 gv_bite("B3 unmeasured guard" as *u8, bad3, good3, ctr) 123 124 var bad4: i64 = 0 125 if dc_scope_class(E_BAR1, E_BAR0, E_DOM1, E_DOM1) == DCS_LOWER { bad4 = 1 } 126 var good4: i64 = 0 127 if dc_scope_class(E_BAR0, E_BAR0, E_DOM0, E_DOM0) == DCS_LOWER { good4 = 1 } 128 gv_bite("B4 lowered-bar detector" as *u8, bad4, good4, ctr) 129 130 // --- REGRESSION vs STALLED. Both defects below were found by RUNNING the CLI on the live 131 // ledger, not by review: window-5 (cur 52->51, bar flat) reported STALLED with advice saying 132 // "nothing moved", and its true delta of -1 printed as UNMEASURED because the sentinel sits 133 // inside the value range it guards. 134 ok = 0 135 if dc_verdict(52, 122, 51, 122, 0) == DCV_REGRESSION { ok = 1 } 136 gv_check("T18 bar flat + delivery 52->51 verdicts REGRESSION, never STALLED" as *u8, ok, ctr) 137 138 ok = 0 139 if dc_exec_class(52, 51) == DCE_LOSS { ok = 1 } 140 gv_check("T19 a one-level loss is a LOSS -- the smallest real delta must not vanish" as *u8, ok, ctr) 141 142 ok = 0 143 if dc_total(52, 122, 51, 122) == 0 - 8 { ok = 1 } 144 gv_check("T20 a delta of exactly -1 level yields a real -8 permil, not a sentinel" as *u8, ok, ctr) 145 146 var bad5: i64 = 0 147 if dc_verdict(52, 122, 51, 122, 0) == DCV_REGRESSION { bad5 = 1 } 148 var good5: i64 = 0 149 if dc_verdict(51, 122, 51, 122, 0) == DCV_REGRESSION { good5 = 1 } 150 gv_bite("B5 regression detector" as *u8, bad5, good5, ctr) 151 152 let rc: i64 = gv_verdict("DELTACLASS-GATE" as *u8, ctr, "scope and execution separate exactly on the real ledger window" as *u8) 153 sys_exit(rc) 154 return rc 155}