nx_agreebound_gate.nx source
↩ module page · 171 lines · 10075 B
1// nx_agreebound_gate.nx -- REFEREE for WRITING rung W-AGB-1 (nx_agreebound).
2//
3// [T1] the interval a single detector's rate must be reported as: lo/hi over the panel.
4// [T2] disagreement ratio reproduces THE RULER'S OWN MEASURED SPREADS -- 3.9x violence,
5// 3.1x insult, 1.45x sexual. Binding the organ to the paper's numbers, not to invented ones.
6// [T3] ratio division guards: an all-zero panel is agreement (1000), a some-zero panel is
7// UNBOUNDED (a contradiction, not a ratio) -- neither is a divide trap.
8// [T4] Krippendorff alpha, perfect agreement WITH variation -> exactly 1000.
9// [T5] alpha on a disagreeing panel -> exact integer (389), computed by hand from the definition.
10// [T6] NEG-CONTROL, WORSE THAN CHANCE: a systematically inverted panel scores NEGATIVE (-500) and
11// is reported as such, never clamped to zero. A meter that cannot go below chance is hiding
12// its worst finding.
13// [T7] FAIL-CLOSED on zero variation: every rater, every unit, one category -> AB_UNDEFINED, NOT
14// a perfect 1000. Two blank planes must never score a perfect match (the blank-decoy trap).
15// [T8] ★THE STRUCTURAL REFUSAL: ONE detector with a PERFECT alpha and PERFECT ratio still cannot
16// enforce -- ndet<2 is a coin flip by construction, and no score buys past it.
17// [T9] THE RULER'S OWN RELIABILITY (alpha 0.24 on model output) -> REPORT-ONLY against the 0.6
18// substantial floor. The paper's headline judge would not license enforcement here.
19// [T10] a WIDE-but-reliable panel (alpha fine, ratio 3.9x over a 2.0x cap) -> REPORT-ONLY, so the
20// two bounds are independently load-bearing rather than one doing all the work.
21// [T11] ★NON-VACUITY: a genuinely good panel (2 detectors, alpha 800, ratio 1200) RETURNS ENFORCE.
22// A gate that never sees its verdict succeed has not tested a decision, only a refusal.
23// [T12] thresholds are PARAMETERS: the SAME panel flips REPORT-ONLY -> ENFORCE when the caller
24// supplies a looser floor, proving no bound is baked into the organ.
25//
26// Evidence -> stdout + knowledge/status/agreebound_gate.log. Exit 0 GREEN / 1 RED.
27// Sovereign x86_64. license_tier: ORIGINAL expect_exit: 0
28import "nx_syscalls_x86_64.nx"
29import "nx_agreebound.nx"
30
31func gp(logfd: i64, s: *u8) -> i64 {
32 var n: i64 = 0
33 while s[n] != (0 as u8) { n = n + 1 }
34 sys_write(1, s, n)
35 if logfd > 0 { sys_write(logfd, s, n) }
36 return 0
37}
38func gn(logfd: i64, v: i64) -> i64 {
39 var m: i64 = v
40 if m < 0 {
41 sys_write(1, "-\x00" as *u8, 1)
42 if logfd > 0 { sys_write(logfd, "-\x00" as *u8, 1) }
43 m = 0 - m
44 }
45 let t: *u8 = sys_mmap(32)
46 let b: *u8 = sys_mmap(32)
47 var k: i64 = 0
48 if m == 0 { t[0] = 48 as u8; k = 1 }
49 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
50 var i: i64 = 0
51 while i < k { b[i] = t[k - 1 - i]; i = i + 1 }
52 sys_write(1, b, k)
53 if logfd > 0 { sys_write(logfd, b, k) }
54 return 0
55}
56func pr(logfd: i64, label: *u8, got: i64, exp: i64) -> i64 {
57 gp(logfd, label)
58 gp(logfd, " got=\x00" as *u8); gn(logfd, got)
59 gp(logfd, " exp=\x00" as *u8); gn(logfd, exp)
60 if got == exp { gp(logfd, " OK\n\x00" as *u8); return 1 }
61 gp(logfd, " FAIL\n\x00" as *u8)
62 return 0
63}
64
65func main() -> i64 {
66 let logfd: i64 = sys_openat_append("knowledge/status/agreebound_gate.log\x00" as *u8, 0x1a4)
67 gp(logfd, "AGREEBOUND-GATE W-AGB-1 (interval / ruler spreads / guards / alpha / negative / fail-closed / structural refusal / non-vacuity / parameters)\n\x00" as *u8)
68 var pass: i64 = 0
69 var total: i64 = 0
70
71 let marg: *i64 = sys_mmap(64) as *i64
72 let cnt: *i64 = sys_mmap(64) as *i64
73
74 // ---- T1 the reporting interval -------------------------------------------------------------
75 let rates: *i64 = sys_mmap(64) as *i64
76 rates[0] = 39; rates[1] = 10; rates[2] = 22
77 total = total + 1; pass = pass + pr(logfd, "T1a span_lo\x00" as *u8, ab_span_lo(rates, 3), 10)
78 total = total + 1; pass = pass + pr(logfd, "T1b span_hi\x00" as *u8, ab_span_hi(rates, 3), 39)
79
80 // ---- T2 the ruler's OWN measured detector spreads -------------------------------------------
81 // violence 3.9x
82 rates[0] = 390; rates[1] = 100
83 total = total + 1; pass = pass + pr(logfd, "T2a ruler violence 3.9x\x00" as *u8, ab_ratio_permil(rates, 2), 3900)
84 // insult 3.1x
85 rates[0] = 310; rates[1] = 100
86 total = total + 1; pass = pass + pr(logfd, "T2b ruler insult 3.1x\x00" as *u8, ab_ratio_permil(rates, 2), 3100)
87 // sexual 1.45x -- the TIGHTEST spread in the paper, and still not agreement
88 rates[0] = 145; rates[1] = 100
89 total = total + 1; pass = pass + pr(logfd, "T2c ruler sexual 1.45x\x00" as *u8, ab_ratio_permil(rates, 2), 1450)
90
91 // ---- T3 division guards ---------------------------------------------------------------------
92 rates[0] = 0; rates[1] = 0
93 total = total + 1; pass = pass + pr(logfd, "T3a all-zero panel = agreement\x00" as *u8, ab_ratio_permil(rates, 2), AB_PERMIL)
94 rates[0] = 50; rates[1] = 0
95 total = total + 1; pass = pass + pr(logfd, "T3b some-zero = UNBOUNDED\x00" as *u8, ab_ratio_permil(rates, 2), AB_RATIO_UNBOUNDED)
96
97 // ---- T4 alpha, perfect agreement WITH variation ----------------------------------------------
98 // 4 units x 3 raters, 2 categories: every rater agrees, and the units genuinely differ.
99 let ra: *i64 = sys_mmap(256) as *i64
100 ra[0]=0; ra[1]=0; ra[2]=0
101 ra[3]=1; ra[4]=1; ra[5]=1
102 ra[6]=0; ra[7]=0; ra[8]=0
103 ra[9]=1; ra[10]=1; ra[11]=1
104 total = total + 1; pass = pass + pr(logfd, "T4 alpha perfect\x00" as *u8, ab_alpha_permil(ra, 4, 3, 2, marg, cnt), 1000)
105
106 // ---- T5 alpha on a disagreeing panel, exact ---------------------------------------------------
107 // 6 units x 2 raters: A=[0,0,0,1,1,1] B=[0,1,0,1,0,1] -> D_pairs=4, n=12, E_pairs=72
108 // alpha = 1000 - (1000*4*11)/((2-1)*72) = 1000 - 611 = 389
109 let rb: *i64 = sys_mmap(256) as *i64
110 rb[0]=0; rb[1]=0
111 rb[2]=0; rb[3]=1
112 rb[4]=0; rb[5]=0
113 rb[6]=1; rb[7]=1
114 rb[8]=1; rb[9]=0
115 rb[10]=1; rb[11]=1
116 total = total + 1; pass = pass + pr(logfd, "T5 alpha disagreeing\x00" as *u8, ab_alpha_permil(rb, 6, 2, 2, marg, cnt), 389)
117
118 // ---- T6 NEG-CONTROL: worse than chance is NEGATIVE, never clamped -----------------------------
119 // 2 units x 2 raters, systematically inverted: A=[0,1] B=[1,0]
120 // D_pairs=4, n=4, E_pairs=8 -> alpha = 1000 - (1000*4*3)/(1*8) = -500
121 let rc: *i64 = sys_mmap(256) as *i64
122 rc[0]=0; rc[1]=1
123 rc[2]=1; rc[3]=0
124 total = total + 1; pass = pass + pr(logfd, "T6 alpha worse-than-chance\x00" as *u8, ab_alpha_permil(rc, 2, 2, 2, marg, cnt), 0 - 500)
125
126 // ---- T7 FAIL-CLOSED on zero variation ---------------------------------------------------------
127 let rd: *i64 = sys_mmap(256) as *i64
128 rd[0]=0; rd[1]=0
129 rd[2]=0; rd[3]=0
130 total = total + 1; pass = pass + pr(logfd, "T7 zero-variation UNDEFINED\x00" as *u8, ab_alpha_permil(rd, 2, 2, 2, marg, cnt), AB_UNDEFINED)
131 // and a single rater is undefined too -- one voice is not a panel
132 total = total + 1; pass = pass + pr(logfd, "T7b one-rater UNDEFINED\x00" as *u8, ab_alpha_permil(ra, 4, 1, 2, marg, cnt), AB_UNDEFINED)
133
134 // ---- T8 ★THE STRUCTURAL REFUSAL ---------------------------------------------------------------
135 total = total + 1; pass = pass + pr(logfd, "T8 one detector, perfect scores, still REFUSED\x00" as *u8,
136 ab_enforce(1, 1000, 1000, AB_ALPHA_FLOOR_DEFAULT, AB_RATIO_CAP_DEFAULT), AB_REFUSE_SINGLE)
137
138 // ---- T9 the ruler's own judge reliability ------------------------------------------------------
139 total = total + 1; pass = pass + pr(logfd, "T9 ruler alpha 0.24 -> REPORT-ONLY\x00" as *u8,
140 ab_enforce(3, 240, 1200, AB_ALPHA_FLOOR_DEFAULT, AB_RATIO_CAP_DEFAULT), AB_REPORT_ONLY)
141 total = total + 1; pass = pass + pr(logfd, "T9b ruler alpha 0.43 (insult) -> REPORT-ONLY\x00" as *u8,
142 ab_enforce(3, 430, 1200, AB_ALPHA_FLOOR_DEFAULT, AB_RATIO_CAP_DEFAULT), AB_REPORT_ONLY)
143
144 // ---- T10 the ratio bound is independently load-bearing ------------------------------------------
145 total = total + 1; pass = pass + pr(logfd, "T10 alpha fine but 3.9x spread -> REPORT-ONLY\x00" as *u8,
146 ab_enforce(3, 800, 3900, AB_ALPHA_FLOOR_DEFAULT, AB_RATIO_CAP_DEFAULT), AB_REPORT_ONLY)
147 total = total + 1; pass = pass + pr(logfd, "T10b UNBOUNDED spread -> REPORT-ONLY\x00" as *u8,
148 ab_enforce(3, 800, AB_RATIO_UNBOUNDED, AB_ALPHA_FLOOR_DEFAULT, AB_RATIO_CAP_DEFAULT), AB_REPORT_ONLY)
149 total = total + 1; pass = pass + pr(logfd, "T10c UNDEFINED alpha -> REPORT-ONLY\x00" as *u8,
150 ab_enforce(3, AB_UNDEFINED, 1200, AB_ALPHA_FLOOR_DEFAULT, AB_RATIO_CAP_DEFAULT), AB_REPORT_ONLY)
151
152 // ---- T11 ★NON-VACUITY: the verdict CAN succeed ---------------------------------------------------
153 total = total + 1; pass = pass + pr(logfd, "T11 good panel -> ENFORCE\x00" as *u8,
154 ab_enforce(2, 800, 1200, AB_ALPHA_FLOOR_DEFAULT, AB_RATIO_CAP_DEFAULT), AB_ENFORCE)
155
156 // ---- T12 thresholds are PARAMETERS, not baked --------------------------------------------------
157 // the SAME panel that was REPORT-ONLY at the default floor ENFORCEs under a looser caller floor.
158 total = total + 1; pass = pass + pr(logfd, "T12a alpha 430 at floor 600 -> REPORT-ONLY\x00" as *u8,
159 ab_enforce(3, 430, 1200, 600, 2000), AB_REPORT_ONLY)
160 total = total + 1; pass = pass + pr(logfd, "T12b SAME panel at floor 400 -> ENFORCE\x00" as *u8,
161 ab_enforce(3, 430, 1200, 400, 2000), AB_ENFORCE)
162 total = total + 1; pass = pass + pr(logfd, "T12c 3.9x spread under a 4.0x cap -> ENFORCE\x00" as *u8,
163 ab_enforce(3, 800, 3900, 600, 4000), AB_ENFORCE)
164
165 gp(logfd, "AGREEBOUNDGATE \x00" as *u8); gn(logfd, pass)
166 gp(logfd, "/\x00" as *u8); gn(logfd, total)
167 if pass == total { gp(logfd, " verdict=GREEN\n\x00" as *u8); sys_close(logfd); return 0 }
168 gp(logfd, " verdict=RED\n\x00" as *u8)
169 sys_close(logfd)
170 return 1
171}