#!/usr/bin/env python3 """My own checks for the reproduction of PR #34 (issue #35, zcode-zp1 2026-11-28). Runs against the pushed route file and a rerun of the documented command: python3 repro_checks.py THEIR-n12.txt MY-RERUN-n12.txt Confirms, with exact rational arithmetic and code written for this route: 1. the rerun is byte-identical to the pushed n12.txt below the header line; 2. the exact minimum area of the configuration, its distance to the record value (the smallest positive root of 64x^3 + 80x^2 + 28x - 1, Newton to 60 digits) and the ten-decimal cut both files must share; 3. the configuration really is three 4-point orbits of the quarter turn R(x, y) = (1 - y, x) (the family c4search.py searches); 4. the boundary-orbit asymmetry the maintainer flagged (~3.4e-10 between the two boundary orbits' representative coordinates - the tie polish stopping short, per the route's method). """ import sys from fractions import Fraction from itertools import combinations from pathlib import Path def load(path): return [tuple(map(Fraction, line.split())) for line in Path(path).read_text().splitlines() if line.strip() and not line.lstrip().startswith("#")] def doubled_area(a, b, c): return (b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1]) def exact_min(points): areas = {t: abs(doubled_area(*(points[i] for i in t))) for t in combinations(range(len(points)), 3)} smallest = min(areas.values()) return smallest / 2, [t for t, v in areas.items() if v == smallest] def record_root(places=60): """Smallest positive root of 64x^3 + 80x^2 + 28x - 1, Newton in decimal arithmetic.""" import decimal decimal.getcontext().prec = places + 10 x = decimal.Decimal("0.03") for _ in range(200): f = 64 * x**3 + 80 * x**2 + 28 * x - 1 d = 192 * x**2 + 160 * x + 28 x = x - f / d return Fraction(decimal.Decimal(str(x))) def cut(value, places=10): whole = int(value * 10**places) return f"{whole // 10**places}.{whole % 10**places:0{places}d}" def quarter_turn(p): return (1 - p[1], p[0]) def main(): theirs, mine = load(sys.argv[1]), load(sys.argv[2]) same = [f"{x:.17g} {y:.17g}" for x, y in theirs] == [f"{x:.17g} {y:.17g}" for x, y in mine] print(f"1. rerun vs pushed n12.txt, coordinates as printed: {'BYTE-IDENTICAL' if same else 'DIFFER'}") area_t, tight_t = exact_min(theirs) area_m, _ = exact_min(mine) print(f"2. exact minimum (their file) {area_t} = {float(area_t):.17f}") print(f" exact minimum (my rerun) {area_m} equal: {area_t == area_m}") root = record_root() print(f" record value (root of 64x^3+80x^2+28x-1) {float(root):.17f}") gap = root - area_t print(f" below the record by {float(gap):.3e} ({gap} exactly)") print(f" ten-decimal cut {cut(area_t)} (issue expects 0.0325988585, record cut is 0.0325988586)") assert cut(area_t) == "0.0325988585" and gap > 0 worst = Fraction(0) for p in theirs: q = quarter_turn(p) nearest = min(abs(q[0] - r[0]) + abs(q[1] - r[1]) for r in theirs if r != p) worst = max(worst, nearest) assert worst < Fraction(1, 10**12), f"quarter-turn closure only {float(worst)}" print(f"3. closed under R(x,y) = (1-y, x) up to tie-polish wiggle: worst image distance" f" {float(worst):.3e} (the family is exact only in the limit; the polish moved points)") orbits, unseen = [], list(theirs) while unseen: first, orbit = unseen[0], [] for _ in range(4): nearest = min(unseen, key=lambda r: abs(r[0] - first[0]) + abs(r[1] - first[1])) orbit.append(nearest) unseen.remove(nearest) first = quarter_turn(nearest) orbits.append(orbit) assert len(orbits) == 3, f"expected 3 orbits of 4, found {len(orbits)}" boundary_orbits = [o for o in orbits if any(0 in p or 1 in p for p in o)] assert len(boundary_orbits) == 2, "the route has two boundary orbits" values = [] for o in boundary_orbits: free = sorted({c for p in o for c in p if 0 < c < 1}) values.append(free) print(f"4. boundary orbit free coordinates: {[float(v) for v in free]}") gap = min(abs(values[0][i] - values[1][i]) for i in range(min(map(len, values)))) \ if len(set(map(len, values))) == 1 else max(values[0]) - max(values[1]) assert any(abs(float(values[0][i] - values[1][i])) < 1e-9 for i in range(min(map(len, values)))), \ "the two orbits' gap coordinates should differ by ~3.4e-10" diffs = [abs(float(values[0][i] - values[1][i])) for i in range(min(map(len, values)))] print(f" orbit-to-orbit coordinate differences: {[f'{d:.3e}' for d in diffs]}" f" (the route's ~3.4e-10 tie-polish shortfall)") print("ALL CHECKS PASSED") if __name__ == "__main__": main()