code wiki / (root) / nx_icecream_bench_gate.nx

nx_icecream_bench_gate.nx source

↩ module page · 255 lines · 11333 B

1// nx_icecream_bench_gate.nx -- gate for the frozen-dessert RULER. 2// 3// T0 Ben & Jerry's Vanilla density off the verified label = 0.906 g/mL 4// T1 composition off the panel: 146 permil fat, 399 permil total solids 5// T2 total milk solids 259 permil (MSNF inferred from protein) 6// T3 unaerated mix density 1.090 g/mL (Guelph specific-volume model) 7// T4 derived overrun 203 permil = 20.3% 8// T5 AIR FRACTION IS NOT OVERRUN: 168 vs 203 permil, and they never agree 9// T6 the two legal floors: weight 539, solids 480 at this TS => WEIGHT binds 10// T7 the floors cross at 356 permil total solids -- computed, not typed 11// T8 above the crossover the shipped one-floor law is right BY LUCK: err 0 12// T9 ★below it the shipped law OVER-PERMITS by 200 permil of air 13// T10 the reference passes all FOUR clauses of 21 CFR 135.110 14// T11 ★ISOLATING NEGATIVE CONTROL: a mix that passes milkfat, milk solids 15// AND the 4.5 lb/gal weight floor and is still NOT ice cream -- failure 16// bitmask is exactly 8, so the fourth clause is load-bearing, not dead 17// T12 assumption-free: the reference is 117 permil denser than Haagen-Dazs 18// T13 meltdown: a mono/di + PS80 system holds shape 2.2x longer than yolk 19// T14 provenance flags all report honestly (derived / inferred / unmeasured) 20// T15 refusals: impossible composition and impossible overrun both REFUSE 21// 22// license_tier: ORIGINAL expect_exit: 0 23import "nx_syscalls.nx" 24import "nx_icecream_bench.nx" 25import "nx_icecream.nx" 26 27func gw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 28func gn(v: i64) -> i64 { 29 let b: *u8=sys_mmap(28); var m: i64=v; if m<0 {sys_write(1,"-" as *u8,1); m=0-m} 30 let t: *u8=sys_mmap(28); var k: i64=0; if m==0 {t[0]=48 as u8;k=1} while m>0 {t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} 31 var i: i64=0; while i<k {b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 32} 33func gck(pass: i64, name: *u8, fails: *i64) -> i64 { 34 if pass==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8); fails[0]=fails[0]+1 } 35 gw(name); gw("\n" as *u8); return 0 36} 37 38// ---- the low-solids mix used by T9: 10% fat, 32% total solids ---- 39const GT_LOW_FAT_PERMIL: i64 = 100 40const GT_LOW_TS_PERMIL: i64 = 320 41 42// ---- T11's isolating control, built to fail ONLY the food-solids floor ---- 43func gt_solids_only_failure() -> *BenchProduct { 44 let p: *BenchProduct = bench_product_new() 45 p.serving_g = 95 46 p.fat_g = 10 47 p.carb_g = 2 48 p.protein_g = 4 49 p.emulsifier = BENCH_EMUL_MONO_DI 50 return p 51} 52 53func t0() -> i64 { 54 let p: *BenchProduct = bench_ref_benjerry() 55 if bench_density_q3(p) != 906 { return 0 } 56 return 1 57} 58 59func t1() -> i64 { 60 let p: *BenchProduct = bench_ref_benjerry() 61 if bench_fat_permil(p) != 146 { return 0 } 62 if bench_total_solids_permil(p) != 399 { return 0 } 63 if bench_water_permil(p) != 601 { return 0 } 64 return 1 65} 66 67func t2() -> i64 { 68 let p: *BenchProduct = bench_ref_benjerry() 69 if bench_msnf_permil(p) != 113 { return 0 } 70 if bench_total_milk_solids_permil(p) != 259 { return 0 } 71 return 1 72} 73 74func t3() -> i64 { 75 let p: *BenchProduct = bench_ref_benjerry() 76 if bench_mix_density_of(p) != 1090 { return 0 } 77 return 1 78} 79 80func t4() -> i64 { 81 let p: *BenchProduct = bench_ref_benjerry() 82 if bench_overrun_of(p) != 203 { return 0 } 83 return 1 84} 85 86// The conflation guard. 16.8% air is 20.3% overrun; treating them as the 87// same number is a 25% error that circulates widely in consumer press. 88func t5() -> i64 { 89 let p: *BenchProduct = bench_ref_benjerry() 90 let orun: i64 = bench_overrun_of(p) 91 let air: i64 = bench_air_permil_from_overrun(orun) 92 if air != 168 { return 0 } 93 if air >= orun { return 0 } 94 if bench_air_equals_overrun(orun) != 0 { return 0 } 95 if bench_air_equals_overrun(0) != 1 { return 0 } 96 return 1 97} 98 99func t6() -> i64 { 100 if bench_min_density_weight_q3() != 539 { return 0 } 101 if bench_min_density_solids_q3(399) != 480 { return 0 } 102 if bench_binding_floor(399) != BENCH_FLOOR_WEIGHT { return 0 } 103 if bench_min_density_q3(399) != 539 { return 0 } 104 return 1 105} 106 107func t7() -> i64 { 108 if bench_floor_crossover_permil() != 356 { return 0 } 109 if bench_binding_floor(357) != BENCH_FLOOR_WEIGHT { return 0 } 110 if bench_binding_floor(350) != BENCH_FLOOR_SOLIDS { return 0 } 111 return 1 112} 113 114func t8() -> i64 { 115 let p: *BenchProduct = bench_ref_benjerry() 116 let mix: i64 = bench_mix_density_of(p) 117 let ts: i64 = bench_total_solids_permil(p) 118 if bench_max_overrun_permil(mix, ts) != 1019 { return 0 } 119 if bench_shipped_law_error_permil(mix, ts) != 0 { return 0 } 120 if bench_shipped_law_over_permits(mix, ts) != 0 { return 0 } 121 return 1 122} 123 124// The finding, measured. At 32% total solids the food-solids floor binds 125// first, and the shipped weight-only law licenses 20 percentage points of 126// air that the standard of identity does not allow. 127func t9() -> i64 { 128 let mix: i64 = bench_mix_density_q3(GT_LOW_FAT_PERMIL, GT_LOW_TS_PERMIL) 129 if mix != 1079 { return 0 } 130 if bench_binding_floor(GT_LOW_TS_PERMIL) != BENCH_FLOOR_SOLIDS { return 0 } 131 if bench_max_overrun_permil(mix, GT_LOW_TS_PERMIL) != 799 { return 0 } 132 if bench_max_overrun_weight_only_permil(mix) != 999 { return 0 } 133 if bench_shipped_law_error_permil(mix, GT_LOW_TS_PERMIL) != 200 { return 0 } 134 if bench_shipped_law_over_permits(mix, GT_LOW_TS_PERMIL) != 1 { return 0 } 135 return 1 136} 137 138func t10() -> i64 { 139 let p: *BenchProduct = bench_ref_benjerry() 140 let d: i64 = bench_density_q3(p) 141 if bench_weight_lb_per_gal_q2(d) != 755 { return 0 } 142 if bench_solids_lb_per_gal_q2(d, 399) != 301 { return 0 } 143 if bench_fda_failures(p) != 0 { return 0 } 144 if bench_is_ice_cream(p) != 1 { return 0 } 145 return 1 146} 147 148// ★The control that makes the fourth clause non-vacuous. This product is 149// compliant on milkfat, on total milk solids, and on the 4.5 lb/gal weight 150// floor -- every check nx_icecream actually performs -- and it is still not 151// ice cream. Bitmask exactly 8 means clause 8 alone caught it. 152func t11() -> i64 { 153 let p: *BenchProduct = gt_solids_only_failure() 154 let d: i64 = bench_density_q3(p) 155 let ts: i64 = bench_total_solids_permil(p) 156 if bench_fat_permil(p) < BENCH_FDA_MIN_MILKFAT_PERMIL { return 0 } 157 if bench_total_milk_solids_permil(p) < BENCH_FDA_MIN_MILK_SOL_PERMIL { return 0 } 158 if bench_weight_lb_per_gal_q2(d) < BENCH_FDA_MIN_LB_PER_GAL_Q2 { return 0 } 159 if bench_solids_lb_per_gal_q2(d, ts) >= BENCH_FDA_MIN_FOOD_SOLIDS_Q2 { return 0 } 160 if bench_fda_failures(p) != 8 { return 0 } 161 if bench_is_ice_cream(p) != 0 { return 0 } 162 return 1 163} 164 165func t12() -> i64 { 166 let p: *BenchProduct = bench_ref_benjerry() 167 if bench_hd_density_q3() != 811 { return 0 } 168 if bench_denser_than_hd_permil(p) != 117 { return 0 } 169 if bench_hd_composition_is_known() != 0 { return 0 } 170 return 1 171} 172 173func t13() -> i64 { 174 let adv: i64 = bench_meltdown_advantage_q3(BENCH_EMUL_EGG_YOLK, BENCH_EMUL_MONO_DI_PS80) 175 if adv != 2200 { return 0 } 176 if bench_first_drip_min(BENCH_EMUL_EGG_YOLK) != 12 { return 0 } 177 if bench_first_drip_min(BENCH_EMUL_MONO_DI_PS80) != 18 { return 0 } 178 // a system compared with itself must show no advantage 179 if bench_meltdown_advantage_q3(BENCH_EMUL_EGG_YOLK, BENCH_EMUL_EGG_YOLK) != 1000 { return 0 } 180 return 1 181} 182 183func t14() -> i64 { 184 if bench_overrun_is_derived() != 1 { return 0 } 185 if bench_meltdown_claim_is_inferred() != 1 { return 0 } 186 if bench_reference_was_physically_measured() != 0 { return 0 } 187 if bench_reference_uses_lbg() != 0 { return 0 } 188 if bench_reference_uses_added_emulsifier() != 0 { return 0 } 189 let p: *BenchProduct = bench_ref_benjerry() 190 if bench_net_weight_is_derived(p) != 1 { return 0 } 191 return 1 192} 193 194func t15() -> i64 { 195 // total solids cannot be at or below fat 196 if bench_mix_density_q3(400, 400) != BENCH_INVALID { return 0 } 197 if bench_mix_density_q3(400, 1000) != BENCH_INVALID { return 0 } 198 // aerating cannot make the product DENSER than its own mix 199 if bench_overrun_permil(900, 1000) != BENCH_INVALID { return 0 } 200 if bench_min_density_solids_q3(0) != BENCH_INVALID { return 0 } 201 if bench_destab_permil(99) != BENCH_INVALID { return 0 } 202 return 1 203} 204 205// **TWO INDEPENDENT IMPLEMENTATIONS OF THE SAME LAW MUST AGREE. 206// nx_icecream now carries the corrected ceiling as ic_max_legal_overrun_pct2 207// (percent) and this organ carries it as bench_max_overrun_permil (permil). 208// They were written separately, in different units, with different integer 209// paths. Agreement is therefore evidence, not restatement -- and the old 210// one-floor law must still differ, exactly where predicted, or the fix 211// changed nothing. 212func t16() -> i64 { 213 // the shared floors 214 if ic_min_density_weight_q3() != bench_min_density_weight_q3() { return 0 } 215 if ic_min_density_solids_q3(399) != bench_min_density_solids_q3(399) { return 0 } 216 // above the crossover: both laws agree with each other AND with the old one 217 if ic_max_legal_overrun_pct2(1090, 399) != 101 { return 0 } 218 if bench_max_overrun_permil(1090, 399) / 10 != 101 { return 0 } 219 // below it: both corrected laws agree, and the old law is 20 points looser 220 if ic_max_legal_overrun_pct2(1079, 320) != 79 { return 0 } 221 if bench_max_overrun_permil(1079, 320) / 10 != 79 { return 0 } 222 if ic_max_legal_overrun_pct(1079) != 99 { return 0 } 223 if bench_max_overrun_weight_only_permil(1079) / 10 != 99 { return 0 } 224 return 1 225} 226 227func main() -> i64 { 228 let fails: *i64 = sys_mmap(16) as *i64 229 fails[0] = 0 230 gw("=== nx_icecream_bench -- the ruler, vs Ben & Jerry's Vanilla ===\n" as *u8) 231 232 gck(t0(), "T0 reference density 0.906 g/mL off the verified label" as *u8, fails) 233 gck(t1(), "T1 composition 146 permil fat / 399 permil total solids" as *u8, fails) 234 gck(t2(), "T2 total milk solids 259 permil (MSNF inferred)" as *u8, fails) 235 gck(t3(), "T3 unaerated mix density 1.090 g/mL" as *u8, fails) 236 gck(t4(), "T4 derived overrun 203 permil" as *u8, fails) 237 gck(t5(), "T5 air fraction 168 != overrun 203, never equal" as *u8, fails) 238 gck(t6(), "T6 floors: weight 539, solids 480 -> WEIGHT binds" as *u8, fails) 239 gck(t7(), "T7 floors cross at 356 permil total solids" as *u8, fails) 240 gck(t8(), "T8 above crossover shipped law right by luck (err 0)" as *u8, fails) 241 gck(t9(), "T9 below it shipped law OVER-PERMITS by 200 permil air" as *u8, fails) 242 gck(t10(), "T10 reference passes all FOUR 21 CFR 135.110 clauses" as *u8, fails) 243 gck(t11(), "T11 isolating control: passes 3 clauses, fails only #4" as *u8, fails) 244 gck(t12(), "T12 assumption-free: 117 permil denser than Haagen-Dazs" as *u8, fails) 245 gck(t13(), "T13 mono/di+PS80 holds shape 2.2x longer than egg yolk" as *u8, fails) 246 gck(t14(), "T14 provenance flags report derived/inferred/unmeasured" as *u8, fails) 247 gck(t15(), "T15 impossible composition and overrun both REFUSE" as *u8, fails) 248 249 gck(t16(), "T16 nx_icecream and the ruler agree on the corrected law" as *u8, fails) 250 251 gw("pass=" as *u8); gn(17 - fails[0]); gw("/17\n" as *u8) 252 if fails[0] == 0 { gw("verdict=GREEN\n" as *u8) } else { gw("verdict=RED\n" as *u8) } 253 sys_exit(fails[0]) 254 return 0 255}