# Data for the figures of the paper. Each block prints the coordinates used in one figure. # Usage: python3 pictures.py [block ...], with blocks among: game soft glow heat quench dual race sets states phases six. No argument: all. # The block "dual" needs seven.json, made by seven.py. import numpy as np, sys, json, itertools from designs import SETS, matrices from arrays import heat, psi, crystallization, levels from ascent import haar, quench def design(name): key = [k for k in SETS if name in k][0] return matrices(*SETS[key]) def soft(): # the 1-norm along the softest rotation, in the plane of the 2 lowest eigenvectors of X = S^t U for name in ["(7,3,1)", "(11,5,2)", "(13,4,1)"]: U = design(name)[1] X = np.sign(U).T @ U lam, V = np.linalg.eigh(X) A = np.outer(V[:, 0], V[:, 1]) - np.outer(V[:, 1], V[:, 0]) pts = [] for t in np.linspace(-0.1, 0.1, 21): R = np.eye(len(U)) + np.sin(t) * A + (1 - np.cos(t)) * (A @ A) pts.append("(%.3f,%.5f)" % (t, np.abs(U @ R).sum() - np.abs(U).sum())) print("soft", name, "lambda1 + lambda2 = %.4f" % (lam[0] + lam[1])) print(" ".join(pts)) def glow(): # the density of states of the Ising array of the 2 Fano matrices, in bins of width 1/2, with the second level and the smallest |Omega| signs = np.array(list(itertools.product([1, -1], repeat=7)), dtype=float) for which, U in zip(["plain", "twisted"], design("(7,3,1)")): om = (signs @ U @ signs.T).ravel() h = np.bincount(np.floor((om + 7.25) * 2).astype(int), minlength=29) lev, cnt = np.unique(np.round(om, 9), return_counts=True) print("glow Fano", which, "levels", len(lev), "states at 7:", int((om > 7 - 1e-9).sum()), "maximum %.6f" % om.max(), "moments of order 2 and 4: %.4f %.4f" % ((om ** 2).mean(), (om ** 4).mean()), "second level %.4f with %d states, smallest absolute value %.4f" % (lev[-2], cnt[-2], np.abs(om).min())) print(" ".join("(%.1f,%d)" % (-7 + k / 2, h[k]) for k in range(29))) g = [2 ** 14 * 0.5 * np.exp(-x * x / 14) / np.sqrt(14 * np.pi) for x in np.arange(-7, 7.01, 0.5)] print("glow Gaussian", " ".join("(%.1f,%.1f)" % (x, y) for x, y in zip(np.arange(-7, 7.01, 0.5), g))) def heatcurves(): # the energy and the specific heat per row wire of some design arrays, against the temperature T = np.arange(0.06, 1.0001, 0.02) for name in ["(7,3,1)", "(13,4,1)", "(15,7,3)", "(19,9,4)"]: U = design(name)[0] out = heat(U, 1 / T) print("heat", name) print("energy", " ".join("(%.2f,%.4f)" % (t, o[0]) for t, o in zip(T, out))) print("specific heat", " ".join("(%.2f,%.4f)" % (t, o[1]) for t, o in zip(T, out))) b = 1 / T print("paramagnetic energy", " ".join("(%.2f,%.4f)" % (t, (np.sqrt(1 + 4 * x * x) - 1) / (2 * x)) for t, x in zip(T, b))) def quenches(): # the end values of the polar iteration at N = 7 and N = 13, from Haar random matrices for n, target in [(7, 1 + 12 * np.sqrt(2)), (13, 5 + 24 * np.sqrt(3))]: np.random.seed(n) vals = np.array([quench(haar(n))[1] for _ in range(3000)]) / n ** 1.5 lo, hi, w = 0.88, 1.0, 0.005 h = np.bincount(np.floor((vals - lo) / w).astype(int).clip(0), minlength=int(round((hi - lo) / w))) print("quench", n, "runs 3000 mean %.4f best %.4f at the design value: %d" % (vals.mean(), vals.max(), int((np.abs(vals - target / n ** 1.5) < 1e-9).sum()))) print(" ".join("(%.4f,%d)" % (lo + w * (k + 0.5), h[k]) for k in range(len(h)) if h[k])) def dual(): # the density of states of the Ising model with energy -Tr|S|, at N = 5, 6, 7, and its specific heat data = {} for n in [5, 6]: m = (n - 1) ** 2 vals = [] for lo in range(0, 1 << m, 1 << 18): x = np.arange(lo, min(lo + (1 << 18), 1 << m), dtype=np.int64) bits = 1 - 2 * ((x[:, None] >> np.arange(m)) & 1).astype(float) S = np.ones((len(x), n, n)) S[:, 1:, 1:] = bits.reshape(-1, n - 1, n - 1) vals.append(np.linalg.svd(S, compute_uv=False).sum(1)) vals = np.concatenate(vals) e, c = np.unique(np.round(vals, 8), return_counts=True) data[n] = (e, c.astype(float)) print("dual", n, "states", len(vals), "levels", len(e), "top levels", " ".join("%.4f:%d" % (a, b) for a, b in zip(e[-4:], c[-4:]))) js = json.load(open("seven.json")) h = np.array(js["bins"], dtype=float) data[7] = ((np.arange(len(h)) + 0.5) / 100, h) print("dual 7 mean of Tr|S|/N^(3/2): %.4f" % ((h * (np.arange(len(h)) + 0.5) / 100).sum() / h.sum() / 7 ** 1.5)) print("dual 7 states", int(h.sum()), "top levels", " ".join("%s:%d" % (k, js["top"][k][0]) for k in sorted(js["top"], reverse=True)[:4])) for n in [5, 6, 7]: e, c = data[n] keep = c > 0 e, c = e[keep], c[keep] w = 0.25 hb = np.bincount(np.floor(e / w).astype(int), weights=c) print("dual", n, "density, log10 of the number of states in bins of width 1/4, against Tr|S|/N^(3/2)") print(" ".join("(%.4f,%.3f)" % ((k + 0.5) * w / n ** 1.5, np.log10(hb[k])) for k in range(len(hb)) if hb[k] > 0)) pts = [] for T in np.arange(0.04, 1.2001, 0.02): lw = np.log(c) + e / T p = np.exp(lw - lw.max()); p /= p.sum() mean = (p * e).sum(); var = (p * e * e).sum() - mean ** 2 pts.append("(%.2f,%.4f)" % (T, var / T ** 2 / (n - 1) ** 2)) print("dual", n, "specific heat per spin:", " ".join(pts)) def race(): # the alternating maximization at N = 7, from random signs and from random phases np.random.seed(5) n = 7 def run(S, steps): out = [(0, 1 - np.linalg.svd(S, compute_uv=False).sum() / n ** 1.5)] for k in range(1, steps + 1): W, s, Vh = np.linalg.svd(S) U = W @ Vh S = np.where(np.abs(U) > 1e-12, U / np.maximum(np.abs(U), 1e-300), S) if k & (k - 1) == 0: out.append((k, 1 - np.linalg.svd(S, compute_uv=False).sum() / n ** 1.5)) return out for r in range(3): print("race real", " ".join("(%d,%.3e)" % p for p in run(np.sign(np.random.randn(n, n)), 64))) for r in range(3): print("race complex", " ".join("(%d,%.3e)" % p for p in run(np.exp(2j * np.pi * np.random.rand(n, n)), 4096))) def game(): # the switching game on the board of the Fano plane from designs import incidence M = incidence(7, [1, 2, 4]); S = 2 * M - 1 signs = np.array(list(itertools.product([1, -1], repeat=7))) best = np.abs(signs @ S).sum(1) a = signs[np.argmax(best)]; b = np.sign(a @ S) board = (S * a[:, None] * b[None, :] + 1) // 2 print("game: lit lamps", int(M.sum()), "best", int((49 + best.max()) // 2), "row switches", a.tolist(), "column switches", b.astype(int).tolist()) print("board", M.astype(int).tolist()); print("best board", board.astype(int).tolist()) def sets(): # crystalline states of the arrays of the 2 designs of order 4, as sets of points of Z_v, chosen with many translation symmetries from crystals import crystalline for name in ["PG(3,2) (15,7,3)", "plane of order 4 (21,5,1)"]: v, D = SETS[name] for sign in [1, -1]: M, states = crystalline(v, D, sign) best = {} for b in states: small = set(np.nonzero(b == (1 if (b == 1).sum() < v / 2 else -1))[0].tolist()) if not small: continue sym = sum(1 for r in range(v) if {(x + r) % v for x in small} == small) key = len(small) cand = (sym, [-x for x in sorted(small)]) if key not in best or cand > best[key]: best[key] = cand for key in sorted(best): print("sets", name, "U_+" if sign == 1 else "U_-", "size", key, "translations", best[key][0], "set", [-x for x in best[key][1]]) def states(): # a Haar random orthogonal matrix of order 7, the end of its polar iteration, and the matrix U_+ of the Fano plane, times sqrt(7) np.random.seed(3) U = haar(7); V, f = quench(U) for name, W in [("hot", U), ("cooled", V), ("Fano", design("(7,3,1)")[0])]: print("states", name, "norm %.4f" % (np.abs(W).sum() / 7 ** 1.5), [[round(float(x), 2) for x in row] for row in W * np.sqrt(7)]) def phases(): # the alternating maximization at N = 5, from random phases: the angles of the entries, in degrees, at the start and at the end, # with the first row and column made positive np.random.seed(2) n = 5 S = np.exp(2j * np.pi * np.random.rand(n, n)) def show(name, S): T = S / S[:, :1]; T = T / T[:1, :] print("phases", name, "Tr|S|/N^1.5 = %.6f" % (np.linalg.svd(S, compute_uv=False).sum() / n ** 1.5), [[int(round(float(np.degrees(np.angle(z))))) % 360 for z in row] for row in T]) show("start", S) for k in range(20000): W, s, Vh = np.linalg.svd(S); U = W @ Vh; S = U / np.abs(U) show("end", S) def six(): # the optimal matrix at N = 6, as the polar part of its sign matrix from optimal import SIX, matrix S = np.array(matrix(SIX), float); W, s, Vh = np.linalg.svd(S); U = W @ Vh vals = sorted(set(np.round(np.abs(U).ravel(), 6).tolist())) print("six: absolute values of the entries", vals, "expected", [round(x, 6) for x in sorted([10 ** -.5, .5 - (1 / 6 - 1 / (3 * 10 ** .5)), .5 + (1 / 6 - 1 / (3 * 10 ** .5))])]) print("six pattern", [["abc"[vals.index(round(abs(float(x)), 6))] for x in row] for row in U]) BLOCKS = {"sets": sets, "states": states, "phases": phases, "six": six, "game": game, "soft": soft, "glow": glow, "heat": heatcurves, "quench": quenches, "dual": dual, "race": race} if __name__ == "__main__": for b in (sys.argv[1:] or list(BLOCKS)): BLOCKS[b]()