nx_faceanat_scale_gate.nx source
↩ module page · 173 lines · 9973 B
1// nx_faceanat_scale_gate.nx -- THE REFEREE FOR THE FACE MODEL'S SCALE (aesthetictwin AT17, 2026-09-02).
2//
3// THE DEFECT: nx_faceanat declared MMU = 35 (3.5 units per mm) from a comment that took a 150 mm HALF-width for
4// a skull that is about 145 mm WIDE, and every millimetre the aesthetictwin board publishes, and every tissue
5// relief the face emitter draws, went through that constant. Four witnesses of the model's OWN declared
6// landmarks against the ANSUR II female means say about 7 to 8.7 units per mm -- a 2.2x error that the board
7// carried as an open contradiction since 2026-08-28.
8//
9// THE MECHANISM: knowledge/faceanat_scale.conf carries one WITNESS row per landmark pair (the model's declared
10// span in units, the ANSUR II female mean in tenths of a mm, n, the refs key), one DERIVED row (the median
11// units-per-mm x10 with the min and max of the witnesses) and one SPREAD row (the widest witness disagreement
12// tolerated, permil of the median, with its reasoning beside it in the conf). This gate RECOMPUTES the
13// derivation from the witness rows and holds nx_faceanat's fa_mmu_x10() to it -- a typed constant that drifts
14// from its own derivation cannot pass -- and its neg-control asserts the LEGACY 35 lies OUTSIDE the witness
15// band: the tooth that could not have passed before this rung existed. The population bound the reader prints
16// (a military sample, not a civilian approximation) travels with the number in the conf and in the verdict.
17// THE SPREAD IS A SEPARATE FINDING FROM THE SCALE: the four witnesses disagree by 218 permil (MEASURED live
18// 2026-09-02), which is the model's PROPORTION error landmark to landmark, not its scale. The bar for it is
19// a conf row so it can be RATCHETED DOWN as the proportions are re-fit -- never a literal here that gets
20// loosened to flatter the number.
21// SCOPE: this proves the SCALE. It does not re-baseline the emitted relief -- that is a visual acceptance under
22// the operator's three-party rule and is a separate rung.
23// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
24import "nx_gate_verdict.nx"
25import "nx_faceanat.nx"
26
27const FS_CONF: *u8 = "knowledge/faceanat_scale.conf"
28const FS_MAXW: i64 = 8 // witness rows this gate will read (the conf carries 4 today; a fifth is welcome)
29const FS_MIN_N: i64 = 1000 // a witness mean over fewer subjects than this is not a population reading
30const FS_LEGACY_MMU_X10: i64 = 35 // the typed constant this rung retires from the measurement path
31const FS_TOL_X10: i64 = 1 // the derived literal may differ from the recomputed median by one tenth (integer rounding)
32const FS_X100: i64 = 100
33const FS_PERMIL: i64 = 1000
34const FS_CH_SPACE: i64 = 32
35const FS_CH_NL: i64 = 10
36const FS_CH_0: i64 = 48
37const FS_CH_9: i64 = 57
38const FS_CH_W: i64 = 87
39const FS_CH_D: i64 = 68
40const FS_CH_S: i64 = 83 // the `S <permil>` row: the witness-spread bar lives in the conf with its reasoning, never here
41
42// parse the next decimal integer in [ip[0], e): skips leading spaces, stops at the first non-digit; -1 when none
43func fs_int(b: *u8, e: i64, ip: *i64) -> i64 {
44 var v: i64 = 0
45 var any: i64 = 0
46 var i: i64 = ip[0]
47 var go: i64 = 1
48 while go == 1 {
49 if i >= e { go = 0 }
50 else {
51 let c: i64 = b[i] as i64
52 if c == FS_CH_SPACE { if any == 0 { i = i + 1 } else { go = 0 } }
53 else { if c >= FS_CH_0 { if c <= FS_CH_9 { v = v*10 + (c - FS_CH_0); any = 1; i = i + 1 } else { go = 0 } } else { go = 0 } }
54 }
55 }
56 ip[0] = i
57 if any == 1 { return v }
58 return 0 - 1
59}
60// index of the end of the line that starts at i (the newline, or n)
61func fs_eol(b: *u8, n: i64, i: i64) -> i64 { var j: i64 = i; var f: i64 = n; var go: i64 = 1; while go == 1 { if j >= n { go = 0 } else { if b[j] == (FS_CH_NL as u8) { f = j; go = 0 } else { j = j + 1 } } } return f }
62// index of the first space at or after i within [i, e), or e
63func fs_space(b: *u8, e: i64, i: i64) -> i64 { var j: i64 = i; var f: i64 = e; var go: i64 = 1; while go == 1 { if j >= e { go = 0 } else { if b[j] == (FS_CH_SPACE as u8) { f = j; go = 0 } else { j = j + 1 } } } return f }
64
65func main(argc: i64, argv: *i64) -> i64 {
66 gv_head("nx_faceanat_scale_gate -- the face model's units-per-millimetre is DERIVED from ANSUR II witnesses, never typed" as *u8)
67 let ctr: *i64 = gv_ctr()
68 let lp: *i64 = sys_mmap(16) as *i64
69 let b: *u8 = sys_read_file(FS_CONF, lp)
70 var ok: i64 = 0
71 if (b as i64) != 0 { if lp[0] > 0 { ok = 1 } }
72 if gv_need("conf-readable-knowledge/faceanat_scale.conf" as *u8, ok, ctr) == 0 {
73 return gv_verdict("nx_faceanat_scale_gate" as *u8, ctr, "no conf, no derivation to hold the constant to" as *u8)
74 }
75 let n: i64 = lp[0]
76 // witness rows: W <name> <model_units> <mean_mm_x10> <n> <refkey> derived row: D <mmu_x10> <lo_x10> <hi_x10> spread row: S <permil>
77 let wu: *i64 = sys_mmap(FS_MAXW*8) as *i64
78 let wmm: *i64 = sys_mmap(FS_MAXW*8) as *i64
79 let wn: *i64 = sys_mmap(FS_MAXW*8) as *i64
80 let ip: *i64 = sys_mmap(16) as *i64
81 var nw: i64 = 0
82 var d_val: i64 = 0 - 1
83 var d_lo: i64 = 0 - 1
84 var d_hi: i64 = 0 - 1
85 var s_bar: i64 = 0 - 1
86 var overflow: i64 = 0
87 var i: i64 = 0
88 while i < n {
89 let e: i64 = fs_eol(b, n, i)
90 let c0: i64 = b[i] as i64
91 var tagged: i64 = 0
92 if i + 1 < e { if b[i+1] == (FS_CH_SPACE as u8) { tagged = 1 } }
93 if tagged == 1 {
94 if c0 == FS_CH_W {
95 ip[0] = fs_space(b, e, i + 2) // skip the name token
96 let u: i64 = fs_int(b, e, ip)
97 let mm: i64 = fs_int(b, e, ip)
98 let cnt: i64 = fs_int(b, e, ip)
99 if u > 0 { if mm > 0 { if cnt > 0 {
100 if nw < FS_MAXW { wu[nw] = u; wmm[nw] = mm; wn[nw] = cnt; nw = nw + 1 } else { overflow = 1 }
101 } } }
102 }
103 if c0 == FS_CH_D {
104 ip[0] = i + 2
105 d_val = fs_int(b, e, ip)
106 d_lo = fs_int(b, e, ip)
107 d_hi = fs_int(b, e, ip)
108 }
109 if c0 == FS_CH_S {
110 ip[0] = i + 2
111 s_bar = fs_int(b, e, ip)
112 }
113 }
114 i = e + 1
115 }
116 gv_subjects("scale witnesses read from the conf" as *u8, nw, ctr)
117 gv_check("conf-carries-at-least-three-witnesses" as *u8, nw >= 3, ctr)
118 gv_check("conf-did-not-overflow-the-witness-table" as *u8, overflow == 0, ctr)
119 gv_check("conf-carries-the-derived-row" as *u8, d_val > 0, ctr)
120 gv_check("conf-carries-the-spread-bar-row" as *u8, s_bar > 0, ctr)
121 // recompute every witness: units-per-mm x10 = units x 100 / mean_mm_x10
122 let wx: *i64 = sys_mmap(FS_MAXW*8) as *i64
123 var lo: i64 = 0
124 var hi: i64 = 0
125 var allpop: i64 = 1
126 var k: i64 = 0
127 while k < nw {
128 wx[k] = wu[k] * FS_X100 / wmm[k]
129 if k == 0 { lo = wx[k]; hi = wx[k] }
130 if wx[k] < lo { lo = wx[k] }
131 if wx[k] > hi { hi = wx[k] }
132 if wn[k] < FS_MIN_N { allpop = 0 }
133 gv_puts(" witness " as *u8); gv_num(k); gv_puts(": model_units=" as *u8); gv_num(wu[k]); gv_puts(" ansur_mean_mm_x10=" as *u8); gv_num(wmm[k]); gv_puts(" n=" as *u8); gv_num(wn[k]); gv_puts(" -> units_per_mm_x10=" as *u8); gv_num(wx[k]); gv_puts("\n" as *u8)
134 k = k + 1
135 }
136 gv_check("every-witness-is-a-population-reading-n>=1000" as *u8, allpop == 1, ctr)
137 // median: insertion sort over at most FS_MAXW values
138 var a: i64 = 1
139 while a < nw {
140 var bb: i64 = a
141 var go: i64 = 1
142 while go == 1 {
143 if bb <= 0 { go = 0 }
144 else { if wx[bb-1] > wx[bb] { let t: i64 = wx[bb-1]; wx[bb-1] = wx[bb]; wx[bb] = t; bb = bb - 1 } else { go = 0 } }
145 }
146 a = a + 1
147 }
148 var med: i64 = 0
149 if nw > 0 { if nw % 2 == 1 { med = wx[nw/2] } else { med = (wx[nw/2 - 1] + wx[nw/2]) / 2 } }
150 let live: i64 = fa_mmu_x10()
151 var spread_permil: i64 = 0
152 if med > 0 { spread_permil = (hi - lo) * FS_PERMIL / med }
153 gv_puts(" recomputed median_x10=" as *u8); gv_num(med); gv_puts(" band_x10=[" as *u8); gv_num(lo); gv_puts("," as *u8); gv_num(hi); gv_puts("] conf_derived=" as *u8); gv_num(d_val); gv_puts(" conf_band=[" as *u8); gv_num(d_lo); gv_puts("," as *u8); gv_num(d_hi); gv_puts("] faceanat_fa_mmu_x10=" as *u8); gv_num(live); gv_puts(" legacy=" as *u8); gv_num(FS_LEGACY_MMU_X10); gv_puts(" spread_permil=" as *u8); gv_num(spread_permil); gv_puts(" conf_spread_bar=" as *u8); gv_num(s_bar); gv_puts("\n" as *u8)
154 var dm: i64 = d_val - med
155 if dm < 0 { dm = 0 - dm }
156 gv_check("conf-derived-value-equals-the-recomputed-median" as *u8, dm <= FS_TOL_X10, ctr)
157 var band_ok: i64 = 0
158 if d_lo == lo { if d_hi == hi { band_ok = 1 } }
159 gv_check("conf-band-equals-the-recomputed-min-max" as *u8, band_ok == 1, ctr)
160 var fm: i64 = live - med
161 if fm < 0 { fm = 0 - fm }
162 gv_check("nx_faceanat-fa_mmu_x10-equals-the-derivation" as *u8, fm <= FS_TOL_X10, ctr)
163 var inside: i64 = 0
164 if live >= lo { if live <= hi { inside = 1 } }
165 gv_check("derived-value-lies-inside-the-witness-band" as *u8, inside == 1, ctr)
166 gv_check("witnesses-agree-within-the-conf-spread-bar" as *u8, (hi - lo) * FS_PERMIL <= med * s_bar, ctr)
167 var legacy_out: i64 = 0
168 if FS_LEGACY_MMU_X10 < lo { legacy_out = 1 }
169 if FS_LEGACY_MMU_X10 > hi { legacy_out = 1 }
170 gv_check("neg-control-legacy-35-lies-OUTSIDE-the-witness-band" as *u8, legacy_out == 1, ctr)
171 gv_check("legacy-constant-is-quarantined-to-relief-not-measurement" as *u8, fa_mmu_relief_legacy_x10() == FS_LEGACY_MMU_X10, ctr)
172 return gv_verdict("nx_faceanat_scale_gate" as *u8, ctr, "units-per-mm derived from ANSUR II female witnesses (military sample, not a civilian approximation); the legacy 35 fails the band it was typed against; the spread bar is a conf row to ratchet" as *u8)
173}