"""Finite scalar consequences of Droll, Sections 6 and 7.""" from fractions import Fraction as Q from math import comb, gcd, prod # Ordinary even and odd, conjugate even and odd, coefficient. MONOMIALS = ( (0, 4, 0, 0, Q(1)), (1, 3, 0, 0, Q(529031, 250000)), (2, 2, 0, 0, Q(219937, 50000)), (3, 1, 0, 0, Q(191671, 50000)), (4, 0, 0, 0, Q(140199, 200000)), (3, 0, 0, 0, -Q(152351, 10**6)), (2, 1, 0, 0, -Q(41547, 10**5)), (1, 2, 0, 0, -Q(5529, 12500)), (0, 3, 0, 0, -Q(144383, 10**6)), (2, 0, 0, 0, -Q(27197, 10**6)), (1, 1, 0, 0, -Q(30407, 10**6)), (0, 2, 0, 0, -Q(6171, 10**6)), (1, 0, 1, 0, -Q(1571, 500000)), (1, 0, 0, 1, -Q(5017, 10**6)), (0, 1, 0, 1, -Q(103, 50000)), ) CERT = (Q(241300793487, 250000000000), Q(121262154483, 125000000000)) TAIL = (Q(2671851, 12500000), Q(693987, 3125000)) RETAINED = Q(964728963181, 500000000000) SIGMA = Q(1952, 1000) ODD = Q(27, 50) A, B = Q(389, 2500), Q(5703, 40000) SAME, MIXED = 1+Q(1, 25), 1-Q(1, 25) def squarefree_factors(n): factors = [] p = 2 while p*p <= n: if n % p == 0: n //= p if n % p == 0: return None factors.append(p) p += 1 if n > 1: factors.append(n) return factors def order(n): if n == 1: return 1 y, k = 2 % n, 1 while y != 1: y = 2*y % n k += 1 return k def arithmetic_checks(ck): # The coupled minima and upper order sum enter here with Droll's rounded values. ck.at("(2.2)") joint = {d for d in range(1, 5006) if 5005 % d == 0} extra = {d for d in range(1, 2002) if gcd(d, 6) == 1 and squarefree_factors(d) is not None} - joint ck.eq("design", "joint and extra modulus counts", (len(joint), len(extra)), (16, 594)) retained = Q(0) for d in sorted(joint | extra): o = order(d) g = Q(1, prod(p-2 for p in squarefree_factors(d))) retained += g*(Q(3, 2) if o % 2 else 2)/o ck.lt("design", "retained-order lower bound", RETAINED, retained) ck.at("(2.3)") sub = [1, 7, 23, 31, 47, 127] ck.eq("design", "odd orders in the positive subsum", [order(d) for d in sub], [1, 3, 11, 5, 23, 7]) odd_sum = sum(Q(1, 2*order(d)*prod(p-2 for p in squarefree_factors(d))) for d in sub) ck.eq("design", "six positive odd-order terms", odd_sum, Q(31200629, 57778875)) ck.lt("design", "odd order sum lower floor", ODD, odd_sum) ck.at("(2.1)") ck.eq("design", "sum of absolute coefficients", sum(abs(m[-1]) for m in MONOMIALS), Q(13277797, 10**6)) ck.lt("design", "outside polynomial ceiling", Q(13277797, 10**6), 14) ck.eq("design", "quartics bounded by ordered parity counts", all(g <= comb(4, a) for a, b, c, d, g in MONOMIALS if g > 0), True) ck.eq("design", "two free coordinates in every pattern", all(2 <= sum(m[:4]) <= 4 for m in MONOMIALS), True) ck.lt("design", "quadratic form positive definite", B, A) ck.lt("design", "sum of energy coefficients", A+B, 1) for residue in range(3): kappa = Q(1 if residue == 2 else -1, 5) W = [Q(0), 1+kappa, 1-kappa] lp = [sum(W[r]*W[(j-r) % 3] for r in range(3)) for j in range(3)] lm = [sum(W[r]*W[(r+j) % 3] for r in range(3)) for j in range(3)] ck.at("(4.3), (7.2)") ck.eq("design", f"difference factors at class {residue}", lm, [2*SAME, MIXED, MIXED]) total = tail = Q(0) for a, b, c, d, gamma in MONOMIALS: if residue == 1: a, b, c, d = b, a, d, c lam = lp[(residue+c-d-a+b) % 3] total += abs(gamma)*lam if gamma < 0: tail -= gamma*lam/2**(a+b+c+d) ck.at("(2.2)") ck.lt("design", f"weighted coefficient sum at class {residue}", total, 20) ck.eq("design", f"negative tail at class {residue}", tail, TAIL[int(residue != 0)]) # B_s = (1/2) sum W(r)e(sr/3). Sum over s gives 3 times # the constant coefficient in the cyclic group ring. ck.at("(4.3)-(4.4)") for j in range(3): for sign, local in [(1, lp), (-1, lm)]: convolution = sum(W[r]*W[v] for r in range(3) for v in range(3) if (r + sign*v - j) % 3 == 0) ck.eq("design", f"local convolution {residue},{j},{sign}", Q(3, 4)*convolution, Q(3, 4)*local[j]) ck.at("(7.2)") ck.eq("design", "same and mixed slope numerators", (A*SAME, A*SAME-B*MIXED), (Q(15171, 93750), Q(9357, 375000))) slope = 2*Q("0.660162")*(A*SAME*SIGMA-(A*SAME-B*MIXED)*ODD) ck.lt("design", "sieve change per unit", slope, Q(".400")) ck.lt("design", "cost of 0.006 multiplier", Q(".006")*slope, Q(".00240")) ck.at("(7.3)") for i, target in enumerate([Q(".014025"), Q(".020238")]): b = CERT[i]-TAIL[i]*(SIGMA-RETAINED)-3*A*SAME*SIGMA+3*(A*SAME-B*MIXED)*ODD ck.lt("design", f"positive series bracket {i}", 0, b) margin = 2*Q(".6601")*b-A*SAME*Q(".5001")*Q(".694") ck.lt("design", f"reference margin for class {2*i}", target, margin) def order_sum(ck, log_two): """Finite order moments of Lemma 6.2(ii), with one upward rounding per k.""" from math import isqrt ck.at("(2.3), (5.1)") cutoff, pmax, grid = 2**14, 2**17, 10**9 spf = list(range(pmax+1)) for p in range(2, isqrt(pmax)+1): if spf[p] == p: for n in range(p*p, pmax+1, p): if spf[n] == n: spf[n] = p numerators = [1]*(cutoff+1) denominators = [1]*(cutoff+1) for p in range(3, pmax+1, 2): if spf[p] != p: continue k = p-1 o = k while k > 1: f = spf[k] while k % f == 0: k //= f while o % f == 0 and pow(2, o//f, p) == 1: o //= f for j in range(o, cutoff+1, o): numerators[j] *= p-1 denominators[j] *= p-2 moment0 = moment1 = 0 for k in range(1, cutoff+1): upper = (grid*numerators[k]+denominators[k]-1)//denominators[k] moment0 += upper moment1 += k*upper ck.le("order", "first finite order moment on 10^9 grid", moment0, 31726406582170) ck.le("order", "second finite order moment on 10^9 grid", moment1, 259964609693760739) # At most k/17 primes >2^17 divide 2^k-1. The residual exponential # is at most 1+k/(17*(P-2)-T), by exp(x)<=1/(1-x). outside_denom = 17*(pmax-2)-cutoff ck.eq("order", "large-prime denominator", outside_denom, 2228190-16384) finite = (Q(moment0, grid)+Q(moment1, grid*outside_denom))/cutoff # Equation (5.1) gives A(u) <= 3 log(u)/C2 < 12 log(u) for u>=T. ck.lt("order", "unweighted order prefix for the infinite tail", 3/Q(".6601"), 12) tail = 12*(1+14*log_two)/cutoff ck.lt("order", "finite moments plus order tail", finite+tail, SIGMA) def facet_scalars(ck, directory, log_two, source=None): """Compare the four symmetry images and the two slopes in every inequality.""" import hashlib import re ck.at("Sec. 2(i), (6.2)") table = (directory/"facets.tsv").read_text(encoding="ascii").splitlines() if table[0] != "a1\ta2\ta3\ta4\tb": raise ValueError("unexpected facet columns") rows = [tuple(map(int, row.split("\t"))) for row in table[1:]] if source is not None: src = source.read_bytes() ck.eq("facets", "release file SHA-256", hashlib.sha256(src).hexdigest(), "9c70d51951032ff85b3c4528340d4ee2b1266dd051853c5c6deea2278150e936") segment = src.decode("utf-8").split("def baseFacets : List BaseFacet := [", 1)[1].split("]", 1)[0] parsed = [] for line in segment.strip().splitlines(): a, b, c, d, e, f, g, h, bn = map(int, re.findall(r"[0-9]+", line)) parsed.append((a-b, c-d, e-f, g-h, bn)) ck.eq("facets", "all transcribed facet integers", rows, parsed) images = [] norm2 = 0 for a, b, c, d, offset in rows: images.extend([(a, b, c, d, offset), (a, -b, c, -d, offset), (c, d, a, b, offset), (c, -d, a, -b, offset)]) norm2 = max(norm2, a*a+b*b, c*c+d*d) ck.eq("facets", "base, orbit and distinct counts", (len(rows), len(images), len(set(images))), (1614, 6456, 6452)) ck.lt("facets", "largest squared slope", Q(norm2, 1024**2), 16) ck.lt("facets", "smallest offset clears the stated rate", Q(67, 200)*log_two, Q(min(row[4] for row in rows), 10**15))