nx_shorebird_gate.nx source
↩ module page · 218 lines · 13419 B
1// nx_shorebird_gate.nx -- PG37: THE FIRST ANIMAL, HONESTLY A GULL, IS A CANON ROW OVER THE ONE BIRD PLAN.
2//
3// SUBJECT: nx_creaturegen.cg_shorebird / cg_bird_row_posed (in-process). The rung's done-rule in its own words:
4// two different seeds produce measurably different gulls on the existing diversity ruler, the gull is distinct
5// from every existing bird row on the same ruler, and a canon table without the gull row emits no gull. The
6// ruler is the one nx_diversity_gate T3 composes -- anatstack_render at the ruler's own view and base colour,
7// then pairwise L1 over the pixel buffer -- with the ruler's own species bar. Every value is emitted with gv_kv
8// so a second method can recompute it from the declared inputs. Fixtures are arithmetic: no filesystem state.
9import "nx_syscalls.nx"
10import "nx_gate_verdict.nx"
11import "nx_creaturegen.nx"
12const SG_SEED_A: i64 = 4 // the diversity ruler's own seed
13const SG_SEED_B: i64 = 5
14const SG_SEED_C: i64 = 17
15const SG_YAW: i64 = 4800 // the ruler's bird view
16const SG_CAMZ: i64 = 3
17const SG_MAXLAYER: i64 = 1
18const SG_INFLATE: i64 = 42
19const SG_BASE_R: i64 = 140 // the ruler's bird base colour
20const SG_BASE_G: i64 = 96
21const SG_BASE_B: i64 = 58
22const SG_SPECIES_BAR: i64 = 150000 // nx_diversity_gate T2: below this L1 two renders are NOT distinct species
23const SG_PARTS_CAP: i64 = 96 // the ruler's part-table capacity
24const SG_BG: i64 = 2890778 // 26 + 28*256 + 44*65536, anatstack_render's background word
25const SG_TIP_PARTS: i64 = 2
26const SG_FK_EXTRA: i64 = 2 // a posed leg is two capsules, the static leg one
27const SG_WALK_THIGH: i64 = 400 // it4096 walk pose
28const SG_WALK_SHIN: i64 = 200
29const SG_SENTINEL: i64 = 424242
30const SG_NSEEDS: i64 = 3
31const SG_BYTE: i64 = 255
32const SG_BIG: i64 = 1000000000
33
34// the ruler's L1, as nx_diversity_gate spells it (low byte of each pixel word)
35func sg_l1(a: *i64, b: *i64, n: i64) -> i64 { var s: i64 = 0; var i: i64 = 0; while i < n { var d: i64 = (a[i] & SG_BYTE) - (b[i] & SG_BYTE); if d < 0 { d = 0 - d } s = s + d; i = i + 1 } return s }
36func sg_ptab_eq(a: *i64, b: *i64, n: i64) -> i64 { var k: i64 = 0; while k < n*AS_STRIDE { if a[k] != b[k] { return 0 } k = k + 1 } return 1 }
37func sg_render(P: *i64, n: i64, fb: *i64) -> i64 { return anatstack_render(P, n, SG_YAW, SG_CAMZ, SG_MAXLAYER, SG_INFLATE, SG_BASE_R, SG_BASE_G, SG_BASE_B, fb) }
38func sg_alloc() -> *i64 { return sys_mmap(SG_PARTS_CAP*AS_STRIDE*8) as *i64 }
39func sg_fb() -> *i64 { return sys_mmap(as_w()*as_h()*8) as *i64 }
40// foreground pixel statistics: out[0]=count, out[1]=sum of the mean channel, out[2]=sum of (max-min channel)
41func sg_fg(fb: *i64, npx: i64, out: *i64) -> i64 {
42 var c: i64 = 0; var ls: i64 = 0; var ss: i64 = 0
43 var i: i64 = 0
44 while i < npx {
45 let v: i64 = fb[i]
46 if v != SG_BG {
47 let r: i64 = v & SG_BYTE; let g: i64 = (v >> 8) & SG_BYTE; let b: i64 = (v >> 16) & SG_BYTE
48 var mx: i64 = r; if g > mx { mx = g } if b > mx { mx = b }
49 var mn: i64 = r; if g < mn { mn = g } if b < mn { mn = b }
50 c = c + 1; ls = ls + (r + g + b)/3; ss = ss + (mx - mn)
51 }
52 i = i + 1
53 }
54 out[0] = c; out[1] = ls; out[2] = ss
55 return 0
56}
57// legs in a part table: capsules whose colour word is the row's leg colour -- out[0]=count, out[1]=lowest far-end y,
58// out[2]=highest far-end y; feet = FEATURE ellipsoids of that colour -- out[3]=count, out[4]=min cz, out[5]=max cz,
59// out[6]=min cy, out[7]=max cy
60func sg_legs(P: *i64, n: i64, leg_rgb: i64, out: *i64) -> i64 {
61 let feat: i64 = leg_rgb + AS_FEAT
62 var lc: i64 = 0; var lo: i64 = SG_BIG; var hi: i64 = 0 - SG_BIG
63 var fc: i64 = 0; var zlo: i64 = SG_BIG; var zhi: i64 = 0 - SG_BIG; var ylo: i64 = SG_BIG; var yhi: i64 = 0 - SG_BIG
64 var k: i64 = 0
65 while k < n {
66 let b: i64 = k*AS_STRIDE
67 if P[b+1] == AS_CAPS { if P[b+11] == leg_rgb { lc = lc + 1; if P[b+9] < lo { lo = P[b+9] } if P[b+9] > hi { hi = P[b+9] } } }
68 if P[b+1] == AS_ELLIP { if P[b+11] == feat { fc = fc + 1; if P[b+4] < zlo { zlo = P[b+4] } if P[b+4] > zhi { zhi = P[b+4] } if P[b+3] < ylo { ylo = P[b+3] } if P[b+3] > yhi { yhi = P[b+3] } } }
69 k = k + 1
70 }
71 out[0] = lc; out[1] = lo; out[2] = hi; out[3] = fc; out[4] = zlo; out[5] = zhi; out[6] = ylo; out[7] = yhi
72 return 0
73}
74
75func main() -> i64 {
76 let ctr: *i64 = gv_ctr()
77 gv_head("=== NX-SHOREBIRD gate (PG37): the gull is a canon row over the one bird plan, judged on the diversity ruler ===" as *u8)
78 let t: *i64 = cg_bird_canon()
79 let rows: i64 = cg_bird_canon_rows()
80 let rg: i64 = cg_bird_canon_find(t, rows, CGB_KIND_GULL)
81 let rs: i64 = cg_bird_canon_find(t, rows, CGB_KIND_SONGBIRD)
82 gv_check("canon-declares-a-gull-row" as *u8, (rg >= 0) as i64, ctr)
83 gv_check("canon-declares-the-songbird-row" as *u8, (rs >= 0) as i64, ctr)
84 let PA: *i64 = sg_alloc()
85 let PB: *i64 = sg_alloc()
86 let seeds: *i64 = sys_mmap(32) as *i64
87 seeds[0] = SG_SEED_A; seeds[1] = SG_SEED_B; seeds[2] = SG_SEED_C
88 var kat: i64 = 1
89 var s: i64 = 0
90 while s < SG_NSEEDS {
91 let na: i64 = cg_build_bird(PA, seeds[s])
92 let nb: i64 = cg_bird_row(PB, seeds[s], t, rows, CGB_KIND_SONGBIRD)
93 if na != nb { kat = 0 }
94 if sg_ptab_eq(PA, PB, na) == 0 { kat = 0 }
95 s = s + 1
96 }
97 gv_check("songbird-row-reproduces-the-hand-written-incumbent-byte-for-byte over 3 seeds" as *u8, kat, ctr)
98 let ns: i64 = creaturegen_build_plan(PA, SG_SEED_A, 1)
99 let ns2: i64 = cg_bird_row(PB, SG_SEED_A, t, rows, CGB_KIND_SONGBIRD)
100 gv_check("plan-1-routes-through-the-canon: creaturegen_build_plan(1) equals the songbird row" as *u8, ((ns == ns2) as i64) * sg_ptab_eq(PA, PB, ns), ctr)
101 let PG: *i64 = sg_alloc()
102 let PG2: *i64 = sg_alloc()
103 let PGB: *i64 = sg_alloc()
104 let PGC: *i64 = sg_alloc()
105 let ng: i64 = cg_shorebird(PG, SG_SEED_A)
106 gv_check("gull-emits-parts (n > 0)" as *u8, (ng > 0) as i64, ctr)
107 gv_check_eq("gull-parts = songbird parts + the two wingtips" as *u8, ng, ns + SG_TIP_PARTS, ctr)
108 let ng2: i64 = cg_shorebird(PG2, SG_SEED_A)
109 gv_check("determinism: the same seed twice gives the same part table" as *u8, ((ng2 == ng) as i64) * sg_ptab_eq(PG, PG2, ng), ctr)
110 let ngb: i64 = cg_shorebird(PGB, SG_SEED_B)
111 let ngc: i64 = cg_shorebird(PGC, SG_SEED_C)
112 let np3: i64 = creaturegen_build_plan(PB, SG_SEED_A, CG_PLAN_GULL)
113 gv_check("plan-3-is-the-gull: creaturegen_build_plan(CG_PLAN_GULL) equals cg_shorebird" as *u8, ((np3 == ng) as i64) * sg_ptab_eq(PB, PG, ng), ctr)
114 // ---- the ruler: render at its view, L1 over the pixels ----
115 let npx: i64 = as_w()*as_h()
116 let fga: *i64 = sg_fb()
117 let fga2: *i64 = sg_fb()
118 let fgb: *i64 = sg_fb()
119 let fgc: *i64 = sg_fb()
120 sg_render(PG, ng, fga); sg_render(PG2, ng2, fga2); sg_render(PGB, ngb, fgb); sg_render(PGC, ngc, fgc)
121 let l1_ab: i64 = sg_l1(fga, fgb, npx)
122 let l1_ac: i64 = sg_l1(fga, fgc, npx)
123 let l1_bc: i64 = sg_l1(fgb, fgc, npx)
124 var l1_seedmin: i64 = l1_ab
125 if l1_ac < l1_seedmin { l1_seedmin = l1_ac }
126 if l1_bc < l1_seedmin { l1_seedmin = l1_bc }
127 let l1_same: i64 = sg_l1(fga, fga2, npx)
128 gv_check("two-seeds-differ-on-the-ruler: L1(gull A, gull B) > 0" as *u8, (l1_ab > 0) as i64, ctr)
129 gv_check("three-seeds-pairwise-differ-on-the-ruler: min L1 over AB AC BC > 0" as *u8, (l1_seedmin > 0) as i64, ctr)
130 gv_check_eq("neg-control-same-seed-same-render: L1(gull A, gull A again)" as *u8, l1_same, 0, ctr)
131 // every existing bird row (the songbird) at three seeds, against gull A and gull B
132 let fs: *i64 = sg_fb()
133 var dmin: i64 = SG_BIG
134 s = 0
135 while s < SG_NSEEDS {
136 let nn: i64 = cg_bird_row(PA, seeds[s], t, rows, CGB_KIND_SONGBIRD)
137 sg_render(PA, nn, fs)
138 let d1: i64 = sg_l1(fga, fs, npx)
139 let d2: i64 = sg_l1(fgb, fs, npx)
140 if d1 < dmin { dmin = d1 }
141 if d2 < dmin { dmin = d2 }
142 s = s + 1
143 }
144 gv_check("gull-distinct-from-every-bird-row-on-the-ruler: min L1(gull A or B, songbird seed s) over 3 seeds > the ruler's species bar" as *u8, (dmin > SG_SPECIES_BAR) as i64, ctr)
145 // palette on the ruler: foreground lightness up, saturation down, versus the songbird at the same seed and view
146 let stg: *i64 = sys_mmap(64) as *i64
147 let sts: *i64 = sys_mmap(64) as *i64
148 sg_fg(fga, npx, stg)
149 let nsa: i64 = cg_bird_row(PA, SG_SEED_A, t, rows, CGB_KIND_SONGBIRD)
150 sg_render(PA, nsa, fs)
151 sg_fg(fs, npx, sts)
152 var g_light: i64 = 0; var s_light: i64 = 0; var g_sat: i64 = 0; var s_sat: i64 = 0
153 if stg[0] > 0 { g_light = stg[1]/stg[0]; g_sat = stg[2]/stg[0] }
154 if sts[0] > 0 { s_light = sts[1]/sts[0]; s_sat = sts[2]/sts[0] }
155 gv_check("both-renders-have-foreground (denominator bound)" as *u8, ((stg[0] > 0) as i64) * ((sts[0] > 0) as i64), ctr)
156 gv_check("white-grey-on-the-ruler: the gull's foreground is lighter than the songbird's at the same view" as *u8, (g_light > s_light) as i64, ctr)
157 gv_check("white-grey-on-the-ruler: the gull's foreground is less saturated than the songbird's" as *u8, (g_sat < s_sat) as i64, ctr)
158 // ---- a canon without the gull row emits no gull ----
159 let t1: *i64 = sys_mmap(CGB_F*8) as *i64
160 var f: i64 = 0
161 while f < CGB_F { t1[f] = cgb_get(t, rs, f); f = f + 1 }
162 var k: i64 = 0
163 while k < AS_STRIDE { PA[k] = SG_SENTINEL; k = k + 1 }
164 let n0: i64 = cg_bird_row(PA, SG_SEED_A, t1, 1, CGB_KIND_GULL)
165 var intact: i64 = 1
166 k = 0
167 while k < AS_STRIDE { if PA[k] != SG_SENTINEL { intact = 0 } k = k + 1 }
168 gv_check("neg-control-canon-without-the-gull-row-emits-no-gull: 0 parts, table untouched" as *u8, ((n0 == 0) as i64) * intact, ctr)
169 gv_check_eq("the-same-table-still-emits-its-songbird (the refusal is per species, not a dead table)" as *u8, cg_bird_row(PA, SG_SEED_A, t1, 1, CGB_KIND_SONGBIRD), ns, ctr)
170 // ---- the gull is found regardless of row order ----
171 let t2: *i64 = sys_mmap(2*CGB_F*8) as *i64
172 f = 0
173 while f < CGB_F { t2[f] = cgb_get(t, rg, f); t2[CGB_F + f] = cgb_get(t, rs, f); f = f + 1 }
174 let n2: i64 = cg_bird_row(PB, SG_SEED_A, t2, 2, CGB_KIND_GULL)
175 gv_check("gull-found-regardless-of-row-order: swapped table gives the same part table" as *u8, ((n2 == ng) as i64) * sg_ptab_eq(PB, PG, ng), ctr)
176 // ---- the row data itself ----
177 let ratio_g: i64 = cgb_get(t, rg, CGB_LEGL_LO)*CGB_PERMIL/cgb_get(t, rg, CGB_BODYR_HI)
178 let ratio_s: i64 = cgb_get(t, rs, CGB_LEGL_LO)*CGB_PERMIL/cgb_get(t, rs, CGB_BODYR_HI)
179 gv_check("stilt-legs-by-data: the gull's leg/body floor exceeds the songbird's" as *u8, (ratio_g > ratio_s) as i64, ctr)
180 gv_check("longer-wings-by-data: the gull's wing permil exceeds the songbird's" as *u8, (cgb_get(t, rg, CGB_WING_LEN) > cgb_get(t, rs, CGB_WING_LEN)) as i64, ctr)
181 // ---- standing, not flying ----
182 let lg: *i64 = sys_mmap(64) as *i64
183 let leg_rgb: i64 = cgb_get(t, rg, CGB_LEG_RGB)
184 sg_legs(PG, ng, leg_rgb, lg)
185 var standing: i64 = 1
186 if lg[0] != 2 { standing = 0 }
187 if lg[1] != lg[2] { standing = 0 }
188 if lg[3] != 2 { standing = 0 }
189 if lg[6] != lg[1] { standing = 0 }
190 if lg[7] != lg[1] { standing = 0 }
191 if PG[3] <= lg[1] { standing = 0 }
192 gv_check("standing-not-flying: two legs end on one ground line, both feet on it, the body above it" as *u8, standing, ctr)
193 // ---- walking through the existing FK ----
194 let pose: *i64 = sys_mmap(32) as *i64
195 pose[0] = 0; pose[1] = 0; pose[2] = 0; pose[3] = 0
196 let PW: *i64 = sg_alloc()
197 let nw: i64 = cg_shorebird_posed(PW, SG_SEED_A, pose)
198 let lw: *i64 = sys_mmap(64) as *i64
199 sg_legs(PW, nw, leg_rgb, lw)
200 let rest_ground: i64 = lw[1]
201 gv_check_eq("posed-rest-carries-two-capsules-per-leg" as *u8, nw, ng + SG_FK_EXTRA, ctr)
202 gv_check_eq("posed-rest-lands-the-feet-on-the-static-ground-line (FK L1+L2 = hip-to-ground)" as *u8, rest_ground, lg[1], ctr)
203 pose[0] = SG_WALK_THIGH; pose[1] = SG_WALK_SHIN; pose[2] = 0 - SG_WALK_THIGH; pose[3] = SG_WALK_SHIN
204 let nw2: i64 = cg_shorebird_posed(PW, SG_SEED_A, pose)
205 sg_legs(PW, nw2, leg_rgb, lw)
206 let stride: i64 = lw[5] - lw[4]
207 gv_check("walk-pose-strides: the feet separate along z under a walk pose" as *u8, (stride > 0) as i64, ctr)
208 gv_check("walk-pose-keeps-the-feet-below-the-body" as *u8, (lw[7] < PW[3]) as i64, ctr)
209 gv_values_head()
210 gv_kv("canon_rows" as *u8, rows); gv_kv("songbird_parts" as *u8, ns); gv_kv("gull_parts" as *u8, ng)
211 gv_kv("l1_gull_ab" as *u8, l1_ab); gv_kv("l1_gull_ac" as *u8, l1_ac); gv_kv("l1_gull_bc" as *u8, l1_bc); gv_kv("l1_same_seed" as *u8, l1_same)
212 gv_kv("l1_min_gull_vs_songbird" as *u8, dmin); gv_kv("species_bar" as *u8, SG_SPECIES_BAR)
213 gv_kv("gull_fg_px" as *u8, stg[0]); gv_kv("gull_fg_light" as *u8, g_light); gv_kv("gull_fg_sat" as *u8, g_sat)
214 gv_kv("songbird_fg_px" as *u8, sts[0]); gv_kv("songbird_fg_light" as *u8, s_light); gv_kv("songbird_fg_sat" as *u8, s_sat)
215 gv_kv("leg_body_permil_gull" as *u8, ratio_g); gv_kv("leg_body_permil_songbird" as *u8, ratio_s)
216 gv_kv("ground_y" as *u8, lg[1]); gv_kv("posed_rest_ground_y" as *u8, rest_ground); gv_kv("walk_stride" as *u8, stride)
217 return gv_verdict("NX-SHOREBIRD" as *u8, ctr, "a species is a row; the plan is one; the ruler is the estate's" as *u8)
218}