code wiki / _hdl_build / nx_curviness_gate.nx

nx_curviness_gate.nx source

↩ module page · 201 lines · 10497 B

1// nx_curviness_gate.nx -- GATE for aesthetictwin rung AT2 (outline curviness), the measure the 2// published evidence prefers to the waist-to-hip ratio. 3// 4// THE DONE-RULE THIS GATE ANSWERS WAS WRITTEN INTO aesthetictwin.plan BEFORE ANY CODE, and it asks 5// for exactly three things: that the metric ORDERS two silhouettes of equal waist-to-hip ratio and 6// different curviness, that it is INVARIANT UNDER UNIFORM SCALE, and that a straight-sided silhouette 7// reads zero. T4, T5 and T6 are those three. They are not paraphrased here from the implementation -- 8// the implementation was corrected to meet them, because a first draft returned a per-row density that 9// RISES when a body is merely smaller, and the pre-declared invariance requirement is what caught it. 10// 11// THE LOAD-BEARING TOOTH IS T4 AND T3 IS WHAT MAKES IT LOAD-BEARING. The gentle and sharp bodies are 12// built with the SAME height, the SAME waist and the SAME hip -- so an identical waist-to-hip ratio, 13// which T3 proves by measuring it with this organ's own narrowest and widest primitives. They differ 14// only in WHERE the taper happens: the gentle body sweeps from hip to waist over its whole height, the 15// sharp body pinches in over the middle half and runs straight above and below. A measure that is a 16// ratio in disguise CANNOT separate them, because every input a ratio reads is identical. 17// 18// EVERY FIXTURE IS ASSEMBLED AT RUNTIME AND IN MEMORY, so this gate can never share a fixture with a 19// production beat, and the widths are painted as an EXACT left-aligned run so the measured run length 20// IS the width with no centring round-off. That is not cosmetic: the signal here is a total second 21// difference of order 8 slope-units, and a plus-or-minus-one quantisation per row would swamp it. 22import "nx_syscalls.nx" 23import "nx_gate_verdict.nx" 24import "nx_gatekit_lib.nx" 25import "nx_anatomy_measure.nx" 26 27const CG_ASCII0: i64 = 48 28const CG_MINUS: i64 = 45 29const CG_NL: i64 = 10 30const CG_INK: i64 = 255 31const CG_CANVAS_W: i64 = 420 32const CG_CANVAS_H: i64 = 120 33const CG_BODY_H: i64 = 100 34const CG_WAIST: i64 = 100 35const CG_HIP: i64 = 200 36const CG_SPAN_GENTLE: i64 = 50 37const CG_SPAN_SHARP: i64 = 25 38const CG_BIG_W: i64 = 520 39const CG_BIG_H: i64 = 220 40const CG_BIG_BODY_H: i64 = 200 41const CG_BIG_WAIST: i64 = 200 42const CG_BIG_HIP: i64 = 400 43const CG_BIG_SPAN: i64 = 100 44const CG_PAINT_X: i64 = 10 45const CG_SHIFT_X: i64 = 27 46const CG_RECT_W: i64 = 200 47const CG_RECT_H: i64 = 80 48const CG_RECT_BODY_H: i64 = 60 49const CG_RECT_WIDTH: i64 = 150 50const CG_SHORT_BAND: i64 = 3 51const CG_ORDER_MIN: i64 = 2 52const CG_TOL_DEN: i64 = 10 53 54func cg_pnum(tag: *u8, v: i64) -> i64 { 55 let b: *u8 = sys_mmap(96) 56 let d: *u8 = sys_mmap(64) 57 var n: i64 = 0 58 var x: i64 = v 59 if x < 0 { b[n] = CG_MINUS; n = n + 1; x = 0 - x } 60 var m: i64 = 0 61 if x == 0 { d[m] = CG_ASCII0; m = m + 1 } 62 while x > 0 { 63 let q: i64 = x / 10 64 d[m] = CG_ASCII0 + (x - q * 10) 65 m = m + 1 66 x = q 67 } 68 while m > 0 { m = m - 1; b[n] = d[m]; n = n + 1 } 69 b[n] = CG_NL 70 n = n + 1 71 sys_write(1, tag, gk_len(tag)) 72 sys_write(1, b, n) 73 return 0 74} 75 76// Paint a body whose WIDTH PROFILE reaches waist at the middle row and hip at plus-or-minus span 77// rows, staying at hip beyond that. SPAN is the whole control: span == bh/2 sweeps the taper over the 78// entire body (gentle), a smaller span pinches it into the middle and leaves straight sides (sharp). 79// Waist and hip are UNCHANGED by span, which is precisely why the waist-to-hip ratio cannot tell the 80// two apart. A quadratic is used rather than a straight taper because a straight taper puts all its 81// turning in one corner and would make the two fixtures differ only in where a single corner sits. 82func cg_paint_body(img: *Image, bh: i64, waist: i64, hip: i64, span: i64, px: i64) -> i64 { 83 let m: i64 = bh / 2 84 let k: i64 = hip - waist 85 var i: i64 = 0 86 while i < bh { 87 var t: i64 = i - m 88 if t < 0 { t = 0 - t } 89 var wd: i64 = hip 90 if t < span { wd = waist + (k * t * t) / (span * span) } 91 var x: i64 = 0 92 while x < wd { 93 nx_image_set(img, px + x, i, 0, CG_INK) 94 x = x + 1 95 } 96 i = i + 1 97 } 98 return 0 99} 100 101func main(argc: i64, argv: *i64) -> i64 { 102 let ctr: *i64 = gv_ctr() 103 gv_head("=== NX-CURVINESS-GATE -- AT2 outline curviness, the shape a waist-to-hip ratio cannot see ===" as *u8) 104 105 let gentle: *Image = nx_image_alloc(CG_CANVAS_W, CG_CANVAS_H, 1) 106 let sharp: *Image = nx_image_alloc(CG_CANVAS_W, CG_CANVAS_H, 1) 107 let shift: *Image = nx_image_alloc(CG_CANVAS_W, CG_CANVAS_H, 1) 108 let big: *Image = nx_image_alloc(CG_BIG_W, CG_BIG_H, 1) 109 let rect: *Image = nx_image_alloc(CG_RECT_W, CG_RECT_H, 1) 110 cg_paint_body(gentle, CG_BODY_H, CG_WAIST, CG_HIP, CG_SPAN_GENTLE, CG_PAINT_X) 111 cg_paint_body(sharp, CG_BODY_H, CG_WAIST, CG_HIP, CG_SPAN_SHARP, CG_PAINT_X) 112 cg_paint_body(shift, CG_BODY_H, CG_WAIST, CG_HIP, CG_SPAN_GENTLE, CG_SHIFT_X) 113 cg_paint_body(big, CG_BIG_BODY_H, CG_BIG_WAIST, CG_BIG_HIP, CG_BIG_SPAN, CG_PAINT_X) 114 cg_paint_body(rect, CG_RECT_BODY_H, CG_RECT_WIDTH, CG_RECT_WIDTH, CG_SPAN_GENTLE, CG_PAINT_X) 115 116 // ASSERT THE FIXTURES REACHED THE CONDITION BEFORE ASSERTING ANY OUTCOME. These read the waist and 117 // hip back with the organ's OWN primitives; a fixture that did not paint the shape claimed would 118 // otherwise make every tooth below vacuous while they all still passed. 119 let yo: *i64 = sys_mmap(16) as *i64 120 let wg: i64 = nx_mask_narrowest_y(gentle, 0, CG_BODY_H, 0, CG_CANVAS_W, yo) 121 let hg: i64 = nx_mask_widest_y(gentle, 0, CG_BODY_H, 0, CG_CANVAS_W, yo) 122 let wsh: i64 = nx_mask_narrowest_y(sharp, 0, CG_BODY_H, 0, CG_CANVAS_W, yo) 123 let hsh: i64 = nx_mask_widest_y(sharp, 0, CG_BODY_H, 0, CG_CANVAS_W, yo) 124 cg_pnum("CURVGATE gentle_waist_px=" as *u8, wg) 125 cg_pnum("CURVGATE gentle_hip_px=" as *u8, hg) 126 cg_pnum("CURVGATE sharp_waist_px=" as *u8, wsh) 127 cg_pnum("CURVGATE sharp_hip_px=" as *u8, hsh) 128 var t1: i64 = 0 129 if wg == CG_WAIST { if hg == CG_HIP { t1 = 1 } } 130 gv_check("fixture-reached-the-condition-gentle-body-waist-and-hip-measured-as-painted" as *u8, t1, ctr) 131 var t2: i64 = 0 132 if wsh == CG_WAIST { if hsh == CG_HIP { t2 = 1 } } 133 gv_check("fixture-reached-the-condition-sharp-body-waist-and-hip-measured-as-painted" as *u8, t2, ctr) 134 135 // T3 -- THE ANTI-VACUITY TOOTH. If these ratios were not equal, T4 would be satisfiable by a 136 // measure that is merely a repackaged waist-to-hip ratio and the gate would prove nothing at all. 137 let rg: i64 = wg * AM_CURV_PERMIL / hg 138 let rs: i64 = wsh * AM_CURV_PERMIL / hsh 139 cg_pnum("CURVGATE gentle_whr_permil=" as *u8, rg) 140 cg_pnum("CURVGATE sharp_whr_permil=" as *u8, rs) 141 var t3: i64 = 0 142 if rg == rs { if rg > 0 { t3 = 1 } } 143 gv_check("anti-vacuity-both-bodies-carry-an-identical-waist-to-hip-ratio-so-no-ratio-can-order-them" as *u8, t3, ctr) 144 145 let og: *i64 = sys_mmap(AM_CURV_O_FIELDS * 8 + 16) as *i64 146 let os: *i64 = sys_mmap(AM_CURV_O_FIELDS * 8 + 16) as *i64 147 let ob: *i64 = sys_mmap(AM_CURV_O_FIELDS * 8 + 16) as *i64 148 let osh: *i64 = sys_mmap(AM_CURV_O_FIELDS * 8 + 16) as *i64 149 let orc: *i64 = sys_mmap(AM_CURV_O_FIELDS * 8 + 16) as *i64 150 let oshort: *i64 = sys_mmap(AM_CURV_O_FIELDS * 8 + 16) as *i64 151 let cg: i64 = am_outline_curvature(gentle, 0, CG_CANVAS_H, 0, CG_CANVAS_W, og) 152 let cs: i64 = am_outline_curvature(sharp, 0, CG_CANVAS_H, 0, CG_CANVAS_W, os) 153 let cb: i64 = am_outline_curvature(big, 0, CG_BIG_H, 0, CG_BIG_W, ob) 154 let csh: i64 = am_outline_curvature(shift, 0, CG_CANVAS_H, 0, CG_CANVAS_W, osh) 155 let cr: i64 = am_outline_curvature(rect, 0, CG_RECT_H, 0, CG_RECT_W, orc) 156 let cz: i64 = am_outline_curvature(gentle, 0, CG_SHORT_BAND, 0, CG_CANVAS_W, oshort) 157 cg_pnum("CURVGATE gentle_curviness=" as *u8, cg) 158 cg_pnum("CURVGATE sharp_curviness=" as *u8, cs) 159 cg_pnum("CURVGATE big_curviness_same_shape_twice_the_scale=" as *u8, cb) 160 cg_pnum("CURVGATE gentle_rows=" as *u8, og[AM_CURV_O_ROWS]) 161 cg_pnum("CURVGATE sharp_rows=" as *u8, os[AM_CURV_O_ROWS]) 162 cg_pnum("CURVGATE big_rows=" as *u8, ob[AM_CURV_O_ROWS]) 163 cg_pnum("CURVGATE rect_curviness=" as *u8, cr) 164 cg_pnum("CURVGATE rect_rows=" as *u8, orc[AM_CURV_O_ROWS]) 165 cg_pnum("CURVGATE shortband_return=" as *u8, cz) 166 167 // T4 -- THE RUNG. The sharp body carries more turning than the gentle one, by a margin far outside 168 // any rounding, while every figure a ratio can read is identical between them. 169 var t4: i64 = 0 170 if cs > cg { if cs > cg * CG_ORDER_MIN { t4 = 1 } } 171 gv_check("curviness-orders-two-silhouettes-of-equal-whr-the-sharper-taper-reading-higher" as *u8, t4, ctr) 172 173 // T5 -- THE PRE-DECLARED INVARIANCE. The big body is the gentle body at exactly twice the scale. 174 // Its curviness must not move. This is the tooth that refuses a measure which merely reports size. 175 var dv: i64 = cg - cb 176 if dv < 0 { dv = 0 - dv } 177 var t5: i64 = 0 178 if cg > 0 { if dv * CG_TOL_DEN <= cg { t5 = 1 } } 179 gv_check("invariant-under-uniform-scale-the-same-shape-at-twice-the-size-reads-the-same" as *u8, t5, ctr) 180 181 // T6 -- NEGATIVE CONTROL. rows>0 is IN the condition: a run that examined nothing would otherwise 182 // report zero curviness and pass this tooth having measured an empty set. 183 var t6: i64 = 0 184 if cr == 0 { if orc[AM_CURV_O_ROWS] > 0 { t6 = 1 } } 185 gv_check("neg-control-straight-sided-body-reads-zero-curviness-on-a-non-empty-band" as *u8, t6, ctr) 186 187 // T7 -- NEGATIVE CONTROL. UNMEASURED must not collapse into a measured zero. 188 var t7: i64 = 0 189 if cz == AM_CURV_UNMEASURED { if oshort[AM_CURV_O_SEGS] == AM_CURV_UNMEASURED { t7 = 1 } } 190 gv_check("neg-control-band-too-short-reports-unmeasured-and-not-a-measured-zero" as *u8, t7, ctr) 191 192 var t8: i64 = 0 193 if csh == cg { if cg > 0 { t8 = 1 } } 194 gv_check("translation-invariant-the-same-body-shifted-in-x-reads-identically" as *u8, t8, ctr) 195 196 var t9: i64 = 0 197 if og[AM_CURV_O_ROWS] > 0 { if ob[AM_CURV_O_ROWS] > og[AM_CURV_O_ROWS] { t9 = 1 } } 198 gv_check("row-count-is-reported-and-tracks-the-body-not-the-canvas" as *u8, t9, ctr) 199 200 return gv_verdict("NX-CURVINESS-GATE" as *u8, ctr, "AT2 proven against the done-rule pre-declared in aesthetictwin.plan: ordering at equal waist-to-hip ratio, invariance under uniform scale, and a straight-sided negative control" as *u8) 201}