"""Exact first test of simultaneous cancellation for divisor degrees 0, 1 and 2.""" from collections import defaultdict from fractions import Fraction from itertools import combinations, product from math import gcd, lcm from sympy import Matrix, divisor_sigma from sympy.ntheory.modular import crt def main(): # These small parameters suffice for the 8 by 8 test. The proof gives # a larger, uniform choice of D using a factorial. length, radix = 8, 15 step, base = 223092870, 49972807679 vertices = list(product(range(length), repeat=2)) dilation = [base + step * (a + radix * b) for a, b in vertices] offset = [step * (a + 2 * radix * b) for a, b in vertices] shifts = [[(j + 1) * p - t for p, t in zip(dilation, offset)] for j in range(3)] assert min(min(row) for row in shifts) > 0 assert all(gcd(p, q) == 1 for p, q in combinations(dilation, 2)) assert len(set(shifts[2])) == len(vertices) assert set(shifts[2]).isdisjoint(shifts[0] + shifts[1]) # Use a separate integer unknown per column, multiplied ultimately by # the LCM of the three divisor sums at that column. sigmas = [[int(divisor_sigma(p, h)) for p in dilation] for h in range(3)] scales = [lcm(*column) for column in zip(*sigmas)] rows = [] for j in range(2): for fixed in range(length): for h in range(3): for i in range(j, min(h, 1) + 1): row = [ (s // sigma) * p ** (i + 1) if e[1 - j] == fixed else 0 for e, p, s, sigma in zip(vertices, dilation, scales, sigmas[h]) ] rows.append(row) matrix = Matrix(rows).to_DM() basis = matrix.nullspace() assert matrix.shape == (56, 64) and basis.shape[0] == 10 raw = [int(x) * s for x, s in zip(basis.to_Matrix().row(0), scales)] content = gcd(*raw) weights = [u // content for u in raw] # Check the original rational equations grouped by actual shift, # independently of the axis-by-axis construction of the integer matrix. for h in range(3): for i in range(min(h, 1) + 1): for j in range(i + 1): groups = defaultdict(Fraction) for u, p, shift, sigma in zip(weights, dilation, shifts[j], sigmas[h]): groups[shift] += Fraction(u * p ** (i + 1), sigma) assert all(value == 0 for value in groups.values()) witness = next(e for e, u in enumerate(weights) if u) p = dilation[witness] final_coefficient = Fraction(weights[witness] * p**3, sigmas[2][witness]) assert final_coefficient and shifts[2].count(shifts[2][witness]) == 1 # Both parities can be prescribed. At every depth the two factors in the # multiplicativity step must be coprime. for residue in range(2): solution, _ = crt([2] + [p*p for p in dilation], [residue] + offset) for p, t in zip(dilation, offset): n = (int(solution) - t) // p assert n % p == 0 and n % 2 == residue for j in range(3): assert p * (n+j+1) == solution + (j+1)*p-t assert gcd(p, n+j+1) == 1 print(f"{matrix.shape[0]} equations, {matrix.shape[1]} vertices, " f"rank {len(vertices)-basis.shape[0]}, nullity {basis.shape[0]}") print(f"{len(set(shifts[2]))} isolated top shifts; recovered an integer " f"vector with {sum(bool(u) for u in weights)} nonzero entries") print("Exact cancellations, final coefficient, and both CRT parity checks passed.") if __name__ == "__main__": main()