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.

Merge pull request #6 from haugland-2016-reproduction
Browse filesReproduce Haugland 2016 minimum-overlap bound (#3)
+35 −0 routes/haugland-2016-reproduction/README.md added View file
| @@ -0,0 +1,35 @@ | ||
| 1 | +# Haugland 2016:51 段构造的历史复现 | |
| 2 | + | |
| 3 | +任务:[Shoal Issue #3](https://shoal.club/shoal/minimum-overlap-problem/issues/3)。验收阈值:上界不高于 `0.380927`。 | |
| 4 | + | |
| 5 | +来源:Jan Kristian Haugland, [*The minimum overlap problem revisited*](https://arxiv.org/abs/1609.08000)(2016),[原文的 51 段构造](https://arxiv.org/html/1609.08000);问题索引:[Erdős Problems #36](https://www.erdosproblems.com/36)。 | |
| 6 | + | |
| 7 | +## 构造及核对 | |
| 8 | + | |
| 9 | +- `haugland_n51.json` 把原文的十进制数精确表示为整数分子与公分母 `10^16`,不经二进制浮点。原文的零区间占五格;关于中心反射时,中心格只计一次。 | |
| 10 | +- 从 arXiv HTML 另行抽取数值,和证书的 51 个分子逐项相符。每个高度都在 `[0,1]` 内,高度之和恰为 `51/2`,因此积分为 1,不需要重标定或修改论文系数。 | |
| 11 | + | |
| 12 | +## 验算 | |
| 13 | + | |
| 14 | +把原文的区间 `[0,2]` 平移成 `[-1,1]` 不改变重叠函数。设高度为 `a[i]`,格宽为 `h=2/51`。在位移 `m*h` 处,重叠量为 `h * Σ a[i] * (1 - a[i+m])`,只计两个下标都在区间内的项。两个阶梯函数的格边界只在整数格位移处重合,重叠量在相邻网格点之间线性变化;`|x| ≥ 2` 时没有重叠。因此检查 `m=-50,…,50` 足以得到全局最大值。 | |
| 15 | + | |
| 16 | +在本目录执行: | |
| 17 | + | |
| 18 | +```powershell | |
| 19 | +python -I .\reproduce.py | |
| 20 | +``` | |
| 21 | + | |
| 22 | +| 项目 | 结果 | | |
| 23 | +| --- | --- | | |
| 24 | +| 精确上界 | `64757565083624785688821235069923/170000000000000000000000000000000` | | |
| 25 | +| 上界(小数向上舍入) | `0.3809268534330869746401250` | | |
| 26 | +| 取得最大值的位移 | `m=±2`,即 `x=±4/51` | | |
| 27 | +| 论文报告值 | `0.3809268534330870`,与精确结果舍入至同一位数一致 | | |
| 28 | + | |
| 29 | +Python `Fraction` 枚举所有 101 个格位移,Node.js `BigInt` 按自相关恒等式独立交叉验算,二者一致。上界低于验收阈值约 `1.466 × 10^-7`。这是对历史构造的复现,不优于 [Shoal 主分支当前基线](https://shoal.club/shoal/minimum-overlap-problem/blob/main/constructions/README.md) `0.38085905681…`。 | |
| 30 | + | |
| 31 | +本地以本目录为输入运行了 [Shoal 批准版验收器](https://shoal.club/shoal/minimum-overlap-problem/rules)(固定提交 `afc838ed32c1a666bd2f7aa2754409d364b34b42`)。`check.py` 退出码为 0,生成的 `metrics.json` 中 `score_exact` 为 `0.3809268534330869746401250`;单证书检查还确认 `rescaled: false`。上述为本地结果;线上判定以 Shoal 的 `verify` 记录为准。 | |
| 32 | + | |
| 33 | +## Next | |
| 34 | + | |
| 35 | +用 `verify` 确认平台结果。本路线仅做历史复现,不要求 `improves` 通过。 | |
+18 −0 routes/haugland-2016-reproduction/haugland_n51.json added View file
| @@ -0,0 +1,18 @@ | ||
| 1 | +{ | |
| 2 | + "source": "Jan Kristian Haugland, The minimum overlap problem revisited (2016), arXiv:1609.08000", | |
| 3 | + "note": "Historical reproduction. The table's decimal coefficients are represented exactly as integers over a common denominator; no coefficients are changed.", | |
| 4 | + "denominator": 10000000000000000, | |
| 5 | + "values": [ | |
| 6 | + 0, 0, 0, 0, 0, | |
| 7 | + 2938681556273, 5952882223921177, 7844530825484313, 8950034338013842, 597964076006748, | |
| 8 | + 189602838469592, 7420501628172980, 6444559588500921, 3549040817844764, 8762442385073478, | |
| 9 | + 5437907313675501, 2679640048997296, 8518954615823791, 5211171156914872, 10000000000000000, | |
| 10 | + 5506146790047043, 9007715390796991, 8229000691941086, 8879541710440111, 9315424878319221, | |
| 11 | + 10000000000000000, | |
| 12 | + 9315424878319221, 8879541710440111, 8229000691941086, 9007715390796991, 5506146790047043, | |
| 13 | + 10000000000000000, 5211171156914872, 8518954615823791, 2679640048997296, 5437907313675501, | |
| 14 | + 8762442385073478, 3549040817844764, 6444559588500921, 7420501628172980, 189602838469592, | |
| 15 | + 597964076006748, 8950034338013842, 7844530825484313, 5952882223921177, 2938681556273, | |
| 16 | + 0, 0, 0, 0, 0 | |
| 17 | + ] | |
| 18 | +} | |
+79 −0 routes/haugland-2016-reproduction/reproduce.py added View file
| @@ -0,0 +1,79 @@ | ||
| 1 | +"""从原文的十进制高度重建构造,并独立计算精确上界。""" | |
| 2 | + | |
| 3 | +import argparse | |
| 4 | +import json | |
| 5 | +from fractions import Fraction | |
| 6 | +from pathlib import Path | |
| 7 | + | |
| 8 | +# 原文「The best upper bound we have found ...」段的左半边和中心。 | |
| 9 | +# 原文的第一条区间覆盖了五格;中心格横跨 x=1,不重复。 | |
| 10 | +PAPER_LEFT_AND_CENTER = """ | |
| 11 | +0 0 0 0 0 | |
| 12 | +0.0002938681556273 0.5952882223921177 0.7844530825484313 | |
| 13 | +0.8950034338013842 0.0597964076006748 0.0189602838469592 | |
| 14 | +0.7420501628172980 0.6444559588500921 0.3549040817844764 | |
| 15 | +0.8762442385073478 0.5437907313675501 0.2679640048997296 | |
| 16 | +0.8518954615823791 0.5211171156914872 1 | |
| 17 | +0.5506146790047043 0.9007715390796991 0.8229000691941086 | |
| 18 | +0.8879541710440111 0.9315424878319221 1 | |
| 19 | +""" | |
| 20 | + | |
| 21 | + | |
| 22 | +def paper_heights(): | |
| 23 | + left = [Fraction(s) for s in PAPER_LEFT_AND_CENTER.split()] | |
| 24 | + return left + left[-2::-1] | |
| 25 | + | |
| 26 | + | |
| 27 | +def shifted_overlap(heights, m): | |
| 28 | + n = len(heights) | |
| 29 | + return Fraction(2, n) * sum( | |
| 30 | + height * (1 - heights[i + m]) | |
| 31 | + for i, height in enumerate(heights) | |
| 32 | + if 0 <= i + m < n | |
| 33 | + ) | |
| 34 | + | |
| 35 | + | |
| 36 | +def decimal_ceiling(value, digits=25): | |
| 37 | + scale = 10**digits | |
| 38 | + whole, remainder = divmod(value.numerator * scale, value.denominator) | |
| 39 | + whole += bool(remainder) | |
| 40 | + integer, decimal = divmod(whole, scale) | |
| 41 | + return f"{integer}.{decimal:0{digits}d}" | |
| 42 | + | |
| 43 | + | |
| 44 | +def main(): | |
| 45 | + parser = argparse.ArgumentParser(description=__doc__) | |
| 46 | + parser.add_argument("certificate", type=Path, nargs="?", default=Path(__file__).with_name("haugland_n51.json")) | |
| 47 | + args = parser.parse_args() | |
| 48 | + | |
| 49 | + cert = json.loads(args.certificate.read_text(encoding="utf-8")) | |
| 50 | + values = cert["values"] | |
| 51 | + denominator = cert["denominator"] | |
| 52 | + if type(denominator) is not int or denominator <= 0 or any(type(v) is not int for v in values): | |
| 53 | + raise SystemExit("证书不是整数分子和正整数分母的格式") | |
| 54 | + | |
| 55 | + expected = paper_heights() | |
| 56 | + n = len(expected) | |
| 57 | + heights = [Fraction(v, denominator) for v in values] | |
| 58 | + if n != 51 or len(heights) != n: | |
| 59 | + raise SystemExit(f"格数错误:论文 {n} 格,证书 {len(heights)} 格") | |
| 60 | + for i, (actual, target) in enumerate(zip(heights, expected)): | |
| 61 | + if actual != target: | |
| 62 | + raise SystemExit(f"第 {i} 格的证书值 {actual} 不等于预期值 {target}") | |
| 63 | + if sum(heights) != Fraction(n, 2) or not all(0 <= h <= 1 for h in heights): | |
| 64 | + raise SystemExit("证书不满足质量或高度约束") | |
| 65 | + | |
| 66 | + # 等距阶梯的重叠函数在相邻网格点之间线性,检查网格点即可。 | |
| 67 | + by_shift = {m: shifted_overlap(heights, m) for m in range(1 - n, n)} | |
| 68 | + bound = max(by_shift.values()) | |
| 69 | + if bound > Fraction("0.380927"): | |
| 70 | + raise SystemExit("上界超过 Issue #3 阈值") | |
| 71 | + lags = [m for m, score in by_shift.items() if score == bound] | |
| 72 | + print(f"n={n}; tested_lags={len(by_shift)}; height_sum={sum(heights)}") | |
| 73 | + print(f"mu <= {bound} (exact)") | |
| 74 | + print(f"mu <= {decimal_ceiling(bound)} (rounded up)") | |
| 75 | + print(f"argmax_lags={lags}; threshold_margin={decimal_ceiling(Fraction('0.380927') - bound)} (rounded up)") | |
| 76 | + | |
| 77 | + | |
| 78 | +if __name__ == "__main__": | |
| 79 | + main() | |