""" bipartite.py -- checks the bipartiteness results of section 5. For the quantum square on M_2 it checks that s = i U Lambda = sigma_y gives a bipartition. For connected Weyl-Cayley graphs with n = 2,3,4,6, and for random regular quantum graphs d = sum_k (Ad_{W_k} + Ad_{W_k^*}) over M_2, M_4, M_6, with W_k random unitaries, arbitrary or anticommuting with a fixed symmetry, it checks that bipartite, symmetric spectrum, and -lambda eigenvalue are equivalent. It does the same for random non-regular graphs d = sum_k (Ad_{Z_k} + Ad_{Z_k^*}), with Z_k random matrices, arbitrary or anticommuting with a fixed symmetry, and in the bipartite case it reconstructs the bipartition from an eigenvector x of -lambda, as in the proof: d(|x|) = lambda |x|, with |x| invertible, and d(x_+) = lambda x_-, the supports of x_+ and x_- being independent. Results are written to bipartite.log. """ import numpy as np from qspace import QSpace, Logger, close, weyl, ad, random_cp log = Logger("bipartite.log") rng = np.random.default_rng(5) def haar(n): z = rng.normal(size=(n, n)) + 1j * rng.normal(size=(n, n)) Q, R = np.linalg.qr(z) return Q * (np.diag(R) / abs(np.diag(R))) def left(q, a): return q.matrix_of(lambda x: [a @ x[0]]) def connected(q, d): return np.sum(np.abs(np.linalg.eigvals(q.laplacian(d))) < 1e-8) == 1 def anticommuting_space(q, d): """dimension of the space of a in C(V) = M_n with d L_a = - L_a d""" n = q.blocks[0] M = [] for j in range(q.N): e = np.zeros((n, n), dtype=complex) e.flat[j] = 1 La = left(q, e) M.append((d @ La + La @ d).flatten()) sv = np.linalg.svd(np.array(M).T, compute_uv=False) return int(np.sum(sv < 1e-8)) + max(0, q.N - len(sv)) def three_conditions(q, d, lam): ev = np.linalg.eigvals(d).real return (anticommuting_space(q, d) > 0, np.allclose(np.sort(ev), np.sort(-ev), atol=1e-7), bool(np.any(np.abs(ev + lam) < 1e-7))) q2 = QSpace([2]) U, Lam = weyl(2, (1, 0)), weyl(2, (0, 1)) d = ad(q2, U) + ad(q2, Lam) s = 1j * U @ Lam p = (np.eye(2) + s) / 2 P = q2.matrix_of(lambda x: [p @ x[0] @ p]) Q = q2.matrix_of(lambda x: [(np.eye(2) - p) @ x[0] @ (np.eye(2) - p)]) log(f"quantum square: s = sigma_y {close(s, np.array([[0, -1j], [1j, 0]]))}, d L_s = -L_s d " f"{close(d @ left(q2, s), -left(q2, s) @ d)}, p and 1-p independent {close(P @ d @ P, 0 * d) and close(Q @ d @ Q, 0 * d)}, " f"psi(p) = {q2.psi(q2.to_vec([p])).real:.0f}") for n in [2, 3, 4, 6]: q = QSpace([n]) G = [(a, b) for a in range(n) for b in range(n) if (a, b) != (0, 0)] ok, count, bip = True, 0, 0 for t in range(40): T = [G[i] for i in rng.choice(len(G), rng.integers(1, 4), replace=False)] S = sorted(set(T) | {((-a) % n, (-b) % n) for a, b in T}) d = sum(ad(q, weyl(n, g)) for g in S) if not connected(q, d): continue c = three_conditions(q, d, len(S)) ok &= (c[0] == c[1] == c[2]) count += 1 bip += c[0] log(f"Weyl-Cayley graphs, n = {n}: {count} connected samples, {bip} bipartite, conditions equivalent {ok}") for n in [2, 4, 6]: q = QSpace([n]) for mode in ["anticommuting", "arbitrary"]: res = [] for t in range(10): d = 0 V = haar(n) for k in range(2): if mode == "anticommuting": h = n // 2 W = np.block([[np.zeros((h, h)), haar(h)], [haar(h), np.zeros((h, h))]]) W = V @ W @ V.conj().T else: W = haar(n) d = d + ad(q, W) + ad(q, W.conj().T) res.append((connected(q, d), close(q.adjoint(d), d)) + three_conditions(q, d, 4)) log(f"random regular graphs over M_{n}, W_k {mode}: connected {sum(r[0] for r in res)}/10, " f"undirected {all(r[1] for r in res)}, bipartite {sum(r[2] for r in res)}, " f"conditions equivalent {all(r[2] == r[3] == r[4] for r in res)}") def sqrt_psd(a): w, v = np.linalg.eigh((a + a.conj().T) / 2) return v @ np.diag(np.sqrt(np.clip(w, 0, None))) @ v.conj().T for n in [2, 4, 6]: q = QSpace([n]) for mode in ["anticommuting", "arbitrary"]: res = [] for t in range(10): d = 0 V = haar(n) for k in range(2): Z = rng.normal(size=(n, n)) + 1j * rng.normal(size=(n, n)) if mode == "anticommuting": h = n // 2 Z[:h, :h] = 0 Z[h:, h:] = 0 Z = V @ Z @ V.conj().T d = d + ad(q, Z) + ad(q, Z.conj().T) ev = np.linalg.eigvalsh((d + d.conj().T) / 2) # d is hermitian here, since psi = n Tr lam = ev.max() regular = close(d @ q.one(), lam * q.one()) cond = three_conditions(q, d, lam) ok = None if cond[2]: # the bipartition, from a self-adjoint eigenvector x of -lambda, via |x| w, v = np.linalg.eigh((d + d.conj().T) / 2) x = q.to_blocks(v[:, np.argmin(w)])[0] x = x + x.conj().T if np.linalg.norm(x + x.conj().T) > 1e-6 else 1j * (x - x.conj().T) ww, vv = np.linalg.eigh(x) xp = vv @ np.diag(np.clip(ww, 0, None)) @ vv.conj().T xm = xp - x ax = xp + xm p = vv @ np.diag((ww > 0).astype(float)) @ vv.conj().T P = q.matrix_of(lambda y: [p @ y[0] @ p]) Q = q.matrix_of(lambda y: [(np.eye(n) - p) @ y[0] @ (np.eye(n) - p)]) vec = q.to_vec ok = (close(d @ vec([ax]), lam * vec([ax]), 1e-7), np.linalg.eigvalsh(ax).min() > 1e-9, close(d @ vec([xp]), lam * vec([xm]), 1e-7), close(P @ d @ P, 0 * d) and close(Q @ d @ Q, 0 * d)) res.append((connected(q, d), close(q.adjoint(d), d), regular) + cond + (ok,)) bip = [r[6] for r in res if r[6] is not None] log(f"random non-regular graphs over M_{n}, Kraus operators {mode}: connected {sum(r[0] for r in res)}/10, " f"undirected {all(r[1] for r in res)}, regular {sum(r[2] for r in res)}, bipartite {sum(r[3] for r in res)}, " f"conditions equivalent {all(r[3] == r[4] == r[5] for r in res)}") if bip: log(f" from an eigenvector x of -lambda: d(|x|) = lambda |x| {all(b[0] for b in bip)}, |x| invertible " f"{all(b[1] for b in bip)}, d(x_+) = lambda x_- {all(b[2] for b in bip)}, supports of x_+, x_- " f"independent {all(b[3] for b in bip)}") log.save()