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

thinning_to_vacuum_posthoc_check.py

In the investigation at sim/matter_light/thinning_to_vacuum_posthoc_check.py · last changed in commit 7743556, 22 November 2026 · 7,799 bytes · runnable copies in the scripts zip


"""Trial 22, post hoc check by the author seat (22 November 2026, after the run at 1e4811f). NOT part of the trial; labelled post hoc.

Two things the author seat's review of the output found:
 1. Precision. The run's Q2 sweep table computes n as a float and then n - 1 = n - 1.0, and its Q5 gas rows take Ciddor's n - 1.0.
    Below n - 1 of about 1e-13 that loses digits, and at 1e-16 (one unit in the last place of 1.0) nothing is left: the run prints
    2.220e-16 for air at 1e-7 Pa (one ulp) and 0 for 1e-10 Pa and the hydrogen rows. Here n - 1 is computed without the cancellation.
 2. The horizon refraction. The run's ray integral warned (quad's subdivision limit, roundoff). Here R(0), R(0.5 deg) and the horizon
    air mass are recomputed with an independent atmosphere and integrator: the US Standard Atmosphere 1976 written afresh from its
    layer table, n - 1 from Ciddor's standard air scaled by density, and the ray integral split at every layer base, in the
    variable z = t^2, by Gauss-Legendre quadrature of increasing order until it settles.
Writes nothing but stdout. Run: python3 thinning_to_vacuum_posthoc_check.py
"""
import subprocess, os
import numpy as np
from numpy.polynomial.legendre import leggauss

here = os.path.dirname(os.path.abspath(__file__))
print("Trial 22 post hoc check (not part of the trial). git HEAD:",
      subprocess.run(["git", "rev-parse", "HEAD"], capture_output=True, text=True, cwd=here).stdout.strip())

kB = 1.380649e-23
a0 = 5.29177210903e-11

# ---------- 1. n - 1 without cancellation ----------
# Dilute gas: Lorentz-Lorenz y = N alpha/(3 eps0); n^2 - 1 = 3y/(1 - y); n - 1 = (n^2 - 1)/(n + 1). For tiny y, n - 1 = 1.5 y (1 + ...).
def n1_from_y(y):
    n2m1 = 3.0 * y / (1.0 - y)
    return n2m1 / (np.sqrt(1.0 + n2m1) + 1.0)

def ciddor_std_n1(lam_um):
    """Ciddor's standard dry air, 15 C, 101325 Pa, 450 ppm CO2: (n - 1), no cancellation (the formula gives n - 1 directly) [I]."""
    s2 = 1.0 / lam_um ** 2
    return (5792105.0 / (238.0185 - s2) + 167917.0 / (57.362 - s2)) * 1e-8

N_STD = 101325.0 / (kB * 288.15)                     # ideal gas; Ciddor's compressibility changes it by 4e-4, irrelevant at these densities
n1d_std = ciddor_std_n1(0.5893)
y_per_N = (n1d_std * (2 + n1d_std) / ((n1d_std * (2 + n1d_std)) + 3.0)) / N_STD   # invert n^2 - 1 = 3y/(1 - y)
yH = (4 * np.pi / 3) * 4.5 * a0 ** 3                  # hydrogen atom: alpha/(4 pi eps0) = 4.5 a0^3, y = N alpha/(3 eps0)

print("\n1. The rows the run printed with lost digits, recomputed (589 nm):")
print(f"{'medium':>40} {'N (1/m^3)':>11} {'n - 1':>11} {'1 - f':>11}   run printed")
rows = [("air, 1e-7 Pa, 20 C", 1e-7 / (kB * 293.15), y_per_N, "2.220e-16, 4.44e-16"),
        ("air, 1e-10 Pa, 20 C", 1e-10 / (kB * 293.15), y_per_N, "0, 0"),
        ("interplanetary neutral H, 1e5 /m^3", 1e5, yH, "0, 0"),
        ("interstellar H, 1e6 /m^3", 1e6, yH, "0, 0"),
        ("intergalactic, 0.252 H /m^3 (as neutral)", 0.252, yH, "0, 0")]
for label, N, ypn, run in rows:
    n1 = n1_from_y(N * ypn)
    print(f"{label:>40} {N:11.3e} {n1:11.3e} {2*n1:11.3e}   {run}")
print("   (1 - f = 1 - 1/n^2 = 2(n - 1) to first order. The run's text values, 2.7e-19 at 1e-10 Pa and 4.2e-24 interstellar, were computed"
      " without the cancellation and agree with these.)")

# The Q5 gas row at 1e-7 Pa (400 nm): Cherenkov thresholds
n1_400_std = ciddor_std_n1(0.4)
n1_400 = n1_400_std * (1e-7 / (kB * 293.15)) / N_STD
g = (1 + n1_400) / np.sqrt(n1_400 * (2 + n1_400))
ME, MMU, MPI, MP = 0.51099895, 105.6583755, 139.57039, 938.27208816
print(f"\n   Air at 1e-7 Pa, 20 C, 400 nm: n - 1 = {n1_400:.3e} (run: 2.220e-16); gamma_th = {g:.3e} (run: 4.75e+07);"
      f" E_th e = {g*ME:.4g} MeV, mu = {g*MMU/1e3:.4g} GeV, pi = {g*MPI/1e3:.4g} GeV, p = {g*MP/1e3:.4g} GeV"
      f" (run: 2.425e+07 MeV, 5.014e+06, 6.623e+06, 4.452e+07 GeV); photons per metre at beta = 1 scale with n - 1:"
      f" {42.5 * n1_400 / 2.779e-4:.3g} (run: 3.39e-11).")

# ---------- 2. The horizon refraction, independently ----------
R0 = 6356.766e3                     # geopotential radius [S, from memory]
RE = 6371.0e3                       # the Earth's radius used for the ray (the run's choice) [M]
g0, Rstar, M0 = 9.80665, 8.31432, 0.0289644
HB = [0.0, 11e3, 20e3, 32e3, 47e3, 51e3, 71e3, 84.852e3]   # geopotential layer bases
LR = [-6.5e-3, 0.0, 1.0e-3, 2.8e-3, 0.0, -2.8e-3, -2.0e-3]
TB, PB = [288.15], [101325.0]
for i in range(7):
    T0, P0, L, dh = TB[i], PB[i], LR[i], HB[i + 1] - HB[i]
    T1 = T0 + L * dh
    P1 = P0 * np.exp(-g0 * M0 * dh / (Rstar * T0)) if L == 0 else P0 * (T0 / T1) ** (g0 * M0 / (Rstar * L))
    TB.append(T1); PB.append(P1)
print(f"\n2. US Standard Atmosphere 1976, written afresh: layer-base pressures {', '.join(f'{p:.2f}' for p in PB[1:7])} Pa;"
      f" T at 84.852 km = {TB[7]:.3f} K (table: 22632.1, 5474.89, 868.019, 110.906, 66.9389, 3.95642 Pa; 186.946 K).")

def state(zg):
    """T, P, density (kg/m^3) at geometric height zg; above 84.852 km geopotential, isothermal [M, as the run]."""
    h = R0 * zg / (R0 + zg)
    i = min(np.searchsorted(HB, h, side="right") - 1, 7)
    if i == 7:
        T = TB[7]; P = PB[7] * np.exp(-g0 * M0 * (h - HB[7]) / (Rstar * T))
    else:
        L = LR[i]; T = TB[i] + L * (h - HB[i])
        P = PB[i] * np.exp(-g0 * M0 * (h - HB[i]) / (Rstar * TB[i])) if L == 0 else PB[i] * (TB[i] / T) ** (g0 * M0 / (Rstar * L))
    return T, P, P * M0 / (Rstar * T)

rho_s = state(0.0)[2]
def n_of(zg, lam_um):
    return 1.0 + ciddor_std_n1(lam_um) * (101325.0 * M0 / (Rstar * 288.15)) ** -1 * state(zg)[2]   # n - 1 proportional to density

ZTOP = 120e3
zbreaks_geom = [R0 * h / (R0 - h) for h in HB[1:]] + [ZTOP]

def refraction(h_app_deg, lam_um, order):
    """R = int over the path of the bending, written as int (tan z)(-dn/n): Bouguer's C = n r cos(h_app); in z = t^2 per layer [S]."""
    C = n_of(0.0, lam_um) * RE * np.cos(np.radians(h_app_deg))
    x, w = leggauss(order)
    tot = 0.0; z_lo = 0.0
    for z_hi in zbreaks_geom:
        t_lo, t_hi = np.sqrt(z_lo), np.sqrt(z_hi)
        for tt, ww in zip(0.5 * (t_hi - t_lo) * x + 0.5 * (t_hi + t_lo), 0.5 * (t_hi - t_lo) * w):
            z = tt * tt
            dz = max(1e-3, 1e-6 * z)
            n = n_of(z, lam_um); dndz = (n_of(z + dz, lam_um) - n_of(z - dz, lam_um)) / (2 * dz) if z > dz else (n_of(z + dz, lam_um) - n) / dz
            u = n * (RE + z); s = u * u - C * C
            if s > 0:
                tot += ww * C / np.sqrt(s) * (-dndz / n) * 2 * tt
        z_lo = z_hi
    return tot

ARCMIN = np.pi / (180 * 60)
for h in (0.0, 0.5, 5.0, 45.0):
    vals = [refraction(h, 0.55, o) / ARCMIN for o in (40, 80, 160)]
    print(f"   R({h:g} deg) at 550 nm, Gauss-Legendre orders 40, 80, 160 per layer: {vals[0]:.4f}', {vals[1]:.4f}', {vals[2]:.4f}'")
print("   The run: R(0) = 33.011', R(0.5) = 27.653', R(5) = 9.664', R(45) = 0.953' (Bennett scaled to 15 C, 1013.25 hPa: 33.988', 28.346', 9.743', 0.981').")

def airmass_h0(order):
    """Horizon air mass: the slant column over the vertical column, the ray bent by refraction (Bouguer's invariant) [S]."""
    C = n_of(0.0, 0.55) * RE
    x, w = leggauss(order)
    slant = vert = 0.0; z_lo = 0.0
    for z_hi in zbreaks_geom:
        t_lo, t_hi = np.sqrt(z_lo), np.sqrt(z_hi)
        for tt, ww in zip(0.5 * (t_hi - t_lo) * x + 0.5 * (t_hi + t_lo), 0.5 * (t_hi - t_lo) * w):
            z = tt * tt; n = n_of(z, 0.55); u = n * (RE + z); s = u * u - C * C
            rho = state(z)[2]
            if s > 0:
                slant += ww * rho * u / np.sqrt(s) * 2 * tt
            vert += ww * rho * 2 * tt
        z_lo = z_hi
    return slant / vert
print(f"   Horizon air mass, orders 80 and 160: {airmass_h0(80):.3f}, {airmass_h0(160):.3f} (the run: 38.159; Kasten and Young: about 38).")