nx_skin_ita_gate.nx source
↩ module page · 147 lines · 6610 B
1// nx_skin_ita_gate.nx -- GATE for genome-driven skin albedo (charsim R0).
2// The tooth that matters is T5: the SAME baker with two different genomes must emit DIFFERENT skin.
3// The incumbent (twelve hardcoded sRGB constants) passes every other tooth here and FAILS that one --
4// so this gate is calibrated to fail the thing it replaced, not merely to agree with what it kept.
5// T4 is the anti-vacuity tooth: a locus that produced one skin tone would satisfy monotonicity and
6// round-tripping perfectly while spanning none of the published classification.
7// Neg-controls named neg-control-* so the gate-law census can see them.
8// license_tier: ORIGINAL expect_exit: 0
9import "nx_syscalls.nx"
10import "nx_skin_ita.nx"
11import "nx_gate_verdict.nx"
12
13// nx_eink_tone's own banked known answer: sRGB 128 -> linear 21586 -> L* 53.59
14const SG_ANCHOR_BYTE: i64 = 128
15const SG_ANCHOR_LSTAR: i64 = 53590
16const SG_LTOL: i64 = 300 // 0.3 L* -- covers the fixed-point residue, far under one class
17const SG_RTOL: i64 = 1200 // 1.2 L* -- covers 8-bit quantisation on the round trip
18const SG_STEPS: i64 = 20
19const SG_HUE_MAX: i64 = 1000
20const SG_UNDER: i64 = 0 - 500
21const SG_OVER: i64 = 5000
22const SG_BYTES: i64 = 256
23
24func sg_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
25
26func main(argc: i64, argv: *i64) -> i64 {
27 let ctr: *i64 = gv_ctr()
28 gv_head("nx_skin_ita -- skin albedo derived from the genome through the published ITA standard" as *u8)
29
30 let rgb: *i64 = sys_mmap(SG_BYTES) as *i64
31 let rgb2: *i64 = sys_mmap(SG_BYTES) as *i64
32 gv_puts(" locus model version = " as *u8); gv_num(si_model_version()); gv_puts("\n" as *u8)
33
34 // T1 -- KNOWN ANSWER, shared with nx_eink_tone. Two organs, one number, no fork needed.
35 let la: i64 = si_lstar_of_byte(SG_ANCHOR_BYTE, SG_ANCHOR_BYTE, SG_ANCHOR_BYTE)
36 var t1: i64 = 0
37 if sg_abs(la - SG_ANCHOR_LSTAR) <= SG_LTOL { t1 = 1 }
38 gv_puts(" anchor L*x1000 = " as *u8); gv_num(la); gv_puts("\n" as *u8)
39 gv_check("T1 sRGB 128 reproduces the banked L* 53.59 anchor" as *u8, t1, ctr)
40
41 // T2 -- the transfer is its own inverse over the whole 8-bit domain (no rival curve, no drift)
42 var t2: i64 = 1
43 var s: i64 = 0
44 while s < SG_BYTES {
45 if si_byte_of_linear(si_linear_of_byte(s)) != s { t2 = 0 }
46 s = s + 1
47 }
48 gv_check("T2 byte -> linear -> byte is exact for all 256 codes" as *u8, t2, ctr)
49
50 // T3 -- lightness rises monotonically with the genome trait
51 var t3: i64 = 1
52 var prev: i64 = 0 - SG_OVER
53 var i: i64 = 0
54 while i <= SG_STEPS {
55 let hue: i64 = i * SG_HUE_MAX / SG_STEPS
56 let l: i64 = si_lstar_of_gene(hue, 0)
57 if l <= prev { t3 = 0 }
58 prev = l
59 i = i + 1
60 }
61 gv_check("T3 L* is strictly monotonic in the genome hue trait" as *u8, t3, ctr)
62
63 // T4 -- ANTI-VACUITY: the sweep must reach every published ITA class, not just vary a little
64 let seen: *i64 = sys_mmap(SI_NCLASS * 8) as *i64
65 var c: i64 = 0
66 while c < SI_NCLASS { seen[c] = 0; c = c + 1 }
67 i = 0
68 while i <= SG_STEPS {
69 let hue2: i64 = i * SG_HUE_MAX / SG_STEPS
70 let cl: i64 = si_class_of_lstar(si_lstar_of_gene(hue2, 0))
71 if cl >= 0 { if cl < SI_NCLASS { seen[cl] = 1 } }
72 i = i + 1
73 }
74 var t4: i64 = 1
75 var nseen: i64 = 0
76 c = 0
77 while c < SI_NCLASS {
78 if seen[c] == 0 { t4 = 0 } else { nseen = nseen + 1 }
79 c = c + 1
80 }
81 gv_puts(" ITA classes reached = " as *u8); gv_num(nseen)
82 gv_puts(" of " as *u8); gv_num(SI_NCLASS); gv_puts("\n" as *u8)
83 gv_check("T4 anti-vacuity: the hue sweep spans all six published ITA classes" as *u8, t4, ctr)
84
85 // T5 -- THE CAPABILITY. Different genomes MUST emit different skin. The twelve-constant
86 // incumbent fails exactly here and nowhere else.
87 si_albedo_of_gene(0, 0, rgb)
88 si_albedo_of_gene(SG_HUE_MAX, 0, rgb2)
89 var t5: i64 = 0
90 if rgb[0] != rgb2[0] { t5 = 1 }
91 if rgb[1] != rgb2[1] { t5 = 1 }
92 if rgb[2] != rgb2[2] { t5 = 1 }
93 gv_puts(" darkest rgb = " as *u8); gv_num(rgb[0]); gv_puts("," as *u8); gv_num(rgb[1])
94 gv_puts("," as *u8); gv_num(rgb[2])
95 gv_puts(" lightest rgb = " as *u8); gv_num(rgb2[0]); gv_puts("," as *u8); gv_num(rgb2[1])
96 gv_puts("," as *u8); gv_num(rgb2[2]); gv_puts("\n" as *u8)
97 gv_check("T5 the genome actually drives the albedo (the incumbent fails this)" as *u8, t5, ctr)
98
99 // T6 -- region offsets order correctly in the perceptual axis
100 let lf: i64 = si_lstar_of_gene(SG_HUE_MAX/2, si_dl_of_region(0))
101 let lt: i64 = si_lstar_of_gene(SG_HUE_MAX/2, si_dl_of_region(1))
102 let ll: i64 = si_lstar_of_gene(SG_HUE_MAX/2, si_dl_of_region(2))
103 let lg: i64 = si_lstar_of_gene(SG_HUE_MAX/2, si_dl_of_region(3))
104 var t6: i64 = 0
105 if lf > lt { if lt > lg { if lg > ll { t6 = 1 } } }
106 gv_check("T6 region lightness orders face > torso > gens > limbs" as *u8, t6, ctr)
107
108 // T7 -- Lab -> sRGB -> L* is self-consistent inside 8-bit quantisation
109 var t7: i64 = 1
110 i = 0
111 while i <= SG_STEPS {
112 let hue3: i64 = i * SG_HUE_MAX / SG_STEPS
113 let want: i64 = si_lstar_of_gene(hue3, 0)
114 si_albedo_of_gene(hue3, 0, rgb)
115 let got: i64 = si_lstar_of_byte(rgb[0], rgb[1], rgb[2])
116 if sg_abs(got - want) > SG_RTOL { t7 = 0 }
117 i = i + 1
118 }
119 gv_check("T7 the emitted colour reads back at the L* it was asked for" as *u8, t7, ctr)
120
121 // T8 -- neg-control: out-of-range genome clamps, never wraps into a different skin
122 si_albedo_of_gene(SG_UNDER, 0, rgb)
123 si_albedo_of_gene(0, 0, rgb2)
124 var t8: i64 = 1
125 if rgb[0] != rgb2[0] { t8 = 0 }
126 if rgb[1] != rgb2[1] { t8 = 0 }
127 if rgb[2] != rgb2[2] { t8 = 0 }
128 si_albedo_of_gene(SG_OVER, 0, rgb)
129 si_albedo_of_gene(SG_HUE_MAX, 0, rgb2)
130 if rgb[0] != rgb2[0] { t8 = 0 }
131 if rgb[1] != rgb2[1] { t8 = 0 }
132 if rgb[2] != rgb2[2] { t8 = 0 }
133 gv_check("T8 neg-control-clamp: an out-of-range genome clamps, never wraps" as *u8, t8, ctr)
134
135 // T9 -- neg-control: the same genome twice is bit-identical (replay/lockstep safe)
136 si_albedo_of_gene(SG_HUE_MAX/3, si_dl_of_region(2), rgb)
137 si_albedo_of_gene(SG_HUE_MAX/3, si_dl_of_region(2), rgb2)
138 var t9: i64 = 1
139 if rgb[0] != rgb2[0] { t9 = 0 }
140 if rgb[1] != rgb2[1] { t9 = 0 }
141 if rgb[2] != rgb2[2] { t9 = 0 }
142 gv_check("T9 neg-control-determinism: one genome yields one skin, always" as *u8, t9, ctr)
143
144 let rc: i64 = gv_verdict("SKIN-ITA" as *u8, ctr, "genome-driven albedo on the published ITA standard" as *u8)
145 sys_exit(rc)
146 return rc
147}