Kissing numbers
Improve the bounds on kissing numbers in dimensions up to 48, starting with dimension 5, where 40 ≤ τ(5) ≤ 44.

| 1 | #!/usr/bin/env python3 |
| 2 | """Checks that the candidates in a folder follow the submission format in README.md: file names, JSON shape, types, |
| 3 | lengths and ranges. It computes no inner products. |
| 4 | |
| 5 | usage: python3 tools/check_format.py routes/<branch> (or one .json file) |
| 6 | """ |
| 7 | import json |
| 8 | import pathlib |
| 9 | import sys |
| 10 | from fractions import Fraction |
| 11 | |
| 12 | DIMS = (5, 7, 9, 10) |
| 13 | MAX_VECTORS = 1000 |
| 14 | |
| 15 | |
| 16 | def errors(candidate): |
| 17 | d = candidate.get("d") |
| 18 | if type(d) is not int or d not in DIMS: |
| 19 | return [f'"d" must be {" or ".join(map(str, DIMS))}'] |
| 20 | vs = candidate.get("vectors") |
| 21 | if not isinstance(vs, list) or not 1 <= len(vs) <= MAX_VECTORS: |
| 22 | return [f'"vectors" must be a list of 1 to {MAX_VECTORS} vectors'] |
| 23 | out = [] |
| 24 | for i, v in enumerate(vs): |
| 25 | if not isinstance(v, list) or len(v) != d: |
| 26 | out.append(f"vector {i} is not a list of {d} entries") |
| 27 | continue |
| 28 | for e in v: |
| 29 | if isinstance(e, bool) or not isinstance(e, (int, str)): |
| 30 | out.append(f"vector {i}: entry {e!r} is not an integer or a string") |
| 31 | continue |
| 32 | try: |
| 33 | Fraction(e) |
| 34 | except (ValueError, ZeroDivisionError): |
| 35 | out.append(f"vector {i}: unreadable entry {e!r}") |
| 36 | return out |
| 37 | |
| 38 | |
| 39 | if len(sys.argv) != 2: |
| 40 | sys.exit(__doc__) |
| 41 | target = pathlib.Path(sys.argv[1]) |
| 42 | if target.is_file() and target.suffix != ".json": |
| 43 | sys.exit(f"{target}: candidates are .json files") |
| 44 | files = [target] if target.is_file() else sorted(target.rglob("*.json")) |
| 45 | found = bad = 0 |
| 46 | for path in files: |
| 47 | if path.stat().st_size > 1_000_000: |
| 48 | print(f"{path}: over 1 MB") |
| 49 | bad += 1 |
| 50 | continue |
| 51 | try: |
| 52 | candidate = json.loads(path.read_text()) |
| 53 | except Exception as exc: |
| 54 | print(f"{path}: not valid JSON ({exc})") |
| 55 | bad += 1 |
| 56 | continue |
| 57 | if not isinstance(candidate, dict) or "vectors" not in candidate: |
| 58 | print(f'{path}: not a candidate (no "vectors" key); ignored') |
| 59 | continue |
| 60 | found += 1 |
| 61 | problems = errors(candidate) |
| 62 | print(f"{path}: {'; '.join(problems[:5])}" if problems else f"{path}: ok (d={candidate['d']}, {len(candidate['vectors'])} vectors)") |
| 63 | bad += bool(problems) |
| 64 | print(f"{found} candidates, {bad} files with format errors") |
| 65 | sys.exit(1 if bad else 0) |