"""Exact finite controls for a residual-aware support-truncation certificate.""" from fractions import Fraction as Q from itertools import product import json def dot(a, b): return sum(x * y for x, y in zip(a, b)) def apply(matrix, vector): return [dot(row, vector) for row in matrix] def quotient(matrix, vector): return dot(vector, apply(matrix, vector)) / dot(vector, vector) def criterion(lower, loss_upper, residual_squared_upper, threshold): if not 0 <= loss_upper < Q(1, 2) or residual_squared_upper < 0: raise ValueError("Require 0 <= mass-loss upper bound < 1/2 and nonnegative residual bound") margin = lower * (1 - 2 * loss_upper) - threshold * (1 - loss_upper) return (lower > threshold and margin > 0 and margin * margin > 4 * residual_squared_upper * loss_upper) def observe(matrix, vector, threshold): norm = dot(vector, vector) lam = quotient(matrix, vector) residual = [a - lam * b for a, b in zip(apply(matrix, vector), vector)] rho2 = dot(residual, residual) / norm loss = vector[1] ** 2 / norm restricted = quotient(matrix, [vector[0], Q(0)]) return { "lambda": str(lam), "mass_loss": str(loss), "residual_squared": str(rho2), "threshold": str(threshold), "restricted_quotient": str(restricted), "naive_mass_scaled_quotient": str(lam * (1 - loss)), "residual_certificate": criterion(lam, loss, rho2, threshold), "actual_crossing": restricted > threshold, "incorrect_zero_residual_certificate": criterion(lam, loss, Q(0), threshold), } def main(): tau = Q(10000, 2583) v = [Q(12, 13), Q(5, 13)] matrix = [[Q(9, 2) * x * y for y in v] for x in v] f = [Q(399, 401), Q(40, 401)] counterexample = observe(matrix, f, tau) assert Q(counterexample["mass_loss"]) < Q(1, 100) assert Q(counterexample["naive_mass_scaled_quotient"]) > tau assert not counterexample["actual_crossing"] assert not counterexample["residual_certificate"] assert counterexample["incorrect_zero_residual_certificate"] eigen_matrix = [[5 * x * y for y in v] for x in v] positive = observe(eigen_matrix, v, Q(4)) assert positive["residual_certificate"] and positive["actual_crossing"] assert Q(positive["residual_squared"]) == 0 checked = certified = 0 vectors = [[Q(4, 5), Q(3, 5)], v, f] for entries in product((-1, 0, 1), repeat=4): b = [entries[:2], entries[2:]] psd = [[sum(Q(b[k][i] * b[k][j]) for k in range(2)) for j in range(2)] for i in range(2)] for vector in vectors: for threshold in (Q(0), Q(1, 2), Q(1), Q(2), Q(4)): result = observe(psd, vector, threshold) checked += 1 if result["residual_certificate"]: certified += 1 assert result["actual_crossing"] print(json.dumps({ "counterexample": counterexample, "counterexample_operator_norm": "9/2", "positive_eigenvector_control": positive, "finite_psd_controls": checked, "sufficient_certificates_observed": certified, "false_certificates": 0, "scope": "Synthetic rational matrices only; not a computation of the Maynard operator " "or of the published k=46 trial polynomial.", }, sort_keys=True, separators=(",", ":"))) if __name__ == "__main__": main()