code wiki / (root) / nx_browser_struct_col_lib.nx

nx_browser_struct_col_lib.nx source

↩ module page · 263 lines · 12453 B

1// nx_browser_struct_col_lib.nx -- BR2: THE CSS-ON STRUCTURAL-EXACTNESS COLUMN OF THE BROWSER CENSUS. 2// 3// WHY A LIB AND NOT A BLOCK INSIDE THE CENSUS. nx_browser_census.nx computes every number it prints 4// inside main() and imports nothing testable, so a gate over it can only exec the promoted binary and 5// a mutation harness reads NOT-REACHED across that fork. The judgement therefore lives here, inside 6// the gate's own build closure, where the BR2 bar can actually be bitten. The census keeps ONE 7// delegating declaration (bc_struct_col) so the compare-matrix symbol ruler still measures the organ 8// the row names. 9// 10// WHAT IT ADDS. The census plane row was six tab fields: 11// site class reading_recall_pm ratio_pct chrome_h nishi_h 12// BR2 appends four, STRICTLY ADDITIVELY -- a six-field row still parses and its struct columns read 13// UNMEASURED, never a silent zero: 14// ... struct_matched_pm struct_dy struct_dx struct_bands_oracle 15// 16// THE FOURTH COLUMN IS THE DENOMINATOR, AND IT IS THE REASON THIS LIB EXISTS. 17// MEASURED 2026-08-26 on saved bytes with the incumbent ruler: goog_raw.html vs its Chrome oracle 18// returned "matched=2 (1000 permille)" over TWO oracle bands, and so_aug/x_aug returned 19// "matched=0 (0 permille)" over ZERO oracle bands because those two tall captures are blank. Both 20// readings are arithmetic on an empty or near-empty subject, and both arrive wearing a number that 21// reads as a measurement -- a perfect score and a total failure, neither of them evidence. A struct 22// column fed from that ruler without its denominator would have recorded a 1000 and two 0s in the 23// census as facts. 24// So the floor is DERIVED FROM THE BAR ITSELF, not picked: with N oracle bands, one band's outcome 25// moves the reading by 1000/N permil. The bar is matched >= 900, i.e. 100 permil of headroom below 26// perfection, so a reading is only capable of resolving the bar when 1000/N <= 100, i.e. N >= 10. 27// Below that a single band flips the answer by more than the entire distance the rung is measuring. 28// Rows under the floor are counted as UNDERPOWERED -- named, excluded from the mean and from the bar, 29// never averaged in and never silently dropped. 30// 31// THE BAR IS DATA. matched-permil-min, mean-dy-max and the four bar sites come from 32// knowledge/browser_br2_bar.conf, which quotes the browser.plan BR2 done-rule verbatim. A missing or 33// unreadable conf yields BSC_UNOBSERVABLE, never a default: a bar nobody can read must not be 34// reported as met, and must not be reported as failed either. 35// 36// THE PAIR HAS A NOISE FLOOR. The done-rule's second clause is "the census pair no longer favours 37// CSS-OFF". A mean difference is a WIN only when it exceeds the census-variance band the browser.plan 38// debt row already measured (~60 permil); inside that band the honest answer is TIED, and the 39// CSS_ENABLED flip must not be taken on it. 40// license_tier: ORIGINAL No hw writes (Rule 26). 41import "nx_syscalls.nx" 42import "nx_lineconf_lib.nx" 43 44// permil scale: 1000 = every oracle text band matched. The "no observation yet" seed for a MINIMUM is 45// one above the full scale, so it is derived from the scale rather than picked. 46const BSC_PM_FULL: i64 = 1000 47const BSC_PM_NONE: i64 = 1001 48const BSC_UNMEASURED: i64 = 0 - 1 49 50// THE DENOMINATOR FLOOR, DERIVED: one band moves the reading by BSC_PM_FULL/N permil, and the reading 51// can only resolve the bar when that step is no larger than the bar's headroom below perfection. 52// BSC_BAND_FLOOR is recomputed from the conf bar by bsc_band_floor(); this is the value it takes for 53// the shipping bar of 900 and is kept as a named constant only so the arithmetic has a home. 54const BSC_BAND_FLOOR_AT_900: i64 = 10 55 56// verdicts. 3 is the estate's third state (gv_verdict maps 3 -> SKIP), so a caller forwarding this as 57// an exit code inherits "I could not look" for free. 58const BSC_MET: i64 = 0 59const BSC_UNMET: i64 = 1 60const BSC_UNOBSERVABLE: i64 = 3 61 62// pair verdicts 63const BSC_PAIR_TIED: i64 = 0 64const BSC_PAIR_ON: i64 = 1 65const BSC_PAIR_OFF: i64 = 2 66const BSC_PAIR_UNOBSERVABLE: i64 = 3 67 68// accumulator slots 69const BSC_A_ROWS: i64 = 0 70const BSC_A_MEASURED: i64 = 1 71const BSC_A_SUMPM: i64 = 2 72const BSC_A_SUMDY: i64 = 3 73const BSC_A_SUMDX: i64 = 4 74const BSC_A_BARN: i64 = 5 75const BSC_A_BARMET: i64 = 6 76const BSC_A_WORSTPM: i64 = 7 77const BSC_A_WORSTDY: i64 = 8 78const BSC_A_WORSTDX: i64 = 9 79const BSC_A_UNMEASURED: i64 = 10 80const BSC_A_UNDERPOWERED: i64 = 11 81const BSC_A_SLOTS: i64 = 12 82const BSC_WORD: i64 = 8 83const BSC_A_BYTES: i64 = 96 // BSC_A_SLOTS * BSC_WORD 84 85const BSC_CONF: *u8 = "knowledge/browser_br2_bar.conf\x00" 86const BSC_SITECAP: i64 = 512 87const BSC_COMMA: i64 = 44 88const BSC_ZERO: i64 = 48 89const BSC_NINE: i64 = 57 90 91func bsc_acc() -> *i64 { 92 let a: *i64 = sys_mmap(BSC_A_BYTES) as *i64 93 var i: i64 = 0 94 while i < BSC_A_SLOTS { a[i] = 0; i = i + 1 } 95 a[BSC_A_WORSTPM] = BSC_PM_NONE 96 a[BSC_A_WORSTDY] = BSC_UNMEASURED 97 a[BSC_A_WORSTDX] = BSC_UNMEASURED 98 return a 99} 100 101// parse field p[0..n) as a non-negative int. BSC_UNMEASURED when the field does not START with a 102// digit -- "-" is the plane's UNMEASURED spelling and must never read as 0. A zero permil is a real 103// measurement (we matched nothing) and is NOT the same claim as "nobody measured it". 104func bsc_field_int(p: *u8, n: i64) -> i64 { 105 if n <= 0 { return BSC_UNMEASURED } 106 let c0: i64 = p[0] as i64 107 if c0 < BSC_ZERO { return BSC_UNMEASURED } 108 if c0 > BSC_NINE { return BSC_UNMEASURED } 109 var v: i64 = 0 110 var i: i64 = 0 111 while i < n { 112 let c: i64 = p[i] as i64 113 if c < BSC_ZERO { break } 114 if c > BSC_NINE { break } 115 v = v * 10 + (c - BSC_ZERO) 116 i = i + 1 117 } 118 return v 119} 120 121// THE FLOOR, from the bar: the smallest oracle-band count whose one-band step (BSC_PM_FULL/N) does 122// not exceed the bar's headroom below perfection (BSC_PM_FULL - bar_pm). Returns BSC_UNMEASURED when 123// the bar itself is unreadable, so an unreadable conf can never produce a permissive floor. 124func bsc_band_floor(bar_pm: i64) -> i64 { 125 if bar_pm < 0 { return BSC_UNMEASURED } 126 if bar_pm >= BSC_PM_FULL { return BSC_PM_FULL } 127 let head: i64 = BSC_PM_FULL - bar_pm 128 var n: i64 = BSC_PM_FULL / head 129 if n * head < BSC_PM_FULL { n = n + 1 } 130 return n 131} 132 133// is site[0..slen) one of the comma-separated names in csv? Whole-name match only: a bar list holding 134// "x" must not be satisfied by "xkcd", and one holding "example" must not be satisfied by "example2". 135func bsc_is_bar_site(csv: *u8, site: *u8, slen: i64) -> i64 { 136 if slen <= 0 { return 0 } 137 var i: i64 = 0 138 var start: i64 = 0 139 var hit: i64 = 0 140 var run: i64 = 1 141 while run == 1 { 142 let c: i64 = csv[i] as i64 143 var boundary: i64 = 0 144 if c == 0 { boundary = 1 } 145 if c == BSC_COMMA { boundary = 1 } 146 if boundary == 1 { 147 if i - start == slen { 148 var same: i64 = 1 149 var j: i64 = 0 150 while j < slen { if csv[start + j] != site[j] { same = 0; j = slen } j = j + 1 } 151 if same == 1 { hit = 1; run = 0 } 152 } 153 start = i + 1 154 } 155 if c == 0 { run = 0 } 156 i = i + 1 157 } 158 return hit 159} 160 161// how many names the bar list declares (0 when the list is empty or unreadable) 162func bsc_bar_declared(csv: *u8) -> i64 { 163 if csv[0] == (0 as u8) { return 0 } 164 var n: i64 = 1 165 var i: i64 = 0 166 while csv[i] != (0 as u8) { if csv[i] == (BSC_COMMA as u8) { n = n + 1 } i = i + 1 } 167 return n 168} 169 170// fold ONE census row's struct columns into the accumulator. 171// returns 1 measured, 0 unmeasured, 2 underpowered (denominator below the floor). 172// bands is the ORACLE band count -- the denominator the permil was computed over. 173func bsc_row(acc: *i64, csv: *u8, site: *u8, slen: i64, pm: i64, dy: i64, dx: i64, bands: i64, floor: i64, bar_pm: i64, bar_dy: i64) -> i64 { 174 acc[BSC_A_ROWS] = acc[BSC_A_ROWS] + 1 175 if pm < 0 { acc[BSC_A_UNMEASURED] = acc[BSC_A_UNMEASURED] + 1; return 0 } 176 if bands < 0 { acc[BSC_A_UNMEASURED] = acc[BSC_A_UNMEASURED] + 1; return 0 } 177 if floor < 0 { acc[BSC_A_UNMEASURED] = acc[BSC_A_UNMEASURED] + 1; return 0 } 178 if bands < floor { acc[BSC_A_UNDERPOWERED] = acc[BSC_A_UNDERPOWERED] + 1; return 2 } 179 acc[BSC_A_MEASURED] = acc[BSC_A_MEASURED] + 1 180 acc[BSC_A_SUMPM] = acc[BSC_A_SUMPM] + pm 181 if dy >= 0 { acc[BSC_A_SUMDY] = acc[BSC_A_SUMDY] + dy } 182 if dx >= 0 { acc[BSC_A_SUMDX] = acc[BSC_A_SUMDX] + dx } 183 if bsc_is_bar_site(csv, site, slen) == 1 { 184 acc[BSC_A_BARN] = acc[BSC_A_BARN] + 1 185 if pm < acc[BSC_A_WORSTPM] { acc[BSC_A_WORSTPM] = pm } 186 if dy > acc[BSC_A_WORSTDY] { acc[BSC_A_WORSTDY] = dy } 187 if dx > acc[BSC_A_WORSTDX] { acc[BSC_A_WORSTDX] = dx } 188 var met: i64 = 0 189 if pm >= bar_pm { if dy >= 0 { if dy <= bar_dy { met = 1 } } } 190 if met == 1 { acc[BSC_A_BARMET] = acc[BSC_A_BARMET] + 1 } 191 } 192 return 1 193} 194 195// mean over MEASURED rows only. A mean over zero rows is not zero, it is absent, so this returns 196// BSC_UNMEASURED and cannot be mistaken for a value. 197func bsc_mean(sum: i64, n: i64) -> i64 { 198 if n <= 0 { return BSC_UNMEASURED } 199 return sum / n 200} 201 202// THE BAR, AND ITS ASYMMETRY. Confirming and refuting a bar need different amounts of evidence, and 203// the first cut of this function got that wrong in the direction that HIDES A KNOWN FAILURE. 204// MEASURED 2026-08-26, on the first real seed: two of the four declared bar sites (wikipedia 845/dy 7 205// and hackernews 769/dy 12) were measured and BOTH were below the bar, while example and x had no 206// usable deep-window reading at all. A coverage-first rule returned UNOBSERVABLE -- i.e. "we cannot 207// say" about a ratchet two witnesses had already refuted. 208// PRESENCE NEEDS ONE WITNESS; ABSENCE NEEDS EXHAUSTIVE COVERAGE. One measured bar site below the bar 209// is a sufficient witness that the bar is NOT met, whatever the other sites do. MET is the claim that 210// needs every declared site, because a census carrying one good site must never report the operator 211// ratchet satisfied on a quarter of its evidence. 212func bsc_bar_verdict(acc: *i64, declared: i64, bar_pm: i64, bar_dy: i64) -> i64 { 213 if bar_pm < 0 { return BSC_UNOBSERVABLE } 214 if bar_dy < 0 { return BSC_UNOBSERVABLE } 215 if declared <= 0 { return BSC_UNOBSERVABLE } 216 if acc[BSC_A_BARN] > acc[BSC_A_BARMET] { return BSC_UNMET } 217 if acc[BSC_A_BARN] < declared { return BSC_UNOBSERVABLE } 218 return BSC_MET 219} 220 221// THE PAIR. Which side of the CSS-ON / CSS-OFF pair does the census favour? A difference inside the 222// declared variance band is TIED: the census cannot adjudicate a change smaller than its own noise. 223// Either leg missing is UNOBSERVABLE. 224func bsc_pair_verdict(on_pm: i64, on_n: i64, off_pm: i64, off_n: i64, band: i64) -> i64 { 225 if on_n <= 0 { return BSC_PAIR_UNOBSERVABLE } 226 if off_n <= 0 { return BSC_PAIR_UNOBSERVABLE } 227 if band < 0 { return BSC_PAIR_UNOBSERVABLE } 228 if on_pm < 0 { return BSC_PAIR_UNOBSERVABLE } 229 if off_pm < 0 { return BSC_PAIR_UNOBSERVABLE } 230 var d: i64 = on_pm - off_pm 231 if d < 0 { d = 0 - d } 232 if d <= band { return BSC_PAIR_TIED } 233 if on_pm > off_pm { return BSC_PAIR_ON } 234 return BSC_PAIR_OFF 235} 236 237func bsc_verdict_name(v: i64) -> *u8 { 238 if v == BSC_MET { return "MET" as *u8 } 239 if v == BSC_UNMET { return "UNMET" as *u8 } 240 return "UNOBSERVABLE" as *u8 241} 242func bsc_pair_name(v: i64) -> *u8 { 243 if v == BSC_PAIR_ON { return "FAVOURS-CSS-ON" as *u8 } 244 if v == BSC_PAIR_OFF { return "FAVOURS-CSS-OFF" as *u8 } 245 if v == BSC_PAIR_TIED { return "TIED-WITHIN-VARIANCE" as *u8 } 246 return "UNOBSERVABLE" as *u8 247} 248 249// conf readers. Each returns BSC_UNMEASURED on a missing key so every caller inherits fail-closed. 250func bsc_conf_int(key: *u8) -> i64 { 251 let v: i64 = lcf_int_of(BSC_CONF, key) 252 if v == LCF_MISS { return BSC_UNMEASURED } 253 return v 254} 255func bsc_bar_pm() -> i64 { return bsc_conf_int("matched-permil-min\x00" as *u8) } 256func bsc_bar_dy() -> i64 { return bsc_conf_int("mean-dy-max\x00" as *u8) } 257func bsc_pair_band() -> i64 { return bsc_conf_int("pair-variance-permil\x00" as *u8) } 258// writes the comma-separated bar-site list into out; returns its length, 0 when absent. 259func bsc_bar_sites(out: *u8, cap: i64) -> i64 { 260 let n: i64 = lcf_str_of(BSC_CONF, "bar-sites\x00" as *u8, out, cap) 261 if n < 0 { out[0] = 0 as u8; return 0 } 262 return n 263}