Does light charge the quons? › Files cited on the page › the trials

ladder_handover.py

In the investigation at sim/charge_wave/ladder_handover.py · last changed in commit b8bfb9e, 15 November 2026 · 9,928 bytes · runnable copies in the scripts zip


"""ladder_handover.py - trial 8 of the charging-quons work: Doug's ladder of levels (15 November 2026): can more levels, of
alternating sign, every factor 2 or 3 in energy, make the handover of light across 511 keV smooth enough for the measurements?

Lock: papers/Lock_ladder_handover_2026-11-15.md, committed with this script before the run.
Light's response: eps(w)/eps0 = f + sum over the light-driven modes of F_m w_m^2 ... written per level as h_k w_k^2/(w_k^2 - w^2),
f chosen so that eps(0) = 1. Group speed v_g/c = 1/(n + w dn/dw), n = sqrt(eps).
Run: ~/aspden-review-venv/bin/python3 ladder_handover.py > ladder_handover_out.txt 2> ladder_handover_err.txt
"""
import math, time
import numpy as np
from scipy.integrate import quad

T0 = time.time()
E511 = 510998.95                       # eV
E_LO, E_HI = 0.1e6, 31e9               # GRB 090510 limit (e): 0.1 MeV against 31 GeV
H = 1e-3                               # the total share handed over in R1 (for clear numbers)
ok_all = True

def eps_and_slope(E, Ek, hk):
    """eps/eps0 and w deps/dw at photon energies E (lossless oscillators at Ek with shares hk; eps(0) = 1)."""
    E = np.atleast_1d(np.asarray(E, float))[:, None]
    Ek = np.asarray(Ek, float)[None, :]; hk = np.asarray(hk, float)[None, :]
    f = 1 - hk.sum()
    den = Ek ** 2 - E ** 2
    eps = f + (hk * Ek ** 2 / den).sum(1)
    w_deps = (hk * Ek ** 2 * 2 * E ** 2 / den ** 2).sum(1)
    return eps, w_deps

def vgroup(E, Ek, hk):
    eps, w_deps = eps_and_slope(E, Ek, hk)
    n = np.sqrt(eps)
    return 1 / (n + w_deps / (2 * n))

def vphase(E, Ek, hk):
    eps, _ = eps_and_slope(E, Ek, hk)
    return 1 / np.sqrt(eps)

print("Trial 8: Doug's ladder of levels, a smooth handover across 511 keV (lock papers/Lock_ladder_handover_2026-11-15.md)")

# ---------------- R1
print(f"\nR1. One level against ladders, the same total share H = {H:g} in levels between 0.1 MeV and 31 GeV")
cases = {}
cases["(a) one level at 511 keV"] = (np.array([E511]), np.array([H]))
k2 = np.arange(-2, 16); E2 = E511 * 2.0 ** k2; in2 = (E2 > E_LO) & (E2 < E_HI)
cases["(b) every factor 2, equal shares, k = -2..15"] = (E2[in2], np.full(in2.sum(), H / in2.sum()))
k3 = np.arange(-1, 10); E3 = E511 * 3.0 ** k3; in3 = (E3 > E_LO) & (E3 < E_HI)
cases["(c) every factor 3, equal shares, k = -1..9"] = (E3[in3], np.full(in3.sum(), H / in3.sum()))
wln = np.exp(-0.5 * (np.log10(E2[in2] / E511) / 1.0) ** 2)
cases["(d) every factor 2, log-normal shares (511 keV, width x10)"] = (E2[in2], H * wln / wln.sum())
ratios = {}
print("     case                                                   levels   v_g(31 GeV) - v_g(0.1 MeV), /c     ratio to H/2   phase-speed difference / (H/2)")
for name, (Ek, hk) in cases.items():
    dg = vgroup(E_HI, Ek, hk)[0] - vgroup(E_LO, Ek, hk)[0]
    dp = vphase(E_HI, Ek, hk)[0] - vphase(E_LO, Ek, hk)[0]
    ratios[name] = dg / (H / 2)
    print(f"     {name:56s} {len(Ek):4d}     {dg:+.4e}                     {dg / (H / 2):6.3f}         {dp / (H / 2):6.3f}")
# check (ii): one level, phase speed against the closed form
E = np.array([1e5, 3e5, 7e5, 3e7, 3e10])
w1 = E511
closed = 1 / np.sqrt((1 - H) + H * w1 ** 2 / (w1 ** 2 - E ** 2))
num = vphase(E, np.array([E511]), np.array([H]))
c2 = np.max(np.abs(num - closed))
ok2 = c2 < 1e-12
ok_all &= ok2
print(f"  (ii) one level, phase speed against the closed form: {c2:.1e} ({'pass' if ok2 else 'MISS'})")
print("  the group speed along the ladder (b), relative to c, at photon energies (eV):")
grid = [1e3, 1e4, 1e5, 3e5, 1e6, 1e7, 1e8, 1e9, 1e10, 3.1e10]
Ek, hk = cases["(b) every factor 2, equal shares, k = -2..15"]
print("     " + "  ".join(f"{e:.0e}: {vgroup(e, Ek, hk)[0] - 1:+.2e}" for e in grid))
Ek, hk = cases["(a) one level at 511 keV"]
print("  the same for one level at 511 keV:")
print("     " + "  ".join(f"{e:.0e}: {vgroup(e, Ek, hk)[0] - 1:+.2e}" for e in grid))

# ---------------- R2
print("\nR2. Coupled stacks: J levels held to their neighbours by springs, driven by a uniform field")
def stack(Q, M, G):
    Q, M, G = map(np.asarray, (Q, M, G))
    J = len(Q); Kmat = np.zeros((J, J))
    for j in range(J - 1):
        Kmat[j, j] += G[j]; Kmat[j + 1, j + 1] += G[j]; Kmat[j, j + 1] -= G[j]; Kmat[j + 1, j] -= G[j]
    s = 1 / np.sqrt(M)
    w2, A = np.linalg.eigh(s[:, None] * Kmat * s[None, :])
    F = (A.T @ (Q * s)) ** 2
    return w2, F, (Q ** 2 / M).sum()

def rises(w2, F):
    """chi(w) = sum F_m/(w2_m - w^2) rising between every pair of resonances (and below the first, above the last)."""
    bright = [(a, b) for a, b in zip(w2, F) if a > 1e-12 * max(w2.max(), 1) and b > 0]
    if not bright:
        return True
    poles = sorted(a for a, _ in bright)
    edges = [0.0] + poles + [poles[-1] * 4]
    okr = True
    for lo, hi in zip(edges[:-1], edges[1:]):
        x = np.linspace(lo + (hi - lo) * 1e-3, hi - (hi - lo) * 1e-3, 200)
        chi = np.array([sum(b / (a - xx) for a, b in bright) for xx in x])
        okr &= bool(np.all(np.diff(chi) > 0))
    return okr

pat = {"+ - + - + -": [1, -1, 1, -1, 1, -1], "+ + - - + + - -": [1, 1, -1, -1, 1, 1, -1, -1], "+ + + - - -": [1, 1, 1, -1, -1, -1]}
worst_neg, worst_sum, all_rise = 0.0, 0.0, True
for s_ in (2, 3):
    for pname, 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            # each pair's frequency grows as s^j
        w2, F, sr = stack(Q, M, G)
        neg = min(0.0, F.min()) / F.max(); worst_neg = min(worst_neg, neg)
        worst_sum = max(worst_sum, abs(F.sum() - sr) / sr)
        r = rises(w2, F); all_rise &= r
        bright = [(math.sqrt(a), b) for a, b in zip(w2, F) if b > 1e-12 * F.max()]
        print(f"  s = {s_}, signs {pname:16s}: modes (frequency, strength) " + ", ".join(f"({a:.3g}, {b:.3g})" for a, b in bright)
              + f"; sum rule {abs(F.sum() - sr) / sr:.1e}; rises between resonances: {r}")
rng = np.random.default_rng(8)
for _ in range(1000):
    J = int(rng.integers(2, 9))
    Q = rng.choice([-1, 1], J) * 10 ** rng.uniform(-1.5, 1.5, J)
    Q[-1] = -Q[:-1].sum()                                   # neutral
    M = 10 ** rng.uniform(-1.5, 1.5, J); G = 10 ** rng.uniform(-1.5, 1.5, J - 1)
    w2, F, sr = stack(Q, M, G)
    worst_neg = min(worst_neg, min(0.0, F.min()) / F.max())
    worst_sum = max(worst_sum, abs(F.sum() - sr) / sr)
    all_rise &= rises(w2, F)
ok1 = worst_neg > -1e-12 and worst_sum < 1e-10
ok_all &= ok1
print(f"  1,000 random neutral stacks (J = 2 to 8): most negative strength / largest {worst_neg:.1e}; worst sum rule {worst_sum:.1e}; "
      f"chi rises between resonances in every stack: {all_rise}")
print(f"  (i) strengths never negative and the sum rule holds: {'pass' if ok1 else 'MISS'}")

# ---------------- R3 and R4
hbar = 1.054571817e-34; me = 9.1093837015e-31; c = 299792458.0; eV = 1.602176634e-19
hbarc = hbar * c / eV
r = hbar / (2 * me * c); d = r / (0.75 * (8 / 1843) ** (1 / 6))
z = 0.903; H0 = 67.4e3 / 3.0856775814913673e22; Om = 0.3153; OL = 1 - Om
hz = lambda x: np.sqrt(Om * (1 + x) ** 3 + OL)
T0p = quad(lambda x: 1 / hz(x), 0, z)[0] / H0
T2p = quad(lambda x: (1 + x) ** 2 / hz(x), 0, z)[0] / H0
lim_e = 2 * 0.010 / T0p                                     # 10 ms, constant speed difference, comoving path
lim_f = 2 * 0.019 / T0p
lim_a = 0.859 / T2p                                         # quadratic law, (1+z)^2
tail = lim_a / 1.5
crab = 2 * 1.64e-16
Eres = 28e9 * math.sqrt(1.5 / lim_a); dmax = math.sqrt(8 * lim_a) / (28e9 / hbarc)
print(f"\nR3. What the measurements allow, per level (U44: own energy 511 keV x s^k, spacing d/s^k, d = {d:.4e} m)")
print(f"  bounds: limit (e) total share < {lim_e:.3g} (0.19 MeV to 28 GeV); limit (f) < {lim_f:.3g} (0.19 MeV to 0.694 GeV);"
      f" Crab < {crab:.3g} (2 to 30 keV); above 28 GeV, sum h (28 GeV/E)^2 < {tail:.3g} (limit (a))")
for s_ in (2, 3):
    ks = np.arange(-10, 61); Ek = E511 * float(s_) ** ks
    ine = (Ek > 0.19e6) & (Ek < 28e9); inf_ = (Ek > 0.19e6) & (Ek < 0.694e9); inc = (Ek > 2e3) & (Ek < 30e3); below = Ek < 2e3
    print(f"\n  s = {s_}:")
    print(f"     levels with own energy 2-30 keV (Crab): k = {list(ks[inc])}; each at most {crab / max(inc.sum(), 1):.2g} if equal")
    print(f"     levels 0.19 MeV - 28 GeV (limit (e)): k = {ks[ine].min()} to {ks[ine].max()} ({ine.sum()} levels); each at most {lim_e / ine.sum():.2g} if equal")
    print(f"     levels 0.19 MeV - 0.694 GeV (limit (f)): k = {ks[inf_].min()} to {ks[inf_].max()} ({inf_.sum()} levels)")
    print(f"     levels below 2 keV (k = {ks[below].min()} to {ks[below].max()}): no bound compiled in the record")
    for frac in (0.01, 0.1, 0.5):
        Emin = 28e9 * math.sqrt(frac / tail)
        kmin = int(ks[Ek >= Emin].min())
        print(f"     a single level carrying {frac:.0%} of light must have its own energy above {Emin:.2e} eV: level {kmin} or finer"
              f" ({E511 * s_ ** kmin:.2e} eV, spacing {d / s_ ** kmin:.2e} m)")
    kd = next(k for k in range(400) if d / s_ ** k < dmax); kE = next(k for k in range(400) if s_ ** k * E511 > Eres)
    print(f"  R4. fine and prompt enough: spacing below {dmax:.3g} m from level {kd}; own energy above {Eres:.3g} eV from level {kE}; both from level {max(kd, kE)}")
    if s_ == 2:
        k_s2 = max(kd, kE)
    else:
        k_s3 = max(kd, kE)
ok3 = (k_s2, k_s3) == (46, 29)
ok_all &= ok3
print(f"  (iii) R4 reproduces 46 and 29: {'pass' if ok3 else 'MISS'}")

# ---------------- summary
smooth = any(v < 0.1 for v in ratios.values())
inband = all(0.5 <= v <= 2 for v in ratios.values())
print("\nSummary:")
print(f"  R1 ratios to H/2: " + ", ".join(f"{k[:3]} {v:.3f}" for k, v in ratios.items()) + f"; all between 0.5 and 2: {inband}")
print(f"  a smooth handover the measurements cannot see (some ratio below 0.1): {smooth}")
print(f"  code checks: {'all pass' if ok_all else 'SOME MISS'}")
print(f"run time {time.time() - T0:.1f} s")