"""The upper bound chi <= 7: the plane tiled by regular hexagons of diameter slightly less than 1, in seven colours. Hexagon (q, r) in axial coordinates gets colour (q + 3r) mod 7, so a hexagon and its six neighbours carry all seven colours. Two points of one hexagon are less than 1 apart, and two hexagons of one colour are more than 1 apart (checked below), so no two points at distance 1 share a colour. Drawn: one colour class in the field colour, the other six in greys, and the circle of radius 1 around the middle hexagon's centre, which meets only other colours. """ import math from itertools import product from pathlib import Path import kit D = 0.98 # hexagon diameter, in units of the forbidden distance 1 colour = lambda q, r: (q + 3 * r) % 7 NEIGHBOURS = [(1, 0), (-1, 0), (0, 1), (0, -1), (1, -1), (-1, 1)] def centre(q, r, rho): return rho * math.sqrt(3) * (q + r / 2), rho * 1.5 * r def corners(x, y, rho): return [(x + rho * math.cos(math.pi / 6 + k * math.pi / 3), y + rho * math.sin(math.pi / 6 + k * math.pi / 3)) for k in range(6)] def gap(P, Q): """Distance between two disjoint convex polygons: the smallest vertex-to-edge distance either way.""" def seg(p, a, b): t = max(0, min(1, ((p[0] - a[0]) * (b[0] - a[0]) + (p[1] - a[1]) * (b[1] - a[1])) / math.dist(a, b) ** 2)) return math.dist(p, (a[0] + t * (b[0] - a[0]), a[1] + t * (b[1] - a[1]))) return min(seg(p, B[i], B[i - 1]) for A, B in ((P, Q), (Q, P)) for p in A for i in range(len(B))) # the colouring is proper: neighbours differ, a hexagon is under 1 across, same-coloured hexagons are over 1 apart assert all(colour(q, r) != colour(q + a, r + b) for q, r in product(range(-7, 8), repeat=2) for a, b in NEIGHBOURS) assert D < 1 home = corners(0, 0, D / 2) same = [corners(*centre(q, r, D / 2), D / 2) for q, r in product(range(-7, 8), repeat=2) if (q, r) != (0, 0) and colour(q, r) == 0] assert min(gap(home, h) for h in same) > 1, min(gap(home, h) for h in same) RHO, CX, CY = 21, kit.W / 2, 134 # hexagon radius in px, centre of the patch UNIT = 2 * RHO / D body = '' for q, r in product(range(-9, 10), repeat=2): x, y = centre(q, r, RHO) if math.hypot(x, y) > 5.6 * RHO or abs(y) > 125: continue c, pts = colour(q, r), corners(CX + x, CY + y, RHO - 1.5) if c == 0: body += kit.polygon(pts, 'f', ' fill-opacity=".5"') + kit.polygon(pts, 'f-s', ' stroke-width="2"') else: body += kit.polygon(pts, 'ink', f' fill-opacity="{0.05 + 0.055 * c:.3f}"') body += kit.circle(CX, CY, UNIT, 'ink-s', ' stroke-width="2" stroke-dasharray="5 5"') kit.write(__file__, 'mathematics', body, label='χ ≤ 7 · seven colours, none twice at distance 1')