#!/usr/bin/env python3 """Exact check of kissing configurations: nonzero vectors in R^d whose pairwise angles are all at least 60 degrees. Unit balls touching a central unit ball at the points x/|x| do not overlap exactly when every two distinct vectors satisfy <= |x| |y| / 2, that is, <= 0 or 4 ^2 <= |x|^2 |y|^2. A vector's entries are integers or rational numbers; each vector is scaled to integers by its own common denominator, which changes no angle. Integer arithmetic only. Python >= 3.9, standard library only. """ from fractions import Fraction from itertools import combinations from math import lcm from operator import mul # The record lower bounds on the kissing number in this tree's dimensions (Henry Cohn's table, October 2026). RECORD = {5: 40, 7: 126, 9: 306, 10: 510} MAX_VECTORS = 1000 class CandidateError(ValueError): pass def entry(value) -> Fraction: if isinstance(value, bool) or not isinstance(value, (int, str)): raise CandidateError(f'an entry must be an integer or a string such as "1/2", not {type(value).__name__}') try: return Fraction(value) except (ValueError, ZeroDivisionError): raise CandidateError(f"unreadable entry {value!r}") from None def vectors(candidate: dict, dims=tuple(RECORD)) -> tuple[int, list[list[int]]]: """The dimension and the vectors, each scaled to integers; raises CandidateError if the candidate is malformed.""" d = candidate.get("d") if type(d) is not int or d not in dims: raise CandidateError(f'"d" must be {" or ".join(map(str, dims))}') vs = candidate.get("vectors") if not isinstance(vs, list) or not 1 <= len(vs) <= MAX_VECTORS: raise CandidateError(f'"vectors" must be a list of 1 to {MAX_VECTORS} vectors') out = [] for i, v in enumerate(vs): if not isinstance(v, list) or len(v) != d: raise CandidateError(f"vector {i} is not a list of {d} entries") x = [entry(e) for e in v] q = lcm(*(e.denominator for e in x)) out.append([int(e * q) for e in x]) return d, out def verify(vs: list[list[int]]) -> None: """Raises CandidateError unless every vector is nonzero and every two are at least 60 degrees apart.""" norms = [sum(map(mul, x, x)) for x in vs] if 0 in norms: raise CandidateError(f"vector {norms.index(0)} is zero") for (i, x), (j, y) in combinations(enumerate(vs), 2): g = sum(map(mul, x, y)) if g > 0 and 4 * g * g > norms[i] * norms[j]: raise CandidateError(f"vectors {i} and {j} are less than 60 degrees apart")