code wiki / _hdl_build / nx_anatstack_gate.nx

nx_anatstack_gate.nx source

↩ module page · 134 lines · 6986 B

1// nx_anatstack_gate.nx -- prove the LAYERED ANATOMICAL model (operator: skeleton->muscle->skin, not circles on 2// circles). The skin EMERGES from the anatomy underneath. 3// T1 all 4 layers render (skeleton, +muscle, +fat, skin envelope) -- a real anatomical build-up 4// T2 ★NESTING: the skin surface is PROUD of the bone (skin front-crossing is forward of the bone front-crossing 5// by ~a tissue depth) AND the deep interior is inside every layer -- i.e. bone is inside muscle inside skin 6// T3 cutaway PNG knowledge/nx_anatstack.png (skeleton | +muscle | +fat | skin) + determinism 7// license_tier: ORIGINAL expect_exit: 0 8import "nx_syscalls.nx" 9import "nx_png.nx" 10import "nx_anatstack.nx" 11 12func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 13func pn(v: i64) -> i64 { let b: *u8=sys_mmap(32) as *u8; var x: i64=v; var ng: i64=0; if x<0{ng=1;x=0-x} var i: i64=31; if x==0{b[i]=48 as u8;i=i-1} while x>0{b[i]=(48+x%10) as u8;x=x/10;i=i-1} if ng==1{b[i]=45 as u8;i=i-1} sys_write(1,(b as i64+i+1) as *u8,31-i); return 0 } 14func lum(px: i64) -> i64 { return (px&255)+((px>>8)&255)+((px>>16)&255) } 15 16func main() -> i64 { 17 hw("=== nx_anatstack_gate -- layered anatomical model: skeleton -> muscle -> fat -> skin ===\n" as *u8) 18 var fails: i64 = 0 19 let W: i64 = as_w() 20 let H: i64 = as_h() 21 let npx: i64 = W*H 22 let P: *i64 = sys_mmap(64*AS_STRIDE*8) as *i64 23 let np: i64 = anatstack_build(P) 24 hw(" anatomical parts: "); pn(np); hw(" (skeleton + muscle + fat)\n" as *u8) 25 26 // ---- MUTATION-DERIVED TOOTH: BILATERAL COLOUR SYMMETRY (2026-08-01, debt 1785604588) ---- 27 // nx_gate_mutation_probe scored this pair 3/4 with a survivor at nx_anatstack.nx:195 -- a ` + ` 28 // flipped to ` - ` inside the RIGHT eyeball's packed colour (246 + 244*256 + 238*65536 + GLOSS). 29 // Line 193 packs the LEFT eyeball with the identical expression, so the mutant makes the eyes 30 // DIFFERENT COLOURS. It survived because every existing tooth measures GEOMETRY -- part counts and 31 // lit-pixel totals per panel -- and a colour change moves neither: the eyeball is still there, still 32 // the same size, still lit. A luminance threshold at >130 cannot see a hue swap. 33 // Bilateral symmetry is the right invariant because it needs no hard-coded colour constant: whatever 34 // the eyes are, the two must MATCH, so any edit that touches one side alone fails. Layout read from 35 // source, not assumed -- AS_STRIDE=12 as layer,type,p1(3),r(3),p2(3),colour, so p1 is [2..4] and the 36 // packed colour is [11] (as_feature_last writes exactly there). 37 var lcol: i64 = 0 38 var rcol: i64 = 0 39 var lfound: i64 = 0 40 var rfound: i64 = 0 41 var pi: i64 = 0 42 while pi < np { 43 let bx: i64 = P[pi*AS_STRIDE + 2] 44 let by: i64 = P[pi*AS_STRIDE + 3] 45 let bz: i64 = P[pi*AS_STRIDE + 4] 46 if by == 178 { 47 if bz == (0 - 560) { 48 if bx == (0 - 258) { lcol = P[pi*AS_STRIDE + 11]; lfound = 1 } 49 if bx == 258 { rcol = P[pi*AS_STRIDE + 11]; rfound = 1 } 50 } 51 } 52 pi = pi + 1 53 } 54 var sym_ok: i64 = 0 55 if lfound == 1 { 56 if rfound == 1 { 57 if lcol == rcol { sym_ok = 1 } 58 } 59 } 60 if sym_ok == 1 { hw(" PASS eyeball colour symmetry: L packed colour == R\n" as *u8) } 61 if sym_ok == 0 { 62 fails = fails + 1 63 hw(" FAIL eyeball colour symmetry -- L/R packed colour differs, or an eyeball was not found\n" as *u8) 64 } 65 66 let fb: *i64 = sys_mmap(npx*8) as *i64 67 let GW: i64 = W*2 68 let gal: *i64 = sys_mmap(GW*H*2*8) as *i64 69 70 // 4 panels: bone / +muscle / +fat / skin 71 let YAW: i64 = 0 72 let CZ: i64 = 3 73 var valid: i64 = 0 74 var pnl: i64 = 0 75 while pnl < 4 { 76 var ml: i64 = 0; var inf: i64 = 0; var cr: i64 = 220; var cg: i64 = 215; var cb: i64 = 205 77 if pnl == 1 { ml=1; cr=182; cg=74; cb=68 } // +muscle : dark red 78 if pnl == 2 { ml=2; cr=236; cg=220; cb=176 } // +fat : cream 79 if pnl == 3 { ml=2; inf=42; cr=232; cg=196; cb=166 } // skin envelope : skin tone 80 anatstack_render(P, np, YAW, CZ, ml, inf, cr, cg, cb, fb) 81 var head: i64 = 0 82 var k: i64 = 0 83 while k < npx { if lum(fb[k]) > 130 { head=head+1 } k=k+1 } 84 if head > 12000 { valid = valid + 1 } 85 hw(" panel "); pn(pnl); hw(" lit_px="); pn(head); hw("\n" as *u8) 86 // tile into 2x2 87 let col: i64 = pnl % 2 88 let row: i64 = pnl / 2 89 var y: i64 = 0 90 while y < H { var x: i64=0; while x<W { gal[(row*H+y)*GW + col*W + x] = fb[y*W+x]; x=x+1 } y=y+1 } 91 pnl = pnl + 1 92 } 93 var t1: i64 = 0 94 if valid == 4 { t1 = 1 } 95 if t1 == 1 { hw("T1 PASS all 4 anatomical layers render (skeleton -> muscle -> fat -> skin)\n" as *u8) } 96 else { fails=fails+1; hw("T1 FAIL only "); pn(valid); hw("/4 rendered\n" as *u8) } 97 98 // T2 NESTING: scan z at a mid-face point; skin front-surface must be FORWARD (more -z) of the bone front-surface 99 var zbone: i64 = 0 100 var zskin: i64 = 0 101 var z: i64 = 0-760 102 while z < 0-260 { 103 if zbone == 0 { if anatstack_sdf(P, np, 0, 0-90, z, 0, 0) < 0 { zbone = z } } 104 if zskin == 0 { if anatstack_sdf(P, np, 0, 0-90, z, 2, 42) < 0 { zskin = z } } 105 z = z + 4 106 } 107 // deep interior inside every layer 108 let dbone: i64 = anatstack_sdf(P, np, 0, 60, 0-260, 0, 0) 109 let dskin: i64 = anatstack_sdf(P, np, 0, 60, 0-260, 2, 42) 110 hw(" nesting: skin front z="); pn(zskin); hw(" bone front z="); pn(zbone); hw(" | deep-interior bone_sdf="); pn(dbone); hw(" skin_sdf="); pn(dskin); hw("\n" as *u8) 111 var t2: i64 = 0 112 if zskin < zbone - 20 { if dbone < 0 { if dskin < 0 { t2 = 1 } } } // skin proud of bone + interior inside both 113 if t2 == 1 { hw("T2 PASS NESTING: skin is proud of the bone by a tissue depth; interior is inside every layer (bone c muscle c skin)\n" as *u8) } 114 else { fails=fails+1; hw("T2 FAIL nesting wrong\n" as *u8) } 115 116 write_png(gal, GW, H*2, "knowledge/nx_anatstack.png" as *u8) 117 118 // T3 determinism (re-render skin) 119 let fb2: *i64 = sys_mmap(npx*8) as *i64 120 anatstack_render(P, np, YAW, CZ, 2, 42, 232, 196, 166, fb) 121 anatstack_render(P, np, YAW, CZ, 2, 42, 232, 196, 166, fb2) 122 var diff: i64 = 0 123 var k3: i64 = 0 124 while k3 < npx { if fb[k3]!=fb2[k3] { diff=diff+1 } k3=k3+1 } 125 var t3: i64 = 0 126 if diff == 0 { t3 = 1 } 127 if t3 == 1 { hw("T3 PASS deterministic + cutaway PNG knowledge/nx_anatstack.png (skeleton|+muscle|+fat|skin)\n" as *u8) } 128 else { fails=fails+1; hw("T3 FAIL diff="); pn(diff); hw("\n" as *u8) } 129 130 if fails == 0 { hw("ANATSTACK-GATE 3/3 GREEN -- a LAYERED anatomical head (skeleton->muscle->fat->skin), skin DERIVED from the anatomy underneath (not circles on circles), sovereign + integer\n" as *u8); sys_exit(0); return 0 } 131 hw("ANATSTACK-GATE RED fails="); pn(fails); hw("\n" as *u8) 132 sys_exit(1) 133 return 1 134}