code wiki / _hdl_build / nx_swcompare_bench.nx

nx_swcompare_bench.nx source

↩ module page · 230 lines · 18250 B

1// nx_swcompare_bench.nx -- RUN-AND-COMPARE bench (the deepest form of "mechanically test and bench"): instead of 2// symbol-presence, it IMPORTS a real Nishi organ, RUNS it on known inputs, and compares OUR computed output to the 3// mathematically-correct answer (identical to what Wolfram / any correct CAS produces). Domain 1 = EXACT RATIONAL 4// arithmetic (nx_rational). Each row shows input -> Nishi's value vs the correct value -> PASS/FAIL. Liar-killed: all 5// real KATs must pass AND a NEG-CONTROL (checked against a deliberately-wrong answer) must FAIL (proves the check 6// discriminates). Modes: no-arg = console + gate; "html" = /compare/computational/bench page. 7// NOTE: no '#'/'!' in string literals (nx_cc trap) -> rgb() + emit '!' byte. license_tier: ORIGINAL expect_exit:0 8import "nx_rational.nx" 9import "nx_poly.nx" 10import "nx_matrix.nx" 11import "nx_bigint_lib.nx" 12const K_MAGIC_5050: i64 = 5050 13const K_MAGIC_4294967296: i64 = 4294967296 14const K_MAGIC_65536: i64 = 65536 15const K_MAGIC_3735928559: i64 = 3735928559 16const K_MAGIC_4294967295: i64 = 4294967295 17 18func 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 } 19func wc(fd: i64, code: i64) -> i64 { let t: *u8 = sys_mmap(2); t[0] = code as u8; sys_write(fd, t, 1); return 0 } 20func wn(fd: i64, v: i64) -> i64 { 21 var m: i64 = v; if m < 0 { w(fd, "-" as *u8); m = 0 - m } 22 let t: *u8 = sys_mmap(24); var k: i64 = 0; if m == 0 { t[0] = 48 as u8; k = 1 } 23 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 24 let o: *u8 = sys_mmap(24); var i: i64 = 0; while i < k { o[i] = t[k-1-i]; i = i + 1 } sys_write(fd, o, k); return 0 25} 26func wrat(fd: i64, num: i64, den: i64) -> i64 { wn(fd, num); w(fd, "/" as *u8); wn(fd, den); return 0 } 27func streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } if b[i] != (0 as u8) { return 0 } return 1 } 28 29func main(argc: i64, argv: *i64) -> i64 { 30 var html: i64 = 0 31 if argc >= 2 { if streq(argv[1] as *u8, "html" as *u8) == 1 { html = 1 } } 32 33 // parallel arrays for rows 34 let lab: *i64 = sys_mmap(32 * 8) 35 let expr: *i64 = sys_mmap(32 * 8) 36 let on: *i64 = sys_mmap(32 * 8) 37 let od: *i64 = sys_mmap(32 * 8) 38 let en: *i64 = sys_mmap(32 * 8) 39 let ed: *i64 = sys_mmap(32 * 8) 40 let ps: *i64 = sys_mmap(32 * 8) 41 let isneg: *i64 = sys_mmap(32 * 8) 42 var n: i64 = 0 43 44 // KAT1: 1/6 + 1/3 = 1/2 (exact rational addition) 45 let a: *i64 = rat_new(); rat_set(a, 1, 6) 46 let b: *i64 = rat_new(); rat_set(b, 1, 3) 47 let s1: *i64 = rat_new(); rat_add(s1, a, b) 48 lab[n] = "Exact rational addition" as i64; expr[n] = "1/6 + 1/3" as i64; on[n] = s1[0]; od[n] = s1[1]; en[n] = 1; ed[n] = 2; ps[n] = ((s1[0] == 1) & (s1[1] == 2)); isneg[n] = 0; n = n + 1 49 50 // KAT2: 2/4 normalizes to 1/2 (gcd canonicalization) 51 let c: *i64 = rat_new(); rat_set(c, 2, 4) 52 lab[n] = "Fraction normalization (gcd)" as i64; expr[n] = "2/4" as i64; on[n] = c[0]; od[n] = c[1]; en[n] = 1; ed[n] = 2; ps[n] = ((c[0] == 1) & (c[1] == 2)); isneg[n] = 0; n = n + 1 53 54 // KAT3: (1/3) * (3/1) = 1/1 55 let d1: *i64 = rat_new(); rat_set(d1, 1, 3) 56 let d2: *i64 = rat_new(); rat_set(d2, 3, 1) 57 let m1: *i64 = rat_new(); rat_mul(m1, d1, d2) 58 lab[n] = "Exact rational multiply" as i64; expr[n] = "(1/3) * (3/1)" as i64; on[n] = m1[0]; od[n] = m1[1]; en[n] = 1; ed[n] = 1; ps[n] = ((m1[0] == 1) & (m1[1] == 1)); isneg[n] = 0; n = n + 1 59 60 // KAT4: -2/6 normalizes to -1/3 (sign + gcd) 61 let e1: *i64 = rat_new(); rat_set(e1, 0 - 2, 6) 62 lab[n] = "Signed normalization" as i64; expr[n] = "-2/6" as i64; on[n] = e1[0]; od[n] = e1[1]; en[n] = 0 - 1; ed[n] = 3; ps[n] = ((e1[0] == (0 - 1)) & (e1[1] == 3)); isneg[n] = 0; n = n + 1 63 64 // KAT5: 1/2 + 1/3 + ... use add twice: (1/2 + 1/3) = 5/6 65 let f1: *i64 = rat_new(); rat_set(f1, 1, 2) 66 let f2: *i64 = rat_new(); rat_set(f2, 1, 3) 67 let fs: *i64 = rat_new(); rat_add(fs, f1, f2) 68 lab[n] = "Common-denominator addition" as i64; expr[n] = "1/2 + 1/3" as i64; on[n] = fs[0]; od[n] = fs[1]; en[n] = 5; ed[n] = 6; ps[n] = ((fs[0] == 5) & (fs[1] == 6)); isneg[n] = 0; n = n + 1 69 70 // KAT6: gcd(48,36) = 12 71 let g: i64 = rat_gcd(48, 36) 72 lab[n] = "Euclid gcd" as i64; expr[n] = "gcd(48, 36)" as i64; on[n] = g; od[n] = 1; en[n] = 12; ed[n] = 1; ps[n] = (g == 12); isneg[n] = 0; n = n + 1 73 74 // ---- POLYNOMIAL section (nx_poly EXECUTED; each row surfaces one representative coefficient/value) ---- 75 // KAT-P1: (x+1)(x-1) = x^2 - 1 -> coefficients [-1, 0, 1]; row shows the constant coeff 76 let pa: *i64 = sys_mmap(32) as *i64; pa[0] = 1; pa[1] = 1 77 let pb: *i64 = sys_mmap(32) as *i64; pb[0] = 0 - 1; pb[1] = 1 78 let pm: *i64 = sys_mmap(64) as *i64 79 let pmdeg: i64 = nx_poly_mul(pa, 1, pb, 1, pm) 80 let p1ok: i64 = ((pmdeg == 2) as i64) & ((pm[0] == (0 - 1)) as i64) & ((pm[1] == 0) as i64) & ((pm[2] == 1) as i64) 81 lab[n] = "Polynomial multiply" as i64; expr[n] = "(x+1)(x-1) -> constant coeff" as i64; on[n] = pm[0]; od[n] = 1; en[n] = 0 - 1; ed[n] = 1; ps[n] = p1ok; isneg[n] = 0; n = n + 1 82 83 // KAT-P2: d/dx(3x^2 + 2x + 1) = 6x + 2 -> [2, 6]; row shows the x coeff (6) 84 let pc: *i64 = sys_mmap(32) as *i64; pc[0] = 1; pc[1] = 2; pc[2] = 3 85 let pd: *i64 = sys_mmap(32) as *i64 86 let pddeg: i64 = nx_poly_derivative(pc, 2, pd) 87 let p2ok: i64 = ((pddeg == 1) as i64) & ((pd[0] == 2) as i64) & ((pd[1] == 6) as i64) 88 lab[n] = "Symbolic derivative" as i64; expr[n] = "d/dx(3x^2+2x+1) -> x coeff" as i64; on[n] = pd[1]; od[n] = 1; en[n] = 6; ed[n] = 1; ps[n] = p2ok; isneg[n] = 0; n = n + 1 89 90 // KAT-P3: Horner eval 3x^2+2x+1 at x=2 -> 17 91 let pev: i64 = nx_poly_eval(pc, 2, 2) 92 lab[n] = "Polynomial evaluation (Horner)" as i64; expr[n] = "3x^2+2x+1 at x=2" as i64; on[n] = pev; od[n] = 1; en[n] = 17; ed[n] = 1; ps[n] = ((pev == 17) as i64); isneg[n] = 0; n = n + 1 93 94 // KAT-P4: (x^2+2x+3) + (4x+5) = x^2 + 6x + 8 -> row shows the x coeff (6) 95 let pe: *i64 = sys_mmap(32) as *i64; pe[0] = 3; pe[1] = 2; pe[2] = 1 96 let pf: *i64 = sys_mmap(32) as *i64; pf[0] = 5; pf[1] = 4 97 let pg: *i64 = sys_mmap(32) as *i64 98 let pgdeg: i64 = nx_poly_add(pe, 2, pf, 1, pg) 99 let p4ok: i64 = ((pgdeg == 2) as i64) & ((pg[0] == 8) as i64) & ((pg[1] == 6) as i64) & ((pg[2] == 1) as i64) 100 lab[n] = "Polynomial addition" as i64; expr[n] = "(x^2+2x+3)+(4x+5) -> x coeff" as i64; on[n] = pg[1]; od[n] = 1; en[n] = 6; ed[n] = 1; ps[n] = p4ok; isneg[n] = 0; n = n + 1 101 102 // KAT-P5: Gauss sum 1+2+...+100 = 5050 (Faulhaber power-sum p=1) 103 let gs: i64 = nx_poly_power_sum(100, 1) 104 lab[n] = "Power sum (Gauss)" as i64; expr[n] = "1+2+...+100" as i64; on[n] = gs; od[n] = 1; en[n] = K_MAGIC_5050; ed[n] = 1; ps[n] = ((gs == K_MAGIC_5050) as i64); isneg[n] = 0; n = n + 1 105 106 // ---- MATRIX section (nx_matrix EXECUTED; classic textbook results, Wolfram-exact) ---- 107 // KAT-M1: [[1,2],[3,4]] x [[5,6],[7,8]] = [[19,22],[43,50]] -- all four entries checked, row shows (0,0)=19 108 let ma: *Matrix = nx_matrix_alloc(2, 2) 109 nx_matrix_set(ma, 0, 0, 1); nx_matrix_set(ma, 0, 1, 2); nx_matrix_set(ma, 1, 0, 3); nx_matrix_set(ma, 1, 1, 4) 110 let mb: *Matrix = nx_matrix_alloc(2, 2) 111 nx_matrix_set(mb, 0, 0, 5); nx_matrix_set(mb, 0, 1, 6); nx_matrix_set(mb, 1, 0, 7); nx_matrix_set(mb, 1, 1, 8) 112 let mc: *Matrix = nx_matrix_alloc(2, 2) 113 nx_matrix_multiply(ma, mb, mc) 114 let m1ok: i64 = ((nx_matrix_get(mc, 0, 0) == 19) as i64) & ((nx_matrix_get(mc, 0, 1) == 22) as i64) & ((nx_matrix_get(mc, 1, 0) == 43) as i64) & ((nx_matrix_get(mc, 1, 1) == 50) as i64) 115 lab[n] = "Matrix multiply 2x2" as i64; expr[n] = "[[1,2],[3,4]] x [[5,6],[7,8]] -> (0,0)" as i64; on[n] = nx_matrix_get(mc, 0, 0); od[n] = 1; en[n] = 19; ed[n] = 1; ps[n] = m1ok; isneg[n] = 0; n = n + 1 116 117 // KAT-M2: det [[1,2],[3,4]] = -2 118 let mdet: i64 = nx_matrix_det_2x2(ma) 119 lab[n] = "Determinant 2x2" as i64; expr[n] = "det [[1,2],[3,4]]" as i64; on[n] = mdet; od[n] = 1; en[n] = 0 - 2; ed[n] = 1; ps[n] = ((mdet == (0 - 2)) as i64); isneg[n] = 0; n = n + 1 120 121 // KAT-M3: det [[1,2,3],[4,5,6],[7,8,10]] = -3 (the classic near-singular example) 122 let m3: *Matrix = nx_matrix_alloc(3, 3) 123 nx_matrix_set(m3, 0, 0, 1); nx_matrix_set(m3, 0, 1, 2); nx_matrix_set(m3, 0, 2, 3) 124 nx_matrix_set(m3, 1, 0, 4); nx_matrix_set(m3, 1, 1, 5); nx_matrix_set(m3, 1, 2, 6) 125 nx_matrix_set(m3, 2, 0, 7); nx_matrix_set(m3, 2, 1, 8); nx_matrix_set(m3, 2, 2, 10) 126 let mdet3: i64 = nx_matrix_det_3x3(m3) 127 lab[n] = "Determinant 3x3" as i64; expr[n] = "det [[1,2,3],[4,5,6],[7,8,10]]" as i64; on[n] = mdet3; od[n] = 1; en[n] = 0 - 3; ed[n] = 1; ps[n] = ((mdet3 == (0 - 3)) as i64); isneg[n] = 0; n = n + 1 128 129 // KAT-M4: transpose([[1,2],[3,4]]) -> (0,1) = 3 130 let mt: *Matrix = nx_matrix_transpose(ma) 131 let mtv: i64 = nx_matrix_get(mt, 0, 1) 132 lab[n] = "Matrix transpose" as i64; expr[n] = "transpose [[1,2],[3,4]] -> (0,1)" as i64; on[n] = mtv; od[n] = 1; en[n] = 3; ed[n] = 1; ps[n] = ((mtv == 3) as i64); isneg[n] = 0; n = n + 1 133 134 // ---- BIGINT section (nx_bigint_lib EXECUTED; multi-precision results composed into i64 for display) ---- 135 // KAT-B1: 4294967295 + 1 = 4294967296 -- the carry must propagate across the 32-bit limb boundary 136 let ba: *i64 = sys_mmap(64) as *i64 137 let bb: *i64 = sys_mmap(64) as *i64 138 let br: *i64 = sys_mmap(64) as *i64 139 bi_zero(ba, 4); bi_zero(bb, 4) 140 ba[0] = 0xFFFFFFFF 141 bb[0] = 1 142 bi_add(br, ba, bb, 4) 143 let bsum: i64 = (br[0] & 0xFFFFFFFF) + ((br[1] & 0xFFFFFFFF) * K_MAGIC_4294967296) 144 lab[n] = "Bignum carry across limb" as i64; expr[n] = "4294967295 + 1" as i64; on[n] = bsum; od[n] = 1; en[n] = K_MAGIC_4294967296; ed[n] = 1; ps[n] = ((bsum == K_MAGIC_4294967296) as i64); isneg[n] = 0; n = n + 1 145 146 // KAT-B2: 65536 * 65536 = 4294967296 (product exceeds one limb) 147 let bm: *i64 = sys_mmap(64) as *i64 148 bi_zero(ba, 4); bi_zero(bb, 4) 149 ba[0] = K_MAGIC_65536 150 bb[0] = K_MAGIC_65536 151 bi_mul(bm, ba, 1, bb, 1) 152 let bprod: i64 = (bm[0] & 0xFFFFFFFF) + ((bm[1] & 0xFFFFFFFF) * K_MAGIC_4294967296) 153 lab[n] = "Bignum multiply" as i64; expr[n] = "65536 x 65536" as i64; on[n] = bprod; od[n] = 1; en[n] = K_MAGIC_4294967296; ed[n] = 1; ps[n] = ((bprod == K_MAGIC_4294967296) as i64); isneg[n] = 0; n = n + 1 154 155 // KAT-B3: big-endian bytes DE AD BE EF -> 3735928559 156 let bbuf: *u8 = sys_mmap(8) 157 bbuf[0] = 0xDE; bbuf[1] = 0xAD; bbuf[2] = 0xBE; bbuf[3] = 0xEF 158 bi_from_bytes_be(br, 4, bbuf, 4) 159 let bval: i64 = br[0] & 0xFFFFFFFF 160 lab[n] = "Bignum byte decode" as i64; expr[n] = "bytes DE AD BE EF" as i64; on[n] = bval; od[n] = 1; en[n] = K_MAGIC_3735928559; ed[n] = 1; ps[n] = ((bval == K_MAGIC_3735928559) as i64); isneg[n] = 0; n = n + 1 161 162 // NEG-CONTROL: 1/6 + 1/3 checked against a WRONG expected (1/3). Must FAIL, proving the checker discriminates. 163 lab[n] = "NEG-CONTROL: 1/6+1/3 vs wrong 1/3" as i64; expr[n] = "1/6 + 1/3 =? 1/3" as i64; on[n] = s1[0]; od[n] = s1[1]; en[n] = 1; ed[n] = 3; ps[n] = ((s1[0] == 1) & (s1[1] == 3)); isneg[n] = 1; n = n + 1 164 165 // NEG-CONTROL-P: (x+1)(x-1) constant coeff checked against WRONG +1. Must FAIL. 166 lab[n] = "NEG-CONTROL: poly const vs wrong +1" as i64; expr[n] = "(x+1)(x-1) const =? 1" as i64; on[n] = pm[0]; od[n] = 1; en[n] = 1; ed[n] = 1; ps[n] = ((pm[0] == 1) as i64); isneg[n] = 1; n = n + 1 167 168 // NEG-CONTROL-M: det [[1,2],[3,4]] checked against WRONG +2. Must FAIL. 169 lab[n] = "NEG-CONTROL: det vs wrong +2" as i64; expr[n] = "det [[1,2],[3,4]] =? 2" as i64; on[n] = mdet; od[n] = 1; en[n] = 2; ed[n] = 1; ps[n] = ((mdet == 2) as i64); isneg[n] = 1; n = n + 1 170 171 // NEG-CONTROL-B: the carry sum checked against WRONG 4294967295 (as if the carry were dropped). Must FAIL. 172 lab[n] = "NEG-CONTROL: carry vs wrong" as i64; expr[n] = "4294967295+1 =? 4294967295" as i64; on[n] = bsum; od[n] = 1; en[n] = K_MAGIC_4294967295; ed[n] = 1; ps[n] = ((bsum == K_MAGIC_4294967295) as i64); isneg[n] = 1; n = n + 1 173 174 // tally 175 var realpass: i64 = 0; var realtot: i64 = 0; var negfail: i64 = 0; var negtot: i64 = 0 176 var i: i64 = 0 177 while i < n { 178 if isneg[i] == 1 { negtot = negtot + 1; if ps[i] == 0 { negfail = negfail + 1 } } else { realtot = realtot + 1; if ps[i] == 1 { realpass = realpass + 1 } } 179 i = i + 1 180 } 181 182 if html == 1 { 183 w(1, "<" as *u8); wc(1, 33); w(1, "DOCTYPE html>\n<html lang='en'><head><meta charset='utf-8'><meta name='viewport' content='width=device-width, initial-scale=1'>\n" as *u8) 184 w(1, "<title>Nishi Compare -- Run-and-Compare Bench (rational arithmetic)</title>\n<style>\n" as *u8) 185 w(1, ":root{--bg:rgb(255,255,255);--fg:rgb(22,22,34);--ac:rgb(42,77,143);--y:rgb(26,127,55);--n:rgb(179,38,30);--line:rgb(227,227,234);--soft:rgb(246,247,251)}\n" as *u8) 186 w(1, "*{box-sizing:border-box}body{background:var(--bg);font-family:-apple-system,Segoe UI,Roboto,sans-serif;max-width:960px;margin:5vh auto;padding:0 20px;color:var(--fg);line-height:1.6}\n" as *u8) 187 w(1, "h1{font-size:2rem;margin:0 0 4px}.sub{color:rgb(102,102,102);font-size:1.05rem;margin:0 0 4px}.crumb{font-size:.85rem;margin-bottom:18px}a{color:var(--ac)}\n" as *u8) 188 w(1, ".meth{background:var(--soft);border:1px solid var(--line);border-radius:12px;padding:14px 18px;margin:18px 0;font-size:.9rem;color:rgb(51,51,51)}\n" as *u8) 189 w(1, ".wrap{overflow-x:auto;border:1px solid var(--line);border-radius:12px}table{border-collapse:collapse;width:100%;min-width:680px;font-size:.94rem}\n" as *u8) 190 w(1, "th,td{padding:9px 12px;text-align:left;border-bottom:1px solid var(--line)}thead th{background:var(--soft);font-weight:600}code{font-family:ui-monospace,Menlo,Consolas,monospace}\n" as *u8) 191 w(1, ".p{color:var(--y);font-weight:700}.f{color:var(--n);font-weight:700}.neg{color:rgb(102,102,102);font-style:italic}\n" as *u8) 192 w(1, ".foot{margin-top:26px;color:rgb(136,136,136);font-size:.78rem;border-top:1px solid var(--line);padding-top:14px}\n" as *u8) 193 w(1, "@media(prefers-color-scheme:dark){:root{--bg:rgb(15,15,20);--fg:rgb(230,230,238);--line:rgb(38,38,47);--soft:rgb(23,23,31)}}\n" as *u8) 194 w(1, "</style></head><body>\n" as *u8) 195 w(1, "<p class='crumb'><a href='/'>Nishi Family</a> &rsaquo; <a href='/compare'>Compare</a> &rsaquo; <a href='/compare/computational'>Computational</a> &rsaquo; Run-and-Compare Bench</p>\n" as *u8) 196 w(1, "<h1>Run-and-Compare Bench</h1>\n<p class='sub'>Exact rationals + polynomials + matrices + bignums &mdash; Nishi is RUN on each input; its output is compared to the mathematically-correct value.</p>\n" as *u8) 197 w(1, "<div class='meth'>This is the deepest form of &ldquo;mechanically test and bench&rdquo;: not symbol-presence, but actual EXECUTION. The real <code>nx_rational</code>, <code>nx_poly</code>, <code>nx_matrix</code> and <code>nx_bigint_lib</code> organs are run on each input and the computed value is compared exactly to the correct answer (identical to what Wolfram or any exact CAS returns). The NEG-CONTROL rows are checked against deliberately-wrong answers &mdash; they MUST fail, proving the comparison discriminates.</div>\n" as *u8) 198 w(1, "<div class='wrap'><table><thead><tr><th>Capability</th><th>Input</th><th>Nishi computed</th><th>Correct (Wolfram-class)</th><th>Verdict</th></tr></thead><tbody>\n" as *u8) 199 i = 0 200 while i < n { 201 w(1, "<tr><td>" as *u8); w(1, lab[i] as *u8); w(1, "</td><td><code>" as *u8); w(1, expr[i] as *u8); w(1, "</code></td><td><code>" as *u8); wrat(1, on[i], od[i]); w(1, "</code></td><td><code>" as *u8); wrat(1, en[i], ed[i]); w(1, "</code></td>" as *u8) 202 if isneg[i] == 1 { if ps[i] == 0 { w(1, "<td class='neg'>correctly rejected</td>" as *u8) } else { w(1, "<td class='f'>LEAK</td>" as *u8) } } else { if ps[i] == 1 { w(1, "<td class='p'>PASS</td>" as *u8) } else { w(1, "<td class='f'>FAIL</td>" as *u8) } } 203 w(1, "</tr>\n" as *u8) 204 i = i + 1 205 } 206 w(1, "</tbody></table></div>\n" as *u8) 207 w(1, "<p class='sub' style='font-size:.95rem;margin-top:16px'>Real KATs passed " as *u8); wn(1, realpass); w(1, "/" as *u8); wn(1, realtot); w(1, " &middot; neg-control correctly rejected " as *u8); wn(1, negfail); w(1, "/" as *u8); wn(1, negtot); w(1, "</p>\n" as *u8) 208 w(1, "<p class='foot'>Generated by nx_swcompare_bench &mdash; imports the real nx_rational organ, executes it, compares to the exact correct value. This upgrades the computational comparison from capability-presence to executed-and-correct. Zero JS, zero trackers.</p>\n" as *u8) 209 w(1, "</body></html>\n" as *u8) 210 sys_exit(0); return 0 211 } 212 213 w(1, "=== NX-SWCOMPARE-BENCH -- run-and-compare (exact rational arithmetic, nx_rational executed) ===\n" as *u8) 214 i = 0 215 while i < n { 216 w(1, " " as *u8) 217 if isneg[i] == 1 { if ps[i] == 0 { w(1, "[neg-ok ]" as *u8) } else { w(1, "[LEAK ]" as *u8) } } else { if ps[i] == 1 { w(1, "[PASS ]" as *u8) } else { w(1, "[FAIL ]" as *u8) } } 218 w(1, " " as *u8); w(1, expr[i] as *u8); w(1, " -> Nishi " as *u8); wrat(1, on[i], od[i]); w(1, " vs correct " as *u8); wrat(1, en[i], ed[i]); w(1, "\n" as *u8) 219 i = i + 1 220 } 221 w(1, " TALLY: real-KATs " as *u8); wn(1, realpass); w(1, "/" as *u8); wn(1, realtot); w(1, " neg-control-rejected " as *u8); wn(1, negfail); w(1, "/" as *u8); wn(1, negtot); w(1, "\n" as *u8) 222 let liar_real: i64 = (realpass == realtot) as i64 223 let liar_neg: i64 = (negfail == negtot) as i64 224 let liar_some: i64 = (realtot >= 5) as i64 225 w(1, " LIAR-KILL: all-real-pass=" as *u8); wn(1, liar_real); w(1, " neg-control-discriminates=" as *u8); wn(1, liar_neg); w(1, " enough-kats=" as *u8); wn(1, liar_some); w(1, "\n" as *u8) 226 let ok: i64 = liar_real & liar_neg & liar_some 227 w(1, "NX-SWCOMPARE-BENCH verdict=" as *u8) 228 if ok == 1 { w(1, "MEASURED-HONEST (liar-killed) -- nx_rational EXECUTED, every result matches the exact correct value; neg-control rejected\n" as *u8); sys_exit(0); return 0 } 229 w(1, "RED (a real KAT gave a wrong value, or the neg-control leaked)\n" as *u8); sys_exit(1); return 1 230}