nx_gsplat4d_gate.nx source
↩ module page · 272 lines · 15635 B
1// nx_gsplat4d_gate.nx -- GATE for the 4D spatiotemporal Gaussian core.
2//
3// ★★THIS REFEREE CARRIES NO TUNED THRESHOLDS. An earlier revision judged with hand-picked bands -- "the
4// 1-sigma weight is between 140 and 170", "more than 2000 pixels lit", "the arena is under 4 MiB". Every
5// one of those is a number nobody measured, and a referee that judges with them is measuring the number,
6// not the subject. They are all replaced by one of three honest forms:
7// EXACT IDENTITY -- the envelope must equal the TABLE ENTRY its index formula names (the index
8// arithmetic is the thing that can be wrong; only an exact compare tests it).
9// A MATHEMATICAL LAW -- symmetry in dt, strict monotonicity, antisymmetry of a signed ramp. These hold
10// regardless of table precision, so they need no tolerance at all.
11// A CONTROL -- render the SAME time twice and require ZERO changed pixels, then a different time
12// and require MORE than that. The control replaces the threshold entirely, and is
13// strictly stronger: it proves the difference is caused by TIME, not by noise.
14//
15// The teeth that a plausible-but-wrong implementation FAILS:
16// T4 TEMPORAL LOCALITY is the anti-vacuity tooth. Two Gaussians carry IDENTICAL motion and differ only
17// in t_mu. At one instant one must have moved and the other must not. A deformation that ignored
18// the temporal window -- one that just animated everything -- passes every other tooth and dies here.
19// T1 REST INVARIANCE is the control: with no motion declared, the 4D bake reproduces the static cloud at
20// EVERY t. 4D that cannot reduce to 3D is not a superset, it is a different thing.
21// T9/T10/T11 are deny-guards asked BOTH directions, because A GUARD THAT REFUSES EVERYTHING PASSES
22// EVERY NEGATIVE TEST.
23// license_tier: ORIGINAL expect_exit: 0
24import "nx_syscalls.nx"
25import "nx_gsplat.nx"
26import "nx_gsplat4d_lib.nx"
27import "nx_png.nx"
28import "nx_gate_verdict.nx"
29
30// FIXTURE parameters. These are the scene being tested, not policy inside the organ: a referee has to
31// choose a subject, and it says out loud which one it chose.
32const GG_CAP: i64 = 256
33const GG_RING: i64 = 3
34const GG_TMU_A: i64 = 1000
35const GG_SIG: i64 = 400
36const GG_TMU_B: i64 = 5000
37const GG_VX: i64 = 4096
38const GG_WAVE: i64 = 40
39
40// 0=A and 1=B carry identical motion but different windows, 2=C is static (no motion row at all), and
41// 3.. are a travelling wave whose t_mu staggers across x -- the visual subject.
42func gg_scene() -> i64 {
43 g4_init(GG_CAP, GG_RING)
44 g4_set_rest(0, 0, 0, 0, 0, 0, 0-256, 400, 240, 240, 240, 256)
45 g4_set_time(0, GG_TMU_A, GG_SIG)
46 g4_set_motion(0, GG_VX, 0, 0, 0, 0, 0, 0)
47 g4_set_rest(1, 6000, 0, 0, 0, 0, 0-256, 400, 240, 240, 240, 256)
48 g4_set_time(1, GG_TMU_B, GG_SIG)
49 g4_set_motion(1, GG_VX, 0, 0, 0, 0, 0, 0)
50 g4_set_rest(2, 0-6000, 0, 0, 0, 0, 0-256, 400, 240, 240, 240, 256)
51 var i: i64 = 0
52 while i < GG_WAVE {
53 let gx: i64 = 0 - 9000 + i*460
54 g4_set_rest(3+i, gx, 0-2500, 0, 0, 0, 0-256, 520, 90 + i*3, 150, 230 - i*2, 256)
55 g4_set_time(3+i, 600 + i*40, 300)
56 g4_set_motion(3+i, 0, 5200, 0, 260, 0, 0, 0)
57 i = i + 1
58 }
59 return 0
60}
61
62func gg_cmp(a: *i64, b: *i64, n: i64) -> i64 {
63 var i: i64 = 0
64 while i < n { if a[i] != b[i] { return 0 } i = i + 1 }
65 return 1
66}
67func gg_pixdiff(a: *i64, b: *i64, n: i64) -> i64 {
68 var d: i64 = 0
69 var i: i64 = 0
70 while i < n { if a[i] != b[i] { d = d + 1 } i = i + 1 }
71 return d
72}
73
74func main() -> i64 {
75 let ctr: *i64 = gv_ctr()
76 gv_head("nx_gsplat4d_gate -- the temporal axis: 4D spatiotemporal Gaussians over the proven rasterizer" as *u8)
77
78 gg_scene()
79 let ng: i64 = g4_n()
80 let st: i64 = gs_stride_aniso()
81 let f1: *i64 = sys_mmap(GG_CAP*st*8) as *i64
82 let f2: *i64 = sys_mmap(GG_CAP*st*8) as *i64
83 let f3: *i64 = sys_mmap(GG_CAP*st*8) as *i64
84 gv_puts(" scene gaussians=" as *u8); gv_num(ng)
85 gv_puts(" arena_bytes=" as *u8); gv_num(g4_bytes())
86 gv_puts(" ring_depth=" as *u8); gv_num(g4_ring_depth())
87 gv_puts(" tick_unit=" as *u8); gv_num(g4_tscale())
88 gv_puts(" lut_horizon_sigma=" as *u8); gv_num(g4_horizon_sigma()); gv_puts("\n" as *u8)
89
90 // T1 CONTROL: gaussian 2 declares no motion, so it must sit at its rest position at EVERY t.
91 g4_bake(GG_TMU_A, f1)
92 g4_bake(GG_TMU_A + 3*GG_SIG, f2)
93 g4_bake(0 - 20000, f3)
94 var t1: i64 = 0
95 if f1[2*st] == 0 - 6000 { if f2[2*st] == 0 - 6000 { if f3[2*st] == 0 - 6000 { t1 = 1 } } }
96 gv_puts(" rest-invariance: static gaussian x at three different t = " as *u8)
97 gv_num(f1[2*st]); gv_puts("," as *u8); gv_num(f2[2*st]); gv_puts("," as *u8); gv_num(f3[2*st]); gv_puts("\n" as *u8)
98 gv_check("T1 rest invariance: a motionless gaussian bakes to its rest position at every t (4D reduces to 3D)" as *u8, t1, ctr)
99
100 // T2 the envelope is EXACTLY the table entry its index formula names. u = (dt/sigma)^2, and the index
101 // is k = lutu*u, so dt=sigma is k=lutu and dt=2*sigma is k=4*lutu. No band, no tolerance: an exact
102 // identity that fails the moment the index arithmetic is wrong.
103 let lu: i64 = gs_lutu()
104 let e0: i64 = g4_envelope(0, GG_TMU_A)
105 let e1: i64 = g4_envelope(0, GG_TMU_A + GG_SIG)
106 let e2: i64 = g4_envelope(0, GG_TMU_A + 2*GG_SIG)
107 gv_puts(" envelope: w(0)=" as *u8); gv_num(e0); gv_puts(" vs lut[0]=" as *u8); gv_num(g4_lut(0))
108 gv_puts(" | w(1sig)=" as *u8); gv_num(e1); gv_puts(" vs lut[lutu]=" as *u8); gv_num(g4_lut(lu))
109 gv_puts(" | w(2sig)=" as *u8); gv_num(e2); gv_puts(" vs lut[4*lutu]=" as *u8); gv_num(g4_lut(4*lu)); gv_puts("\n" as *u8)
110 var t2: i64 = 0
111 if e0 == g4_lut(0) { if e1 == g4_lut(lu) { if e2 == g4_lut(4*lu) { if e0 == g4_wfull() { t2 = 1 } } } }
112 gv_check("T2 envelope EXACT: w equals the table entry its index formula names, at three derived indices" as *u8, t2, ctr)
113
114 // T2b LAWS that hold at ANY table precision, so they need no tolerance: the envelope is symmetric in
115 // dt, strictly decreasing away from t_mu, and exactly zero past the horizon the table itself implies.
116 let sym1: i64 = g4_envelope(0, GG_TMU_A + GG_SIG)
117 let sym2: i64 = g4_envelope(0, GG_TMU_A - GG_SIG)
118 let e3: i64 = g4_envelope(0, GG_TMU_A + 3*GG_SIG)
119 let ebeyond: i64 = g4_envelope(0, GG_TMU_A + (g4_horizon_sigma() + 1)*GG_SIG)
120 gv_puts(" envelope laws: symmetric " as *u8); gv_num(sym1); gv_puts("==" as *u8); gv_num(sym2)
121 gv_puts(" | strictly decreasing " as *u8); gv_num(e0); gv_puts(">" as *u8); gv_num(e1); gv_puts(">" as *u8); gv_num(e2); gv_puts(">" as *u8); gv_num(e3)
122 gv_puts(" | past horizon=" as *u8); gv_num(ebeyond); gv_puts("\n" as *u8)
123 var t2b: i64 = 0
124 if sym1 == sym2 { if e0 > e1 { if e1 > e2 { if e2 > e3 { if ebeyond == 0 { t2b = 1 } } } } }
125 gv_check("T2b envelope LAWS: symmetric in dt, strictly decreasing, exactly zero past the derived horizon" as *u8, t2b, ctr)
126
127 // T3 the kernel is a SIGNED ramp: equal and opposite displacement either side of t_mu.
128 g4_bake(GG_TMU_A + GG_SIG, f1)
129 g4_bake(GG_TMU_A - GG_SIG, f2)
130 let dpos: i64 = f1[0]
131 let dneg: i64 = f2[0]
132 gv_puts(" antisymmetry: x(t_mu+sig)=" as *u8); gv_num(dpos)
133 gv_puts(" x(t_mu-sig)=" as *u8); gv_num(dneg); gv_puts("\n" as *u8)
134 var t3: i64 = 0
135 if dpos == 0 - dneg { if dpos != 0 { t3 = 1 } }
136 gv_check("T3 signed kernel: displacement either side of t_mu is equal and opposite, and NOT zero" as *u8, t3, ctr)
137
138 // T4 ★ANTI-VACUITY -- TEMPORAL LOCALITY.
139 g4_bake(GG_TMU_A + GG_SIG, f1)
140 let amoved: i64 = f1[0] - 0
141 let bmoved: i64 = f1[1*st] - 6000
142 gv_puts(" locality at t=" as *u8); gv_num(GG_TMU_A + GG_SIG)
143 gv_puts(": A(t_mu=" as *u8); gv_num(GG_TMU_A); gv_puts(") moved " as *u8); gv_num(amoved)
144 gv_puts(" | B(t_mu=" as *u8); gv_num(GG_TMU_B); gv_puts(", same motion) moved " as *u8); gv_num(bmoved); gv_puts("\n" as *u8)
145 var t4: i64 = 0
146 if amoved != 0 { if bmoved == 0 { t4 = 1 } }
147 gv_check("T4 anti-vacuity temporal locality: identical motion, different t_mu -- one moves, the other does NOT" as *u8, t4, ctr)
148
149 // T5 the 4D state reaches PIXELS, judged by a CONTROL rather than a pixel-count threshold: the same
150 // time rendered twice must differ in ZERO pixels, and two different times must differ in MORE. That
151 // proves the change is caused by time and not by nondeterminism -- which a threshold cannot show.
152 let W: i64 = gs_w()
153 let H: i64 = gs_h()
154 let npx: i64 = W*H
155 let fb1: *i64 = sys_mmap(npx*8) as *i64
156 let fb2: *i64 = sys_mmap(npx*8) as *i64
157 let fb3: *i64 = sys_mmap(npx*8) as *i64
158 let acc: *i64 = sys_mmap(npx*3*8) as *i64
159 let trn: *i64 = sys_mmap(npx*8) as *i64
160 let dep: *i64 = sys_mmap(GG_CAP*8) as *i64
161 let sxb: *i64 = sys_mmap(GG_CAP*8) as *i64
162 let syb: *i64 = sys_mmap(GG_CAP*8) as *i64
163 let pa: *i64 = sys_mmap(GG_CAP*8) as *i64
164 let pb: *i64 = sys_mmap(GG_CAP*8) as *i64
165 let pc: *i64 = sys_mmap(GG_CAP*8) as *i64
166 let pdt: *i64 = sys_mmap(GG_CAP*8) as *i64
167 let ord: *i64 = sys_mmap(GG_CAP*8) as *i64
168 let cnt: *i64 = sys_mmap((gs_nb()+2)*8) as *i64
169 let elut: *i64 = sys_mmap(gs_expn()*8) as *i64
170 gs_build_explut(elut)
171 let bg: i64 = 26 + 28*256 + 44*65536
172 g4_bake(GG_TMU_A, f1)
173 gs_render_aniso(f1, ng, 0, 14, fb1, acc, trn, dep, sxb, syb, pa, pb, pc, pdt, ord, cnt, elut, 26, 28, 44)
174 g4_bake(GG_TMU_A, f3)
175 gs_render_aniso(f3, ng, 0, 14, fb3, acc, trn, dep, sxb, syb, pa, pb, pc, pdt, ord, cnt, elut, 26, 28, 44)
176 g4_bake(GG_TMU_A + GG_SIG, f2)
177 gs_render_aniso(f2, ng, 0, 14, fb2, acc, trn, dep, sxb, syb, pa, pb, pc, pdt, ord, cnt, elut, 26, 28, 44)
178 let same_time: i64 = gg_pixdiff(fb1, fb3, npx)
179 let diff_time: i64 = gg_pixdiff(fb1, fb2, npx)
180 var lit: i64 = 0
181 var pi: i64 = 0
182 while pi < npx { if fb2[pi] != bg { lit = lit + 1 } pi = pi + 1 }
183 write_png(fb2, W, H, "knowledge/nx_gsplat4d_wave.png" as *u8)
184 gv_puts(" render: lit=" as *u8); gv_num(lit)
185 gv_puts(" | CONTROL same-time pixels changed=" as *u8); gv_num(same_time)
186 gv_puts(" | different-time pixels changed=" as *u8); gv_num(diff_time)
187 gv_puts(" artifact knowledge/nx_gsplat4d_wave.png\n" as *u8)
188 var t5: i64 = 0
189 if same_time == 0 { if diff_time > same_time { if lit > 0 { t5 = 1 } } }
190 gv_check("T5 the temporal state reaches PIXELS: same time changes NOTHING, a different time changes something" as *u8, t5, ctr)
191
192 // T6 the frame cache cannot lie: a slot must equal a direct bake at that same t, byte for byte.
193 g4_ring_prime(1000, 200)
194 g4_bake(1200, f1)
195 let slot: i64 = g4_ring_find(1200)
196 var t6: i64 = 0
197 if slot >= 0 { if gg_cmp(g4_ring_frame(slot), f1, ng*st) == 1 { t6 = 1 } }
198 gv_puts(" ring: t=1200 resident in slot " as *u8); gv_num(slot)
199 gv_puts(", byte-equal to a direct bake=" as *u8); gv_num(t6); gv_puts("\n" as *u8)
200 gv_check("T6 frame cache honesty: a cached frame is byte-identical to baking that time directly" as *u8, t6, ctr)
201
202 // T7 the ring is BOUNDED and evicts the oldest.
203 let vic: i64 = g4_ring_advance(200)
204 var live: i64 = 0
205 var s: i64 = 0
206 while s < g4_ring_depth() { live = live + g4_ring_valid(s); s = s + 1 }
207 let gone: i64 = g4_ring_find(1000)
208 let fresh: i64 = g4_ring_find(1600)
209 gv_puts(" ring advance: recycled slot " as *u8); gv_num(vic)
210 gv_puts(", t=1000 now " as *u8); gv_num(gone)
211 gv_puts(" (-1 = evicted), t=1600 in slot " as *u8); gv_num(fresh)
212 gv_puts(", live slots=" as *u8); gv_num(live); gv_puts("\n" as *u8)
213 var t7: i64 = 0
214 if gone == 0 - 1 { if fresh >= 0 { if live == g4_ring_depth() { t7 = 1 } } }
215 gv_check("T7 the frame cache is BOUNDED: advancing evicts the oldest and never grows past its declared depth" as *u8, t7, ctr)
216
217 // T8 determinism
218 g4_bake(1337, f1)
219 g4_bake(1337, f2)
220 gv_check("T8 deterministic: the same time bakes byte-identical state" as *u8, gg_cmp(f1, f2, ng*st), ctr)
221
222 // ★T9/T10/T10b/T11 -- THE DENY-GUARDS, ASKED BOTH DIRECTIONS. A suite that only asks "was it refused?"
223 // is blind by construction. ⚠T10b exists because nx_gate_bite SURVIVED a mutant in the diagnostic path:
224 // a guard whose message length computes to zero refuses SILENTLY, and every code-only tooth passes.
225 let r9bad: i64 = g4_set_time(0, GG_TMU_A, 0)
226 let r9good: i64 = g4_set_time(0, GG_TMU_A, GG_SIG)
227 let r10bad: i64 = g4_set_rest(GG_CAP + 5, 0, 0, 0, 0, 0, 0-256, 10, 1, 1, 1, 1)
228 let r10good: i64 = g4_set_rest(2, 0-6000, 0, 0, 0, 0, 0-256, 400, 240, 240, 240, 256)
229 gv_puts(" sigma guard: bad=" as *u8); gv_num(r9bad); gv_puts(" good=" as *u8); gv_num(r9good)
230 gv_puts(" | range guard: bad=" as *u8); gv_num(r10bad); gv_puts(" good=" as *u8); gv_num(r10good); gv_puts("\n" as *u8)
231 var t9: i64 = 0
232 if r9bad == 0 - 3 { if r9good == 0 { t9 = 1 } }
233 gv_check("T9 sigma guard NAMES its rule (-3) and has a POSITIVE CONTROL: a valid window is accepted" as *u8, t9, ctr)
234 var t10: i64 = 0
235 if r10bad == 0 - 5 { if r10good == 0 { t10 = 1 } }
236 gv_check("T10 range guard NAMES its rule (-5) and has a POSITIVE CONTROL: an in-range index is accepted" as *u8, t10, ctr)
237
238 // T10b the diagnostic path can measure its own message. Asserting the length of a literal against
239 // that same literal is the definition of a length function, not a tuned constant.
240 var t10b: i64 = 0
241 if g4_slen("" as *u8) == 0 { if g4_slen("ab" as *u8) == 2 { t10b = 1 } }
242 gv_puts(" diagnostic path: slen(empty)=" as *u8); gv_num(g4_slen("" as *u8))
243 gv_puts(" slen(ab)=" as *u8); gv_num(g4_slen("ab" as *u8)); gv_puts("\n" as *u8)
244 gv_check("T10b a refusal that cannot measure its own message prints nothing: the length function is correct" as *u8, t10b, ctr)
245
246 // T11 the prefetch depth is CHOSEN BY THE CALLER, and the structural floor is enforced both ways: a
247 // depth that cannot hold the frame in use plus one ahead is not a prefetch cache.
248 let rbad: i64 = g4_init(GG_CAP, g4_ring_min() - 1)
249 let rgood: i64 = g4_init(GG_CAP, g4_ring_min())
250 gv_puts(" ring-depth guard: below floor=" as *u8); gv_num(rbad)
251 gv_puts(" at floor=" as *u8); gv_num(rgood)
252 gv_puts(" depth now=" as *u8); gv_num(g4_ring_depth()); gv_puts("\n" as *u8)
253 var t11: i64 = 0
254 if rbad == 0 - 6 { if rgood == 0 { if g4_ring_depth() == g4_ring_min() { t11 = 1 } } }
255 gv_check("T11 prefetch depth is the CALLER'S choice, with a structural floor enforced both ways" as *u8, t11, ctr)
256
257 // T12 the arena COUNTS ITSELF. No expected byte total is written here -- writing one would recreate
258 // the hand-maintained count this organ was changed to eliminate. What is asserted instead is that the
259 // number is real and behaves like a measurement: non-zero, and tracking the capacity it was given.
260 g4_init(GG_CAP*4, GG_RING)
261 let bbig: i64 = g4_bytes()
262 gv_puts(" arena: " as *u8); gv_num(bbig)
263 gv_puts(" bytes at capacity " as *u8); gv_num(g4_cap())
264 gv_puts(", counted by construction at every allocation\n" as *u8)
265 var t12: i64 = 0
266 if bbig > 0 { if g4_cap() == GG_CAP*4 { t12 = 1 } }
267 gv_check("T12 the arena counts itself: bytes are accumulated at every allocation, never hand-maintained" as *u8, t12, ctr)
268
269 let rc: i64 = gv_verdict("GSPLAT4D-GATE" as *u8, ctr, "the temporal axis is real: exact envelope identities, laws instead of tolerances, controls instead of thresholds, refusals that fail closed" as *u8)
270 sys_exit(rc)
271 return rc
272}