""" pictures.py -- computes and checks the data shown in the figures and tables of the paper. In order of appearance: - the finite quantum spaces with at most 10 points, the operations on V = M_2 and W = C^2, and the canonical trace on C + M_2 + M_3 (section 1), - the entries of the simplex over M_3 in the multimatrix basis (section 2), - the Catalan and Fuss-Catalan numbers, by counting noncrossing partitions, the action of SO_3 on M_2, the colors of K_4, and the quantum graphs of a fibration and of C^3 in M_3 (section 3), - the Weyl matrices U_g for n = 3, the products of K_2 and K_4, the graphs C_5 o K_2 and K_333, the 2-cocycle theta on Z_3^2, the map Ad_U(1,1), the eigenvalue landscapes over Z_7^2, and the pictures of the quantum torus over M_3 and of the Weyl cycle over M_4, the complement of C_6, and the colored Cayley graph of Z_2^2 (section 4), - the closed walks of the 4 simple quantum graphs over M_2, 2 drawings of K_4, the walks of length 2 in the square, the distances in the cube, the spectra of C_6 and C_5, and an eigenvector of the star K_1,3 (section 5), - the Laplacian spectra of K_N, C_N, the hypercube and P_7, the heat kernel on Z via Bessel functions, the heat traces, 3 heat flows on the Bloch ball, a bump on the path Z and its Laplacian, the heat flow on P_7, a graph with a negative weight, the Choi matrix of the quantum square, and the generator of a random walk on a weighted triangle (section 6), - the numbers N, E, c, beta_1, tau of several quantum graphs, and the quantum star (section 7), - spectra, the degree bounds for K_1,3, the incidence matrix of C_4, the spanning trees of C_4 and K_4, the Cayley formula, and the Cheeger constant of 2 triangles joined by an edge (section 8), - the Hoffman bounds of several regular quantum graphs, an interlacing example, and the coloring of the quantum torus over M_3 by the eigenspaces of U Lambda (section 9), - the spectra of the simple quantum graphs over M_2 (section 10), - the triangles of K_4, the octahedron, and the eigenvalue histogram of X(30,1/2) (section 11), - an electrical network, with its currents, resistances and Foster sum, a stationary distribution, the Thomson principle, the transfer current theorem on C_4, max-flow min-cut, and the convergence of quantum random walks (section 12). Results are written to pictures.log. """ import itertools import collections from math import comb import numpy as np from qspace import QSpace, Logger, close, weyl, ad rng = np.random.default_rng(30) log = Logger("pictures.log") om3 = np.exp(2j * np.pi / 3) def spec(M, nd=6): return np.sort(np.round(np.linalg.eigvals(M).real, nd)) def mult(vals): out = [] for v in vals: v = 0.0 if abs(v) < 1e-9 else round(float(v), 4) if out and abs(out[-1][0] - v) < 1e-6: out[-1][1] += 1 else: out.append([v, 1]) return out # ---------------------------------------------------------------- section 1 log("=== section 1: finite quantum spaces with N <= 10 points") def square_partitions(N, maxn=None): if maxn is None: maxn = int(np.sqrt(N)) if N == 0: yield [] return for n in range(min(maxn, int(np.sqrt(N))), 0, -1): for rest in square_partitions(N - n * n, n): yield [n] + rest for N in range(1, 11): spaces = [] for p in square_partitions(N): ones = p.count(1) parts = [f"M_{n}" for n in p if n > 1] name = ([f"C^{ones}"] if ones > 1 else (["C"] if ones == 1 else [])) + parts spaces.append(" + ".join(reversed(name)) if False else " + ".join(name)) log(f" N = {N}: {len(spaces)} spaces: {', '.join(spaces)}") log("--- operations on quantum spaces: V = M_2, W = C + C") prod_blocks = sorted(a * b for a in [2] for b in [1, 1]) log(f" V u W has blocks [2, 1, 1], with |V u W| = {4 + 1 + 1}, and V x W has blocks {prod_blocks}, " f"with |V x W| = {sum(b * b for b in prod_blocks)} = 4 x 2") q12 = QSpace([1, 2]) log(f" canonical trace on C + M_2: psi(1) = {q12.psi(q12.one()).real:g}, and mu mu^* = 1: " f"{np.allclose(q12.mu() @ q12.mu_star(), np.eye(q12.N))}") log("--- canonical trace on C + M_2 + M_3: psi(1_r) = n_r^2 on each block") q123 = QSpace([1, 2, 3]) ones = q123.to_blocks(q123.one()) log(" psi of the block units: " + ", ".join(f"{q123.psi(q123.to_vec([o if k == r else 0 * o for k, o in enumerate(ones)])).real:g}" for r in range(3)) + f", total {q123.psi(q123.one()).real:g}") # ---------------------------------------------------------------- section 2 log("=== section 2: the simplex J - 1 over M_3, in the basis e_11, e_12, e_13, e_21, ...") q3 = QSpace([3]) S3 = q3.simplex() vals = sorted(set(np.round(S3.real.flatten(), 6))) log(f" real: {np.allclose(S3.imag, 0)}, values taken: {[float(v) for v in vals]}") diag3 = [q3.pos[(0, a, a)] for a in range(3)] rs = S3.real.sum(1) log(f" row sums: {[int(round(rs[i])) for i in range(9)]}, 8 at the diagonal points and -1 elsewhere; " f"degree (J-1)(1) = 8 * 1: {np.allclose(S3 @ q3.one(), 8 * q3.one())}") for i in range(9): log(" " + " ".join(f"{int(round(S3[i, j].real)):3d}" for j in range(9))) # ---------------------------------------------------------------- section 3 log("=== section 3: Catalan and Fuss-Catalan numbers, by counting noncrossing partitions") def noncrossing(points): """all noncrossing partitions of the ordered list points, as lists of blocks""" if not points: yield [] return first, rest = points[0], points[1:] # the block of first is {first} + a subset S of rest; the gaps between consecutive # elements of the block are filled independently, by noncrossing partitions for r in range(len(rest) + 1): for S in itertools.combinations(range(len(rest)), r): idx = [-1] + list(S) + [len(rest)] gaps = [rest[idx[i] + 1:idx[i + 1]] for i in range(len(idx) - 1)] block = [first] + [rest[i] for i in S] for parts in itertools.product(*[list(noncrossing(g)) for g in gaps]): yield [block] + [b for p in parts for b in p] catalan = lambda m: comb(2 * m, m) // (m + 1) fix_S, fix_FC, end_S, end_FC = [], [], [], [] for k in range(1, 6): for m, lS, lF in [(k, fix_S, fix_FC), (2 * k, end_S, end_FC)]: NC = list(noncrossing(list(range(m)))) lS.append(len(NC)) # pairs sigma <= pi of noncrossing partitions: sigma restricts to a noncrossing partition of each block of pi lF.append(sum(int(np.prod([catalan(len(b)) for b in pi])) for pi in NC)) log(f" k = 1..5, Fix, S_V^+ (noncrossing partitions of k points): {fix_S}") log(f" k = 1..5, Fix, G^+(X_W) (pairs sigma <= pi of noncrossing partitions): {fix_FC}") log(f" k = 1..5, End, S_V^+ (noncrossing partitions of 2k points): {end_S}") log(f" k = 1..5, End, G^+(X_W) (pairs sigma <= pi, 2k points): {end_FC}") log(f" agreement with C_k, binom(3k,k)/(2k+1), C_2k, binom(6k,2k)/(4k+1): " f"{fix_S == [catalan(k) for k in range(1, 6)] and fix_FC == [comb(3 * k, k) // (2 * k + 1) for k in range(1, 6)] and end_S == [catalan(2 * k) for k in range(1, 6)] and end_FC == [comb(6 * k, 2 * k) // (4 * k + 1) for k in range(1, 6)]}") log("--- the fibration with 3 fibers of size 3, and the diagonal inclusion C^3 in M_3") fib = np.kron(np.eye(3), np.ones((3, 3))) log(f" d_W = 1_3 x J_3: 3 triangles with loops, spectrum {mult(spec(fib))}") EW = np.zeros((9, 9)) for a in range(3): EW[4 * a, 4 * a] = 1 log(f" E_W for C^3 in M_3 is the projection onto the diagonal: idempotent {np.allclose(EW @ EW, EW)}, " f"E_W o E_W = E_W/3: {np.allclose(q3.schur_fast(EW, EW), EW / 3)}, so d_W = 3E_W has loops 3 on the e_aa") log("--- S_{M_2}^+ = SO_3: conjugation by a unitary rotates the Pauli vector, and fixes 1") th = 0.7 W = np.array([[np.cos(th / 2), -1j * np.sin(th / 2)], [-1j * np.sin(th / 2), np.cos(th / 2)]]) pauli = [np.array([[0, 1], [1, 0]]), np.array([[0, -1j], [1j, 0]]), np.array([[1, 0], [0, -1]])] R = np.array([[np.trace(P @ W @ Q @ W.conj().T).real / 2 for Q in pauli] for P in pauli]) log(f" rotation matrix in SO_3: {np.allclose(R @ R.T, np.eye(3)) and np.isclose(np.linalg.det(R), 1)}, " f"fixes sigma_x: {np.allclose(R[:, 0], [1, 0, 0])}") log("--- colors: K_4 with a perfect matching colored a, and the 4-cycle colored b") D = np.zeros((4, 4)) for i, j, c in [(0, 2, 1), (1, 3, 1), (0, 1, 2), (1, 2, 2), (2, 3, 2), (3, 0, 2)]: D[i, j] = D[j, i] = c P1, P2 = (D == 1).astype(float), (D == 2).astype(float) log(f" d = 1 p_1 + 2 p_2, with p_1 = 2K_2 and p_2 = C_4: {np.allclose(D, P1 + 2 * P2)}, " f"p_1 o p_2 = 0: {np.allclose(P1 * P2, 0)}") # ---------------------------------------------------------------- section 4 log("=== section 4: Weyl matrices U_g = U^g1 Lambda^g2 for n = 3, nonzero entries (row, col, phase exponent)") for g in itertools.product(range(3), repeat=2): M = weyl(3, g) ent = [] for a in range(3): for b in range(3): if abs(M[a, b]) > 1e-9: k = int(round(np.angle(M[a, b]) / (2 * np.pi / 3))) % 3 ent.append((a, b, k)) log(f" g = {g}: {ent}") for n, S, name in [(7, [(1, 0), (6, 0), (0, 1), (0, 6)], "quantum torus"), (7, [(1, 0), (6, 0), (0, 1), (0, 6), (0, 2), (0, 5), (2, 1), (5, 6)], "rigid S")]: om = np.exp(2j * np.pi / n) F = np.array([[sum(om ** ((g[1] * h1 - g[0] * h2) % n) for g in S).real for h2 in range(n)] for h1 in range(n)]) log(f" eigenvalue landscape F(h1,h2) over Z_{n}^2, {name}, rows h1, columns h2:") for h1 in range(n): log(" " + " ".join(f"{F[h1, h2]:7.3f}" for h2 in range(n))) distinct = len(set(np.round(F.flatten(), 6))) log(f" number of distinct eigenvalues: {distinct}, symmetric under h1 <-> h2: {np.allclose(F, F.T)}") log("--- the quantum torus over M_3 in the multimatrix basis") qT = QSpace([3]) dT = sum(ad(qT, weyl(3, g)) for g in [(1, 0), (2, 0), (0, 1), (0, 2)]) ok = True for a in range(3): for b in range(3): col = dT[:, qT.pos[(0, a, b)]] expect = np.zeros(9, dtype=complex) expect[qT.pos[(0, (a + 1) % 3, (b + 1) % 3)]] += 1 expect[qT.pos[(0, (a - 1) % 3, (b - 1) % 3)]] += 1 expect[qT.pos[(0, a, b)]] += 2 * np.cos(2 * np.pi * (a - b) / 3) ok &= np.allclose(col, expect) log(f" d(e_ab) = e_(a+1,b+1) + e_(a-1,b-1) + 2cos(2pi(a-b)/3) e_ab: {ok}, so loops 2 on the diagonal, -1 elsewhere") log(f" spectrum: {mult(spec(dT))}, the spectrum of the rook's graph K_3 [] K_3") rook = np.zeros((9, 9)) for x in range(9): for y in range(9): if x != y and (x // 3 == y // 3 or x % 3 == y % 3): rook[x, y] = 1 log(f" rook's graph spectrum: {mult(spec(rook))}") log("--- the Weyl cycle over M_4 in the multimatrix basis") q4 = QSpace([4]) dW = ad(q4, weyl(4, (1, 0))) + ad(q4, weyl(4, (3, 0))) ok = all(np.allclose(dW[:, q4.pos[(0, a, b)]], np.eye(16)[q4.pos[(0, (a + 1) % 4, (b + 1) % 4)]] + np.eye(16)[q4.pos[(0, (a - 1) % 4, (b - 1) % 4)]]) for a in range(4) for b in range(4)) log(f" d(e_ab) = e_(a+1,b+1) + e_(a-1,b-1): {ok}, so 4 cycles, indexed by b - a modulo 4") log("--- K_2 x K_4 is the cube Q_3, and K_2 [] K_4 is the prism over K_4") def adj(n, edges): A = np.zeros((n, n)) for i, j in edges: A[i, j] = A[j, i] = 1 return A K2, K4 = adj(2, [(0, 1)]), np.ones((4, 4)) - np.eye(4) dir_ = np.kron(K2, K4) cart = np.kron(K2, np.eye(4)) + np.kron(np.eye(2), K4) cube = adj(8, [(a, b) for a in range(8) for b in range(8) if a < b and bin(a ^ b).count("1") == 1]) iso = any(np.allclose(dir_[np.ix_(p, p)], cube) for p in map(list, itertools.permutations(range(8)))) log(f" K_2 x K_4 isomorphic to the cube: {iso}, spectrum {mult(spec(dir_))}; K_2 [] K_4: {int(cart.sum() / 2)} edges, " f"spectrum {mult(spec(cart))}") log("--- C_5 o K_2, and the complement of 3K_3, which is K_{3,3,3}") C5 = adj(5, [(i, (i + 1) % 5) for i in range(5)]) lex = np.kron(C5, np.ones((2, 2))) + np.kron(np.eye(5), K2) log(f" C_5 o K_2: {int(lex.sum() / 2)} edges, regular of valence {int(lex.sum(1)[0])}") K333 = np.ones((9, 9)) - np.kron(np.eye(3), np.ones((3, 3))) log(f" K_333: spectrum {mult(spec(K333))}, the same as J - 3E over M_3") log("--- the 2-cocycle theta(g,h) = omega^(g_2 h_1) on Z_3^2, with U_g U_h = theta(g,h) U_(g+h)") G3 = [(a, b) for a in range(3) for b in range(3)] ok = all(np.allclose(weyl(3, g) @ weyl(3, h), om3 ** (g[1] * h[0]) * weyl(3, ((g[0] + h[0]) % 3, (g[1] + h[1]) % 3))) for g in G3 for h in G3) log(f" verified: {ok}; exponents g_2 h_1 mod 3, rows g, columns h, in the order {G3}:") for g in G3: log(" " + " ".join(str(g[1] * h[0] % 3) for h in G3)) log("--- Ad_U_(1,1) on M_3: e_ab -> omega^(a-b) e_(a+1,b+1)") A11 = ad(q3, weyl(3, (1, 1))) ok = True for a in range(3): for b in range(3): x = np.zeros((3, 3), dtype=complex); x[a, b] = 1 y = np.zeros((3, 3), dtype=complex); y[(a + 1) % 3, (b + 1) % 3] = om3 ** (a - b) ok &= np.allclose(q3.to_blocks(A11 @ q3.to_vec([x]))[0], y) log(f" verified: {ok}") log("--- the complement of C_6, which is the prism K_3 [] K_2, and the colored Cayley graph of Z_2^2") C6c = np.ones((6, 6)) - np.eye(6) - adj(6, [(i, (i + 1) % 6) for i in range(6)]) prism = adj(6, [(0, 2), (2, 4), (4, 0), (1, 3), (3, 5), (5, 1), (0, 3), (1, 4), (2, 5)]) H2 = C6c @ C6c log(f" complement of C_6 = 2 triangles 135, 246 and 3 diameters: {np.allclose(C6c, prism)}, rows distinct " f"{len({tuple(r) for r in C6c}) == 6}, row sums {sorted(set(int(x) for x in C6c.sum(1)))}, H^2 diagonal " f"{sorted(set(int(x) for x in np.diag(H2)))}, off-diagonal {sorted({int(H2[i, j]) for i in range(6) for j in range(6) if i != j})}") Kl = np.array([[0, 1, 2, 3], [1, 0, 3, 2], [2, 3, 0, 1], [3, 2, 1, 0]]) log(f" K_4 with matchings 0a,bc colored 1, 0b,ac colored 2, 0c,ab colored 3: eigenvalues {[int(round(x)) for x in np.linalg.eigvalsh(Kl)]}") # ---------------------------------------------------------------- section 5 log("=== section 5: closed walks c_k = Tr(d^k) of the simple quantum graphs over M_2") q2 = QSpace([2]) sx = np.array([[0, 1], [1, 0]], dtype=complex) sy = np.array([[0, -1j], [1j, 0]]) sz = np.array([[1, 0], [0, -1]], dtype=complex) M2graphs = [("empty", 0 * q2.identity()), ("Ad_sx", ad(q2, sx)), ("quantum square", ad(q2, sx) + ad(q2, sz)), ("simplex", q2.simplex())] for name, d in M2graphs: ck = [int(round(np.trace(np.linalg.matrix_power(d, k)).real)) for k in range(1, 7)] log(f" {name}: spectrum {mult(spec(d))}, c_1..c_6 = {ck}") log("--- K_4, with its center 0, drawn in the plane, and with the cyclic order at the center reversed") from diagrams import hom, genus, random_undirected_real K4 = {0: ["a", "b", "c"], 1: ["a", "z", "x"], 2: ["b", "x", "y"], 3: ["c", "y", "z"]} K4t = dict(K4) K4t[0] = ["c", "b", "a"] for blocks in [[1, 1, 1, 1], [2], [1, 2]]: q = QSpace(blocks) d = random_undirected_real(q) h0, h1 = hom(q, d, K4).real, hom(q, d, K4t).real log(f" V with blocks {blocks}: genus {genus(K4)} value {h0.real:.10g}, genus {genus(K4t)} value {h1.real:.10g}, " f"equal {np.isclose(h0, h1)}") log("--- distances in the cube from a vertex, and the spectra of C_6 and C_5") layers = collections.Counter(bin(v).count("1") for v in range(8)) log(f" layers at distance 0,1,2,3: {[layers[k] for k in range(4)]}") C6 = adj(6, [(i, (i + 1) % 6) for i in range(6)]) log(f" C_6: {mult(spec(C6))}, symmetric; C_5: {mult(spec(C5))}, not symmetric") log("--- the star K_1,3: eigenvector x of -sqrt 3, and |x|") S13 = adj(4, [(0, 1), (0, 2), (0, 3)]) xs = np.array([np.sqrt(3), -1, -1, -1]) log(f" d x = -sqrt3 x {np.allclose(S13 @ xs, -np.sqrt(3) * xs)}, d|x| = sqrt3 |x| {np.allclose(S13 @ abs(xs), np.sqrt(3) * abs(xs))}, " f"x_+ on the center, x_- on the leaves, d x_+ = sqrt3 x_- {np.allclose(S13 @ np.clip(xs, 0, None), np.sqrt(3) * np.clip(-xs, 0, None))}") log("--- walks of length 2 in the square C_4, from vertex 1 to the opposite vertex 3") C4 = adj(4, [(0, 1), (1, 2), (2, 3), (3, 0)]) log(f" (d^2)_13 = {int((C4 @ C4)[0, 2])}, (d^2)_11 = {int((C4 @ C4)[0, 0])}") # ---------------------------------------------------------------- section 6 log("=== section 6: heat traces Tr(exp(-tL)), at t = 0, 0.1, ..., 1.5") graphs6 = [("simplex over M_2", q2, q2.simplex()), ("quantum square", q2, ad(q2, sx) + ad(q2, sz)), ("Weyl cycle over M_3", q3, ad(q3, weyl(3, (1, 0))) + ad(q3, weyl(3, (2, 0))))] for name, q, d in graphs6: L = q.laplacian(d) ev = np.linalg.eigvals(L).real pts = " ".join(f"({t:.1f},{np.sum(np.exp(-t * ev)):.3f})" for t in np.arange(0, 1.51, 0.1)) log(f" {name}: Laplacian spectrum {mult(np.sort(ev))}") log(f" {pts}") log("--- 3 heat flows on M_2, acting on the Pauli matrices, at t = 0.25") t = 0.25 for name, d in [("simplex (depolarizing)", q2.simplex()), ("quantum square", ad(q2, sx) + ad(q2, sz)), ("Ad_sigma_x (dephasing)", ad(q2, sx))]: L = q2.laplacian(d) w, V = np.linalg.eig(L) E = V @ np.diag(np.exp(-t * w)) @ np.linalg.inv(V) radii = [] for P in [sx, sy, sz]: img = q2.to_blocks(E @ q2.to_vec([P]))[0] coef = np.trace(img @ P).real / 2 radii.append(round(float(coef), 4)) assert np.allclose(img, coef * P) log(f" {name}: Bloch axes x, y, z scaled by {radii}") log("--- the Laplacian of a bump on the path Z: f_i = exp(-i^2/4), (Lf)_i = 2f_i - f_(i-1) - f_(i+1), i = -4..4") fb = {i: np.exp(-i * i / 4) for i in range(-5, 6)} log(" f: " + " ".join(f"{fb[i]:.3f}" for i in range(-4, 5))) log(" Lf: " + " ".join(f"{2 * fb[i] - fb[i - 1] - fb[i + 1]:.3f}" for i in range(-4, 5))) log("--- classical Laplacian spectra: K_N, C_N, the hypercube, the path P_7, and the heat kernel on Z") from scipy.special import ive from scipy.linalg import expm as _expm lap = lambda A: np.diag(A.sum(1)) - A KN = np.ones((6, 6)) - np.eye(6) CN = adj(7, [(i, (i + 1) % 7) for i in range(7)]) cube4 = np.array([[1.0 if bin(i ^ j).count("1") == 1 else 0 for j in range(16)] for i in range(16)]) P7 = adj(7, [(i, i + 1) for i in range(6)]) okK = np.allclose(np.sort(np.linalg.eigvalsh(lap(KN))), [0] + [6] * 5) okC = np.allclose(np.sort(np.linalg.eigvalsh(lap(CN))), np.sort([2 - 2 * np.cos(2 * np.pi * k / 7) for k in range(7)])) okQ = np.allclose(np.sort(np.linalg.eigvalsh(lap(cube4))), np.sort([2 * k for k in range(5) for _ in range(comb(4, k))])) evP7 = np.sort(np.linalg.eigvalsh(lap(P7))) okP = np.allclose(evP7, np.sort([2 - 2 * np.cos(np.pi * k / 7) for k in range(7)])) R = 150 Z = adj(2 * R + 1, [(i, i + 1) for i in range(2 * R)]) okZ, var = True, [] for t in [1.0, 3.0]: row = _expm(-t * lap(Z))[R] ks = np.arange(-20, 21) okZ &= np.allclose(row[R + ks], ive(np.abs(ks), 2 * t), atol=1e-12) # ive(k, x) = exp(-x) I_k(x) var.append(round(float(sum(row[R + k] * k * k for k in range(-R, R + 1))) / t, 6)) omN = np.exp(2j * np.pi / 7) okF = all(np.allclose(_expm(-t * lap(CN)), np.real(np.array([[sum(np.exp(-t * (2 - 2 * np.cos(2 * np.pi * k / 7))) * omN ** (k * (i - j)) for k in range(7)) / 7 for j in range(7)] for i in range(7)]))) for t in [0.4, 2.0]) ret = [float(_expm(-t * lap(CN))[0, 0]) for t in [0.5, 1, 2, 4, 8, 16]] okR = all(a > b for a, b in zip(ret, ret[1:])) and abs(ret[-1] - 1 / 7) < 1e-3 log(f" C_7: heat kernel via Fourier {okF}, return probabilities decreasing to 1/7 {okR}") log(f" K_6: 0, 6^5 {okK}; C_7: 2 - 2cos(2pi k/7) {okC}; Q_4: 2k with multiplicity binom(4,k) {okQ}; " f"P_7: 2 - 2cos(pi k/7) {okP}, lambda_2 = {evP7[1]:.4f}; Z: (e^-tL)_0k = e^-2t I_k(2t) {okZ}, variance/t = {var}") log("--- heat flow on the path P_7, starting from a unit mass at the middle vertex") P7 = adj(7, [(i, i + 1) for i in range(6)]) L7 = np.diag(P7.sum(1)) - P7 f0 = np.zeros(7); f0[3] = 1 for tt in [0, 0.5, 2, 8]: w7, V7 = np.linalg.eigh(L7) ft = V7 @ np.diag(np.exp(-tt * w7)) @ V7.T @ f0 log(f" t = {tt:g}: " + " ".join(f"{round(v, 3) + 0.0:.3f}" for v in ft) + f", total mass {ft.sum():.3f}") log("--- a negative weight: d_12 = d_23 = 1, d_13 = -1/5, entries of exp(-tL) at t = 0, 0.1, ..., 2") dn = np.array([[0, 1, -0.2], [1, 0, 1], [-0.2, 1, 0]]) Ln = np.diag(dn.sum(1)) - dn wn, Vn = np.linalg.eigh(Ln) for (i, j) in [(0, 2), (0, 1)]: vals = [(Vn @ np.diag(np.exp(-tt * wn)) @ Vn.T)[i, j] for tt in np.arange(0, 2.01, 0.1)] log(f" entry ({i + 1},{j + 1}): " + " ".join(f"{round(v, 4) + 0.0:.4f}" for v in vals)) log("--- the Choi matrix of the quantum square, C = sum_ab e_ab x d(e_ab)") dq = ad(q2, sx) + ad(q2, sz) C = np.zeros((4, 4), dtype=complex) for a in range(2): for b in range(2): x = np.zeros((2, 2), dtype=complex); x[a, b] = 1 C += np.kron(x, q2.to_blocks(dq @ q2.to_vec([x]))[0]) log(" real entries, rows: " + " | ".join(" ".join(f"{int(round(v.real)):2d}" for v in row) for row in C)) log(f" eigenvalues {mult(np.sort(np.linalg.eigvalsh(C)))}, so C >= 0, of rank 2 = number of Kraus operators") log("--- a weighted triangle, d_12 = 1, d_13 = 2, d_23 = 3: the generator -L of the continuous time random walk") dT3 = np.array([[0, 1, 2], [1, 0, 3], [2, 3, 0]], dtype=float) LT3 = np.diag(dT3.sum(1)) - dT3 log(" -L rows: " + " | ".join(" ".join(f"{int(v):2d}" for v in row) for row in -LT3) + f", row sums {(-LT3).sum(1)}") # ---------------------------------------------------------------- section 7 log("=== section 7: N, E, c, beta_1 = E - N + c, tau") def invariants(q, d): N = q.N E = q.psi(d @ q.one()).real / 2 L = q.laplacian(d) ev = np.sort(np.linalg.eigvals(L).real) c = int(np.sum(np.abs(ev) < 1e-9)) tau = np.prod(ev[np.abs(ev) > 1e-9]) / N if c == 1 else None return N, E, c, E - N + c, tau def bipartite_complete(qv, qw): """K_{V,W} over the disjoint union, d(x,y) = (psi_W(y)1, psi_V(x)1)""" q = QSpace(qv.blocks + qw.blocks) nv = qv.N d = np.zeros((q.N, q.N), dtype=complex) psiv = np.array([qv.psi(np.eye(nv)[j]) for j in range(nv)]) psiw = np.array([qw.psi(np.eye(qw.N)[j]) for j in range(qw.N)]) d[:nv, nv:] = np.outer(qv.one(), psiw) d[nv:, :nv] = np.outer(qw.one(), psiv) return q, d qtor = (q3, dT) q1 = QSpace([1]) examples7 = [("quantum square", q2, ad(q2, sx) + ad(q2, sz)), ("simplex over M_2", q2, q2.simplex()), ("quantum star K_1,M_2", *bipartite_complete(q1, q2)), ("K_M2,M2", *bipartite_complete(q2, q2)), ("Weyl cycle over M_3", q3, ad(q3, weyl(3, (1, 0))) + ad(q3, weyl(3, (2, 0)))), ("quantum torus over M_3", q3, dT)] for name, q, d in examples7: N, E, c, b1, tau = invariants(q, d) log(f" {name}: N = {N}, E = {E:g}, c = {c}, beta_1 = {b1:g}, tau = {tau if tau is None else round(tau, 6)}") N, E, c, b1, tau = invariants(QSpace([1] * 9), rook) log(f" rook's graph K_3 [] K_3: N = {N}, E = {E:g}, c = {c}, beta_1 = {b1:g}, tau = {round(tau, 6)}") log("--- the quantum star K_{1,M_2}: d(x,y) = (psi_W(y), psi_V(x) 1), in the basis f, e_11, e_12, e_21, e_22") star = np.zeros((5, 5)) q4 = QSpace([1, 2]) for j in range(5): v = np.zeros(5); v[j] = 1 x, y = v[0], v[1:].reshape(2, 2) out = np.zeros(5) out[0] = 2 * np.trace(y).real out[1], out[4] = x, x star[:, j] = out log(" matrix rows: " + " | ".join(" ".join(f"{int(v)}" for v in row) for row in star)) log(f" undirected (adjoint w.r.t. psi): {np.allclose(q4.adjoint(star), star)}, Laplacian spectrum of K_1,4: " f"{mult(spec(q4.laplacian(star)))}") # ---------------------------------------------------------------- section 8 log("=== section 8: spectra") J3 = q3.J() E3 = q3.matrix_of(lambda x: [np.diag(np.diag(x[0]))]) examples8 = [("quantum square", ad(q2, sx) + ad(q2, sz)), ("simplex over M_2", q2.simplex()), ("Weyl cycle over M_3", ad(q3, weyl(3, (1, 0))) + ad(q3, weyl(3, (2, 0)))), ("quantum torus over M_3", dT), ("J - 3E over M_3", J3 - 3 * E3), ("simplex over M_3", q3.simplex())] for name, d in examples8: log(f" {name}: {mult(spec(d))}") log("--- Cayley formula tau(K_V) = N^(N-2)") for blocks in [[1, 1, 1], [2], [1, 2], [2, 2], [3]]: q = QSpace(blocks) N, E, c, b1, tau = invariants(q, q.simplex()) log(f" V blocks {blocks}: N = {N}, tau = {tau:.6g}, N^(N-2) = {N ** (N - 2)}, equal: {np.isclose(tau, N ** (N - 2))}") log("--- Cheeger: 2 triangles joined by an edge, p = one triangle") Lb = np.zeros((6, 6)) for i, j in [(0, 1), (1, 2), (0, 2), (3, 4), (4, 5), (3, 5), (2, 3)]: Lb[i, i] += 1; Lb[j, j] += 1; Lb[i, j] -= 1; Lb[j, i] -= 1 lam = np.sort(np.linalg.eigvalsh(Lb)) best = min((sum(1 for i, j in [(0, 1), (1, 2), (0, 2), (3, 4), (4, 5), (3, 5), (2, 3)] if (i in S) != (j in S)) / len(S), S) for r in range(1, 4) for S in itertools.combinations(range(6), r)) log(f" Laplacian spectrum {[round(float(x), 4) for x in lam]}, h(X) = {best[0]:.4f} at {best[1]}, " f"lambda_2 = {lam[1]:.4f} <= 2h = {2 * best[0]:.4f}: {lam[1] <= 2 * best[0]}") log("--- spanning trees of C_4 and of K_4, by brute force") def spanning_trees(n, edges): out = [] for S in itertools.combinations(edges, n - 1): parent = list(range(n)) def find(x): while parent[x] != x: x = parent[x] return x okk = True for i, j in S: ri, rj = find(i), find(j) if ri == rj: okk = False; break parent[ri] = rj if okk: out.append(S) return out eC4 = [(0, 1), (1, 2), (2, 3), (3, 0)] eK4 = [(i, j) for i in range(4) for j in range(i + 1, 4)] tC4, tK4 = spanning_trees(4, eC4), spanning_trees(4, eK4) log(f" C_4: {len(tC4)} spanning trees, K_4: {len(tK4)} spanning trees, = 4^2") log(" the spanning trees of K_4, as edge lists: " + " ".join("".join(f"{i}{j}." for i, j in T) for T in tK4)) log("--- the star K_1,3: average degree <= lambda_max <= maximal degree") S13 = adj(4, [(0, 1), (0, 2), (0, 3)]) log(f" average degree {S13.sum() / 4:g}, lambda_max = {spec(S13)[-1]:.4f} = sqrt 3, maximal degree {int(S13.sum(1).max())}") log("--- the oriented incidence matrix of C_4, with edges 12, 23, 34, 41, and L = B^t B") Binc = np.zeros((4, 4)) for k, (i, j) in enumerate([(0, 1), (1, 2), (2, 3), (3, 0)]): Binc[k, i], Binc[k, j] = 1, -1 log(" B rows: " + " | ".join(" ".join(f"{int(v):2d}" for v in row) for row in Binc)) log(f" B^t B = L: {np.allclose(Binc.T @ Binc, np.diag(C4.sum(1)) - C4)}") # ---------------------------------------------------------------- section 9 log("=== section 9: Hoffman bounds 1 - k/lmin and -N lmin/(k - lmin)") for name, q, d in [("quantum square", q2, ad(q2, sx) + ad(q2, sz)), ("J - 3E over M_3", q3, J3 - 3 * E3), ("quantum torus over M_3", q3, dT), ("simplex over M_2", q2, q2.simplex()), ("simplex over M_3", q3, q3.simplex())]: ev = spec(d) k = (d @ q.one())[0].real lmin = ev[0] log(f" {name}: k = {k:g}, lambda_min = {lmin:g}, chi >= {1 - k / lmin:g}, alpha <= {-q.N * lmin / (k - lmin):g}") log("--- Hoffman, interlacing: the square C_4 with its coloring {1,3}, {2,4}, and the compressed matrix C = S^* d S") Smat = np.zeros((4, 2)); Smat[[0, 2], 0] = 1 / np.sqrt(2); Smat[[1, 3], 1] = 1 / np.sqrt(2) Cc = Smat.T @ C4 @ Smat log(f" C = {Cc.round(6).tolist()}, eigenvalues {mult(spec(Cc))}, interlacing those of C_4, {mult(spec(C4))}") log("--- the quantum torus over M_3: U and Lambda permute the eigenspaces of W = U Lambda") U3, L3 = weyl(3, (1, 0)), weyl(3, (0, 1)) w3, v3 = np.linalg.eig(U3 @ L3) om3 = np.exp(2j * np.pi / 3) up = all(np.allclose(U3 @ L3 @ (U3 @ v3[:, j]), om3 * w3[j] * (U3 @ v3[:, j])) for j in range(3)) down = all(np.allclose(U3 @ L3 @ (L3 @ v3[:, j]), w3[j] / om3 * (L3 @ v3[:, j])) for j in range(3)) log(f" eigenvalues of W distinct {len(set(np.round(w3, 6))) == 3}, U multiplies them by omega {up}, Lambda by omega^-1 {down}") # ---------------------------------------------------------------- section 10 log("=== section 10: the simple quantum graphs over M_2, by number of quantum edges m") for m, (name, d) in enumerate(M2graphs): E = q2.psi(d @ q2.one()).real / 2 log(f" m = {m}, {name}: simple {close(q2.schur_fast(d, d), d)}, E = {E:g}, spectrum {mult(spec(d))}") # ---------------------------------------------------------------- section 11 log("=== section 11: eigenvalue histogram of the random quantum graph X(30,1/2)") def gell_mann(n): basis = [] for a in range(n): for b in range(a + 1, n): X = np.zeros((n, n), dtype=complex) X[a, b] = X[b, a] = 1 basis.append(X * np.sqrt(n / 2)) Y = np.zeros((n, n), dtype=complex) Y[a, b], Y[b, a] = -1j, 1j basis.append(Y * np.sqrt(n / 2)) for l in range(1, n): Z = np.zeros((n, n)) Z[:l, :l] = np.eye(l) Z[l, l] = -l basis.append(Z * np.sqrt(n / (l * (l + 1)))) return basis n, p = 30, 0.5 basis = gell_mann(n) D = len(basis) k = int(round(p * D)) Q, _ = np.linalg.qr(rng.normal(size=(D, k))) W = [sum(Q[i, j] * basis[i] for i in range(D)) for j in range(k)] d = sum(np.kron(w, w.T) for w in W) N = n * n ev = np.sort(np.linalg.eigvalsh((d + d.conj().T) / 2)) sigma = np.sqrt(p * (1 - p) * N) bulk = (ev[:-1] + p) / sigma log(f" N = {N}, k = {k}, top eigenvalue {ev[-1]:.2f}, pN = {p * N:g}, bulk rescaled by (x + p)/sqrt(p(1-p)N)") edges = np.linspace(-2.2, 2.2, 23) hist, _ = np.histogram(bulk, bins=edges) dens = hist / (len(bulk) * (edges[1] - edges[0])) log(" histogram (left edge, density): " + " ".join(f"({edges[i]:.1f},{dens[i]:.3f})" for i in range(len(dens)))) xs = np.linspace(-2, 2, 41) log(" semicircle: " + " ".join(f"({x:.1f},{np.sqrt(max(4 - x * x, 0)) / (2 * np.pi):.3f})" for x in xs)) log("--- triangles: K_4 has 4 triangles and c_3 = 24 = 6 x 4; the octahedron K_222 is K_4-free with 12 edges") tri = sum(1 for S in itertools.combinations(range(4), 3)) log(f" triangles of K_4: {tri}, Tr(d^3) = {int(np.trace(np.linalg.matrix_power(np.ones((4, 4)) - np.eye(4), 3)))}") K222 = np.ones((6, 6)) - np.kron(np.eye(3), np.ones((2, 2))) k4free = not any(all(K222[i, j] for i, j in itertools.combinations(S, 2)) for S in itertools.combinations(range(6), 4)) log(f" K_222: {int(K222.sum() / 2)} edges = (1 - 1/3) 6^2 / 2, K_4-free: {k4free}") # ---------------------------------------------------------------- section 12 log("=== section 12: the square a,b,c,d with the diagonal ac, unit conductances, unit current from a to c") Lc = np.array([[3, -1, -1, -1], [-1, 2, -1, 0], [-1, -1, 3, -1], [-1, 0, -1, 2]], dtype=float) # vertices a, b, c, d = 0, 1, 2, 3, edges ab, bc, cd, da, ac x = np.array([1, 0, -1, 0], dtype=float) pot = np.linalg.pinv(Lc) @ x log(f" effective resistance R_ac = {x @ pot:.4f}") Lp = np.linalg.pinv(Lc) foster = 0 for (i, j), name in zip([(0, 1), (1, 2), (2, 3), (3, 0), (0, 2)], ["ab", "bc", "cd", "da", "ac"]): e = np.zeros(4); e[i], e[j] = 1, -1 R = e @ Lp @ e foster += R log(f" current on {name}: {pot[i] - pot[j]:.4f}, effective resistance R_{name} = {R:.4f}") log(f" Foster: sum of the effective resistances over the edges = {foster:.4f} = N - 1") log("--- quantum random walks P(x) = d(1)^(-1/2) d(x) d(1)^(-1/2), distance ||P^m(x) - psi(x)1/N|| for a fixed x") x0 = np.array([[1, 0.3 - 0.2j, 0.1], [0.3 + 0.2j, 0, 0.5j], [0.1, -0.5j, 0.4]]) for name, q, d, x in [("simplex over M_2", q2, q2.simplex(), x0[:2, :2]), ("quantum torus over M_3", q3, dT, x0), ("J - 3E over M_3", q3, J3 - 3 * E3, x0), ("simplex over M_3", q3, q3.simplex(), x0)]: k = (d @ q.one())[0].real P = d / k v = q.to_vec([x]) target = q.psi(v) / q.N * q.one() dist = [] for m in range(0, 9): diff = v - target dist.append(np.sqrt(q.inner(diff, diff).real)) v = P @ v log(f" {name}: valence {k:g}, eigenvalues of P {mult(spec(P))}, distances m = 0..8: " + " ".join(f"{t:.2e}" for t in dist)) log("--- C_4 with unit conductances: effective resistance of an edge = probability that it lies in a random spanning tree") L4 = np.diag(adj(4, eC4).sum(1)) - adj(4, eC4) e01 = np.array([1, -1, 0, 0]) R01 = e01 @ np.linalg.pinv(L4) @ e01 prob = sum(1 for T in tC4 if (0, 1) in T) / len(tC4) log(f" R_e = {R01:.4f}, P(e in T) = {prob:.4f}, Foster sum 4 R_e = {4 * R01:.4f} = N - 1") log("--- max-flow min-cut on s, a, b, t with capacities sa 3, sb 2, ab 1, at 2, bt 3") cap = {("s", "a"): 3, ("s", "b"): 2, ("a", "b"): 1, ("a", "t"): 2, ("b", "t"): 3} cuts = [] for r in range(3): for S in itertools.combinations(["a", "b"], r): side = {"s", *S} cuts.append((sum(c for (u, v), c in cap.items() if u in side and v not in side), sorted(side))) flow = {("s", "a"): 3, ("s", "b"): 2, ("a", "b"): 1, ("a", "t"): 2, ("b", "t"): 3} cons = all(sum(f for (u, v), f in flow.items() if v == x) == sum(f for (u, v), f in flow.items() if u == x) for x in "ab") log(f" cuts {cuts}, min cut {min(cuts)[0]}; flow sa 3, sb 2, ab 1, at 2, bt 3: feasible " f"{cons and all(flow[e] <= cap[e] for e in cap)}, value {flow[('s', 'a')] + flow[('s', 'b')]}") log("--- stationary distribution of the random walk on a triangle with a pendant vertex, proportional to the degrees") Gp = adj(4, [(0, 1), (1, 2), (2, 0), (2, 3)]) Pp = Gp / Gp.sum(1)[:, None] pi = Gp.sum(1) / Gp.sum() log(f" degrees {Gp.sum(1).astype(int).tolist()}, pi = {pi.tolist()}, stationary: {np.allclose(pi @ Pp, pi)}") log("--- Thomson: unit flow from a to c in the square with diagonal ac, energies") cur = {"ab": 0.25, "bc": 0.25, "ad": 0.25, "dc": 0.25, "ac": 0.5} alt = {"ab": 0, "bc": 0, "ad": 0, "dc": 0, "ac": 1} log(f" current flow energy {sum(v * v for v in cur.values()):.4f} = R_ac, diagonal flow energy {sum(v * v for v in alt.values()):.4f}") log.save()