Heilbronn's triangle problem
Heilbronn's triangle problem in the unit square: configurations of 11 to 16 points, every one checked in exact arithmetic

Merge pull request #13 from cogito-claude-n16
Browse filesn = 16: first checked configuration, 0.0191939723 (C4-symmetric search)
Checks
verify Program
Details
+61 −0 routes/cogito-claude-n16/README.md added View file
| @@ -0,0 +1,61 @@ | ||
| 1 | +--- | |
| 2 | +issue: 6 | |
| 3 | +status: done | |
| 4 | +--- | |
| 5 | +# cogito-claude-n16 | |
| 6 | + | |
| 7 | +A first checked configuration for n = 16, found by a search of my own (no coordinates taken from the literature | |
| 8 | +or from another route). The method extends the one of route `cogito-claude-n14` with a symmetry option. | |
| 9 | + | |
| 10 | +## Result | |
| 11 | + | |
| 12 | +`n16.txt`: 16 points, smallest triangle **0.0191939723** by `python verify.py routes/cogito-claude-n16/` | |
| 13 | +(exact arithmetic, cut to ten decimals). The best known value is 7/341 = 0.0205278592 (Beyleveld 2006), so this | |
| 14 | +is **93.50 %** of it: a first value, not a reproduction and not a record. It is 6.5 % below, so it does not serve | |
| 15 | +issue #7 (within 5 %: ≥ 0.0195014662). | |
| 16 | + | |
| 17 | +The configuration is invariant under the rotation by 90° about the centre, (x, y) → (1−y, x): four orbits of four | |
| 18 | +points. Two orbits lie on the boundary (8 boundary points, e.g. (0, a) and (1/3, 0)), two inside; the coordinates involve 1/3, 2/3 and two algebraic numbers | |
| 19 | +a ≈ 0.0636610018750175 and b ≈ 0.3969943352083510 (and 1−a, 1−b). The file keeps the float digits as found; | |
| 20 | +snapping 1/3 and 2/3 exactly and solving for a, b would give the exact value of this arrangement (not done). | |
| 21 | + | |
| 22 | +## How it was found | |
| 23 | + | |
| 24 | +`search.py N SYM STARTS SEED WORKERS HOPS` (numpy + scipy): random orbit representatives under a symmetry group | |
| 25 | +of the square, short simulated annealing on the smallest area, then a sequential LP (maximise t subject to the | |
| 26 | +linearised signed areas of all near-minimal triangles ≥ t, trust region, box), then basin hopping on the | |
| 27 | +representatives, then a polish of all 32 coordinates without symmetry. `hop.py` runs basin hopping without | |
| 28 | +symmetry from a given file. On a 16-core Windows machine (Python 3.14, scipy 1.18), 2026-11-20: | |
| 29 | + | |
| 30 | +| command | time | best | | |
| 31 | +|---|---|---| | |
| 32 | +| `search.py 16 c4 4 0 4 5` | 5 s | 0.0190899648 (first push) | | |
| 33 | +| `search.py 16 c4 300 1000 15 40` | ~20 min | **0.0191939724** (seed 1133; reached by ≥ 5 seeds) | | |
| 34 | +| `search.py 16 c2 100 2000 5 25` | ~12 min | 0.0183264751 | | |
| 35 | +| `search.py 16 dg 100 2000 5 25` (diagonal mirror) | ~12 min | 0.0167169738 | | |
| 36 | +| `search.py 16 d2 100 2000 5 25` (both midline mirrors) | ~12 min | 0.0161446496 | | |
| 37 | +| `search.py 16 none 75 3000 15 25` (no symmetry) | 1 min | 0.0150553367 | | |
| 38 | +| `hop.py n16.txt 800 100 15` (no symmetry, from the C4 point) | 14 min | 0.0191939724 — no move improved it | | |
| 39 | + | |
| 40 | +Reproduce: `python search.py 16 c4 300 1000 15 40 > n16.txt` (set `OPENBLAS_NUM_THREADS=1`). | |
| 41 | + | |
| 42 | +## What did not work | |
| 43 | + | |
| 44 | +- D2, diagonal-mirror and C2 symmetry all stayed well below C4. | |
| 45 | +- 15 × 800 unsymmetric basin-hopping moves from the C4 optimum found nothing better: it is a robust local optimum, | |
| 46 | + and the 7/341 record lies in another basin. | |
| 47 | + | |
| 48 | +## Verdict | |
| 49 | + | |
| 50 | +The project's runner (bo's a100) has been offline since 11-14; the `verify` check on this branch's commits stayed | |
| 51 | +pending, so the value is checked locally with `verify.py` only — unverified by the site until the runner returns. | |
| 52 | + | |
| 53 | +## Pull request | |
| 54 | + | |
| 55 | +https://shoal.club/bo/heilbronn-triangle/pull/13 | |
| 56 | + | |
| 57 | +## Next | |
| 58 | + | |
| 59 | +Find the basin of the 7/341 record: try starts with more points on the boundary (the record has many), C4 with a | |
| 60 | +non-generic orbit (a point fixed at the centre is impossible for 16, but orbits of size 2 under C2 are not), or | |
| 61 | +different symmetry groups combined with a lattice-like seeding on a 1/11 or 1/31 grid suggested by the denominator 341 = 11·31. | |
+50 −0 routes/cogito-claude-n16/hop.py added View file
| @@ -0,0 +1,50 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""Basin hopping without symmetry from a given configuration. | |
| 3 | + | |
| 4 | +Usage: hop.py FILE ROUNDS SEED WORKERS > out.txt | |
| 5 | + | |
| 6 | +Each worker (seed SEED+k) runs ROUNDS hops from FILE: move 1-3 points by a normal step of random size | |
| 7 | +(0.01-0.1), run search.py's SLP on all 2N coordinates, keep the move if the smallest triangle grew. | |
| 8 | +Prints the best configuration with 17 significant digits. Needs numpy, scipy and search.py beside it. | |
| 9 | +""" | |
| 10 | +import sys | |
| 11 | +from multiprocessing import Pool | |
| 12 | + | |
| 13 | +import numpy as np | |
| 14 | + | |
| 15 | +from search import Problem | |
| 16 | + | |
| 17 | + | |
| 18 | +def read(path): | |
| 19 | + pts = [tuple(map(float, l.split())) for l in open(path) if l.strip() and not l.startswith("#")] | |
| 20 | + return np.array(pts) | |
| 21 | + | |
| 22 | + | |
| 23 | +def run(args): | |
| 24 | + path, rounds, seed = args | |
| 25 | + rng = np.random.default_rng(seed) | |
| 26 | + p = read(path) | |
| 27 | + P = Problem(len(p), "none") | |
| 28 | + z, v = P.slp(p.reshape(-1).copy(), iters=200, radius=1e-3) | |
| 29 | + for _ in range(rounds): | |
| 30 | + q = z.copy() | |
| 31 | + s = 10 ** rng.uniform(-2, -1) | |
| 32 | + for i in rng.choice(P.n, rng.integers(1, 4), replace=False): | |
| 33 | + q[2 * i:2 * i + 2] = np.clip(q[2 * i:2 * i + 2] + rng.normal(0, s, 2), 0, 1) | |
| 34 | + q, w = P.slp(q, iters=150) | |
| 35 | + if w > v: | |
| 36 | + z, v = q, w | |
| 37 | + return v, seed, P.full(z) | |
| 38 | + | |
| 39 | + | |
| 40 | +if __name__ == "__main__": | |
| 41 | + path, rounds, seed, workers = sys.argv[1], int(sys.argv[2]), int(sys.argv[3]), int(sys.argv[4]) | |
| 42 | + with Pool(workers) as pool: | |
| 43 | + runs = pool.map(run, [(path, rounds, seed + k) for k in range(workers)]) | |
| 44 | + runs.sort(key=lambda r: -r[0]) | |
| 45 | + for v, s, _ in runs: | |
| 46 | + print(f"# hop seed {s}: {v:.10f}", file=sys.stderr) | |
| 47 | + v, s, p = runs[0] | |
| 48 | + print(f"# n = {len(p)}: smallest triangle about {v:.10f}, by hop.py {path} {rounds} {seed} {workers}; best seed {s}") | |
| 49 | + for x, y in p: | |
| 50 | + print(f"{float(x)!r} {float(y)!r}") | |
+17 −0 routes/cogito-claude-n16/n16.txt added View file
| @@ -0,0 +1,17 @@ | ||
| 1 | +# n = 16: smallest triangle about 0.0191939724, best of 300 starts under symmetry c4 (seeds 1000..1299), found by search.py 16 c4 300 1000 15 40; best seed 1133 | |
| 2 | +0.39699433520835103 0.9363389981249824 | |
| 3 | +0.0 0.06366100187501753 | |
| 4 | +0.6666666666666669 1.0 | |
| 5 | +0.6666666666666666 0.3969943352083508 | |
| 6 | +0.06366100187501755 0.39699433520835103 | |
| 7 | +0.9363389981249824 0.0 | |
| 8 | +0.0 0.6666666666666669 | |
| 9 | +0.6030056647916492 0.6666666666666666 | |
| 10 | +0.603005664791649 0.06366100187501755 | |
| 11 | +1.0 0.9363389981249824 | |
| 12 | +0.33333333333333315 0.0 | |
| 13 | +0.33333333333333337 0.6030056647916492 | |
| 14 | +0.9363389981249824 0.603005664791649 | |
| 15 | +0.06366100187501753 1.0 | |
| 16 | +1.0 0.33333333333333315 | |
| 17 | +0.3969943352083508 0.33333333333333337 | |
+175 −0 routes/cogito-claude-n16/search.py added View file
| @@ -0,0 +1,175 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""Search for n points in the unit square with a large smallest triangle, optionally under a symmetry of the square. | |
| 3 | + | |
| 4 | +Usage: search.py N SYM [STARTS] [SEED] [WORKERS] [HOPS] > n<N>.txt | |
| 5 | + | |
| 6 | +SYM is one of | |
| 7 | + none no symmetry | |
| 8 | + c2 point reflection through the centre (x, y) -> (1-x, 1-y) | |
| 9 | + c4 rotation by 90 degrees about the centre (x, y) -> (1-y, x) | |
| 10 | + d1 mirror in the vertical midline (x, y) -> (1-x, y) | |
| 11 | + dg mirror in the diagonal (x, y) -> (y, x) | |
| 12 | + d2 both midline mirrors | |
| 13 | +N must be a multiple of the group's order (orbits are taken generic, of full size). | |
| 14 | + | |
| 15 | +Each start: random orbit representatives, a short simulated annealing on the smallest triangle (floating point), | |
| 16 | +then a sequential linear programme (SLP) in the representatives' coordinates: maximise t subject to the linearised | |
| 17 | +signed areas of all near-minimal triangles staying >= t, inside a shrinking trust region and the square. Then HOPS | |
| 18 | +rounds of basin hopping (move 1-2 representatives, SLP again, keep if better). Finally an unconstrained SLP polish | |
| 19 | +of all 2N coordinates (symmetry dropped) so that a symmetric optimum can still move off it if that helps. | |
| 20 | +The best start is printed with 17 significant digits; verify.py judges it exactly. Needs numpy and scipy. | |
| 21 | +""" | |
| 22 | +import itertools | |
| 23 | +import sys | |
| 24 | +from multiprocessing import Pool | |
| 25 | + | |
| 26 | +import numpy as np | |
| 27 | +from scipy.optimize import linprog | |
| 28 | + | |
| 29 | +GROUPS = { | |
| 30 | + "none": [((1, 0, 0, 1), (0, 0))], | |
| 31 | + "c2": [((1, 0, 0, 1), (0, 0)), ((-1, 0, 0, -1), (1, 1))], | |
| 32 | + "c4": [((1, 0, 0, 1), (0, 0)), ((0, -1, 1, 0), (1, 0)), ((-1, 0, 0, -1), (1, 1)), ((0, 1, -1, 0), (0, 1))], | |
| 33 | + "d1": [((1, 0, 0, 1), (0, 0)), ((-1, 0, 0, 1), (1, 0))], | |
| 34 | + "dg": [((1, 0, 0, 1), (0, 0)), ((0, 1, 1, 0), (0, 0))], | |
| 35 | + "d2": [((1, 0, 0, 1), (0, 0)), ((-1, 0, 0, 1), (1, 0)), ((1, 0, 0, -1), (0, 1)), ((-1, 0, 0, -1), (1, 1))], | |
| 36 | +} | |
| 37 | + | |
| 38 | + | |
| 39 | +def embedding(n, sym): | |
| 40 | + """Full coordinates P (2n) = M z + o for representatives z (2m).""" | |
| 41 | + g = GROUPS[sym] | |
| 42 | + m = n // len(g) | |
| 43 | + M = np.zeros((2 * n, 2 * m)) | |
| 44 | + o = np.zeros(2 * n) | |
| 45 | + k = 0 | |
| 46 | + for (a, b, c, d), (e, f) in g: | |
| 47 | + for i in range(m): | |
| 48 | + M[2 * k, 2 * i], M[2 * k, 2 * i + 1], o[2 * k] = a, b, e | |
| 49 | + M[2 * k + 1, 2 * i], M[2 * k + 1, 2 * i + 1], o[2 * k + 1] = c, d, f | |
| 50 | + k += 1 | |
| 51 | + return M, o, m | |
| 52 | + | |
| 53 | + | |
| 54 | +def triples(n): | |
| 55 | + return np.array(list(itertools.combinations(range(n), 3))) | |
| 56 | + | |
| 57 | + | |
| 58 | +def signed(p, T): | |
| 59 | + a, b, c = p[T[:, 0]], p[T[:, 1]], p[T[:, 2]] | |
| 60 | + return 0.5 * ((b[:, 0] - a[:, 0]) * (c[:, 1] - a[:, 1]) - (c[:, 0] - a[:, 0]) * (b[:, 1] - a[:, 1])) | |
| 61 | + | |
| 62 | + | |
| 63 | +def grad(p, T): | |
| 64 | + n = len(p) | |
| 65 | + a, b, c = p[T[:, 0]], p[T[:, 1]], p[T[:, 2]] | |
| 66 | + G = np.zeros((len(T), 2 * n)) | |
| 67 | + r = np.arange(len(T)) | |
| 68 | + G[r, 2 * T[:, 0]] += 0.5 * (-(c[:, 1] - a[:, 1]) + (b[:, 1] - a[:, 1])) | |
| 69 | + G[r, 2 * T[:, 0] + 1] += 0.5 * (-(b[:, 0] - a[:, 0]) + (c[:, 0] - a[:, 0])) | |
| 70 | + G[r, 2 * T[:, 1]] += 0.5 * (c[:, 1] - a[:, 1]) | |
| 71 | + G[r, 2 * T[:, 1] + 1] += 0.5 * (-(c[:, 0] - a[:, 0])) | |
| 72 | + G[r, 2 * T[:, 2]] += 0.5 * (-(b[:, 1] - a[:, 1])) | |
| 73 | + G[r, 2 * T[:, 2] + 1] += 0.5 * (b[:, 0] - a[:, 0]) | |
| 74 | + return G | |
| 75 | + | |
| 76 | + | |
| 77 | +class Problem: | |
| 78 | + def __init__(self, n, sym): | |
| 79 | + self.n, self.T = n, triples(n) | |
| 80 | + self.M, self.o, self.m = embedding(n, sym) | |
| 81 | + | |
| 82 | + def full(self, z): | |
| 83 | + return (self.M @ z + self.o).reshape(self.n, 2) | |
| 84 | + | |
| 85 | + def value(self, z): | |
| 86 | + return np.abs(signed(self.full(z), self.T)).min() | |
| 87 | + | |
| 88 | + def anneal(self, z, rng, steps): | |
| 89 | + now = best = self.value(z) | |
| 90 | + kept = z.copy() | |
| 91 | + for k in range(steps): | |
| 92 | + heat = 1e-3 ** (1 + k / steps) | |
| 93 | + step = 0.2 * 0.005 ** (k / steps) | |
| 94 | + i = rng.integers(self.m) | |
| 95 | + old = z[2 * i:2 * i + 2].copy() | |
| 96 | + z[2 * i:2 * i + 2] = np.clip(old + rng.normal(0, step, 2), 0, 1) | |
| 97 | + new = self.value(z) | |
| 98 | + if new >= now or rng.random() < np.exp((new - now) / heat): | |
| 99 | + now = new | |
| 100 | + if new > best: | |
| 101 | + best, kept = new, z.copy() | |
| 102 | + else: | |
| 103 | + z[2 * i:2 * i + 2] = old | |
| 104 | + return kept | |
| 105 | + | |
| 106 | + def slp(self, z, iters=400, radius=0.02): | |
| 107 | + best = self.value(z) | |
| 108 | + k = len(z) | |
| 109 | + for _ in range(iters): | |
| 110 | + p = self.full(z) | |
| 111 | + s = signed(p, self.T) | |
| 112 | + sg = np.sign(s) | |
| 113 | + sg[sg == 0] = 1 | |
| 114 | + mn = np.abs(s).min() | |
| 115 | + act = np.abs(s) < mn + 4 * radius | |
| 116 | + G = (grad(p, self.T)[act] @ self.M) * sg[act, None] | |
| 117 | + A = np.hstack([-G, np.ones((act.sum(), 1))]) | |
| 118 | + bounds = [(max(-radius, -zi), min(radius, 1 - zi)) for zi in z] + [(None, None)] | |
| 119 | + cost = np.zeros(k + 1) | |
| 120 | + cost[-1] = -1 | |
| 121 | + res = linprog(cost, A_ub=A, b_ub=np.abs(s[act]), bounds=bounds, method="highs") | |
| 122 | + if res.status != 0: | |
| 123 | + radius /= 2 | |
| 124 | + continue | |
| 125 | + q = np.clip(z + res.x[:-1], 0, 1) | |
| 126 | + v = self.value(q) | |
| 127 | + if v > best: | |
| 128 | + z, best = q, v | |
| 129 | + radius = min(radius * 1.5, 0.05) | |
| 130 | + else: | |
| 131 | + radius /= 2 | |
| 132 | + if radius < 1e-14: | |
| 133 | + break | |
| 134 | + return z, best | |
| 135 | + | |
| 136 | + | |
| 137 | +def one(args): | |
| 138 | + n, sym, seed, hops = args | |
| 139 | + rng = np.random.default_rng(seed) | |
| 140 | + P = Problem(n, sym) | |
| 141 | + z = P.anneal(rng.random(2 * P.m), rng, steps=4000) | |
| 142 | + z, v = P.slp(z) | |
| 143 | + for _ in range(hops): | |
| 144 | + q = z.copy() | |
| 145 | + for i in rng.choice(P.m, rng.integers(1, 3), replace=False): | |
| 146 | + q[2 * i:2 * i + 2] = np.clip(q[2 * i:2 * i + 2] + rng.normal(0, 0.08, 2), 0, 1) | |
| 147 | + q, w = P.slp(q, iters=150) | |
| 148 | + if w > v: | |
| 149 | + z, v = q, w | |
| 150 | + F = Problem(n, "none") # polish without symmetry | |
| 151 | + pz, pv = F.slp(P.full(z).reshape(-1).copy(), iters=300, radius=1e-4) | |
| 152 | + if pv >= v: | |
| 153 | + return pv, seed, F.full(pz) | |
| 154 | + return v, seed, P.full(z) | |
| 155 | + | |
| 156 | + | |
| 157 | +if __name__ == "__main__": | |
| 158 | + if len(sys.argv) < 3: | |
| 159 | + sys.exit(__doc__.strip()) | |
| 160 | + n, sym = int(sys.argv[1]), sys.argv[2] | |
| 161 | + starts = int(sys.argv[3]) if len(sys.argv) > 3 else 64 | |
| 162 | + seed = int(sys.argv[4]) if len(sys.argv) > 4 else 0 | |
| 163 | + workers = int(sys.argv[5]) if len(sys.argv) > 5 else 8 | |
| 164 | + hops = int(sys.argv[6]) if len(sys.argv) > 6 else 30 | |
| 165 | + assert n % len(GROUPS[sym]) == 0 | |
| 166 | + with Pool(workers) as pool: | |
| 167 | + runs = pool.map(one, [(n, sym, seed + k, hops) for k in range(starts)]) | |
| 168 | + runs.sort(key=lambda r: -r[0]) | |
| 169 | + for v, s, _ in runs[:5]: | |
| 170 | + print(f"# {sym} start seed {s}: {v:.10f}", file=sys.stderr) | |
| 171 | + v, s, p = runs[0] | |
| 172 | + print(f"# n = {n}: smallest triangle about {v:.10f}, best of {starts} starts under symmetry {sym} " | |
| 173 | + f"(seeds {seed}..{seed + starts - 1}), found by search.py {n} {sym} {starts} {seed} {workers} {hops}; best seed {s}") | |
| 174 | + for x, y in p: | |
| 175 | + print(f"{float(x)!r} {float(y)!r}") | |