#!/usr/bin/env python3 # -*- coding: utf-8 -*- """The normalization of `(H_w)`: block mass, per-modulus diagonal, and what the printed form computes. `recon-0830-smooth-aps.md` section 3.1 states (H_w) as sum_{d<=Q} sum_{(a,d)=1} max_{t in [E,2E]} |Delta_a(t;d)|^2 <= C_A (log^{-A} E + Q/E), Delta_a(t;d) = sum_{e<=t, e=a(d)} w(e) - (1/phi(d)) sum_{e<=t,(e,d)=1} w(e), and calls it "Harper's Theorem 2 ... divided by E^2". That division is calibrated on a weight-one count, whose mass on the block [E,2E] is asymp E and whose diagonal is asymp E per modulus, so that the two coincide. Our weight is w(e) = f(e)/e = lam1(e), and the whole question of the transfer is what its masses are. Computed here from the definition on the corpus's own L = x#, y = the largest prime <= sqrt L: M_bl := sum_{E 1: p = spf[n] k = 0 while n % p == 0: n //= p k += 1 if k > 1: sq = True break if p > y: ok = False break prod *= F(p, p - 4) if ok and not sq: w[e] = prod / e return w def window_stats(w, E, D, span=6): """Exact block-local and full-range deviations for the moduli in (D, D+span].""" lo, hi = E + 1, 2 * E diag_bl = F(0) for d in range(D + 1, D + span + 1): cls, tot = {}, F(0) for e in range(lo, hi + 1): if w[e] == 0: continue a = e % d cls[a] = cls.get(a, F(0)) + w[e] if gcd(e, d) == 1: tot += w[e] phi = sum(1 for a in range(1, d + 1) if gcd(a, d) == 1) for a, m in cls.items(): if gcd(a, d) == 1: dev = m - tot / phi diag_bl += dev * dev # the PRINTED form's modulus d=7, Q >= 7, full-range Delta at t = 2E printed = F(0) d = 7 cls, tot = {}, F(0) for e in range(1, hi + 1): if w[e] == 0: continue a = e % d cls[a] = cls.get(a, F(0)) + w[e] if gcd(e, d) == 1: tot += w[e] phi = 6 for a, m in cls.items(): if gcd(a, d) == 1: dev = m - tot / phi printed += dev * dev return diag_bl, printed def main(): print("== block mass and the two diagonals (exact rationals) ==") print(" x L E D M_bl S2 E*S2 diagW diagW/6S2 full2") for x in (19, 23, 29): L, y = build(x) Emax = 2 * isqrt(L) w = lam1_table(Emax, y) for E in (y, isqrt(L) // 2, isqrt(L)): if E < 3 or 2 * E > Emax: continue D = L // E # so that E = L / D, i.e. M = 1 in the corpus's E = L/(DM) M_bl = sum((w[e] for e in range(E + 1, 2 * E + 1)), F(0)) S2 = sum((w[e] * w[e] for e in range(E + 1, 2 * E + 1)), F(0)) diagW, printed = window_stats(w, E, D) full2 = sum((w[e] * w[e] for e in range(1, 2 * E + 1)), F(0)) print(" %-4d %-12d %-8d %-6d %-9.5f %-11.3e %-9.5f %-9.3e %-10.3f %-9.3e" % (x, L, E, D, float(M_bl), float(S2), float(E * S2), float(diagW), float(diagW / (6 * S2)), float(full2))) print("\n== the printed (full-range) statement at its smallest modulus d = 7 ==") print(" x E |Delta_7(2E)|^2 summed over a printed RHS C_A(log^-A E + 7/E)") for x in (19, 23, 29): L, y = build(x) Emax = 2 * isqrt(L) w = lam1_table(Emax, y) D = 7 E = isqrt(L) # any E with 2E <= Emax _, printed = window_stats(w, E, D, span=0) print(" %-4d %-8d %-9.3e -> O(log^-A E), A arbitrary" % (x, E, float(printed))) print("\n== the block-local reading is the one Harper's normalization produces ==") print(" Harper Thm 2 (weight one): V = (Q/2) sum a_n^2 + O(Psi^2 log^-A x), Psi asymp x;") print(" divided by x^2 and with Q = D, x = E: D/E + log^-A E -- exactly the right-hand side of (H_w).") print(" For w the block mass is M_bl asymp C_0 = O(1) (printed above) and the diagonal is") print(" S2 asymp C_2/E, so the same normalization gives the same D/E; the full-range reading") print(" gives D*full2 instead, which is a constant per modulus and cannot be O(log^-A E).") return 0 if __name__ == "__main__": raise SystemExit(main())