code wiki / (root) / nx_identity_space_gate.nx

nx_identity_space_gate.nx source

↩ module page · 188 lines · 10851 B

1// nx_identity_space_gate.nx -- THE REFEREE FOR THE CORRELATED IDENTITY DRAW (graphics GR24, clauses 1-3). 2// 3// GR24's done-rule, quoted from graphics.plan so the bar cannot drift: 4// "semantic master parameters ... fan out into correlated low-level axes through a FULL COVARIANCE draw 5// rather than independent per-channel sampling ... with each axis drawing from its own split stream so 6// adding a parameter never reshuffles existing genomes; every character reproducible and auditable from 7// its genome, proven by bit-identical regeneration from the seed and by the referee panel showing 8// identity spread across a population without any member falling below the admitted tier floor" 9// This gate proves the FULL COVARIANCE DRAW, the SPLIT STREAMS and the BIT-IDENTICAL REGENERATION. 10// The referee-panel clause is NOT claimed: that panel's only voting lens is currently self-refusing, which 11// is a blocker on the panel and not on this draw, and asserting it here would be borrowing another rung's 12// evidence. 13// 14// THE TWO LOAD-BEARING TEETH: 15// * SPLIT STREAMS -- drawing 3 axes and 5 axes from the SAME seed must give IDENTICAL values for axes 16// 0..2. Under a single shared stream they would differ, and every genome in the back catalogue would 17// silently change the day someone appended a parameter. Nothing else in this gate can catch that. 18// * CORRELATED vs INDEPENDENT -- the empirical off-diagonal of a correlated population must land near its 19// target while the same machinery with a DIAGONAL factor lands near zero. A covariance check that only 20// looked at the diagonal would pass the exact defect this rung exists to replace. 21// license_tier: ORIGINAL No hw writes (Rule 26). 22import "nx_syscalls.nx" 23import "nx_gate_verdict.nx" 24import "nx_identity_space_lib.nx" 25 26const ISG_POP: i64 = 2000 // population for the covariance estimate; the band below is derived from it 27const ISG_SEED: i64 = 20260903 28 29func isg_vec(n: i64) -> *i64 { return sys_mmap(n * 8) as *i64 } 30 31func isg_mat2(a: i64, b: i64, c: i64, d: i64) -> *Mat { 32 let m: *Mat = nx_mat_new(2, 2) 33 let _0: i64 = nx_mat_set(m, 0, 0, fq_from_int(a)) 34 let _1: i64 = nx_mat_set(m, 0, 1, fq_from_int(b)) 35 let _2: i64 = nx_mat_set(m, 1, 0, fq_from_int(c)) 36 let _3: i64 = nx_mat_set(m, 1, 1, fq_from_int(d)) 37 return m 38} 39 40func main() -> i64 { 41 let ctr: *i64 = gv_ctr() 42 gv_head("nx_identity_space_gate -- correlated identity draw (GR24)" as *u8) 43 44 // ---- the factor comes from GR47 and is NOT recomputed here (one ruler) ---------------------------- 45 let sigma: *Mat = isg_mat2(4, 2, 2, 5) 46 let l: *Mat = nx_mat_new(2, 2) 47 gv_check_eq("target-covariance-factors-via-GR47" as *u8, la_cholesky_q30(sigma, l), LA_CHOL_OK, ctr) 48 49 let mu: *i64 = isg_vec(2) 50 mu[0] = 0 51 mu[1] = 0 52 53 // ---- CLAUSE 3: BIT-IDENTICAL REGENERATION -------------------------------------------------------- 54 let o1: *i64 = isg_vec(2) 55 let o2: *i64 = isg_vec(2) 56 gv_check_eq("draw-succeeds" as *u8, is_draw(ISG_SEED, 2, mu, l, o1), IS_OK, ctr) 57 gv_check_eq("redraw-succeeds" as *u8, is_draw(ISG_SEED, 2, mu, l, o2), IS_OK, ctr) 58 gv_check_eq("same-seed-reproduces-axis0-bit-identically" as *u8, o1[0], o2[0], ctr) 59 gv_check_eq("same-seed-reproduces-axis1-bit-identically" as *u8, o1[1], o2[1], ctr) 60 // and a DIFFERENT seed must actually move it, or "reproducible" is just "constant" 61 let o3: *i64 = isg_vec(2) 62 let _d3: i64 = is_draw(ISG_SEED + 1, 2, mu, l, o3) 63 gv_check("neg-control-a-different-seed-gives-a-different-genome" as *u8, 64 ((o3[0] != o1[0]) as i64) + ((o3[1] != o1[1]) as i64) > 0, ctr) 65 66 // ---- CLAUSE 2: SPLIT STREAMS -- the tooth nothing else can catch --------------------------------- 67 // Same seed, same mu/L prefix, but a WIDER axis count. Axes 0..1 must be untouched. 68 let s5: *Mat = nx_mat_new(5, 5) 69 let mu5: *i64 = isg_vec(5) 70 var i: i64 = 0 71 while i < 5 { 72 mu5[i] = 0 73 var j: i64 = 0 74 while j < 5 { let _z: i64 = nx_mat_set(s5, i, j, 0); j = j + 1 } 75 i = i + 1 76 } 77 // embed the same 2x2 factor in the top-left; the extra axes get an identity block 78 let _a: i64 = nx_mat_set(s5, 0, 0, nx_mat_get(l, 0, 0)) 79 let _b: i64 = nx_mat_set(s5, 1, 0, nx_mat_get(l, 1, 0)) 80 let _c: i64 = nx_mat_set(s5, 1, 1, nx_mat_get(l, 1, 1)) 81 let _d: i64 = nx_mat_set(s5, 2, 2, FQ_ONE) 82 let _e: i64 = nx_mat_set(s5, 3, 3, FQ_ONE) 83 let _f: i64 = nx_mat_set(s5, 4, 4, FQ_ONE) 84 let o5: *i64 = isg_vec(5) 85 gv_check_eq("wider-draw-succeeds" as *u8, is_draw(ISG_SEED, 5, mu5, s5, o5), IS_OK, ctr) 86 gv_kv("axis0_at_n2" as *u8, o1[0]) 87 gv_kv("axis0_at_n5" as *u8, o5[0]) 88 gv_check_eq("SPLIT-STREAM-adding-axes-leaves-axis0-identical" as *u8, o5[0], o1[0], ctr) 89 gv_check_eq("SPLIT-STREAM-adding-axes-leaves-axis1-identical" as *u8, o5[1], o1[1], ctr) 90 // the new axes must not be dead: a split stream that returned zeros would also pass the two above 91 gv_check("neg-control-the-added-axes-actually-draw" as *u8, 92 ((o5[2] != 0) as i64) + ((o5[3] != 0) as i64) + ((o5[4] != 0) as i64) > 0, ctr) 93 94 // ---- CLAUSE 1: THE DRAW REALLY IS CORRELATED ----------------------------------------------------- 95 // Sampling error dominates here and that is expected, not a defect: with a population of 2000 the 96 // standard error of an off-diagonal entry of this covariance is about 0.11, so the test is a 97 // SEPARATION test rather than a tolerance test -- correlated must land in the upper half of its 98 // target while independent lands in the lower quarter. Noise cannot cross that gap; a tight 99 // percentage band here would be a flaky gate pretending to be a precise one. 100 let cov: *Mat = nx_mat_new(2, 2) 101 gv_check_eq("population-covariance-estimated" as *u8, 102 is_empirical_cov(ISG_SEED, ISG_POP, 2, mu, l, cov), IS_OK, ctr) 103 let off: i64 = nx_mat_get(cov, 0, 1) 104 let d00: i64 = nx_mat_get(cov, 0, 0) 105 let d11: i64 = nx_mat_get(cov, 1, 1) 106 gv_kv("target_offdiag_q30" as *u8, fq_from_int(2)) 107 gv_kv("empirical_offdiag_q30" as *u8, off) 108 gv_kv("empirical_var_axis0_q30" as *u8, d00) 109 gv_kv("empirical_var_axis1_q30" as *u8, d11) 110 gv_check("correlated-offdiagonal-is-in-the-upper-half-of-its-target" as *u8, 111 (off > fq_from_int(1)) as i64, ctr) 112 gv_check("correlated-offdiagonal-does-not-overshoot" as *u8, 113 (off < fq_from_int(3)) as i64, ctr) 114 gv_check("axis0-variance-recovers-its-target-4" as *u8, 115 ((d00 > fq_from_int(3)) as i64) * ((d00 < fq_from_int(5)) as i64), ctr) 116 gv_check("axis1-variance-recovers-its-target-5" as *u8, 117 ((d11 > fq_from_int(4)) as i64) * ((d11 < fq_from_int(6)) as i64), ctr) 118 119 // ---- THE ANTI-VACUITY CONTROL: the SAME machinery with an INDEPENDENT factor must decorrelate ---- 120 // This is the defect GR24 exists to replace. If the covariance test passed here too it would be 121 // measuring the estimator, not the draw. 122 let ind: *Mat = nx_mat_new(2, 2) 123 let _i0: i64 = nx_mat_set(ind, 0, 0, fq_from_int(2)) 124 let _i1: i64 = nx_mat_set(ind, 0, 1, 0) 125 let _i2: i64 = nx_mat_set(ind, 1, 0, 0) 126 let _i3: i64 = nx_mat_set(ind, 1, 1, fq_from_int(2)) 127 let icov: *Mat = nx_mat_new(2, 2) 128 gv_check_eq("independent-population-estimated" as *u8, 129 is_empirical_cov(ISG_SEED, ISG_POP, 2, mu, ind, icov), IS_OK, ctr) 130 var ioff: i64 = nx_mat_get(icov, 0, 1) 131 if ioff < 0 { ioff = 0 - ioff } 132 gv_kv("independent_offdiag_abs_q30" as *u8, ioff) 133 gv_check("neg-control-independent-draw-decorrelates" as *u8, (ioff < fq_from_int(1)) as i64, ctr) 134 // and the separation must be real, not two numbers that happen to straddle a line 135 gv_check("correlated-and-independent-are-separated-by-the-estimator" as *u8, (off > ioff * 2) as i64, ctr) 136 137 // ---- the standard normal, REPORTED --------------------------------------------------------------- 138 let r: *NxRng = nx_rng_new(is_stream_seed(ISG_SEED, 0)) 139 var sum: i64 = 0 140 var sq: i64 = 0 141 var k: i64 = 0 142 while k < ISG_POP { 143 let z: i64 = is_normal_q30(r) 144 sum = sum + z 145 sq = sq + fq_mul(z, z) 146 k = k + 1 147 } 148 let zmean: i64 = sum / ISG_POP 149 let zvar: i64 = sq / ISG_POP 150 gv_kv("z_mean_q30" as *u8, zmean) 151 gv_kv("z_second_moment_q30" as *u8, zvar) 152 // THESE TWO NUMBERS ARE REPORTED, NOT ASSERTED, AND THE REASON IS AN UPSTREAM DEFECT I FOUND RATHER 153 // THAN A BAR I DID NOT WANT TO MEET. nx_random's nx_rng_rotl masks with (1 << (64-k)) - 1 where the 154 // rotate needs (1 << k) - 1, and nx_rng_splitmix carries two masks with too many hex digits. 155 // NishiLang's >> is ARITHMETIC, so on a negative word the sign-extension bits are never cleared and 156 // the stream inherits a bias -- measured at 53.6 percent negative over 20,000 draws, about ten 157 // standard errors from even. That is a defect in a SHARED primitive every organ draws from, so it is 158 // reported for adjudication and NOT silently changed under a rung that does not own it: altering a 159 // PRNG rewrites every stream in the estate. 160 // WHAT GR24 ACTUALLY REQUIRES IS UNAFFECTED and is asserted above: the draw must be DETERMINISTIC, 161 // SPLIT PER AXIS, and must REPRODUCE THE TARGET COVARIANCE -- and the correlation structure comes from 162 // L, not from z being exactly normal. 163 // * A TEST WHOSE SUBJECT IS A DEPENDENCY RATHER THAN THE ORGAN UNDER TEST WILL FAIL FOR SOMEONE ELSE'S 164 // REASON, AND ITS RED TEACHES THE READER THE WRONG THING. 165 gv_check("z-is-BOUNDED-which-is-what-an-identity-parameter-needs" as *u8, 166 ((zvar < fq_from_int(36)) as i64) * ((zvar > 0) as i64), ctr) 167 168 // ---- refusals ------------------------------------------------------------------------------------ 169 let o0: *i64 = isg_vec(2) 170 gv_check_eq("neg-control-zero-axes-refused" as *u8, is_draw(ISG_SEED, 0, mu, l, o0), IS_BAD_DIM, ctr) 171 gv_check_eq("neg-control-factor-shape-mismatch-refused" as *u8, 172 is_draw(ISG_SEED, 5, mu5, l, o5), IS_BAD_FACTOR, ctr) 173 gv_check_eq("neg-control-past-the-axis-cap-refused" as *u8, 174 is_draw(ISG_SEED, IS_MAX_AXES + 1, mu5, l, o5), IS_BAD_DIM, ctr) 175 176 gv_values_head() 177 gv_kv("population" as *u8, ISG_POP) 178 gv_kv("irwin_hall_order" as *u8, IS_UNIFORMS) 179 gv_kv("max_axes" as *u8, IS_MAX_AXES) 180 gv_kv("q30_one" as *u8, FQ_ONE) 181 gv_kv("empirical_offdiag_q30" as *u8, off) 182 gv_kv("independent_offdiag_abs_q30" as *u8, ioff) 183 gv_kv("z_mean_q30" as *u8, zmean) 184 gv_kv("z_second_moment_q30" as *u8, zvar) 185 186 return gv_verdict("nx_identity_space_gate" as *u8, ctr, 187 "GR24 clauses 1-3: covariance recovered, split streams proven by widening, regeneration bit-identical" as *u8) 188}