"""State space metrics of the twisted Platonic solids. The edge seminorm is Lip(F) = max_{x~y} ||F(x)-F(y)||, all edges having length 1, and the distance between 2 states is delta(w,v) = sup { w(F)-v(F) : F = F^*, Lip(F) <= 1 }. A self-adjoint F is encoded by its values s + x.sigma at the orbit representatives, and ||s + x.sigma|| = |s| + |x|, so delta is a convex program, solved here with SLSQP. The program computes the distances between the claimed diametral states, and searches for the diameter by maximizing the distance over pairs of pure states, from random starting points. """ import sys import numpy as np from scipy.optimize import minimize from solids import placement, TwistedSpace, adjacency_lists, GAMMA, PHI rng = np.random.default_rng(2026) class MetricModel: def __init__(self, label): pts, edges, faces = placement(label) self.label = label self.sp = TwistedSpace(pts) self.edges = edges # parameters: for each orbit, s (and x in R^3 for free, t for size 2) self.layout = [] k = 0 for x, orb, stab in self.sp.orbits: kind = {1: "free", 2: "pair", 4: "fixed"}[len(stab)] npar = {"free": 4, "pair": 2, "fixed": 1}[kind] axis = stab[1] - 1 if kind == "pair" else None self.layout.append((x, kind, axis, k)) k += npar self.npar = k # value of F at each point, as an affine function of the parameters n = self.sp.n self.S = np.zeros((n, k)) # scalar part self.V = np.zeros((n, 3, k)) # vector part for x, kind, axis, k0 in self.layout: for g, (Rg, _) in enumerate(GAMMA): y = self.sp.perm[g][x] self.S[y, k0] = 1 if kind == "free": self.V[y, :, k0 + 1:k0 + 4] = Rg elif kind == "pair": e = np.zeros(3) e[axis] = 1 self.V[y, :, k0 + 1] = Rg @ e self.blocks = [(x, kind, axis, k0) for x, kind, axis, k0 in self.layout] def constraints(self): cons = [] for i, j in self.edges: dS = self.S[i] - self.S[j] dV = self.V[i] - self.V[j] for sgn in (1, -1): cons.append({"type": "ineq", "fun": lambda p, dS=dS, dV=dV, sgn=sgn: 1 - sgn * dS @ p - np.sqrt((dV @ p) @ (dV @ p) + 1e-16), "jac": lambda p, dS=dS, dV=dV, sgn=sgn: -sgn * dS - (dV.T @ (dV @ p)) / np.sqrt((dV @ p) @ (dV @ p) + 1e-16)}) return cons def state(self, b, u): """Linear form on parameters of the pure state on block b: Bloch vector u for a free block, sign u = +1/-1 for a pair block.""" x, kind, axis, k0 = self.blocks[b] w = np.zeros(self.npar) w[k0] = 1 if kind == "free": w[k0 + 1:k0 + 4] = u elif kind == "pair": w[k0 + 1] = u return w def distance(self, w1, w2, starts=2): c = w1 - w2 cons = self.constraints() best = -np.inf # gauge: the overall scalar is irrelevant, fix it to 0 cons.append({"type": "eq", "fun": lambda p: p[0], "jac": lambda p: np.eye(self.npar)[0]}) for t in range(starts): p0 = rng.normal(size=self.npar) * 0.01 r = minimize(lambda p: -c @ p, p0, jac=lambda p: -c, constraints=cons, method="SLSQP", options={"maxiter": 500, "ftol": 1e-12}) if r.success or r.status == 9: best = max(best, -r.fun) return best def free_blocks(self): return [b for b, (x, kind, axis, k0) in enumerate(self.blocks) if kind == "free"] def sph(a, b): return np.array([np.sin(a) * np.cos(b), np.sin(a) * np.sin(b), np.cos(a)]) def diameter_search(m, trials=6, iters=60): """Maximize the distance over pairs of pure states (free blocks only).""" fb = m.free_blocks() best = (0, None) for b1 in fb: for b2 in fb: if b2 < b1: continue for t in range(trials): ang = rng.uniform(0, np.pi, 4) * np.array([1, 2, 1, 2]) val = m.distance(m.state(b1, sph(*ang[:2])), m.state(b2, sph(*ang[2:])), starts=1) step = 0.5 for it in range(iters): cand = ang + rng.normal(size=4) * step v = m.distance(m.state(b1, sph(*cand[:2])), m.state(b2, sph(*cand[2:])), starts=1) if v > val: ang, val = cand, v else: step *= 0.93 if val > best[0]: best = (val, (b1, b2, sph(*ang[:2]), sph(*ang[2:]))) return best def report_tetrahedron(): m = MetricModel("tetrahedron") states = [np.array(s) / 3 ** 0.5 for s in [(a, b, c) for a in (1, -1) for b in (1, -1) for c in (1, -1)]] print("tetrahedron: distances from (1,1,1)/sqrt3 to the other 7 diametral states") for s in states[1:]: flips = int(np.sum(np.sign(s) != 1)) print(f" {flips} sign changes: {m.distance(m.state(0, states[0]), m.state(0, s)):.6f}") print(f" expected 1/sqrt3={1/3**.5:.6f}, sqrt(2/3)={(2/3)**.5:.6f}, sqrt(3/2)={1.5**.5:.6f}") return m def report_cube(): m = MetricModel("cube") d = [np.array(s) / 3 ** 0.5 for s in [(a, b, c) for a in (1, -1) for b in (1, -1) for c in (1, -1)]] b0, b1 = m.free_blocks() print("cube: within-block antipodal distance", m.distance(m.state(b0, d[0]), m.state(b0, -d[0])), "expected 3/sqrt2 =", 3 / 2 ** .5) reps = [m.blocks[b][0] for b in (b0, b1)] print(" block representatives:", [tuple(m.sp.points[r]) for r in reps]) print(" cross-block distances from block 1, direction (1,1,1)/sqrt3, to block 2:") for u in d: print(f" {tuple(np.round(u*3**.5).astype(int))}: {m.distance(m.state(b0, d[0]), m.state(b1, u)):.6f}") return m def report_octahedron(): m = MetricModel("octahedron") print("octahedron: distances between the 6 characters") labels = [] for b, (x, kind, axis, k0) in enumerate(m.blocks): for sgn in (1, -1): labels.append((b, sgn)) for (b, s) in labels[1:]: print(f" (block 0,+) to (block {b},{'+' if s > 0 else '-'}): {m.distance(m.state(0, 1), m.state(b, s)):.6f}") return m def report_icosahedron(): m = MetricModel("icosahedron") reps = {tuple(np.round(m.sp.points[m.blocks[b][0]], 6)): b for b in range(len(m.blocks))} print("icosahedron: orbit representatives", list(reps.keys())) # diametral states: Bloch vectors (0,+-1,+-2)/sqrt5 at the representative with zero first coordinate, cyclically states = [] for b, (x, kind, axis, k0) in enumerate(m.blocks): p = m.sp.points[x] z = int(np.argmin(np.abs(p))) # position of the zero coordinate for s1 in (1, -1): for s2 in (1, -1): u = np.zeros(3) u[(z + 1) % 3] = s1 * 1 / 5 ** .5 u[(z + 2) % 3] = s2 * 2 / 5 ** .5 states.append((b, u)) print(" representative points:", [tuple(np.round(m.sp.points[m.blocks[b][0]], 3)) for b in range(3)]) D = np.zeros((12, 12)) for i in range(12): for j in range(i + 1, 12): D[i, j] = D[j, i] = m.distance(m.state(*states[i]), m.state(*states[j])) vals = np.round(np.sort(D[0][1:]), 5) print(" distances from state 0:", vals) expected = [1 / 5 ** .5, 3 ** .5 / 2 + 3 / (2 * 5 ** .5), 4 / 5 ** .5, 3 ** .5 / 2 + 5 / (2 * 5 ** .5), 5 ** .5] print(" expected values:", np.round(expected, 5)) # nearest neighbor graph G = np.zeros((12, 12), int) for i in range(12): order = np.argsort(D[i] + np.eye(12)[i] * 99) for j in order[:5]: G[i, j] = 1 sym = np.allclose(G, G.T) deg = G.sum(axis=1) ev = np.round(np.sort(np.linalg.eigvalsh((G + G.T) / 2)), 4) print(f" 5-nearest-neighbor graph symmetric: {sym}, degrees {set(deg)}, spectrum {ev}") print(f" icosahedral spectrum: 5, sqrt5 (x3), -1 (x5), -sqrt5 (x3)") short = sorted(set(np.round(D[G.astype(bool)], 5))) print(" edge lengths in it:", short) return m, states, D if __name__ == "__main__": which = sys.argv[1:] or ["tetrahedron", "cube", "octahedron", "icosahedron", "search"] if "tetrahedron" in which: report_tetrahedron() if "cube" in which: report_cube() if "octahedron" in which: report_octahedron() if "icosahedron" in which: report_icosahedron() if "search" in which: for label in ("tetrahedron", "cube", "icosahedron"): m = MetricModel(label) val, arg = diameter_search(m, trials=3, iters=40) print(f"diameter search {label}: {val:.6f}, blocks {arg[0]},{arg[1]}, states {np.round(arg[2], 4)} {np.round(arg[3], 4)}")