#!/usr/bin/env python3 """Job #1049 (triage, route #15) -- the sigma-image of a tile-chunk, as a law on slot indices. Wheel v = 19, b = 43, G2 = 618, K = -(G2+2) mod 43#, P43 = 19# * NCOPY. A position with slot index i is r = s[i] + j*19#. Its sigma-partner is r' = (K - r) mod P43. Since P43 = NCOPY*19#, r' = (NCOPY - 1 - j)*19# + ((19# - 620 - s[i]) mod 19#) (with a borrow; the residue is exact) so the partner's SLOT INDEX is a function of i alone, i' = rank( phi(i) ), phi(i) = (19# - 620 - s[i]) mod 19#, whenever phi(i) happens to be a T_19 slot. If it is not a slot then r' cannot be a slot, and since the partner of an attaining start IS an attaining start (hence a slot), such an i can carry NO attaining start at level 43. That is a necessary condition on the attaining set, available with no enumeration, and it decides the chunk question exactly: chunk [40,47) (i in [327680, 378675)) attains G2 = 618 with 4 maxima (staging record). Where can their partners be? Only where rank(phi(i)) lands. Also reports the reverse (chunk [0,10)) image set, and the pairs where both directions are defined. Output: JSON on stdout; progress on stderr. Usage: python mirror_chunk.py """ import json import sys from chunk_sigma import P19, P43, G2, t19_slots, WPERTILE, CHUNKS SHIFT = G2 + 2 # 620 def main(): S = t19_slots() D19 = len(S) rank = {s: i for i, s in enumerate(S)} K = (-SHIFT) % P43 def phi(i): return (P19 - SHIFT - S[i]) % P19 sys.stderr.write("D_19=%d P43=%d K=%d shift=%d\n" % (D19, P43, K, SHIFT)) rows = [] for lo, hi in CHUNKS: ilo, ihi = lo * WPERTILE, min(hi * WPERTILE, D19) img, undef = [], 0 for i in range(ilo, ihi): t = phi(i) if t in rank: img.append(rank[t]) else: undef += 1 dist = {} for v in img: c = [c for c in CHUNKS if c[0] * WPERTILE <= v < min(c[1] * WPERTILE, D19)] k = str(c[0]) if c else "out" dist[k] = dist.get(k, 0) + 1 rows.append(dict(chunk=[lo, hi], i_lo=ilo, i_hi=ihi, n_i=ihi - ilo, n_partner_defined=len(img), n_i_cannot_attain=undef, img_min=min(img) if img else None, img_max=max(img) if img else None, img_distribution=dist)) sys.stderr.write("chunk [%d,%d): i in [%d,%d) partner-index defined for %d of %d " "(so %d indices cannot carry an attaining start)\n" " partner indices in [%s,%s], by chunk %s\n" % (lo, hi, ilo, ihi, len(img), ihi - ilo, undef, rows[-1]["img_min"], rows[-1]["img_max"], dist)) # composition where both directions are defined inv_ok = sum(1 for lo, hi in CHUNKS for i in range(lo * WPERTILE, min(hi * WPERTILE, D19)) if phi(i) in rank and phi(rank[phi(i)]) in rank and rank[phi(rank[phi(i)])] == i) out = dict(P19=P19, P43=P43, D19=D19, K=K, SHIFT=SHIFT, WPERTILE=WPERTILE, rows=rows, two_sided_compositions=inv_ok) print(json.dumps(out, indent=1)) if __name__ == "__main__": main()