""" laplacian.py -- checks, for random positively weighted undirected quantum graphs d = T + T^*, with T completely positive: the Laplacian L(x) = (d(1)x + xd(1))/2 - d(x) is self-adjoint and positive (section 6), the bounds psi(d(1))/N <= lambda_max <= ||d(1)|| (section 8), the formula cut(p) = and the easy half of the Cheeger inequality (section 8). For the hard half, it diagonalizes a self-adjoint lambda_2-eigenvector f in each block, and checks that the compression of L to the resulting diagonal algebra D is a classical weighted Laplacian, with vertex weights psi(e_i) and edge weights psi(e_i d(e_j)) >= 0, with the same lambda_2, whose cuts give the bound h(X) <= h_D <= sqrt(2 ||d(1)|| lambda_2). Results are written to laplacian.log. """ import itertools import numpy as np from qspace import QSpace, Logger, close, random_cp rng = np.random.default_rng(2026) log = Logger("laplacian.log") for blocks in [[1, 1, 1], [2], [3], [2, 1], [2, 1, 1], [2, 2], [3, 1]]: qs = QSpace(blocks) N = qs.N ok_pos, ok_bounds, ok_cheeger, ok_hard = True, True, True, True for _ in range(5): T = random_cp(qs, rng) d = T + qs.adjoint(T) L = qs.laplacian(d) H = qs.G @ L # L is self-adjoint for psi iff G L is hermitian if not close(H, H.conj().T, 1e-7) or np.min(np.linalg.eigvals(L).real) < -1e-8: ok_pos = False lam = np.max(np.linalg.eigvals(d).real) avg = qs.psi(qs.degree(d)).real / N degnorm = max(np.max(np.abs(np.linalg.eigvalsh(m))) for m in qs.to_blocks(qs.degree(d))) if not (avg <= lam + 1e-8 and lam <= degnorm + 1e-8): ok_bounds = False lam2 = np.sort(np.linalg.eigvals(L).real)[1] for _ in range(20): r = rng.integers(len(blocks)) v = rng.normal(size=blocks[r]) + 1j * rng.normal(size=blocks[r]) v /= np.linalg.norm(v) bl = [np.zeros((m, m), dtype=complex) for m in blocks] bl[r] = np.outer(v, v.conj()) p = qs.to_vec(bl) cut = qs.inner(d @ (qs.one() - p), p).real if abs(cut - qs.inner(L @ p, p).real) > 1e-8: ok_cheeger = False if qs.psi(p).real <= N / 2 and lam2 > 2 * cut / qs.psi(p).real + 1e-8: ok_cheeger = False # hard half: diagonalize a self-adjoint lambda_2-eigenvector, block by block sq, isq = np.sqrt(qs.G), np.sqrt(qs.Ginv) w, v = np.linalg.eigh((sq @ L @ isq + (sq @ L @ isq).conj().T) / 2) f = isq @ v[:, 1] f = f + qs.star(f) if np.linalg.norm(f + qs.star(f)) > 1e-6 else 1j * (f - qs.star(f)) es, ms = [], [] for r, m in enumerate(qs.to_blocks(f)): _, Ur = np.linalg.eigh((m + m.conj().T) / 2) for a in range(blocks[r]): bl = [np.zeros((n, n), dtype=complex) for n in blocks] bl[r] = np.outer(Ur[:, a], Ur[:, a].conj()) es.append(qs.to_vec(bl)) ms.append(blocks[r]) k = len(es) A = np.array([[qs.psi(qs.product(es[i], d @ es[j])).real for j in range(k)] for i in range(k)]) M = np.diag(ms).astype(float) LD = np.diag(A.sum(1)) - A muD = np.sort(np.linalg.eigvals(np.linalg.solve(M, LD)).real) hD = min(sum(A[i, j] for i in S for j in range(k) if j not in S) / sum(ms[i] for i in S) for t in range(1, k) for S in itertools.combinations(range(k), t) if sum(ms[i] for i in S) <= N / 2) dn = max(np.max(np.abs(np.linalg.eigvalsh(m))) for m in qs.to_blocks(qs.degree(d))) ok_hard &= (np.all(A >= -1e-9) and close(A, A.T, 1e-8) and abs(muD[1] - lam2) < 1e-7 and lam2 <= 2 * hD + 1e-8 and hD <= np.sqrt(2 * dn * lam2) + 1e-8) log(f"=== V with blocks {blocks}: L self-adjoint and positive {ok_pos}, " f"spectral bounds {ok_bounds}, cut(p) = and easy Cheeger {ok_cheeger}, " f"diagonal compression with the same lambda_2, and lambda_2/2 <= h_D <= sqrt(2||d(1)|| lambda_2) {ok_hard}") log.save()