""" products.py -- checks the product results of section 4, on the quantum prisms K_2 x S and K_2 [] S, with S the simplex over M_n, and on the lexicographic products C_m o S and m copies of S. For each product, it checks the regularity and connectivity of the factors, the spectral conditions, and that the spectral projections used in the proofs are sums of spectral projections of the product graph. For the prisms it also computes the smallest subspace of M_N(C) containing 1, J, d and stable under the 4 basic operations, which must sit inside End(u) = End(u_X) x End(u_Y), of dimension 4. For C_m o S with 3 | m, where the spectral condition fails, it checks the complement argument: J - 1 - d = H x J_W, with H the complement of C_m, the composition square is |W| H^2 x J_W, and a Hadamard polynomial in it gives 1 x J_W, so 1 x Q_1 is in End(u) for all m >= 5. It also checks that a nonreal simple graph without loops can produce a lexicographic product which is not simple. Results are written to products.log. """ import numpy as np from qspace import QSpace, Logger, close TOL = 1e-8 def product_space(qv, qw): """V x W, with the permutation taking kron(x, y) to the multimatrix basis of V x W""" blocks = [n * m for n in qv.blocks for m in qw.blocks] q = QSpace(blocks) P = np.zeros((q.N, qv.N * qw.N)) for i, (r, a, b) in enumerate(qv.index): for k, (s, c, d) in enumerate(qw.index): m = qw.blocks[s] t = r * len(qw.blocks) + s P[q.pos[(t, a * m + c, b * m + d)], i * qw.N + k] = 1 return q, P def spectrum(q, d): """distinct eigenvalues and spectral projections of an undirected d (d = d^*)""" S = np.sqrt(q.G) @ d @ np.sqrt(q.Ginv) # hermitian in an orthonormal basis w, v = np.linalg.eigh((S + S.conj().T) / 2) vals, projs = [], [] for x in w: if not any(abs(x - y) < TOL for y in vals): vals.append(x) for x in vals: cols = v[:, np.abs(w - x) < TOL] projs.append(np.sqrt(q.Ginv) @ (cols @ cols.conj().T) @ np.sqrt(q.G)) return np.array(vals), projs def regular_connected(q, d): lam = (d @ q.one())[0] vals, projs = spectrum(q, d) k = int(np.argmin(np.abs(vals - lam))) return close(d @ q.one(), lam * q.one()) and close(projs[k], q.J() / q.N), lam def sum_of_projections(q, d, target): """is target a sum of spectral projections of d ?""" vals, projs = spectrum(q, d) T = sum(p for p in projs if close(p @ target, p)) return close(T, target) def closure(q, gens): basis = [] def add(M): v = M.flatten() for b in basis: v = v - np.vdot(b, v) * b if np.linalg.norm(v) > 1e-7: basis.append(v / np.linalg.norm(v)) return True return False for g in gens: add(g) grown = True while grown: grown = False mats = [b.reshape(q.N, q.N) for b in basis] for A in mats: grown |= add(q.adjoint(A)) | add(q.sharp(A)) for B in mats: grown |= add(A @ B) | add(q.schur_fast(A, B)) return len(basis) if __name__ == "__main__": log = Logger("products.log") K2 = QSpace([1, 1]) dK2 = np.array([[0, 1], [1, 0]], dtype=complex) def cycle(m): q = QSpace([1] * m) d = np.zeros((m, m), dtype=complex) for i in range(m): d[i, (i + 1) % m] = d[(i + 1) % m, i] = 1 return q, d for n in [2, 3]: W = QSpace([n]) S = W.simplex() q, P = product_space(K2, W) rng = np.random.default_rng(1) x, y = rng.normal(size=2), rng.normal(size=W.N) x2, y2 = rng.normal(size=2), rng.normal(size=W.N) mult_ok = close(q.product(P @ np.kron(x, y), P @ np.kron(x2, y2)), P @ np.kron(K2.product(x, x2), W.product(y, y2))) psi_ok = np.isclose(q.psi(P @ np.kron(x, y)), K2.psi(x) * W.psi(y)) J_ok = close(P @ np.kron(K2.J(), W.J()) @ P.T, q.J()) log(f"=== V = K_2 points, W = M_{n}, N = {q.N}") log(f" product space: multiplication {mult_ok}, trace {psi_ok}, J = J x J {J_ok}") rcX, lX = regular_connected(K2, dK2) rcY, lY = regular_connected(W, S) vX, _ = spectrum(K2, dK2) vY, _ = spectrum(W, S) log(f" K_2 regular connected {rcX}, spectrum {np.round(vX, 6)}; simplex regular connected " f"{rcY}, spectrum {np.round(vY, 6)}") ratios = lambda v: {round(a / b, 6) for a in v for b in v} diffs = lambda v: {round(a - b, 6) for a in v for b in v} log(f" ratio condition {ratios(vX) & ratios(vY) == {1.0}}, difference condition " f"{diffs(vX) & diffs(vY) == {0.0}}") for name, D in [("direct product", np.kron(dK2, S)), ("Cartesian product", np.kron(dK2, np.eye(W.N)) + np.kron(np.eye(2), S))]: Dq = P @ D @ P.T P1 = P @ np.kron(K2.J() / 2, np.eye(W.N)) @ P.T Q1 = P @ np.kron(np.eye(2), W.J() / W.N) @ P.T dX1 = P @ np.kron(dK2, np.eye(W.N)) @ P.T e1 = P @ np.kron(np.eye(2), S) @ P.T sp = sum_of_projections(q, Dq, P1) and sum_of_projections(q, Dq, Q1) cl = closure(q, [q.identity(), q.J(), Dq]) log(f" {name}: undirected {close(q.adjoint(Dq), Dq)}, P_1 x 1 and 1 x Q_1 spectral {sp}, " f"closure of 1, J, d has dimension {cl}") for n, m in [(2, 5), (2, 7), (3, 5), (2, 6)]: W = QSpace([n]) S = W.simplex() V, dC = cycle(m) q, P = product_space(V, W) vX, _ = spectrum(V, dC) vY, _ = spectrum(W, S) lam1 = W.N - 1 cond = not any(abs((lam1 - l) - (-W.N * mu)) < 1e-6 for l in vY if abs(l - lam1) > 1e-6 for mu in vX) D = P @ (np.kron(dC, W.J()) + np.kron(np.eye(m), S)) @ P.T Q1 = P @ np.kron(np.eye(m), W.J() / W.N) @ P.T eX = P @ np.kron(np.eye(m), S) @ P.T sp = sum_of_projections(q, D, Q1) _, QY = spectrum(W, S) e_ok = all(sum_of_projections(q, D, P @ np.kron(np.eye(m), Qi) @ P.T) for Qi in QY) log(f"=== lexicographic C_{m} o S over M_{n}, N = {q.N}: condition {cond}, " f"1 x Q_1 spectral {sp}, all 1 x Q_i spectral, so 1 x e in End {e_ok}") for n, m in [(2, 5), (2, 6), (2, 9), (3, 6)]: W = QSpace([n]) S = W.simplex() V, dC = cycle(m) q, P = product_space(V, W) D = P @ (np.kron(dC, W.J()) + np.kron(np.eye(m), S)) @ P.T H = np.ones((m, m)) - np.eye(m) - dC.real B = q.J() - q.identity() - D comp = close(B, P @ np.kron(H, W.J()) @ P.T) C = B @ B / W.N sq = close(C, P @ np.kron(H @ H, W.J()) @ P.T) H2 = H @ H off = sorted({round(H2[i, j]) for i in range(m) for j in range(m) if i != j}) diag = {round(H2[i, i]) for i in range(m)} T = q.J() for t in off: # Hadamard polynomial, 1 at m-3, 0 at the other values T = q.schur_fast(T, (C - t * q.J()) / (m - 3 - t)) res = close(T, P @ np.kron(np.eye(m), W.J()) @ P.T) log(f"=== C_{m} o S over M_{n}: J-1-d = H x J_W {comp}, (J-1-d)^2 = |W| H^2 x J_W {sq}, " f"diagonal of H^2 {diag}, off-diagonal values {off}, Hadamard polynomial gives 1 x J_W {res}") # nonreal simple graph without loops, lexicographic product with K_2 W2 = QSpace([2]) I2, S2 = W2.identity(), W2.simplex() y = np.random.default_rng(3).normal(size=(4, 4)) + 1j * np.random.default_rng(4).normal(size=(4, 4)) dn = S2 + W2.schur_fast(W2.schur_fast(I2, y), S2) q, P = product_space(W2, K2) D = P @ (np.kron(dn, K2.J()) + np.kron(I2, dK2)) @ P.T log(f"=== lexicographic product X o K_2, with X = (M_2, (J-1) + 1 o y o (J-1)) simple without loops, " f"not real: X o K_2 simple {close(q.schur_fast(D, D), D)}, without loops " f"{close(q.schur_fast(D, q.identity()), 0 * D)}") for n, m in [(2, 3), (3, 2)]: W = QSpace([n]) S = W.simplex() V = QSpace([1] * m) q, P = product_space(V, W) D = P @ np.kron(np.eye(m), S) @ P.T Q1 = P @ np.kron(np.eye(m), W.J() / W.N) @ P.T log(f"=== {m} copies of S over M_{n}: 1 x Q_1 spectral {sum_of_projections(q, D, Q1)}") log.save()