#!/usr/bin/env python3 """Job #4332 (route 59, rescue) driver. Three measurements, all on the kernel pinned by return #878 and used by #1075, served as falsifier1676.py / shuffle1676.py with return #1075: 1. REGRESSION. Reproduce #1075's published |S|/A1 cell values at x = 1e5 and 1e6 to the digits the published falsifier1676.json carries, then add the spectral quantities. 2. SPECTRAL AXIS. A_op = ||beta||_2^2 sum_q lambda(q) ||N_q||_op satisfies |S| <= A_op (Rayleigh), and A_op uses no sign information beyond sum_e beta(e)^2 = #squarefree. Report A1/A_op against the route's required factor x^(7/200) in every cell. 3. E-SWEEP. Route 59's unclaimed step (queued as job 2020 and released), with the trusted review's correction: at x = 1e6, M = 1e4, Q = 2, sigma = +1, z'/x in {0.6, 0.9} and E = 25, 50, 100, 200, 400, ONE sign vector is drawn per replicate and used at every z' (shared draws), and the one-sided joint p-value over the z' grid is reported. Also an M-sweep at x = 1e5, Q = 2, E = 50: the m-window length is the one knob of the toy model that moves toward the note's own normalisation (where M = x^(1/2) is large). Output: spectral_axis.json (all numbers) and 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, spectral_profile, hermiticity_defect, shuffle_shared) def eprint(*a): print(*a, file=sys.stderr, flush=True) def build(x, M, Q, A, sigma, z, E): return describe(kernel_matrices(x, M, Q, A, sigma, z, E)) def describe(km): S = signed_sum(km) A1 = absolute_majorant(km) ob = operator_bound(km) Ssp, prof = spectral_profile(km) d = dict( n=int(km['beta'].size), E=int(km['E']), qs=[int(q) for q in km['qs']], nterms=int(km['nterms']), S_abs=float(abs(S)), A1=float(A1), ratio_S_A1=float(abs(S) / A1), spectral_S_abs=float(abs(Ssp)), spectral_consistency=float(abs(Ssp - S) / max(abs(S), 1e-300)), A_op=float(ob['A_op']), ratio_Aop_A1=float(ob['A_op'] / A1), guaranteed_saving=float(A1 / ob['A_op']), rho=[float(v) for v in ob['rho']], fro=[float(v) for v in ob['fro']], effrank=[float(v) for v in ob['effrank']], align_top=[float(p['align_top']) for p in prof], random_align=float(1.0 / np.sqrt(km['beta'].size)), top_share=[float(p['top_share']) for p in prof], fro_over_op=[float(p['fro_over_op']) for p in prof], herm_defect=float(hermiticity_defect(km['N'])), ) return d, km def part1(out): eprint("== part 1: regression + spectral axis ==") zfs = [0.6, 0.75, 0.9, 1.0] res = {} for x, M, N in [(10 ** 5, 1000, 100), (10 ** 6, 10 ** 4, 100)]: thr = x ** (-7.0 / 200.0) for Q in [2, 4, 8, 16]: E = N // Q for sigma in (1, -1): kms = {} for zf in zfs: z = zf * x t0 = time.time() d, km = build(x, M, Q, 4, sigma, z, E) kms[zf] = km key = f"x={x} Q={Q} E={E} sigma={sigma} z'/x={zf}" res[key] = d eprint(f" {key}: |S|/A1={d['ratio_S_A1']:.6f} A1/A_op={d['guaranteed_saving']:.3f} " f"effrank={np.mean(d['effrank']):.1f}/{d['n']} ({time.time()-t0:.1f}s)") if x == 10 ** 5: sh = shuffle_shared(kms, nperm=4000, seed=20260927) for zf in zfs: res[f"x={x} Q={Q} E={E} sigma={sigma} z'/x={zf}"].update(sh[zf]) res[f"x={x} Q={Q} E={E} sigma={sigma} shuffle_joint"] = sh['joint'] out['part1'] = res return res def part2(out): eprint("== part 2: E-sweep (route 59's unclaimed step, shared draws) ==") x = 10 ** 6 M = 10 ** 4 Q = 2 sigma = 1 A = 4 zfs = [0.6, 0.9] res = {} for E in [25, 50, 100, 200, 400]: kms = {} for zf in zfs: t0 = time.time() d, km = build(x, M, Q, A, sigma, zf * x, E) kms[zf] = km key = f"E={E} z'/x={zf}" res[key] = d eprint(f" {key}: n={d['n']} nterms={d['nterms']} |S|/A1={d['ratio_S_A1']:.6f} " f"A1/A_op={d['guaranteed_saving']:.3f} effrank={np.mean(d['effrank']):.1f} " f"align_top={np.mean(d['align_top']):.3f} (rand {d['random_align']:.3f}) ({time.time()-t0:.1f}s)") sh = shuffle_shared(kms, nperm=4000, seed=4332) for zf in zfs: res[f"E={E} z'/x={zf}"].update(sh[zf]) res[f"E={E} shuffle_joint"] = sh['joint'] eprint(f" E={E} joint: true={sh['joint']['true_log_sum']:.3f} " f"p_upper={sh['joint']['p_upper']:.4f} p_lower={sh['joint']['p_lower']:.4f}") # log-log slopes against n = #squarefree e in the window ns, tru, med, aop = [], [], [], [] for E in [25, 50, 100, 200, 400]: keys = [f"E={E} z'/x={zf}" for zf in zfs] ns.append(np.mean([res[k]['n'] for k in keys])) tru.append(np.mean([res[k]['ratio_S_A1'] for k in keys])) med.append(np.mean([res[k]['null_median'] for k in keys])) aop.append(np.mean([res[k]['ratio_Aop_A1'] for k in keys])) ns = np.array(ns, float) slopes = {} for name, y in [('true', np.array(tru)), ('null_median', np.array(med)), ('Aop_over_A1', np.array(aop))]: s = np.polyfit(np.log(ns), np.log(y), 1) rng = np.random.default_rng(7) boots = [] for _ in range(2000): idx = rng.integers(0, ns.size, ns.size) boots.append(np.polyfit(np.log(ns[idx]), np.log(y[idx]), 1)[0]) slopes[name] = dict(slope=float(s[0]), bootstrap_sd=float(np.std(boots))) res['slopes'] = slopes res['n_grid'] = [float(v) for v in ns] eprint(" slopes:", json.dumps(slopes)) out['part2'] = res return res def part3(out): eprint("== part 3: M-sweep (m-window growth), x=1e5, Q=2, E=50 ==") x = 10 ** 5 Q, A, sigma, E = 2, 4, 1, 50 res = {} for M in [125, 250, 500, 1000, 2000, 4000]: d, km = build(x, M, Q, A, sigma, 0.6 * x, E) res[f"M={M}"] = d eprint(f" M={M}: n={d['n']} |S|/A1={d['ratio_S_A1']:.6f} A1/A_op={d['guaranteed_saving']:.3f} " f"effrank={np.mean(d['effrank']):.1f}/{d['n']}") out['part3'] = res return res if __name__ == '__main__': t0 = time.time() out = {} part1(out) json.dump(out, open('spectral_axis.json', 'w'), indent=1, default=float) part2(out) json.dump(out, open('spectral_axis.json', 'w'), indent=1, default=float) part3(out) json.dump(out, open('spectral_axis.json', 'w'), indent=1, default=float) eprint(f"total {time.time()-t0:.0f}s -> spectral_axis.json")