"""Reproduce all finite inequalities in the four-power theorem.""" from fractions import Fraction as F from hashlib import sha256 from pathlib import Path import os import shlex import subprocess import sys import tempfile from four_power_check import (PI_UP, log2_bound, polynomial_bound, scalar_exp_weights, scalar_support) from linnik_check import budgets, direct_checks, rounded from tables import build ROOT = Path(__file__).resolve().parent def main(): if not __debug__: raise SystemExit('The verifier requires Python assertions. Disable optimization.') if sys.byteorder!='little': raise SystemExit('The C++ table reader expects a little-endian host.') with tempfile.TemporaryDirectory(prefix='four-powers-') as scratch: tmp = Path(scratch) table_path = tmp/'tables.bin' print('Generating outward trigonometric and exponential tables.',flush=True) table = build(table_path) assert table_path.read_bytes()==(ROOT/'tables.bin').read_bytes() print('Table SHA-256',sha256(table_path.read_bytes()).hexdigest(),flush=True) # A 16384-point scalar grid is the subgrid of every fourth table entry. scalar_table = table[::4] log2_bound() weights = scalar_exp_weights() rows = [tuple(map(int,line.split())) for line in (ROOT/'scalar.tsv').read_text().splitlines()] assert [row[0] for row in rows]==list(range(65)) and all(len(row)==4 for row in rows) for row in rows: scalar_support(*row,scalar_table,weights) square = polynomial_bound([r[3] for r in rows],scalar_table) assert square<=F('.051269390163')F('.21911')>F('.219097314') print('Checking direct tuple sums, Ramanujan transforms and the two margins.',flush=True) direct_checks() budgets() print('PASS all finite inequalities',flush=True) if __name__=='__main__': main()