#!/usr/bin/env python3 """What the T37 record site becomes in T41: all 41 fold images, computed locally. Route 3, item 3 (locate the T37 528-gap's image under the fold and check whether it is the certified 546) needs no tile pass. The served T37 histogram carries the record's POSITION: A1 = 528 at A1pos, A2 = 540 at A1pos - 12. Folding by 41 places the T37 period at 41 copies, copy k at [kW, (k+1)W); the image of the record site is therefore n_k = A1pos + k*W, and everything about the T41 gap structure around n_k is decidable on a few thousand integers, because T_x slot : n with gcd(n(n+2), x#) = 1, i.e. n != 0, -2 (mod p) for p <= x T41 slots : the same test with p <= 41 fold bookkeeping: copy k keeps the T37 slot at s iff (s + kW) != 0, -2 (mod 41) Two independent routes to the same answer, so the fold bookkeeping is checked against a direct 41# sieve rather than trusted: (a) sieve 41# locally, (b) test the T37 slots' survival mod 41 and merge across the killed ones. No tile pass, no randomness, no clock in stdout. Input: t37-hist.json (served). Usage: python3 t41-images.py [t37-hist.json] [half-window] """ import json import sys HIST = sys.argv[1] if len(sys.argv) > 1 else "t37-hist.json" HALF = int(sys.argv[2]) if len(sys.argv) > 2 else 1500 P37 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] P41 = P37 + [41] def slot(n, primes): """n is a twin slot of T_x iff no p <= x divides n or n+2.""" for p in primes: if n % p == 0 or (n + 2) % p == 0: return False return True def gaps_in(lo, hi, primes): """The twin slots of T_x in [lo, hi], and the gaps between them.""" ns = [n for n in range(lo, hi + 1) if slot(n, primes)] return ns, [b - a for a, b in zip(ns, ns[1:])] def main(): d = json.load(open(HIST)) W = d["W"] A1, A1pos = d["A1"], d["A1pos"] A2, A2pos = d["A2"], d["A2pos"] print("input : %s" % HIST) print("T37 : A1 = %d at %d ; A2 = %d at %d (gap before = %d)" % (A1, A1pos, A2, A2pos, A1pos - A2pos)) print("W = 37# = %d ; 41# = %d ; window +/-%d around each image" % (W, 41 * W, HALF)) # gate on the local method: the T37 word around the site must BE the record lo, hi = A1pos - HALF, A1pos + A1 + HALF ns37, g37 = gaps_in(lo, hi, P37) assert A1pos in ns37 and A1pos + A1 in ns37, "record site not found locally" i = ns37.index(A1pos) print("gate : local T37 slots in [A1pos-%d, A1pos+%d] = %d, gap at the record " "= %d, previous gap = %d" % (HALF, A1 + HALF, len(ns37), ns37[i + 1] - ns37[i], ns37[i] - ns37[i - 1])) print("gate : local max T37 gap in that window = %d" % max(g37)) # the T37 word around the record, for the branch of the bookkeeping that needs it gT = [ns37[j + 1] - ns37[j] for j in range(len(ns37) - 1)] rec = i # index of the record gap in gT print("\n k endpoints alive image prev next max pair at image" " local max gap local max A2") rows = [] loc_a2 = {} for k in range(41): shift = k * W n1, n2 = A1pos + shift, A1pos + A1 + shift alive = (slot(n1, P41), slot(n2, P41)) # (a) direct local sieve of 41# n41, g41 = gaps_in(n1 - HALF, n2 + HALF, P41) img = None for a, b in zip(n41, n41[1:]): if a <= n1 and b >= n2: img = b - a pa = n41[n41.index(a) - 1] if n41.index(a) > 0 else None break ii = n41.index([x for x in n41 if x <= n1][-1]) if any(x <= n1 for x in n41) else None prev_gap = n41[ii] - n41[ii - 1] if ii and ii > 0 else None nxt = None for a, b in zip(n41, n41[1:]): if a <= n1 and b >= n2: nxt = b break next_gap = None if nxt is not None: j = n41.index(nxt) if j + 1 < len(n41): next_gap = n41[j + 1] - nxt pair = max([img + g for g in (prev_gap, next_gap) if g is not None], default=None) # (b) independent fold bookkeeping from the T37 word merged = None j0 = rec while j0 > 0 and not slot(ns37[j0] + shift, P41): j0 -= 1 j1 = rec + 1 while j1 < len(ns37) - 1 and not slot(ns37[j1] + shift, P41): j1 += 1 merged = ns37[j1] - ns37[j0] la2 = max((a + b for a, b in zip(g41, g41[1:])), default=0) loc_a2[k] = la2 rows.append((k, alive, img, prev_gap, next_gap, pair, max(g41), merged)) print("%3d %-20s %5s %4s %4s %8s %13d %12d" % (k, "%s,%s" % alive, img, prev_gap, next_gap, pair, max(g41), la2)) ok = [r for r in rows if r[2] == r[7]] print("\nagreement: direct 41# sieve == fold bookkeeping at %d of 41 copies" % len(ok)) bad = [(r[0], r[2], r[7]) for r in rows if r[2] != r[7]] if bad: print("MISMATCH:", bad) from collections import Counter c = Counter(r[2] for r in rows) print("image values: %s" % dict(sorted(c.items()))) print("546 at any image? %s" % (546 in c)) print("alive patterns: %s" % dict(Counter("%s,%s" % r[1] for r in rows))) mx = max(rows, key=lambda r: r[5] or 0) print("largest max-pair-at-image: %d at copy k = %d (prev %s, next %s)" % (mx[5], mx[0], mx[3], mx[4])) print("local max gap over all copies: %d (copy k = %d)" % (max(r[6] for r in rows), max(rows, key=lambda r: r[6])[0])) print("local max A2 over all copies: %d (copy k = %d)" % (max(loc_a2.values()), max(loc_a2, key=loc_a2.get))) print("local max A2 at the record image: max over copies of the pair-sum = %d" % max(r[5] for r in rows if r[5] is not None)) if __name__ == "__main__": main()