#!/usr/bin/env python3 """ Validator for problem 063: Kissing Number in Dimension 6 The kissing number τ₆ is the maximum number of non-overlapping unit spheres that can touch a central unit sphere in 6 dimensions. Known bounds: 72 ≤ τ₆ ≤ 77 A valid kissing configuration is a set of unit vectors in R⁶ (contact points on the central sphere) such that the Euclidean distance between any two contact points is at least 1. Equivalently, the dot product between any two distinct unit vectors is at most 1/2 (angular separation ≥ 60°). This validator checks that: 1. All points lie on the unit sphere S⁵ (‖x‖ = 1) 2. All pairwise contact-point distances are ≥ 1 (dot products ≤ 1/2) 3. No two points are identical (deduplication) 4. Reports the number of valid contact points Expected input format: {"points": [[x₁, …, x₆], …]} each point in R⁶ or [[x₁, …, x₆], …] """ import argparse from typing import Any import numpy as np from . import ValidationResult, load_solution, output_result, success, failure DIMENSION = 6 # Contact points on the unit sphere must have pairwise distance ≥ 1, # equivalently pairwise dot product ≤ 1/2. # See validate_049_kissing_number_dim5.py for the derivation. MIN_CONTACT_DISTANCE = 1.0 TOLERANCE = 1e-9 def validate(solution: Any) -> ValidationResult: """ Validate a kissing configuration in dimension 6. Args: solution: Dict with 'points' key or list of points Returns: ValidationResult with point count and minimum distance """ # --- Parse input --- try: if isinstance(solution, dict) and 'points' in solution: points_data = solution['points'] elif isinstance(solution, list): points_data = solution else: return failure("Invalid format: expected dict with 'points' or list of points") points = np.array(points_data, dtype=np.float64) except (ValueError, TypeError) as e: return failure(f"Failed to parse points: {e}") if points.ndim != 2: return failure(f"Points must be 2D array, got {points.ndim}D") n, d = points.shape if d != DIMENSION: return failure(f"Points must be in R^{DIMENSION}, got dimension {d}") if n == 0: return failure("No points provided") # --- Check all points are on the unit sphere --- norms = np.linalg.norm(points, axis=1) off_sphere = np.abs(norms - 1.0) > TOLERANCE if np.any(off_sphere): worst_idx = int(np.argmax(np.abs(norms - 1.0))) return failure( f"Point {worst_idx} not on unit sphere: |x| = {norms[worst_idx]:.12f}", off_sphere_count=int(np.sum(off_sphere)) ) # --- Deduplicate: remove points that are identical up to tolerance --- unique_mask = np.ones(n, dtype=bool) for i in range(n): if not unique_mask[i]: continue for j in range(i + 1, n): if not unique_mask[j]: continue if np.linalg.norm(points[i] - points[j]) < TOLERANCE: unique_mask[j] = False n_unique = int(np.sum(unique_mask)) if n_unique < n: points = points[unique_mask] n = n_unique # --- Check pairwise distances ≥ 1 (equivalently, dot products ≤ 0.5) --- gram = points @ points.T min_dist = float('inf') min_pair = (0, 0) max_dot = -float('inf') max_dot_pair = (0, 0) for i in range(n): for j in range(i + 1, n): dot_ij = gram[i, j] if dot_ij > max_dot: max_dot = dot_ij max_dot_pair = (i, j) dist_ij = np.sqrt(max(2.0 - 2.0 * dot_ij, 0.0)) if dist_ij < min_dist: min_dist = dist_ij min_pair = (i, j) if max_dot > 0.5 + TOLERANCE: return failure( f"Points {max_dot_pair[0]} and {max_dot_pair[1]} violate non-overlap: " f"dot product = {max_dot:.12f} > 0.5 " f"(distance = {min_dist:.12f} < 1)", min_distance=min_dist, max_dot_product=max_dot, violating_pair=list(max_dot_pair) ) return success( f"Valid kissing configuration in R^{DIMENSION}: {n} points, " f"min distance = {min_dist:.10f}, max dot product = {max_dot:.10f}", dimension=DIMENSION, num_points=n, min_distance=min_dist, max_dot_product=max_dot ) def main(): parser = argparse.ArgumentParser(description='Validate kissing configuration in dimension 6') parser.add_argument('solution', help='Solution as JSON string or path to JSON file') parser.add_argument('--verbose', '-v', action='store_true', help='Verbose output') args = parser.parse_args() solution = load_solution(args.solution) result = validate(solution) output_result(result) if __name__ == '__main__': main()