#!/usr/bin/env python3 """Numerical verification of the propositions proved in the paper. This script is an independent re-implementation of the finite-group computation used by the mission engine. It reads only the artefacts shipped in anc/artefacts and recomputes, for every one of the 200 grid rows, * the character table, the period kernel and the amplifier, * the amplified second moment, its principal and non-principal parts, * the diagonal, the off-diagonal correlation and both localization functionals (the engine proxy and the exact l=m diagonal), * the gain ratio, and compares them with the engine output. It then checks each proposition of the paper on the grid. Nothing here is a proof: the proofs are in the paper, and this file only certifies that the statements are not contradicted by the shipped data and that the engine numbers quoted in the paper are reproducible from an independent implementation. Usage: python3 verify_propositions.py [--out proposition_checks.json] Exit code 0 when every check passes, 1 otherwise. """ import cmath import json import math import os import sys HERE = os.path.dirname(os.path.abspath(__file__)) ART = os.path.join(HERE, 'artefacts') MODULI = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31] KERNELS = ['bump', 'half', 'indicator'] SUPPORT_INDEPENDENT = {'bump', 'half'} SUPPORTS = [4, 8, 16] LENGTHS = [1, 2, 4, 8] ITERATIONS = [1, 2, 4] SIGNAL_THRESHOLD = 1e-9 TOL = 1e-9 def units_of(q): return [a for a in range(1, q) if math.gcd(a, q) == 1] def is_prime(n): if n < 2: return False for d in range(2, int(math.isqrt(n)) + 1): if n % d == 0: return False return True def primitive_root(q): if q < 3 or not is_prime(q): raise ValueError('modulus must be an odd prime, got %d' % q) for g in range(2, q): seen = set() value = 1 for _ in range(q - 1): value = (value * g) % q seen.add(value) if len(seen) == q - 1: return g raise ValueError('no primitive root for q=%d' % q) def character_table(q): """chi[j][i] = exp(2 pi i j ind(a)/phi), j = 0 is the principal character.""" g = primitive_root(q) index = {} value = 1 for k in range(q - 1): index[value] = k value = (value * g) % q units = units_of(q) order = len(units) chi = [[cmath.exp(2j * math.pi * j * index[a] / order) for a in units] for j in range(order)] return units, chi def kernel_values(units, q, kind, support_n): if kind == 'bump': denom = max(q - 2, 1) return [(1.0 - ((a - 1) / denom) ** 2) ** 2 for a in units] if kind == 'indicator': return [1.0 if a <= support_n else 0.0 for a in units] if kind == 'half': return [1.0 if a <= q // 2 else 0.0 for a in units] if kind == 'delta': return [1.0 if a == units[0] else 0.0 for a in units] if kind == 'zero': return [0.0 for _ in units] raise ValueError('unknown kernel ' + kind) def amplifier_weights(q, length, weights='ones'): lam = [] for ell in range(1, length + 1): residue = ell % q if residue == 0 or math.gcd(residue, q) != 1: continue if weights == 'ones': lam.append((residue, 1.0)) elif weights == 'inverse': lam.append((residue, 1.0 / ell)) else: raise ValueError('unknown weights ' + weights) return lam def amplifier_values(units, chi, lam): pos = {a: i for i, a in enumerate(units)} out = [] for row in chi: out.append(sum(w * row[pos[r]] for r, w in lam)) return out def transform(units, chi, values): return [sum(v * row[i] for i, v in enumerate(values)) for row in chi] def grid_points(): points = [] for q in MODULI: for kind in KERNELS: supports = [SUPPORTS[0]] if kind in SUPPORT_INDEPENDENT else SUPPORTS for support_n in supports: for length in LENGTHS: points.append({'q': q, 'kernel': kind, 'support_N': support_n, 'L': length}) return points def recompute(point): q = point['q'] units, chi = character_table(q) kernel = kernel_values(units, q, point['kernel'], point['support_N']) khat = transform(units, chi, kernel) lam = amplifier_weights(q, point['L'], 'ones') amp = amplifier_values(units, chi, lam) phi = len(units) sum_k = sum(kernel) sum_k2 = sum(v * v for v in kernel) sum_w = sum(w for _, w in lam) sum_w2 = sum(w * w for _, w in lam) s_direct = sum(abs(a) ** 2 * abs(k) ** 2 for a, k in zip(amp, khat)) s_np = sum(abs(a) ** 2 * abs(k) ** 2 for a, k in zip(amp[1:], khat[1:])) s0 = sum(abs(k) ** 2 for k in khat) s0_np = sum(abs(k) ** 2 for k in khat[1:]) principal = abs(amp[0]) ** 2 * abs(khat[0]) ** 2 diagonal = phi * sum_w2 * sum_k2 diagonal_np_proxy = (phi - 1) * sum_w2 * sum_k2 diagonal_np_exact = sum_w2 * (phi * sum_k2 - sum_k ** 2) # off-diagonal correlation: pairs are split by index, not by residue pos = {a: i for i, a in enumerate(units)} corr = {} for t in units: corr[t] = sum(kernel[i] * kernel[pos[(t * a) % q]] for i, a in enumerate(units)) off_diagonal = 0.0 for i1, (r1, w1) in enumerate(lam): for i2, (r2, w2) in enumerate(lam): if i1 == i2: continue t = (r1 * pow(r2, -1, q)) % q off_diagonal += w1 * w2 * corr[t] off_diagonal *= phi off_diagonal_np_exact = off_diagonal - ((sum_w ** 2 - sum_w2) * sum_k ** 2) off_diagonal_np_engine = s_np - diagonal_np_proxy gain = (s_np / s0_np) if s0_np > 0 else None loc_proxy = (diagonal_np_proxy / s_np) if s_np > 0 else None loc_exact = (diagonal_np_exact / s_np) if s_np > 0 else None return { 'q': q, 'phi': phi, 'units': units, 'kernel': kernel, 'khat': khat, 'amp': amp, 'lam': lam, 'sum_k': sum_k, 'sum_k2': sum_k2, 'sum_w': sum_w, 'sum_w2': sum_w2, 'measured_norm': max(abs(a) for a in amp), 'declared_bound': sum(abs(w) for _, w in lam), 'second_moment_direct': s_direct, 'diagonal': diagonal, 'second_moment_nonprincipal': s_np, 'unamplified_nonprincipal': s0_np, 'unamplified': s0, 'principal_term': principal, 'diagonal_nonprincipal': diagonal_np_proxy, 'diagonal_nonprincipal_exact': diagonal_np_exact, 'off_diagonal': off_diagonal, 'off_diagonal_nonprincipal': off_diagonal_np_engine, 'off_diagonal_nonprincipal_exact': off_diagonal_np_exact, 'gain_ratio': gain, 'localization': loc_proxy, 'localization_exact': loc_exact, 'signal_present': s0_np > SIGNAL_THRESHOLD, 'corr': corr, } def close(a, b, tol=TOL): if a is None or b is None: return a is None and b is None scale = max(1.0, abs(a), abs(b)) return abs(a - b) <= tol * scale def main(): out_path = os.path.join(HERE, 'proposition_checks.json') if '--out' in sys.argv: out_path = sys.argv[sys.argv.index('--out') + 1] checks = [] notes = [] def add(cid, statement, passed, detail): checks.append({'id': cid, 'statement': statement, 'passed': bool(passed), 'detail': detail}) operator = json.load(open(os.path.join(ART, 'operator.json'))) adequacy = json.load(open(os.path.join(ART, 'adequacy.json'))) spectra = json.load(open(os.path.join(ART, 'spectra.json'))) by_key = {(r['q'], r['kernel'], r['support_N'], r['L']): r for r in operator['rows']} # ---------------------------------------------------------------- P1 worst = 0.0 for row in spectra['rows']: q = row['q'] units, chi = character_table(q) kernel = kernel_values(units, q, row['kernel'], row['support_N']) khat = transform(units, chi, kernel) lhs = sum(abs(v) ** 2 for v in khat) rhs = len(units) * sum(v * v for v in kernel) worst = max(worst, abs(lhs - rhs) / max(1.0, rhs)) add('P1', 'finite Parseval identity sum_chi |Khat(chi)|^2 = phi sum_a K(a)^2', worst <= 1e-12, 'max relative gap %.3e over %d spectra rows' % (worst, len(spectra['rows']))) # ------------------------------------------- engine reproduction + P2..P11 recomputed = {} mismatches = [] skipped_loc = 0 for point in grid_points(): key = (point['q'], point['kernel'], point['support_N'], point['L']) got = recompute(point) recomputed[key] = got ref = by_key[key] for field in ('measured_norm', 'declared_bound', 'second_moment_direct', 'diagonal', 'second_moment_nonprincipal', 'unamplified_nonprincipal', 'principal_term', 'diagonal_nonprincipal', 'off_diagonal', 'off_diagonal_nonprincipal'): if not close(got[field], ref[field]): mismatches.append({'key': list(key), 'field': field, 'recomputed': got[field], 'engine': ref[field]}) if got['second_moment_nonprincipal'] > 1e-9 and got['unamplified_nonprincipal'] > 1e-9: for field in ('gain_ratio', 'localization'): if not close(got[field], ref[field]): mismatches.append({'key': list(key), 'field': field, 'recomputed': got[field], 'engine': ref[field]}) else: skipped_loc += 1 add('R0', 'independent re-implementation reproduces the engine rows', not mismatches, '%d rows recomputed, %d field mismatches, %d rows skipped for a numerically ' 'vanishing non-principal moment' % (len(recomputed), len(mismatches), skipped_loc)) # P2 amplifier is the truncated character sum worst = 0.0 for key, got in recomputed.items(): q, _, _, L = key units = got['units'] chi = character_table(q)[1] for j in range(1, len(units)): classical = sum(chi[j][units.index(n % q)] for n in range(1, L + 1) if math.gcd(n % q, q) == 1 and n % q != 0) worst = max(worst, abs(got['amp'][j] - classical)) add('P2', 'A_L(chi) equals the classical truncated character sum on non-principal chi', worst <= 1e-12, 'max |A_L - sum_{n<=L} chi(n)| = %.3e' % worst) # P3 periodicity and vanishing worst = 0.0 vanish_rows = 0 vanish_ok = 0 for key, got in recomputed.items(): q, _, _, L = key units = got['units'] chi = character_table(q)[1] lm = L % q for j in range(1, len(units)): reduced = sum(chi[j][units.index(n)] for n in range(1, lm + 1)) worst = max(worst, abs(got['amp'][j] - reduced)) if lm in (0, q - 1): vanish_rows += 1 if all(abs(got['amp'][j]) <= 1e-12 for j in range(1, len(units))): vanish_ok += 1 add('P3', 'A_L(chi) = A_{L mod q}(chi) on non-principal chi, and A_L = 0 when ' 'L mod q is 0 or q-1', worst <= 1e-12 and vanish_rows == vanish_ok, 'max periodicity gap %.3e; %d of %d rows with L mod q in {0,q-1} vanish ' 'identically on the non-principal characters' % (worst, vanish_ok, vanish_rows)) # P4 principal decomposition worst = 0.0 for got in recomputed.values(): lhs = got['second_moment_direct'] rhs = got['second_moment_nonprincipal'] + got['principal_term'] worst = max(worst, abs(lhs - rhs) / max(1.0, abs(lhs))) expect = got['sum_w'] ** 2 * got['sum_k'] ** 2 worst = max(worst, abs(got['principal_term'] - expect) / max(1.0, abs(expect))) add('P4', 'S = S_np + (sum w)^2 (sum K)^2', worst <= 1e-12, 'max relative gap %.3e' % worst) # P5 orthogonality form and diagonal/off-diagonal split worst = 0.0 for key, got in recomputed.items(): q, _, _, L = key units = got['units'] pos = {a: i for i, a in enumerate(units)} lam = got['lam'] kernel = got['kernel'] total = 0.0 for r1, w1 in lam: for r2, w2 in lam: for i, a in enumerate(units): for j, b in enumerate(units): if (r1 * a - r2 * b) % q == 0: total += w1 * w2 * kernel[i] * kernel[j] total *= got['phi'] worst = max(worst, abs(total - got['second_moment_direct']) / max(1.0, abs(total))) split = got['diagonal'] + got['off_diagonal'] worst = max(worst, abs(split - got['second_moment_direct']) / max(1.0, abs(split))) add('P5', 'orthogonality form and the index-level split ' 'S = phi (sum w^2)(sum K^2) + phi sum_{i != j} w_i w_j C(r_i r_j^{-1})', worst <= 1e-10, 'max relative gap %.3e' % worst) # P6 gain as a spectral-mass-weighted average worst = 0.0 bound_ok = True l1_ok = True for got in recomputed.values(): if not got['signal_present']: continue num = 0.0 den = 0.0 lo = None hi = None for j in range(1, got['phi']): w = abs(got['khat'][j]) ** 2 v = abs(got['amp'][j]) ** 2 num += w * v den += w lo = v if lo is None else min(lo, v) hi = v if hi is None else max(hi, v) if den <= 0: continue avg = num / den worst = max(worst, abs(avg - got['gain_ratio']) / max(1.0, abs(avg))) if not (lo - 1e-12 <= got['gain_ratio'] <= hi + 1e-12): bound_ok = False for key, got in recomputed.items(): q, _, _, L = key if not got['signal_present']: continue if got['gain_ratio'] > (L % q) ** 2 + 1e-9: bound_ok = False if L == 1 and abs(got['gain_ratio'] - 1.0) > 1e-12: l1_ok = False add('P6', 'gain ratio is the spectral-mass-weighted average of |A_L(chi)|^2, ' 'min <= G <= max, G <= (L mod q)^2 and G = 1 at L = 1', worst <= 1e-12 and bound_ok and l1_ok, 'max average gap %.3e; bounds %s; L=1 identity %s' % (worst, bound_ok, l1_ok)) # P7 L=2 annihilation quad_ok = True detail = [] for q in MODULI: units, chi = character_table(q) lam = amplifier_weights(q, 2, 'ones') amp = amplifier_values(units, chi, lam) # the quadratic character is chi^{(q-1)/2} quad_index = (q - 1) // 2 a2 = amp[quad_index] expect_zero = (q % 8) in (3, 5) if expect_zero and abs(a2) > 1e-12: quad_ok = False if (not expect_zero) and abs(a2) < 1e-12: quad_ok = False allzero = all(abs(amp[j]) <= 1e-12 for j in range(1, len(units))) if allzero != (q == 3): quad_ok = False detail.append('q=%d quadratic|A_2|=%.3e all-nonprincipal-zero=%s' % (q, abs(a2), allzero)) lam = amplifier_weights(3, 2, 'inverse') units, chi = character_table(3) amp = amplifier_values(units, chi, lam) inv_ok = abs(abs(amp[1]) ** 2 - 0.25) <= 1e-12 add('P7', 'A_2(chi) = 1 + chi(2) annihilates the quadratic character exactly when ' 'q = 3,5 mod 8, annihilates the whole non-principal spectrum exactly when ' 'q = 3, and never vanishes for inverse weights (G = 1/4 at q = 3)', quad_ok and inv_ok, '; '.join(detail) + '; inverse-weight gain at q=3: %.6f' % abs(amp[1]) ** 2) # P8 proxy versus exact diagonal ok = True worst = 0.0 for got in recomputed.values(): diff = got['diagonal_nonprincipal'] - got['diagonal_nonprincipal_exact'] expect = got['sum_w2'] * (got['sum_k'] ** 2 - got['sum_k2']) worst = max(worst, abs(diff - expect) / max(1.0, abs(expect))) if any(v < 0 for v in got['kernel']): continue if diff < -1e-12: ok = False add('P8', 'proxy diagonal minus exact l=m diagonal equals ' '(sum w^2)((sum K)^2 - sum K^2) >= 0 for nonnegative kernels', ok and worst <= 1e-12, 'max identity gap %.3e; sign check %s' % (worst, ok)) # P9 spectral floor ok = True worst = 0.0 for row in spectra['rows']: q = row['q'] units, chi = character_table(q) kernel = kernel_values(units, q, row['kernel'], row['support_N']) khat = transform(units, chi, kernel) phi = len(units) sum_k = sum(kernel) sum_k2 = sum(v * v for v in kernel) floor = (phi * sum_k2 - sum_k ** 2) / (phi - 1) sup = max(abs(v) for v in khat[1:]) if sup * sup + 1e-12 < floor: ok = False worst = max(worst, abs(row['sup_abs_khat_nonprincipal'] - sup)) add('P9', 'sup_{chi != chi_0} |Khat(chi)|^2 >= (phi sum K^2 - (sum K)^2)/(phi-1)', ok, 'floor respected on all %d spectra rows; max gap to the stored supremum %.3e' % (len(spectra['rows']), worst)) # P10 amplification-localization trade-off ok = True worst = 0.0 negative = 0 considered = 0 loc_lo = None loc_hi = None for got in recomputed.values(): if not got['signal_present']: continue considered += 1 lhs = got['off_diagonal_nonprincipal_exact'] d_exact = got['diagonal_nonprincipal_exact'] total = got['second_moment_nonprincipal'] if abs((d_exact + lhs) - total) > 1e-9 * max(1.0, abs(total)): ok = False worst = max(worst, abs((d_exact + lhs) - total) / max(1.0, abs(total))) if lhs < 0: negative += 1 le = got['localization_exact'] if le is not None: loc_lo = le if loc_lo is None else min(loc_lo, le) loc_hi = le if loc_hi is None else max(loc_hi, le) add('P10', 'S_np = D_exact + R_np with R_np = R - (W^2 - W2)(sum K)^2, so the ' 'exact localization is at least theta only if the index-level correlation ' 'sum is at most ((1-theta)/theta) W2 sum K^2', ok, 'decomposition gap %.3e over %d rows; %d rows have a negative exact ' 'off-diagonal; exact localization ranges over [%.6f, %.6f]' % (worst, considered, negative, loc_lo, loc_hi)) # P11 norm identities ok = True worst_norm = 0.0 worst_lip = 0.0 for key, got in recomputed.items(): if abs(got['measured_norm'] - got['declared_bound']) > 1e-12: ok = False worst_norm = max(worst_norm, abs(got['measured_norm'] - got['declared_bound'])) eps = 1e-3 units = got['units'] chi = character_table(got['q'])[1] base = got['amp'] for idx in range(len(got['lam'])): shifted = list(got['lam']) ell, weight = shifted[idx] shifted[idx] = (ell, weight + eps) pert = amplifier_values(units, chi, shifted) lip = max(abs(p - b) for p, b in zip(pert, base)) / eps worst_lip = max(worst_lip, abs(lip - 1.0)) if lip > 1.0 + 1e-9: ok = False add('P11', 'for unit weights the sup norm of A_L equals the declared l1 bound with ' 'equality at the principal character, and the weight-Lipschitz constant ' 'equals 1, so both engine norm assertions are identities', ok, 'max |norm - bound| = %.3e; max |Lipschitz - 1| = %.3e' % (worst_norm, worst_lip)) # ------------------------------------------------- verdict cross-checks fails = [r for r in adequacy['rows'] if r['admissible'] and not r['adequate']] explained = 0 for r in fails: q = r['q'] lm = r['L'] % q if lm in (0, 1, q - 1): explained += 1 elif (q, lm) == (5, 3): explained += 1 add('V1', 'every admissible row that fails the gain threshold is explained by ' 'L mod q in {0,1,q-1} or by (q,L mod q) = (5,3)', explained == len(fails), '%d of %d failing admissible rows explained' % (explained, len(fails))) noise = [r for r in adequacy['rows'] if r['adequate'] and not r['admissible']] noise_ok = all(not r['signal_present'] for r in noise) add('V2', 'the 16 adequate-but-inadmissible rows are exactly rows whose ' 'non-principal spectrum is numerically zero', noise_ok and len(noise) == 16, '%d rows, all with signal_present false: %s' % (len(noise), noise_ok)) loc_min = min(r['localization'] for r in adequacy['rows'] if r['admissible'] and r['localization'] is not None) add('V3', 'the localization threshold is never binding on the admissible grid', loc_min >= adequacy['thresholds']['min_localization'], 'minimum admissible localization %.6f against threshold %.2f' % (loc_min, adequacy['thresholds']['min_localization'])) payload = { 'generated_by': 'anc/verify_propositions.py', 'grid_rows': len(recomputed), 'checks': checks, 'failures': [c['id'] for c in checks if not c['passed']], 'status': 'PASS' if all(c['passed'] for c in checks) else 'FAIL', 'notes': notes, } with open(out_path, 'w', encoding='utf-8') as handle: json.dump(payload, handle, indent=1) for c in checks: print('%-4s %s %s' % (c['id'], 'PASS' if c['passed'] else 'FAIL', c['detail'])) print('status=%s checks=%d failures=%d -> %s' % (payload['status'], len(checks), len(payload['failures']), out_path)) return 0 if payload['status'] == 'PASS' else 1 if __name__ == '__main__': sys.exit(main())