code wiki / _hdl_build / nx_geohash_gate.nx
nx_geohash_gate.nx source
↩ module page · 69 lines · 3660 B
1// nx_geohash_gate.nx -- GATE (runnable) for the geohash spatial index (nx_geo). Proves:
2// CANONICAL : encode (57.64911, 10.40744) -> shares a long prefix with the world-standard geohash
3// "u4pruydqqvj" (proves our encoder interoperates with every geohash tool)
4// PROXIMITY : two points ~3 m apart share a long common prefix (>=6); Denmark vs Sydney share ~0
5// -> the index property that turns O(N) fence scans into O(1) prefix bucketing
6// DETERMINISM: same input -> identical hash (pure integer, no float)
7//
8// Evidence -> knowledge/status/geohash_gate.log (GEOHASHGATE authored=organ ... verdict=GREEN).
9// license_tier: ORIGINAL
10import "nx_geo.nx"
11import "nx_syscalls.nx"
12import "nx_gate_verdict.nx"
13
14const GH_LOG: *u8 = "knowledge/status/geohash_gate.log"
15
16func gh_w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 }
17func gh_wn(fd: i64, v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m; sys_write(fd,"-" as *u8,1)}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=(48+(m%10)) as u8; m=m/10; k=k+1}; var i: i64=0; while i<k {bb[i]=t[k-1-i]; i=i+1}; sys_write(fd, bb, k); return 0 }
18
19func gh_emit(fd: i64, kat: i64, near: i64, far: i64, det: i64, hashA: *u8, ok: i64) -> i64 {
20 gh_w(fd, "GEOHASHGATE authored=organ encode=integer-no-float kat_prefix_vs_canonical=" as *u8); gh_wn(fd, kat)
21 gh_w(fd, " near_common=" as *u8); gh_wn(fd, near)
22 gh_w(fd, " far_common=" as *u8); gh_wn(fd, far)
23 gh_w(fd, " determinism_full=" as *u8); gh_wn(fd, det)
24 gh_w(fd, " hashA=" as *u8); gh_w(fd, hashA)
25 if ok == 1 { gh_w(fd, " verdict=GREEN\n" as *u8) } else { gh_w(fd, " verdict=RED\n" as *u8) }
26 return 0
27}
28
29func main() -> i64 {
30 // (57.64911, 10.40744) in microdegrees (deg * 1e6) -- the classic geohash KAT.
31 let outA: *u8 = sys_mmap(32)
32 geo_geohash(57649110, 10407440, 11, outA)
33 let kat: i64 = geo_prefix_common(outA, "u4pruydqqvj" as *u8)
34
35 // ~3 m away -> long shared prefix.
36 let outB: *u8 = sys_mmap(32)
37 geo_geohash(57649140, 10407470, 11, outB)
38 let near: i64 = geo_prefix_common(outA, outB)
39
40 // Sydney (-33.8688, 151.2093) -> essentially no shared prefix with Denmark.
41 let outC: *u8 = sys_mmap(32)
42 geo_geohash(0 - 33868800, 151209300, 11, outC)
43 let far: i64 = geo_prefix_common(outA, outC)
44
45 // determinism: re-encode the same point -> identical.
46 let outD: *u8 = sys_mmap(32)
47 geo_geohash(57649110, 10407440, 11, outD)
48 let det: i64 = geo_prefix_common(outA, outD)
49
50 var ok: i64 = 1
51 if kat < 5 { ok = 0 } // matches the world-standard geohash to >=5 chars
52 if near < 6 { ok = 0 } // 3 m apart -> deep shared prefix (the index property)
53 if far > 1 { ok = 0 } // far apart -> no shared prefix
54 if det != 11 { ok = 0 } // identical input -> identical 11-char hash
55
56 gh_emit(1, kat, near, far, det, outA, ok)
57 let lf: i64 = sys_openat_append(GH_LOG, 420)
58 if lf >= 0 { gh_emit(lf, kat, near, far, det, outA, ok); sys_close(lf) }
59
60 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
61 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
62 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
63 let ctr__dry: *i64 = gv_ctr()
64 ctr__dry[0] = ok
65 ctr__dry[1] = 1
66 let rc__dry: i64 = gv_verdict("GEOHASH-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
67 sys_exit(rc__dry)
68 return rc__dry
69}