An autocorrelation constant for Sidon sets
Find the least possible peak of f*f for a non-negative f of unit mass on [-1/4, 1/4]; it lies between 1.2802 and 1.50286.
| 1 | #!/usr/bin/env python3 |
| 2 | """The project's second judge, the check `improves`, which informs and does not block a merge: the pushed route's best |
| 3 | candidate against the best the default branch holds (constructions/ and routes/ of the check's own checkout, the |
| 4 | approved version) and against the best known bound. It says by how much the route improves on the default branch and |
| 5 | passes when that is at least the minimum improvement, 1e-8 (EinsteinArena's on this problem); a route at least that far |
| 6 | below the best known bound is a new result. On the default branch itself it reports what it holds and passes.""" |
| 7 | import json |
| 8 | import os |
| 9 | import pathlib |
| 10 | import sys |
| 11 | from fractions import Fraction |
| 12 | |
| 13 | from autocorrelation import decimal_up, ratio |
| 14 | |
| 15 | MINIMUM = Fraction("1e-8") |
| 16 | KNOWN = "1.502743486709583" # the EinsteinArena leader, Atris, seen 2026-10-22 (the README's known bounds) |
| 17 | |
| 18 | |
| 19 | def show(x): |
| 20 | return f"{float(x):.3g}".replace("e-0", "e-") |
| 21 | |
| 22 | |
| 23 | def best(roots): |
| 24 | out = None |
| 25 | for root in roots: |
| 26 | for path in sorted(root.rglob("*.json")) if root.exists() else []: |
| 27 | try: |
| 28 | candidate = json.loads(path.read_text()) |
| 29 | if not isinstance(candidate, dict) or "heights" not in candidate: |
| 30 | continue |
| 31 | _, r = ratio(candidate) |
| 32 | except (OSError, ValueError): |
| 33 | continue |
| 34 | if out is None or r < out[0]: |
| 35 | out = (r, path) |
| 36 | return out |
| 37 | |
| 38 | |
| 39 | |
| 40 | main_dir = pathlib.Path(sys.argv[2]) |
| 41 | held = best([main_dir / "constructions", main_dir / "routes"]) |
| 42 | if os.environ.get("SS_ROUTE_DIR", "") == "routes": |
| 43 | print(f"the default branch holds best upper bound {decimal_up(held[0])}" if held else "the default branch holds no candidate") |
| 44 | sys.exit(0) |
| 45 | route = best([pathlib.Path(sys.argv[1])]) |
| 46 | if not route: |
| 47 | print("no candidate in this route to compare") |
| 48 | sys.exit(1) |
| 49 | this = f"best upper bound {decimal_up(route[0])} ({route[1].name})" |
| 50 | known = f"a new result, {show(Fraction(KNOWN) - route[0])} below the best known {KNOWN}" if Fraction(KNOWN) - route[0] >= MINIMUM else f"not a new result: the best known is {KNOWN}" |
| 51 | gain = held[0] - route[0] if held else None |
| 52 | if gain is None: |
| 53 | print(f"improves on the default branch, which holds no candidate: {this}; {known}") |
| 54 | elif gain <= 0: |
| 55 | print(f"no improvement: {this}; the default branch holds {decimal_up(held[0])}; {known}") |
| 56 | sys.exit(1) |
| 57 | elif gain < MINIMUM: |
| 58 | print(f"improves on the default branch by {show(gain)}, less than the minimum {show(MINIMUM)}: {this}, against {decimal_up(held[0])}; {known}") |
| 59 | sys.exit(1) |
| 60 | else: |
| 61 | print(f"improves on the default branch by {show(gain)} (at least {show(MINIMUM)}): {this}, against {decimal_up(held[0])}; {known}") |
