"""Finite checks for the Jordan and divisor factorial-sum research proof. Run with Python 3 and SymPy. No input files are needed. """ from collections import Counter from fractions import Fraction from functools import cache from itertools import combinations, product from math import gcd, prod from shutil import which from subprocess import check_output from sympy import divisors, factorint, isprime, mobius, primerange def factorizations(numbers): """Use GNU factor when available, with a SymPy fallback.""" if which("factor"): lines = check_output(["factor", *map(str, numbers)], text=True).splitlines() result = {} for line in lines: key, factors = line.split(":") result[int(key)] = Counter(map(int, factors.split())) else: result = {n: factorint(n) for n in numbers} for n in numbers: factors = result[n] assert prod(p**e for p, e in factors.items()) == n assert all(isprime(p) for p in factors) return result def function_values(n, factors): values = [1, prod(e + 1 for e in factors.values())] for h in (1, 2): sigma = prod(sum(p**(h*i) for i in range(e+1)) for p, e in factors.items()) jordan = prod(p**(h*(e-1)) * (p**h-1) for p, e in factors.items()) values.extend((sigma, jordan)) return values def kernel_witness(rows, field): matrix = [row.copy() for row in rows] pivots = [] for column in range(len(matrix[0])): rank = len(pivots) pivot = next((i for i in range(rank, len(matrix)) if matrix[i][column]), None) if pivot is None: continue matrix[rank], matrix[pivot] = matrix[pivot], matrix[rank] inverse = pow(matrix[rank][column], -1, field) matrix[rank] = [v*inverse % field for v in matrix[rank]] for i, row in enumerate(matrix): if i != rank and row[column]: scale = row[column] matrix[i] = [(a-scale*b) % field for a,b in zip(row, matrix[rank])] pivots.append(column) free = next(j for j in range(len(matrix[0])) if j not in pivots) witness = [0] * len(matrix[0]) witness[free] = 1 for i, p in enumerate(pivots): witness[p] = -matrix[i][free] % field assert all(sum(a*b for a,b in zip(row, witness)) % field == 0 for row in rows) return len(pivots), free def crt_pair(a, q, b, t): assert gcd(q,t) == 1 return a + q*((b-a)*pow(q,-1,t) % t), q*t def check_mixed_grid(): # All six numerators 1, τ, σ₁, J₁, σ₂, J₂ occur, on a common class mod 6. side, radix, modulus = 11, 11, 6 vertices = list(product(range(side), repeat=2)) middle = (side**2-1)//2 spacing = prod(primerange(2, middle+1)) center = prod(primerange(middle+1, 2*middle+1)) multiple = next(i for i in range(1, 100) if i*center % modulus == 1 and gcd(i, spacing) == 1 and i*center > 4*middle*spacing) base = multiple*center-middle*spacing p = [base+spacing*(x+radix*y) for x,y in vertices] offsets = [spacing*(x+2*radix*y) for x,y in vertices] shifts = [[(j+1)*n-t for n,t in zip(p,offsets)] for j in range(3)] assert len(set(p)) == len(p) and min(min(level) for level in shifts)>0 assert all(gcd(n,k)==1 for n,k in combinations(p,2)) assert len(set(shifts[2]))==len(p) and set(shifts[2]).isdisjoint(shifts[0]+shifts[1]) for j in range(2): assert all(len({s for v,s in zip(vertices,shifts[j]) if v[1-j]==a})==1 for a in range(side)) factors = factorizations(p) values = [function_values(n, factors[n]) for n in p] field = 1_000_000_007 assert isprime(field) and all(z % field for column in values for z in column) rows = [] for depth, families in [(0, range(6)), (1, range(2,6))]: # These are all nonzero Taylor rows to cancel. At depth 1 only i=0 # occurs. At depth 2 only the four positive-degree numerators need i=1. for s in sorted(set(shifts[depth])): for f in families: rows.append([pow(n,depth+1,field)*pow(val[f],-1,field) % field if t==s else 0 for n,val,t in zip(p,values,shifts[depth])]) rank, free = kernel_witness(rows,field) # A nonzero full-row minor modulo this prime is nonzero over Q. # Setting this free variable to 1, and the other free variables to 0, # now has a Q-solution with the same designated surviving coefficient. assert rank == len(rows) == 110 and len(p) == 121 a, q = 2, modulus for n,t in zip(p,offsets): a,q = crt_pair(a,q,t,n*n) ell = 2**127-1 assert isprime(ell) and gcd(ell,q)==1 and ell>max(map(max,shifts)) target = shifts[2][free] for v, residue in enumerate((0,ell-target,ell**2-target)): N, period = crt_pair(a,q,residue,ell**3) N += period assert (N+target) % ell**v == 0 and (N+target) % ell**(v+1) != 0 assert all((N+s) % ell for s in set(sum(shifts,[]))-{target}) for n,t in zip(p,offsets): index, rem = divmod(N-t,n) assert rem==0 and index>0 and index % modulus==2 and index % n==0 assert all(gcd(n,index+j)==1 for j in (1,2,3)) print(f"Mixed degrees 0,1,2: {rank} x {len(p)} matrix; rank {rank} mod {field} and over Q.") print(f"The lifted rational kernel has a unit at vertex {vertices[free]}.") print("Exact CRT verified at all vertices, all three tail positions and all three valuations.") @cache def normalized(n, h): ds = list(map(int, divisors(n))) sigma = sum(d**h for d in ds) jordan = sum(int(mobius(d))*(n//d)**h for d in ds) return Fraction(sigma,n**h), Fraction(jordan,n**h) def check_means(): ell, coarse, away = 7, 12, 360 period = away*ell**3 target = 2 count = 0 for h, a, s in product(range(1,6), range(coarse), (1,2,4)): means = [] for residue in (0,ell-target,ell**2-target): samples = [gcd(N+s,period) for N in range(residue,period,ell**3) if N%coarse==a] assert len(samples) == away//coarse pairs = [normalized(n,h) for n in samples] means.append([sum(values)/len(pairs) for values in zip(*pairs)]) if s==target: x = Fraction(1,ell**h) m_sigma,m_jordan = means[0] assert m_sigma>=1 and m_jordan>0 assert means[1]==[m_sigma*(1+x), m_jordan*(1-x)] assert means[2]==[m_sigma*(1+x+x*x), m_jordan*(1-x)] # This mixture makes the first difference identically zero. mix = [m_jordan*S + m_sigma*J for S,J in means] assert mix[0]==mix[1] and mix[2]-mix[1]==m_jordan*m_sigma*x*x else: assert means[0]==means[1]==means[2] count += 1 print(f"Exact finite-kernel means: {count} triples of progressions, in degrees 1 through 5.") print("At the target the second jump detects every tested mixture canceling the first jump.") for n in range(1,26): primitive = sum(gcd(gcd(i,j),n)==1 for i,j in product(range(n),repeat=2)) assert primitive == normalized(n,2)[1]*n**2 print("Direct counts of primitive residue pairs agree with J₂ for n=1,...,25.") if __name__ == "__main__": check_mixed_grid() check_means()