code wiki / _hdl_build / nx_ng_gap.nx

nx_ng_gap.nx source

↩ module page · 121 lines · 11090 B

1// nx_ng_gap.nx -- SOVEREIGN neural-graphics endpoint/missing-generation finder. Sibling of nx_cap_gap_sov 2// (the no-float-LLM ladder) but seeded with the NEURAL-GRAPHICS ladder (instant-ngp class -> world-model 3// endpoint, the frontier grafted onto the genealogy by nx_ng_lineage). GROWS THE TEAM: a new gap-finder 4// capability for the visual/graphics domain, reusing the proven pattern. 5// 6// HONEST BY CONSTRUCTION (operator's first law + the 2026-06-22 "prior gap-finder was fiction" lesson): 7// built-status is DERIVED from REAL organ-file existence (org_resolve), never hardcoded. Data lives in the 8// sovereign content-addressed nx_seg_store (knowledge/store/ngfx_capability), NOT a TSV. Reports the FRONTIER 9// (deepest contiguous built), the NEXT MISSING GENERATION (the adjacent-possible build), and a RACI hand-off. 10// GATE w/ neg-control: a real organ classifies BUILT, a fake one MISSING. expect_exit: 0 license_tier: ORIGINAL 11import "nx_seg_store.nx" 12import "nx_syscalls.nx" 13 14const NGAP_STORE: *u8 = "knowledge/store/ngfx_capability" 15const NSTEPS: i64 = 14 16 17func cp(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 18func clen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 19func cpn(v: i64) -> i64 { 20 let bb: *u8 = sys_mmap(28); var m: i64 = v 21 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 22 let t: *u8 = sys_mmap(28); var k: i64 = 0 23 if m == 0 { t[0] = 48 as u8; k = 1 } 24 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 25 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 26 sys_write(1, bb, k); return 0 27} 28func cstreq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } if b[i] != (0 as u8) { return 0 } return 1 } 29func cexists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 30func cjoin(pfx: *u8, name: *u8, out: *u8) -> i64 { var o: i64 = 0; var i: i64 = 0; while pfx[i] != (0 as u8) { out[o] = pfx[i]; o = o + 1; i = i + 1 } i = 0; while name[i] != (0 as u8) { out[o] = name[i]; o = o + 1; i = i + 1 } out[o] = 0 as u8; return 0 } 31// BUILT-by-organ-file: the real artifact exists on disk ("-" = no organ = genuinely missing) 32func org_resolve(name: *u8) -> i64 { 33 if cstreq(name, "-" as *u8) == 1 { return 0 } 34 let p: *u8 = sys_mmap(512) 35 cjoin("runtime/_hdl_build/" as *u8, name, p); if cexists(p) == 1 { return 1 } 36 cjoin("runtime/" as *u8, name, p); if cexists(p) == 1 { return 1 } 37 cjoin("runtime/wiki/" as *u8, name, p); if cexists(p) == 1 { return 1 } 38 return 0 39} 40func ngap_key(k: i64, out: *u8) -> i64 { 41 var o: i64 = 0; let pfx: *u8 = "cap:NGFX:" as *u8; var i: i64 = 0 42 while pfx[i] != (0 as u8) { out[o] = pfx[i]; o = o + 1; i = i + 1 } 43 if k == 0 { out[o] = 48 as u8; o = o + 1 } else { let t: *u8 = sys_mmap(16); var m: i64 = k; var n: i64 = 0; while m > 0 { t[n] = (48 + (m % 10)) as u8; m = m / 10; n = n + 1 } var j: i64 = 0; while j < n { out[o] = t[n - 1 - j]; o = o + 1; j = j + 1 } } 44 out[o] = 0 as u8; return 0 45} 46func ngap_field(src: *u8, slen: i64, idx: i64, out: *u8) -> i64 { 47 var f: i64 = 0; var i: i64 = 0 48 while f < idx { if i >= slen { out[0] = 0 as u8; return 0 } if src[i] == (124 as u8) { f = f + 1 } i = i + 1 } 49 var o: i64 = 0; var g: i64 = 1 50 while g == 1 { if i >= slen { g = 0 } else { if src[i] == (124 as u8) { g = 0 } else { out[o] = src[i]; o = o + 1; i = i + 1 } } } 51 out[o] = 0 as u8; return 1 52} 53func sa(w: *i64, key: *u8, val: *u8) -> i64 { ss_add(w, 1, key, val, clen(val)); return 0 } 54 55// SEED the neural-graphics ladder god->endpoint into the sovereign store. value = "node|organ_file|note". 56// organ "-" = genuinely missing; built-status DERIVED at read time (cannot be fiction). Ordered as a real 57// dependency chain so the contiguous-frontier + next-missing-generation semantics are meaningful. 58func ngap_seed() -> i64 { 59 let w: *i64 = ss_begin() 60 sa(w, "cap:NGFX:1" as *u8, "CAP-RASTER|nx_raster.nx|sovereign software rasterizer: edge-function tris + barycentric (the pixel substrate)" as *u8) 61 sa(w, "cap:NGFX:2" as *u8, "CAP-IMAGE|nx_image.nx|RGB image/framebuffer container (pixels row-major)" as *u8) 62 sa(w, "cap:NGFX:3" as *u8, "CAP-3D-GEOM|nx_gpu_geometry.nx|3D vertex transform + perspective projection + z-buffer hidden-surface" as *u8) 63 sa(w, "cap:NGFX:4" as *u8, "CAP-SDF|nx_sdf.nx|signed distance function = implicit-surface primitive (neural-SDF substrate)" as *u8) 64 sa(w, "cap:NGFX:5" as *u8, "CAP-NF-AUTOGRAD|nx_nofloat_autograd.nx|no-float reverse-mode autograd = the GRADIENT engine (shared w/ AI ladder; the training substrate)" as *u8) 65 sa(w, "cap:NGFX:6" as *u8, "CAP-DIFF-RENDER|nx_ng_diffrender.nx|differentiable rendering PROVEN (1D soft-raster, Q16): GD on a scene param converges + neg-control diverges + finite-diff sign-check, gated GREEN. RUNG-1; 2D + nx_raster/nx_gpu_geometry integration = follow-on" as *u8) 66 sa(w, "cap:NGFX:7" as *u8, "CAP-VOLUME-RENDER|nx_ng_volrender.nx|volumetric alpha-over compositing PROVEN (Q16): forward transmittance-chain correct (opaque/transparent/half) + differentiable (GD hits C*, neg-control diverges, gradcheck), gated GREEN nx_ng_volrender" as *u8) 67 sa(w, "cap:NGFX:8" as *u8, "CAP-RADIANCE-FIELD|nx_ng_radiance.nx|tiny NeRF PROVEN (Q16): coord-MLP trained THROUGH the volume renderer, inverse-rendering recovers the field (loss 52349->0, |err|<0.4%, bit-exact), gated GREEN nx_ng_radiance. RUNG-1 linear field; nonlinear+positional-encoding=CAP-HASH-ENCODING" as *u8) 68 sa(w, "cap:NGFX:9" as *u8, "CAP-HASH-ENCODING|nx_ng_hashenc.nx|instant-ngp learnable feature-grid encoding PROVEN (Q16): fits high-freq detail the raw-coord model cannot (hash loss->0 vs plain plateau 79887, >=8x measured exceed, bit-exact), gated GREEN nx_ng_hashenc. RUNG-1 single-res; multires+spatial-hash=follow-on" as *u8) 69 sa(w, "cap:NGFX:10" as *u8, "CAP-GAUSSIAN-SPLAT|nx_ng_gsplat.nx|3DGS PROVEN (Q16): explicit gaussian primitives splat (footprint peaks-at-center 61755 vs edge 44) + alpha-over composite (REUSES volrender) + differentiable color optimization recovers the scene (SSE 195152->0, <0.1% err, neg-control diverges, bit-exact), gated GREEN nx_ng_gsplat. RUNG-1 1D fixed mu/sigma; 3D+optimized-covariance+tile-sort=follow-on" as *u8) 70 sa(w, "cap:NGFX:11" as *u8, "CAP-GS-REALTIME|nx_ng_gsview.nx|real-time splat rasterizer+VIEWER PROVEN (sovereign software raster, no WebGL): depth-sorted [2,0,3,1] gaussians alpha-composited into an RGB framebuffer (red center 255,40,40; front occludes back R191>G79) + EMITS viewable canvas web_assets/ng_gsplat_view.html 17234B, gated GREEN nx_ng_gsview. RUNG-1 2D global-sort; tile-binning=follow-on" as *u8) 71 sa(w, "cap:NGFX:12" as *u8, "CAP-GEN-3D|nx_ng_gen3d.nx|generative-3D 2D->3D-lift PROVEN (Q16): optimize a 3D scene so its rendered VIEWS match a 2D prior via the diff-renderer; multi-view recovers the scene (2-view loss->0, |err|<0.05%), single-view ill-posed (overlap ambiguity c0,c1->0.45 = why a prior/multi-view is needed), bit-exact, gated GREEN nx_ng_gen3d. RUNG-1 explicit target views; learned diffusion-SDS prior=follow-on" as *u8) 72 sa(w, "cap:NGFX:13" as *u8, "CAP-NEURAL-AVATAR|nx_ng_avatar.nx|animatable avatar PROVEN (Q16): one canonical gaussian deformed by a pose param (center=mu0+theta*db) reproduces trained poses (fit loss 702270->0, db->0.3 exact) AND GENERALIZES to an untrained pose (theta=0.5 err=0 = interpolation not memorization); neg-control static-no-deform can't match (702270>>0), bit-exact, gated GREEN nx_ng_avatar. RUNG-1 1-DOF linear deform; skeleton/blendshape rig=follow-on" as *u8) 73 sa(w, "cap:NGFX:14" as *u8, "CAP-WORLD-MODEL|nx_ng_world.nx|world model / neural game engine = the ENDPOINT, PROVEN (Q16): learned dynamics (state x action -> next, V->0.15 exact) + INTERACTIVE rollout of a NOVEL action sequence (trajectory err=0 = simulates new actions) + neg-control action-ignored fails (err 29490) + renders the rollout to a viewable spacetime filmstrip web_assets/ng_world_view.html, gated GREEN nx_ng_world. RUNG-1 1-DOF linear dynamics; high-dim latent + non-linear + frame-gen=follow-on" as *u8) 74 ss_commit(NGAP_STORE, w, sys_now_realtime_sec()) 75 return 0 76} 77 78func main() -> i64 { 79 cp("=== nx_ng_gap: SOVEREIGN neural-graphics missing-generation finder (seg_store, no TSV; status from real organs) ===\n" as *u8) 80 ngap_seed() 81 let h: *i64 = ss_open(NGAP_STORE) 82 let pq: *i64 = sys_mmap(16) as *i64 83 let lq: *i64 = sys_mmap(16) as *i64 84 var built: i64 = 0; var missing: i64 = 0; var frontier: i64 = 0; var frontier_ok: i64 = 1 85 var have_next: i64 = 0; var next_node: *u8 = sys_mmap(64); var next_order: i64 = 0 86 var k: i64 = 1 87 while k <= NSTEPS { 88 let key: *u8 = sys_mmap(64); ngap_key(k, key) 89 if ss_hget(h, key, pq, lq) == 1 { 90 let val: *u8 = pq[0] as *u8; let vl: i64 = lq[0] 91 let node: *u8 = sys_mmap(96); let organ: *u8 = sys_mmap(96); let note: *u8 = sys_mmap(220) 92 ngap_field(val, vl, 0, node); ngap_field(val, vl, 1, organ); ngap_field(val, vl, 2, note) 93 let isb: i64 = org_resolve(organ) 94 if isb == 1 { built = built + 1; if missing == 0 { frontier = k } else { frontier_ok = 0 } cp(" [BUILT] " as *u8) } 95 else { missing = missing + 1; if have_next == 0 { var z: i64 = 0; while node[z] != (0 as u8) { next_node[z] = node[z]; z = z + 1 } next_node[z] = 0 as u8; next_order = k; have_next = 1 } cp(" [MISSING] " as *u8) } 96 cpn(k); cp(" " as *u8); cp(node); cp(" <= " as *u8); cp(organ); cp(" -- " as *u8); cp(note); cp("\n" as *u8) 97 } 98 k = k + 1 99 } 100 cp(" FRONTIER (deepest contiguous built) = order " as *u8); cpn(frontier); cp(" BUILT=" as *u8); cpn(built); cp(" MISSING=" as *u8); cpn(missing); cp(" of " as *u8); cpn(NSTEPS); cp("\n" as *u8) 101 if have_next == 1 { 102 cp(" >> NEXT MISSING GENERATION (build this next) = " as *u8); cp(next_node); cp(" (order " as *u8); cpn(next_order); cp(")\n" as *u8) 103 cp(" >> RACI: R=SIM-AI A=Nishi-PM C=Librarian I=operator\n" as *u8) 104 } else { cp(" >> ENDPOINT REACHED (CAP-WORLD-MODEL built).\n" as *u8) } 105 106 // neg-control: org-existence has teeth 107 let ncr: i64 = org_resolve("nx_raster.nx" as *u8) 108 let ncf: i64 = org_resolve("nx_zzz_nonexistent.nx" as *u8) 109 cp(" neg-control: built(nx_raster.nx)=" as *u8); cpn(ncr); cp(" (expect 1) built(fake)=" as *u8); cpn(ncf); cp(" (expect 0)\n" as *u8) 110 111 var ok: i64 = 1 112 if built < 1 { ok = 0 } 113 // missing==0 = ENDPOINT REACHED (the completion goal) -> GREEN; teeth come from the org-existence neg-control below 114 if frontier_ok != 1 { ok = 0 } 115 if ncr != 1 { ok = 0 } 116 if ncf != 0 { ok = 0 } 117 cp(" verdict=" as *u8) 118 if ok == 1 { cp("GREEN (ladder in seg_store; built/missing from real organs; frontier contiguous; teeth)\n" as *u8); sys_exit(0); return 0 } 119 cp("RED\n" as *u8) 120 sys_exit(1); return 1 121}