"""Common geometry for the twisted Platonic solids. Builds the 5 Platonic solids, their cells (vertices, edges, faces), the Klein group of half-turns about the coordinate axes, the 7 framed placements, and the Klein twist of any finite set of points stable under the half-turns. The twisted algebra C(V) is realized inside the functions from the points to M_2(C), with its multimatrix basis and canonical trace, as in the paper. """ import itertools import numpy as np from scipy.spatial import ConvexHull PHI = (1 + 5 ** 0.5) / 2 TOL = 1e-9 # Pauli matrices and the half-turns R_1, R_2, R_3 SIGMA = [np.array([[0, 1], [1, 0]], dtype=complex), np.array([[0, -1j], [1j, 0]], dtype=complex), np.array([[1, 0], [0, -1]], dtype=complex)] ONE = np.eye(2, dtype=complex) R = [np.diag([1., -1., -1.]), np.diag([-1., 1., -1.]), np.diag([-1., -1., 1.])] # the Klein group: identity and the 3 half-turns, with their Pauli lifts GAMMA = [(np.eye(3), ONE)] + [(R[k], SIGMA[k]) for k in range(3)] def cyclic(v): a, b, c = v return [(a, b, c), (c, a, b), (b, c, a)] def signs(v): out = set() for s in itertools.product([1, -1], repeat=3): out.add(tuple(si * vi for si, vi in zip(s, v))) return sorted(out) def vertices(name): if name == "tetrahedron": pts = [p for p in itertools.product([1, -1], repeat=3) if np.prod(p) == 1] elif name == "cube": pts = list(itertools.product([1, -1], repeat=3)) elif name == "octahedron": pts = [tuple(s * e for e in row) for row in np.eye(3) for s in (1, -1)] elif name == "icosahedron": pts = [q for p in signs((0, 1, PHI)) for q in cyclic(p)] elif name == "dodecahedron": pts = list(itertools.product([1, -1], repeat=3)) pts += [q for p in signs((0, PHI, 1 / PHI)) for q in cyclic(p)] else: raise ValueError(name) pts = np.array(sorted(set(tuple(np.round(p, 12)) for p in pts)), dtype=float) return pts def cells(pts): """Edges (index pairs) and faces (index tuples) of the convex hull.""" n = len(pts) dist = np.linalg.norm(pts[:, None, :] - pts[None, :, :], axis=2) m = min(dist[i, j] for i in range(n) for j in range(i + 1, n)) edges = [(i, j) for i in range(n) for j in range(i + 1, n) if abs(dist[i, j] - m) < 1e-6] hull = ConvexHull(pts) planes = {} for eq in hull.equations: key = tuple(np.round(eq, 6)) planes[key] = eq faces = [] for eq in planes.values(): on = [i for i in range(n) if abs(eq[:3] @ pts[i] + eq[3]) < 1e-6] faces.append(tuple(on)) return edges, faces # frames: rows are the 3 half-turn axes, written in the original coordinates STANDARD = np.eye(3) OTHER = np.array([[1, 1, 0], [-1, 1, 0], [0, 0, 2 ** 0.5]]) / 2 ** 0.5 PLACEMENTS = [("tetrahedron", "tetrahedron", STANDARD), ("cube", "cube", STANDARD), ("octahedron", "octahedron", STANDARD), ("icosahedron", "icosahedron", STANDARD), ("dodecahedron", "dodecahedron", STANDARD), ("other cube", "cube", OTHER), ("other octahedron", "octahedron", OTHER)] def placement(label): for lab, name, frame in PLACEMENTS: if lab == label: pts = vertices(name) edges, faces = cells(pts) pts = pts @ frame.T # coordinates adapted to the frame return pts, edges, faces raise ValueError(label) def cell_centers(pts, edges, faces): c0 = pts c1 = np.array([(pts[i] + pts[j]) / 2 for i, j in edges]) c2 = np.array([pts[list(f)].mean(axis=0) for f in faces]) return [c0, c1, c2] def find(points, p): for i, q in enumerate(points): if np.linalg.norm(q - p) < 1e-6: return i raise ValueError("point not found: the set is not stable") def action(points): """perm[g][i] = index of R_g applied to point i, for g = 0 (identity),1,2,3.""" return [[find(points, Rg @ p) for p in points] for Rg, _ in GAMMA] class TwistedSpace: """The Klein twist of a finite set of points stable under the half-turns. Elements are arrays F of shape (n, 2, 2) with F[g x] = U_g F[x] U_g^*. The multimatrix basis is stored as a list of such arrays, with block data. """ def __init__(self, points): self.points = np.array(points, dtype=float) self.n = len(points) self.perm = action(self.points) self.orbits = [] seen = set() for x in range(self.n): if x in seen: continue orb = sorted(set(self.perm[g][x] for g in range(4))) seen.update(orb) stab = [g for g in range(4) if self.perm[g][x] == x] self.orbits.append((x, orb, stab)) self.basis, self.size, self.block, self.unit = [], [], [], [] nblock = 0 for x, orb, stab in self.orbits: if len(stab) == 1: # free orbit: a block M_2 for a in range(2): for b in range(2): m = np.zeros((2, 2), complex) m[a, b] = 1 self._add(x, m, 2, nblock, (a, b)) nblock += 1 elif len(stab) == 2: # stabilizer {1,R_k}: 2 blocks C k = stab[1] - 1 w, v = np.linalg.eigh(SIGMA[k]) for c in range(2): p = np.outer(v[:, c], v[:, c].conj()) self._add(x, p, 1, nblock, (0, 0)) nblock += 1 else: # fixed point: a block C self._add(x, ONE, 1, nblock, (0, 0)) nblock += 1 self.dim = len(self.basis) self.nblocks = nblock assert self.dim == self.n def _add(self, x, m, size, blk, ab): F = np.zeros((self.n, 2, 2), complex) for g, (_, U) in enumerate(GAMMA): F[self.perm[g][x]] = U @ m @ U.conj().T self.basis.append(F) self.size.append(size) self.block.append(blk) self.unit.append(ab) # canonical trace psi(F) = sum_x tr(F(x)), tr = Tr/2, and = psi(G^*F) def psi(self, F): return sum(np.trace(F[x]) / 2 for x in range(self.n)) def inner(self, F, G): return sum(np.trace(G[x].conj().T @ F[x]) / 2 for x in range(self.n)) def coords(self, F): return np.array([self.inner(F, e) / s for e, s in zip(self.basis, self.size)]) def function(self, c): return sum(ci * e for ci, e in zip(c, self.basis)) def is_equivariant(self, F): for g, (_, U) in enumerate(GAMMA): for x in range(self.n): if np.abs(F[self.perm[g][x]] - U @ F[x] @ U.conj().T).max() > 1e-9: return False return True def matrix(self, op): """Matrix of a linear map C(V) -> C(V), given on functions.""" return np.array([self.coords(op(e)) for e in self.basis]).T # the 4 basic operations from the quantum graph paper, in the multimatrix basis def product_index(self, i, j): if self.block[i] != self.block[j]: return None a, b = self.unit[i] c, d = self.unit[j] if b != c: return None for k in range(self.dim): if self.block[k] == self.block[i] and self.unit[k] == (a, d): return k def bar(self, i): a, b = self.unit[i] for k in range(self.dim): if self.block[k] == self.block[i] and self.unit[k] == (b, a): return k def adjoint(self, A): n = np.array(self.size, float) return (A.conj().T) * n[None, :] / n[:, None] def hadamard(self, A, B): N = self.dim C = np.zeros((N, N), complex) prods = [(i, j, self.product_index(i, j)) for i in range(N) for j in range(N)] prods = [(i, j, m) for i, j, m in prods if m is not None] for i, j, m in prods: for k, l, p in prods: C[m, p] += A[i, k] * B[j, l] / self.size[p] return C def sharp(self, A): N = self.dim bar = [self.bar(i) for i in range(N)] return np.array([[np.conj(A[bar[i], bar[j]]) for j in range(N)] for i in range(N)]) def J(self): one = self.coords(self.function_one()) return np.outer(one, np.array([self.psi(e) for e in self.basis])) def function_one(self): F = np.zeros((self.n, 2, 2), complex) F[:] = ONE return F def choi_positive(self, A): """Complete positivity of a map C(V) -> C(V), via its block Choi matrices.""" blocks = sorted(set(self.block)) for r in blocks: idx_r = [i for i in range(self.dim) if self.block[i] == r] nr = self.size[idx_r[0]] for s in blocks: idx_s = [i for i in range(self.dim) if self.block[i] == s] ns = self.size[idx_s[0]] choi = np.zeros((nr * ns, nr * ns), complex) for i in idx_r: a, b = self.unit[i] out = np.zeros((ns, ns), complex) for k in idx_s: c, d = self.unit[k] out[c, d] += A[k, i] E = np.zeros((nr, nr)) E[a, b] = 1 choi += np.kron(E, out) if np.linalg.eigvalsh((choi + choi.conj().T) / 2).min() < -1e-9: return False return True def edge_sum(space, adj): """The twisted adjacency dF(x) = sum_{y ~ x} F(y), as a function operator.""" def op(F): G = np.zeros_like(F) for x in range(space.n): for y in adj[x]: G[x] += F[y] return G return op def adjacency_lists(n, edges): adj = [[] for _ in range(n)] for i, j in edges: adj[i].append(j) adj[j].append(i) return adj