code wiki / _hdl_build / nx_weather_gate.nx
nx_weather_gate.nx source
↩ module page · 162 lines · 7535 B
1// nx_weather_gate.nx -- GATE for nx_weather_lib (2026-08-26). The accept rule, PRE-DECLARED:
2// the continuous weather system may ship only if (1) it PRESERVES the banked seasonal rain rates
3// (P_RAINS rows) within the binomial envelope -- adopting it cannot silently change any world's
4// climate; (2) it exhibits the PERSISTENCE the old coin structurally lacked, measured, not
5// asserted; (3) every field is replay-deterministic; (4) precipitation typing obeys the freezing
6// bound; (5) wind spikes on pressure fronts. Neg-controls prove the teeth can fail.
7// license_tier: ORIGINAL No hw writes (Rule 26).
8import "nx_syscalls.nx"
9import "nx_weather_lib.nx"
10import "nx_gate_verdict.nx"
11
12const XW_EIGHTHS: i64 = 8000 // ~1000 days per season row: binomial envelope ~ +/-3 sigma
13const XW_SEED: i64 = 424242
14
15func xw_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
16
17func main() -> i64 {
18 let ctr: *i64 = gv_ctr()
19
20 // T1 DETERMINISM: the same (seed, eighth) reproduces every field bit-for-bit.
21 var t1: i64 = 1
22 var k: i64 = 0
23 while k < 50 {
24 let e: i64 = 1000 + k*37
25 if wx_pressure(XW_SEED, e) != wx_pressure(XW_SEED, e) { t1 = 0 }
26 if wx_rain(XW_SEED, e, 300) != wx_rain(XW_SEED, e, 300) { t1 = 0 }
27 if wx_wind_speed(XW_SEED, e) != wx_wind_speed(XW_SEED, e) { t1 = 0 }
28 k = k + 1
29 }
30 gv_check("T1 DETERMINISM: every field is a pure function of (seed, eighth) -- replay exact" as *u8, t1, ctr)
31
32 // T2 RATE PRESERVATION: empirical rain frequency over XW_EIGHTHS matches the row within
33 // 3 binomial sigmas (sigma = sqrt(p(1-p)/n)); tested at the four banked craft-world rows.
34 var t2: i64 = 1
35 let rows: *i64 = sys_mmap(4*8) as *i64
36 rows[0] = 420; rows[1] = 220; rows[2] = 380; rows[3] = 180
37 var s9: i64 = 0
38 while s9 < 4 {
39 let row: i64 = rows[s9]
40 var hits: i64 = 0
41 var e2: i64 = 0
42 while e2 < XW_EIGHTHS {
43 hits = hits + wx_rain(XW_SEED + s9, e2, row)
44 e2 = e2 + 1
45 }
46 let emp: i64 = hits*1000/XW_EIGHTHS
47 // 3 sigma in permil: 3*sqrt(row*(1000-row)/n) -- integer sqrt via crude Newton
48 var v9: i64 = row*(1000 - row)/XW_EIGHTHS
49 var r9: i64 = v9
50 if r9 > 1 { var it9: i64 = 0
51 while it9 < 20 { if r9 > 0 { r9 = (r9 + v9/r9)/2 } it9 = it9 + 1 } }
52 let tol: i64 = 3*r9 + 12 // +12 permil: the quantization floor of the Q12 mix, named
53 gv_puts(" row=" as *u8); gv_num(row)
54 gv_puts(" empirical=" as *u8); gv_num(emp)
55 gv_puts(" tol=" as *u8); gv_num(tol); gv_puts("\n" as *u8)
56 if xw_abs(emp - row) > tol { t2 = 0 }
57 s9 = s9 + 1
58 }
59 gv_check("T2 RATE PRESERVATION: empirical seasonal rain frequency stays inside the banked row's binomial envelope -- adoption cannot change any world's climate" as *u8, t2, ctr)
60
61 // T3 PERSISTENCE: P(rain | rain at e-1) must exceed P(rain | dry at e-1) by a measurable
62 // margin. THE OLD COIN CANNOT PASS THIS (memoryless: both conditionals equal) -- this tooth IS
63 // the capability claim.
64 var rr: i64 = 0
65 var rn: i64 = 0
66 var dr: i64 = 0
67 var dn: i64 = 0
68 var e3: i64 = 1
69 while e3 < XW_EIGHTHS {
70 let prev: i64 = wx_rain(XW_SEED, e3 - 1, 300)
71 let cur: i64 = wx_rain(XW_SEED, e3, 300)
72 if prev == 1 { rn = rn + 1; rr = rr + cur }
73 if prev == 0 { dn = dn + 1; dr = dr + cur }
74 e3 = e3 + 1
75 }
76 var pr_r: i64 = 0
77 if rn > 0 { pr_r = rr*1000/rn }
78 var pr_d: i64 = 0
79 if dn > 0 { pr_d = dr*1000/dn }
80 gv_puts(" P(rain|rain)=" as *u8); gv_num(pr_r)
81 gv_puts(" P(rain|dry)=" as *u8); gv_num(pr_d); gv_puts(" permil\n" as *u8)
82 var t3: i64 = 0
83 if pr_r > pr_d + 50 { t3 = 1 }
84 gv_check("T3 PERSISTENCE: fronts exist -- P(rain|rain) exceeds P(rain|dry) by >50 permil, the structure the memoryless coin could not express" as *u8, t3, ctr)
85
86 // T4 TYPED PRECIPITATION: snow requires cold -- across many eighths, every precip==2 event
87 // has temp below freezing, and summer daytime NEVER snows.
88 var t4: i64 = 1
89 var sn: i64 = 0
90 var e4: i64 = 0
91 while e4 < 4000 {
92 var ssn: i64 = (e4/16) % 4
93 let pt: i64 = wx_precip(XW_SEED, e4, 400, ssn, e4 % 2)
94 if pt == 2 {
95 sn = sn + 1
96 if wx_temp(ssn, e4 % 2, XW_SEED, e4) >= WX_FREEZE_Q { t4 = 0 }
97 }
98 if ssn == 1 { if e4 % 2 == 0 { if pt == 2 { t4 = 0 } } }
99 e4 = e4 + 1
100 }
101 gv_puts(" snow_events=" as *u8); gv_num(sn); gv_puts("\n" as *u8)
102 var t4b: i64 = 0
103 if sn > 0 { t4b = 1 }
104 gv_check("T4 SNOW IS COLD: every snow event sits below the freezing bound; summer noon never snows" as *u8, t4, ctr)
105 gv_check("T4b FIXTURE REACHED THE CONDITION: snow actually occurred in the sampled winter nights (a typed-precip tooth over zero events proves nothing)" as *u8, t4b, ctr)
106
107 // T5 WIND FRONTS: mean wind speed on eighths where pressure moved most (top decile of
108 // |gradient|) must exceed the mean on the calmest decile -- wind is the gradient, measured.
109 var gsum: i64 = 0
110 var e5: i64 = 1
111 while e5 < 2001 {
112 gsum = gsum + xw_abs(wx_pressure(XW_SEED, e5) - wx_pressure(XW_SEED, e5 - 1))
113 e5 = e5 + 1
114 }
115 let gavg: i64 = gsum/2000
116 var whi: i64 = 0
117 var nhi: i64 = 0
118 var wlo: i64 = 0
119 var nlo: i64 = 0
120 e5 = 1
121 while e5 < 2001 {
122 let g5: i64 = xw_abs(wx_pressure(XW_SEED, e5) - wx_pressure(XW_SEED, e5 - 1))
123 let w5: i64 = wx_wind_speed(XW_SEED, e5)
124 if g5 > gavg*2 { whi = whi + w5; nhi = nhi + 1 }
125 if g5 < gavg/2 { wlo = wlo + w5; nlo = nlo + 1 }
126 e5 = e5 + 1
127 }
128 var t5: i64 = 0
129 if nhi > 0 { if nlo > 0 { if whi/nhi > wlo/nlo { t5 = 1 } } }
130 gv_puts(" wind hi-gradient avg=" as *u8); if nhi > 0 { gv_num(whi/nhi) }
131 gv_puts(" lo-gradient avg=" as *u8); if nlo > 0 { gv_num(wlo/nlo) }
132 gv_puts(" (n=" as *u8); gv_num(nhi); gv_puts("/" as *u8); gv_num(nlo); gv_puts(")\n" as *u8)
133 gv_check("T5 WIND RIDES FRONTS: high-pressure-gradient eighths are windier than calm ones -- the physical shape, not a random number" as *u8, t5, ctr)
134
135 // T6 neg-control-memoryless-coin-fails-T3: the OLD system (a fresh draw per eighth against the
136 // row) must show NO persistence margin -- proving T3's ruler discriminates.
137 var crr: i64 = 0
138 var crn: i64 = 0
139 var cdr: i64 = 0
140 var cdn: i64 = 0
141 var e6: i64 = 1
142 while e6 < XW_EIGHTHS {
143 var cp: i64 = 0
144 if wx_draw(XW_SEED, e6 - 1, 771)*1000 < 300*WX_Q { cp = 1 }
145 var cc: i64 = 0
146 if wx_draw(XW_SEED, e6, 771)*1000 < 300*WX_Q { cc = 1 }
147 if cp == 1 { crn = crn + 1; crr = crr + cc }
148 if cp == 0 { cdn = cdn + 1; cdr = cdr + cc }
149 e6 = e6 + 1
150 }
151 var cpr_r: i64 = 0
152 if crn > 0 { cpr_r = crr*1000/crn }
153 var cpr_d: i64 = 0
154 if cdn > 0 { cpr_d = cdr*1000/cdn }
155 var t6: i64 = 0
156 if xw_abs(cpr_r - cpr_d) < 50 { t6 = 1 }
157 gv_puts(" coin control: P(r|r)=" as *u8); gv_num(cpr_r)
158 gv_puts(" P(r|d)=" as *u8); gv_num(cpr_d); gv_puts("\n" as *u8)
159 gv_check("T6 neg-control-the-memoryless-coin-shows-no-persistence: T3's ruler discriminates structure from chance" as *u8, t6, ctr)
160
161 return gv_verdict("WEATHER" as *u8, ctr, "the continuous weather system: replay-deterministic, preserves every banked seasonal rain rate, exhibits measured front persistence the old coin could not, types precipitation by cold, and winds up on pressure gradients" as *u8)
162}