# Sections 3, 4, 5, 8: checks for the classical objects which appear in the pictures of the paper, namely the Heawood graph, the # Paley biplane, the projective plane of order 3, the Kummer configuration and the Clebsch graph, the tetrahedral model of # PG(3,2), the hyperovals and Baer subplanes of PG(2,4), a coded aperture mask, and the Paley graphs with their conference # matrices, whose diagonal can be filled with signs. Usage: python3 portraits.py [names of the functions to be run] import numpy as np, itertools, networkx as nx from networkx.algorithms.isomorphism import GraphMatcher from designs import SETS, incidence from crystals import crystalline def levi(M): G = nx.Graph() for i in range(M.shape[0]): for j in range(M.shape[1]): if M[i, j]: G.add_edge(("block", i), ("point", j)) return G def automorphisms(M): G = levi(np.array(M)); p0 = ("point", 0) return sum(1 for f in GraphMatcher(G, G).isomorphisms_iter() if f[p0][0] == "point") def isdesign(M, k, lam): M = np.array(M); v = len(M) return bool((M @ M.T == (k - lam) * np.eye(v, dtype=int) + lam).all() and (M.T @ M == (k - lam) * np.eye(v, dtype=int) + lam).all()) def heawood(): M = incidence(7, [1, 2, 4]).astype(int); G = levi(M) cycle = [] for j in range(7): cycle += [("point", j), ("block", (j - 1) % 7)] ham = all(G.has_edge(cycle[i], cycle[(i + 1) % 14]) for i in range(14)) chords = sorted({min((cycle.index(b) - cycle.index(a)) % 14, (cycle.index(a) - cycle.index(b)) % 14) for a, b in G.edges()}) print("Heawood graph: 14 vertices, %d edges, degrees %s, girth %d, Hamiltonian cycle point j, line j-1: %s, lengths of the edges on this cycle: %s" % (G.number_of_edges(), sorted(set(dict(G.degree()).values())), nx.girth(G), ham, chords)) # the map on the torus: hexagons at (a,b), with color a + 3b modulo 7 nb = [(1, 0), (-1, 0), (0, 1), (0, -1), (1, -1), (-1, 1)] print(" torus map: the 6 neighbors of a hexagon have the 6 other colors:", sorted((a + 3 * b) % 7 for a, b in nb) == [1, 2, 3, 4, 5, 6]) T = nx.Graph() for c in range(7): down = frozenset({c, (c + 1) % 7, (c + 3) % 7}); up = frozenset({c, (c + 1) % 7, (c - 2) % 7}) T.add_node(("down", down)); T.add_node(("up", up)) for x, y in itertools.combinations(range(7), 2): ends = [n for n in T.nodes if x in n[1] and y in n[1]] assert len(ends) == 2; T.add_edge(*ends) print(" torus map: 7 hexagons, %d vertices, %d edges, isomorphic to the Heawood graph: %s" % (T.number_of_nodes(), T.number_of_edges(), nx.is_isomorphic(T, G))) print(" automorphisms of the Fano plane:", automorphisms(M)) def biplane(): v, D = 11, [1, 3, 4, 5, 9]; M = incidence(v, D).astype(int) blocks = [sorted((d + i) % v for d in D) for i in range(v)] through = [i for i in range(v) if 0 in blocks[i] and 1 in blocks[i]] print("Paley biplane: design (11,5,2): %s; blocks through the points 0 and 1: %s; automorphisms: %d" % (isdesign(M, 5, 2), [blocks[i] for i in through], automorphisms(M))) def planethree(): pts = [(x, y) for x in range(3) for y in range(3)] + ["inf0", "inf1", "inf2", "infv"] lines = [] for m in range(3): lines += [[(x, (m * x + c) % 3) for x in range(3)] + ["inf%d" % m] for c in range(3)] lines += [[(c, y) for y in range(3)] + ["infv"] for c in range(3)] lines.append(["inf0", "inf1", "inf2", "infv"]) M = np.array([[1 if p in l else 0 for p in pts] for l in lines]) C = incidence(13, [0, 1, 3, 9]).astype(int) print("plane of order 3: affine model with 9 + 4 points is a design (13,4,1): %s, isomorphic to the cyclic one: %s; automorphisms: %d" % (isdesign(M, 4, 1), nx.is_isomorphic(levi(M), levi(C)), automorphisms(C))) def kummer(): cells = [(r, c) for r in range(4) for c in range(4)] B = np.array([[1 if (y != x and (y[0] == x[0] or y[1] == x[1])) else 0 for y in cells] for x in cells]) V = list(itertools.product([0, 1], repeat=4)) A = np.array([[1 if sum(a != b for a, b in zip(x, y)) in (1, 4) else 0 for y in V] for x in V]) Cl = A + np.eye(16, dtype=int) S = np.array([[1 if ((x[0] - y[0]) % 4, (x[1] - y[1]) % 4) in [(1, 0), (3, 0), (0, 1), (0, 3), (1, 1), (3, 3)] else 0 for y in cells] for x in cells]) def same(X, Y): # the rank modulo 2 is an invariant; when the ranks agree, we look for an isomorphism of the incidence graphs return gf2rank(X) == gf2rank(Y) and nx.is_isomorphic(levi(X), levi(Y)) print("Kummer configuration on the board: design (16,6,2): %s, rank modulo 2: %d" % (isdesign(B, 6, 2), gf2rank(B)), flush=True) print("Clebsch graph: regular of degree %d, closed neighborhoods form a design (16,6,2): %s, rank modulo 2: %d, isomorphic to the board design: %s" % (int(A.sum(1)[0]), isdesign(Cl, 6, 2), gf2rank(Cl), same(Cl, B)), flush=True) print("Shrikhande graph: neighborhoods form a design (16,6,2): %s, rank modulo 2: %d, isomorphic to the board design: %s" % (isdesign(S, 6, 2), gf2rank(S), same(S, B)), flush=True) def gf2rank(M): M = (np.array(M) % 2).astype(np.uint8).copy(); r = 0 for c in range(M.shape[1]): piv = [i for i in range(r, M.shape[0]) if M[i, c]] if not piv: continue M[[r, piv[0]]] = M[[piv[0], r]] for i in range(M.shape[0]): if i != r and M[i, c]: M[i] ^= M[r] r += 1 return r def tetrahedron(): P = [x for x in itertools.product([0, 1], repeat=4) if any(x)] add = lambda x, y: tuple((a + b) % 2 for a, b in zip(x, y)) lines = {frozenset({x, y, add(x, y)}) for x, y in itertools.combinations(P, 2)} planes = [[x for x in P if sum(a * b for a, b in zip(f, x)) % 2 == 0] for f in P] M = np.array([[1 if x in pl else 0 for x in P] for pl in planes]) C = incidence(15, [0, 1, 2, 4, 5, 8, 10]).astype(int) frame = [x for x in P if sum(x) in (1, 4)] e = [tuple(1 if i == j else 0 for i in range(4)) for j in range(4)] edge = lambda i, j: {e[i], e[j], add(e[i], e[j])} print("PG(3,2): %d points (%s of weights 1, 2, 3, 4), %d lines, %d planes with %d points; points and planes isomorphic to the cyclic design (15,7,3): %s" % (len(P), [sum(1 for x in P if sum(x) == w) for w in (1, 2, 3, 4)], len(lines), len(planes), len(planes[0]), nx.is_isomorphic(levi(M), levi(C)))) print(" the 4 vertices and the center meet the planes in %s points; 2 opposite edges meet the planes in %s points, and are disjoint: %s" % (sorted({sum(1 for x in frame if x in pl) for pl in planes}), sorted({sum(1 for x in (edge(0, 1) | edge(2, 3)) if x in pl) for pl in planes}), not (edge(0, 1) & edge(2, 3)))) def witt(): v, D = SETS["plane of order 4 (21,5,1)"] def sets(sign, size): M, states = crystalline(v, D, sign); out = set() for b in states: for s in (1, -1): T = frozenset(np.nonzero(b == s)[0].tolist()) if len(T) == size: out.add(T) return M, sorted(out, key=sorted) M, hyper = sets(1, 6); M, baer = sets(-1, 7) def classes(items, rel): G = nx.Graph(); G.add_nodes_from(range(len(items))) for i, j in itertools.combinations(range(len(items)), 2): if rel(len(items[i] & items[j])): G.add_edge(i, j) comps = list(nx.connected_components(G)) clique = all(G.subgraph(c).number_of_edges() == len(c) * (len(c) - 1) // 2 for c in comps) return sorted(len(c) for c in comps), clique print("PG(2,4): %d hyperovals, classes for the relation of meeting in an even number of points: %s, this is an equivalence relation: %s" % ((len(hyper),) + classes(hyper, lambda m: m % 2 == 0))) print("PG(2,4): %d Baer subplanes, classes for the relation of meeting in an odd number of points: %s, this is an equivalence relation: %s" % ((len(baer),) + classes(baer, lambda m: m % 2 == 1))) print(" blocks of the Witt design on 24 points: 21 + %d + %d + 210 = %d" % (len(hyper), len(baer), 21 + len(hyper) + len(baer) + 210)) def legendre(x, p): return 0 if x % p == 0 else (1 if pow(x, (p - 1) // 2, p) == 1 else -1) def mask(r=13, s=11): return np.array([[0 if i == 0 else (1 if j == 0 else (1 if legendre(i, r) * legendre(j, s) == 1 else 0)) for j in range(s)] for i in range(r)]) def masks(): A = mask(); r, s = A.shape corr = np.array([[int((A * np.roll(np.roll(A, a, 0), b, 1)).sum()) for b in range(s)] for a in range(r)]) off = sorted(set(corr.ravel().tolist()) - {corr[0, 0]}) v, k = r * s, int(A.sum()) print("coded aperture mask %d x %d: %d open cells out of %d, periodic autocorrelation %d at the origin and %s elsewhere" % (r, s, k, v, corr[0, 0], off)) if len(off) == 1: lam = off[0] if 2 * k > v: k, lam = v - k, v - 2 * k + lam # the closed cells form the complementary design n = k - lam for sign in (1, -1): print(" design (%d,%d,%d), of order n = %d, with v = 4n - 1: %s; 1-norm of U_%s divided by v^1.5: %.4f" % (v, k, lam, n, v == 4 * n - 1, "+" if sign == 1 else "-", (2 * (v - 1) * n ** .5 + sign * (v - 2 * k)) / v ** 1.5)) def paleygraph(q): if q == 9: F = [(a, b) for a in range(3) for b in range(3)] mul = lambda x, y: ((x[0] * y[0] - x[1] * y[1]) % 3, (x[0] * y[1] + x[1] * y[0]) % 3) sq = {mul(x, x) for x in F if x != (0, 0)} return np.array([[1 if ((x[0] - y[0]) % 3, (x[1] - y[1]) % 3) in sq else 0 for y in F] for x in F]) return np.array([[1 if legendre(x - y, q) == 1 else 0 for y in range(q)] for x in range(q)]) def conference(q): A = paleygraph(q); S = 2 * A - 1 + np.eye(q, dtype=int) C = np.zeros((q + 1, q + 1), dtype=int); C[0, 1:] = 1; C[1:, 0] = 1; C[1:, 1:] = S return C def paley(): for q in (5, 9, 13): A = paleygraph(q); C = conference(q); n = q + 1 srg = bool((A @ A == (q - 1) // 2 * np.eye(q, dtype=int) + (q - 5) // 4 * A + (q - 1) // 4 * (1 - A - np.eye(q, dtype=int))).all()) U = C / q ** .5 np.random.seed(q); best = 0 for trial in range(200): V = U + 0.05 * np.random.randn(n, n); W, s, Vh = np.linalg.svd(V); V = W @ Vh; f = np.abs(V).sum() for it in range(5000): W, s, Vh = np.linalg.svd(np.sign(V)); V2 = W @ Vh; g = np.abs(V2).sum() if g <= f + 1e-13: break V, f = V2, g best = max(best, f) extra = "" if q == 9: R = nx.cartesian_product(nx.complete_graph(3), nx.complete_graph(3)); extra = ", isomorphic to the 3 x 3 rook graph: %s" % nx.is_isomorphic(nx.from_numpy_array(A), R) print("Paley graph of order %d: strongly regular: %s%s; conference matrix of order %d: C C^t = %d: %s, 1-norm of C/sqrt(%d) divided by N^1.5: %.4f, best polar iteration from 200 perturbations: %.4f" % (q, srg, extra, n, q, bool((C @ C.T == q * np.eye(n, dtype=int)).all()), q, np.abs(U).sum() / n ** 1.5, best / n ** 1.5)) print(" conference matrix of order 6:", conference(5).tolist()) def filled(): # the sign matrices C + D, with C a conference matrix and D a diagonal matrix of signs: maximum of Tr|C + D| over D from optimal import charpoly, product expected = {6: [([1, -10], 2), ([1, -4], 4)], 14: [([1, -10], 2), ([1, -44, 608, -2624], 4)]} for q in (5, 9, 13): C = conference(q); n = q + 1; best = (0, None) for d in itertools.product([1, -1], repeat=q): f = np.linalg.svd(C + np.diag((1,) + d), compute_uv=False).sum() if f > best[0] + 1e-9: best = (f, (1,) + d) S = C + np.diag(best[1]); W, sv, Vh = np.linalg.svd(S.astype(float)); U = W @ Vh line = "filled conference matrix of order %d: best diagonal %s, Tr|S| = %.6f, divided by N^1.5: %.4f, S is the sign matrix of its polar part: %s" % (n, list(best[1]), best[0], best[0] / n ** 1.5, bool((np.sign(U) == S).all())) if n in expected: G = [[int(x) for x in row] for row in S @ S.T] line += "; characteristic polynomial of S S^t as expected: %s" % (charpoly(G) == product(expected[n])) print(line, flush=True) if n == 14: print(" S =", S.tolist()) if __name__ == "__main__": import sys todo = [globals()[x] for x in sys.argv[1:]] or [heawood, biplane, planethree, kummer, tetrahedron, witt, masks, paley, filled] for f in todo: f()