code wiki / _hdl_build / nx_geo_union_gate.nx
nx_geo_union_gate.nx source
↩ module page · 69 lines · 3512 B
1// nx_geo_union_gate.nx -- GATE for GEO-016 polygon union/intersection measure (inclusion-exclusion).
2// A = [0,4e6]^2 (doubled area 3.2e13). Three B polygons prove inclusion-exclusion exactly:
3// overlap B=[2e6,6e6]^2 : A n B = 8e12 -> union = 3.2e13+3.2e13-8e12 = 5.6e13; iou = 8e12/5.6e13 = 142permil
4// disjoint B=[10e6,14e6]^2 : A n B = 0 -> union = 6.4e13 (purely additive); iou = 0
5// contain B=[1e6,3e6]^2 : A n B = 8e12 = area(B) -> union = 3.2e13 (= area(A)); iou = 8e12/3.2e13 = 250permil
6//
7// Evidence -> knowledge/status/geo_union.log (GEOUNIONGATE authored=organ ... verdict=GREEN).
8// license_tier: ORIGINAL
9import "nx_geo_union.nx"
10import "nx_syscalls.nx"
11import "nx_gate_verdict.nx"
12
13const GU_LOG: *u8 = "knowledge/status/geo_union.log"
14
15func gu_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 }
16func gu_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 }
17
18func gu_set(p: *i64, i: i64, lat: i64, lon: i64) -> i64 { p[i * 2] = lat; p[i * 2 + 1] = lon; return 0 }
19func gu_square(p: *i64, lo: i64, hi: i64) -> i64 { gu_set(p, 0, lo, lo); gu_set(p, 1, lo, hi); gu_set(p, 2, hi, hi); gu_set(p, 3, hi, lo); return 0 }
20
21func gu_emit(fd: i64, uO: i64, iouO: i64, uD: i64, uC: i64, iouC: i64, ok: i64) -> i64 {
22 gu_w(fd, "GEOUNIONGATE authored=organ method=inclusion-exclusion overlap_union2=" as *u8); gu_wn(fd, uO)
23 gu_w(fd, " overlap_iou_permil=" as *u8); gu_wn(fd, iouO)
24 gu_w(fd, " disjoint_union2=" as *u8); gu_wn(fd, uD)
25 gu_w(fd, " contains_union2=" as *u8); gu_wn(fd, uC)
26 gu_w(fd, " contains_iou_permil=" as *u8); gu_wn(fd, iouC)
27 if ok == 1 { gu_w(fd, " verdict=GREEN\n" as *u8) } else { gu_w(fd, " verdict=RED\n" as *u8) }
28 return 0
29}
30
31func main() -> i64 {
32 let a: *i64 = sys_mmap(8 * 8) as *i64
33 gu_square(a, 0, 4000000)
34
35 let bO: *i64 = sys_mmap(8 * 8) as *i64
36 gu_square(bO, 2000000, 6000000)
37 let uO: i64 = geo_union_area2(a, 4, bO, 4)
38 let iouO: i64 = geo_iou_permil(a, 4, bO, 4)
39
40 let bD: *i64 = sys_mmap(8 * 8) as *i64
41 gu_square(bD, 10000000, 14000000)
42 let uD: i64 = geo_union_area2(a, 4, bD, 4)
43
44 let bC: *i64 = sys_mmap(8 * 8) as *i64
45 gu_square(bC, 1000000, 3000000)
46 let uC: i64 = geo_union_area2(a, 4, bC, 4)
47 let iouC: i64 = geo_iou_permil(a, 4, bC, 4)
48
49 var ok: i64 = 1
50 if uO != 56000000000000 { ok = 0 }
51 if iouO != 142 { ok = 0 }
52 if uD != 64000000000000 { ok = 0 }
53 if uC != 32000000000000 { ok = 0 }
54 if iouC != 250 { ok = 0 }
55
56 gu_emit(1, uO, iouO, uD, uC, iouC, ok)
57 let lf: i64 = sys_openat_append(GU_LOG, 420)
58 if lf >= 0 { gu_emit(lf, uO, iouO, uD, uC, iouC, 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("GEO-UNION-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}