amphora's picture
v2: add 216 optimize tasks / 77 families (Tao constants, AlphaEvolve, Leaps in Bounds, FrontierShift, FrontierCO MDS, ALE-Bench, FrontierCS, EdgeBench)
ac7c4a9 verified
Raw History Blame Contribute Delete
1.11 kB
"""Thomson problem (AlphaEvolve problem 33): minimize the Coulomb energy of n points on the unit sphere S^2.
Same objective as the upstream get_score (thomson_problem.ipynb): vectors are projected onto the sphere and
E = sum_{i<j} 1/|p_i - p_j|. Changes: zero / non-finite vectors are rejected instead of being normalized to
NaN, and coincident points (distance < 1e-12) are rejected instead of being clamped to 1e-12.
"""
import numpy as np
from run import Invalid, float_matrix
def check(inst, ans):
n = inst["n"]
v = np.array(float_matrix(ans.get("vectors"), n, 3, "vectors"))
nr = np.linalg.norm(v, axis=1, keepdims=True)
if not np.all(np.isfinite(nr)) or np.any(nr < 1e-9) or np.any(nr > 1e9):
raise Invalid("each vector must have norm in [1e-9, 1e9]")
v = v / nr
d = np.sqrt(((v[:, None, :] - v[None, :, :]) ** 2).sum(-1))[np.triu_indices(n, 1)]
if d.min() < 1e-12:
raise Invalid("two points coincide")
e = float(np.sum(1.0 / d))
if not np.isfinite(e):
raise Invalid("non-finite energy")
return e, {"min_distance": float(d.min())}