code wiki / _hdl_build / nx_chaos_gate.nx
nx_chaos_gate.nx source
↩ module page · 107 lines · 8150 B
1// nx_chaos_gate.nx -- NATIVE verify of the browser chaos sim (base = mmap; SAME code runs in sovereign WASM). The
2// logistic map x'=r x(1-x) across regimes: (a) FIXED POINT at r=2.5 -> x*=1-1/r=0.6, (b) PERIOD-2 at r=3.2 (orbit
3// alternates between two values), (c) CHAOS at r=3.9 (wide aperiodic spread), (d) SENSITIVE DEPENDENCE -- two starts
4// one unit apart diverge hugely at r=3.9. The headline: (e) DETERMINISM -- the SAME (x0,r) run twice gives the
5// BIT-EXACT same chaotic sequence; integer/no-float chaos is reproducible exactly where IEEE-754 float chaos
6// diverges machine-to-machine = the live face of the Reproducibility EXCEEDS. Liar-kill: at r=2.5 the two nearby
7// starts CONVERGE (no divergence) -- chaos is genuinely r-dependent, not faked. license_tier: ORIGINAL expect_exit: 0
8import "nx_syscalls.nx"
9import "nx_chaos.nx"
10import "nx_png.nx"
11import "nx_gate_verdict.nx"
12
13func g_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
14func g_n(v: i64) -> i64 { var m: i64=v; if m<0{g_w("-");m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i:i64=0; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1}; sys_write(1,o,k); return 0 }
15// ★D001 MIGRATED BY HAND, same as nx_solarsim_gate and nx_gassim_gate: the pass[0]-pointer-against-a
16// -literal-denominator idiom is one nx_gate_dry_apply does not recognise, and the allow_own_verdict
17// escape ships a gate no judge can read. On the shared base class declared == executed BY
18// CONSTRUCTION -- the two rows added below move the count themselves, where the hand-written literal
19// would have printed 9/7 and been "fixed" by editing the literal rather than the tooth.
20func g_row(id: *u8, ok: i64, ctr: *i64) -> i64 { return gv_check(id, ok, ctr) }
21func iabs(x: i64) -> i64 { if x<0 { return 0-x } return x }
22
23func iterate_n(x0: i64, R: i64, n: i64) -> i64 { var x: i64=x0; var i: i64=0; while i<n { x=logistic(x,R); i=i+1 } return x }
24func diff_after(R: i64, a0: i64, b0: i64, n: i64) -> i64 { var a: i64=a0; var b: i64=b0; var i: i64=0; while i<n { a=logistic(a,R); b=logistic(b,R); i=i+1 } return iabs(a-b) }
25func spread(R: i64, trans: i64, samp: i64) -> i64 {
26 var x: i64=500000; var i: i64=0; while i<trans { x=logistic(x,R); i=i+1 }
27 var mn: i64=x; var mx: i64=x; i=0; while i<samp { x=logistic(x,R); if x<mn { mn=x } if x>mx { mx=x } i=i+1 }
28 return mx-mn
29}
30
31func main() -> i64 {
32 let pass: *i64 = gv_ctr()
33 g_w("=== NX-CHAOS native verify (logistic-map deterministic chaos; SAME code runs in sovereign wasm) ===\n")
34 let base: i64 = sys_mmap(2*1048576) as i64
35
36 let fp: i64 = iterate_n(500000, 2500, 800) // r=2.5 fixed point -> 600000
37 // r=3.2 period-2
38 var x: i64=500000; var i: i64=0; while i<600 { x=logistic(x,3200); i=i+1 }
39 let a: i64=x; let b: i64=logistic(a,3200); let c: i64=logistic(b,3200)
40 var p2: i64=0; if iabs(a-c)<300 { if iabs(a-b)>50000 { p2=1 } }
41 let sp_chaos: i64 = spread(3900, 200, 200) // r=3.9 wide spread
42 let sp_fixed: i64 = spread(2500, 200, 200) // r=2.5 ~0 spread
43 let div39: i64 = diff_after(3900, 500000, 500001, 60) // sensitive dependence
44 let div25: i64 = diff_after(2500, 500000, 500001, 200)// converges (liar-kill)
45 let run1: i64 = iterate_n(500000, 3900, 120); let run2: i64 = iterate_n(500000, 3900, 120)
46
47 g_w(" fixed-pt(r2.5)="); g_n(fp); g_w(" (x*=600000) period2(r3.2): a="); g_n(a); g_w(" b="); g_n(b); g_w(" c="); g_n(c); g_w("\n")
48 g_w(" spread chaos(r3.9)="); g_n(sp_chaos); g_w(" vs fixed(r2.5)="); g_n(sp_fixed); g_w(" sensitive div(r3.9,60it)="); g_n(div39); g_w(" vs div(r2.5)="); g_n(div25); g_w("\n")
49 g_w(" determinism: run1="); g_n(run1); g_w(" run2="); g_n(run2); g_w(" (must be identical)\n")
50
51 init_impl(base); var t: i64=0; while t<HISTN { tick_impl(base, 0); t=t+1 }
52 render_impl(base)
53 write_png((base + O_FB) as *i64, W, H, "knowledge/nx_chaos.png" as *u8)
54 let m: *u8=(base+O_FB) as *u8; var nb: i64=0; i=0
55 while i<W*H { let bb: i64=i*8; if (m[bb] as i64)!=10 { nb=nb+1 } else { if (m[bb+1] as i64)!=10 { nb=nb+1 } else { if (m[bb+2] as i64)!=18 { nb=nb+1 } } } i=i+1 }
56
57 // ★THE RASTER ROW CLAIMED "two diverging trajectories" WHILE COUNTING PIXELS. nb>100 is satisfied
58 // by ONE trajectory, or by two that never separate -- neither the count nor the divergence was
59 // ever tested in the FRAME. Found 2026-08-14 by nx_vacuity_census; same class as nx_solarsim_gate
60 // ("Sun + planets", tested the Sun) and nx_gassim_gate ("20 particles", counted pixels).
61 // The plot mapping is taken from render_impl rather than re-derived:
62 // ya = (H-8) - HA[x]*(H-16)/SC at column x+8, trajectory A rgb(90,170,255)
63 // yb likewise for HB[x], trajectory B rgb(255,110,90)
64 // B is drawn AFTER A, so where the two coincide B legitimately overwrites A -- which is why this
65 // asks for each colour to be PRESENT rather than for every sample to match, a demand that would
66 // make the tooth flaky the moment the trajectories touch.
67 let fbc: *i64 = (base+O_FB) as *i64
68 let HAg: *i64 = (base+O_HA) as *i64
69 let HBg: *i64 = (base+O_HB) as *i64
70 let colA: i64 = rgb(90,170,255)
71 let colB: i64 = rgb(255,110,90)
72 var seenA: i64=0; var seenB: i64=0
73 var firstgap: i64=0-1; var lastgap: i64=0-1
74 var cx: i64=0
75 while cx<HISTN {
76 let av: i64=HAg[cx]; let bv: i64=HBg[cx]
77 if av>=0 { if bv>=0 {
78 let ya: i64=(H-8) - av*(H-16)/SC
79 let yb: i64=(H-8) - bv*(H-16)/SC
80 if ya>=0 { if ya<H { if fbc[ya*W + cx+8]==colA { seenA=seenA+1 } } }
81 if yb>=0 { if yb<H { if fbc[yb*W + cx+8]==colB { seenB=seenB+1 } } }
82 let gap: i64 = iabs(ya-yb)
83 if firstgap<0 { firstgap=gap }
84 lastgap=gap
85 } }
86 cx=cx+1
87 }
88 g_w(" plotted: A-coloured samples="); g_n(seenA); g_w(" B-coloured samples="); g_n(seenB)
89 g_w(" vertical gap first="); g_n(firstgap); g_w(" last="); g_n(lastgap); g_w("\n")
90
91 g_row("RUNS: the logistic map iterated across regimes (fixed point / period-2 / chaos)" as *u8, (fp>0) as i64, pass)
92 g_row("FIXED POINT (r=2.5): converges to x* = 1-1/r = 0.6 within 0.2%" as *u8, (iabs(fp-600000)<2000) as i64, pass)
93 g_row("PERIOD-2 (r=3.2): the orbit alternates between two distinct values (x_n = x_n+2 != x_n+1)" as *u8, p2, pass)
94 g_row("CHAOS (r=3.9): aperiodic wide spread (>0.4) vs the fixed point's ~0 spread" as *u8, ((sp_chaos>400000) as i64)*((sp_fixed<2000) as i64), pass)
95 g_row("SENSITIVE DEPENDENCE: two starts one unit apart diverge hugely at r=3.9 (>0.1) -- the butterfly effect" as *u8, (div39>100000) as i64, pass)
96 g_row("DETERMINISM=EXCEEDS: the SAME (x0,r) run twice gives the BIT-EXACT same chaotic value (integer reproducibility where float diverges)" as *u8, (run1==run2) as i64, pass)
97 g_row("LIAR-KILL: at r=2.5 the two nearby starts CONVERGE (<0.01 apart) -- divergence is genuinely r-dependent, not faked" as *u8, (div25<10000) as i64, pass)
98 g_row("RASTER: the frame is non-empty (this row only counts non-background pixels -- see the two below)" as *u8, (nb>100) as i64, pass)
99 g_row("BOTH TRAJECTORIES PLOTTED: pixels of A's colour AND of B's colour are both present, so the picture really shows TWO runs and not one drawn twice" as *u8, ((seenA>0) as i64)*((seenB>0) as i64), pass)
100 g_row("DIVERGENCE IS VISIBLE: the vertical gap between the two plotted trajectories is larger at the end than at the start -- the butterfly effect in the FRAME, not just in the numbers" as *u8, (lastgap > firstgap) as i64, pass)
101 var iface: i64=0; if ww()==W { if hh()==H { if fb_off()==O_FB { iface=1 } } }
102 g_row("WASM-READY: init/tick/render/ww/hh/fb_off interface intact" as *u8, iface, pass)
103
104 let rc: i64 = gv_verdict("CHAOS-GATE" as *u8, pass, "deterministic chaos; sensitive-dependence + BIT-EXACT reproducibility, and BOTH trajectories verified present and visibly diverging in the rendered frame" as *u8)
105 sys_exit(rc)
106 return rc
107}