#!/usr/bin/env python3 # -*- coding: utf-8 -*- """The EXACT nuclear norm of (D1)'s coefficient, against the sqrt(rank)*Frobenius bound. Follows `artifacts/report-audit-r2-rank.md` (#899). That audit bounded the Frobenius price from BELOW by `sqrt(rank)` and concluded the Hilbert-Schmidt interface is priced out by a power of x. The bound `||gamma||_nuc <= sqrt(rank)||gamma||_F` is attained only when the singular values are EQUAL; the true price is the exact nuclear norm. This script measures it. The object (served note `grouped-divisor-moment.md` (4), same normalisation the audit used): gamma_{t,pair} = coeff(pair) * hat F_pair(t), hat F_pair = DFT_c(F_pair), F_pair(m) = Phi_{u1,h1}(m) * conj(Phi_{u2,h2}(m)), Phi_{u,h}(m) = e( h z0'/(g m u) ) - e( h z'/(g m u) ), u = j*l. Two EXACT reductions, then one measurement: (R1) gamma = A . Omega with Omega_{m,t} = e_c(-tm), and Omega Omega* = c I. Hence the singular values of gamma are sqrt(c) times those of A, so ||gamma||_nuc / ||gamma||_F = ||A||_nuc / ||A||_F (exact, c cancels) i.e. the price above the Frobenius price is a property of the pair-profile matrix A alone. So measure A. (R2) with beta = z0'/(g j) and beta' = z'/(g j), and w := h/l, Phi_{j l,h}(m) = e(beta w/m) - e(beta' w/m) =: Psi_w(m). **Everything depends on (l,h) only through the single ratio w = h/l.** So the whole row family is the set {Psi_w}. In one (M,N,A)-box the ratio is confined to a factor-4 window (h in [A,2A), l in [L/2,2L)), so the phases beta w/m at m = M span a FIXED multiple of ONE number, the typical phase v := beta * (A/L) / M (= A*x/(M*N) in the corpus's own exponents). Therefore the nuclear-norm ratio is a function of v (and the box shape) alone, and v is the single knob. v << 1: the exponentials are linearisable and every row is nearly the SAME vector. v >> 1: the rows are distinct frequencies, near-orthogonal, and the audit's sqrt(rank) is attained. Exact integer phase reduction throughout (beta is an exact Fraction; no float touches a phase before it is reduced mod 1). """ import cmath import math from fractions import Fraction import numpy as np def frac_mod(num, den): """(num/den) mod 1, exactly, as a float in [0,1).""" r = num % den return r / den def box_ratios(A0, L0): """distinct w = h/l for h in [A0,2A0), l in [L0,2L0) -- the corpus's factor-4 window.""" return sorted({Fraction(h, l) for h in range(A0, 2 * A0) for l in range(L0, 2 * L0)}) def profile_matrix(v, A0, L0, M, rho): """A_{w,m} = e(beta w/m) - e(rho beta w/m), beta chosen so the typical phase at m=M is v. beta = v * M * L0 / A0 => beta * (A0/L0) / M = v. Exact Fractions; phases reduced modulo 1 in integers before any float is taken. """ beta = Fraction(v.numerator * M * L0, v.denominator * A0) ws = box_ratios(A0, L0) ms = list(range(M + 1, 2 * M + 1)) V = np.empty((len(ws), len(ms)), dtype=complex) for i, w in enumerate(ws): wn, wd = w.numerator, w.denominator bn = beta.numerator * wn bd = beta.denominator * wd for j, m in enumerate(ms): f1 = frac_mod(bn, bd * m) f2 = frac_mod(rho.numerator * bn, rho.denominator * bd * m) V[i, j] = (cmath.exp(2j * math.pi * f1) - cmath.exp(2j * math.pi * f2)) return V, ws def spectrum(V): sv = np.linalg.svd(V, compute_uv=False) smax = float(sv[0]) rank = int((sv > 1e-9 * smax).sum()) nuc = float(sv.sum()) fro = float(math.sqrt((np.abs(V) ** 2).sum())) return rank, nuc, fro, sv def scan(v, A0=8, L0=8, M=512, rho=Fraction(2, 1)): V, ws = profile_matrix(v, A0, L0, M, rho) rank, nuc, fro, sv = spectrum(V) R = nuc / fro return dict(v=v, rows=V.shape[0], distinct_w=len(ws), rank=rank, nuc=nuc, fro=fro, R=R, sqrt_rank=math.sqrt(rank), R_over_sqrt=math.sqrt(rank) / R if R else float("nan")) def main(): print("=" * 92) print("(R1)+(R2): the price of the Hilbert-Schmidt interface is ||A||_nuc/||A||_F,") print("a function of ONE parameter v = beta*(A/L)/M = A*x/(M*N) (the typical phase).") print("=" * 92) A0 = L0 = 8 M = 512 print("box: h in [%d,%d), l in [%d,%d) => #distinct w = %d, M = %d, rho = z'/z0' = 2" % (A0, 2 * A0, L0, 2 * L0, len(box_ratios(A0, L0)), M)) print() print("%-12s %8s %8s %10s %12s %12s %10s" % ("v", "#w", "rank", "Frobenius", "nuclear", "R=nuc/F", "sqrt(rank)")) vs = [Fraction(1, 1000), Fraction(1, 300), Fraction(1, 100), Fraction(1, 30), Fraction(1, 10), Fraction(1, 4), Fraction(1, 2), Fraction(1, 1), Fraction(2, 1), Fraction(4, 1), Fraction(10, 1), Fraction(30, 1), Fraction(100, 1), Fraction(1000, 1)] rows = [] for v in vs: r = scan(v, A0, L0, M) rows.append(r) print("%-12s %8d %8d %10.3f %12.3f %12.4f %10.3f" % (str(v), r["distinct_w"], r["rank"], r["fro"], r["nuc"], r["R"], r["sqrt_rank"])) print() print(" the audit's bound: R <= sqrt(rank). Its ratio R/sqrt(rank):") for r in rows: print(" v=%-10s R/sqrt(rank) = %.4f (1.0000 = bound attained, = no economy)" % (str(r["v"]), r["R"] / r["sqrt_rank"])) print() print(" small-v law (R - 1)/v -- constant => R = 1 + C v, LINEAR in the phase:") for r in rows[:5]: print(" v=%-10s R-1 = %.6f (R-1)/v = %.4f" % (str(r["v"]), r["R"] - 1, (r["R"] - 1) / float(r["v"]))) print() # ---------- is the economy an artefact of the box size? ---------- print("=" * 92) print("does R(v) depend on the box (rank) as well as on v?") print("=" * 92) for (a, l) in [(8, 8), (12, 12), (8, 24), (16, 16), (20, 20)]: for v in [Fraction(1, 100), Fraction(1, 10), Fraction(1, 1), Fraction(10, 1)]: V, ws = profile_matrix(v, a, l, M, Fraction(2, 1)) rank, nuc, fro, sv = spectrum(V) print(" box A0=%-3d L0=%-3d #w=%-5d rank=%-5d v=%-8s R=%.4f sqrt(rank)/R=%.3f" % (a, l, len(ws), rank, str(v), nuc / fro, math.sqrt(rank) / (nuc / fro))) print() # ---------- the PAIR / product structure: does it kill the economy? ---------- print("=" * 92) print("the true object is the PAIR family F_pair = Phi_p * conj(Phi_q) (entrywise product).") print("the audit reduced it to the single family on a fixed second factor; test BOTH.") print("=" * 92) for v in [Fraction(1, 100), Fraction(1, 4), Fraction(1, 1), Fraction(10, 1)]: V, ws = profile_matrix(v, 6, 6, M, Fraction(2, 1)) rank1, nuc1, fro1, _ = spectrum(V) # full product family: all ordered pairs (p,q) of the same w-set X = V n = X.shape[0] rowsP = [] for p in range(n): for q in range(n): rowsP.append(X[p] * np.conj(X[q])) P = np.array(rowsP) rankp, nucp, frop, _ = spectrum(P) print(" v=%-9s single: R=%.4f (rank %d) pair-product: R=%.4f (rank %d) [rows %d]" % (str(v), nuc1 / fro1, rank1, nucp / frop, rankp, P.shape[0])) print() # ---------- the payoff arithmetic in the corpus's own exponents ---------- print("=" * 92) print("what the economy is worth in the corpus's normalisation (audit #899 sec.4)") print("=" * 92) C = (rows[0]["R"] - 1) / float(rows[0]["v"]) print(" measured small-v constant C = %.4f (R = 1 + C*v to the accuracy of this box)" % C) print(" audit #899 compared: sqrt(rank) in [x^0.255, x^0.475] vs the deficit x^(7/400).") for x in [10 ** 6, 10 ** 9, 10 ** 12]: need = x ** (7 / 400.0) vstar = (need - 1) / C print(" x=1e%-3d : interface affordable iff R <= x^(7/400) = %.4f, i.e. v <= %.4f" % (int(math.log10(x)), need, vstar)) print() print(" and v = A*x/(M*N) in the corpus's exponents, so v <= v* is a ceiling on the") print(" harmonic band A. At the (D1) cell M=x^(14/25), N=x^(1/2) => M*N/x = x^(3/50):") for x in [10 ** 9]: need = x ** (7 / 400.0) vstar = (need - 1) / C Astar = vstar * x ** (3 / 50.0) print(" x=1e9 : A <= %.3e (i.e. v <= %.4f); the top band runs to T = x^(3/50+2*tau)" % (Astar, vstar)) print(" T <= x^(7/400)*x^(3/50) iff 2*tau <= 7/400, i.e. tau <= 7/800 = %.5f" % (7 / 800)) return 0 if __name__ == "__main__": raise SystemExit(main())