code wiki / _hdl_build / nx_analyst.nx

nx_analyst.nx source

↩ module page · 181 lines · 8346 B

1// nx_analyst.nx -- the NISHI ANALYST organ (the market-researcher RENAMED + given its real job). 2// Operator: "determine why it is so expensive to get an AC when its simpler than a computer and get 3// REAL answers, not regurgitated common wisdoms filled in the media... trace the supply chain costs, 4// the labor cycle, benchmark, to see where all the shenanigans like corruption/inflation are." 5// RACI: the RESEARCHER gathers + corroborates evidence (V_RESEARCH); the ANALYST EXPLAINS it 6// (V_ANALYZE) -- decomposes a measured price into a TRACED COST LEDGER and quantifies what the 7// trace CANNOT explain. The verdict mechanism that kills common-wisdom answers: 8// - a cost claim with no corroborated source is a NARRATIVE node: it is NEVER admitted as a cost, 9// it becomes a fetch-task for the Researcher (media answers are narrative nodes -> 0 admitted); 10// - the ledger must CLOSE arithmetically (children sum to parent within tolerance) -- a story 11// whose numbers don't add up is a defect, not an explanation; 12// - the UNEXPLAINED RESIDUAL (price minus traced costs) is computed and NAMED, never smoothed 13// over: that residual is exactly where margin-stacking / rent-seeking / "shenanigans" live; 14// - verdicts are DETERMINISTIC: same ledger, same verdict, every run (an LLM one-shot varies). 15// Honest boundary (same as nx_researcher.nx): FETCH+EXTRACT of source prose into numbers is the 16// one delegated step; everything that makes the analysis RIGOROUS the team owns and runs. 17// LAWS: struct-free, integer-only (cents / permil / ppm / q10), no &&/||. license_tier: ORIGINAL 18 19import "nx_syscalls.nx" 20const AN_MAGIC_1000000: i64 = 1000000 21const AN_MAGIC_1024: i64 = 1024 22 23// ---- node kinds: how a ledger row earned its number ---- 24const AN_NARRATIVE: i64 = 0 // claim with NO corroborated source ("everyone knows installs are pricey") 25const AN_MEASURED: i64 = 1 // value from >=2 independent sources (Researcher rd_corroborated rule) 26const AN_DERIVED: i64 = 2 // computed from measured children (sum/share), provenance inherited 27 28// ---- verdicts ---- 29const AN_EXPLAINED: i64 = 1 // coverage high, residual small -> the price IS its traced costs 30const AN_SHENANIGAN: i64 = 2 // ledger closes, coverage high, residual LARGE -> unexplained money, NAMED 31const AN_UNDERTRACED: i64 = 3 // coverage too low to call -> honest "don't know yet" + fetch tasks owed 32const AN_BROKEN: i64 = 4 // arithmetic does not close, or narrative admitted -> not an explanation 33 34// ledger = parallel arrays over n nodes; node 0 is the ROOT (the sticker price). 35// parent[i] = index of i's parent (-1 for root); value[i] = cents; kind[i] = AN_* above. 36 37// sum of the direct children of `node`. 38func an_children_sum(parent: *i64, value: *i64, n: i64, node: i64) -> i64 { 39 var s: i64 = 0 40 var i: i64 = 0 41 while i < n { 42 if parent[i] == node { s = s + value[i] } 43 i = i + 1 44 } 45 return s 46} 47 48// 1 iff `node` has no children (a leaf -- where provenance must live). 49func an_is_leaf(parent: *i64, n: i64, node: i64) -> i64 { 50 var i: i64 = 0 51 while i < n { 52 if parent[i] == node { return 0 } 53 i = i + 1 54 } 55 return 1 56} 57 58// closure error of one interior node in ppm: |value - children_sum| * 1e6 / value. 59func an_closure_ppm(node_value: i64, csum: i64) -> i64 { 60 if node_value <= 0 { return AN_MAGIC_1000000 } 61 var d: i64 = node_value - csum 62 if d < 0 { d = 0 - d } 63 return (d * AN_MAGIC_1000000) / node_value 64} 65 66// count interior nodes whose children do NOT sum to them within tol_ppm. 0 = the ledger CLOSES. 67func an_closure_fails(parent: *i64, value: *i64, n: i64, tol_ppm: i64) -> i64 { 68 var fails: i64 = 0 69 var i: i64 = 0 70 while i < n { 71 if an_is_leaf(parent, n, i) == 0 { 72 let cs: i64 = an_children_sum(parent, value, n, i) 73 if an_closure_ppm(value[i], cs) > tol_ppm { fails = fails + 1 } 74 } 75 i = i + 1 76 } 77 return fails 78} 79 80// count NARRATIVE nodes carrying a nonzero cost -- each one is a DEFECT (common wisdom admitted 81// as data). The gate requires this to be ZERO before any verdict other than AN_BROKEN. 82func an_narrative_admitted(kind: *i64, value: *i64, n: i64) -> i64 { 83 var c: i64 = 0 84 var i: i64 = 0 85 while i < n { 86 if kind[i] == AN_NARRATIVE { if value[i] != 0 { c = c + 1 } } 87 i = i + 1 88 } 89 return c 90} 91 92// every NARRATIVE node owes the Researcher one fetch-task (claim -> go corroborate it). 93// The Analyst never argues with a narrative -- it converts it into work. 94func an_fetch_tasks_owed(kind: *i64, n: i64) -> i64 { 95 var c: i64 = 0 96 var i: i64 = 0 97 while i < n { 98 if kind[i] == AN_NARRATIVE { c = c + 1 } 99 i = i + 1 100 } 101 return c 102} 103 104// sum of MEASURED leaf costs = the money the trace actually explains with provenance. 105func an_traced_cents(parent: *i64, value: *i64, kind: *i64, n: i64) -> i64 { 106 var s: i64 = 0 107 var i: i64 = 1 108 while i < n { 109 if kind[i] == AN_MEASURED { 110 if an_is_leaf(parent, n, i) == 1 { s = s + value[i] } 111 } 112 i = i + 1 113 } 114 return s 115} 116 117// coverage: traced cents as permil of the root price. 118func an_traced_permil(price_cents: i64, traced_cents: i64) -> i64 { 119 if price_cents <= 0 { return 0 } 120 return (traced_cents * 1000) / price_cents 121} 122 123// the UNEXPLAINED RESIDUAL: price minus traced. Negative = double-counted costs (also a defect). 124func an_residual_cents(price_cents: i64, traced_cents: i64) -> i64 { 125 return price_cents - traced_cents 126} 127 128func an_residual_permil(price_cents: i64, traced_cents: i64) -> i64 { 129 if price_cents <= 0 { return 1000 } 130 return (an_residual_cents(price_cents, traced_cents) * 1000) / price_cents 131} 132 133// ---- the deterministic verdict ---- 134// min_traced_permil: coverage below this -> UNDERTRACED (no verdict, fetch tasks instead). 135// max_residual_permil: residual above this, with good coverage -> SHENANIGAN (named, not smoothed). 136func an_verdict(closure_fails: i64, narrative_admitted: i64, traced_permil: i64, 137 residual_permil: i64, min_traced_permil: i64, max_residual_permil: i64) -> i64 { 138 if closure_fails != 0 { return AN_BROKEN } 139 if narrative_admitted != 0 { return AN_BROKEN } 140 if residual_permil < 0 { return AN_BROKEN } 141 if traced_permil < min_traced_permil { return AN_UNDERTRACED } 142 if residual_permil > max_residual_permil { return AN_SHENANIGAN } 143 return AN_EXPLAINED 144} 145 146// full-ledger verdict (the one callers use). 147func an_ledger_verdict(parent: *i64, value: *i64, kind: *i64, n: i64, 148 tol_ppm: i64, min_traced_permil: i64, max_residual_permil: i64) -> i64 { 149 let cf: i64 = an_closure_fails(parent, value, n, tol_ppm) 150 let na: i64 = an_narrative_admitted(kind, value, n) 151 let tc: i64 = an_traced_cents(parent, value, kind, n) 152 let tp: i64 = an_traced_permil(value[0], tc) 153 let rp: i64 = an_residual_permil(value[0], tc) 154 return an_verdict(cf, na, tp, rp, min_traced_permil, max_residual_permil) 155} 156 157// ---- the complexity lens (the operator's AC-vs-computer paradox, as a NUMBER) ---- 158// price per unit of complexity (cents per complexity unit, e.g. distinct-part count). 159func an_price_per_complexity(price_cents: i64, complexity_units: i64) -> i64 { 160 if complexity_units <= 0 { return 0 } 161 return price_cents / complexity_units 162} 163 164// paradox ratio in q10 fixed point: how many TIMES more good A costs per unit of complexity 165// than good B. q10=1024 means parity; 10x = 10240. "AC simpler than a computer yet pricier" 166// stops being a vibe and becomes a measured, comparable quantity. 167func an_paradox_q10(price_a: i64, cx_a: i64, price_b: i64, cx_b: i64) -> i64 { 168 let pa: i64 = an_price_per_complexity(price_a, cx_a) 169 let pb: i64 = an_price_per_complexity(price_b, cx_b) 170 if pb <= 0 { return 0 } 171 return (pa * AN_MAGIC_1024) / pb 172} 173 174// ---- REPRODUCIBILITY (the core exceed, same as the Researcher's): same ledger -> same verdict ---- 175func an_is_reproducible(parent: *i64, value: *i64, kind: *i64, n: i64, 176 tol_ppm: i64, min_tp: i64, max_rp: i64) -> i64 { 177 let v1: i64 = an_ledger_verdict(parent, value, kind, n, tol_ppm, min_tp, max_rp) 178 let v2: i64 = an_ledger_verdict(parent, value, kind, n, tol_ppm, min_tp, max_rp) 179 if v1 == v2 { return 1 } 180 return 0 181}