Does light charge the quons? › Files cited on the page › check_ladder_fable/

check_ladder.py

In the investigation at sim/charge_wave/check_ladder_fable/check_ladder.py · last changed in commit 23afed1, 15 November 2026 · 21,833 bytes · the folder as a zip


"""check_ladder.py - the eleventh independent reviewer's own reproduction of trial 8 (ladder_handover.py, lock
papers/Lock_ladder_handover_2026-11-15.md), with the extra tests the brief asks for.

Written from the lock and the model (eps(w)/eps0 = f + sum_k h_k w_k^2/(w_k^2 - w^2), eps(0) = eps0), not copied from the script.
Run: ~/aspden-review-venv/bin/python3 check_ladder.py > check_ladder_out.txt 2>&1
"""
import math, subprocess, time
import numpy as np
from scipy.integrate import quad

def clock():
    return subprocess.run(["date"], env={"TZ": "America/New_York"}, capture_output=True, text=True).stdout.strip()

print("Eleventh reviewer's check of trial 8; start", clock())
T_START = time.time()

# ------------------------------------------------------------------ constants (CODATA 2018), as in the record
hbar = 1.054571817e-34; me = 9.1093837015e-31; c = 299792458.0; eV = 1.602176634e-19
hbarc = hbar * c / eV                              # eV m
E511 = me * c**2 / eV                              # 510998.95 eV
r_asp = hbar / (2 * me * c); d_asp = r_asp / (0.75 * (8 / 1843) ** (1 / 6))
print(f"m_e c^2 = {E511:.2f} eV; Aspden's d = {d_asp:.4e} m (record: 6.3740e-13)")

# ------------------------------------------------------------------ the optical model, written independently
def n_and_ng(E, Ek, hk):
    """Refractive index n and group index n_g = d(w n)/dw, exact for the lossless model, at photon energies E."""
    E = np.atleast_1d(np.asarray(E, float))
    Ek = np.asarray(Ek, float); hk = np.asarray(hk, float)
    f = 1.0 - hk.sum()
    x2 = (E[:, None] / Ek[None, :]) ** 2
    eps = f + (hk[None, :] / (1 - x2)).sum(1)                      # h w_k^2/(w_k^2-w^2) = h/(1-x^2)
    deps_dlnw = (hk[None, :] * 2 * x2 / (1 - x2) ** 2).sum(1)       # w deps/dw
    n = np.sqrt(eps)
    ng = n + deps_dlnw / (2 * n)
    return n, ng

def phi(x):
    """First-order per-unit-share group-index change: n_g - 1 = (h/2) phi(x), x = E/E_k."""
    x2 = x * x
    return x2 * (3 - x2) / (1 - x2) ** 2

# numerical check of n_g against a finite difference of w n(w)
Ek_t = np.array([5e5, 2e6]); hk_t = np.array([3e-4, 7e-4])
for E in (1e5, 1.5e6, 1e9):
    dl = 1e-6
    nP, _ = n_and_ng(E * (1 + dl), Ek_t, hk_t); nM, _ = n_and_ng(E * (1 - dl), Ek_t, hk_t)
    fd = (E * (1 + dl) * nP[0] - E * (1 - dl) * nM[0]) / (2 * dl * E)
    _, ng = n_and_ng(E, Ek_t, hk_t)
    print(f"  group index check at {E:.1e} eV: formula {ng[0]:.12f}, finite difference {fd:.12f}, diff {ng[0]-fd:.1e}")

# ================================================================== R1
print("\n================ R1. One level against ladders (my own numbers) ================")
E_LO, E_HI = 0.1e6, 31e9; H = 1e-3
def ladder(s, kmin, kmax, lo=E_LO, hi=E_HI):
    k = np.arange(kmin, kmax + 1); E = E511 * float(s) ** k
    m = (E > lo) & (E < hi)
    return k[m], E[m]
k2, E2 = ladder(2, -2, 15); k3, E3 = ladder(3, -1, 9)
w_ln = np.exp(-0.5 * (np.log10(E2 / E511)) ** 2)
cases = {
    "(a) one level at 511 keV": (np.array([E511]), np.array([H])),
    "(b) factor 2, equal, k=-2..15": (E2, np.full(len(E2), H / len(E2))),
    "(c) factor 3, equal, k=-1..9": (E3, np.full(len(E3), H / len(E3))),
    "(d) factor 2, log-normal": (E2, H * w_ln / w_ln.sum()),
}
record = {"(a)": 1.123, "(b)": 1.537, "(c)": 1.192, "(d)": 2.375}
def ratio(Ek, hk, lo=E_LO, hi=E_HI, Hs=H):
    _, ng = n_and_ng([lo, hi], Ek, hk)
    vg = 1 / ng
    return (vg[1] - vg[0]) / (Hs / 2)
print(f"  levels in (b): k = {k2.min()}..{k2.max()} ({len(k2)}); in (c): k = {k3.min()}..{k3.max()} ({len(k3)})")
print("  case                              exact ratio   first-order sum(h/H)[phi(lo)-phi(hi)]   record")
for name, (Ek, hk) in cases.items():
    rx = ratio(Ek, hk)
    r1 = ((hk / H) * (phi(E_LO / Ek) - phi(E_HI / Ek))).sum()
    print(f"  {name:34s} {rx:8.4f}      {r1:8.4f}                               {record[name[:3]]}")

print("\n  Per-level first-order contributions to the ratio, ladder (b) (each level's share is 1/18 of H):")
Ek, hk = cases["(b) factor 2, equal, k=-2..15"]
for k, E, h in zip(k2, Ek, hk):
    print(f"    k = {k:3d}  E_k = {E:10.4g} eV   phi(lo) = {phi(E_LO/E):9.4f}   -phi(hi) = {-phi(E_HI/E):8.4f}   contribution {(h/H)*(phi(E_LO/E)-phi(E_HI/E)):8.4f}")
print("  -> the excess over 1 comes almost entirely from k = -2 (128 keV), just above the 0.1 MeV photon;")
print("     the top level k = 15 (16.7 GeV, within a factor 1.85 of 31 GeV) contributes less than its share.")

print("\n  Where a unit share counts for less than 1 (the top photon at E_hi still slowed by a level above or just below it):")
for Ek_ in (E_HI / math.sqrt(3), 22e9, 28e9, 31e9 * 1.0001, 35e9, 50e9, 100e9, 1e12):
    print(f"    E_k = {Ek_:9.3g} eV: contribution per unit share = {phi(E_LO/Ek_) - phi(E_HI/Ek_):+9.3f}")

print("\n  Constructed counter-examples (passive, lossless):")
# (e1) Doug-like ladder below 511 keV plus one level at 22 GeV tuned to cancel
Ek_in = np.array([E511 / 8, E511 / 4, E511 / 2, E511]); h_in = np.full(4, H / 4)
need = -((h_in / H) * (phi(E_LO / Ek_in) - phi(E_HI / Ek_in))).sum() / (phi(E_LO / 22e9) - phi(E_HI / 22e9))
Ek_e1 = np.append(Ek_in, 22e9); h_e1 = np.append(h_in, need * H)
print(f"    (e1) four levels 64-511 keV (total H) plus one at 22 GeV with share {need:.3f} H: ratio {ratio(Ek_e1, h_e1):+.4f}")
# (e2) same but a level just above 31 GeV
Ek_e2 = np.append(Ek_in, 35e9)
need2 = -((h_in / H) * (phi(E_LO / Ek_in) - phi(E_HI / Ek_in))).sum() / (phi(E_LO / 35e9) - phi(E_HI / 35e9))
h_e2 = np.append(h_in, need2 * H)
print(f"    (e2) the same four levels plus one at 35 GeV with share {need2:.4f} H: ratio {ratio(Ek_e2, h_e2):+.4f}")
# (e3) all share between 18 and 31 GeV
Ek_e3 = np.array([19e9, 22e9, 26e9]); h_e3 = np.full(3, H / 3)
print(f"    (e3) all of H in three levels at 19, 22, 26 GeV: ratio {ratio(Ek_e3, h_e3):+.4f} (the 31 GeV photon slower than the 0.1 MeV one)")
print("    These are tuned to one photon energy. What the other photons of the burst then see (first order, group index minus 1, units of H):")
for E in (1e8, 1e9, 1e10, 28e9, 31e9, 40e9):
    for lab, Ek_, h_ in (("e1", Ek_e1, h_e1), ("e2", Ek_e2, h_e2)):
        _, ng = n_and_ng([E], Ek_, h_)
        print(f"      {lab}: E = {E:8.3g} eV  n_g - 1 = {(ng[0]-1)/H:+9.4f} H", end="")
    print()
print("    -> a 1 GeV photon is early by about H/2 while 31 GeV is made to arrive 'on time', so limits (c), (d) see the ladder;")
print("       and 28 GeV (limit (a)) is slowed by several H in (e1), (e2). Cancellation buys at most a factor of order 10 in the bound, never removes it.")

print("\n  The general statement (first order): contribution per unit share = phi(E_lo/E_k) - phi(E_hi/E_k), phi(x) = x^2 (3 - x^2)/(1 - x^2)^2.")
def contrib(Ek_): return phi(E_LO / Ek_) - phi(E_HI / Ek_)
for a in (0.99, 0.9, 0.5, 0.0):
    # -phi(x) = a  ->  (a-1) x^4 + (3-2a) x^2 + a = 0, the root with x^2 > 1
    x2 = ((2 * a - 3) - math.sqrt(9 - 8 * a)) / (2 * (a - 1)) if a != 1 else None
    print(f"    the contribution stays above {a:4.2f} for every level with own energy below 31 GeV/{math.sqrt(x2):.2f} = {E_HI/math.sqrt(x2):.3g} eV")
print(f"    for Doug's levels at or below 511 keV (and above 0.1 MeV) it is >= 1: at 511 keV {contrib(E511):.4f}, at 255 keV {contrib(E511/2):.4f}, at 128 keV {contrib(E511/4):.3f}")
print(f"    below 0.1 MeV (both photons above the level) it lies between 0 and 1: at 50 keV {contrib(5e4):.3f}, at 10 keV {contrib(1e4):.4f}, at 1 keV {contrib(1e3):.2e}")
print(f"    between 31 GeV/sqrt(3) and 31 GeV it is negative, and above 31 GeV it is negative and small: at 100 GeV {contrib(1e11):+.3f}, at 1 TeV {contrib(1e12):+.4f}, at 1 PeV {contrib(1e15):+.2e}")
print("    So a ladder whose levels all lie below about 3 GeV hands over at least 0.99 x (its share)/2 between the two photons, however spread;")
print("    only levels within a factor of about 3 below the top photon, or above it, can reduce the difference, by slowing the top photon itself.")

# ------------- the reference energies and the path integral
print("\n  Does the one-point comparison at the observed energies represent limit (e)?")
z = 0.903; H0 = 67.4e3 / 3.0856775814913673e22; Om = 0.3153; OL = 1 - Om
hz = lambda x: math.sqrt(Om * (1 + x) ** 3 + OL)
T0 = quad(lambda x: 1 / hz(x), 0, z)[0] / H0
T2 = quad(lambda x: (1 + x) ** 2 / hz(x), 0, z)[0] / H0
yr = 365.25 * 86400
print(f"    comoving path T0 = {T0:.4e} s = {T0/yr/1e9:.2f} Gyr; (1+z)^2-weighted T2 = {T2:.4e} s (record: 3.2450e17, 6.6835e17)")
def path_ratio(Ek, hk, Elo=E_LO, Ehi=E_HI, Hs=H):
    """Observed delay of the high photon relative to the low one, divided by (H/2) T0, with both energies redshifting along the path."""
    def integrand(x):
        _, ng = n_and_ng([Elo * (1 + x), Ehi * (1 + x)], Ek, hk)
        return (ng[1] - ng[0]) / hz(x)        # dt_obs = (n_g,hi - n_g,lo) dz/H(z)  (lateness of the high photon)
    val = quad(integrand, 0, z, limit=400)[0] / H0
    return -val / ((Hs / 2) * T0)              # sign: positive when the high photon is early, as the script's ratio
print("    case                                ratio at observed E   at emitted E (x1.903)   path-integrated")
for name, (Ek, hk) in cases.items():
    crossed = [(E, (E > E_LO) and (E < E_LO * (1 + z))) or ((E > E_HI) and (E < E_HI * (1 + z))) for E in Ek]
    anyc = any(cc for _, cc in crossed)
    pr = "sweeps a resonance (diverges, lossless)" if anyc else f"{path_ratio(Ek, hk):8.4f}"
    print(f"    {name:36s} {ratio(Ek, hk):8.4f}             {ratio(Ek, hk, E_LO*(1+z), E_HI*(1+z)):8.4f}              {pr}")
print("    The same ladders restricted to the record's own range 0.19 MeV to 28 GeV (levels no photon sweeps across), same total H:")
for s_, kmin, kmax in ((2, -2, 15), (3, -1, 9)):
    kk, EE = ladder(s_, kmin, kmax, 0.19e6, 28e9); hh = np.full(len(EE), H / len(EE))
    print(f"    factor {s_}, k = {kk.min()}..{kk.max()} ({len(EE)} levels): observed-E ratio {ratio(EE, hh):.4f}, emitted-E ratio {ratio(EE, hh, E_LO*(1+z), E_HI*(1+z)):.4f}, path-integrated {path_ratio(EE, hh):.4f}")
wl = np.exp(-0.5 * (np.log10(EE / E511)) ** 2)
kk2, EE2 = ladder(2, -2, 15, 0.19e6, 28e9); wl2 = np.exp(-0.5 * (np.log10(EE2 / E511)) ** 2); hh2 = H * wl2 / wl2.sum()
print(f"    factor 2 log-normal, restricted ({len(EE2)} levels): observed-E ratio {ratio(EE2, hh2):.4f}, path-integrated {path_ratio(EE2, hh2):.4f}")

print("\n  One level alone, placed anywhere in the record's range 0.19 MeV to 28 GeV: the path-integrated ratio (limit (e)'s real observable / (h/2) T0):")
scan = np.logspace(np.log10(0.2e6), np.log10(28e9), 60)   # from 0.2 MeV: a level at 0.19 MeV is crossed by the low photon at emission (0.1903 MeV)
vals = np.array([path_ratio(np.array([Ek_]), np.array([H])) for Ek_ in scan])
imin, imax = np.nanargmin(vals), np.nanargmax(vals)
print(f"    min {vals[imin]:.3f} at E_k = {scan[imin]:.3g} eV; max {vals[imax]:.3f} at E_k = {scan[imax]:.3g} eV; median {np.nanmedian(vals):.3f}")
print("    (the step model's value is 1 everywhere; the record's '0.78 to 1.41' is the band for a level well inside the range)")
m_mid = (scan > 2e6) & (scan < 3e9)
print(f"    between 2 MeV and 3 GeV: min {vals[m_mid].min():.3f}, max {vals[m_mid].max():.3f}")


# ================================================================== R2
print("\n================ R2. Coupled stacks: my own implementation ================")
rng = np.random.default_rng(20261115)
def modes(Q, M, K):
    """Normal modes of M x'' = -K x + Q E; returns w^2, strengths F_m = (sum_j Q_j a_j^(m)/sqrt(M_j))^2, and the sum rule value."""
    s = 1 / np.sqrt(M)
    w2, A = np.linalg.eigh(s[:, None] * K * s[None, :])
    F = (A.T @ (Q * s)) ** 2
    return w2, F, (Q * Q / M).sum()
def chi_direct(w, Q, M, K):
    """Polarization per unit field, sum_j Q_j x_j, by solving (K - w^2 M) x = Q directly."""
    x = np.linalg.solve(K - w * w * np.diag(M), Q)
    return Q @ x
def spring_matrix(J, pairs, G, anchors=None):
    K = np.zeros((J, J))
    for (i, j), g in zip(pairs, G):
        K[i, i] += g; K[j, j] += g; K[i, j] -= g; K[j, i] -= g
    if anchors is not None:
        K += np.diag(anchors)
    return K

# (1) the lock's patterned stacks, to reproduce the printed mode frequencies and strengths
pat = {"+ - + - + -": [1, -1, 1, -1, 1, -1], "+ + - - + + - -": [1, 1, -1, -1, 1, 1, -1, -1], "+ + + - - -": [1, 1, 1, -1, -1, -1]}
for s_ in (2, 3):
    for name, sg in pat.items():
        J = len(sg); j = np.arange(J); M = float(s_) ** j; Q = np.array(sg, float)
        G = M[:-1] * (float(s_) ** j[:-1]) ** 2
        K = spring_matrix(J, [(i, i + 1) for i in range(J - 1)], G)
        w2, F, sr = modes(Q, M, K)
        bright = [(math.sqrt(max(a, 0)), b) for a, b in zip(w2, F) if b > 1e-12 * F.max()]
        # direct solve against the mode sum at a few frequencies
        worst = 0.0
        for w in (0.37, 1.3, 2.9, 6.1, 13.0, 50.0):
            cm = sum(b / (a - w * w) for a, b in zip(w2, F))
            worst = max(worst, abs(cm - chi_direct(w, Q, M, K)) / abs(cm))
        print(f"  s = {s_}, {name:16s}: " + ", ".join(f"({a:.3g}, {b:.3g})" for a, b in bright) + f"; sum rule {abs(F.sum()-sr)/sr:.1e}; direct solve vs mode sum {worst:.1e}; min F/max F {F.min()/F.max():+.1e}")

# (2) random stacks with arbitrary spring networks (not only nearest neighbours), with and without anchors, neutral or not
def dchi_positive(w2, F, npts=400):
    bright = [(a, b) for a, b in zip(w2, F) if b > 0]
    poles = sorted(a for a, b in bright if a > 1e-12)
    edges = [0.0] + poles + [(poles[-1] if poles else 1.0) * 10]
    ok = True
    for lo, hi in zip(edges[:-1], edges[1:]):
        w2grid = np.linspace(lo + (hi - lo) * 1e-4, hi - (hi - lo) * 1e-4, npts)
        chi = np.array([sum(b / (a - u) for a, b in bright) for u in w2grid])
        ok &= bool(np.all(np.diff(chi) > 0))
    return ok
stats = {"neutral free": [0, 0.0, 0.0, True], "charged free": [0, 0.0, 0.0, True], "neutral anchored": [0, 0.0, 0.0, True], "charged anchored": [0, 0.0, 0.0, True]}
for _ in range(2000):
    J = int(rng.integers(2, 9))
    Q = rng.choice([-1.0, 1.0], J) * 10 ** rng.uniform(-1.5, 1.5, J)
    neutral = rng.random() < 0.5
    if neutral:
        Q[-1] = -Q[:-1].sum()
    M = 10 ** rng.uniform(-1.5, 1.5, J)
    npairs = int(rng.integers(J - 1, J * (J - 1) // 2 + 1))
    allpairs = [(i, j) for i in range(J) for j in range(i + 1, J)]
    chosen = [allpairs[i] for i in rng.choice(len(allpairs), npairs, replace=False)]
    chosen = list({*chosen, *[(i, i + 1) for i in range(J - 1)]})           # keep it connected
    G = 10 ** rng.uniform(-1.5, 1.5, len(chosen))
    anchored = rng.random() < 0.5
    anchors = 10 ** rng.uniform(-1.5, 1.5, J) if anchored else None
    K = spring_matrix(J, chosen, G, anchors)
    w2, F, sr = modes(Q, M, K)
    key = ("neutral" if neutral else "charged") + (" anchored" if anchored else " free")
    st = stats[key]; st[0] += 1
    st[1] = min(st[1], F.min() / F.max()); st[2] = max(st[2], abs(F.sum() - sr) / sr)
    st[3] &= dchi_positive(w2, F)
    if not neutral and not anchored:
        # the free translation mode: w^2 = 0 with strength (sum Q)^2 / sum M
        i0 = np.argmin(np.abs(w2)); F0 = Q.sum() ** 2 / M.sum()
        assert abs(F[i0] - F0) < 1e-8 * max(F0, 1e-30), (F[i0], F0)
for key, (nn, neg, sr, rise) in stats.items():
    print(f"  {nn:4d} random {key:17s} stacks: most negative F/max F {neg:+.1e}; worst sum rule {sr:.1e}; chi rising between resonances in all: {rise}")
print("  Charged free stacks have a zero-frequency mode of strength (sum Q)^2/sum M (asserted): a plasma term -F0/w^2, negative but still rising with w.")
print("  Why F_m >= 0 is a theorem, not a finding: F_m is the square of the real number sum_j Q_j a_j^(m)/sqrt(M_j); any real symmetric K and positive M give it.")

# ================================================================== R3 and R4
print("\n================ R3 and R4. The bounds, counts and levels ================")
lim_e = 2 * 0.010 / T0; lim_f = 2 * 0.019 / T0; lim_a = 0.859 / T2; tail = lim_a / 1.5
crab_dng = 33.7e-6 / (6523 * yr)                    # 1 milliperiod over 6,523 light-years (Rots et al. 2004 as quoted in the record)
crab = 2 * 1.64e-16
print(f"  limit (e): h_total < {lim_e:.3g}; limit (f): < {lim_f:.3g}; limit (a) group deficit at 28 GeV < {lim_a:.4g}; tail sum h (28 GeV/E)^2 < {tail:.3g}")
print(f"  Crab: delta n_g = 33.7 us / 6,523 ly = {crab_dng:.3g} (record 1.64e-16); a level between 2 and 30 keV: h < 2 delta n_g = {crab:.3g}")
print(f"  limit (e)'s lower edge: 0.1 MeV x (1+z) = {0.1*(1+z):.4f} MeV (the low photon's energy at emission); (f)'s upper edge 0.694 GeV (observed, 1-sigma low)")
# sensitivity to Abdo's own cosmology and z = 0.900
Om2, OL2, h2, z2 = 0.27, 0.73, 0.71, 0.900
H02 = h2 * 1e5 / 3.0856775814913673e22
hz2 = lambda x: math.sqrt(Om2 * (1 + x) ** 3 + OL2)
T0b = quad(lambda x: 1 / hz2(x), 0, z2)[0] / H02; T2b = quad(lambda x: (1 + x) ** 2 / hz2(x), 0, z2)[0] / H02
print(f"  with Abdo et al.'s cosmology (0.27, 0.73, h = 0.71) and z = 0.900: T0 = {T0b:.4e} s, T2 = {T2b:.4e} s; limit (e) -> {2*0.010/T0b:.3g}, tail -> {0.859/T2b/1.5:.3g} (changes of a few %)")
# their 1.19 M_Planck check for limit (a), linear law, (1+z) weighting
T1b = quad(lambda x: (1 + x) / hz2(x), 0, z2)[0] / H02
MPl = 1.220890e19  # GeV
xi = (28.0 - 1e-4) * T1b / (0.859 * MPl)
print(f"  check of Abdo's limit (a): linear law, (1+z) weighting, their cosmology: M_QG,1/M_Planck > {xi:.3f} (they print 1.19)")

print("\n  Per-level table, step model [M], s = 2 and 3, k = -10..60:")
for s_ in (2, 3):
    ks = np.arange(-10, 61); Ek = E511 * float(s_) ** ks; dk = d_asp / float(s_) ** ks
    in_crab = (Ek > 2e3) & (Ek < 30e3); in_e = (Ek > 0.19e6) & (Ek < 28e9); in_f = (Ek > 0.19e6) & (Ek < 0.694e9)
    gap1 = (Ek >= 30e3) & (Ek <= 0.19e6); gap2 = (Ek >= 28e9) & (Ek <= 28e9 * (1 + z)); below = Ek < 2e3
    print(f"  s = {s_}:")
    print(f"    Crab 2-30 keV: k = {list(ks[in_crab])}, E = {[f'{e/1e3:.3g} keV' for e in Ek[in_crab]]}; equal shares each < {crab/in_crab.sum():.2g}")
    print(f"    limit (e) 0.19 MeV-28 GeV: k = {ks[in_e].min()}..{ks[in_e].max()} ({in_e.sum()} levels), {Ek[in_e].min()/1e3:.0f} keV to {Ek[in_e].max()/1e9:.1f} GeV; equal shares each < {lim_e/in_e.sum():.2g}")
    print(f"    limit (f) 0.19 MeV-0.694 GeV: k = {ks[in_f].min()}..{ks[in_f].max()} ({in_f.sum()} levels)")
    print(f"    NOT in any compiled bound, 30 keV to 0.19 MeV: k = {list(ks[gap1])}, E = {[f'{e/1e3:.3g} keV' for e in Ek[gap1]]}")
    print(f"    between 28 GeV and 28 GeV x (1+z) = {28*(1+z):.1f} GeV (limit (e) over part of the path only): k = {list(ks[gap2])}")
    print(f"    below 2 keV: k = {ks[below].min()}..{ks[below].max()}")
    for frac in (0.01, 0.1, 0.5):
        Emin = 28e9 * math.sqrt(frac / tail); kmin = int(ks[Ek >= Emin].min())
        print(f"    {frac:4.0%} of light by limit (a): E_k > {Emin:.3g} eV -> level {kmin} ({Ek[ks == kmin][0]:.3g} eV, spacing {dk[ks == kmin][0]:.3g} m)")
    dmax = math.sqrt(8 * lim_a) / (28e9 / hbarc); Eres = 28e9 * math.sqrt(1.5 / lim_a)
    kd = int(ks[dk < dmax].min()); kE = int(ks[Ek > Eres].min())
    print(f"    R4: spacing < {dmax:.3g} m from level {kd}; own energy > {Eres:.3g} eV from level {kE}; both from {max(kd, kE)}")

print("\n  Partial-path bound from limit (e) for a level between 0.1 and 0.19 MeV (the low photon crosses it on the way):")
for Ek_ in (E511 / 4, E511 / 3):
    zc = Ek_ / 0.1e6 - 1                       # redshift at which the low photon's energy equals E_k
    frac = (quad(lambda x: 1 / hz(x), 0, zc)[0]) / (quad(lambda x: 1 / hz(x), 0, z)[0])
    print(f"    E_k = {Ek_/1e3:.1f} keV: the step applies over the last {frac:.2f} of the comoving path -> h < {lim_e/frac:.2g} (not 'uncovered', but {1/frac:.1f} x weaker)")

print("\n  How the tail bound depends on which of Abdo's limits is used (each applied to a level above the photons, quadratic law, (1+z)^2 path):")
for lab, dt, Eph in (("(a) 859 ms, start of any <1 MeV emission", 0.859, 28e9), ("(d) 99 ms, start of >1 GeV emission", 0.099, 28e9), ("(e) 10 ms, the <1 MeV spike", 0.010, 28e9)):
    tl = dt / T2 / 1.5
    e1, e10, e50 = (28e9 * math.sqrt(fr / tl) for fr in (0.01, 0.1, 0.5))
    lv = lambda E, s: math.ceil(math.log(E / E511) / math.log(s) - 1e-12)
    print(f"    {lab:44s}: sum h (28 GeV/E)^2 < {tl:.2g}; 1%/10%/50% above {e1:.2g}/{e10:.2g}/{e50:.2g} eV; levels s=2: {lv(e1,2)}/{lv(e10,2)}/{lv(e50,2)}, s=3: {lv(e1,3)}/{lv(e10,3)}/{lv(e50,3)}")
print("    (Abdo et al. take 28 GeV for all of (a)-(e). The record uses (e) for the in-range bound and (a) for the tail.)")

print("\n  Step model against the true oscillator, for the levels the bounds cover (factor by which the step over- or under-states |delta n_g| between the two photons):")
for lab, lo, hi, s_, kk in (("Crab s=2", 2e3, 30e3, 2, (-7, -6, -5)), ("Crab s=3", 2e3, 30e3, 3, (-5, -4, -3)), ("(e) s=2 ends", 0.19e6, 28e9, 2, (-1, 0, 14, 15)), ("(e) s=3 ends", 0.19e6, 28e9, 3, (0, 1, 8, 9))):
    out = []
    for k in kk:
        Ek_ = E511 * float(s_) ** k
        osc = 0.5 * (phi(lo / Ek_) - phi(hi / Ek_))          # true first-order group-index change per unit share (low minus high)
        out.append(f"k={k} ({Ek_:.3g} eV): oscillator/step = {osc/0.5:+.2f}")
    print(f"    {lab:13s}: " + "; ".join(out))
print("    (A ratio below +1 means the step model over-bounds that level; negative means the high photon is slower than the low one.)")

# the low-frequency group deficit of a level above the photon
print("\n  Check of 1 - v_g/c = (3/2) h (E/E_k)^2 for a level far above the photon:")
for x in (1e-3, 1e-2, 0.1, 0.3, 0.5, 0.7):
    print(f"    x = E/E_k = {x:5.3f}: exact phi/2 = {phi(x)/2:.5g}, (3/2) x^2 = {1.5*x*x:.5g}, ratio {phi(x)/(3*x*x):.4f}")

print(f"\nrun time {time.time()-T_START:.1f} s; end", clock())