code wiki / _hdl_build / nx_capaxes_lib.nx
nx_capaxes_lib.nx source
↩ module page · 277 lines · 8963 B
1// nx_capaxes_lib.nx -- CAPABILITY AXIS PROFILE, pure core. No main, no I/O beyond emit helpers.
2//
3// WHY (operator 2026-07-30): "the capabilities census is gamed on coverage to 1000permil but with below toy
4// quality, a case of imbalanced quality and quantity" + "capabilities graph with all the axes where there are
5// between 1 and x and on each axis a measurement happens to see how imbalanced or how things skew in a
6// direction, not just boolean type thinking".
7//
8// MEASURED DISEASE. nx_cap_census emits "torrent 377/1000 HAVE 20 / PARTIAL 6 / GAP 35 vs 0 SOTA-src" and
9// "ECOSYSTEM (3 targets) 527/1000". (1) HAVE/PARTIAL/GAP is a PRESENCE ladder so a toy and a SOTA impl both
10// score HAVE; (2) "vs 0 SOTA-src" = EMPTY comparator, self-referential, can only drift up; (3) 3 targets
11// labelled ECOSYSTEM while the maturity rollup tracks 26 domains. Independently nx_sota_status reports
12// PROVEN 0/40 and lists workermesh cov=1000 gaps=0 INSIDE CLAIM-ONLY -- perfect coverage, zero evidence.
13//
14// LAW L1 -- HEADLINE IS THE MINIMUM, NEVER THE MEAN. Kills coverage-gaming BY CONSTRUCTION. Averaging
15// [coverage 1000, evidence 0] yields ~500 and reads like progress; the minimum yields 0 and reads like the
16// truth. A capability is exactly as good as its WEAKEST axis, because that is the axis a user hits first.
17// cax_mean exists ONLY so the gate can assert headline != mean on a gamed vector: a revert to averaging
18// turns that tooth RED. It must never be the headline.
19//
20// LAW L2 -- GROUNDING ZERO REFUSES TO EMIT A NUMBER. No external reference => UNGROUNDED, never a score,
21// because an ungrounded number is indistinguishable from a measured one once quoted.
22//
23// LAW L3 -- UNMEASURED IS -1, NEVER A SILENT 0, and must never become the minimum.
24//
25// SKEW IS THE PRODUCT, NOT THE SCORE. A balanced 600 profile and a [1000,200] profile can share a mean and
26// are completely different objects: the second is breadth-gamed and starved names its rock.
27// license_tier: ORIGINAL No hw writes (Rule 26).
28import "nx_syscalls.nx"
29
30const CAX_N: i64 = 6
31const CAX_A_COVER: i64 = 0
32const CAX_A_QUALITY: i64 = 1
33const CAX_A_SCALE: i64 = 2
34const CAX_A_EVIDENCE: i64 = 3
35const CAX_A_ADOPT: i64 = 4
36const CAX_A_GROUND: i64 = 5
37const CAX_UNMEASURED: i64 = 0 - 1
38const CAX_FULL: i64 = 1000
39const CAX_BALANCED_PERMIL: i64 = 800
40
41func cax_axis_name(i: i64) -> *u8 {
42 if i == CAX_A_COVER { return "coverage" as *u8 }
43 if i == CAX_A_QUALITY { return "quality" as *u8 }
44 if i == CAX_A_SCALE { return "scale" as *u8 }
45 if i == CAX_A_EVIDENCE { return "evidence" as *u8 }
46 if i == CAX_A_ADOPT { return "adoption" as *u8 }
47 if i == CAX_A_GROUND { return "grounding" as *u8 }
48 return "unknown" as *u8
49}
50
51func cax_measured(v: *i64, n: i64) -> i64 {
52 var c: i64 = 0
53 var i: i64 = 0
54 while i < n {
55 if v[i] != CAX_UNMEASURED { c = c + 1 }
56 i = i + 1
57 }
58 return c
59}
60
61func cax_min_idx(v: *i64, n: i64) -> i64 {
62 var best: i64 = 0 - 1
63 var i: i64 = 0
64 while i < n {
65 if v[i] != CAX_UNMEASURED {
66 if best < 0 { best = i }
67 else { if v[i] < v[best] { best = i } }
68 }
69 i = i + 1
70 }
71 return best
72}
73
74func cax_max_idx(v: *i64, n: i64) -> i64 {
75 var best: i64 = 0 - 1
76 var i: i64 = 0
77 while i < n {
78 if v[i] != CAX_UNMEASURED {
79 if best < 0 { best = i }
80 else { if v[i] > v[best] { best = i } }
81 }
82 i = i + 1
83 }
84 return best
85}
86
87func cax_headline(v: *i64, n: i64) -> i64 {
88 let i: i64 = cax_min_idx(v, n)
89 if i < 0 { return CAX_UNMEASURED }
90 return v[i]
91}
92
93func cax_mean(v: *i64, n: i64) -> i64 {
94 var s: i64 = 0
95 var c: i64 = 0
96 var i: i64 = 0
97 while i < n {
98 if v[i] != CAX_UNMEASURED {
99 s = s + v[i]
100 c = c + 1
101 }
102 i = i + 1
103 }
104 if c == 0 { return CAX_UNMEASURED }
105 return s / c
106}
107
108func cax_skew(v: *i64, n: i64) -> i64 {
109 let lo: i64 = cax_min_idx(v, n)
110 let hi: i64 = cax_max_idx(v, n)
111 if lo < 0 { return CAX_UNMEASURED }
112 return v[hi] - v[lo]
113}
114
115func cax_balance(v: *i64, n: i64) -> i64 {
116 let lo: i64 = cax_min_idx(v, n)
117 let hi: i64 = cax_max_idx(v, n)
118 if lo < 0 { return CAX_UNMEASURED }
119 if v[hi] <= 0 { return CAX_FULL }
120 return v[lo] * CAX_FULL / v[hi]
121}
122
123func cax_grounded(v: *i64, n: i64) -> i64 {
124 if n <= CAX_A_GROUND { return 0 }
125 if v[CAX_A_GROUND] == CAX_UNMEASURED { return 0 }
126 if v[CAX_A_GROUND] <= 0 { return 0 }
127 return 1
128}
129
130func cax_rock(v: *i64, n: i64, leverage: i64) -> i64 {
131 let h: i64 = cax_headline(v, n)
132 if h == CAX_UNMEASURED { return 0 }
133 return (CAX_FULL - h) * leverage
134}
135
136func cax_puts(s: *u8) {
137 var n: i64 = 0
138 while s[n] != (0 as u8) { n = n + 1 }
139 sys_write(1, s, n)
140}
141
142func cax_puti(x: i64) {
143 var buf: *u8 = sys_mmap(64) as *u8
144 var v: i64 = x
145 var neg: i64 = 0
146 if v < 0 {
147 neg = 1
148 v = 0 - v
149 }
150 var i: i64 = 40
151 if v == 0 {
152 i = i - 1
153 buf[i] = 48 as u8
154 }
155 while v > 0 {
156 let d: i64 = v - (v / 10) * 10
157 i = i - 1
158 buf[i] = (d + 48) as u8
159 v = v / 10
160 }
161 if neg == 1 {
162 i = i - 1
163 buf[i] = 45 as u8
164 }
165 sys_write(1, ((buf as i64) + i) as *u8, 40 - i)
166}
167
168// A gate result that lives only in stdout is INVISIBLE to this ecosystem's evidence machinery -- the
169// rollup, the honesty gate and the evidence audit all read knowledge/status/<name>_gate.log. A GREEN
170// gate nothing can read is, to every ruler here, an UNMEASURED capability. This lives at the BASE layer
171// (not in nx_capgraph_lib) because it is generic and because the layer above already imports this one;
172// putting it higher would have forced either a circular import or a duplicated int-writer.
173// Append-only, so verdict history accumulates (rule 13).
174func cax_gate_log(path: *u8, tag: *u8, passed: i64, total: i64) {
175 let fd: i64 = sys_openat_append(path, 0x1A4)
176 if fd < 0 { return }
177 var n: i64 = 0
178 while tag[n] != (0 as u8) { n = n + 1 }
179 sys_write(fd, tag, n)
180 if passed == total { sys_write(fd, " verdict=GREEN passed=" as *u8, 22) }
181 else { sys_write(fd, " verdict=RED passed=" as *u8, 20) }
182 let b: *u8 = sys_mmap(128) as *u8
183 var v: i64 = passed
184 var i: i64 = 40
185 if v == 0 {
186 i = i - 1
187 b[i] = 48 as u8
188 }
189 while v > 0 {
190 let d: i64 = v - (v / 10) * 10
191 i = i - 1
192 b[i] = (d + 48) as u8
193 v = v / 10
194 }
195 sys_write(fd, ((b as i64) + i) as *u8, 40 - i)
196 sys_write(fd, " total=" as *u8, 7)
197 let b2: *u8 = sys_mmap(128) as *u8
198 var v2: i64 = total
199 var j: i64 = 40
200 if v2 == 0 {
201 j = j - 1
202 b2[j] = 48 as u8
203 }
204 while v2 > 0 {
205 let d2: i64 = v2 - (v2 / 10) * 10
206 j = j - 1
207 b2[j] = (d2 + 48) as u8
208 v2 = v2 / 10
209 }
210 sys_write(fd, ((b2 as i64) + j) as *u8, 40 - j)
211 sys_write(fd, "\n" as *u8, 1)
212 sys_close(fd)
213}
214
215func cax_kv(k: *u8, x: i64) {
216 cax_puts(k)
217 cax_puts("=" as *u8)
218 cax_puti(x)
219 cax_puts(" " as *u8)
220}
221
222func cax_atoi(s: *u8) -> i64 {
223 var r: i64 = 0
224 var i: i64 = 0
225 var neg: i64 = 0
226 if s[0] == (45 as u8) {
227 neg = 1
228 i = 1
229 }
230 while s[i] != (0 as u8) {
231 let c: i64 = s[i] as i64
232 if c >= 48 {
233 if c <= 57 {
234 r = r * 10 + (c - 48)
235 }
236 }
237 i = i + 1
238 }
239 if neg == 1 { return 0 - r }
240 return r
241}
242
243func cax_report(v: *i64, n: i64, leverage: i64) -> i64 {
244 var i: i64 = 0
245 cax_puts("CAPAXES " as *u8)
246 while i < n {
247 cax_puts(cax_axis_name(i))
248 cax_puts("=" as *u8)
249 cax_puti(v[i])
250 cax_puts(" " as *u8)
251 i = i + 1
252 }
253 cax_kv("measured" as *u8, cax_measured(v, n))
254 cax_puts("\n" as *u8)
255 if cax_grounded(v, n) == 0 {
256 cax_puts("VERDICT=UNGROUNDED no external reference (grounding<=0) -- refusing to emit a score.\n" as *u8)
257 cax_puts(" L2: an ungrounded number is indistinguishable from a measured one once quoted.\n" as *u8)
258 return 3
259 }
260 let lo: i64 = cax_min_idx(v, n)
261 cax_kv("headline_MIN" as *u8, cax_headline(v, n))
262 cax_kv("skew" as *u8, cax_skew(v, n))
263 cax_kv("balance_permil" as *u8, cax_balance(v, n))
264 cax_puts("starved=" as *u8)
265 cax_puts(cax_axis_name(lo))
266 cax_puts(" " as *u8)
267 cax_kv("rock_score" as *u8, cax_rock(v, n, leverage))
268 cax_kv("mean_NOT_the_headline" as *u8, cax_mean(v, n))
269 cax_puts("\n" as *u8)
270 if cax_balance(v, n) < CAX_BALANCED_PERMIL {
271 cax_puts("VERDICT=SKEWED breadth outruns the weakest axis -- the rock is the starved axis above.\n" as *u8)
272 } else {
273 cax_puts("VERDICT=BALANCED all measured axes within tolerance of each other.\n" as *u8)
274 }
275 cax_puts("envelope: axes=6 scale=0..1000 -1=UNMEASURED(never a silent 0) headline=MIN(L1) ground0=refuse(L2)\n" as *u8)
276 return 0
277}