#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Is the CENTERED consumer posed on the arithmetic, or on its auxiliary split? THE QUESTION (mission B, continuation of return #787). Return #787 showed that `B` -- the remainder the board's `B-MARGIN` node bounds, and the node `tpc_deps.py cheapest` calls the cheapest in the whole graph -- is an artefact of a LABELLING choice: across six legal Vaughan gauges (U,V) at x=2^20 it sweeps from -7.52x to +0.18x (a factor 44) while the split-invariant P(1,e_1) = T_I^low + B sits at -0.0139x for every one of them. The corpus says the other single-node-closure branch is the same kind of object -- research/ moving-cutoff-parity.md line 285: the two remainders "differ in coefficients and ranges, not in kind" -- and its own (17) ties them: D_y = B_L + 2C_2 M + O_A(x/log^A x). So the same test must be run on the centered consumer, whose free parameter is not (U,V) but the AUXILIARY CUT y: y = ceil(x^(12/25)), Q = floor(x/y), J = (x/2, x], a(n) = Lambda(n-2), f(n) = a(n) mu(n), M = sum_{n in J} f(n), D_y(x) = sum_{e <= Q, e odd} mu(e) int_{(a_e, x]} log(e/t) dDelta_e(t), a_e = max(x/2, ey), Delta_e(t) = sum_{x/2 < n <= t, e|n} f(n) - (1/phi(e)) sum_{x/2 < n <= t} f(n). (9) WHAT IS MEASURED, AND WHY THE INVARIANT IS T_1 + T_2. The analogue of P(1,e_1) is exact and comes from the corpus's own chain: with T_1(y) = sum_{n in J} a(n) mu^2(n) A_y(n), A_y(n) = -sum_{d|n, d<=y} mu(d) log d, T_2(y) = sum_{n in J} f(n) sum_{e|n, ey= 0, (5) where S(x) = sum_{n in J} a(n) Lambda(n) does NOT depend on y at all. So T_1(y) + T_2(y) is cut-free up to the explicitly non-negative, O(sqrt(x) log^3 x) E_pp: it is the invariant. And, as in the Vaughan case, the object the node bounds is one half of a cancelling pair -- here T_2 (and D_y, its centred part) moves with y while T_1 + T_2 does not. GATES (a refusal, not a print, if any fails). G1 exact, on fixtures: S(x) = sum_{n in J} a(n)Lambda(n) computed DIRECTLY equals T_1 + T_2 + E_pp -- as an exact rational combination of the symbols log p, i.e. in the same formal-log basis the corpus's own validator uses. This validates both implementations against a trivial sum. G2 exact, on fixtures: T_2 = D_y + density_odd + E_even, where density_odd = sum_{e odd <= Q} mu(e)/phi(e) sum_{n>a_e} f(n) (log e - log n) and E_even is the even-e part of T_2. This is the corpus's (10), checked as an identity in the log basis. G3 exact, on fixtures: E_pp >= 0, and the boundary e with e*y >= x contributes exactly zero. G4 (11): sum_{e -2C_2. G5 NEGATIVE CONTROLS: delete the moving boundary, and replace phi(e) by e -- each must move the value. A control that does not move means the check is not measuring what it claims. Usage: python centered-census.py exact --x 256 [--ys 15,20,32] python centered-census.py sweep --x 1048576 [--cuts 776,900,1024] """ import argparse import json import math import sys from fractions import Fraction sys.stdout.reconfigure(encoding='utf-8') # ---------------------------------------------------------------- shared utilities def sieve_spf(N): spf = list(range(N + 1)) i = 2 while i * i <= N: if spf[i] == i: for j in range(i * i, N + 1, i): if spf[j] == j: spf[j] = i i += 1 return spf def sieve_mu(N): """mu by flipping multiples of each prime. The sieve flag MUST be separate from mu itself. A first version tested `if mu[p] == 1` to recognise a prime, but a squarefree p with an even number of prime factors has mu[p] = 1 too, so composites like 6, 10, 30 were sieved a second time and came out with the wrong sign. The gates caught it (G1 residual was the whole of S). """ mu = [1] * (N + 1) mu[0] = 0 comp = bytearray(N + 1) for p in range(2, N + 1): if not comp[p]: for j in range(p, N + 1, p): mu[j] = -mu[j] pp = p * p for j in range(pp, N + 1, pp): mu[j] = 0 for j in range(pp, N + 1, p): comp[j] = 1 return mu def factorize(n, spf): out = [] while n > 1: p = spf[n] e = 0 while n % p == 0: n //= p e += 1 out.append((p, e)) return out def prime_power_log(n, spf): """(p, 1) when n is a prime power p^k, else None -- Lambda's support.""" if n < 2: return None f = factorize(n, spf) return (f[0][0], 1) if len(f) == 1 else None # ---------------------------------------------------------------- exact log-basis arithmetic # Every quantity in the chain is a rational POLYNOMIAL in the symbols {log p} -- degree 2, since # a(n) = Lambda(n-2) is itself a logarithm. Representing a polynomial as {monomial: Fraction}, # with a monomial a sorted tuple of primes (repetition = power), makes the identities of the chain # EXACT to check, in the same "formal prime logarithms" basis the corpus's own moving-cutoff # validator uses. A first version of this file used a linear {p: Fraction} basis, which cannot # hold log d * log p; the gates caught it (see the framework review). def mono(*primes): return tuple(sorted(primes)) def pmul(m1, m2): return tuple(sorted(m1 + m2)) def padd(P, key, c): v = P.get(key, Fraction(0)) + c if v: P[key] = v elif key in P: del P[key] def ladd(dest, src, scale=Fraction(1)): """dest += scale * src, both polynomials.""" for k, c in src.items(): padd(dest, k, scale * c) def logpoly(n, spf): """log n as a polynomial: the SUM over n's distinct primes of e_p * log p. A first version returned one monomial carrying all of n's primes, which represents the PRODUCT log 2 * log 5 for n = 10 instead of the sum log 2 + log 5. The gates caught it: the G1 residual was exactly the terms where a composite index appears in a logarithm. """ out = {} if n < 2: return out for p, e in factorize(n, spf): padd(out, mono(p), Fraction(e)) return out def prod_poly(P, Q): out = {} for k1, c1 in P.items(): for k2, c2 in Q.items(): padd(out, pmul(k1, k2), c1 * c2) return out def apoly(n, spf): """a(n) = Lambda(n-2) as a polynomial: log p when n-2 is a prime power, else 0.""" pp = prime_power_log(n - 2, spf) return {mono(pp[0]): Fraction(1)} if pp else {} def lpoly(n, spf): """Lambda(n) as a polynomial.""" pp = prime_power_log(n, spf) return {mono(pp[0]): Fraction(1)} if pp else {} def zero(P): return {k: v for k, v in P.items() if v} def squarefree_scale(P, k): """k * P for a rational scalar k.""" return zero({m: k * c for m, c in P.items()}) def exact_census(x, y): spf = sieve_spf(x + 2) mu = sieve_mu(x + 2) J = range(x // 2 + 1, x + 1) Q = x // y phi = {e: (sum(1 for aa in range(1, e + 1) if math.gcd(aa, e) == 1) if e > 1 else 1) for e in range(1, Q + 1)} ap = {n: apoly(n, spf) for n in J} lp = {n: lpoly(n, spf) for n in J} # S(x) = sum_{n in J} Lambda(n-2) Lambda(n), computed DIRECTLY -- the gate's other side S = {} for n in J: ladd(S, prod_poly(ap[n], lp[n])) # E_pp = sum_{n in J, mu^2(n)=0} a(n) Lambda(n) >= 0, term by term (a >= 0, Lambda >= 0) Epp = {} Epp_terms = 0 for n in J: if mu[n] == 0 and ap[n]: Epp_terms += 1 ladd(Epp, prod_poly(ap[n], lp[n])) # T_1 = -sum_{d<=y} mu(d) log d sum_{m: dm in J} a(dm) mu^2(dm) T1 = {} for d in range(1, min(y, x) + 1): if mu[d] == 0: continue ld = logpoly(d, spf) for m in range(max(1, x // (2 * d) + 1), x // d + 1): n = d * m if ap[n] and mu[n] != 0: ladd(T1, prod_poly(ld, ap[n]), Fraction(-mu[d])) # T_2 = -sum_{e<=Q} mu(e) sum_{m: em in J, m>y} log(m) f(em); split odd/even e T2_odd, T2_even = {}, {} for e in range(1, Q + 1): if mu[e] == 0: continue tgt = T2_odd if e % 2 else T2_even for m in range(max(y + 1, x // (2 * e) + 1), x // e + 1): n = e * m if ap[n] and mu[n] != 0: ladd(tgt, prod_poly(logpoly(m, spf), ap[n]), Fraction(-mu[e] * mu[n])) # density_odd = sum_{e odd <= Q} mu(e)/phi(e) sum_{n>a_e} f(n) (log e - log n) density = {} for e in range(1, Q + 1, 2): if mu[e] == 0: continue a_e = max(x // 2, e * y) le = logpoly(e, spf) for n in J: if n <= a_e or not ap[n] or mu[n] == 0: continue fp = squarefree_scale(ap[n], Fraction(mu[n])) ladd(density, prod_poly(fp, le), Fraction(mu[e], phi[e])) ladd(density, prod_poly(fp, logpoly(n, spf)), Fraction(-mu[e], phi[e])) # D_y from (9), directly Dy = {} for e in range(1, Q + 1, 2): if mu[e] == 0: continue a_e = max(x // 2, e * y) for m in range(max(y + 1, x // (2 * e) + 1), x // e + 1): n = e * m if ap[n] and mu[n] != 0: ladd(Dy, prod_poly(logpoly(m, spf), ap[n]), Fraction(-mu[e] * mu[n])) le = logpoly(e, spf) for n in J: if n <= a_e or not ap[n] or mu[n] == 0: continue fp = squarefree_scale(ap[n], Fraction(mu[n])) ladd(Dy, prod_poly(fp, le), Fraction(-mu[e], phi[e])) ladd(Dy, prod_poly(fp, logpoly(n, spf)), Fraction(mu[e], phi[e])) boundary_empty = [e for e in range(1, Q + 1) if e * y >= x] # G5 controls: the first computes D_y with phi(e) replaced by e; the second with the moving # boundary a_e deleted (static cut). A control that does not move means the check is blind. ctl_phi = {} for e in range(1, Q + 1, 2): if mu[e] == 0: continue a_e = max(x // 2, e * y) le = logpoly(e, spf) for n in J: if n <= a_e or not ap[n] or mu[n] == 0: continue fp = squarefree_scale(ap[n], Fraction(mu[n])) ladd(ctl_phi, prod_poly(fp, le), Fraction(-mu[e], e)) ladd(ctl_phi, prod_poly(fp, logpoly(n, spf)), Fraction(mu[e], e)) ctl_boundary = {} for e in range(1, Q + 1, 2): if mu[e] == 0: continue le = logpoly(e, spf) for n in J: if n <= x // 2 or not ap[n] or mu[n] == 0: continue fp = squarefree_scale(ap[n], Fraction(mu[n])) ladd(ctl_boundary, prod_poly(fp, le), Fraction(-mu[e], phi[e])) ladd(ctl_boundary, prod_poly(fp, logpoly(n, spf)), Fraction(mu[e], phi[e])) return {"x": x, "y": y, "Q": Q, "S": S, "Epp": Epp, "Epp_terms": Epp_terms, "T1": T1, "T2_odd": T2_odd, "T2_even": T2_even, "density": density, "Dy": Dy, "ctl_phi": ctl_phi, "ctl_boundary": ctl_boundary, "boundary_empty": boundary_empty} def pcomb(d1, d2): out = dict(d1) for p, c in d2.items(): v = out.get(p, Fraction(0)) + c if v: out[p] = v elif p in out: del out[p] return out def check_exact(x, ys): report = [] for y in ys: r = exact_census(x, y) lhs = dict(r["T1"]) ladd(lhs, r["T2_odd"]); ladd(lhs, r["T2_even"]); ladd(lhs, r["Epp"]) d1 = pcomb(lhs, {k: -c for k, c in r["S"].items()}) g1 = (d1 == {}) # (10) split by parity of e: T_2 = T_2^odd + T_2^even and E_even IS T_2^even, so the # identity to check is T_2^odd = D_y + density_odd -- an earlier version of this gate added # T_2^even to the right-hand side and therefore reported a residual equal to -T_2^even. rhs = dict(r["Dy"]); ladd(rhs, r["density"]) d2 = pcomb(r["T2_odd"], {k: -c for k, c in rhs.items()}) g2 = (d2 == {}) report.append({"x": x, "y": y, "Q": Q if False else r["Q"], "G1 S = T1+T2+Epp": g1, "G1 residual monomials": len(d1), "G2 T2_odd = Dy + density_odd": g2, "G2 residual monomials": len(d2), "E_even monomials (= T2_even, definitional)": len(r["T2_even"]), "E_pp terms (all positive)": r["Epp_terms"], "boundary e with e*y>=x": r["boundary_empty"], "G5.phi->e moves the value": r["ctl_phi"] != r["Dy"], "G5.boundary deleted moves the value": r["ctl_boundary"] != r["Dy"]}) return report # ---------------------------------------------------------------- float census at scale def float_arrays(x): import numpy as np mu = np.array(sieve_mu(x), dtype=np.int64) lam = np.zeros(x + 1) sqrtx = int(math.isqrt(x)) is_p = np.ones(x + 1, dtype=bool) is_p[:2] = False for p in range(2, sqrtx + 1): if is_p[p]: is_p[p * p::p] = False primes = np.nonzero(is_p)[0] lam[primes] = np.log(primes.astype(float)) for p in primes: q = int(p) * int(p) while q <= x: lam[q] = math.log(int(p)) q *= int(p) return np, mu, lam def float_cut(x, y, np, mu, lam, cache): n0 = x // 2 + 1 if 'n' not in cache: n = np.arange(n0, x + 1, dtype=np.int64) cache['n'] = n cache['a'] = lam[n - 2] cache['mun'] = mu[n] cache['f'] = cache['a'] * cache['mun'] cache['logn'] = np.log(n.astype(float)) cache['S'] = float(np.sum(cache['a'] * lam[n])) nonfree = (mu[n] == 0) cache['Epp'] = float(np.sum(cache['a'][nonfree] * lam[n][nonfree])) fw = cache['f'] cache['F1'] = np.concatenate([np.cumsum(fw[::-1])[::-1], [0.0]]) # suffix sums cache['F2'] = np.concatenate([np.cumsum((fw * cache['logn'])[::-1])[::-1], [0.0]]) a, mun, f, logn = cache['a'], cache['mun'], cache['f'], cache['logn'] Q = x // y T1 = 0.0 for d in range(1, min(y, x) + 1): if mu[d] == 0: continue mlo = max(1, x // (2 * d) + 1) mhi = x // d if mlo > mhi: continue ms = np.arange(mlo, mhi + 1) idx = d * ms - n0 sel = mun[idx] != 0 if sel.any(): T1 += -mu[d] * math.log(d) * float(np.sum(a[idx][sel])) T2o = T2e = 0.0 Dy = 0.0 for e in range(1, Q + 1): if mu[e] == 0: continue mlo = max(y + 1, x // (2 * e) + 1) mhi = x // e val = 0.0 if mlo <= mhi: ms = np.arange(mlo, mhi + 1) idx = e * ms - n0 sel = mun[idx] != 0 if sel.any(): val = float(np.sum(np.log(ms[sel]) * f[idx][sel])) if e % 2: T2o += -mu[e] * val if mlo <= mhi: ms = np.arange(mlo, mhi + 1) idx = e * ms - n0 sel = mun[idx] != 0 Dy += -mu[e] * float(np.sum(np.log(ms[sel]) * f[idx][sel])) else: T2e += -mu[e] * val # density_odd via suffix sums phi = [0] * (Q + 1) for e in range(1, Q + 1): phi[e] = sum(1 for aa in range(1, e + 1) if math.gcd(aa, e) == 1) if e > 1 else 1 density = 0.0 for e in range(1, Q + 1, 2): if mu[e] == 0: continue a_e = max(x // 2, e * y) if a_e >= x: continue k = a_e + 1 - n0 F1 = cache['F1'][k] F2 = cache['F2'][k] density += (mu[e] / phi[e]) * (math.log(e) * F1 - F2) Dy += -(mu[e] / phi[e]) * (math.log(e) * F1 - F2) I = T1 + T2o + T2e M = float(np.sum(f)) return {"x": x, "y": y, "Q": Q, "T1": T1, "T2": T2o + T2e, "T2_odd": T2o, "T2_even": T2e, "invariant_I": I, "Dy": Dy, "M": M, "S": cache['S'], "Epp": cache['Epp'], "resid_G1": (I + cache['Epp']) - cache['S'], "resid_G2": T2o - (Dy + density)} def main(): ap = argparse.ArgumentParser() ap.add_argument('mode', choices=['exact', 'sweep']) ap.add_argument('--x', type=int, required=True) ap.add_argument('--ys', default=None) ap.add_argument('--cuts', default=None) a = ap.parse_args() if a.mode == 'exact': ys = [int(t) for t in (a.ys or '').split(',') if t] or [math.ceil(a.x ** 0.48)] print(json.dumps(check_exact(a.x, ys), indent=1)) return 0 np, mu, lam = float_arrays(a.x) if a.cuts: cuts = [int(t) for t in a.cuts.split(',')] else: # The admissible window of the note: the Möbius-mean input needs Q = floor(x/y) <= x^(13/25), # i.e. y >= x^(12/25); the Bombieri-Vinogradov input needs the moduli [d,b^2] <= y (log x)^k # below the BV level x^(1/2). So the window is [x^(12/25), x^(1/2)] up to log powers -- a # factor ~x^(1/50), i.e. 1.15 at x=2^20, at reachable scales. An earlier default used # sqrt(x)/log(x) as the top, which at reachable x falls BELOW the bottom and silently made # the sweep a diagnostic rather than a statement about the admissible window. lo = math.ceil(a.x ** (12 / 25)) hi = math.isqrt(a.x) cuts = sorted({lo, lo + (hi - lo) // 3, lo + 2 * (hi - lo) // 3, hi}) cache = {} rows = [] for y in cuts: rows.append(float_cut(a.x, y, np, mu, lam, cache)) outs = [] for r in rows: outs.append({k: (round(v, 6) if isinstance(v, float) else v) for k, v in r.items() if k in ('x', 'y', 'Q')} | {k: round(r[k] / r['x'], 8) for k in ('T1', 'T2', 'T2_odd', 'T2_even', 'invariant_I', 'Dy', 'M', 'S', 'Epp')} | {"resid_G1": r['resid_G1'], "resid_G2": r['resid_G2']}) def spread(key): v = [r[key] / r['x'] for r in rows] return round(max(v) - min(v), 8) print(json.dumps({"x": a.x, "cuts": cuts, "rows_over_x": outs, "spread_over_x": {k: spread(k) for k in ('T1', 'T2', 'T2_odd', 'T2_even', 'invariant_I', 'Dy', 'S', 'Epp')}, "threshold_4_over_25": 0.16, "budget_1_over_log2x": round(1 / math.log(a.x) ** 2, 6)}, indent=1)) return 0 if __name__ == '__main__': sys.exit(main())