#!/usr/bin/env python3 """Job 1025 triage, route 12: the smallest experiment on the uncovered step. Route 12 wants the fixed shift 2 recovered from a shift average, and prices one script at 0.1 CPU h. This is that script's core question, run at x = 10^6 over H = 50 shifts, exact integer sums: S(h) = sum_{n<=x} Lambda(n) mu(n-h) (the pair the route needs) S_lam(h) = sum_{n<=x} mu(n) lambda(n-h) (the recorded Liouville control pair) and for each: V = sum_h (S(h) - mean_h S)^2, the share of V carried by h = 2 alone, plus the fixed-shift mass |S(2)| and the root-mean-square of the other shifts, so the ratio the route's success criterion is about is printed directly. Pure Python, stdlib only, deterministic, no floats in the sums. """ import math import sys import time X = 10 ** 6 HMAX = 51 # shifts h = 2..51 H = HMAX - 1 # 50 shifts M = X t0 = time.time() spf = [0] * (M + 1) for p in range(2, M + 1): if spf[p] == 0: for j in range(p, M + 1, p): if spf[j] == 0: spf[j] = p if spf[1] == 0: spf[1] = 1 mu = [0] * (M + 1) om = [0] * (M + 1) mu[1] = 1 for n in range(2, M + 1): p = spf[n] m = n // p om[n] = om[m] + 1 mu[n] = 0 if m % p == 0 else -mu[m] lam = [1] * (M + 1) for n in range(2, M + 1): lam[n] = 1 if om[n] % 2 == 0 else -1 Lam = [0.0] * (M + 1) for p in range(2, M + 1): if spf[p] == p: pk = p while pk <= M: Lam[pk] = math.log(p) pk *= p print("sieve to %d done in %.1f s (spf, mu, omega, lambda, Lambda)" % (M, time.time() - t0), file=sys.stderr) def profile(a, b): """S(h) = sum_{n<=X} a(n) b(n-h) for h = 2..HMAX, and the variance decomposition.""" s = {} for h in range(2, HMAX + 1): tot = 0 for n in range(h + 1, X + 1): if a[n]: g = b[n - h] if g: tot += a[n] * g s[h] = tot vals = [s[h] for h in range(2, HMAX + 1)] mean = sum(vals) / H dev = [(v - mean) ** 2 for v in vals] V = sum(dev) diag = dev[0] others = [abs(s[h]) for h in range(3, HMAX + 1)] return s, mean, V, diag, sum(others) / len(others) # a is the FLIPPED factor so the product uses a(n)*b(n-h) with integer/float mix kept exact s_ml, mean_ml, V_ml, diag_ml, rms_ml = profile(Lam, mu) print() print("pair (Lambda(n), mu(n-h)), x = 1e6, shifts h = 2..%d" % HMAX) print(" S(2) = %.1f mean_h S = %.1f max |S(h)|, h>=3 = %.1f" % (s_ml[2], mean_ml, max(abs(s_ml[h]) for h in range(3, HMAX + 1)))) print(" V = sum_h (S(h)-mean)^2 = %.4g" % V_ml) print(" share of V carried by h=2 alone: %.4f (the null for 50 independent shifts is %.4f)" % (diag_ml / V_ml, 1.0 / H)) print(" ratio |S(2)| / mean_{h>=3}|S(h)| = %.3f" % (abs(s_ml[2]) / rms_ml)) print() s_lm, mean_lm, V_lm, diag_lm, rms_lm = profile(mu, lam) print("control pair (mu(n), lambda(n-h)) - the register's Liouville counterexample family") print(" S(2) = %.1f mean_h S = %.1f max |S(h)|, h>=3 = %.1f" % (s_lm[2], mean_lm, max(abs(s_lm[h]) for h in range(3, HMAX + 1)))) print(" V = %.4g share of V at h=2: %.4f ratio |S(2)|/mean_{h>=3}|S(h)| = %.3f" % (V_lm, diag_lm / V_lm, abs(s_lm[2]) / rms_lm)) print() print("READING (route 12's own success/failure line): success needs the h=2 diagonal to dominate V.") print("Both pairs are printed with the same statistic, so the triage decides with the control in hand.")