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

blind_t22.py

In the investigation at sim/matter_light/check_trial22_fable/blind_t22.py · last changed in commit 6a4b731, 23 November 2026 · 34,005 bytes · the folder as a zip


#!/usr/bin/env python3
"""Thirtieth reviewer, blind computation for trial 22 (23 Nov 2026).
Written from the brief's model M2 (and M3 for the vacuum-Cherenkov part) without
reading the trial's lock, script or results. Own code; nothing imported from the project.

Rule kept: n - 1 and 1 - 1/n^2 are computed directly, never by subtracting from 1.
Labels: [S] standard physics, [I] input measurement, [D] derived here, [M] my choice,
[mem] value from memory (not read from a source in this session).
"""
import math, sys
import numpy as np
from scipy.integrate import quad

# ---------- constants (PDG 2024 constants sheet in sources; exact SI where exact) [S]
c = 299792458.0
h = 6.62607015e-34
hbar = h / (2 * math.pi)
e = 1.602176634e-19
kB = 1.380649e-23
NA = 6.02214076e23
eps0 = 8.8541878128e-12
alpha = 1 / 137.035999177
me_eV = 0.51099895000e6          # eV
mp_eV = 938.27208816e6
mmu_eV = 105.6583755e6           # [S, mem]
mpi_eV = 139.57039e6             # [S, mem]
me_kg = 9.1093837015e-31
re = 2.8179403262e-15
sigma_T = 0.66524587321e-28
a0 = 0.529177210903e-10
hbarc_eVm = 197.3269804e-9       # eV m  (197.327 MeV fm)
Mair = 28.9644e-3                # kg/mol, US Std Atm 1976 [S, mem]
g0 = 9.80665
Rstar = 8.31432                  # J/(mol K), the 1976 standard's own value [S, mem]

def pr(*a):
    print(*a); sys.stdout.flush()

pr("=" * 78)
pr("PART A. n - 1 of air at 589 nm from 1 atm to 1e-10 Pa; thin media; Rayleigh mean free path")
pr("=" * 78)

# Ciddor 1996 (refractiveindex.info 'formula 6', standard air: dry, 15 C, 101325 Pa, 450 ppm CO2) [S, source yml]
def nm1_ciddor(lam_um):
    s2 = 1 / lam_um**2
    return 0.05792105 / (238.0185 - s2) + 0.00167917 / (57.362 - s2)

# Peck & Reeder 1972, same conditions (288 K nominal) [S, source yml]
def nm1_peck_reeder(lam_um):
    s2 = 1 / lam_um**2
    return 8.06051e-5 + 2.480990e-2 / (132.274 - s2) + 1.74557e-4 / (39.32957 - s2)

lam = 0.589
nm1_std = nm1_ciddor(lam)
pr(f"Ciddor      n-1 at 589 nm, 15 C, 101325 Pa, dry: {nm1_std:.6e}")
pr(f"Peck-Reeder n-1 at 589 nm, same:                 {nm1_peck_reeder(lam):.6e}")
pr(f"Birch-Downs table (source): 0.58 um 2.77295756e-4, 0.59 um (interpolate) -> consistent to ~1e-9")
T_std = 288.15; P_std = 101325.0
N_std = P_std / (kB * T_std)
pr(f"N at standard conditions: {N_std:.4e} m^-3")

# Lorentz-Lorenz: LL = (n^2-1)/(n^2+2) is proportional to N.  n^2 - 1 = 3 LL/(1 - LL) (direct).
n_std = 1 + nm1_std
LL_std = (n_std**2 - 1) / (n_std**2 + 2)     # fine at this size (n^2-1 ~ 5.5e-4, 12 digits kept)
# For tiny LL use n^2-1 = 3LL/(1-LL) and n-1 = (n^2-1)/(1+sqrt(1+(n^2-1)))  -- no subtraction from 1
def nm1_from_LL(LL):
    n2m1 = 3 * LL / (1 - LL)
    return n2m1 / (1 + math.sqrt(1 + n2m1))

pr("\nA1. Air at 589 nm, 15 C, dry, versus pressure (n - 1 by Lorentz-Lorenz scaled with number density):")
pr(f"{'P (Pa)':>12} {'N (m^-3)':>12} {'n - 1':>12} {'1 - 1/n^2':>12} {'Rayleigh mfp':>14}")
# Rayleigh cross-section per molecule from n-1 (thin): alpha' = (n-1)/(2 pi N);  sigma = (8 pi/3) k^4 alpha'^2 * F_King
k589 = 2 * math.pi / (lam * 1e-6)
F_king = 1.048   # King correction factor for air near 589 nm [S, mem; Bodhaine et al. 1999 give ~1.048]
alpha_p_air = nm1_std / (2 * math.pi * N_std)     # m^3 (polarizability volume per molecule)
sigma_R_air = (8 * math.pi / 3) * k589**4 * alpha_p_air**2 * F_king
pr(f"polarizability volume per air molecule alpha' = {alpha_p_air:.4e} m^3 ({alpha_p_air/a0**3:.3f} a0^3); "
   f"sigma_Rayleigh(589 nm) = {sigma_R_air:.3e} m^2 = {sigma_R_air*1e4:.3e} cm^2")
rows = []
for P in [101325.0, 1e4, 1e3, 1e2, 1.0, 1e-2, 1e-4, 1e-6, 1e-8, 1e-10]:
    N = P / (kB * T_std)
    LL = LL_std * N / N_std
    nm1 = nm1_from_LL(LL)
    n = 1 + nm1
    one_m_inv_n2 = (n * n - 1) / (n * n)   # direct: (n^2-1)/n^2 with n^2-1 = 3LL/(1-LL)
    n2m1 = 3 * LL / (1 - LL)
    one_m_inv_n2 = n2m1 / (1 + n2m1)
    mfp = 1 / (N * sigma_R_air)
    rows.append((P, N, nm1, one_m_inv_n2, mfp))
    pr(f"{P:12.3e} {N:12.3e} {nm1:12.4e} {one_m_inv_n2:12.4e} {mfp:14.3e} m")
pr("Check of the thin-limit linearity: n-1 at 1e-10 Pa / n-1 at 1 atm =",
   f"{rows[-1][2]/rows[0][2]:.4e}; N ratio = {rows[-1][1]/rows[0][1]:.4e}")

pr("\nA2. Thin astrophysical media at 589 nm.")
alpha_H = 4.5 * a0**3            # ground-state hydrogen polarizability volume, exactly 9/2 a0^3 [S]
alpha_He = 1.3832 * a0**3        # [S, mem]
pr(f"alpha'(H) = {alpha_H:.4e} m^3; alpha'(He) = {alpha_He:.4e} m^3")
omega = 2 * math.pi * c / (lam * 1e-6)
pr(f"omega(589 nm) = {omega:.4e} rad/s")
def nm1_neutral(N_H, N_He=0.0):
    # thin: n - 1 = N alpha/(2 eps0) = 2 pi N alpha'   (alpha = 4 pi eps0 alpha')
    return 2 * math.pi * (N_H * alpha_H + N_He * alpha_He)
def plasma(N_e):
    wp2 = N_e * e**2 / (eps0 * me_kg)
    x = wp2 / omega**2                      # = 1 - n^2  (phase)
    n = math.sqrt(1 - x)
    nm1_phase = -x / (1 + n)                # n - 1 = (n^2-1)/(n+1), direct
    ng = 1 / n                              # cold plasma: n * n_g = 1
    ngm1 = x / (n * (1 + n))                # n_g - 1 = (1-n)/n = x/(n(1+n)), direct
    return wp2, nm1_phase, ngm1
def rayleigh_sigma(alpha_p):
    return (8 * math.pi / 3) * k589**4 * alpha_p**2
sigma_H = rayleigh_sigma(alpha_H)
pr(f"Rayleigh sigma for one H atom at 589 nm: {sigma_H:.3e} m^2; Thomson sigma: {sigma_T:.3e} m^2")
pc = 3.0856775814913673e16
media = [
    # name, N_H neutral (m^-3), N_He (m^-3), N_e (m^-3); densities [S, mem], see notes
    ("Interplanetary, 1 AU: neutral H ~0.1 cm^-3; solar wind e ~5 cm^-3", 1e5, 0.0, 5e6),
    ("Interstellar, warm neutral: H 0.3 cm^-3; warm ionized e 0.03 cm^-3", 3e5, 0.3e5, 3e4),
    ("Interstellar, cold neutral cloud: H 30 cm^-3", 3e7, 3e6, 0.0),
    ("Intergalactic, mean: H 1.9e-7 cm^-3 if neutral; e 2.2e-7 cm^-3 (ionized)", 0.19, 0.015, 0.22),
]
pr(f"\n{'medium':<70} {'n-1 neutral':>12} {'n-1 e (phase)':>14} {'n_g-1 e':>12} {'mfp Rayleigh':>14} {'mfp Thomson':>14}")
for name, NH, NHe, Ne in media:
    nm1n = nm1_neutral(NH, NHe)
    wp2, nm1p, ngm1 = plasma(Ne) if Ne > 0 else (0, 0.0, 0.0)
    mfpR = 1 / ((NH * sigma_H + NHe * rayleigh_sigma(alpha_He))) if (NH + NHe) > 0 else float('inf')
    mfpT = 1 / (Ne * sigma_T) if Ne > 0 else float('inf')
    pr(f"{name:<70} {nm1n:12.3e} {nm1p:14.3e} {ngm1:12.3e} {mfpR/pc:11.3e} pc {mfpT/pc:11.3e} pc")
pr("Notes: free electrons give a phase index below 1 (phase speed above c) and a group index above 1;")
pr("       both differ from 1 by (omega_p/omega)^2/2 to first order. Per electron per cm^-3 at 589 nm:",
   f"{plasma(1e6)[1]:.3e} (phase), {plasma(1e6)[2]:.3e} (group).")
pr(f"Per H atom per cm^-3 at 589 nm: n-1 = {nm1_neutral(1e6):.3e}")

# Fresnel-volume validity criterion from the brief: N_F = N pi lam L^2 / 6 >> 1
pr("\nA3. Brief's validity rule N_F = N*pi*lambda*L^2/6: path L for N_F = 1 at 589 nm")
for name, N in [("air 1 atm", N_std), ("air 1e-10 Pa", 1e-10/(kB*T_std)), ("ISM 1 H/cm^3", 1e6), ("IGM 2e-7/cm^3", 0.2)]:
    L = math.sqrt(6 / (N * math.pi * lam * 1e-6))
    pr(f"  {name:<16} N = {N:9.3e} m^-3  L(N_F=1) = {L:9.3e} m")

pr("\n" + "=" * 78)
pr("PART B. Cherenkov light (Frank-Tamm) for water, N-BK7 glass, air at sea level and at 30 km")
pr("=" * 78)
# Frank-Tamm [S, PDG 34.43/34.44 in sources]: d2N/dEdx = (alpha/hbar c) sin^2 theta_c;  d2N/dx dlambda = 2 pi alpha / lambda^2 (1 - 1/(beta^2 n^2))
pr(f"alpha/(hbar c) = {alpha/hbarc_eVm:.4e} per eV per m = {alpha/hbarc_eVm*1e-2:.2f} per eV per cm (PDG: ~370)")
# N-BK7 Sellmeier (Schott) [S, mem]
BK7 = dict(B1=1.03961212, B2=0.231792344, B3=1.01046945, C1=0.00600069867, C2=0.0200179144, C3=103.560653)
def n2m1_bk7(lam_um):
    L2 = lam_um**2
    return (BK7['B1']*L2/(L2-BK7['C1']) + BK7['B2']*L2/(L2-BK7['C2']) + BK7['B3']*L2/(L2-BK7['C3']))
def n_bk7(lam_um): return math.sqrt(1 + n2m1_bk7(lam_um))
pr(f"N-BK7 n at 587.6 nm (Sellmeier): {n_bk7(0.5876):.5f}  (catalogue n_d = 1.5168 [S, mem]);  at 589 nm: {n_bk7(0.589):.5f}")
# water [S, mem]: n(589 nm, 20 C) = 1.3330; small dispersion; a Cauchy form n = A + B/lam^2 fitted to 1.3390 (400 nm) and 1.3330 (589 nm)
B_w = (1.3390 - 1.3330) / (1/0.400**2 - 1/0.589**2)
A_w = 1.3330 - B_w / 0.589**2
def n_water(lam_um): return A_w + B_w / lam_um**2
pr(f"water Cauchy fit: n = {A_w:.5f} + {B_w:.6f}/lam^2 (um); n(300 nm) = {n_water(0.300):.4f} [mem: ~1.349], n(600) = {n_water(0.600):.4f}")

def one_minus_inv_n2(n2m1):   # 1 - 1/n^2 = (n^2 - 1)/n^2, direct
    return n2m1 / (1 + n2m1)

def cherenkov_summary(name, n2m1_fun, lam_lo=0.300, lam_hi=0.600, beta=1.0):
    n2m1_589 = n2m1_fun(0.589)
    n = math.sqrt(1 + n2m1_589)
    s2 = one_minus_inv_n2(n2m1_589)           # sin^2 theta at beta=1
    theta = math.degrees(math.asin(math.sqrt(s2)))
    gamma_t = math.sqrt(1 + 1 / n2m1_589)      # gamma_t = n/sqrt(n^2-1) = sqrt(1 + 1/(n^2-1))
    beta_t = 1 / n
    # beta_t gamma_t = 1/sqrt(n^2-1)
    bg_t = 1 / math.sqrt(n2m1_589)
    # yield per metre, beta = 1, with dispersion: integral over lambda of 2 pi alpha/lam^2 * (1 - 1/(beta^2 n^2))
    def integrand(lam_um):
        n2m1 = n2m1_fun(lam_um)
        n2 = 1 + n2m1
        val = 1 - 1 / (beta**2 * n2) if beta < 1 else n2m1 / n2
        if beta < 1:
            val = (beta**2 * n2 - 1) / (beta**2 * n2)
        return 2 * math.pi * alpha / (lam_um * 1e-6)**2 * max(val, 0.0)
    Y, _ = quad(integrand, lam_lo, lam_hi, limit=200)   # per metre of path (dlambda in um -> factor 1e-6)
    Y *= 1e-6
    # no-dispersion yield with n at 589
    Y0 = 2 * math.pi * alpha * s2 * (1 / (lam_lo * 1e-6) - 1 / (lam_hi * 1e-6))
    pr(f"\n{name}: n(589) = {n:.9f}, n-1 = {n2m1_589/(1+n):.4e}, 1-1/n^2 = {s2:.4e}")
    pr(f"  angle at beta=1: {theta:.4f} deg = {theta*60:.2f} arcmin; threshold beta = 1/n = {beta_t:.7f}, gamma_t = {gamma_t:.5f}, (beta gamma)_t = {bg_t:.5f}")
    for pname, m in [("electron", me_eV), ("muon", mmu_eV), ("pion", mpi_eV), ("proton", mp_eV)]:
        pr(f"    threshold {pname:<8}: kinetic energy {(gamma_t-1)*m:.4e} eV, momentum {bg_t*m:.4e} eV/c")
    pr(f"  yield 300-600 nm at beta=1: {Y:.4e} photons/m = {Y*1e-2:.4e} /cm (with dispersion); {Y0:.4e} /m with n fixed at 589 nm")
    return n2m1_589, Y

cherenkov_summary("Water (20 C)", lambda l: n_water(l)**2 - 1)
cherenkov_summary("N-BK7 glass", n2m1_bk7)
# air: n - 1 scales with density; use Ciddor's dispersion
def n2m1_air_factor(lam_um, dens_ratio):
    LL = (lambda nm1: ((1+nm1)**2 - 1)/((1+nm1)**2 + 2))(nm1_ciddor(lam_um)) * dens_ratio
    return 3 * LL / (1 - LL)
cherenkov_summary("Air, sea level, 15 C, 101325 Pa (dry)", lambda l: n2m1_air_factor(l, 1.0))

# ---- US Standard Atmosphere 1976, built from its defining constants [S, mem]
layers_H = [0, 11000, 20000, 32000, 47000, 51000, 71000, 84852]      # geopotential metres
lapse = [-6.5e-3, 0.0, 1.0e-3, 2.8e-3, 0.0, -2.8e-3, -2.0e-3]        # K/m
T0, P0 = 288.15, 101325.0
Tb = [T0]; Pb = [P0]
for i in range(1, len(layers_H)):
    L = lapse[i-1]; dH = layers_H[i] - layers_H[i-1]
    if L == 0:
        T = Tb[-1]; P = Pb[-1] * math.exp(-g0 * Mair * dH / (Rstar * Tb[-1]))
    else:
        T = Tb[-1] + L * dH; P = Pb[-1] * (T / Tb[-1]) ** (-g0 * Mair / (Rstar * L))
    Tb.append(T); Pb.append(P)
r0_geo = 6356766.0   # m, the 1976 standard's Earth radius for geopotential conversion [S, mem]
def std_atm(Z):
    """geometric altitude Z (m) -> (T, P, rho, drho/dZ). Above 84.852 km geopotential: isothermal continuation (tiny)."""
    H = r0_geo * Z / (r0_geo + Z)
    dHdZ = (r0_geo / (r0_geo + Z)) ** 2
    i = 0
    while i < len(layers_H) - 2 and H >= layers_H[i+1]:
        i += 1
    L = lapse[i]
    if L == 0:
        T = Tb[i]; P = Pb[i] * math.exp(-g0 * Mair * (H - layers_H[i]) / (Rstar * T))
    else:
        T = Tb[i] + L * (H - layers_H[i]); P = Pb[i] * (T / Tb[i]) ** (-g0 * Mair / (Rstar * L))
    rho = P * Mair / (Rstar * T)
    drho_dH = -rho * (g0 * Mair / Rstar + L) / T
    return T, P, rho, drho_dH * dHdZ
rho0 = std_atm(0.0)[2]
pr("\nUS Standard Atmosphere 1976 rebuilt from its constants [S, mem]; checks against remembered table values")
pr("(the layer-boundary values are at GEOPOTENTIAL height H; Z = H r0/(r0 - H) converts; the 30 km row is geometric):")
def Z_of_H(H): return r0_geo * H / (r0_geo - H)
for Z, want in [(0.0, "T 288.15 K, P 101325 Pa, rho 1.2250"), (Z_of_H(11000), "H 11 km: T 216.65, P 22632 Pa"), (Z_of_H(20000), "H 20 km: P 5474.9 Pa"),
                (30000.0, "Z 30 km: T 226.65, P 1197.0 Pa, rho 0.018410"), (Z_of_H(32000), "H 32 km: T 228.65, P 868.02 Pa"), (Z_of_H(47000), "H 47 km: T 270.65, P 110.91 Pa"), (Z_of_H(71000), "H 71 km: T 214.65, P 3.9564 Pa")]:
    T, P, rho, _ = std_atm(float(Z))
    pr(f"  Z = {Z:8.1f} m: T = {T:.2f} K, P = {P:.3f} Pa, rho = {rho:.6f} kg/m^3   (remembered: {want})")
T30, P30, rho30, _ = std_atm(30000.0)
pr(f"density ratio at 30 km: {rho30/rho0:.5e}; N = {P30/(kB*T30):.4e} m^-3")
cherenkov_summary("Air at 30 km (US Std 1976)", lambda l: n2m1_air_factor(l, rho30 / rho0))

pr("\nB2. How threshold and yield go with density (thin gas): n-1 ~ rho; sin^2(theta) = 1-1/n^2 ~ 2(n-1) ~ rho;")
pr("    yield ~ rho; theta_max ~ sqrt(rho); threshold gamma_t ~ 1/sqrt(2(n-1)) ~ rho^(-1/2); threshold momentum ~ rho^(-1/2).")
pr(f"{'Z (km)':>7} {'rho/rho0':>10} {'n-1':>11} {'theta_max (deg)':>16} {'yield 300-600/m':>16} {'e- thr (MeV)':>13} {'mu thr (GeV)':>13} {'p thr (GeV)':>12}")
for Z in [0, 5, 10, 15, 20, 30, 40, 50]:
    T, P, rho, _ = std_atm(Z * 1000.0)
    n2m1 = n2m1_air_factor(0.589, rho / rho0)
    nm1 = n2m1 / (1 + math.sqrt(1 + n2m1))
    s2 = one_minus_inv_n2(n2m1)
    th = math.degrees(math.asin(math.sqrt(s2)))
    Y = 2 * math.pi * alpha * s2 * (1/300e-9 - 1/600e-9)
    gt = math.sqrt(1 + 1 / n2m1)
    pr(f"{Z:7d} {rho/rho0:10.4e} {nm1:11.4e} {th:16.4f} {Y:16.4e} {(gt-1)*me_eV*1e-6:13.3f} {(gt-1)*mmu_eV*1e-9:13.3f} {(gt-1)*mp_eV*1e-9:12.2f}")

pr("\n" + "=" * 78)
pr("PART C. Vacuum Cherenkov: light slower than a charged particle's limit by delta")
pr("=" * 78)
pr("C1. Non-dispersive: c_light = c(1 - delta), particle limit c. Radiates when beta > 1 - delta.")
pr("    Threshold: gamma_t = 1/sqrt(1-(1-delta)^2) = 1/sqrt(delta(2-delta)) ~ 1/sqrt(2 delta); E_t = m gamma_t.")
pr("    Seen particle of energy E and mass m, not radiating => delta < m^2/(2 E^2) (to first order).")
def delta_bound(E_eV, m_eV):
    return m_eV**2 / (2 * E_eV**2)
cases = [("Fly's Eye 320 EeV event, if a proton [I: 3.2e20 eV, source abstract]", 3.2e20, mp_eV),
         ("same event, if an iron nucleus (A=56) [M: worst plausible case]", 3.2e20, 56 * 931.494e6),
         ("same event at its 1-sigma low energy 230 EeV, proton", 2.3e20, mp_eV),
         ("Cosmic-ray electrons to 40 TeV [I: HESS 2024 abstract]", 4.0e13, me_eV),
         ("Cosmic-ray electrons to 1 TeV (Coleman-Glashow / Stecker-Glashow input)", 1.0e12, me_eV),
         ("Crab electrons >= 1.1 PeV [I: LHAASO 1.1 PeV photon; electron >= photon energy for IC]", 1.1e15, me_eV),
         ("Crab electrons 50 TeV [I: Jacobson et al., from 50 TeV IC photons]", 5.0e13, me_eV)]
pr(f"{'case':<88} {'gamma':>10} {'delta <':>10}")
for name, E, m in cases:
    pr(f"{name:<88} {E/m:10.3e} {delta_bound(E, m):10.2e}")
pr("Compare sources: Coleman-Glashow c_p - c_gamma < 1e-23 (proton, 3e20 eV); c_e - c_gamma < 5e-13 (500 GeV e);")
pr("                 Stecker-Glashow delta < 1.3e-13 (1 TeV e); Klinkhamer-Schreck kappa_tr < 6e-20 (Auger event, two-sided with photon decay).")
pr("Which side: vacuum Cherenkov bounds only c_particle > c_light (light slower). The other side (light faster than the")
pr("  particle limit) is bounded by photon decay gamma -> e+ e- (Stecker-Glashow: -delta < 2e-16 from 50 TeV Crab photons;")
pr("  Coleman-Glashow c_gamma - c_e < 1e-15; LHAASO 1.4 PeV photons; Klinkhamer-Schreck -kappa_tr < 9e-16) and photon splitting.")
pr("Assumptions about the source: the primary's identity (proton vs nucleus: factor A^2 in delta), that it is charged and")
pr("  existed at that energy after a path long compared with the loss length (microscopic here), that the Crab electron")
pr("  energy is inferred (IC/synchrotron model), and that direct CR electrons are measured at Earth (no path assumption needed).")

pr("\nC2. Dispersive case, model M3: n^2 = f + (1-f)/(1-(E/E_h)^2), low energy: n - 1 ~ (1-f) E^2/(2 E_h^2)")
f_vals = [0.25, 0.085]
for f in f_vals:
    pr(f"  f = {f}: 1-f = {1-f}; bare speed c/sqrt(f) = {1/math.sqrt(f):.4f} c; n_g - 1 = 3(1-f)E^2/(2E_h^2)")
pr("""
  R-i  (matter's limit is the bare speed c/sqrt(f) > c):
       Every charged particle can exceed light's phase speed c/n(E) <= c at all photon energies in the dispersive band.
       A particle at v = c (gamma_bare = 1/sqrt(1-f) only: 1.155 for f=1/4) radiates at every E > 0; faster ones more so.
       Particles with E >> m c_b^2 (a few GeV) move at ~c/sqrt(f) = 2c: excluded by direct timing of relativistic
       particles against light (accelerator time-of-flight, [S, mem]) before any Cherenkov argument.
       Frank-Tamm energy loss for a particle at v = c: dW/dx = (alpha/hbar c)(1-f) E_h^2/4 (band to E_h), enormous.
  R-ii (matter's speed at energy E_p is capped at light's speed at the same energy, c/n(E_p), same dispersion):
       Cherenkov needs v_particle > c/n(E_gamma). With normal dispersion n rising with E, and E_gamma <= E_p
       (energy conservation), c/n(E_p) <= c/n(E_gamma): never satisfied. If the particle's dispersion is
       E^2 = p^2 c^2/n(E)^2 + m^2 c^4, its group speed is below c/n(E_p) (shown below). So 'nothing radiates'
       FOLLOWS from monotone dispersion plus energy conservation; it is not merely asserted. It costs the particle a
       velocity deficit (1-f)E^2/(2E_h^2) on top of m^2/(2E^2), which the Crab synchrotron bounds (see C3).
  R-iii (matter's limit is c, ordinary dispersion; light's phase speed c/n(E) < c for E > 0):
       Cherenkov when 1/(2 gamma^2) < (1-f)E^2/(2E_h^2), i.e. for photon energies E > E_min = E_h/(gamma sqrt(1-f)).
       Exact kinematics (recoil kept): emission of a photon of energy w from a particle of energy E needs
       (1-f) w^2/(2E_h^2) >= m^2 c^4/(2E(E-w)); the left/right ratio is largest at w = 2E/3, so NO photon can be
       emitted iff E_h > sqrt(4(1-f)/27) E^2/(m c^2) = 0.3849 sqrt(1-f) E^2/(m c^2).
""")
def Eh_bound_Riii(E, m, f):
    return math.sqrt(4 * (1 - f) / 27) * E**2 / m
pr("  R-iii: lower bounds on the hold E_h from particles seen not to radiate (no-emission condition):")
pr(f"{'particle':<70} {'E^2/m (eV)':>12} {'E_h > (f=1/4)':>14} {'E_h > (f=0.085)':>16}")
for name, E, m in cases:
    pr(f"{name[:70]:<70} {E**2/m:12.3e} {Eh_bound_Riii(E, m, 0.25):14.3e} {Eh_bound_Riii(E, m, 0.085):16.3e}")
# energy-loss scale if below the bound: classical Frank-Tamm over the band E_min..E
def loss_rate(E, m, f, Eh):
    gamma = E / m
    Emin = Eh / (gamma * math.sqrt(1 - f))
    if Emin >= E: return 0.0, Emin
    # dW/dx = (alpha/hbar c) int_{Emin}^{E} w [ (1-f) w^2/Eh^2 - 1/gamma^2 ] dw   (classical, soft-photon form)
    A = (1 - f) / Eh**2
    W = (alpha / hbarc_eVm) * (A * (E**4 - Emin**4) / 4 - (E**2 - Emin**2) / (2 * gamma**2))
    return W, Emin
pr("\n  R-iii: if E_h sits below the bound, classical loss rate (soft-photon Frank-Tamm; indicative only near w ~ E):")
for name, E, m in [("proton 3.2e20 eV", 3.2e20, mp_eV), ("electron 40 TeV", 4e13, me_eV), ("electron 1.1 PeV", 1.1e15, me_eV)]:
    for Eh in [3e19, 1e20, 1e22, 1e24, 1e26, 1e28, 1e30]:
        W, Emin = loss_rate(E, m, 0.25, Eh)
        if W > 0:
            pr(f"    {name:<18} E_h = {Eh:8.1e} eV: photons above {Emin:9.3e} eV; dW/dx = {W:9.3e} eV/m; loss length E/(dW/dx) = {E/W:9.3e} m")
        else:
            pr(f"    {name:<18} E_h = {Eh:8.1e} eV: no emission (E_min = {Emin:9.3e} eV >= E)")

# R-ii particle group speed below c/n(E): show numerically for the massless and massive case
pr("\n  R-ii check: particle with E^2 = p^2c^2/n(E)^2 + m^2c^4, v = dE/dp versus c/n(E) (analytic derivative):")
pr("    p c = n(E) sqrt(E^2-m^2);  c dp/dE = n'(E) sqrt(E^2-m^2) + n(E) E/sqrt(E^2-m^2);  v/c = 1/(c dp/dE).")
pr("    c/n - v = c [n' (E^2-m^2) + n m^2/E ... ] / (n * c dp/dE) > 0 whenever n' >= 0: both terms positive.")
def n_of_E(E, f, Eh):
    return math.sqrt(f + (1 - f) / (1 - (E / Eh)**2))
def dn_dE(E, f, Eh):
    # d/dE sqrt(f + (1-f)/(1-x^2)), x = E/Eh:  = (1-f) * 2x/(1-x^2)^2 / (2 n Eh)
    x = E / Eh
    return (1 - f) * 2 * x / (1 - x * x)**2 / (2 * n_of_E(E, f, Eh) * Eh)
f = 0.25; Eh = 1e20
for E in [1e12, 1e15, 1e18, 3e19, 6e19]:
    m = me_eV
    n = n_of_E(E, f, Eh); npr = dn_dE(E, f, Eh)
    s = math.sqrt(E * E - m * m)
    cdpdE = npr * s + n * E / s
    v_over_c = 1 / cdpdE
    # (c/n - v)/c = (cdpdE - n)/(n cdpdE) = (n' s + n (E/s - 1))/(n cdpdE), with E/s - 1 = m^2/(s (E + s)) > 0
    gap = (npr * s + n * m * m / (s * (E + s))) / (n * cdpdE)
    pr(f"    E = {E:8.1e} eV: n(E) - 1 = {n-1:.3e}, (c/n - v)/c = {gap:.3e} > 0: {gap > 0}")

pr("\nC3. Light's own dispersion under M3 (any reading): time-of-flight bound on E_h from GRB 090510 (z = 0.903).")
# Delta t = int dz (1+z)^2/H(z) * (3/2)(1-f) E^2/E_h^2  for the quadratic case (group speed c(1 - 3(1-f)E^2/(2E_h^2)))
H0 = 70.0 * 1e3 / 3.0856775814913673e22   # s^-1 [S, mem: ~70 km/s/Mpc]
Om, OL = 0.3, 0.7
def kappa2(z):
    val, _ = quad(lambda zz: (1 + zz)**2 / math.sqrt(Om * (1 + zz)**3 + OL), 0, z)
    return val / H0   # seconds
K2 = kappa2(0.903)
pr(f"  kappa_2 = int (1+z)^2 dz / H(z) = {K2:.4e} s  (Omega_m 0.3, Omega_L 0.7, H0 70 [S, mem])")
for label, E, dt in [("(a) 0.859 s at 28 GeV", 28e9, 0.859), ("(e) 10 ms at 31 GeV", 31e9, 0.010), ("31 GeV photon, 0.829 s after trigger [mem]", 31e9, 0.829)]:
    for f in f_vals:
        Eh = math.sqrt(1.5 * (1 - f) * E**2 * K2 / dt)
        pr(f"  {label:<44} f = {f:<6}: E_h > {Eh:.3e} eV   (E_QG,2 equivalent {Eh/math.sqrt(1-f):.3e} eV)")
EQG2 = 1.3e11 * 1e9
for f in f_vals:
    pr(f"  Vasileiou et al. 2013 subluminal E_QG,2 > 1.3e11 GeV [S, abstract] -> E_h > {EQG2*math.sqrt(1-f):.3e} eV (f = {f}); "
       f"convention v_g = c(1 - (3/2)(E/E_QG,2)^2) assumed [mem]")
pr("  Side: these TOF limits are for the SUBLUMINAL photon case (high-energy light slower), which is M3's sign (n > 1 below E_h).")
pr("  Source assumption: no intrinsic lag of the high-energy photons at emission (the 'conservative' limits relax this).")

pr("\nC4. R-ii synchrotron check [D]: Crab synchrotron to 100 MeV needs electrons of ~1500 TeV (Jacobson et al., LI case)")
pr("    moving with velocity deficit no larger than about m^2/(2E^2). Under R-ii the extra deficit (1-f)E^2/(2E_h^2) must be")
pr("    no bigger than that: E_h >~ sqrt(1-f) E^2/m.")
for E in [1.5e15, 2.3e15]:
    for f in f_vals:
        pr(f"    E = {E:.1e} eV, f = {f}: E_h >~ {math.sqrt(1-f)*E**2/me_eV:.3e} eV")

pr("\n" + "=" * 78)
pr("PART D. The setting Sun: horizon refraction through the 1976 standard atmosphere")
pr("=" * 78)
R_earth = 6371000.0   # m [M: mean radius for the ray geometry]
def make_n_profile(lam_um=0.589, T_surf=None, P_surf=None):
    """n(r) - 1 = (n_std - 1) * rho(h)/rho_std where rho follows the standard atmosphere; optionally rescale
    the whole profile for a different surface T and P keeping the standard lapse structure (density ratio P/T)."""
    nm1_ref = nm1_ciddor(lam_um)      # at 288.15 K, 101325 Pa (dry)
    scale = 1.0
    if T_surf is not None or P_surf is not None:
        Ts = T_surf if T_surf is not None else 288.15
        Ps = P_surf if P_surf is not None else 101325.0
        scale = (Ps / 101325.0) * (288.15 / Ts)
    def nm1(hm):
        return nm1_ref * scale * std_atm(hm)[2] / rho0
    def dn_dh(hm):
        return nm1_ref * scale * std_atm(hm)[3] / rho0
    return nm1, dn_dh

def refraction_arcmin(app_alt_deg, h_obs=0.0, lam_um=0.589, T_surf=None, P_surf=None, h_top=90000.0, want_airmass=False):
    """Astronomical refraction for apparent altitude app_alt_deg (deg) for an observer at height h_obs (m).
    Bouguer: n r sin z = n0 r0 sin z0.  R = int_{r0}^{r_top} (n0 r0 sin z0)(-dn/dr) / (n sqrt(n^2 r^2 - (n0 r0 sin z0)^2)) dr.
    Singular endpoint at z0 = 90 deg handled by r = r0 + t^2."""
    nm1, dndh = make_n_profile(lam_um, T_surf, P_surf)
    r0 = R_earth + h_obs
    n0 = 1 + nm1(h_obs)
    z0 = math.radians(90.0 - app_alt_deg)
    Cst = n0 * r0 * math.sin(z0)
    def integrand_t(t):
        r = r0 + t * t
        hm = r - R_earth
        n = 1 + nm1(hm)
        # n^2 r^2 - Cst^2 computed as (n r - Cst)(n r + Cst)
        d = (n * r - Cst) * (n * r + Cst)
        if d <= 0: return 0.0
        return Cst * (-dndh(hm)) / (n * math.sqrt(d)) * 2 * t
    tmax = math.sqrt(h_top - h_obs)
    # split the integral: dense near the observer, and at the layer boundaries (kinks in dn/dh), in geometric height
    Zb = [r0_geo * Hb / (r0_geo - Hb) for Hb in layers_H[1:-1]]
    pts = sorted(set([0.0] + [math.sqrt(x - h_obs) for x in [1, 10, 100, 1000, 3000, 5000, 25000, 40000, 60000] + Zb if x > h_obs] + [tmax]))
    total = 0.0
    for a, b in zip(pts[:-1], pts[1:]):
        val, err = quad(integrand_t, a, b, limit=400, epsabs=1e-13, epsrel=1e-10)
        total += val
    R = math.degrees(total) * 60.0
    if not want_airmass:
        return R
    # air mass: column along the ray / vertical column
    def integrand_am(t):
        r = r0 + t * t
        hm = r - R_earth
        n = 1 + nm1(hm)
        d = (n * r - Cst) * (n * r + Cst)
        if d <= 0: return 0.0
        # ds = n r dr / sqrt(n^2 r^2 - Cst^2)
        return std_atm(hm)[2] * n * r / math.sqrt(d) * 2 * t
    col = sum(quad(integrand_am, a, b, limit=400, epsabs=1e-9, epsrel=1e-9)[0] for a, b in zip(pts[:-1], pts[1:]))
    vcol = quad(lambda hm: std_atm(hm)[2], h_obs, h_top, limit=200)[0]
    return R, col / vcol

def bennett(app_alt_deg, P_mb=1010.0, T_C=10.0):
    """Bennett 1982: R' = cot(h + 7.31/(h + 4.4)) arcmin, h in degrees, for 1010 mb and 10 C; scaled by (P/1010)(283/(273+T)). [S, mem]"""
    h = app_alt_deg
    R = 1 / math.tan(math.radians(h + 7.31 / (h + 4.4)))
    return R * (P_mb / 1010.0) * (283.0 / (273.0 + T_C))

R_h, am_h = refraction_arcmin(0.0, want_airmass=True)
pr(f"D1. Horizon refraction (apparent altitude 0), observer at sea level, 589 nm, 1976 standard atmosphere: {R_h:.2f} arcmin")
pr(f"    air mass along that ray (column relative to vertical): {am_h:.1f}")
pr(f"    Bennett at 1010 mb, 10 C: {bennett(0.0):.2f}'; Bennett scaled to 1013.25 mb, 15 C: {bennett(0.0, 1013.25, 15.0):.2f}'")
pr("    Nautical Almanac / Bennett horizon value [S, mem]: 34.5' at 1010 mb, 10 C; Pulkovo tables 35.4' at 0 C, 1013.25 mb [S, mem].")
# Independent cross-check of the integral: Cartesian ray trace d(n s_hat)/ds = grad n, DOP853
from scipy.integrate import solve_ivp
def ray_trace_arcmin(app_alt_deg, h_obs=0.0, lam_um=0.589, h_top=90000.0):
    nm1, dndh = make_n_profile(lam_um)
    r0 = R_earth + h_obs; n0 = 1 + nm1(h_obs); a = math.radians(app_alt_deg)
    def rhs(s, u):
        x, y, px, py = u; r = math.hypot(x, y); hm = r - R_earth; n = 1 + nm1(hm); g = dndh(hm)
        return [px / n, py / n, g * x / r, g * y / r]
    def top(s, u): return math.hypot(u[0], u[1]) - (R_earth + h_top)
    top.terminal = True; top.direction = 1
    sol = solve_ivp(rhs, [0, 4e6], [0.0, r0, n0 * math.cos(a), n0 * math.sin(a)], method='DOP853', rtol=1e-12, atol=1e-6, events=top, max_step=2000.0)
    x, y, px, py = sol.y[:, -1]
    return -math.degrees(math.atan2(py, px) - a) * 60
pr(f"    Cross-check by Cartesian ray trace (DOP853): horizon {ray_trace_arcmin(0.0):.3f}', 45 deg {ray_trace_arcmin(45.0):.4f}' "
   f"(integral: {refraction_arcmin(45.0):.4f}'; plane-parallel (n0-1) tan z = {math.degrees(nm1_std)*60:.4f}')")
pr("    Sensitivity to the model's tropospheric lapse rate (surface 15 C, 1013.25 mb kept):")
_lapse_saved = lapse[0]; _Tb_saved = list(Tb); _Pb_saved = list(Pb)
for Ltest in [-9.8e-3, -6.5e-3, -3.0e-3, 0.0]:
    lapse[0] = Ltest
    Tb[:] = [T0]; Pb[:] = [P0]
    for i in range(1, len(layers_H)):
        L = lapse[i-1]; dH = layers_H[i] - layers_H[i-1]
        if L == 0:
            T = Tb[-1]; P = Pb[-1] * math.exp(-g0 * Mair * dH / (Rstar * Tb[-1]))
        else:
            T = Tb[-1] + L * dH; P = Pb[-1] * (T / Tb[-1]) ** (-g0 * Mair / (Rstar * L))
        Tb.append(T); Pb.append(P)
    pr(f"      lapse {Ltest*1e3:5.1f} K/km: horizon refraction {refraction_arcmin(0.0):.2f}'")
lapse[0] = _lapse_saved; Tb[:] = _Tb_saved; Pb[:] = _Pb_saved
Hs = Rstar * T0 / (Mair * g0)
pr(f"    Isothermal closed form (n0-1) sqrt(pi r0/(2H)), H = {Hs:.0f} m: {math.degrees(nm1_std*math.sqrt(math.pi*R_earth/(2*Hs)))*60:.2f}'")
pr("\nD2. Refraction versus apparent altitude (standard conditions) against Bennett scaled to 1013.25 mb, 15 C:")
pr(f"{'app alt (deg)':>14} {'R integrator':>13} {'Bennett(15C)':>13} {'Bennett(10C,1010)':>18}")
for a in [0.0, 0.25, 0.5, 0.5333, 1.0, 2.0, 5.0, 10.0, 20.0, 45.0, 80.0]:
    pr(f"{a:14.4f} {refraction_arcmin(a):13.3f} {bennett(a, 1013.25, 15.0):13.3f} {bennett(a):18.3f}")
# flattening: lower limb at apparent altitude 0, upper limb 32' higher (apparent); true diameter 32.0' (~31.5-32.5 through the year)
D_sun = 32.0
R_low = R_h; R_up = refraction_arcmin(D_sun / 60.0)
# apparent vertical diameter d_app satisfies: true separation = d_app + R(0) - R(d_app)  -> solve
def app_diam(true_d):
    d = true_d
    for _ in range(50):
        d = true_d - (refraction_arcmin(0.0) - refraction_arcmin(d / 60.0))
    return d
d_app = app_diam(D_sun)
pr(f"\nD3. Flattening of the Sun with its lower limb on the horizon: true diameter {D_sun}', apparent vertical {d_app:.2f}'"
   f" (shrunk by {D_sun-d_app:.2f}', ratio {d_app/D_sun:.3f}); horizontal unchanged at 32'.")
pr(f"    (refraction at the upper limb's apparent altitude {d_app:.1f}': {refraction_arcmin(d_app/60):.2f}')")
pr("\nD4. Delay of sunset: the Sun's centre is geometrically below the horizon by R(0) + semi-diameter when the upper limb")
pr("    seems to touch it; the geometric centre crosses the horizon earlier by R(0) / (rate of sinking).")
for lat in [0, 30, 40, 50, 60]:
    rate = 15.0 * math.cos(math.radians(lat))   # arcmin per minute at equinox (declination 0) [S]
    pr(f"    latitude {lat:2d}, equinox: sinking rate {rate:.2f}'/min -> refraction delays the set by {R_h/rate:.2f} min; "
       f"whole disc (R + 16'): {(R_h+16)/rate:.2f} min after the geometric centre crossing")
pr("\nD5. Colour: dispersion of air lifts blue more than red (refraction ~ n-1):")
for lam_nm in [400, 450, 500, 550, 589, 650, 700]:
    R_l = refraction_arcmin(0.0, lam_um=lam_nm / 1000)
    pr(f"    {lam_nm} nm: n-1 = {nm1_ciddor(lam_nm/1000):.4e}, horizon refraction {R_l:.3f}' ({(R_l-R_h)*60:+.1f} arcsec vs 589 nm)")
# Rayleigh extinction along the horizon ray
pr(f"    Reddening is extinction, not refraction: vertical column N = {P_std/(Mair/NA*g0):.3e} m^-2; air mass at horizon {am_h:.1f}.")
for lam_nm in [450, 550, 650]:
    kl = 2 * math.pi / (lam_nm * 1e-9)
    nm1_l = nm1_ciddor(lam_nm / 1000)
    ap = nm1_l / (2 * math.pi * N_std)
    sig = (8 * math.pi / 3) * kl**4 * ap**2 * F_king
    tau_v = sig * P_std / (Mair / NA * g0)
    pr(f"    {lam_nm} nm: Rayleigh sigma {sig:.3e} m^2, vertical tau {tau_v:.4f}, along horizon ray tau {tau_v*am_h:.2f}, transmission {math.exp(-tau_v*am_h):.2e}")
pr("\nD6. Dependence on surface temperature and pressure (standard lapse structure kept, whole profile scaled by P/T):")
for T_C in [-20, 0, 15, 30, 40]:
    pr(f"    T = {T_C:4d} C, 1013.25 mb: R(0) = {refraction_arcmin(0.0, T_surf=273.15+T_C, P_surf=101325.0):.2f}'  Bennett scaled: {bennett(0.0, 1013.25, T_C):.2f}'")
for P_mb in [950, 980, 1013.25, 1040]:
    pr(f"    15 C, {P_mb:7.2f} mb: R(0) = {refraction_arcmin(0.0, T_surf=288.15, P_surf=P_mb*100):.2f}'  Bennett scaled: {bennett(0.0, P_mb, 15):.2f}'")
pr("    Note: a real surface inversion (temperature rising with height) bends horizon rays far more; this scaling does not model it.")
pr("\nD7. Dependence on the observer's height (horizontal ray, apparent altitude 0, from that height):")
for hm in [0, 10, 100, 1000, 3000, 10000, 30000]:
    R_obs = refraction_arcmin(0.0, h_obs=float(hm))
    dip_geo = math.degrees(math.acos(R_earth / (R_earth + hm))) * 60
    pr(f"    h = {hm:6d} m: R(0) = {R_obs:7.3f}' ; density ratio {std_atm(float(hm))[2]/rho0:.4f}; geometric dip of the sea horizon {dip_geo:.2f}'"
       f"  (rule 1.93'*sqrt(h/m) = {1.93*math.sqrt(hm):.2f}'; with refraction ~1.76'*sqrt(h/m) = {1.76*math.sqrt(hm):.2f}' [S, mem])")

pr("\n" + "=" * 78)
pr("PART E. Scharnhorst and Euler-Heisenberg sizes")
pr("=" * 78)
lamC = hbar / (me_kg * c)
pr(f"reduced Compton wavelength hbar/(m c) = {lamC:.5e} m")
pr("Scharnhorst (review eq. 10, in sources): n_perp(0) = 1 - (11 pi^2/90^2) alpha^2 (hbar/(m c L))^4 between mirrors a distance L apart.")
for L in [1e-9, 1e-8, 1e-7, 1e-6, 1e-5]:
    dc = (11 * math.pi**2 / 8100) * alpha**2 * (lamC / L)**4
    pr(f"    L = {L:.0e} m: (c_perp - c)/c = {dc:.3e}")
pr("    Casimir energy density between the mirrors: u = -pi^2 hbar c/(720 L^4):")
for L in [1e-6]:
    u = -math.pi**2 * hbar * c / (720 * L**4)
    pr(f"    L = {L:.0e} m: u = {u:.3e} J/m^3 = {u/e*1e-6:.3e} eV/cm^3")
pr("Euler-Heisenberg (PVLAS review eq. 4/20 in sources): A_e = (2/45) alpha^2 hbar^3/(mu0 m^4 c^5); n_par - 1 = 7 A_e B^2, n_perp - 1 = 4 A_e B^2, Delta n = 3 A_e B^2")
mu0 = 1 / (eps0 * c**2)
Ae = (2 / 45) * alpha**2 * hbar**3 / (mu0 * me_kg**4 * c**5)
pr(f"    A_e = {Ae:.3e} T^-2  (review: 1.32e-24 T^-2)")
for B in [1.0, 2.5, 10.0, 100.0, 1e4, 4.414e9]:
    pr(f"    B = {B:9.3e} T: n_par - 1 = {7*Ae*B*B:.3e}, n_perp - 1 = {4*Ae*B*B:.3e}, Delta n = {3*Ae*B*B:.3e}")
Bc = me_kg**2 * c**2 / (e * hbar)
pr(f"    critical field B_c = m^2 c^2/(e hbar) = {Bc:.4e} T; weak-field form valid for B << B_c")
pr("    PVLAS-FE measured Delta n = (12 +/- 17)e-23 at 2.5 T (review abstract) versus predicted 3 A_e B^2 =", f"{3*Ae*2.5**2:.2e}")
pr("    Electric field: n - 1 ~ A_e (E/c)^2: for E = 1e8 V/m (laboratory limit), (E/c)^2 = ", f"{(1e8/c)**2:.3e} T^2 -> n-1 ~ {7*Ae*(1e8/c)**2:.1e}")
pr("\nDone.")