""" extremal.py -- checks the results of section 11. It checks the formula psi((A o B)(1)) = Tr(A^t B), with A^t = (A^*)^#, the formula Tr(d^2) = 2E for simple real undirected quantum graphs, and the formula Tr(d^k) = sum_W |Tr(W)|^2, over the words W in the Kraus operators, for positively weighted quantum graphs. It checks the quantum Mantel theorem, lambda_max^2 <= E and E <= N^2/4, on triangle-free examples, including one where lambda_max has multiplicity 2, and the equality cases d(x) = psi(qx)p + psi(px)q, with p a projection of trace N/2 and q = 1 - p, including the quantum square. Finally, it computes the spectra of random quantum graphs over M_n, given by random subspaces of density p of the traceless self-adjoint matrices, and compares them with the Erdos-Renyi graphs G(N,p), N = n^2: top eigenvalue, center, variance and moments of the bulk. It also checks the clique example over M_4, d = J - 1 - Ad_h with h = diag(1,1,1,-3)/sqrt3, which is simple, real, undirected, positively weighted, without loops and connected, with E = 112, with the cliques being the projections p with php = 0, so that omega = 4, while psi(rho d(rho)) = 7/8 for the uniform density, above 1 - 1/omega = 3/4, and E is above the Turan value 96. Results are written to extremal.log. """ import itertools import numpy as np from qspace import QSpace, Logger, close, ad, weyl, random_matrix log = Logger("extremal.log") rng = np.random.default_rng(13) ok = True for blocks in [[2], [1, 2], [2, 3], [1, 1, 2]]: q = QSpace(blocks) for t in range(5): A, B = random_matrix(q, rng), random_matrix(q, rng) ok &= np.isclose(q.psi(q.schur_fast(A, B) @ q.one()), np.trace(q.sharp(q.adjoint(A)) @ B)) log(f"psi((A o B)(1)) = Tr(A^t B) with A^t = (A^*)^#, for random A, B over 4 spaces: {ok}") def kraus_graph(q, pairs): n, off = q.blocks, np.cumsum([0] + q.blocks) H, Ks = off[-1], [] for r, s in pairs: K = np.zeros((H, H), dtype=complex) K[off[r]:off[r + 1], off[s]:off[s + 1]] = rng.normal(size=(n[r], n[s])) + 1j * rng.normal(size=(n[r], n[s])) Ks += [K, np.sqrt(n[s] / n[r]) * K.conj().T] def f(x): X = np.zeros((H, H), dtype=complex) for r, b in enumerate(x): X[off[r]:off[r + 1], off[r]:off[r + 1]] = b Y = sum(K.conj().T @ X @ K for K in Ks) return [Y[off[r]:off[r + 1], off[r]:off[r + 1]] for r in range(len(n))] return q.matrix_of(f), Ks ok = True for blocks, pairs in [([2], [(0, 0)]), ([1, 2], [(0, 1), (1, 1)]), ([1, 1, 2], [(0, 1), (1, 2), (2, 0)])]: q = QSpace(blocks) d, Ks = kraus_graph(q, pairs) for k in [2, 3, 4]: words = sum(abs(np.trace(np.linalg.multi_dot(w) if k > 1 else w[0])) ** 2 for w in itertools.product(Ks, repeat=k)) ok &= np.isclose(np.trace(np.linalg.matrix_power(d, k)).real, words) log(f"Tr(d^k) = sum over the words W of |Tr(W)|^2, for k = 2,3,4 and random positively weighted graphs: {ok}") def mantel(name, q, d): E = q.psi(d @ q.one()).real / 2 ev = np.sort(np.linalg.eigvals(d).real) c3 = np.trace(d @ d @ d).real log(f"{name}: simple {close(q.schur_fast(d, d), d)}, real undirected {close(q.sharp(d), d) and close(q.adjoint(d), d)}, " f"Tr(d^2) = 2E {np.isclose(np.trace(d @ d).real, 2 * E)}, triangle-free {abs(c3) < 1e-8}, " f"lambda_max^2 = {ev[-1] ** 2:.3f} <= E = {E:.3f}, E <= N^2/4 = {q.N ** 2 / 4:.2f}") q = QSpace([2]) mantel("quantum square", q, ad(q, weyl(2, (1, 0))) + ad(q, weyl(2, (0, 1)))) for blocks in [[2], [1, 2]]: q = QSpace(blocks + blocks) r0 = len(blocks) def f(x): pv = sum(q.blocks[r] * np.trace(x[r]) for r in range(r0)) pw = sum(q.blocks[r] * np.trace(x[r]) for r in range(r0, len(q.blocks))) return [(pw if r < r0 else pv) * np.eye(n) for r, n in enumerate(q.blocks)] mantel(f"K_V,V with V blocks {blocks}", q, q.matrix_of(f)) q = QSpace([2]) mantel("Ad_sigma_x over M_2", q, ad(q, weyl(2, (1, 0)))) sq = ad(q, weyl(2, (1, 0))) + ad(q, weyl(2, (0, 1))) q2 = QSpace([2, 2]) mantel("2 copies of the quantum square, lambda_max of multiplicity 2", q2, np.kron(np.eye(2), sq)) # the equality cases: d(x) = psi(qx)p + psi(px)q, with p a projection of trace psi(p) = N/2, q = 1 - p rng_eq = np.random.default_rng(31) def random_rank(n, r): z = rng_eq.normal(size=(n, n)) + 1j * rng_eq.normal(size=(n, n)) U, _ = np.linalg.qr(z) return U[:, :r] @ U[:, :r].conj().T def is_cp(q, d): """Choi matrices of the block components of d""" for r, nr in enumerate(q.blocks): for t, nt in enumerate(q.blocks): C = np.zeros((nr * nt, nr * nt), dtype=complex) for a in range(nr): for b in range(nr): bl = [np.zeros((n, n), dtype=complex) for n in q.blocks] bl[r][a, b] = 1 E = np.zeros((nr, nr)) E[a, b] = 1 C += np.kron(E, q.to_blocks(d @ q.to_vec(bl))[t]) if np.linalg.eigvalsh((C + C.conj().T) / 2).min() < -1e-9: return False return True eq_ok = True for blocks, ranks in [([2], [1]), ([4], [2]), ([2, 2], [1, 1]), ([1, 1, 2], [1, 0, 1]), ([3, 3], [1, 2])]: q = QSpace(blocks) assert sum(n * r for n, r in zip(blocks, ranks)) * 2 == q.N p = q.to_vec([random_rank(n, r) for n, r in zip(blocks, ranks)]) qq = q.one() - p d = q.matrix_of(lambda x: [q.psi(q.product(qq, q.to_vec(x))) * pb + q.psi(q.product(p, q.to_vec(x))) * qb for pb, qb in zip(q.to_blocks(p), q.to_blocks(qq))]) E = q.psi(d @ q.one()).real / 2 ev = np.sort(np.linalg.eigvals(d).real) eq_ok &= (close(q.schur_fast(d, d), d) and close(q.sharp(d), d) and close(q.adjoint(d), d) and is_cp(q, d) and abs(np.trace(d @ d @ d)) < 1e-8 and np.isclose(E, q.N ** 2 / 4) and np.allclose(ev, sorted([-q.N / 2, q.N / 2] + [0] * (q.N - 2)), atol=1e-8)) log(f"equality cases d(x) = psi(qx)p + psi(px)q, psi(p) = N/2, over M_2, M_4, M_2+M_2, C+C+M_2, M_3+M_3: simple, real, " f"undirected, completely positive, triangle-free, E = N^2/4, spectrum N/2, -N/2, 0, ..., 0: {eq_ok}") p = (np.eye(2) + np.array([[0, -1j], [1j, 0]])) / 2 q = QSpace([2]) pv, qv = q.to_vec([p]), q.to_vec([np.eye(2) - p]) dsq = q.matrix_of(lambda x: [q.psi(q.product(qv, q.to_vec(x))) * p + q.psi(q.product(pv, q.to_vec(x))) * (np.eye(2) - p)]) log(f"the quantum square is of this form, with p = (1 + sigma_y)/2: {close(dsq, sq)}") 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 def random_quantum_graph(n, p): basis = gell_mann(n) D = len(basis) k = int(np.floor(p * D + 0.5)) 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)] return sum(np.kron(w, w.T) for w in W), k for n, p in [(10, 0.5), (20, 0.5), (30, 0.5), (24, 0.2), (24, 0.8)]: d, k = random_quantum_graph(n, p) N = n * n ev = np.sort(np.linalg.eigvalsh((d + d.conj().T) / 2)) bulk = ev[:-1] s = np.sqrt(p * (1 - p) * N) x = (bulk - bulk.mean()) / bulk.std() log(f"random quantum graph, n = {n}, p = {p}: k = {k}, top eigenvalue / pN = {ev[-1] / (p * N):.4f}, " f"bulk center = {bulk.mean():.3f}, bulk std / sqrt(p(1-p)N) = {bulk.std() / s:.4f}, " f"bulk edges / 2sqrt(p(1-p)N) = {bulk.min() / (2 * s):.3f}, {bulk.max() / (2 * s):.3f}, " f"normalized moments m3 = {np.mean(x ** 3):.3f}, m4 = {np.mean(x ** 4):.3f}") # cliques: the reverse Motzkin-Straus and Turan inequalities fail, for a connected graph over M_4 from fractions import Fraction as Fr q = QSpace([4]) h = np.diag([1, 1, 1, -3]) / np.sqrt(3) d = q.simplex() - ad(q, h) I4 = q.identity() choi = sum(np.kron(np.outer(np.eye(4)[a], np.eye(4)[b]), q.to_blocks(d[:, q.pos[(0, a, b)]])[0]) for a in range(4) for b in range(4)) L = q.laplacian(d) props = {"simple": close(q.schur(d, d), d), "real": close(q.sharp(d), d), "undirected": close(q.adjoint(d), d), "without loops": close(q.schur(d, I4), 0 * d), "positively weighted": np.linalg.eigvalsh(choi).min() > -1e-9, "connected": int(np.sum(np.abs(np.linalg.eigvals(L)) < 1e-9)) == 1} props = {k: bool(v) for k, v in props.items()} # d is the graph of the orthogonal complement of h in the traceless self-adjoint matrices basis = [np.diag(v) for v in [[1, -1, 0, 0], [1, 1, -2, 0]]] basis += [np.outer(np.eye(4)[a], np.eye(4)[b]) + np.outer(np.eye(4)[b], np.eye(4)[a]) for a in range(4) for b in range(a + 1, 4)] basis += [1j * (np.outer(np.eye(4)[a], np.eye(4)[b]) - np.outer(np.eye(4)[b], np.eye(4)[a])) for a in range(4) for b in range(a + 1, 4)] ortho = [] for W in basis: for Z in ortho: W = W - np.trace(Z @ W) / 4 * Z W = W - np.trace(h @ W) / 4 * h if np.linalg.norm(W) > 1e-9: ortho.append(2 * W / np.sqrt(np.trace(W @ W).real)) dS = sum(ad(q, W) for W in ortho) E = q.psi(d @ q.one()).real / 2 log(f"M_4, psi = 4 Tr, h = diag(1,1,1,-3)/sqrt3, d = J - 1 - Ad_h: {props}, " f"d = sum of Ad_W over an orthonormal basis of the {len(ortho)}-dimensional complement of h {close(dS, d)}, E = {E:.6f}") def is_clique(p): ok = True for t in range(3): x = rng.normal(size=(4, 4)) + 1j * rng.normal(size=(4, 4)) pxp = p @ x @ p lhs = p @ q.to_blocks(d @ q.to_vec([pxp]))[0] @ p ok &= np.allclose(lhs, 4 * np.trace(pxp) * p - pxp) return ok agree, cl = True, {1: 0, 2: 0, 3: 0} for t in range(300): r = 1 + t % 3 Z = rng.normal(size=(4, r)) + 1j * rng.normal(size=(4, r)) if t % 2 == 0 and r == 1: # isotropic lines of the form (cos, 0, 0, sin) up to rotations z = rng.normal(size=3) + 1j * rng.normal(size=3) z = z / np.linalg.norm(z) * np.sqrt(3) / 2 Z = np.array([[z[0]], [z[1]], [z[2]], [0.5 * np.exp(1j * rng.uniform(0, 7))]]) Qm, _ = np.linalg.qr(Z) p = Qm @ Qm.conj().T c = is_clique(p) agree &= (c == np.allclose(p @ h @ p, 0)) cl[r] += c v = np.array([np.sqrt(3) / 2, 0, 0, 0.5]) pv = np.outer(v, v) sig = np.linalg.eigvalsh(h) log(f" the cliques are the projections p with php = 0 {agree}, cliques found by rank {cl}, signature of h " f"({int(np.sum(sig > 0))},{int(np.sum(sig < 0))}), so the isotropic subspaces are at most lines; " f"(sqrt3/2,0,0,1/2) gives a clique {is_clique(pv)}, of size psi(p) = {4 * np.trace(pv).real:.0f}, so omega = 4") Ex, Nx, om = Fr(112), Fr(16), Fr(4) rho = np.eye(4) / 16 val = q.psi(q.product(q.to_vec([rho]), d @ q.to_vec([rho]))).real log(f" uniform density rho = 1/16: psi(rho d(rho)) = 2E/N^2 = {2 * Ex / Nx ** 2} (numerically {val:.6f}), " f"> 1 - 1/omega = {1 - 1 / om}; Turan bound (1 - 1/omega) N^2/2 = {(1 - 1 / om) * Nx ** 2 / 2} < E = {Ex}") log.save()