#!/usr/bin/env python3 """Exact verification of the arithmetic in finding #2617 (job #3849). Claim under audit (reading 6 clause (c), the last two prose lines): "the L-1 gaps inside a run ... have MEAN at least 3p when L-1 is even and at least 3p - (3p - s)/(L-1) when L-1 is odd, s = 2p-2 for p = 1 (mod 6) ... the bound is tight at fold 31, where the four four-runs 60+126+60 have mean 82 against 82.67 for L = 4, p = 29." The defect: the four-runs 60+126+60 occur when the tile T29 is folded by 31, so the fold prime is p = 31 (the qualifying set is {60, 126, 186, 246}, small class s = 2p-2 = 60), not p = 29; and 82.67 is not a rival tight bound but the value of the REFUTED old expression 3p - p/(L-1) at p = 31. Exact-rational checks, all with sympy Rational: M1 s = 2p-2 = 60 exactly and the large class 4p+2 = 126 exactly, s+large = 6p M2 the run word 60+126+60 has mean exactly 82 = 248/3? no: 246/3 = 82 M3 3p - (3p-s)/(L-1) with p=31, s=60, L=4 equals the observed mean exactly M4 3p - p/(L-1) = 82.67.. = 248/3 > 82, so the old expression FAILS here M5 the two algebraic forms (3p(L-2)+s)/(L-1) and 3p-(3p-s)/(L-1) are identical as rational functions of p,s,L (sympy simplify -> 0) M6 at p = 29 (the wrongly named prime) the four-runs' words would be 60+?: check that p=29 gives small class 2p-2 = 56 and large class 4p+2 = 118, and that 60+126+60 is NOT a word for p = 29 (60 mod 29 = 2 is the +2 class, 126 mod 29 = 10 is inert) -- so the printed word itself identifies p = 31. M7 the qualifying set at p=31 is {60,126,186,246} (embedded output l.730) and at p=29 it is {56,118,174}: the fold-31 word 60+126+60 cannot be a fold-29 word. """ import sys from sympy import Rational, simplify, symbols, Integer p, s, L = symbols("p s L", positive=True) fails = [] def chk(name, cond, detail=""): status = "PASS" if cond else "FAIL" print(f" [{status}] {name} {detail}") if not cond: fails.append(name) def main(): P = Integer(31) S = 2 * P - 2 Lq = Integer(4) large = 4 * P + 2 print("== M1 exact classes at p=31 ==") chk("s = 2p-2 = 60", S == 60, f"s={S}") chk("large = 4p+2 = 126", large == 126, f"large={large}") chk("s + large = 6p", S + large == 6 * P, f"{S}+{large}={S+large}=6*{P}") print("== M2 the run word 60+126+60 ==") word = [Integer(60), Integer(126), Integer(60)] total = sum(word) mean = Rational(total, len(word)) chk("sum = 246", total == 246, f"sum={total}") chk("mean = 82", mean == 82, f"mean={mean}") print("== M3 corrected bound is exactly the observed mean ==") corrected = 3 * P - Rational(3 * P - S, Lq - 1) chk("3p-(3p-s)/(L-1) = 93-33/3 = 82", corrected == 82, f"={corrected}") chk("corrected == observed mean", corrected == mean) print("== M4 the refuted old expression ==") old = 3 * P - Rational(P, Lq - 1) chk("3p-p/(L-1) = 248/3", old == Rational(248, 3), f"={old}={float(old):.6f}") chk("old > observed mean (so it FAILS)", old > mean, f"{old} > {mean}") chk("old rounds to 82.67", f"{float(old):.2f}" == "82.67", f"{float(old):.4f}") print("== M5 the two algebraic forms are identical ==") a = simplify((3 * p * (L - 2) + s) / (L - 1) - (3 * p - (3 * p - s) / (L - 1))) chk("(3p(L-2)+s)/(L-1) == 3p-(3p-s)/(L-1)", a == 0, f"difference={a}") print("== M6/M7 p=29 does not carry the word 60+126+60 ==") P29 = Integer(29) s29, l29 = 2 * P29 + 2, 4 * P29 - 2 # p = 29 = 5 (mod 6): small = 2p+2, large = 4p-2 chk("p=29: s=60, large=114", (s29, l29) == (60, 114), f"{s29},{l29}") # gap classes mod p=29: 60 -> 2 (+2 class), 126 -> 10 (inert) chk("60 mod 29 = 2 is the +2 class", 60 % 29 == 2, f"{60%29}") chk("126 mod 29 = 10 is inert", 126 % 29 == 10, f"{126%29}") chk("so 60+126 is impossible for p=29", (60 % 29) != 0 and (126 % 29) not in (0, 2, 29 - 2)) # the twin-pair coincidence: 29 and 31 share the small class 2(p+1) = 60, # but only p = 31 has 126 as its large class 4p+2, which is why the WORD # 60+126+60 identifies p = 31. chk("small class is shared by the twin pair 29/31 (both 60)", (2 * P29 + 2) == (2 * (P29 + 2) - 2) == 60) chk("large class 4p+2 = 126 only at p=31", 4 * (P29 + 2) + 2 == 126) # qualifying sets def qualset(pp): six = 6 * pp aP = 2 while aP % 6 != 0: aP += pp return sorted([six, aP, six - aP]) chk("qualifying set p=31 = {60,126,186}", qualset(31) == [60, 126, 186], str(qualset(31))) chk("qualifying set p=29 = {60,114,174}", qualset(29) == [60, 114, 174], str(qualset(29))) chk("126 is NOT in the p=29 qualifying set", 126 not in qualset(29)) print() if fails: print("FAILED:", fails) sys.exit(1) print("ALL EXACT CHECKS PASS") if __name__ == "__main__": main()