#!/usr/bin/env python3 # Cycle 1028 — (OGF-PM2-QR11) corroboration script. # # Purpose (two finite checks of the algebra in # cycle1028/theory/QR11_PROOF.md; neither is a substitute # for the proof): # Part A: exhaustive exercise of the identity # 5R = 4^k + 2 * 4^z * L_|d| (L_0=2, L_1=3, # L_{j+1} = 3 L_j - L_{j-1}) # and of the ratio classification on ALL ordered # all-even tuples e in {0,2,4,6,8}^k, k = 0..6, at # shift l = 11 (logs in Z/10, base 2). # Part B: the same identity exercised on every # realised all-QR pattern at l = 11 over the B5 # population (wild6/data/b5_data_reached.csv), with # R computed by two independent paths (subset # products mod 11; halved-log subset sums over Z/5), # plus the realised ratio distribution split by # s = k - z, overall and on the exceptional subset # (first_good_p = 0). Cross-checks against the # Cycle 1027 record: 1,363 exceptional primes with # own subgroup exactly QR(11); (11, QR) coverage # 1,174 with max covered ratio 15/16. # # Exact integer / Fraction arithmetic only. No floats # anywhere (math.isqrt for the sieve bound). No # default-parameter fallbacks on data loads: the CSV # path is a literal, a missing file raises. # # Run: python3 cycle1028/qr11/qr11_check.py # Writes: cycle1028/qr11/qr11_results.json import csv import itertools import json from fractions import Fraction from math import gcd, isqrt L = 11 CSV_PATH = "wild6/data/b5_data_reached.csv" OUT_PATH = "cycle1028/qr11/qr11_results.json" # discrete log base 2 mod 11 (2 is the smallest # primitive root mod 11); LOG[r] = e with 2^e = r. LOG = {} _v = 1 for _e in range(10): LOG[_v] = _e _v = (_v * 2) % 11 assert len(LOG) == 10 and LOG[1] == 0 # Lucas-type integers L_j = alpha^j + alpha^-j, # alpha = (3 + sqrt(5))/2, alpha + alpha^-1 = 3. LUCAS = [2, 3] for _ in range(2, 40): LUCAS.append(3 * LUCAS[-1] - LUCAS[-2]) def lucas(j): return LUCAS[abs(j)] def subset_R_from_logs(logs, mod): """R = sum_g c_g^2 for subset sums of `logs` in Z/mod, by direct enumeration of all 2^k subset sums.""" counts = {} k = len(logs) for mask in range(1 << k): s = 0 for i in range(k): if mask >> i & 1: s += logs[i] counts[s % mod] = counts.get(s % mod, 0) + 1 return sum(c * c for c in counts.values()) def classify(logs10): """Given all-even logs e_i in Z/10, return (R, m, ratio, z, s, d) with the halved data: f_i = e_i/2 in Z/5; z = #{f_i = 0}; n1 = #{f_i in {1,4}}, n2 = #{f_i in {2,3}}; d = n1 - n2; s = k - z.""" k = len(logs10) R = subset_R_from_logs(logs10, 10) m = 10 for e in logs10: m = gcd(m, e) ratio = Fraction(5 * R, m * (4 ** k)) if k >= 0 else None f = [e // 2 for e in logs10] z = sum(1 for x in f if x == 0) n1 = sum(1 for x in f if x in (1, 4)) n2 = sum(1 for x in f if x in (2, 3)) return R, m, ratio, z, k - z, n1 - n2 # ---------------- Part A: exhaustive tuples ---------------- partA = {"tuples": 0, "identity_failures": 0, "ratio_5_4_iff_s1_failures": 0, "cap_failures": 0, "max_ratio": None, "max_ratio_s_ge_2": None} EVEN = (0, 2, 4, 6, 8) for k in range(0, 7): for tup in itertools.product(EVEN, repeat=k): partA["tuples"] += 1 R, m, ratio, z, s, d = classify(list(tup)) # identity: 5R = 4^k + 2 * 4^z * L_|d| if 5 * R != 4 ** k + 2 * (4 ** z) * lucas(d): partA["identity_failures"] += 1 if k >= 1: if (ratio == Fraction(5, 4)) != (s == 1): partA["ratio_5_4_iff_s1_failures"] += 1 if s >= 2 or m == 10: if ratio > Fraction(15, 16): partA["cap_failures"] += 1 if partA["max_ratio"] is None or ratio > partA["max_ratio"]: partA["max_ratio"] = ratio if s >= 2 and (partA["max_ratio_s_ge_2"] is None or ratio > partA["max_ratio_s_ge_2"]): partA["max_ratio_s_ge_2"] = ratio partA["max_ratio"] = str(partA["max_ratio"]) partA["max_ratio_s_ge_2"] = str(partA["max_ratio_s_ge_2"]) # ---------------- Part B: realised primes ---------------- # spf sieve up to 1,521,937 + slack for K_11 <= (n+11)/4 LIM = 1521937 spf = list(range(LIM + 1)) for i in range(2, isqrt(LIM) + 1): if spf[i] == i: for j in range(i * i, LIM + 1, i): if spf[j] == j: spf[j] = i def distinct_prime_factors(x): out = [] while x > 1: p = spf[x] out.append(p) while x % p == 0: x //= p return out rows = [] with open(CSV_PATH, newline="") as fh: for rec in csv.DictReader(fh): rows.append((int(rec["n"]), int(rec["first_good_p"]))) assert len(rows) == 14375, len(rows) partB = {"population": len(rows), "allqr_primes": 0, "identity_failures": 0, "path_disagreements": 0, "factorisation_failures": 0, "ratio_values": {}, "s_values": {}, "max_ratio": None, "s1_primes": [], "exc": {"allqr": 0, "own_subgroup_QR_exact": 0, "own_subgroup_trivial": 0, "covered_ratio_lt_1": 0, "max_ratio": None, "max_ratio_s_ge_2": None, "s1_count": 0, "s1_first": []}} for n, fgp in rows: K = (n + L) // 4 assert 4 * K - L == n facs = distinct_prime_factors(K) # factorisation reconstruction check prod = 1 for q in facs: a = 0 x = K while x % q == 0: x //= q a += 1 prod *= q ** a if prod != K: partB["factorisation_failures"] += 1 residues = [q % L for q in facs] if any(r == 0 for r in residues): partB["factorisation_failures"] += 1 continue logs = [LOG[r] for r in residues] if any(e % 2 == 1 for e in logs): continue # not in the all-QR class at l = 11 partB["allqr_primes"] += 1 # Path 1: subset products mod 11 directly. counts = {} kk = len(residues) for mask in range(1 << kk): p = 1 for i in range(kk): if mask >> i & 1: p = (p * residues[i]) % L counts[p] = counts.get(p, 0) + 1 R1 = sum(c * c for c in counts.values()) # Path 2: halved-log subset sums over Z/5. f = [e // 2 for e in logs] dcounts = {} for mask in range(1 << kk): ssum = 0 for i in range(kk): if mask >> i & 1: ssum += f[i] dcounts[ssum % 5] = dcounts.get(ssum % 5, 0) + 1 R2 = sum(c * c for c in dcounts.values()) if R1 != R2: partB["path_disagreements"] += 1 R, m, ratio, z, s, d = classify(logs) if R != R1: partB["path_disagreements"] += 1 if 5 * R != 4 ** kk + 2 * (4 ** z) * lucas(d): partB["identity_failures"] += 1 key = str(ratio) partB["ratio_values"][key] = partB["ratio_values"].get(key, 0) + 1 partB["s_values"][str(s)] = partB["s_values"].get(str(s), 0) + 1 if partB["max_ratio"] is None or ratio > Fraction(partB["max_ratio"]): partB["max_ratio"] = str(ratio) if s == 1: partB["s1_primes"].append(n) if fgp == 0: ex = partB["exc"] ex["allqr"] += 1 # own subgroup H_0: generated by the residues; # order = 10 / m. QR exactly iff m = 2 and not # all residues 1; trivial iff all residues 1. if all(r == 1 for r in residues): ex["own_subgroup_trivial"] += 1 elif m == 2: ex["own_subgroup_QR_exact"] += 1 if ratio < 1: ex["covered_ratio_lt_1"] += 1 if ex["max_ratio"] is None or ratio > Fraction(ex["max_ratio"]): ex["max_ratio"] = str(ratio) if s >= 2 and (ex["max_ratio_s_ge_2"] is None or ratio > Fraction(ex["max_ratio_s_ge_2"])): ex["max_ratio_s_ge_2"] = str(ratio) if s == 1: ex["s1_count"] += 1 if len(ex["s1_first"]) < 10: ex["s1_first"].append(n) partB["s1_count"] = len(partB["s1_primes"]) partB["s1_first10"] = partB["s1_primes"][:10] del partB["s1_primes"] results = {"partA": partA, "partB": partB} with open(OUT_PATH, "w") as fh: json.dump(results, fh, indent=1, sort_keys=True) print(json.dumps(results, indent=1, sort_keys=True))