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 judge: every candidate (*.json with "heights") in the route's folder, checked exactly by |
| 3 | autocorrelation.py. Both are in checks/judge/, which a check runs at the project's approved version. One line per candidate, then |
| 4 | the best upper bound, which it also writes to metrics.json here; fails when a candidate is unreadable or not admissible.""" |
| 5 | import json |
| 6 | import pathlib |
| 7 | import sys |
| 8 | |
| 9 | from autocorrelation import CandidateError, decimal_up, ratio |
| 10 | |
| 11 | root = pathlib.Path(sys.argv[1]) |
| 12 | best, bad = None, 0 |
| 13 | for path in sorted(root.rglob("*.json")) if root.exists() else []: |
| 14 | name = path.relative_to(root) |
| 15 | try: |
| 16 | candidate = json.loads(path.read_text()) |
| 17 | except Exception as exc: |
| 18 | print(f"{name}: unreadable ({exc})") |
| 19 | bad += 1 |
| 20 | continue |
| 21 | if not isinstance(candidate, dict) or "heights" not in candidate: |
| 22 | continue |
| 23 | try: |
| 24 | n, r = ratio(candidate) |
| 25 | except CandidateError as exc: |
| 26 | print(f"{name}: invalid: {exc}") |
| 27 | bad += 1 |
| 28 | continue |
| 29 | print(f"{name}: {n} steps, C <= {decimal_up(r)}") |
| 30 | if best is None or r < best[0]: |
| 31 | best = (r, name) |
| 32 | if best: |
| 33 | pathlib.Path("metrics.json").write_text(json.dumps({"score": float(best[0]), "score_exact": decimal_up(best[0], 25)}) + "\n") |
| 34 | print(f"best upper bound C <= {decimal_up(best[0])} ({best[1]})") |
| 35 | else: |
| 36 | print(f"no valid candidates: {bad} failed" if bad else "no candidates to check") |
| 37 | sys.exit(1 if bad else 0) |
