reach.py
Checks: TRIPLE: The least partial place leans non-square observation; rule.
Cited on: TRIPLE.
To run it: save reach.py, with central.py, cubic.py, room.py beside it; needs mpmath.
"""reach.py -- the worst-case room of L(s, rho) past width 6, and how much
of the least odd partial place's lean it carries.
QUESTION. K a complex cubic field of 2-rank 1, L/K its unramified
quadratic extension, rho = zeta_L/zeta_K. room.py's (9): U_A(T) =
log |d_K| + G(T) - sum w c, with the primes of A in 2Cl and every other
class-dependent prime outside, bounds the zero sum H(T) over every
configuration with A in, so U_A < 0 at some width forbids A under GRH
from K's splitting and |d_K| alone. Over room.py's population read
afresh with every prime to e^8 = 2980, at room.py's widths and 7, 8:
(a) do the fields left free at T <= 6 fall? (b) does the first prime's
forbidden share rise? (c) THE LEAN: where the first prime of room.py's
(8) order is the least odd partial place, its outside share s, the
share f the bound forbids in 2Cl (so forces outside), and s' the
outside share over the fields it leaves free.
THE DERIVATION (before code). A free partial or split prime outside
adds +w at k = 1 (c = -1), w = 2 log p F_T(log p)/sqrt p; at p near e^4,
w = 0.12 at T = 6 and 0.34 at T = 8 (f(2/3) = 0.109, f(1/2) = 1/pi),
so the free primes' sum grows like e^(T/2) while log |d_K| + G(T) falls
0.78 from T = 6 to 8 and a held prime's -2w at p = 3 moves 2.18 to
2.33. Hence U_A(8) > U_A(6) almost everywhere: widths 7, 8 forbid
almost nothing new; the wall is the worst case, each free prime at its
least coefficient independently. TRANSPLANT: "wider support sharpens"
comes from Odlyzko's discriminant bounds, where every coefficient is
>= 0; here the free ones are adversarial. f <= s exactly (C2: a forbidden field
reads outside); s' = (s - f)/(1 - f), its se binomial over the free
fields.
PREDICTIONS, frozen before the engine.
P1 at T <= 8, at least 18 of the 21 fields free at T <= 6 stay free.
P2 the first prime's forbidden share at T <= 8 is <= 0.615.
P3 printed, not judged: each forbidding's least margin, the largest
min_T U_A among the forbidden.
P4 printed, not judged: s' by terciles of the held configuration's
headroom min_T U_A over the free fields; predicted falling toward 1/2.
KILL CARRIES. "The conductor's worst case carries the lean of the
least odd partial place" only if s' at T <= 8 is <= 0.60.
C1 the fresh read reproduces room.py's F7 at widths <= 6: 1532
fields, the first prime forbidden at 925, both at 1511, 21 free;
the least odd partial place outside at 0.817.
C2 no actual configuration forbidden at any width <= 8; the actual
H(T) >= 0 at T = 7, 8 (GRH); U_empty >= H everywhere.
C3 the formula at T = 7, 8 on zeta and L(s, chi_-3) (central.py's K3).
C4 THE BREAK: sides permuted across the lean fields make some
forbidden field read in 2Cl.
ADDED BEFORE THE FIRST RUN, a print: f and s' over every field with an
odd partial prime, holding the least odd partial place alone in (a
valid bound wherever it sits in (8)'s order).
CHANGED BEFORE THE FIRST FULL RUN: C1 compares nothing at a rehearsal
cap, and its 0.817 is room.py's share over least odd partial primes
<= 403; a rehearsal reads past a failed control (at --cap 6000 C4 has
no field in 2Cl to permute: all 59 lean fields read outside).
FINDINGS.
F0 CONTROLS (C1 to C4 held). The formula at T = 7, 8 to 2.5e-7;
7975 fields, 1532 of 2-rank 1, no relation broken, no place
unplaced; at T <= 6 the first prime forbidden at 925, both at
1511, 21 free from |d_K| = 21767, the least odd partial outside
0.8166, all as room.py's F7; no actual pattern forbidden at any
width, the least H(7), H(8) 0.0009; permuted sides put 49 of the 727
lean fields in 2Cl where the bound forbids it.
F1 WIDTH 7 AND 8 FORBID NOTHING (P1, P2 held). At T <= 7 and T <= 8
the counts are T <= 6's: 925 (0.604), 1511 (0.986). All 21 free
fields stay free, U2 rising from a least 0.013 to 0.436 at T <= 6
to 1.075 to 3.374 at T = 7 and 3.317 to 6.561 at T = 8. The least
U1 of a forbidden field sits at T = 4 (66), 5 (750), 6 (109), never
past 6: the free primes' worst case grows faster than the conductor
term falls, as derived.
F2 THE MARGIN (P3). The forbidding nearest 0: -0.0007 for the first
prime, -0.0287 for both, at every width set; far above float error.
F3 THE BOUND CARRIES PART OF THE LEAN (KILL CARRIES FIRED). Where the
first prime is the least odd partial place (727 fields) it reads
outside at 0.895 +- 0.011, the bound forbids it in 2Cl at 0.561,
and over the 319 fields it leaves free it reads outside at 0.762
+- 0.024 (bar 0.60). Over every field, the least odd partial place
held alone: outside 0.817 +- 0.010, forbidden in 0.362, outside
over the 978 free 0.713 +- 0.014. The same at T <= 6 and T <= 8.
F4 printed, not judged (P4). Over the 319 free lean fields by
terciles of min U1: outside 0.802, 0.783, 0.701 (+- 0.039 to
0.044) as the headroom runs 0.002 to 0.326, 0.334 to 0.762, 0.769
to 1.897: falling, its largest tercile 0.701.
TIERS. Each forbidding is a rule under GRH at the field read; F1 to F4
are observations over this population.
RUN RECORD. 4/4 controls, 435.8 s (the population 360.1 s, 7975
fields, checkpointed; the formula 75 s), peak commit 222.2 MB under a
memory guard (512 MB). A rehearsal at --cap 6000 first ran its formula
section at cubic.py's 60 digits (217 s), moved inside the 20-digit block
before any reading; then 75 s, 108.7 MB.
"""
import hashlib
import inspect
import json
import os
import random
import sys
import tempfile
import time
from math import exp, log, sqrt
os.environ.setdefault("OPENBLAS_NUM_THREADS", "1")
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
import mpmath # noqa: E402
import cubic as C # noqa: E402
import room as R # noqa: E402
import central as Z # noqa: E402
RESULTS = []
LOW = list(R.WIDTHS) # room.py's widths, to 6
WIDTHS = LOW + [7, 8]
PMAX = int(exp(max(WIDTHS))) # 2980
SEED = 1658
R.PRIMES = [p for p in C.PRIMES if p <= PMAX] # read_field's primes
def check(name, ok, detail=""):
RESULTS.append(bool(ok))
print(f" [{'PASS' if ok else 'FAIL'}] {name}"
+ (f" -- {detail}" if detail else ""))
T0 = time.time()
def section(title):
print(f"\n{title} [{time.time() - T0:.0f} s]")
def weights(T):
W = {}
for p in R.PRIMES:
k = 1
while k * log(p) < T:
W[(p, k)] = 2 * log(p) * R.f(k * log(p) / T) / p ** (k / 2)
k += 1
return W
W = {T: weights(T) for T in WIDTHS}
G = {}
_SRC = hashlib.sha1(
open(os.path.join(HERE, "cubic.py"), "rb").read()
.split(b'"""', 2)[2] + inspect.getsource(R.read_field).encode()
+ str(PMAX).encode()).hexdigest()[:12]
CKPT = os.path.join(tempfile.gettempdir(),
"reach_%d_%s.json" % (R.CAP, _SRC))
def population():
if "--fresh" not in sys.argv and os.path.exists(CKPT):
print(" read from the checkpoint %s" % CKPT)
with open(CKPT) as fh:
return json.load(fh)
t0 = time.time()
F = C.enumerate_fields(R.CAP)
print(" %d complex cubic fields with |d_K| <= %d" % (len(F), R.CAP))
recs = []
for i, (key, dk) in enumerate(sorted(F.items(),
key=lambda kv: (-kv[1], kv[0]))):
recs.append(R.read_field(key, dk))
if (i + 1) % 1000 == 0:
print(" %d fields read, %.0f s" % (i + 1, time.time() - t0),
flush=True)
with open(CKPT, "w") as fh:
json.dump(recs, fh)
print(" read in %.1f s, checkpointed to %s" % (time.time() - t0, CKPT))
return recs
def upper(rec, held, actual=False):
"""U_A(T) over WIDTHS, room.py's upper at these weights."""
logq, U = log(-rec["d"]), {}
pr = {p: (t, v) for p, t, v in rec["primes"]}
for T in WIDTHS:
s = 0.0
for (p, k), w in W[T].items():
t, v = pr[p]
if p in held:
v = 0
elif not actual and t in R.OUT:
v = R.OUT[t]
s += w * R.coeff(t, v, k)
U[T] = logq + G[T] - s
return U
def least(U, widths):
return min(U[T] for T in widths)
def share(v):
n = len(v)
if n == 0:
return float("nan"), float("nan"), 0
s = sum(v) / n
return s, sqrt(s * (1 - s) / n), n
def main():
t0 = time.time()
section("A THE FORMULA")
with mpmath.workdps(20):
for T in WIDTHS:
G[T] = 2 * R.gamma_piece(T, 0) + R.gamma_piece(T, 1)
Z.G[T] = G[T]
for T in WIDTHS:
print(" T %-4g G %9.4f e^-G %8.0f" % (T, G[T], exp(-G[T])))
Z.control_wide()
RESULTS.extend(Z.RESULTS)
section("B THE POPULATION")
recs = population()
seat = [r for r in recs if r["ok"] and "primes" in r]
bad = sum(r["bad"] for r in seat)
unpl = sum(r["unplaced"] for r in seat)
print(" fields %d, uncertified %d, 2-rank 1 %d; bad %d, unplaced %d"
% (len(recs), sum(not r["ok"] for r in recs), len(seat), bad,
unpl))
rows = []
for rec in seat:
seq = R.sequence(rec)
p1, p2 = seq[0], seq[1]
lop = [(p, v) for p, t, v in rec["primes"] if t == "p" and p > 2]
lop = lop[0] if lop else None
row = {"d": rec["d"], "seq": seq,
"H": upper(rec, set(), actual=True),
"U0": upper(rec, set()),
"U1": upper(rec, {p1[0]}),
"U2": upper(rec, {p1[0], p2[0]}),
"lop": lop,
"UL": upper(rec, {lop[0]}) if lop else None}
rows.append(row)
def forb(U, widths):
return least(U, widths) < 0
section("C CONTROLS")
n = len(rows)
wc1 = sum(forb(r["U1"], LOW) for r in rows)
wc2 = sum(forb(r["U2"], LOW) for r in rows)
free6 = [r for r in rows if not forb(r["U2"], LOW)]
lops = [r["lop"][1] for r in rows if r["lop"] and r["lop"][0] <= 403]
s_all = share(lops)
ok1 = (n == 1532 and wc1 == 925 and wc2 == 1511 and len(free6) == 21
and abs(s_all[0] - 0.817) < 0.0005) or R.CAP != 48000
check("C1 room.py's F7 at T <= 6 reproduced"
+ (" (a rehearsal: not compared)" if R.CAP != 48000 else ""), ok1,
"%d fields, first %d, both %d, free %d, least free |d_K| %d;"
" least odd partial outside %.4f (%d)"
% (n, wc1, wc2, len(free6),
min(-r["d"] for r in free6) if free6 else 0, s_all[0],
s_all[2]))
clash = 0
for r in rows:
o1, o2 = r["seq"][0][2], r["seq"][1][2]
clash += forb(r["U1"], WIDTHS) and not o1
clash += forb(r["U2"], WIDTHS) and not o1 and not o2
if r["lop"]:
clash += forb(r["UL"], WIDTHS) and not r["lop"][1]
hmin = min(least(r["H"], [7, 8]) for r in rows)
gap = min(r["U0"][T] - r["H"][T] for r in rows for T in WIDTHS)
check("C2 no actual pattern forbidden; H(7), H(8) >= 0; U_empty >= H",
clash == 0 and hmin >= -1e-9 and gap >= -1e-9 and bad == 0
and unpl == 0,
"forbidden yet seen %d, least H(7, 8) %.4f, least U - H %.2e"
% (clash, hmin, gap))
lean = [r for r in rows if r["seq"][0][1] == "p" and r["seq"][0][0] > 2]
rng = random.Random(SEED)
perm = [r["seq"][0][2] for r in lean]
rng.shuffle(perm)
broke = sum(1 for r, o in zip(lean, perm)
if forb(r["U1"], WIDTHS) and not o)
check("C4 THE BREAK: permuted sides put forbidden fields in 2Cl",
broke > 0, "%d of %d lean fields" % (broke, len(lean)))
if not all(RESULTS) and R.CAP == 48000:
print("\na control failed; nothing below is read")
raise SystemExit(1)
section("D PAST T = 6")
for name, ws in (("T <= 6", LOW), ("T <= 7", LOW + [7]),
("T <= 8", WIDTHS)):
a = sum(forb(r["U1"], ws) for r in rows)
b = sum(forb(r["U2"], ws) for r in rows)
print(" %s: first forbidden %d (%.3f), both %d (%.3f)"
% (name, a, a / n, b, b / n))
stay = [r for r in free6 if not forb(r["U2"], WIDTHS)]
print(" P1 of the %d free at T <= 6, %d stay free at T <= 8 (>= 18)"
% (len(free6), len(stay)))
for r in free6:
print(" d %d min U2 to 6 %.3f, U2(7) %.3f, U2(8) %.3f"
% (r["d"], least(r["U2"], LOW), r["U2"][7], r["U2"][8]))
a8 = sum(forb(r["U1"], WIDTHS) for r in rows)
print(" P2 first prime forbidden at T <= 8: %.3f (<= 0.615)" % (a8 / n))
wins = {}
for r in rows:
if forb(r["U1"], WIDTHS):
T = min(WIDTHS, key=lambda t: r["U1"][t])
wins[T] = wins.get(T, 0) + 1
print(" the width of least U1 among the forbidden: %s"
% ", ".join("%g: %d" % kv for kv in sorted(wins.items())))
for name, key in (("first", "U1"), ("both", "U2")):
for wn, ws in (("T <= 6", LOW), ("T <= 8", WIDTHS)):
m = [least(r[key], ws) for r in rows if forb(r[key], ws)]
print(" P3 %s, %s: least margin %.4f (largest min U among"
" %d forbidden)" % (name, wn, max(m), len(m)))
section("E THE LEAN")
def lean_read(pop, key, side, label):
out = []
for wn, ws in (("T <= 6", LOW), ("T <= 8", WIDTHS)):
fo = [forb(r[key], ws) for r in pop]
sv = [side(r) for r in pop]
s, se, m = share(sv)
f = sum(fo) / m
fr = [o for o, x in zip(sv, fo) if not x]
s1 = share(fr)
print(" %s, %s: %d fields, outside %.3f +- %.3f, forbidden in"
" %.3f, outside over the free %.3f +- %.3f (%d)"
% (label, wn, m, s, se, f, s1[0], s1[1], s1[2]))
out.append(s1[0])
return out
sl = lean_read(lean, "U1", lambda r: r["seq"][0][2],
"first prime the least odd partial")
allp = [r for r in rows if r["lop"]]
lean_read(allp, "UL", lambda r: r["lop"][1],
"every field, the least odd partial held")
fr = [r for r in lean if not forb(r["U1"], WIDTHS)]
fr.sort(key=lambda r: least(r["U1"], WIDTHS))
k = len(fr) // 3
print(" P4 outside over the free by terciles of min U1:")
for i, part in enumerate((fr[:k], fr[k:2 * k], fr[2 * k:])):
if not part:
continue
s, se, m = share([r["seq"][0][2] for r in part])
print(" tercile %d: min U1 %.3f to %.3f, outside %.3f +- %.3f"
" (%d)" % (i + 1, least(part[0]["U1"], WIDTHS),
least(part[-1]["U1"], WIDTHS), s, se, m))
section("F THE VERDICT")
print(" KILL CARRIES %s: s' at T <= 8 %.3f (bar 0.60)"
% ("MISSED" if sl[1] <= 0.60 else "FIRED", sl[1]))
print("\n%d/%d controls, %.1f s" % (sum(RESULTS), len(RESULTS),
time.time() - t0))
raise SystemExit(0 if all(RESULTS) else 1)
if __name__ == "__main__":
main()