#!/usr/bin/env python3 """Job #4332 (route 59, rescue), part 4: the COUPLED sweep. The E-sweep of spectral_axis.py part 2 grows the pair count n at fixed x (the step #1075 priced). This script instead moves the toy model along x with the note's own coupling N = E*Q (so Q = 2 stays the prime-power factor) and the m-window M fixed, x = M*N. It then tests the two halves of the exponent claim used in the report: (i) the sign-blind saving A1/A_op obeys A1/A_op = c * sqrt(n) with c approximately independent of x (so the h-summed pair kernel's operator norm is Wigner-like: rho ~ ||N||_F / sqrt(n)); (ii) at the note's own normalisation (Q = x^(1/20), E = x^(9/20), hence the e-window count n ~ x^(9/20)), (i) gives the saving exponent (1/2)*(9/20) = 9/40, against the route's requirement x^(7/200). Writes coupled_sweep.json; progress on stderr. """ import json import sys import time import numpy as np from pair_kernel import (kernel_matrices, signed_sum, absolute_majorant, operator_bound, hermiticity_defect, shuffle_shared) def eprint(*a): print(*a, file=sys.stderr, flush=True) def main(): M = 10 ** 4 A = 4 Q = 2 sigma = 1 zfs = [0.6] out = {} xs, sav, cs, thr = [], [], [], [] for E in [25, 50, 100, 200]: N = E * Q x = M * N kms, row = {}, {} for zf in zfs: t0 = time.time() km = kernel_matrices(x, M, Q, A, sigma, zf * x, E) kms[zf] = km S = abs(signed_sum(km)) A1 = absolute_majorant(km) ob = operator_bound(km) n = int(km['beta'].size) row[f"z'/x={zf}"] = dict( n=n, S_abs=float(S), A1=float(A1), A_op=float(ob['A_op']), guaranteed_saving=float(A1 / ob['A_op']), c_over_sqrt_n=float((A1 / ob['A_op']) / np.sqrt(n)), fro_over_op=[float(np.sqrt((np.abs(M_) ** 2).sum()) / max(float(np.abs(np.linalg.eigvalsh(M_)).max()), 1e-300)) for M_ in km['N']], herm_defect=float(hermiticity_defect(km['N'])), ) eprint(f" x={x} E={E} z'/x={zf}: n={n} saving={row[f"z'/x={zf}"]['guaranteed_saving']:.3f} " f"c=saving/sqrt(n)={row[f"z'/x={zf}"]['c_over_sqrt_n']:.3f} ({time.time()-t0:.1f}s)") sh = shuffle_shared(kms, nperm=1500, seed=4332 + E) for zf in zfs: row[f"z'/x={zf}"].update(sh[zf]) row['shuffle_joint'] = sh['joint'] row['x'] = x row['threshold_x_7_200'] = float(x ** (7.0 / 200.0)) row['saving_over_threshold'] = float(np.mean([row[f"z'/x={zf}"]['guaranteed_saving'] for zf in zfs]) / row['threshold_x_7_200']) out[f"E={E} x={x}"] = row xs.append(x) sav.append(np.mean([row[f"z'/x={zf}"]['guaranteed_saving'] for zf in zfs])) cs.append(np.mean([row[f"z'/x={zf}"]['c_over_sqrt_n'] for zf in zfs])) thr.append(row['threshold_x_7_200']) eprint(f" E={E} x={x}: saving/threshold={row['saving_over_threshold']:.2f} " f"joint p_upper={sh['joint']['p_upper']:.4f} p_lower={sh['joint']['p_lower']:.4f}") xs = np.array(xs, float) fit_sav = np.polyfit(np.log(xs), np.log(np.array(sav)), 1) fit_c = np.polyfit(np.log(xs), np.log(np.array(cs)), 1) fit_thr = np.polyfit(np.log(xs), np.log(np.array(thr)), 1) out['fits'] = dict( saving_exponent_in_x=float(fit_sav[0]), c_over_sqrt_n_exponent_in_x=float(fit_c[0]), threshold_exponent_in_x=float(fit_thr[0]), n_exponent_in_x=float(np.polyfit(np.log(xs), np.log([out[k][f"z'/x=0.6"]['n'] for k in out]), 1)[0]), ) eprint(" fits:", json.dumps(out['fits'])) json.dump(out, open('coupled_sweep.json', 'w'), indent=1, default=float) eprint("wrote coupled_sweep.json") if __name__ == '__main__': main()