code wiki / _hdl_build / nx_ocr_recall_gate.nx

nx_ocr_recall_gate.nx source

↩ module page · 59 lines · 3124 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_ocr_recall_gate.nx -- PROOF the reading-recall scorer is honest (the metric that ended the typography 4// arc's "it looks fine" self-deception, now on the browser). Known-answer fixtures written to disk, scored, 5// asserted EXACT. T1 identity=1000; T2 half the truth tokens present -> ~500; T3 NEG garbage vs truth -> ~0 6// (the liar-kill: a render of noise cannot score readable); T4 order-independent (multiset, not sequence); 7// T5 articles dropped (a/an/the ignored so chrome function-word noise can't inflate). The SCORE is always 8// printed raw. license_tier: ORIGINAL expect_exit: 0 9import "nx_syscalls.nx" 10import "nx_ocr_recall_lib.nx" 11 12func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 13" as *u8); return ok } 14 15// score in-process via the shared lib (no fork/pipe -- the scorer's math IS the lib; the .elf is a thin CLI) 16func grecall(truth: *u8, ours: *u8) -> i64 { 17 var tn: i64 = 0 18 while truth[tn] != (0 as u8) { tn = tn + 1 } 19 var on: i64 = 0 20 while ours[on] != (0 as u8) { on = on + 1 } 21 let out: *i64 = sys_mmap(32) as *i64 22 ocr_recall_score(truth, tn, ours, on, out) 23 return out[0] 24} 25func near(v: i64, want: i64, tol: i64) -> i64 { 26 var d: i64 = v - want 27 if d < 0 { d = 0 - d } 28 if d <= tol { return 1 } 29 return 0 30} 31 32func main() -> i64 { 33 gw("=== nx_ocr_recall_gate -- the reading-recall metric is honest (known-answer) ===\n" as *u8) 34 var fails: i64 = 0 35 36 let r1: i64 = grecall("alpha bravo charlie delta echo\x00" as *u8, "alpha bravo charlie delta echo\x00" as *u8) 37 gw(" T1 identity RECALL=" as *u8); gn(r1) 38 if r1 == 1000 { gw(" PASS\n" as *u8) } else { fails=fails+1; gw(" FAIL (want 1000)\n" as *u8) } 39 40 let r2: i64 = grecall("alpha bravo charlie delta\x00" as *u8, "alpha bravo zulu yankee\x00" as *u8) 41 gw(" T2 half-present RECALL=" as *u8); gn(r2) 42 if r2 == 500 { gw(" PASS\n" as *u8) } else { fails=fails+1; gw(" FAIL (want 500)\n" as *u8) } 43 44 let r3: i64 = grecall("alpha bravo charlie delta echo foxtrot\x00" as *u8, "qwxz plld mmnn vvbb\x00" as *u8) 45 gw(" T3 NEG garbage RECALL=" as *u8); gn(r3) 46 if r3 == 0 { gw(" PASS (noise cannot score readable)\n" as *u8) } else { fails=fails+1; gw(" FAIL (want 0)\n" as *u8) } 47 48 let r4: i64 = grecall("alpha bravo charlie\x00" as *u8, "charlie alpha bravo\x00" as *u8) 49 gw(" T4 order-independent RECALL=" as *u8); gn(r4) 50 if r4 == 1000 { gw(" PASS (multiset, not sequence)\n" as *u8) } else { fails=fails+1; gw(" FAIL\n" as *u8) } 51 52 let r5: i64 = grecall("the alpha a bravo an charlie\x00" as *u8, "alpha bravo charlie\x00" as *u8) 53 gw(" T5 articles-dropped RECALL=" as *u8); gn(r5) 54 if r5 == 1000 { gw(" PASS (a/an/the ignored)\n" as *u8) } else { fails=fails+1; gw(" FAIL\n" as *u8) } 55 56 if fails == 0 { gw("NX-OCR-RECALL GREEN -- reading-recall is exact, order-free, article-immune, noise-proof\n" as *u8); sys_exit(0); return 0 } 57 gw("NX-OCR-RECALL RED fails=" as *u8); gn(fails); gw("\n" as *u8) 58 sys_exit(1); return 1 59}