"""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 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())}