"""Nine electrons on a sphere in their lowest-energy arrangement known, N = 9 being the smallest case with no proof. Computed here: Coulomb energy minimized by projected gradient descent from several seeded random starts (Python's random, seed 1); every start reaches the same energy, 25.7599865313, which is asserted so that a change shows. Drawn with its convex hull, the edges in front solid and those behind dashed, the electrons larger and darker the nearer they are. """ import math import random from itertools import combinations from pathlib import Path import kit N = 9 sub = lambda a, b: [x - y for x, y in zip(a, b)] dot = lambda u, v: sum(x * y for x, y in zip(u, v)) cross = lambda u, v: [u[1] * v[2] - u[2] * v[1], u[2] * v[0] - u[0] * v[2], u[0] * v[1] - u[1] * v[0]] unit = lambda u: [c / math.hypot(*u) for c in u] def energy(P): return sum(1 / math.dist(p, q) for p, q in combinations(P, 2)) def relax(P, steps=4000): """Projected gradient descent with an adaptive step; returns the points, their energy and the tangential force.""" E, h = energy(P), 0.05 for _ in range(steps): F = [[0.0] * 3 for _ in P] for i, j in combinations(range(len(P)), 2): d = sub(P[i], P[j]); r3 = math.hypot(*d) ** 3 for k in range(3): F[i][k] += d[k] / r3; F[j][k] -= d[k] / r3 T = [sub(f, [dot(p, f) * c for c in p]) for p, f in zip(P, F)] g = math.sqrt(sum(c * c for t in T for c in t)) if g < 1e-11: break Q = [unit([a + h * b for a, b in zip(p, t)]) for p, t in zip(P, T)] E2 = energy(Q) if E2 < E: P, E, h = Q, E2, h * 1.2 else: h *= 0.5 return P, E, g rnd = random.Random(1) runs = [relax([unit([rnd.gauss(0, 1) for _ in range(3)]) for _ in range(N)]) for _ in range(4)] P, E, g = min(runs, key=lambda r: r[1]) assert all(abs(r[1] - E) < 1e-9 for r in runs) and g < 1e-6, [r[1] for r in runs] assert f'{E:.10f}' == '25.7599865313', E # the convex hull, by brute force: a triple is a face when every other point lies on one side of its plane faces = [] for t in combinations(range(N), 3): n = cross(sub(P[t[1]], P[t[0]]), sub(P[t[2]], P[t[0]])) side = [dot(sub(P[m], P[t[0]]), n) for m in range(N) if m not in t] if all(s < 0 for s in side) or all(s > 0 for s in side): faces.append((t, n if all(s < 0 for s in side) else [-c for c in n])) # outward normal assert len(faces) == 2 * N - 4 def view(d, up=(0, 1, 0)): d = unit(d); e1 = unit(cross(up, d)); e2 = cross(d, e1) return lambda p: [dot(p, e) for e in (e1, e2, d)] # look from the direction (on a 6-degree grid) that spreads the nine points farthest apart on the page dirs = [(math.sin(a) * math.cos(b), math.sin(a) * math.sin(b), math.cos(a)) for a in [i * math.pi / 30 for i in range(1, 30)] for b in [j * math.pi / 30 for j in range(60)]] see = view(max(dirs, key=lambda d: min(math.dist(view(d)(p)[:2], view(d)(q)[:2]) for p, q in combinations(P, 2)))) Q = [see(p) for p in P] front = {} for t, n in faces: for a, b in combinations(sorted(t), 2): front[a, b] = front.get((a, b), False) or see(n)[2] > 0 assert len(front) == 3 * N - 6 R, CX, CY = 118, kit.W / 2, 134 at = lambda q: (CX + q[0] * R, CY - q[1] * R) body = ('' '') body += kit.circle(CX, CY, R, 'f', ' style="fill:url(#sphere)"') + kit.circle(CX, CY, R, 'faint-s', ' stroke-width="2"') body += ''.join(kit.line(*at(Q[a]), *at(Q[b]), 'faint-s', 2, ' stroke-dasharray="4 5"') for (a, b), f in front.items() if not f) body += ''.join(kit.line(*at(Q[a]), *at(Q[b]), 'ink2-s', 2.4) for (a, b), f in front.items() if f) for q in sorted(Q, key=lambda q: q[2]): near = (q[2] + 1) / 2 r = 6 + 4.5 * near body += kit.circle(*at(q), r, 'ink', ' style="fill:var(--bg)"') + kit.circle(*at(q), r, 'f ring', f' fill-opacity="{0.4 + 0.6 * near:.2f}"') kit.write(__file__, 'mathematics', body, label='N = 9 electrons ยท lowest energy known, not proved')