The Erdős minimum overlap problem
Pin down the constant c ≈ 0.38 such that every split of {1,…,2N} into equal halves has a difference occurring cN times.

Search and certify a 64-cell minimum-overlap construction
Browse files+31 −4 routes/zhihuxunyouren/minoverlap-64/README.md View file
| @@ -1,15 +1,42 @@ | ||
| 1 | 1 | --- |
| 2 | 2 | issue: 4 |
| 3 | -status: working | |
| 3 | +status: done | |
| 4 | 4 | --- |
| 5 | 5 | # A 64-cell search for the minimum-overlap upper bound |
| 6 | 6 | |
| 7 | -This route searches over step functions with 64 equal cells. It starts from | |
| 7 | +The route searches over step functions with 64 equal cells. It starts from | |
| 8 | 8 | the block-averaged 1,024-cell construction in `constructions/hyra_n1024.json` |
| 9 | 9 | and makes local moves that preserve the integral, then reports the best |
| 10 | 10 | bound its own code finds. |
| 11 | 11 | |
| 12 | +## Command | |
| 13 | + | |
| 14 | +From the repository root: | |
| 15 | + | |
| 16 | +```sh | |
| 17 | +python3 routes/zhihuxunyouren/minoverlap-64/search64.py | |
| 18 | +python3 tools/check_format.py routes/zhihuxunyouren/minoverlap-64 | |
| 19 | +python3 checks/judge/check.py routes/zhihuxunyouren/minoverlap-64 | |
| 20 | +``` | |
| 21 | + | |
| 22 | +The search seed is `SEED = 20261204` in `search64.py`; it uses the block | |
| 23 | +average as its initial point, SLSQP, then 30,000 seeded transfer moves. | |
| 24 | + | |
| 25 | +## Result | |
| 26 | + | |
| 27 | +`best64.json` has 64 cells. The local judge prints: | |
| 28 | + | |
| 29 | +```text | |
| 30 | +best64.json: n=64, mu <= 0.3811593760404977942676184 | |
| 31 | +best upper bound 0.3811593760404977942676184 (best64.json) | |
| 32 | +``` | |
| 33 | + | |
| 34 | +This is the best 64-cell bound found by this search, not a claim that it is | |
| 35 | +the global optimum. It is above the main branch's 1,024-cell construction, | |
| 36 | +so `improves` fails by design; the task only asks for a certified 64-cell | |
| 37 | +construction. | |
| 38 | + | |
| 12 | 39 | ## Next |
| 13 | 40 | |
| 14 | -Write the search, run it with a recorded seed, and let the judge certify the | |
| 15 | -best 64-cell construction. | |
| 41 | +Rerun the three commands with the recorded seed and compare the exact `mu` | |
| 42 | +line. The site's `verify` check on this route's commit is the record. | |
+68 −0 routes/zhihuxunyouren/minoverlap-64/best64.json added View file
| @@ -0,0 +1,68 @@ | ||
| 1 | +{ | |
| 2 | + "values": [ | |
| 3 | + 0.00022052611565215, | |
| 4 | + 0.000230731439883217, | |
| 5 | + 1.73157956137971e-06, | |
| 6 | + 0.00239931510505169, | |
| 7 | + 0.00705029822912804, | |
| 8 | + 0.00504834898971798, | |
| 9 | + 0.0209232913160101, | |
| 10 | + 0.223911681747412, | |
| 11 | + 0.696793767123566, | |
| 12 | + 0.727688252575581, | |
| 13 | + 0.94903276528249, | |
| 14 | + 0.286125134756997, | |
| 15 | + 4.02468096261413e-05, | |
| 16 | + 0.171599163008994, | |
| 17 | + 0.761445962672963, | |
| 18 | + 0.659613653554246, | |
| 19 | + 0.413859230652485, | |
| 20 | + 0.578549305971615, | |
| 21 | + 0.835427155997721, | |
| 22 | + 0.532008390306615, | |
| 23 | + 0.26460344695293, | |
| 24 | + 0.679263369870841, | |
| 25 | + 0.720570685959101, | |
| 26 | + 0.615255592328485, | |
| 27 | + 0.939899228062098, | |
| 28 | + 0.661402152347089, | |
| 29 | + 0.697802929088781, | |
| 30 | + 0.908237492525659, | |
| 31 | + 0.764723794577916, | |
| 32 | + 0.991106648733318, | |
| 33 | + 0.908446879427034, | |
| 34 | + 0.999734584415082, | |
| 35 | + 0.992575940059224, | |
| 36 | + 0.879090807804393, | |
| 37 | + 0.84315508063009, | |
| 38 | + 0.849675067114869, | |
| 39 | + 0.929283417744369, | |
| 40 | + 0.730360904790037, | |
| 41 | + 0.609878308513171, | |
| 42 | + 0.99130968905033, | |
| 43 | + 0.619576849117698, | |
| 44 | + 0.716391146973679, | |
| 45 | + 0.654147117153867, | |
| 46 | + 0.28939141506478, | |
| 47 | + 0.493584244922612, | |
| 48 | + 0.874209728144993, | |
| 49 | + 0.567511190784378, | |
| 50 | + 0.424966837988182, | |
| 51 | + 0.647473994930057, | |
| 52 | + 0.773218788300425, | |
| 53 | + 0.171831173049521, | |
| 54 | + 2.65576166637219e-05, | |
| 55 | + 0.286114412845057, | |
| 56 | + 0.949060174383818, | |
| 57 | + 0.717559820293158, | |
| 58 | + 0.706943753089542, | |
| 59 | + 0.223864721481006, | |
| 60 | + 0.0209460503370635, | |
| 61 | + 0.00500174820259887, | |
| 62 | + 0.00947242861522368, | |
| 63 | + 2.48294564523834e-06, | |
| 64 | + 0.000456760894413839, | |
| 65 | + 2.03138780894685e-06, | |
| 66 | + 1.59824767569664e-06 | |
| 67 | + ] | |
| 68 | +} | |
+76 −0 routes/zhihuxunyouren/minoverlap-64/search64.py added View file
| @@ -0,0 +1,76 @@ | ||
| 1 | +"""Seed and local search for a 64-cell minimum-overlap construction. | |
| 2 | + | |
| 3 | +The judge computes, for a step function f on [-1,1] with n equal cells, | |
| 4 | + bound(f) = (2/n) max_m sum_i f_i (1 - f_{i+m}). | |
| 5 | +This script starts from the block average of the 1,024-cell construction in | |
| 6 | +constructions/hyra_n1024.json, then runs SLSQP and a seeded local transfer | |
| 7 | +search. It is a search, not a copy of a 64-cell record. | |
| 8 | +""" | |
| 9 | + | |
| 10 | +import json | |
| 11 | +import sys | |
| 12 | +from pathlib import Path | |
| 13 | + | |
| 14 | +import numpy as np | |
| 15 | +from scipy.optimize import minimize | |
| 16 | + | |
| 17 | +N = 64 | |
| 18 | +SEED = 20261204 | |
| 19 | + | |
| 20 | + | |
| 21 | +def bound(f): | |
| 22 | + c = np.correlate(f, 1.0 - f, mode="full") | |
| 23 | + return float((2.0 / N) * c.max()) | |
| 24 | + | |
| 25 | + | |
| 26 | +def project(f): | |
| 27 | + f = np.clip(f, 0.0, 1.0) | |
| 28 | + total = f.sum() | |
| 29 | + if total <= 0: | |
| 30 | + return np.full(N, 0.5) | |
| 31 | + return f * (32.0 / total) | |
| 32 | + | |
| 33 | + | |
| 34 | +def search(): | |
| 35 | + root = Path(__file__).resolve().parents[3] | |
| 36 | + source = np.asarray(json.loads((root / "constructions/hyra_n1024.json").read_text())["values"], dtype=float) | |
| 37 | + f0 = source.reshape(N, 16).mean(axis=1) | |
| 38 | + f0 = project(f0) | |
| 39 | + print(f"seed bound {bound(f0):.15f}", flush=True) | |
| 40 | + | |
| 41 | + cons = ({"type": "eq", "fun": lambda f: f.sum() - 32.0},) | |
| 42 | + res = minimize(bound, f0, method="SLSQP", bounds=[(0.0, 1.0)] * N, | |
| 43 | + constraints=cons, options={"maxiter": 2000, "ftol": 1e-12, "disp": False}) | |
| 44 | + f = project(np.asarray(res.x)) | |
| 45 | + print(f"SLSQP status={res.status} bound {bound(f):.15f}", flush=True) | |
| 46 | + | |
| 47 | + rng = np.random.default_rng(SEED) | |
| 48 | + best = f.copy() | |
| 49 | + best_bound = bound(best) | |
| 50 | + step = 0.02 | |
| 51 | + for iteration in range(30000): | |
| 52 | + candidate = best.copy() | |
| 53 | + i, j = rng.choice(N, size=2, replace=False) | |
| 54 | + delta = float(rng.uniform(-step, step)) | |
| 55 | + candidate[i] = min(1.0, candidate[i] + delta) | |
| 56 | + candidate[j] = max(0.0, candidate[j] - delta) | |
| 57 | + candidate = project(candidate) | |
| 58 | + value = bound(candidate) | |
| 59 | + if value < best_bound: | |
| 60 | + best, best_bound = candidate, value | |
| 61 | + if iteration % 5000 == 0: | |
| 62 | + step *= 0.92 | |
| 63 | + print(f"local-search bound {best_bound:.15f}", flush=True) | |
| 64 | + return best | |
| 65 | + | |
| 66 | + | |
| 67 | +if __name__ == "__main__": | |
| 68 | + result = search() | |
| 69 | + # Keep a tiny positive margin above 32 so the exact judge rescales down, | |
| 70 | + # never up; this guarantees the [0,1] admissibility check cannot overflow. | |
| 71 | + result = result + 0.0001 / N | |
| 72 | + result = result * (32.0001 / result.sum()) | |
| 73 | + route = Path(__file__).resolve().parent | |
| 74 | + payload = {"values": [float(f"{x:.15g}") for x in result]} | |
| 75 | + (route / "best64.json").write_text(json.dumps(payload, indent=2) + "\n") | |
| 76 | + print(f"wrote {route / 'best64.json'} with {len(result)} cells, sum={result.sum():.15g}") | |