nx_commonsbench_gate.nx source
↩ module page · 264 lines · 16935 B
1// nx_commonsbench_gate.nx -- THE RULER for neighbour-commons standing. Scores BOTH rules on ONE
2// population so the delta is a measurement, not a claim.
3//
4// Per operator doctrine (feedback-match-known-good-then-improve, said twice): bank the baseline
5// FIRST, ship the smallest edit, RE-MEASURE, state the delta. An unmeasured change is an opinion and
6// a stack of them is unattributable. So this gate runs the INCUMBENT (the pairwise tolerance-ratio
7// rule nx_mycorrhiza/nx_hypha compute TODAY) and the CHALLENGER (nx_commons_lib) over identical
8// fixtures. Both rules live in nx_commons_lib, the incumbent kept deliberately as a NEGATIVE CONTROL
9// exactly as nx_connect_match_lib keeps the arithmetic mean beside the harmonic mean -- so a later
10// author can reproduce the comparison that justified the replacement.
11//
12// EVERY DISCRIMINATING TOOTH IS BITE-PROVEN, not merely passed: it must FIRE on the incumbent and be
13// SILENT on the challenger. A tooth that is green before the defect exists is VACUOUS and proves
14// nothing. T6 is the exception and is marked as such: both rules pass it, so it is a GUARD (it can
15// only catch a regression) and not a discriminator. Naming that difference is the point.
16//
17// verdict emission INHERITS nx_gate_verdict (D001 / law L009), so nx_gate_green can judge this gate
18// from outside and it records a harness.jrnl frame -- flake and erosion stay visible.
19// license_tier: ORIGINAL expect_exit: 0
20import "nx_gate_verdict.nx"
21import "nx_commons_lib.nx"
22
23const CB_N: i64 = 15
24const CB_RING: i64 = 7
25const CB_RING_N: i64 = 3
26
27func cpad(s: *u8, w: i64) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); var j: i64=n; while j<w { sys_write(1," " as *u8,1); j=j+1 } return 0 }
28func cname(i: i64) -> i64 {
29 if i==0 { cpad("JANITOR" as *u8, 13); return 0 }
30 if i==1 { cpad("NURSE" as *u8, 13); return 0 }
31 if i==2 { cpad("TEACHER" as *u8, 13); return 0 }
32 if i==3 { cpad("NEWCOMER" as *u8, 13); return 0 }
33 if i==4 { cpad("APPRENTICE" as *u8, 13); return 0 }
34 if i==5 { cpad("SKIMMER(PE)" as *u8, 13); return 0 }
35 if i==6 { cpad("HOARDER" as *u8, 13); return 0 }
36 if i==7 { cpad("SYBIL-A" as *u8, 13); return 0 }
37 if i==8 { cpad("SYBIL-B" as *u8, 13); return 0 }
38 if i==9 { cpad("SYBIL-C" as *u8, 13); return 0 }
39 if i==10 { cpad("ELDER-ACTIVE" as *u8, 13); return 0 }
40 if i==11 { cpad("ELDER-DORMANT" as *u8, 13); return 0 }
41 if i==12 { cpad("WITNESSED" as *u8, 13); return 0 }
42 if i==13 { cpad("UNWITNESSED" as *u8, 13); return 0 }
43 cpad("BREAK-EVEN" as *u8, 13); return 0
44}
45
46func agreement_permil(score: *i64, rank: *i64, n: i64, agree_out: *i64, pairs_out: *i64) -> i64 {
47 var agree: i64 = 0
48 var pairs: i64 = 0
49 var a: i64 = 0
50 while a < n {
51 var b: i64 = 0
52 while b < n {
53 if rank[a] > rank[b] {
54 pairs = pairs + 1
55 if score[a] > score[b] { agree = agree + 1 }
56 }
57 b = b + 1
58 }
59 a = a + 1
60 }
61 agree_out[0] = agree
62 pairs_out[0] = pairs
63 if pairs <= 0 { return 0 }
64 return (agree * 1000) / pairs
65}
66
67func main() -> i64 {
68 let gave: *i64 = sys_mmap(8*CB_N) as *i64
69 let took: *i64 = sys_mmap(8*CB_N) as *i64
70 let pout: *i64 = sys_mmap(8*CB_N) as *i64 // passed to INDEPENDENT parties (never in-ring)
71 let witn: *i64 = sys_mmap(8*CB_N) as *i64 // third-party-attested share of giving, permil
72 let rec: *i64 = sys_mmap(8*CB_N) as *i64 // recency of giving, permil
73 let outs: *i64 = sys_mmap(8*CB_N) as *i64 // INDEPENDENT counterparties
74 let worst:*i64 = sys_mmap(8*CB_N) as *i64 // worst pairwise ratio Q10 -- the incumbent's ONLY input
75 let rank: *i64 = sys_mmap(8*CB_N) as *i64 // declared ground-truth desert
76
77 // 0 JANITOR -- shares steadily, takes modestly, everything witnessed.
78 gave[0]=900; took[0]=300; pout[0]=280; witn[0]=950; rec[0]=900; outs[0]=12; worst[0]=1400; rank[0]=90
79 // 1 NURSE -- most generous member, gives 7.5x what she takes. NEGATIVE CONTROL: a rule that
80 // punishes the biggest net giver is disqualified outright.
81 gave[1]=1500; took[1]=200; pout[1]=190; witn[1]=980; rec[1]=950; outs[1]=20; worst[1]=7680; rank[1]=95
82 // 2 TEACHER -- balanced, broad, well witnessed.
83 gave[2]=600; took[2]=400; pout[2]=380; witn[2]=900; rec[2]=900; outs[2]=15; worst[2]=1300; rank[2]=85
84 // 3 NEWCOMER -- arrived with nothing. Must NOT be punished.
85 gave[3]=0; took[3]=0; pout[3]=0; witn[3]=0; rec[3]=0; outs[3]=0; worst[3]=1024; rank[3]=50
86 // 4 APPRENTICE -- genuine net taker because he is LEARNING. NEGATIVE CONTROL: a rule that cannot
87 // tell an apprentice from a skimmer will starve the young before it starves the predator.
88 gave[4]=50; took[4]=400; pout[4]=40; witn[4]=800; rec[4]=900; outs[4]=3; worst[4]=8192; rank[4]=40
89 // 5 SKIMMER -- THE CASE THAT MATTERS. Balanced with EVERY counterparty individually, huge reach,
90 // net-negative on the network, converts almost nothing onward, barely third-party-witnessed.
91 gave[5]=1000; took[5]=1400; pout[5]=60; witn[5]=120; rec[5]=800; outs[5]=40; worst[5]=1100; rank[5]=5
92 // 6 HOARDER -- gave once, long ago; sits on it; no throughput. Only DECAY can see the age.
93 gave[6]=800; took[6]=100; pout[6]=5; witn[6]=700; rec[6]=50; outs[6]=2; worst[6]=1500; rank[6]=20
94 // 7,8,9 SYBIL RING -- three identities trading with each other to MANUFACTURE reciprocity.
95 // Pairwise-flawless by construction. pout=0: ALL circulation is internal, which is laundering,
96 // not flow-through. No outside partners, no third-party witness.
97 gave[7]=2000; took[7]=2000; pout[7]=0; witn[7]=0; rec[7]=900; outs[7]=0; worst[7]=1024; rank[7]=1
98 gave[8]=2000; took[8]=2000; pout[8]=0; witn[8]=0; rec[8]=900; outs[8]=0; worst[8]=1024; rank[8]=1
99 gave[9]=2000; took[9]=2000; pout[9]=0; witn[9]=0; rec[9]=900; outs[9]=0; worst[9]=1024; rank[9]=1
100 // 10,11 THE DECAY PROBE -- added 2026-08-06 to close the blind spot this gate named about ITSELF.
101 // The previous population could not discriminate the decay term at all (976 permil with decay on
102 // AND off), so the anti-ossification tooth was shipped with NO evidence it did anything. These two
103 // members are byte-for-byte IDENTICAL in every field except `rec` (recency of giving). That makes
104 // decay a SINGLE-VARIABLE probe: any ranking difference between them is attributable to the term
105 // and to nothing else.
106 // Ground truth: the ACTIVE elder outranks the DORMANT one. That IS the anti-ossification claim --
107 // a founder who stopped contributing must not outrank someone still carrying the load. Every co-op
108 // that calcified into an oligarchy failed exactly this test.
109 // Note both present worst=8192 to a pairwise auditor, so the INCUMBENT scores them identically AND
110 // flags them both: it cannot see the difference and punishes the active one anyway.
111 gave[10]=800; took[10]=100; pout[10]=90; witn[10]=900; rec[10]=900; outs[10]=10; worst[10]=8192; rank[10]=80
112 gave[11]=800; took[11]=100; pout[11]=90; witn[11]=900; rec[11]=50; outs[11]=10; worst[11]=8192; rank[11]=30
113 // 12,13 THE WITNESS PROBE -- added 2026-08-07 after MUTATION TESTING. Deleting the witness term
114 // from nx_commons_lib entirely left this gate GREEN: every number moved, the ORDERING did not,
115 // because flow-through alone carried all five teeth. No two members differed ONLY in witness.
116 // I had already fixed exactly this blind spot for DECAY (members 10/11) and never thought to ask
117 // the same question of the other terms.
118 // A FIXTURE PROVES A TERM ONLY IF TWO MEMBERS DIFFER IN THAT TERM AND NOTHING ELSE.
119 // Identical in every field except witn. Ground truth: someone whose contribution NOBODY
120 // independent can corroborate must not outrank someone whose can -- that is the whole basis on
121 // which the sybil ring is refused.
122 gave[12]=800; took[12]=100; pout[12]=90; witn[12]=900; rec[12]=900; outs[12]=10; worst[12]=8192; rank[12]=75
123 gave[13]=800; took[13]=100; pout[13]=90; witn[13]=100; rec[13]=900; outs[13]=10; worst[13]=8192; rank[13]=25
124 // 14 THE BOUNDARY PROBE -- retained EXACTLY equals witnessed giving. A `>` vs `>=` slip in
125 // nxc_is_extractor is invisible to every other row and survived mutation. Giving exactly what
126 // you kept is BALANCE, not extraction, so this member must not be flagged.
127 gave[14]=100; took[14]=100; pout[14]=0; witn[14]=1000; rec[14]=1000; outs[14]=5; worst[14]=1024; rank[14]=45
128
129 let inc: *i64 = sys_mmap(8*CB_N) as *i64
130 let incf: *i64 = sys_mmap(8*CB_N) as *i64
131 let new: *i64 = sys_mmap(8*CB_N) as *i64
132 let newf: *i64 = sys_mmap(8*CB_N) as *i64
133 let nodecay: *i64 = sys_mmap(8*CB_N) as *i64
134
135 let ctr: *i64 = gv_ctr()
136 gv_head("nx_commonsbench_gate -- neighbour-commons standing: pairwise INCUMBENT vs network CHALLENGER" as *u8)
137
138 gv_puts("actor gave took pout witn rec out | INCUMBENT flag | CHALLENGER flag | truth\n" as *u8)
139 var i: i64 = 0
140 while i < CB_N {
141 inc[i] = nxc_incumbent_pairwise_standing(worst[i])
142 incf[i] = nxc_incumbent_pairwise_flags(worst[i])
143 new[i] = nxc_standing(gave[i], took[i], pout[i], witn[i], rec[i], outs[i])
144 newf[i] = nxc_is_extractor(gave[i], took[i], pout[i], witn[i], rec[i])
145 nodecay[i] = nxc_standing(gave[i], took[i], pout[i], witn[i], 1000, outs[i])
146 cname(i)
147 gv_num(gave[i]); gv_puts(" " as *u8); gv_num(took[i]); gv_puts(" " as *u8); gv_num(pout[i]); gv_puts(" " as *u8)
148 gv_num(witn[i]); gv_puts(" " as *u8); gv_num(rec[i]); gv_puts(" " as *u8); gv_num(outs[i]); gv_puts(" | " as *u8)
149 gv_num(inc[i]); gv_puts(" " as *u8)
150 if incf[i]==1 { gv_puts("FLAG" as *u8) } else { gv_puts("ok " as *u8) }
151 gv_puts(" | " as *u8); gv_num(new[i]); gv_puts(" " as *u8)
152 if newf[i]==1 { gv_puts("FLAG" as *u8) } else { gv_puts("ok " as *u8) }
153 gv_puts(" | " as *u8); gv_num(rank[i]); gv_puts("\n" as *u8)
154 i = i + 1
155 }
156 gv_puts("\n" as *u8)
157
158 let ag: *i64 = sys_mmap(8) as *i64
159 let pr: *i64 = sys_mmap(8) as *i64
160 let inc_permil: i64 = agreement_permil(inc, rank, CB_N, ag, pr)
161 let inc_agree: i64 = ag[0]
162 let inc_pairs: i64 = pr[0]
163 let new_permil: i64 = agreement_permil(new, rank, CB_N, ag, pr)
164 let new_agree: i64 = ag[0]
165 let nod_permil: i64 = agreement_permil(nodecay, rank, CB_N, ag, pr)
166
167 // ---- teeth, scored for BOTH rules ----------------------------------------------------------
168 var i2: i64 = 0; var i3: i64 = 0; var i4: i64 = 0; var i5: i64 = 0; var i6: i64 = 0
169 if inc[0] > inc[5] { i2 = 1 }
170 if incf[1] == 0 { i3 = 1 }
171 if inc[4] > inc[5] { i4 = 1 }
172 var inc_ring: i64 = 0
173 var r: i64 = 0
174 while r < CB_RING_N { inc_ring = inc_ring + inc[CB_RING + r]; r = r + 1 }
175 let inc_honest: i64 = inc[0] + inc[1] + inc[2]
176 if inc_ring < inc_honest { i5 = 1 }
177 if incf[3] == 0 { i6 = 1 }
178
179 var n2: i64 = 0; var n3: i64 = 0; var n4: i64 = 0; var n5: i64 = 0; var n6: i64 = 0
180 if new[0] > new[5] { n2 = 1 }
181 if newf[1] == 0 { n3 = 1 }
182 if new[4] > new[5] { n4 = 1 }
183 var new_ring: i64 = 0
184 var r2: i64 = 0
185 while r2 < CB_RING_N { new_ring = new_ring + new[CB_RING + r2]; r2 = r2 + 1 }
186 let new_honest: i64 = new[0] + new[1] + new[2]
187 if new_ring < new_honest { n5 = 1 }
188 if newf[3] == 0 { n6 = 1 }
189 let new_teeth: i64 = n2 + n3 + n4 + n5 + n6
190 let inc_teeth: i64 = i2 + i3 + i4 + i5 + i6
191
192 // ---- BITE-PROVEN teeth: each must FIRE on the incumbent and be SILENT on the challenger -----
193 gv_bite("T2 skimmer-below-worker tooth (fires on pairwise, silent on network)" as *u8, 1-i2, 1-n2, ctr)
194 gv_bite("T3 generosity tooth: biggest net giver must not be flagged" as *u8, 1-i3, 1-n3, ctr)
195 gv_bite("T4 apprentice tooth: a learner outranks a predator" as *u8, 1-i4, 1-n4, ctr)
196 gv_bite("T5 sybil bound: ring total < honest total" as *u8, 1-i5, 1-n5, ctr)
197 // T6 is a GUARD, not a discriminator -- BOTH rules pass it, so it cannot be bite-proven. It can
198 // only ever catch a regression. Saying so is the honest form; counting it as a win would inflate
199 // the challenger with a tooth it never had to earn.
200 gv_check("T6 GUARD (not bite-provable, both rules pass): newcomer not punished" as *u8, n6, ctr)
201
202 var five: i64 = 0
203 if new_teeth == 5 { five = 1 }
204 gv_check("challenger passes all five teeth" as *u8, five, ctr)
205 var better: i64 = 0
206 if new_permil > inc_permil { better = 1 }
207 gv_check("challenger ordering strictly beats incumbent" as *u8, better, ctr)
208 var toothy: i64 = 0
209 if inc_teeth < 5 { toothy = 1 }
210 gv_check("ruler is non-vacuous (incumbent does NOT pass everything)" as *u8, toothy, ctr)
211
212 gv_puts("\nring totals : incumbent ring=" as *u8); gv_num(inc_ring); gv_puts(" honest=" as *u8); gv_num(inc_honest)
213 gv_puts(" challenger ring=" as *u8); gv_num(new_ring); gv_puts(" honest=" as *u8); gv_num(new_honest); gv_puts("\n" as *u8)
214 gv_puts("teeth : incumbent " as *u8); gv_num(inc_teeth); gv_puts("/5 challenger " as *u8); gv_num(new_teeth); gv_puts("/5\n" as *u8)
215 gv_puts("ordering : incumbent " as *u8); gv_num(inc_permil); gv_puts(" permil (" as *u8); gv_num(inc_agree)
216 gv_puts("/" as *u8); gv_num(inc_pairs); gv_puts(") challenger " as *u8); gv_num(new_permil); gv_puts(" permil (" as *u8)
217 gv_num(new_agree); gv_puts("/" as *u8); gv_num(inc_pairs); gv_puts(")\n" as *u8)
218 gv_puts("DELTA : teeth +" as *u8); gv_num(new_teeth - inc_teeth); gv_puts(" ordering +" as *u8)
219 gv_num(new_permil - inc_permil); gv_puts(" permil\n" as *u8)
220
221 // ---- HONEST GAP: can this fixture even measure the decay term? -----------------------------
222 // Run the challenger with decay disabled (recency pinned to 1000). If the ordering is identical,
223 // this population does NOT discriminate decay and we must not claim credit for it. An instrument
224 // that cannot see a term is not evidence about that term.
225 // ---- DECAY, now actually measured -----------------------------------------------------------
226 // Members 10 and 11 differ ONLY in recency. With decay ON the active elder must outrank the dormant
227 // one; with decay OFF they are identical in every input and MUST tie, so the term is the only thing
228 // that can separate them. That makes the tooth bite-provable: it fires when decay is disabled and is
229 // silent when it is enabled. Previously this gate could only confess it was blind here.
230 gv_puts("\n--- decay discrimination probe (members 10/11 differ ONLY in recency) ---\n" as *u8)
231 gv_puts(" decay ON : ELDER-ACTIVE=" as *u8); gv_num(new[10]); gv_puts(" ELDER-DORMANT=" as *u8); gv_num(new[11])
232 gv_puts("\n decay OFF: ELDER-ACTIVE=" as *u8); gv_num(nodecay[10]); gv_puts(" ELDER-DORMANT=" as *u8); gv_num(nodecay[11])
233 gv_puts("\n ordering WITH decay=" as *u8); gv_num(new_permil); gv_puts(" permil decay DISABLED=" as *u8)
234 gv_num(nod_permil); gv_puts(" permil hoarder " as *u8); gv_num(new[6]); gv_puts(" vs " as *u8)
235 gv_num(nodecay[6]); gv_puts("\n\n" as *u8)
236 var decay_off_blind: i64 = 0
237 if nodecay[10] <= nodecay[11] { decay_off_blind = 1 }
238 var decay_on_blind: i64 = 0
239 if new[10] <= new[11] { decay_on_blind = 1 }
240 gv_bite("T7 anti-ossification: active member outranks dormant equal-contributor" as *u8,
241 decay_off_blind, decay_on_blind, ctr)
242 // The incumbent cannot see this distinction AT ALL: identical pairwise ratio, identical score.
243 var inc_decay_blind: i64 = 0
244 if inc[10] == inc[11] { inc_decay_blind = 1 }
245 gv_check("T8 incumbent is provably blind to age (scores 10 and 11 identically)" as *u8, inc_decay_blind, ctr)
246
247 // ---- MUTATION-DRIVEN TEETH (added 2026-08-07; each kills a mutant that previously survived) ----
248 gv_puts("\n--- term-isolation probes ---\n" as *u8)
249 gv_puts(" WITNESSED=" as *u8); gv_num(new[12]); gv_puts(" UNWITNESSED=" as *u8); gv_num(new[13])
250 gv_puts(" (identical but for witn 900 vs 100)\n" as *u8)
251 gv_puts(" BREAK-EVEN standing=" as *u8); gv_num(new[14]); gv_puts(" extractor-flag=" as *u8); gv_num(newf[14])
252 gv_puts(" (retained EXACTLY equals witnessed giving)\n" as *u8)
253 var t9: i64 = 0
254 if new[12] > new[13] { t9 = 1 }
255 gv_check("T9 WITNESS ISOLATION corroborated giving outranks identical UNcorroborated giving" as *u8, t9, ctr)
256 var t10: i64 = 0
257 if newf[14] == 0 { t10 = 1 }
258 gv_check("T10 BOUNDARY giving exactly what you kept is BALANCE, not extraction (kills > vs >=)" as *u8, t10, ctr)
259
260 let rc: i64 = gv_verdict("COMMONSBENCH" as *u8, ctr,
261 "network standing beats the pairwise incumbent on a ruler the incumbent provably fails" as *u8)
262 sys_exit(rc)
263 return rc
264}