"""Verify the strict lower bound with constant 11901/10^6 on 1000 < H <= 10^100. Use --generate to regenerate the bundled bases with fplll. Verification of the saved bases uses only Python and SymPy. """ import json import re import subprocess import sys from fractions import Fraction from math import factorial, isqrt from pathlib import Path from audit import B, C, init CERTIFICATE = Path(__file__).with_name("window-bases.json") END = 10**100 ORDER = 270 SCORE = Fraction(11901, 10**6) def moment_centers(): base = [[Fraction(b) for b in row] for row in B.tolist()] lead = [[Fraction(c) for c in row] for row in C.tolist()] previous = [Fraction(t) for t in init] totals = previous[1:3] order = [0, 6, 7, 5, 3, 4, 1, 2] for i, index in enumerate(order): assert all(base[index][j] == 0 for j in order[i + 1 :]) for n in range(1, ORDER + 1): row = [Fraction(0)] * 8 for i in order: rhs = sum(c * t for c, t in zip(lead[i], previous)) rhs += sum(b * t for b, t in zip(base[i], row)) row[i] = rhs / (n - base[i][i]) for j in range(2): totals[j] += row[j + 1] previous = row return totals, Fraction(2 * 3 ** (ORDER + 1), factorial(ORDER + 1)) def gram_bounds(basis): def dot(a, b): return sum(x * y for x, y in zip(a, b)) a, b, c = basis determinant = ( a[0] * (b[1] * c[2] - b[2] * c[1]) - a[1] * (b[0] * c[2] - b[2] * c[0]) + a[2] * (b[0] * c[1] - b[1] * c[0]) ) first = dot(a, a) second = first * dot(b, b) - dot(a, b) ** 2 return abs(determinant), min( Fraction(first), Fraction(second, first), Fraction(determinant**2, second) ) def reduced_basis(s, a, b): inp = f"[[1 0 {a}][0 1 {b}][0 0 {s}]]" out = subprocess.run( ["fplll", "-a", "lll"], input=inp, text=True, check=True, capture_output=True ) numbers = list(map(int, re.findall(r"-?\d+", out.stdout))) assert len(numbers) == 9 return [numbers[i : i + 3] for i in (0, 3, 6)] def test_window(low, high, scale, basis, centers, tail): rounded = [round(scale * x) for x in centers] err = max(abs(scale * x - a) + scale * tail for x, a in zip(centers, rounded)) assert err < Fraction(51, 100) for u, v, w in basis: assert (w - u * rounded[0] - v * rounded[1]) % scale == 0 det, min_gs = gram_bounds(basis) assert det == scale # isqrt rounds the denominator down, enlarging the upper bound. third = 2 * high * err + scale * SCORE / isqrt(low**5) return min_gs / (2 * high**2 + third**2) def run(generate): centers, tail = moment_centers() records = [] if generate else json.loads(CERTIFICATE.read_text()) worst = None low = 1001 i = 0 while low <= END: high = min(2 * (low - 1), END) if generate: for k in range(4, 27): scale = 2**k * high**3 a, b = (round(scale * x) for x in centers) basis = reduced_basis(scale, a, b) margin = test_window(low, high, scale, basis, centers, tail) if margin > 2: records.append([k, basis]) break else: raise ArithmeticError(f"No certificate for {low}..{high}") else: k, basis = records[i] scale = 2**k * high**3 margin = test_window(low, high, scale, basis, centers, tail) assert margin > 2, (low, high) if worst is None or margin < worst[0]: worst = (margin, low, high) low = high + 1 i += 1 assert len(records) == i if generate: CERTIFICATE.write_text(json.dumps(records, separators=(",", ":")) + "\n") m, low, high = worst assert m > Fraction(200104, 100000) assert i == 323 print( f"{i} lattice windows cover 1001 through 10^100; least squared-norm ratio > {m.numerator * 100000 // m.denominator}/100000 on [{low}, {high}]" ) if __name__ == "__main__": run("--generate" in sys.argv)