| | @@ -0,0 +1,126 @@ |
| 1 | +"""Independently certify both rows at 2^512 and the K=96 row at 2^362. |
| 2 | + |
| 3 | +All arithmetic uses integers or fractions. Monotonicity extending the |
| 4 | +endpoint comparisons to larger hosts is proved in VERIFY.md, section 4. |
| 5 | +""" |
| 6 | + |
| 7 | +from fractions import Fraction |
| 8 | +from math import floor, isqrt |
| 9 | + |
| 10 | + |
| 11 | +# Integrate the four secants above 1/x on [1,2] with mesh 1/4. |
| 12 | +LOG_TWO_UPPER = ( |
| 13 | + Fraction(1, 2) + Fraction(4, 5) + Fraction(2, 3) + Fraction(4, 7) + Fraction(1, 4) |
| 14 | +) / 4 |
| 15 | + |
| 16 | + |
| 17 | +def ceil_sqrt(value: Fraction) -> int: |
| 18 | + lower = isqrt(value.numerator // value.denominator) |
| 19 | + return lower if lower**2 == value else lower + 1 |
| 20 | + |
| 21 | + |
| 22 | +def deletion_bounds_fit( |
| 23 | + n_exponent: int, sigma: Fraction, error_limit: Fraction, entropy_limit: Fraction |
| 24 | +) -> bool: |
| 25 | + """Bound e_m and B_m + P_m/m by rational comparisons at m = sqrt(2^n_exponent).""" |
| 26 | + assert n_exponent > 0 and n_exponent % 2 == 0 |
| 27 | + m = 2**(n_exponent // 2) |
| 28 | + fourth_root_lower = isqrt(isqrt(m)) |
| 29 | + eighth_root_lower = isqrt(fourth_root_lower) |
| 30 | + log_m_upper = (n_exponent // 2) * LOG_TWO_UPPER |
| 31 | + log_host_upper = 2 * log_m_upper |
| 32 | + error = Fraction(52, eighth_root_lower) + Fraction(64, fourth_root_lower) |
| 33 | + |
| 34 | + # Either covering gives |T| <= 2pm and p^3 <= 2*162*10^4*log(M)/(sigma*m). |
| 35 | + # Cube the cost 2p*log(M) and reserve space for the other two entropy terms. |
| 36 | + fingerprint_factor = 2 * 162 * 10**4 |
| 37 | + fingerprint_cost_cubed = 8 * fingerprint_factor * log_host_upper**4 / (sigma * m) |
| 38 | + rounding_cost = log_host_upper / m |
| 39 | + graph_cost = 96 * log_m_upper / fourth_root_lower |
| 40 | + remaining = entropy_limit - rounding_cost - graph_cost |
| 41 | + return error < error_limit and remaining > 0 and fingerprint_cost_cubed < remaining**3 |
| 42 | + |
| 43 | + |
| 44 | +def verify_row( |
| 45 | + coefficient: int, |
| 46 | + max_deficit: Fraction, |
| 47 | + host_constant: int, |
| 48 | + expected_ratio: Fraction, |
| 49 | + threshold_exponent: int, |
| 50 | +) -> None: |
| 51 | + delta = Fraction(2, 5 * coefficient) |
| 52 | + sigma = 12 * delta / 17 |
| 53 | + ratio = 1 - delta / 5 |
| 54 | + host_factor = 1 - delta - delta**2 |
| 55 | + container_factor = 1 + coefficient * sigma |
| 56 | + tail_center = 1 - 2 * delta + delta * container_factor |
| 57 | + gap = 1 - sigma - tail_center |
| 58 | + assert ratio == expected_ratio and gap == delta / 85 |
| 59 | + assert 0 < sigma <= max_deficit and container_factor == Fraction(109, 85) |
| 60 | + assert Fraction(1, 2) < host_factor < 1 |
| 61 | + |
| 62 | + # Recover the common threshold with stronger error budgets on a doubling grid. |
| 63 | + common_exponent = 16 |
| 64 | + while common_exponent <= 512 and not deletion_bounds_fit( |
| 65 | + common_exponent, sigma, gap / 64, gap**2 / 512 |
| 66 | + ): |
| 67 | + common_exponent *= 2 |
| 68 | + assert common_exponent == 512 |
| 69 | + |
| 70 | + # At the lowest claimed endpoint for this row use the budgets from (1). |
| 71 | + assert deletion_bounds_fit(threshold_exponent, sigma, gap / 2, gap**2 / 8) |
| 72 | + n_min = 2**threshold_exponent |
| 73 | + m_min = isqrt(n_min) |
| 74 | + assert m_min**2 == n_min |
| 75 | + assert m_min >= 81 and m_min * sigma**2 >= host_constant and m_min * sigma >= 1 |
| 76 | + assert gap**2 * m_min / 8 > 2 |
| 77 | + |
| 78 | + # Also verify the coarser common dyadic bounds printed in the proof. |
| 79 | + assert 3240000 / sigma <= (2**12)**3 |
| 80 | + assert 512**4 == (2**12)**3 and (2**85)**3 < 2**256 |
| 81 | + printed_cost = Fraction(1, 2**60) + Fraction(512, 2**256) + Fraction(96 * 256, 2**64) |
| 82 | + printed_error = Fraction(52, 2**32) + Fraction(64, 2**64) |
| 83 | + assert printed_cost < gap**2 / 8 and printed_error < gap / 2 |
| 84 | + |
| 85 | + if threshold_exponent == 362: |
| 86 | + # The rounded majorants printed in the note's smaller-threshold paragraph. |
| 87 | + assert LOG_TWO_UPPER < Fraction(7, 10) and 362 * Fraction(7, 10) < 256 |
| 88 | + assert 3240000 / sigma < (2**11)**3 and 256**4 < (2**11)**3 |
| 89 | + assert (2**60)**3 < m_min and Fraction(19, 16)**4 < 2 |
| 90 | + graph_cost = Fraction(96 * 181 * 7 * 16, 10 * 19 * 2**45) |
| 91 | + printed_cost = Fraction(1, 2**37) + Fraction(256, m_min) + graph_cost |
| 92 | + printed_error = Fraction(52, 2**22) + Fraction(64, 2**45) |
| 93 | + assert printed_cost < gap**2 / 8 and printed_error < gap / 2 |
| 94 | + |
| 95 | + assert delta**2 * n_min > 2 and 8 / (delta**3 * n_min) < Fraction(1, 4) |
| 96 | + squared_margin = ratio**2 * host_factor - (1 - sigma)**2 |
| 97 | + expanded = ( |
| 98 | + delta / 85 - (Fraction(14, 25) + Fraction(144, 289)) * delta**2 |
| 99 | + + (9 - delta) * delta**3 / 25 |
| 100 | + ) |
| 101 | + assert squared_margin == expanded and squared_margin > delta / 85 - 2 * delta**2 > 0 |
| 102 | + |
| 103 | + # Apply the actual floor and ceiling at the endpoint, including a |
| 104 | + # potentially nonsquare host, and check the survivor estimate there. |
| 105 | + host = floor(n_min / host_factor) |
| 106 | + assert n_min <= host <= 2 * n_min |
| 107 | + mean = (1 - delta) * host |
| 108 | + variance = host * delta * (1 - delta) |
| 109 | + assert mean - n_min > delta**2 * n_min / 2 |
| 110 | + assert variance / (mean - n_min)**2 < Fraction(1, 4) |
| 111 | + seed_squared = (1 - sigma)**2 * host |
| 112 | + seed_size = ceil_sqrt(seed_squared) |
| 113 | + assert (seed_size - 1)**2 < seed_squared <= seed_size**2 |
| 114 | + assert seed_squared < ratio**2 * n_min |
| 115 | + |
| 116 | + print(f"K={coefficient} delta={delta} sigma={sigma} g={gap} coefficient={ratio}") |
| 117 | + print(f" N >= 2^{common_exponent}, e_m < g/64, B_m + P_m/m < g^2/512") |
| 118 | + print(f" N >= 2^{threshold_exponent}, both failure probabilities < 1/4") |
| 119 | + print(f" exact squared threshold margin = {squared_margin}") |
| 120 | + |
| 121 | + |
| 122 | +if __name__ == "__main__": |
| 123 | + if not __debug__: |
| 124 | + raise SystemExit("Run the verifier with Python assertions enabled.") |
| 125 | + verify_row(96, Fraction(1, 100), 10**14, Fraction(1199, 1200), 362) |
| 126 | + verify_row(3600, Fraction(1, 1001), 10**5, Fraction(44999, 45000), 512) |