code wiki / _hdl_build / nx_ad_h2h_gate.nx
nx_ad_h2h_gate.nx source
↩ module page · 75 lines · 3790 B
1// nx_ad_h2h_gate.nx -- GATE (runnable) for the measured head-to-head comparators (nx_ad_h2h). Proves
2// the raw measured values AND that we strictly beat the incumbent baseline on each named axis, AND
3// that the comparator is a genuine liar-kill (equal/worse -> no beat):
4// DELIVERY ours third-party-JS=0, incumbent(GPT)=1 -> beat
5// TRANSPARENCY ours external-seller-domain=0, incumbent=1 -> beat
6// SIGNUP ours cost-on-miss=$0, incumbent(CPM)>0 -> beat
7// liar-kill beats_lower(1,1)=0, beats_lower(2,1)=0, beats_lower(0,1)=1
8// Evidence -> knowledge/status/ad_h2h.log (H2HGATE ... verdict=GREEN). license_tier: ORIGINAL
9import "nx_ad_h2h.nx"
10import "nx_syscalls.nx"
11import "nx_gate_verdict.nx"
12
13const HG_LOG: *u8 = "knowledge/status/ad_h2h.log"
14
15func hg_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 hg_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 main() -> i64 {
19 let d_ours: i64 = h2h_delivery_ours()
20 let d_inc: i64 = h2h_delivery_incumbent()
21 let d: i64 = h2h_delivery()
22 let t_ours: i64 = h2h_transparency_ours()
23 let t_inc: i64 = h2h_transparency_incumbent()
24 let t: i64 = h2h_transparency()
25 let s_ours: i64 = h2h_signup_ours()
26 let s_inc: i64 = h2h_signup_incumbent()
27 let s: i64 = h2h_signup()
28 let lk_equal: i64 = h2h_beats_lower(1, 1)
29 let lk_worse: i64 = h2h_beats_lower(2, 1)
30 let lk_better: i64 = h2h_beats_lower(0, 1)
31
32 var ok: i64 = 1
33 if d_ours != 0 { ok = 0 }
34 if d_inc != 1 { ok = 0 }
35 if d != 1 { ok = 0 }
36 if t_ours != 0 { ok = 0 }
37 if t_inc != 1 { ok = 0 }
38 if t != 1 { ok = 0 }
39 if s_ours != 0 { ok = 0 }
40 if s_inc != 1 { ok = 0 }
41 if s != 1 { ok = 0 }
42 if lk_equal != 0 { ok = 0 }
43 if lk_worse != 0 { ok = 0 }
44 if lk_better != 1 { ok = 0 }
45
46 hg_w(1, "H2HGATE authored=organ delivery[ours=" as *u8); hg_wn(1, d_ours)
47 hg_w(1, " incumbent=" as *u8); hg_wn(1, d_inc); hg_w(1, " beat=" as *u8); hg_wn(1, d)
48 hg_w(1, "] transparency[ours=" as *u8); hg_wn(1, t_ours)
49 hg_w(1, " incumbent=" as *u8); hg_wn(1, t_inc); hg_w(1, " beat=" as *u8); hg_wn(1, t)
50 hg_w(1, "] signup[ours_cost_on_miss=" as *u8); hg_wn(1, s_ours)
51 hg_w(1, " incumbent=" as *u8); hg_wn(1, s_inc); hg_w(1, " beat=" as *u8); hg_wn(1, s)
52 hg_w(1, "] liar_kill[eq=" as *u8); hg_wn(1, lk_equal); hg_w(1, " worse=" as *u8); hg_wn(1, lk_worse); hg_w(1, " better=" as *u8); hg_wn(1, lk_better)
53 if ok == 1 { hg_w(1, "] verdict=GREEN\n" as *u8) }
54 if ok != 1 { hg_w(1, "] verdict=RED\n" as *u8) }
55
56 let lf: i64 = sys_openat_append(HG_LOG, 420)
57 if lf >= 0 {
58 hg_w(lf, "H2HGATE delivery_beat=" as *u8); hg_wn(lf, d)
59 hg_w(lf, " transparency_beat=" as *u8); hg_wn(lf, t)
60 hg_w(lf, " signup_beat=" as *u8); hg_wn(lf, s)
61 if ok == 1 { hg_w(lf, " verdict=GREEN\n" as *u8) }
62 if ok != 1 { hg_w(lf, " verdict=RED\n" as *u8) }
63 sys_close(lf)
64 }
65
66 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
67 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
68 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
69 let ctr__dry: *i64 = gv_ctr()
70 ctr__dry[0] = ok
71 ctr__dry[1] = 1
72 let rc__dry: i64 = gv_verdict("AD-H2H-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
73 sys_exit(rc__dry)
74 return rc__dry
75}