| | @@ -0,0 +1,255 @@ |
| 1 | +"""Exact checks for the Erdős #530 deletion estimates. Python 3.10+.""" |
| 2 | + |
| 3 | +from collections import Counter |
| 4 | +from fractions import Fraction as Q |
| 5 | +from itertools import combinations |
| 6 | +from math import isqrt |
| 7 | +from pathlib import Path |
| 8 | +from runpy import run_path |
| 9 | + |
| 10 | + |
| 11 | +HERE = Path(__file__).resolve().parent |
| 12 | +K135 = Q(359, 10) |
| 13 | +MIN_DEFICIT = Q(4, 10**6) |
| 14 | + |
| 15 | + |
| 16 | +def sqrt_bracket(value): |
| 17 | + """Rational endpoints enclosing the square root.""" |
| 18 | + scale = 10**18 |
| 19 | + below = isqrt(value.numerator * scale**2 // value.denominator) |
| 20 | + return Q(below, scale), Q(below + 1, scale) |
| 21 | + |
| 22 | + |
| 23 | +def check_optimum(): |
| 24 | + root_lo, root_hi = sqrt_bracket(Q(2)) |
| 25 | + assert Q("0.08578643") < Q(3, 2) - root_hi |
| 26 | + assert Q(3, 2) - root_lo < Q("0.08578644") |
| 27 | + |
| 28 | + # Isolate the unique critical point of the old coefficient. |
| 29 | + k = K135 |
| 30 | + lo, hi = Q(0), Q(1, 2) |
| 31 | + for _ in range(80): |
| 32 | + delta = (lo + hi) / 2 |
| 33 | + derivative_sign = k * (k - 1) * delta**2 + (2 * k + 1) * delta - 1 |
| 34 | + if derivative_sign < 0: |
| 35 | + lo = delta |
| 36 | + else: |
| 37 | + hi = delta |
| 38 | + sigma_lo = lo / (1 + k * lo) |
| 39 | + sigma_hi = hi / (1 + k * hi) |
| 40 | + keep_root_lo, _ = sqrt_bracket(1 - hi) |
| 41 | + _, keep_root_hi = sqrt_bracket(1 - lo) |
| 42 | + unrestricted_lo = 1 - (1 - sigma_lo) / keep_root_lo |
| 43 | + unrestricted_hi = 1 - (1 - sigma_hi) / keep_root_hi |
| 44 | + assert Q("0.00238672") < unrestricted_lo <= unrestricted_hi < Q("0.00238673") |
| 45 | + assert 2 * unrestricted_hi < Q(1, 200) |
| 46 | + |
| 47 | + sigma = Q(1, 135) |
| 48 | + width = k * sigma |
| 49 | + q_lo, q_hi = sqrt_bracket(1 - sigma / (1 - width)) |
| 50 | + assert Q("0.00236114") < 1 - (1 - sigma) / q_lo |
| 51 | + assert 1 - (1 - sigma) / q_hi < Q("0.00236115") < Q(1, 422) |
| 52 | + print("Old optimum: 0.08578643 < limiting scaled saving < 0.08578644.") |
| 53 | + print("K=35.9: unrestricted saving in (0.00238672, 0.00238673)," |
| 54 | + " certified-row ceiling in (0.00236114, 0.00236115).") |
| 55 | + |
| 56 | + |
| 57 | +def check_graph_examples(): |
| 58 | + """Compute every induced cover number on all five-vertex graphs.""" |
| 59 | + n = 5 |
| 60 | + edges = [1 << i | 1 << j for i, j in combinations(range(n), 2)] |
| 61 | + full = (1 << n) - 1 |
| 62 | + for graph in range(1 << len(edges)): |
| 63 | + present = [e for i, e in enumerate(edges) if graph & (1 << i)] |
| 64 | + cover = [0] * (1 << n) |
| 65 | + for mask in range(1, full + 1): |
| 66 | + edge = next((e for e in present if mask & e == e), 0) |
| 67 | + if edge: |
| 68 | + end = edge & -edge |
| 69 | + cover[mask] = 1 + min(cover[mask ^ end], cover[mask ^ (edge ^ end)]) |
| 70 | + pivotal = sum(cover[mask] - cover[mask ^ (1 << i)] |
| 71 | + for i in range(n) if mask & (1 << i)) |
| 72 | + assert pivotal <= 2 * cover[mask] |
| 73 | + for q in (Q(1, 4), Q(2, 3), Q(99, 100)): |
| 74 | + weights = [q**s * (1 - q)**(n - s) for s in range(n + 1)] |
| 75 | + expected = sum(t * weights[mask.bit_count()] for mask, t in enumerate(cover)) |
| 76 | + assert expected >= q**2 * cover[full] |
| 77 | + if len(present) == cover[full]: |
| 78 | + # Equality includes each matching with its isolated vertices. |
| 79 | + assert expected == q**2 * cover[full] |
| 80 | + print("Checked induced covers on all 1,024 labeled five-vertex graphs.") |
| 81 | + |
| 82 | + |
| 83 | +def check_signed_windows(seed, differences, host_size): |
| 84 | + """Integrate the squared window count directly between successive jumps.""" |
| 85 | + locations = [Q(2 * v - 1, 2 * host_size) for v in seed] |
| 86 | + for width in (Q(1, 8), Q(5, 16), Q(3, 4)): |
| 87 | + breaks = sorted(set(locations) | {v - width for v in locations}) |
| 88 | + integral = Q(0) |
| 89 | + for lo, hi in zip(breaks, breaks[1:]): |
| 90 | + t = (lo + hi) / 2 |
| 91 | + count = sum(t <= v <= t + width for v in locations) |
| 92 | + integral += (hi - lo) * count**2 / (host_size * width**2) |
| 93 | + actual, signed = Q(0), Q(0) |
| 94 | + for d in range(1, host_size): |
| 95 | + tent = max(0, 1 - d / (host_size * width)) |
| 96 | + actual += differences[d] * tent |
| 97 | + signed += (1 - differences[d]) * tent |
| 98 | + assert integral == (len(seed) + 2 * actual) / (host_size * width) |
| 99 | + assert signed / host_size <= Q(len(seed), 2 * host_size) + width * (1 - integral) / 2 |
| 100 | + |
| 101 | + |
| 102 | +def check_additive_counts(): |
| 103 | + """Test the signed count before the power bounds, including repeated differences.""" |
| 104 | + host = tuple(range(1, 9)) |
| 105 | + distances = range(1, len(host)) |
| 106 | + plus = [max(0, 8 - d) for d in range(8)] |
| 107 | + minus = [2 * max(0, 5 - d) for d in range(8)] |
| 108 | + |
| 109 | + def score(weight): |
| 110 | + return min(j - 1 + Q(weight, j) for j in range(1, weight + 2)) |
| 111 | + |
| 112 | + gp, gm = [score(w) for w in plus], [score(w) for w in minus] |
| 113 | + gmax = max(gp[0], gm[0]) |
| 114 | + quadruples = [v for v in combinations(host, 4) if v[0] + v[3] == v[1] + v[2]] |
| 115 | + cases = 0 |
| 116 | + negative_cost_seen = False |
| 117 | + for mask in range(1 << len(host)): |
| 118 | + seed = [v for i, v in enumerate(host) if mask & (1 << i)] |
| 119 | + outside = sorted(set(host).difference(seed)) |
| 120 | + differences = Counter(b - a for a, b in combinations(seed, 2)) |
| 121 | + check_signed_windows(seed, differences, len(host)) |
| 122 | + sums = Counter(a + b for a in seed for b in seed) |
| 123 | + triples = Counter(a + b - c for a in seed for b in seed for c in seed) |
| 124 | + # Test the neighbor charges with a graph having an independent seed. |
| 125 | + edges = {(x, y) for x in outside for y in seed if (x + 2 * y) % 3 == 0} |
| 126 | + free = sum(len(set(quad).intersection(outside)) == 1 |
| 127 | + and all(x not in quad or y not in quad for x, y in edges) |
| 128 | + for quad in quadruples) |
| 129 | + diagonal = sum(2 * a - c in outside for a in seed for c in seed) |
| 130 | + neighbors = sum(2 * differences[abs(x - y)] + sums[x + y] for x, y in edges) |
| 131 | + assert sum(triples[x] for x in outside) <= diagonal + 2 * free + neighbors |
| 132 | + |
| 133 | + excess = {d: max(0, differences[d] - 1) for d in distances} |
| 134 | + signed_cost = sum((plus[d] + minus[d]) * (1 - differences[d]) for d in distances) |
| 135 | + negative_cost_seen |= signed_cost < 0 |
| 136 | + repeat_cost = sum((plus[d] + minus[d]) * excess[d] for d in distances) |
| 137 | + local = {x: sum(gp[a - x] if a > x else gm[x - a] for a in seed) for x in outside} |
| 138 | + for size in range(len(outside) + 1): |
| 139 | + for subset in combinations(outside, size): |
| 140 | + collision_excess = 2 * sum(excess[y - x] for x, y in combinations(subset, 2)) |
| 141 | + budget = (size * (size - 1) + signed_cost + repeat_cost + collision_excess |
| 142 | + + gmax * sum(triples[x] for x in subset)) |
| 143 | + assert sum(local[x] for x in subset) <= budget |
| 144 | + cases += 1 |
| 145 | + assert negative_cost_seen and cases == 3**len(host) |
| 146 | + print(f"Checked {cases:,} disjoint seed/test-set pairs in [8] and all 768 signed windows.") |
| 147 | + |
| 148 | + |
| 149 | +def check_small_threshold(): |
| 150 | + sigma = Q(1, 135) |
| 151 | + a = 1 + K135 * sigma |
| 152 | + delta, z = Q("0.010072"), Q("0.0000042") |
| 153 | + q = 1 - delta |
| 154 | + gap = delta * (1 - q * (a - 1)) - sigma |
| 155 | + m0 = 2**181 |
| 156 | + log2_hi = Q(7, 10) |
| 157 | + assert 1 + log2_hi + log2_hi**2 / 2 + log2_hi**3 / 6 > 2 |
| 158 | + assert m0 * sigma**2 >= 10**14 and 1 < a < 2 |
| 159 | + assert (Q(3240000) / sigma) < (2**11)**3 |
| 160 | + assert 2 * 181 * log2_hi < 256 and 256**4 < (2**11)**3 |
| 161 | + assert (2**60)**3 < m0 |
| 162 | + assert Q(3, 2)**8 * (2**22)**8 < m0 |
| 163 | + assert Q(19, 16)**4 * (2**45)**4 < m0 |
| 164 | + error = Q(104, 3 * 2**22) + Q(64, 2**45) |
| 165 | + cover = Q(2 * 2**11 * 2**11, 2**60) + Q(256, m0) |
| 166 | + graphs = 96 * 181 * log2_hi * Q(16, 19 * 2**45) |
| 167 | + mode_cost = 3 * 181 * log2_hi / m0 |
| 168 | + assert error + z < gap |
| 169 | + assert 0 < z / (2 * a * delta) <= 1 |
| 170 | + assert cover + graphs + mode_cost < z**2 / (4 * a * delta) |
| 171 | + assert (1 - sigma)**2 < q * Q(421, 422)**2 |
| 172 | + print("K=35.9, N >= 2^362: strict saving 1/422.") |
| 173 | + |
| 174 | + |
| 175 | +def check_uniform_certificate(): |
| 176 | + uniform = run_path(str(HERE.parent / "upper-large-deficit" / "check.py")) |
| 177 | + row = next(t for t in uniform["TESTS"] if t.uniform and t.inverse_deficit == 100) |
| 178 | + cutoff = Q(1, 100) |
| 179 | + uniform["check"](row, cutoff=cutoff) |
| 180 | + weights = list(map(Q, row.weights.split())) |
| 181 | + reverse, = map(Q, row.reverse_weight.split()) |
| 182 | + c0 = sum(weights) * (1 + reverse) |
| 183 | + g_max = uniform["score"](max(sum(weights), sum(weights) * reverse)) |
| 184 | + assert row.half_size == 48 and 19 < g_max <= 20 and c0 <= 120 |
| 185 | + assert uniform["CUTOFF"] == Q(1, 10000) and uniform["HOST"] == 10**14 |
| 186 | + assert uniform["SMOOTH"] == Q(1, 10**5) and uniform["VARIANCE_SLACK"] == Q(1, 1000) |
| 187 | + |
| 188 | + m0 = 2**256 |
| 189 | + degree_power = Q(5, 32) |
| 190 | + edge_free_power = 1 + 3 * degree_power |
| 191 | + energy_power = 2 + degree_power |
| 192 | + mixed_power = (energy_power + edge_free_power) / 2 |
| 193 | + assert edge_free_power == Q(47, 32) < Q(7, 4) |
| 194 | + assert energy_power == Q(69, 32) and mixed_power == Q(29, 16) |
| 195 | + assert (1 + energy_power) / 2 == Q(101, 64) < mixed_power |
| 196 | + assert 256 * (2 - edge_free_power) == 136 and 256 * (2 - mixed_power) == 48 |
| 197 | + assert 256 * degree_power == 40 |
| 198 | + assert m0 * MIN_DEFICIT**2 >= uniform["HOST"] |
| 199 | + excess = Q(1, m0) + Q(100, 2**136) |
| 200 | + eps2 = uniform["SMOOTH"]**2 |
| 201 | + assert excess <= Q(1, 10000) * eps2 * MIN_DEFICIT**2 |
| 202 | + assert eps2 + Q(1, 10000) + eps2 / 10000 < uniform["VARIANCE_SLACK"] |
| 203 | + |
| 204 | + # Constants for differences, repeated summands, and triples at graph neighbors. |
| 205 | + assert 16 + 3 * 2**2 * 4 // 2 == 40 |
| 206 | + assert 2 + 4 + 6 * 40 == 246 |
| 207 | + assert 4 + 2 * 246 == 496 |
| 208 | + assert 2 * 496 < 32**2 |
| 209 | + assert 4 * 16 * 100 == 80**2 and 4 * 8 * 32 == 32**2 |
| 210 | + assert 4 * 246 * 100 < 320**2 |
| 211 | + assert 32 + 24 * 16 + 5 * 8 + 80 + 32 == 568 |
| 212 | + assert 568 * g_max + 320 + 50 * c0 <= 18000 |
| 213 | + assert Q(18000, 2**48) < row.half_size * cutoff * 19 * MIN_DEFICIT**2 |
| 214 | + print("Uniform R=100 certificate transfers to the refined graphs for m >= 2^256.") |
| 215 | + |
| 216 | + |
| 217 | +def check_large_thresholds(): |
| 218 | + m0 = 2**256 |
| 219 | + fingerprints = Q(64, 2**40) |
| 220 | + alpha_error = Q(52, 2**32) |
| 221 | + assert fingerprints + alpha_error < Q(1, 10**7) |
| 222 | + log_m_hi = 256 * Q(7, 10) |
| 223 | + assert 2 * log_m_hi < 360 and 360**4 < (2**12)**3 |
| 224 | + assert 1 + Q(5, 16) * log_m_hi == 57 and 3 * log_m_hi < 540 |
| 225 | + cover = Q(2 * 2**11 * 2**12, 2**85) + Q(360, m0) |
| 226 | + graphs = Q(24 * 57, 2**40) |
| 227 | + rows = ((135, K135, 270, Q("0.0000135"), Q("0.000009")), |
| 228 | + (100, Q(75, 2), 200, Q("0.000020"), Q("0.000011")), |
| 229 | + (100, 96, 200, Q("0.000020"), Q("0.000011"))) |
| 230 | + for r, k, denominator, slack, z in rows: |
| 231 | + sigma = Q(1, r) |
| 232 | + delta = sigma + slack |
| 233 | + width = k * sigma |
| 234 | + assert m0 * sigma**2 >= 10**14 and Q(3240000) / sigma < (2**11)**3 |
| 235 | + assert 0 < MIN_DEFICIT < sigma and 0 < width < 1 |
| 236 | + assert 98 * delta < 1 |
| 237 | + assert MIN_DEFICIT + fingerprints + alpha_error + z < delta - sigma |
| 238 | + assert fingerprints + z < delta * (1 - 2 * sigma - width) |
| 239 | + assert 0 < z / (4 * delta) <= 1 |
| 240 | + assert cover + graphs + Q(540, m0) < z**2 / (8 * delta) |
| 241 | + ratio = 1 - Q(1, denominator) |
| 242 | + assert (1 - sigma)**2 < (1 - delta) * ratio**2 |
| 243 | + print(f"K={k}, N >= 2^512: strict saving 1/{denominator}.") |
| 244 | + assert Q(1, 200) > Q(2, 428) |
| 245 | + |
| 246 | + |
| 247 | +if __name__ == "__main__": |
| 248 | + if not __debug__: |
| 249 | + raise RuntimeError("Run the certificate with Python assertions enabled.") |
| 250 | + check_optimum() |
| 251 | + check_graph_examples() |
| 252 | + check_additive_counts() |
| 253 | + check_small_threshold() |
| 254 | + check_uniform_certificate() |
| 255 | + check_large_thresholds() |