code wiki / _hdl_build / nx_evidence.nx

nx_evidence.nx source

↩ module page · 150 lines · 7187 B

1// nx_evidence.nx -- GRADED EVIDENCE ADMISSION for the dmkt lane. 2// 3// ★★THE DEFECT THIS FIXES IS MY OWN, FOUND HOURS AFTER SHIPPING IT. nx_gonogo's demand gate counted 4// ROWS IN A PLANE. A row count is not evidence: ten rows harvested from one interest are an ECHO of 5// that interest, not corroboration, and nothing stopped a CPSC recall (failure-mode evidence) from 6// being counted as DEMAND evidence and flipping the verdict to GO. **A COUNT IS NOT A MEASUREMENT 7// OF TRUTH, IT IS A MEASUREMENT OF HARVESTING EFFORT.** 8// 9// The estate already had the answer and the lane was not using it: nx_source_grade (45/45 gate) is a 10// source-criticism library encoding NATO/Admiralty reliability x credibility, first-party distance, 11// research-method rung, and -- the sharp one -- the INDEPENDENCE RULE: a claim is corroborated only 12// across >=2 DISTINCT incentive classes; same-class agreement is an echo of one interest. This organ 13// is that library applied where the decision actually gets made. 14// 15// ADMISSION IS THEREFORE THREE TESTS, ALL OF WHICH MUST PASS: 16// 1. VALID -- grades in range. Out-of-range is a DEFECT, never a default (sg_score_permil = -1). 17// 2. ACTIONABLE -- Admiralty F reliability or 6 credibility are honest cannot-judge states and are 18// NEVER actionable. They owe a fetch-task rather than a verdict. 19// 3. INDEPENDENT -- >=2 distinct incentive classes among the admitted rows, or the whole class of 20// evidence resolves to ECHO and COUNTS AS ZERO. Uncorroborated evidence is not weak evidence; 21// for a go/no-go it is no evidence. 22// 23// So `count` returns 0 for a plane full of same-class rows. That is the point: it makes nx_gonogo 24// say BLOCKED-ON-EVIDENCE when the evidence is real but incestuous, which is the failure mode that 25// actually kills products. 26// 27// DATA, NOT CODE (rule 11). Plane row `evidence-`: 28// <id> TAB <class> TAB <incentive_class> TAB <rel 1-6> TAB <cred 1-6> TAB <party 1-3> 29// TAB <method 1-5> TAB <source_url> TAB <claim> 30// class : demand | failure | cost | regulatory (WHAT the row is evidence OF) 31// incentive_class: 1 gov 2 vendor 3 consumer 4 media 5 academic 6 platform 32// Two rows may agree loudly and still be one voice; the incentive_class is what detects that. 33// 34// VERBS: 35// nx_evidence admit <planeprefix> <class> -> per-row grading + corroboration verdict (JSON) 36// nx_evidence count <planeprefix> <class> -> ONE integer: admitted rows, or 0 if not corroborated 37// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 38import "nx_syscalls.nx" 39import "nx_sourcing_path.nx" 40import "nx_source_grade.nx" 41 42const EV_MAXROWS: i64 = 128 43const EV_BUF: i64 = 65536 44const EV_CORROB_MIN_CLASSES: i64 = 2 45 46// k: 0 rows_in_class 1 admitted 2 unactionable 3 invalid 4 distinct_classes 5 corroborated 6 best_score 47func ev_admit(buf: *u8, n: i64, class: *u8, scratch: *u8, k: *i64) -> i64 { 48 var i: i64 = 0 49 while i < 8 { k[i] = 0; i = i + 1 } 50 let classes: *i64 = sys_mmap(EV_MAXROWS * 8) as *i64 51 var nclass: i64 = 0 52 let cnt: i64 = sp_rowcount(buf, n) 53 var r: i64 = 0 54 while r < cnt { 55 let rs: i64 = sp_row_start(buf, n, r) 56 if rs >= 0 { 57 lc_extract(buf, n, rs, 1, scratch, SP_FLDBUF) 58 if lc_eq(scratch, class) == 1 { 59 k[0] = k[0] + 1 60 let ic: i64 = sp_num(buf, n, rs, 2, scratch) 61 let rel: i64 = sp_num(buf, n, rs, 3, scratch) 62 let cred: i64 = sp_num(buf, n, rs, 4, scratch) 63 let party: i64 = sp_num(buf, n, rs, 5, scratch) 64 let method: i64 = sp_num(buf, n, rs, 6, scratch) 65 let score: i64 = sg_score_permil(rel, cred, party, method) 66 if score < 0 { 67 k[3] = k[3] + 1 68 } else { 69 if sg_actionable(rel, cred) == 0 { 70 k[2] = k[2] + 1 71 } else { 72 k[1] = k[1] + 1 73 if score > k[6] { k[6] = score } 74 // record a DISTINCT incentive class among ADMITTED rows only -- an 75 // unactionable row must not buy independence it did not earn. 76 var seen: i64 = 0 77 var c: i64 = 0 78 while c < nclass { if classes[c] == ic { seen = 1 } c = c + 1 } 79 if seen == 0 { if nclass < EV_MAXROWS { classes[nclass] = ic; nclass = nclass + 1 } } 80 } 81 } 82 } 83 } 84 r = r + 1 85 } 86 k[4] = nclass 87 if nclass >= EV_CORROB_MIN_CLASSES { k[5] = 1 } 88 return k[1] 89} 90 91// THE INTEGER nx_gonogo CONSUMES. Uncorroborated evidence returns ZERO, not a smaller number -- 92// for a decision gate, one voice repeated is indistinguishable from no voice at all. 93func ev_count(buf: *u8, n: i64, class: *u8, scratch: *u8) -> i64 { 94 let k: *i64 = sys_mmap(64) as *i64 95 ev_admit(buf, n, class, scratch, k) 96 if k[5] == 0 { return 0 } 97 return k[1] 98} 99 100func main(argc: i64, argv: *i64) -> i64 { 101 if argc < 4 { spw(2, "usage: nx_evidence {admit|count} <planeprefix> <class>\n" as *u8); return 2 } 102 let verb: *u8 = argv[1] as *u8 103 let buf: *u8 = sys_mmap(EV_BUF) 104 let n: i64 = sts_load(argv[2] as *u8, buf, EV_BUF) 105 let scratch: *u8 = sys_mmap(SP_FLDBUF) 106 let class: *u8 = argv[3] as *u8 107 let out: *u8 = sys_mmap(EV_BUF) 108 var o: i64 = 0 109 if n <= 0 { 110 if lc_eq(verb, "count" as *u8) == 1 { spw(1, "0\n" as *u8); return 0 } 111 spw(1, "{\"rows_in_class\":0,\"admitted\":0,\"corroborated\":0,\"verdict\":\"NO-EVIDENCE\"}\n" as *u8) 112 return 0 113 } 114 let k: *i64 = sys_mmap(64) as *i64 115 ev_admit(buf, n, class, scratch, k) 116 if lc_eq(verb, "count" as *u8) == 1 { 117 var c: i64 = 0 118 if k[5] == 1 { c = k[1] } 119 o = lc_num(out, o, c) 120 out[o] = 10 as u8; o = o + 1 121 out[o] = 0 as u8 122 spw(1, out) 123 return 0 124 } 125 o = lc_lit(out, o, "{\"class\":\"" as *u8) 126 o = lc_lit(out, o, class) 127 o = lc_lit(out, o, "\",\"rows_in_class\":" as *u8) 128 o = lc_num(out, o, k[0]) 129 o = lc_lit(out, o, ",\"admitted\":" as *u8) 130 o = lc_num(out, o, k[1]) 131 o = lc_lit(out, o, ",\"unactionable_owes_fetch\":" as *u8) 132 o = lc_num(out, o, k[2]) 133 o = lc_lit(out, o, ",\"invalid_grades\":" as *u8) 134 o = lc_num(out, o, k[3]) 135 o = lc_lit(out, o, ",\"distinct_incentive_classes\":" as *u8) 136 o = lc_num(out, o, k[4]) 137 o = lc_lit(out, o, ",\"best_score_permil\":" as *u8) 138 o = lc_num(out, o, k[6]) 139 o = lc_lit(out, o, ",\"counts_as\":" as *u8) 140 var c2: i64 = 0 141 if k[5] == 1 { c2 = k[1] } 142 o = lc_num(out, o, c2) 143 o = lc_lit(out, o, ",\"verdict\":\"" as *u8) 144 if k[0] == 0 { o = lc_lit(out, o, "NO-EVIDENCE" as *u8) } else { if k[1] == 0 { o = lc_lit(out, o, "NONE-ADMISSIBLE" as *u8) } else { if k[5] == 0 { o = lc_lit(out, o, "ECHO -- one incentive class only, counts as zero" as *u8) } else { o = lc_lit(out, o, "CORROBORATED" as *u8) } } } 145 o = lc_lit(out, o, "\"}" as *u8) 146 out[o] = 10 as u8; o = o + 1 147 out[o] = 0 as u8 148 spw(1, out) 149 return 0 150}