#!/usr/bin/env python3 """Job #1007 — the attaining set is closed under n -> -n-2 (mod x#). Reason: the T_x slot condition forbids n = 0 and n = -2 (mod p) for every p <= x. The map sigma(n) = -n - 2 sends 0 -> -2 and -2 -> 0, so it permutes the slot set (and is an involution), hence maps a maximal gap of length G starting at s to a maximal gap of the same length starting at sigma(s + G) = -s - G - 2 (mod x#), with the ancestry pattern reversed. Consequence: every multiplicity on the ladder is even, and a position and its partner must have the same end/interior split. This is checked on the fully enumerated levels. """ import json import sys sys.path.insert(0, 'job1007') import splits as P # noqa: E402 def main(): d = json.load(open('job1007/splits.json', encoding='utf-8')) bad = 0 lines = [] def say(s): print(s) lines.append(s) def emit(name, text): with open('job1007/' + name, 'w', encoding='utf-8', newline='\n') as fh: fh.write(text) for x in sorted(int(k) for k in d): L = d[str(x)] Pm = P.primorial(x) starts = L['starts'] rows = {r['pos']: r for r in L['rows']} paired, mism = [], [] for s in starts: # sigma maps the window [s, s+G] to a gap [sigma(s+G), sigma(s)] of the same # length whose START is sigma(s+G) = -s-G-2, not sigma(s) t = (Pm - 2 - L['G2'] - s) % Pm if t not in rows: mism.append(('missing partner', s, t)) continue pair_share_ok = abs(rows[s]['share'] - rows[t]['share']) < 1e-12 rev_ok = rows[t]['gaps'] == rows[s]['gaps'][::-1] paired.append((s, t, pair_share_ok, rev_ok)) # sigma is an involution, so every attaining start has its partner in the set: the # check is that each position's partner is PRESENT (and distinct) with the mirrored # ancestry and an identical split -- paired may then be rewritten as 2-cycles ok = (not mism) and all(p and r and s != t for s, t, p, r in paired) \ and len(paired) == len(starts) bad += 0 if ok else 1 say('x=%-3d mult=%-3d sigma-orbits=%-3d closed=%s splits equal=%s ancestry reversed=%s cycles=%s' % (x, len(starts), len(paired) // 2, not mism, all(p for _, _, p, _ in paired), all(r for _, _, _, r in paired), sorted(tuple(sorted((s, t))) for s, t, _, _ in paired))) if mism: say(' MISSING PARTNERS: ' + str(mism[:4])) say('') say('involution gate: ' + ('HOLDS on all enumerated levels' if not bad else 'FAILS at %d level(s)' % bad)) emit('involution.out', '\n'.join(lines) + '\n') return 0 if not bad else 1 if __name__ == '__main__': sys.exit(main())