#!/usr/bin/env python3 """Job #1049 (triage, route #15) -- the sigma-action on the attaining starts, and its fixed points. Route 15 rests on: the attaining set of A_1(x) = G2(x#) is closed under sigma(r) = -r - 2 (mod x#), so the positions pair up and the number of independent positions is "nmax/2 orbits". That halving needs the action on the attaining STARTS to be free. This script (1) derives the action on starts in closed form (it is the reflection s -> -(g+2)-s), (2) states the fixed-point criterion, c := (g+2)/2 must itself be a T_x slot, (3) checks both exhaustively against every attaining start for x = 11..23, (4) gates the ladder values A_1(x) and the record multiplicities it must reproduce. Output: one JSON object per level on stdout (the artifact). Progress goes to stderr. Usage: python orbits.py [x ...] """ import json import sys from math import gcd import numpy as np PRIMES = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43] # corpus / record values used as GATES, not as the result: A_1(x) from the ladder table # (job1007/splits.py LADDER) and the record's multiplicity nmax (route 15 table, return #424). GATE_A1 = {11: 42, 13: 66, 17: 108, 19: 150, 23: 204, 29: 258, 31: 348, 37: 528, 41: 546, 43: 618} GATE_NMAX = {11: 4, 13: 12, 17: 20, 19: 20, 23: 4, 29: 2, 31: 4} def primorial(x): r = 1 for p in PRIMES: if p <= x: r *= p return r def slots(x): """Boolean sieve of the T_x slots r in [0, x#): r odd and r, r+2 coprime to x#.""" D = primorial(x) alive = np.ones(D, dtype=bool) for p in (q for q in PRIMES if q <= x): alive[0::p] = False # r = 0 mod p alive[(p - 2) % p::p] = False # r = -2 mod p return alive def analyse(x): D = primorial(x) alive = slots(x) idx = np.flatnonzero(alive).astype(np.int64) # cyclic gaps: consecutive slots, plus the seam from the last back to the first + D d = np.diff(idx) seam = int(idx[0] + D - idx[-1]) g = int(max(int(d.max()), seam)) starts = [int(s) for s in idx[:-1][d == g]] if seam == g: starts.append(int(idx[-1])) if seam > g: starts = [int(idx[-1])] starts = sorted(set(starts)) # the action on starts, predicted tau = {s: (-(s + g) - 2) % D for s in starts} closed = all(t in starts for t in tau.values()) invol = all(tau[tau[s]] == s for s in starts) and len(set(tau.values())) == len(starts) # the reflection centre and its fixed points c = (g + 2) // 2 crit = gcd(c * (c - 2), D) == 1 fixed_cand = sorted({(-c) % D, (-c + D // 2) % D}) fixed_actual = [s for s in starts if tau[s] == s] # why a candidate fails: its own gap, when it is a slot at all cand_gaps = {} for s0 in fixed_cand: j = int(np.searchsorted(idx, s0)) if j < idx.size and int(idx[j]) == s0: nxt = int(idx[j + 1]) if j + 1 < idx.size else int(idx[0]) + D cand_gaps[str(s0)] = nxt - s0 else: cand_gaps[str(s0)] = None # orbit structure seen, orbits = set(), [] for s in starts: if s in seen: continue o = [s, tau[s]] if tau[s] != s else [s] seen.update(o) orbits.append(sorted(o)) res = dict( x=x, D=D, A1=g, expected_A1=GATE_A1.get(x), gate_A1=(GATE_A1.get(x) == g), n_slots=int(idx.size), nmax=len(starts), expected_nmax=GATE_NMAX.get(x), gate_nmax=(GATE_NMAX.get(x) == len(starts)), starts=starts[:12], # truncated listing, the whole set is in nmax/orbits sigma_closed=closed, sigma_involution=invol, c=c, c_is_slot=crit, gcd_c_c2_D=int(gcd(c * (c - 2), D)), fixed_candidates=fixed_cand, fixed_actual=fixed_actual, fixed_candidate_gaps=cand_gaps, fixed_implies_c_slot=(len(fixed_actual) == 0 or crit), criterion_not_conclusive=(crit and not fixed_actual), free_action=(len(fixed_actual) == 0), n_orbits=len(orbits), orbit_sizes=sorted(len(o) for o in orbits), nmax_even=(len(starts) % 2 == 0), ) return res def criterion(x, g): """The test needs only (x, g): a fixed point of the reflection must be the slot -c, c = (g+2)/2.""" D = primorial(x) c = (g + 2) // 2 return dict(x=x, A1=g, c=c, factors=[] if c == 0 else None, gcd=int(gcd(c * (c - 2), D)), D=D, fixed_point_possible=(gcd(c * (c - 2), D) == 1)) def ladder(): rows = [] for x in sorted(GATE_A1): if x <= 23: continue r = criterion(x, GATE_A1[x]) r.pop("factors", None) rows.append(r) print(json.dumps(rows, indent=1)) def main(): if len(sys.argv) > 1 and sys.argv[1] == "--ladder": return ladder() xs = [int(a) for a in sys.argv[1:]] or [11, 13, 17, 19, 23] out = [] for x in xs: sys.stderr.write("x=%d D=%d ...\n" % (x, primorial(x))) sys.stderr.flush() r = analyse(x) sys.stderr.write(" A1=%d gate=%s nmax=%d gate=%s orbits=%s fixed=%s c_slot=%s\n" % (r["A1"], r["gate_A1"], r["nmax"], r["gate_nmax"], r["orbit_sizes"], r["fixed_actual"], r["c_is_slot"])) out.append(r) print(json.dumps(out, indent=1)) if __name__ == "__main__": main()