#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Steps (b) and (c) of the (H_w) transfer: exact check of the twist identity and of its truncation. Step (b) writes f(e) = prod_{p|e} g(p) (g(p) = p/(p-4), p >= 7) as the divisor sum sum_{m|e} h(m), h(m) = mu^2(m) prod_{p|m} (g(p)-1) = mu^2(m) prod_{p|m} 4/(p-4). Substituting into a block-local class sum gives, EXACTLY, sum_{E= 1} h(m) * #{ e' : E/m < e' <= 2E/m , e = m e' is squarefree, y-friable, (e,30)=1, e = a (d) }, where h(m) = 0 unless m is squarefree. This parametrizes each admissible e by *all* its divisors m, so every constraint must be imposed on the product e = m e', not on e' alone: - e squarefree <=> m squarefree, e' squarefree, (m,e') = 1; - e y-friable <=> m y-friable and e' y-friable; - (e,30) = 1 <=> (m,30) = 1 and (e',30) = 1; - e = a (d) <=> e' = a m^{-1} (d) -- meaningful only when (m,d) = 1, since (a,d) = 1 (if (m,d) = g > 1 then e = m e' = a (d) would force g | a). Truncating the m-sum at m <= T leaves a tail bounded by sum_{m>T} |h(m)| * (mass of the shifted block) <= Phi_bl * sum_{m>T} |h(m)|/m <= Phi_bl * T^{-1/2} * sum_m |h(m)|/m^{1/2}, and sum_m |h(m)|/m^{1/2} = prod_{p>=7} (1 + 4/((p-4) p^{1/2})) converges. Checked here on the corpus's own L = x# with y the largest prime <= sqrt(L). """ from fractions import Fraction as F from math import gcd, isqrt def primes_upto(n): s = bytearray([1]) * (n + 1) s[0:2] = b"\x00\x00" for i in range(2, isqrt(n) + 1): if s[i]: s[i * i::i] = bytearray(len(s[i * i::i])) return [i for i in range(n + 1) if s[i]] def build(x): ps = primes_upto(x) L = 1 for p in ps: L *= p r = isqrt(L) return L, max(p for p in primes_upto(r) if p <= r) def sieve_tables(N, y): """spf up to N; f[e] = prod_{p|e} p/(p-4) when e is squarefree, y-friable, (e,30)=1, else 0.""" spf = list(range(N + 1)) for i in range(2, isqrt(N) + 1): if spf[i] == i: for j in range(i * i, N + 1, i): if spf[j] == j: spf[j] = i f = [F(0)] * (N + 1) for e in range(1, N + 1): if gcd(e, 30) != 1: continue n, ok, sq = e, True, False while n > 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 if ok and not sq: n2, pr = e, F(1) while n2 > 1: p = spf[n2] while n2 % p == 0: n2 //= p pr *= F(p, p - 4) f[e] = pr return spf, f def h_of(m, y, spf): """h(m) = mu^2(m) prod_{p|m} 4/(p-4) if m is squarefree, y-friable and (m,30)=1; else None.""" if gcd(m, 30) != 1: return None n, prod = m, F(1) while n > 1: p = spf[n] if p > y: return None k = 0 while n % p == 0: n //= p k += 1 if k > 1: return None prod *= F(4, p - 4) return prod def tail_constant(y, spf, upto): """sum_{m squarefree, y-friable, (m,30)=1, m<=upto} |h(m)|/m^{1/2} -- grows to the Euler product.""" tot = 0.0 for m in range(1, upto + 1): h = h_of(m, y, spf) if h is None: continue tot += abs(float(h)) / m ** 0.5 return tot def main(): for x, E in ((13, 300), (17, 2000)): L, y = build(x) spf, f = sieve_tables(2 * E, y) print("== x=%d L=%d y=%d E=%d block=(%d,%d] ==" % (x, L, y, E, E, 2 * E)) # tail constant (Euler product partial sum) for step (c) C = tail_constant(y, spf, 2 * E) for d in (7, 11, 49): lhs = {a: F(0) for a in range(1, d) if gcd(a, d) == 1} for e in range(E + 1, 2 * E + 1): if f[e] and gcd(e, d) == 1: lhs[e % d] += f[e] phi_bl = sum(lhs.values()) print(" d=%-3d block mass Phi_bl = %-24s (%.6f)" % (d, phi_bl, float(phi_bl))) for T in (1, 2, 8, 64, 10 ** 9): rhs = {a: F(0) for a in lhs} mmax = min(T, 2 * E) # m > 2E leaves an empty shifted block for m in range(1, mmax + 1): hm = h_of(m, y, spf) if hm is None or gcd(m, d) != 1: continue mr = m % d for ep in range(E // m + 1, 2 * E // m + 1): if f[ep] == 0 or gcd(ep, m) != 1 or gcd(ep, d) != 1: continue rhs[mr * (ep % d) % d] += hm # class of e = m e' worst = max((abs(lhs[a] - rhs[a]) for a in lhs), default=F(0)) rel = float(worst) / max(1.0, float(phi_bl)) bound = float(phi_bl) * C / T ** 0.5 print(" T=%-10d max_a|lhs-rhs| = %-14.6f rel = %.3e tail bd/Phi = %.3e" % (T, float(worst), rel, bound / max(1e-300, float(phi_bl)))) print() return 0 if __name__ == "__main__": raise SystemExit(main())