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

| 1 | """Twelve unit spheres touching a central one in three dimensions, tau(3) = 12, drawn with depth. |
| 2 | |
| 3 | The twelve centres are the vertices of a regular icosahedron at distance 2 from the centre: every two of them are at |
| 4 | least 60 degrees apart (inner product of the unit vectors 1/sqrt(5) <= 1/2), so the spheres touch the middle one and do |
| 5 | not overlap each other. Checked below, then drawn back to front in a slight perspective. |
| 6 | """ |
| 7 | import math |
| 8 | from itertools import combinations |
| 9 | from pathlib import Path |
| 10 | |
| 11 | import kit |
| 12 | |
| 13 | phi = (1 + 5 ** 0.5) / 2 |
| 14 | V = [] |
| 15 | for a in (-1, 1): |
| 16 | for b in (-phi, phi): |
| 17 | V += [(0, a, b), (a, b, 0), (b, 0, a)] |
| 18 | V = [tuple(c / math.hypot(*v) for c in v) for v in V] |
| 19 | assert len(V) == 12 and len(set(V)) == 12 |
| 20 | assert all(sum(p * q for p, q in zip(u, v)) <= 0.5 + 1e-12 for u, v in combinations(V, 2)) # the kissing condition |
| 21 | |
| 22 | |
| 23 | def view(d, up=(0, 1, 0)): |
| 24 | """Coordinates seen looking along -d: (right, up, towards the viewer).""" |
| 25 | cross = lambda u, v: (u[1] * v[2] - u[2] * v[1], u[2] * v[0] - u[0] * v[2], u[0] * v[1] - u[1] * v[0]) |
| 26 | unit = lambda u: tuple(c / math.hypot(*u) for c in u) |
| 27 | d = unit(d); e1 = unit(cross(up, d)); e2 = cross(d, e1) |
| 28 | return lambda p: tuple(sum(a * b for a, b in zip(p, e)) for e in (e1, e2, d)) |
| 29 | |
| 30 | |
| 31 | # nearly along a 3-fold axis: three balls in front, six around the rim, three hidden behind the middle one |
| 32 | see = view((1, 1.08, 1.18)) |
| 33 | R, CX, CY, CAM = 44, kit.W / 2, 132, 16 # ball radius in px, centre of the drawing, camera distance in radii |
| 34 | spheres = [((0, 0, 0), True)] + [(tuple(2 * c for c in see(v)), False) for v in V] |
| 35 | spheres.sort(key=lambda s: s[0][2]) # back to front: the camera looks down -z from z = CAM |
| 36 | |
| 37 | # shading, lit from the top left in both themes: the highlight is the light end of the ramp |
| 38 | SHADE = ('<style>.hi-f,.hi-i{stop-color:var(--bg)}.lo-f{stop-color:var(--f);stop-opacity:.6}.lo-i{stop-color:var(--ink);stop-opacity:.75}' |
| 39 | '@media (prefers-color-scheme: dark){.hi-f{stop-color:var(--f);stop-opacity:.6}.lo-f{stop-opacity:.14}' |
| 40 | '.hi-i{stop-color:var(--ink);stop-opacity:.6}.lo-i{stop-opacity:.1}}</style>' |
| 41 | '<defs><radialGradient id="ball-f" cx=".36" cy=".32" r=".78"><stop offset="0" class="hi-f"/><stop offset="1" class="lo-f"/></radialGradient>' |
| 42 | '<radialGradient id="ball-i" cx=".36" cy=".32" r=".78"><stop offset="0" class="hi-i"/><stop offset="1" class="lo-i"/></radialGradient></defs>') |
| 43 | body = SHADE |
| 44 | for (x, y, z), centre in spheres: |
| 45 | k = CAM / (CAM - z) # perspective |
| 46 | px, py, r = CX + x * R * k, CY - y * R * k, R * k |
| 47 | if centre: # the fixed ball, solid |
| 48 | body += kit.circle(px, py, r, 'ink', ' style="fill:var(--bg)"') + kit.circle(px, py, r, 'ink', ' style="fill:url(#ball-i)"') |
| 49 | body += kit.circle(px, py, r, 'ink2-s', ' stroke-width="2"') |
| 50 | elif z < 0.6: # around the rim and behind: solid, nearer ones hiding farther ones |
| 51 | body += kit.circle(px, py, r, 'ink', ' style="fill:var(--bg)"') + kit.circle(px, py, r, 'f', ' style="fill:url(#ball-f)"') |
| 52 | body += kit.circle(px, py, r, 'f-s', ' stroke-width="2" stroke-opacity=".6"') |
| 53 | else: # the three in front: dashed outlines, so the middle ball stays in view |
| 54 | body += kit.circle(px, py, r, 'f-s', ' stroke-width="2.4" stroke-dasharray="6 5"') |
| 55 | kit.write(__file__, 'mathematics', body, label='τ(3) = 12 · twelve spheres touch the middle one') |