code wiki / (root) / nx_claim_verify_core.nx

nx_claim_verify_core.nx source

↩ module page · 58 lines · 2728 B

1// nx_claim_verify_core.nx -- importable CORE of the sovereign claim verifier (logic extracted from nx_claim_verify.nx, 2// the 07-14 CLI, so it composes IN-PROCESS). Given fetched evidence text + a pattern the value follows + a claimed 3// value (tenths of a unit) + tolerance, returns the refutation verdict: 0 CONFIRMED, 3 DISCREDITED, 4 UNVERIFIABLE 4// (pattern absent -> invents NO number). Pure / deterministic / $0 / no-model / no-network -- the fetch stays in the 5// caller (S2 gate Tier-2). Prefix cvc_ so it never clashes when co-imported with other verify organs. 6// DUP-DEBT (honest): nx_claim_verify.nx (CLI) still carries private copies of find_after/parse_tenths/claim_verdict; 7// a follow-up should point it here (DRY) with a live re-run -- deferred now to avoid editing a same-day sibling file. 8// license_tier: ORIGINAL 9import "nx_syscalls.nx" 10 11func cvc_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 12 13// find pattern pat in buf[0..blen); index of the first char AFTER the match, or -1. 14func cvc_find_after(buf: *u8, blen: i64, pat: *u8) -> i64 { 15 let pl: i64 = cvc_slen(pat) 16 if pl == 0 { return 0-1 } 17 var i: i64 = 0 18 while i + pl <= blen { 19 var k: i64 = 0 20 var ok: i64 = 1 21 while k < pl { if ok == 1 { if buf[i+k] != pat[k] { ok = 0 } } k = k + 1 } 22 if ok == 1 { return i + pl } 23 i = i + 1 24 } 25 return 0-1 26} 27 28// parse a decimal at buf[off..] as TENTHS: "86.8"->868, "51.0"->510, "20"->200. non-digit start -> -1. 29func cvc_parse_tenths(buf: *u8, blen: i64, off: i64) -> i64 { 30 if off < 0 { return 0-1 } 31 var i: i64 = off 32 var whole: i64 = 0 33 var any: i64 = 0 34 var go: i64 = 1 35 while go == 1 { 36 go = 0 37 if i < blen { let c: i64 = buf[i] as i64; if c >= 48 { if c <= 57 { whole = whole*10 + (c-48); any = 1; i = i + 1; go = 1 } } } 38 } 39 if any == 0 { return 0-1 } 40 var tenths: i64 = whole * 10 41 if i < blen { if (buf[i] as i64) == 46 { if i+1 < blen { let d: i64 = buf[i+1] as i64; if d >= 48 { if d <= 57 { tenths = tenths + (d-48) } } } } } 42 return tenths 43} 44 45func cvc_iabs(x: i64) -> i64 { if x < 0 { return 0-x } return x } 46 47// the refutation decision: 0 CONFIRMED (|ext-claim|<=tol), 3 DISCREDITED, 4 UNVERIFIABLE (ext<0 = absent). 48func cvc_claim_verdict(ext: i64, claim: i64, tol: i64) -> i64 { 49 if ext < 0 { return 4 } 50 if cvc_iabs(ext - claim) <= tol { return 0 } 51 return 3 52} 53 54// one-shot: extract the value after pat in fetched text and verdict it. 0/3/4. 55func cvc_verify_text(buf: *u8, n: i64, pat: *u8, claim: i64, tol: i64) -> i64 { 56 let ext: i64 = cvc_parse_tenths(buf, n, cvc_find_after(buf, n, pat)) 57 return cvc_claim_verdict(ext, claim, tol) 58}