"""Exact block, moment and window checks for both denominator-gap bounds.""" from fractions import Fraction as F from itertools import product R_MAX = F(7, 64) SWITCH_LOSS = F(1, 16) def type_i(theta, b, xi, sigma, tau): s_cap = sigma - 3 * theta - tau for r in (xi - s_cap, b - s_cap): s = xi - r yield { "Q <= R": theta - r, "Q^2 R^2 S": 2 * theta + 2 * r + s - 1, "M1": (1 + theta - xi) / 2 - sigma, "M2": 3 * theta + s - sigma, } def type_ii(theta, b, xi, sigma, tau): for nu in (1 - 3 * sigma, F(1, 4)): s_cap = nu - tau for r in (xi - s_cap, b - s_cap): s = xi - r k = nu - s # log_x(V/S) yield { "high frequency, diagonal": 3 * theta + r - s / 2 + nu - F(1, 2), "low frequency, diagonal": 6 * theta + 2 * k - nu, "Q^4 <= S": 4 * theta - s, "Q^4 R^2 V": 4 * theta + 2 * r + nu - 1, "fixed spectrum, high": ( 5 * theta / 2 + r / 2 + 5 * nu / 4 - F(1, 2) + R_MAX * (r - theta / 2) ), "fixed spectrum, low": ( 5 * theta + k + nu / 2 - r + 2 * R_MAX * (r - theta / 2) ), } def switched_type_i(theta, b, xi, sigma, tau): s_cap = sigma - 3 * theta - tau for r, m in product((xi - s_cap, b - s_cap), (sigma, theta + xi)): s = xi - r level = theta + 2 * r baseline = 5 * theta + 4 * r + s - 1 - m yield { "regular spectrum": baseline, "twice switched spectrum": ( baseline + 2 * R_MAX * (2 * s + 2 * r - (2 - SWITCH_LOSS) * level) ), "switched frequency length": ( 2 * r + s + m - 1 - (1 - SWITCH_LOSS) * (1 - 2 * R_MAX) * level ), } def occupancy_ratio(groups, mean_bound, kernel_error, sieve_level): u = F(1, 10**5) return (groups * (1 + u) / (mean_bound * (1 - u) * (1 - kernel_error)) + (2 / sieve_level + F(3, 10000) + u) * (1 + u) * (1 + kernel_error) / ((1 - u)**2 * (1 - kernel_error)**2)) def block_vertices(level, delta, tau, slope): for theta in (F(0), 2 * delta): left = F(1, 2) - theta - tau for xi in (left, level): sigma = F(2917, 10000) + slope * (xi - left) yield theta, xi, sigma def verify_block_region(level, delta, tau, slope, sigma_cap, caps): for theta, xi, sigma in block_vertices(level, delta, tau, slope): assert F(7, 24) < sigma < sigma_cap for bounds in type_i(theta, level, xi, sigma, tau): for term in ("Q <= R", "Q^2 R^2 S", "M1", "M2"): assert bounds[term] <= caps[term], (term, bounds[term]) s_cap = sigma - 3 * theta - tau for r in (xi - s_cap, level - s_cap): s = xi - r assert (5 * theta + 2 * r + s - 3 * sigma) / 4 <= caps["Type I Poisson zero"] assert s - theta / 2 > F(24, 100) # Lower bound for the admissible spectral length when P_0 < 1. assert F(375, 512) * (theta + 2 * r) > F(29, 100) for bounds in switched_type_i(theta, level, xi, sigma, tau): for term, value in bounds.items(): assert value <= caps[term], (term, value) for bounds in type_ii(theta, level, xi, sigma, tau): for term in ("high frequency, diagonal", "low frequency, diagonal", "fixed spectrum, high", "fixed spectrum, low", "Q^4 <= S", "Q^4 R^2 V"): assert bounds[term] <= caps[term], (term, bounds[term]) for nu in (1 - 3 * sigma, F(1, 4)): assert nu > F(1, 15) for r in (xi - nu + tau, level - nu + tau): assert r - theta / 2 > F(1, 5) assert xi - r > F(1, 26) assert r < min(1 - 3 * (theta + nu) / 2, 1 - (xi - r)) - tau def verify_26_groups(): level = F(27, 50) delta = F(1, 3200) tau = F(1, 20_000_000_000) caps = { "Q <= R": -F(1, 5), "Q^2 R^2 S": -F(1, 5), "M1": -F(1, 25), "M2": -tau, "Type I Poisson zero": -F(29, 1000), "regular spectrum": -F(33, 1000), "twice switched spectrum": -F(23, 10000), "switched frequency length": -F(31, 1000), "high frequency, diagonal": -F(26, 100000), "low frequency, diagonal": -F(39, 1000), "fixed spectrum, high": -F(9, 1000), "fixed spectrum, low": -F(57, 1000), "Q^4 <= S": -F(81, 1000), "Q^4 R^2 V": -F(15, 1000), } verify_block_region(level, delta, tau, F(11, 50), F(301, 1000), caps) # The comparison vertex in Type I is also admissible for the singleton q = 1. theta, xi = F(0), level sigma = F(2917, 10000) + F(11, 50) * (xi - (F(1, 2) - theta - tau)) s = sigma - 3 * theta - tau r = xi - s old_length = 4 * theta + 3 * r + 2 * s - 1 - sigma assert old_length > F(19, 1000) bounds = next(switched_type_i(theta, level, xi, sigma, tau)) fixed_level = bounds["regular spectrum"] + 2 * R_MAX * max(0, 2 * s - theta) assert fixed_level > F(89, 1000) assert max(bounds["regular spectrum"], bounds["twice switched spectrum"]) < -F(87, 10000) # Type II diagonal at the bottom main-modulus block and the largest R. theta = 2 * delta xi = F(1, 2) - theta - tau nu = 1 - 3 * F(2917, 10000) r = level - (nu - tau) s = xi - r diagonal = 3 * theta + r - s / 2 + nu - F(1, 2) assert diagonal == -F(2624999, 10**10) assert diagonal + theta / 2 == F(500001, 10**10) # The two-switch weight lies in Lichtman's general-coefficient range. beta = 2 * R_MAX z_max = (1 - SWITCH_LOSS) * (1 - beta) assert z_max == F(375, 512) assert z_max + beta * (2 - SWITCH_LOSS - z_max) == F(16319, 16384) assert F(26, 7) - F(37133, 10000) == F(69, 70000) sieve_level = F(5399, 10000) assert F(2) / F(7, 13) == F(26, 7) assert F(7, 13) < sieve_level < level assert sieve_level + 4 * delta**2 < level assert 1 - F(31, 32) - 2 * delta - 4 * delta**2 > F(1, 100) assert F(9, 10) * delta * 16_000_000 * F(69, 100) > 3100 ratio = occupancy_ratio(26, 3100, F(1, 10**7), sieve_level) assert ratio < F(37133, 10000) < F(26, 7) assert F(6997, 1000) / F(190001, 10000) > F(40320, 109601) + F(1, 10000) assert F("6.999") + F("0.0009") == 7 - F("0.0001") print("Verified the Type I spectral comparison, the Type II diagonal,") print("all 26-group block bounds and the moment ratio < 3.7133.") def verify_145_groups(): b = F(673, 1250) delta = F(1, 10**6) tau = F(1, 10**7) slope = F(52, 125) for theta, xi, sigma in block_vertices(b, delta, tau, slope): assert F(7, 24) < sigma < F(4, 13) # Type I: the diagonal itself, then the four terms of the fourth power. s_cap = sigma - 3 * theta - tau for rho, m in product((xi - s_cap, b - s_cap), (sigma, theta + xi)): s = xi - rho assert (3 * theta + s - m) / 2 <= -tau / 2 assert 4 * theta + 4 * rho + 2 * s - 2 <= -F("0.46") assert 5 * theta + 4 * rho + s - 1 - m <= -F("0.051") assert 4 * theta + 3 * rho + 2 * s - 1 - m <= -F("0.000136") assert 5 * theta + 2 * rho + s - 3 * m <= -F("0.128") assert theta < rho and 2 * theta + s - m <= -tau assert 1 + theta - xi - 2 * m < -F("0.08") assert 2 * rho + s + m - 1 - (theta + 2 * rho) < -F("0.1") assert s - theta / 2 > F("0.24") # Type II: test both branches of H in the three squared monomials. for nu in (1 - 3 * sigma, F(1, 4)): assert nu > F(1, 13) s_cap = nu - tau for rho in (xi - s_cap, b - s_cap): s = xi - rho kappa = nu - s assert kappa >= tau and s > F(1, 26) and rho - theta / 2 > F("0.20") assert 4 * theta - s < -F("0.076") assert 4 * theta + 2 * rho + nu - 1 < -F("0.000165") assert rho + 3 * (theta + nu) / 2 < 1 - tau and xi < 1 - tau natural = 2 * theta + 2 * rho + s - (1 - nu) # The paper gives unsquared bounds for the natural cutoff. for h, power, (diag, first, second) in ( (natural, 2, (F("-0.000080"), F("-0.043"), F("-0.0336"))), (2 * theta, 1, (F("-0.048"), F("-0.124"), F("-0.105"))), ): assert (4 * theta + 2 * kappa + h - nu) / power <= diag assert (3 * theta + kappa + nu / 2 + h - rho) / power <= first assert (9 * theta / 4 + kappa + h - rho / 2) / power <= second bs = F(10767, 20000) assert bs + 4 * delta**2 < b and 2 < 4 * (bs - F(1, 10**7)) < 3 assert F(9, 10) * delta * 400_000_000_000 * F(69, 100) > 200_000 assert occupancy_ratio(145, 200_000, F(1, 10**7), bs) < F("3.7163") < F(145, 39) assert F("38.997") / F("106.0001") > F(40320, 109601) + F("0.00001") assert F("38.999") + F("0.0009") == 39 - F("0.0001") print("Verified the classical Type I/II bounds, the 145-group window and moment ratio < 3.7163.") if __name__ == "__main__": verify_26_groups() verify_145_groups()