"""A cap set of 20 points in F_3^4: the 81 points drawn as a 9 x 9 grid of 3 x 3 blocks, point (a, b, c, d) in block row a, block column b, row c, column d. Found by depth-first search from 0 and the four unit vectors (any cap that spans the space can be moved there by an affine map); checked here: no three distinct points x, y, z with x + y + z = 0.""" import itertools from pathlib import Path import kit P = list(itertools.product(range(3), repeat=4)) idx = {p: i for i, p in enumerate(P)} third = [[idx[tuple(-(a + b) % 3 for a, b in zip(x, y))] for y in P] for x in P] def search(cap, blocked, start, want): if len(cap) == want: return cap free = [i for i in range(start, 81) if not blocked >> i & 1] if len(cap) + len(free) < want: return None for k, i in enumerate(free): if len(cap) + len(free) - k < want: return None b = blocked | 1 << i for j in cap: b |= 1 << third[i][j] found = search(cap + [i], b, i + 1, want) if found: return found return None seed = [idx[p] for p in ((0, 0, 0, 0), (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1))] blocked = 0 for k, i in enumerate(seed): blocked |= 1 << i for j in seed[:k]: blocked |= 1 << third[i][j] cap = search(seed, blocked, 0, 20) assert cap and len(set(cap)) == 20 def spread(pts): """How unevenly the points fall over the 9 blocks, the 9 rows and the 9 columns of the drawing (0 is even).""" def var(keys): n = [0] * 9 for k in keys: n[k] += 1 return sum((c - len(pts) / 9) ** 2 for c in n) return var(3 * a + b for a, b, c, d in pts) + var(3 * a + c for a, b, c, d in pts) + var(3 * b + d for a, b, c, d in pts) # the same cap moved by a coordinate permutation, sign changes and a translation (affine maps keep lines), so that it # spreads evenly over the drawing; ties go to the first image found, so the result is deterministic best = None for perm in itertools.permutations(range(4)): for sign in itertools.product((1, 2), repeat=4): for t in P: img = [tuple((sign[k] * P[i][perm[k]] + t[k]) % 3 for k in range(4)) for i in cap] key = spread(img) if best is None or key < best[0] - 1e-9: best = (key, img) cap = [idx[p] for p in best[1]] assert len(set(cap)) == 20 assert all(third[x][y] not in cap for x, y in itertools.combinations(cap, 2)) s, g = 25, 11 # cell and the gap between blocks side = 9 * s + 2 * g x0, y0 = (kit.W - side) / 2, 14 def at(p): a, b, c, d = p return x0 + b * (3 * s + g) + d * s + s / 2, y0 + a * (3 * s + g) + c * s + s / 2 inside = set(cap) body = [kit.circle(*at(p), 2.6, 'faint') for i, p in enumerate(P) if i not in inside] body += [kit.dot(*at(P[i]), 8.5, 'f') for i in cap] kit.write(__file__, 'mathematics', ''.join(body), label='20 points of F₃⁴, no three on a line')