nx_chargen_param_gate.nx source
↩ module page · 256 lines · 12837 B
1// nx_chargen_param_gate.nx -- CHARACTER-GEN-PARAMETRIC: a parameter vector becomes a DISTINCT,
2// VALID character, reproducibly, across a RANGE -- proven end-to-end on the PROMOTED generator.
3//
4// WHY THIS GATE EXISTS (measured 2026-08-23, not assumed). nx_gamebench row 22
5// (character-gen-parametric, capv[22]=1 PARTIAL) was the board's LAST gap and the entire
6// gap_queue. It is also the ONLY capability row in the whole board carrying NO reason: every
7// neighbour that reached HAVE cites the same shape -- "flipped GAP->HAVE <date>: <organ>
8// (certified part) + <gate> N/N GREEN, mutation-proven (<the mutant that drove it RED>)".
9// nx_catalog measured the actual gap: the generators are LIVE (nx_body_gen PROMOTED+REGISTERED
10// 77455 B, nx_body_proc PROMOTED+REGISTERED 75120 B) while nx_body_proc_gate / nx_bodygen_gate /
11// nx_charactergen_gate are ALL **ABSENT**. The capability was never the missing thing; the proof
12// binding it to the board was. This gate is that binding.
13//
14// Subject: ./nx_body_gen.elf -- the SERVING-ROOT binary, forked e2e (never an in-process
15// re-derive) through gk_run_capture, the estate's deadlock-proven subprocess primitive. A
16// hand-rolled pipe/fork/wait in a sibling gate wedged for 50+ minutes in production today
17// (pid 2240, utime=0, wchan=pipe_wait, artifact frozen at its header): fixtures and subprocess
18// come from nx_gatekit_lib, and this gate never re-rolls them.
19//
20// EVERY BOUND HERE IS READ OR MEASURED, NONE IS PICKED:
21// * N (how many characters) is READ from the reference corpus that DEFINES validity
22// (knowledge/rigfloor_msh.conf n_read). The generated set must be able to express at least
23// the width of the corpus that defines "valid"; a smaller N could not.
24// * the validity band (tris/parts) is READ from that same conf -- the floor organ owns those
25// numbers, this gate restates none of them.
26// * the radial sweep range is DERIVED AT RUNTIME from the generator's OWN reported defaults
27// (a probe run with radial omitted makes the organ report radial0/tris0), scaled onto the
28// floor's band. That linear sampling model is a HEURISTIC FOR CHOOSING SAMPLES ONLY -- its
29// correctness is not assumed, it is CHECKED by the in-band tooth on every generated asset.
30
31import "nx_syscalls.nx"
32import "nx_gate_verdict.nx"
33import "nx_gatekit_lib.nx"
34
35const CG_ELF: *u8 = "./nx_body_gen.elf"
36const CG_DIR: *u8 = "/tmp/nxcgp"
37const CG_CONF: *u8 = "knowledge/rigfloor_msh.conf"
38const CG_CAP: i64 = 65536
39const CG_MAXN: i64 = 64
40
41// HEIGHT IS THE CONTROL VARIABLE, NOT A BOUND. It is held FIXED across every vector so that all
42// measured difference is attributable to the VARIED axis (radial). Holding a control constant is
43// what makes an experiment attributable; nothing is ever compared against this value.
44const CG_H: *u8 = "1700"
45
46func cg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
47
48// first integer after `key`, ANCHORED on the key (never a bare scan of the buffer)
49func cg_num_after(buf: *u8, n: i64, key: *u8) -> i64 {
50 let kl: i64 = cg_slen(key)
51 var i: i64 = 0
52 while i + kl < n {
53 var j: i64 = 0
54 var hit: i64 = 1
55 while j < kl { if buf[i+j] != key[j] { hit = 0; j = kl } else { j = j + 1 } }
56 if hit == 1 {
57 var p: i64 = i + kl
58 var v: i64 = 0
59 var got: i64 = 0
60 while p < n {
61 let c: i64 = buf[p] as i64
62 if c >= 48 {
63 if c <= 57 { v = v * 10 + (c - 48); got = 1; p = p + 1 } else { p = n }
64 } else { p = n }
65 }
66 if got == 1 { return v }
67 return 0 - 1
68 }
69 i = i + 1
70 }
71 return 0 - 1
72}
73
74func cg_itoa(v: i64, out: *u8) -> *u8 {
75 if v == 0 { out[0] = (48 as u8); out[1] = (0 as u8); return out }
76 var d: i64 = 0
77 var t: i64 = v
78 while t > 0 { d = d + 1; t = t / 10 }
79 out[d] = (0 as u8)
80 var n: i64 = v
81 var i: i64 = d - 1
82 while i >= 0 { out[i] = ((48 + (n % 10)) as u8); n = n / 10; i = i - 1 }
83 return out
84}
85
86// read a `key=<int>` row out of a conf file (the floor organ OWNS these numbers)
87func cg_conf_num(key: *u8) -> i64 {
88 let lp: *i64 = sys_mmap(16) as *i64
89 let b: *u8 = sys_read_file(CG_CONF, lp)
90 if (b as i64) == 0 { return 0 - 1 }
91 return cg_num_after(b, lp[0], key)
92}
93
94func cg_same(a: *u8, b: *u8) -> i64 {
95 let la: *i64 = sys_mmap(16) as *i64
96 let lb: *i64 = sys_mmap(16) as *i64
97 let ba: *u8 = sys_read_file(a, la)
98 let bb: *u8 = sys_read_file(b, lb)
99 if (ba as i64) == 0 { return 0 }
100 if (bb as i64) == 0 { return 0 }
101 if la[0] != lb[0] { return 0 }
102 var i: i64 = 0
103 let n: i64 = la[0]
104 while i < n { if ba[i] != bb[i] { return 0 } i = i + 1 }
105 return 1
106}
107
108// generate one character: <out> <height> [radial]. radial<0 => omit it, so the ORGAN reports its
109// own defaults (that is how the sweep range is derived instead of picked).
110func cg_gen(out: *u8, radial: i64, buf: *u8, bl: *i64, sbuf: *u8) -> i64 {
111 if radial < 0 { return gk_run_capture(CG_ELF, out, CG_H, 0 as *u8, 0 as *u8, buf, CG_CAP, bl) }
112 let rs: *u8 = cg_itoa(radial, sbuf)
113 return gk_run_capture(CG_ELF, out, CG_H, rs, 0 as *u8, buf, CG_CAP, bl)
114}
115
116func main(argc: i64, argv: *i64) -> i64 {
117 gv_head("nx_chargen_param_gate -- a parameter vector becomes a distinct, valid character, reproducibly" as *u8)
118 let ctr: *i64 = gv_ctr()
119 sys_mkdir(CG_DIR, 493)
120
121 let buf: *u8 = sys_mmap(CG_CAP) as *u8
122 let bl: *i64 = sys_mmap(16) as *i64
123 let sbuf: *u8 = sys_mmap(64) as *u8
124 let pbuf: *u8 = sys_mmap(256) as *u8
125
126 // ---- the ruler: the DERIVED floor owns every validity number ----------------------------
127 let n_ref: i64 = cg_conf_num("n_read=" as *u8)
128 let tmin: i64 = cg_conf_num("tris_min=" as *u8)
129 let tmax: i64 = cg_conf_num("tris_max=" as *u8)
130 let pmin: i64 = cg_conf_num("parts_min=" as *u8)
131 let pmax: i64 = cg_conf_num("parts_max=" as *u8)
132 gv_puts(" floor conf: n_read=" as *u8); gv_num(n_ref)
133 gv_puts(" tris=[" as *u8); gv_num(tmin); gv_puts("," as *u8); gv_num(tmax)
134 gv_puts("] parts=[" as *u8); gv_num(pmin); gv_puts("," as *u8); gv_num(pmax); gv_puts("]\n" as *u8)
135 var confok: i64 = 0
136 if n_ref > 0 { if tmin > 0 { if tmax > tmin { if pmax >= pmin { confok = 1 } } } }
137 gv_check("derived-floor-conf-readable (this gate restates no validity number)" as *u8, confok, ctr)
138
139 // ---- probe: the ORGAN reports its own defaults; the sweep is derived from them -----------
140 let rcp: i64 = cg_gen("/tmp/nxcgp/probe.nxmesh" as *u8, 0 - 1, buf, bl, sbuf)
141 let r0: i64 = cg_num_after(buf, bl[0], "\"radial\":" as *u8)
142 let t0: i64 = cg_num_after(buf, bl[0], "\"tris\":" as *u8)
143 gv_puts(" probe defaults: radial0=" as *u8); gv_num(r0)
144 gv_puts(" tris0=" as *u8); gv_num(t0); gv_puts(" rc=" as *u8); gv_num(rcp); gv_puts("\n" as *u8)
145 var probeok: i64 = 0
146 if rcp == 0 { if r0 > 0 { if t0 > 0 { probeok = 1 } } }
147 gv_check("probe-run-reports-the-organs-OWN-defaults (fixture reached the condition)" as *u8, probeok, ctr)
148
149 // sweep range derived from the probe measurement scaled onto the floor's band.
150 // SAMPLING HEURISTIC ONLY: correctness is checked per-asset by the in-band tooth below.
151 // CEILING on the low end, FLOOR on the high end. The band is a CLOSED interval, so a sample
152 // chosen by truncation on the low side lands BELOW tris_min by construction -- measured on the
153 // first live run: radial=2 -> tris=3072 < tris_min=4033, and the in-band tooth caught it.
154 // Rounding each end INTO the interval is the correct arithmetic for choosing samples; the BAND
155 // ITSELF IS UNTOUCHED (this widens nothing -- it stops the sampler from stepping outside).
156 var rlo: i64 = (r0 * tmin + t0 - 1) / t0
157 var rhi: i64 = (r0 * tmax) / t0
158 if rlo < 1 { rlo = 1 }
159 var N: i64 = n_ref
160 if N > CG_MAXN { N = CG_MAXN }
161 var step: i64 = 0
162 if N > 1 { step = (rhi - rlo) / (N - 1) }
163 if step < 1 { step = 1 }
164 gv_puts(" derived sweep: N=" as *u8); gv_num(N)
165 gv_puts(" radial in [" as *u8); gv_num(rlo); gv_puts("," as *u8); gv_num(rhi)
166 gv_puts("] step=" as *u8); gv_num(step); gv_puts("\n" as *u8)
167
168 // ---- generate the population -------------------------------------------------------------
169 let tris: *i64 = sys_mmap(CG_MAXN * 8) as *i64
170 let parts: *i64 = sys_mmap(CG_MAXN * 8) as *i64
171 let rads: *i64 = sys_mmap(CG_MAXN * 8) as *i64
172 var i: i64 = 0
173 var n_ok: i64 = 0
174 var inband: i64 = 0
175 while i < N {
176 let rr: i64 = rlo + i * step
177 var op: *u8 = pbuf
178 op[0] = (47 as u8); op[1] = (116 as u8); op[2] = (109 as u8); op[3] = (112 as u8)
179 op[4] = (47 as u8); op[5] = (110 as u8); op[6] = (120 as u8); op[7] = (99 as u8)
180 op[8] = (103 as u8); op[9] = (112 as u8); op[10] = (47 as u8); op[11] = (99 as u8)
181 var ds: *u8 = sys_mmap(32) as *u8
182 let dd: *u8 = cg_itoa(i, ds)
183 var k: i64 = 0
184 while dd[k] != (0 as u8) { op[12 + k] = dd[k]; k = k + 1 }
185 op[12 + k] = (46 as u8); op[13 + k] = (110 as u8); op[14 + k] = (120 as u8)
186 op[15 + k] = (109 as u8); op[16 + k] = (0 as u8)
187 let rc: i64 = cg_gen(op, rr, buf, bl, sbuf)
188 let tv: i64 = cg_num_after(buf, bl[0], "\"tris\":" as *u8)
189 let pv: i64 = cg_num_after(buf, bl[0], "\"parts\":" as *u8)
190 rads[i] = rr; tris[i] = tv; parts[i] = pv
191 if rc == 0 { n_ok = n_ok + 1 }
192 var ib: i64 = 0
193 if tv >= tmin { if tv <= tmax { if pv >= pmin { if pv <= pmax { ib = 1 } } } }
194 inband = inband + ib
195 gv_puts(" [" as *u8); gv_num(i); gv_puts("] radial=" as *u8); gv_num(rr)
196 gv_puts(" tris=" as *u8); gv_num(tv); gv_puts(" parts=" as *u8); gv_num(pv)
197 gv_puts(" in_band=" as *u8); gv_num(ib); gv_puts("\n" as *u8)
198 i = i + 1
199 }
200 gv_puts(" generated n_ok=" as *u8); gv_num(n_ok)
201 gv_puts(" in_band=" as *u8); gv_num(inband); gv_puts(" of N=" as *u8); gv_num(N); gv_puts("\n" as *u8)
202
203 // count bound IN the condition: an empty or short population CANNOT pass
204 var genok: i64 = 0
205 if N > 1 { if n_ok == N { if N == n_ref { genok = 1 } } }
206 gv_check("every-declared-vector-generated (n_ok==N==corpus n_read; empty set cannot pass)" as *u8, genok, ctr)
207
208 var bandok: i64 = 0
209 if N > 1 { if inband == N { bandok = 1 } }
210 gv_check("every-generated-character-IN-BAND-on-the-derived-floor" as *u8, bandok, ctr)
211
212 // ---- ANTI-VACUITY: distinct vectors must give distinct characters ------------------------
213 // A generator that ignores its parameters returns the SAME character for every vector; it
214 // would pass every tooth above and fail exactly here. Pairwise over the FULL population.
215 var dup: i64 = 0
216 var a: i64 = 0
217 while a < N {
218 var b: i64 = a + 1
219 while b < N {
220 if tris[a] == tris[b] { dup = dup + 1 }
221 b = b + 1
222 }
223 a = a + 1
224 }
225 var tw: i64 = 0
226 if N > 1 { tw = tris[N-1] - tris[0] }
227 if tw < 0 { tw = 0 - tw }
228 gv_puts(" distinctness: duplicate_pairs=" as *u8); gv_num(dup)
229 gv_puts(" tris_width=" as *u8); gv_num(tw); gv_puts("\n" as *u8)
230 var distok: i64 = 0
231 if N > 1 { if dup == 0 { if tw > 0 { distok = 1 } } }
232 gv_check("distinct-vectors-produce-DISTINCT-characters (0 duplicate pairs, nonzero width)" as *u8, distok, ctr)
233
234 // ---- reproducibility: the same vector must reproduce the same bytes ----------------------
235 let rcr: i64 = cg_gen("/tmp/nxcgp/repro.nxmesh" as *u8, rlo, buf, bl, sbuf)
236 var reprook: i64 = 0
237 if rcr == 0 { reprook = cg_same("/tmp/nxcgp/repro.nxmesh" as *u8, "/tmp/nxcgp/c0.nxm" as *u8) }
238 gv_check("same-vector-reproduces-BYTE-IDENTICAL (deterministic generation)" as *u8, reprook, ctr)
239
240 // ---- neg-control: a DEGENERATE sweep (one vector repeated) must FAIL distinctness ---------
241 var dupd: i64 = 0
242 var q: i64 = 0
243 while q < N {
244 let rcd: i64 = cg_gen("/tmp/nxcgp/deg.nxmesh" as *u8, rlo, buf, bl, sbuf)
245 let tvd: i64 = cg_num_after(buf, bl[0], "\"tris\":" as *u8)
246 if tvd == tris[0] { dupd = dupd + 1 }
247 q = q + 1
248 }
249 gv_puts(" neg-control degenerate sweep: identical_results=" as *u8); gv_num(dupd)
250 gv_puts(" of " as *u8); gv_num(N); gv_puts(" (an identity generator looks exactly like this)\n" as *u8)
251 // fired-on-bad: the degenerate set IS all-identical (distinctness would fail on it).
252 // fired-on-good: the real varied set is NOT all-identical.
253 gv_bite("neg-control-degenerate-generator-detected" as *u8, dupd == N, dup > 0, ctr)
254
255 return gv_verdict("NX-CHARGEN-PARAM" as *u8, ctr, "a parameter vector becomes a distinct, valid, reproducible character across a corpus-sized range" as *u8)
256}