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

check_windows.py

In the investigation at sim/charge_wave/check_questions_fable/check_windows.py · last changed in commit 32efd1b, 13 November 2026 · 15,766 bytes · the folder as a zip


"""check_windows.py - eighth independent reviewer's own check of section 9.1 of Charging_quons draft 0.14 (commit 4ed0ede).

Question: where does a quon whose charge fills a uniform ball of radius a (Aspden's b/d = 0.036135562) rest in an even
simple cubic grid of finer quons, N times finer, held rigid and in register; how strongly is it held there; and which whole
numbers N pass the five tests of section 9.1 (rests at a centre of symmetry; positive hold; cubic (isotropic) hold;
hold >= 0.0927; whole number)?

Own code, written for this review (not copied from the trial or the earlier checks):
  * the potential of the point finer grid (unit spacing, unit charges, neutralizing uniform background) by an Ewald sum
    of my own; checked against the Madelung constant of the simple cubic lattice (-2.837297479);
  * the ball's energy by the interior potential of a uniform ball (3 alpha^2 - rho^2)/(2 alpha^3) for sites inside it;
  * the Hessian (the hold tensor) by central finite differences of the energy, not an analytic formula;
  * checked against the trace rule (n_in/y_f - 1)/3 and against the Fourier series (trial 5's D1) at a few points;
  * the finer quons with the trial's Gaussian width (s2 N = 0.02) and as uniform balls of radius b/N (a smaller copy),
    at the symmetric positions, by the Fourier series with the shapes' form factors.
Units: finer spacing 1; v = N u is the offset in finer units; alpha = a N the ball's radius in finer units. In trial 5's
units the quon's energy is E(u) = -(1/N^2) e(v) and the hold tensor, in units of 4 pi n q^2, is K = -(1/(4 pi)) d2e/dv2.
Run: ~/aspden-review-venv/bin/python3 check_windows.py > check_windows_out.txt 2> check_windows_err.txt
"""
import itertools, math, time
import numpy as np
from scipy.optimize import minimize
from scipy.special import erf, erfc

T0 = time.time()
A_ASPDEN = 0.036135562          # b/d, Part 1 U05 (aether_units.py)
SC_MIN = 0.0927                 # requirement 2: the lowest wave of the simple cubic lattice at M, trial 2 C4
ETA = 2.0
SITES = np.array(list(itertools.product(range(-4, 6), repeat=3)), float)            # 1000 sites around [0, 1/2]^3
MVEC = np.array([m for m in itertools.product(range(-6, 7), repeat=3) if any(m)], float)
M2 = (MVEC ** 2).sum(1)
RECIP_COEF = np.exp(-math.pi ** 2 * M2 / ETA ** 2) / (math.pi * M2)                  # 4 pi exp(-G^2/4eta^2)/G^2, G = 2 pi m


def e_ball(V, alpha):
    """Energy of a unit uniform ball (radius alpha) centred at each row of V in the zero-mean potential of the unit point grid.
    e(v) = sum_s phi_ball(|s - v|) - background; computed as Ewald(point grid at v) + sum over sites inside the ball of
    [(3 alpha^2 - rho^2)/(2 alpha^3) - 1/rho]. The constant mean-value term 2 pi alpha^2/5 of the background is omitted
    (it does not depend on v)."""
    V = np.atleast_2d(np.asarray(V, float))
    out = np.empty(len(V))
    for i0 in range(0, len(V), 500):
        Vc = V[i0:i0 + 500]
        D = Vc[:, None, :] - SITES[None, :, :]
        rho = np.sqrt((D ** 2).sum(2))
        rs = np.where(rho < 1e-14, 1.0, rho)
        inside = rho < alpha
        term_out = erfc(ETA * rs) / rs
        term_in = (3 * alpha ** 2 - rho ** 2) / (2 * alpha ** 3) - np.where(rho < 1e-14, 2 * ETA / math.sqrt(math.pi), erf(ETA * rs) / rs)
        real = np.where(inside, term_in, term_out).sum(1)
        recip = np.cos(2 * math.pi * Vc @ MVEC.T) @ RECIP_COEF
        out[i0:i0 + 500] = real + recip - math.pi / ETA ** 2
    return out


def hessian_fd(v, alpha, h=2e-4):
    """Central finite differences of e at v (3 x 3)."""
    v = np.asarray(v, float)
    H = np.zeros((3, 3))
    e0 = e_ball(v, alpha)[0]
    for i in range(3):
        ei = np.zeros(3); ei[i] = h
        H[i, i] = (e_ball(v + ei, alpha)[0] - 2 * e0 + e_ball(v - ei, alpha)[0]) / h ** 2
        for j in range(i + 1, 3):
            ej = np.zeros(3); ej[j] = h
            H[i, j] = H[j, i] = (e_ball(v + ei + ej, alpha)[0] - e_ball(v + ei - ej, alpha)[0]
                                 - e_ball(v - ei + ej, alpha)[0] + e_ball(v - ei - ej, alpha)[0]) / (4 * h ** 2)
    return H


def hold_tensor(v, alpha):
    return -hessian_fd(v, alpha) / (4 * math.pi)


def n_inside(v, alpha):
    return int(np.sum(np.sqrt(((np.asarray(v) - SITES) ** 2).sum(1)) < alpha))


WEDGE = np.array([(i, j, l) for i in range(21) for j in range(i, 21) for l in range(j, 21)], float) / 40


def rest_position(alpha):
    """The maximum of e (minimum of the quon's energy) over a finer cell: scan the symmetry wedge, refine locally."""
    ev = e_ball(WEDGE, alpha)
    best_v, best_e = None, -np.inf
    for st in WEDGE[np.argsort(-ev)[:5]]:
        res = minimize(lambda x: -e_ball(np.clip(x, 0, 0.5), alpha)[0], st, method="Nelder-Mead",
                       options=dict(xatol=1e-7, fatol=1e-13, maxiter=4000))
        x = np.clip(res.x, 0, 0.5)
        val = e_ball(x, alpha)[0]
        if val > best_e:
            best_v, best_e = np.sort(np.abs(x)), val
    v = np.where(best_v < 2e-5, 0.0, np.where(np.abs(best_v - 0.5) < 2e-5, 0.5, best_v))
    return v, e_ball(v, alpha)[0]


NAMES = {(0.0, 0.0, 0.0): "on a finer quon", (0.0, 0.0, 0.5): "edge midpoint", (0.0, 0.5, 0.5): "face centre",
         (0.5, 0.5, 0.5): "cube centre"}


def name(v):
    return NAMES.get(tuple(float(x) for x in v), "(%.4f, %.4f, %.4f)" % tuple(v))


def form_ball(x):
    x = np.asarray(x, float)
    return np.where(x < 1e-6, 1.0, 3 * (np.sin(x) - x * np.cos(x)) / np.where(x < 1e-6, 1.0, x) ** 3)


# Fourier series for the trace/3 of the hold at offset v with finer quons of a given shape (trial 5's D2, my own code):
# K_T(v) = (1/3) sum_{m != 0} F_ball(2 pi |m| alpha) F_finer(2 pi |m|) cos(2 pi m . v)
MF = np.array([m for m in itertools.product(range(-70, 71), repeat=3) if any(m)], float)
MFN = np.sqrt((MF ** 2).sum(1))


def hold_fourier(v, alpha, finer="point", s2=0.02, a_f=A_ASPDEN):
    F1 = form_ball(2 * math.pi * MFN * alpha)
    if finer == "point":
        F2 = np.ones_like(MFN)
    elif finer == "gauss":
        F2 = np.exp(-0.5 * (2 * math.pi * MFN * s2) ** 2)
    else:
        F2 = form_ball(2 * math.pi * MFN * a_f)
    return float(np.sum(F1 * F2 * np.cos(2 * math.pi * MF @ np.asarray(v, float)))) / 3


print("Eighth reviewer: section 9.1's five tests at Aspden's radius, with code of my own (post hoc to trial 5, as a check)")
print("Units: finer spacing 1; hold in units of 4 pi n q^2 (the continuum's pull along the beam); share = 1/(1 + hold)")

# ---------------------------------------------------------------- A. checks of the route
print("\nA. Checks of the route")
phi_site = e_ball(np.zeros(3), 1e-3)[0]        # a tiny ball on a site: the ball term is (3/(2 alpha)) - 2 eta/sqrt(pi) + ...
# For a ball of radius alpha on a site, e(0) = phi_site(Madelung) + 3/(2 alpha) exactly (the site's point potential replaced
# by the ball's self-potential at its centre), so the Madelung potential is e(0) - 3/(2 alpha), for any alpha below 1.
for al in (0.3, 0.45):
    print(f"   Madelung potential of the simple cubic lattice from e(0) - 3/(2 alpha), alpha = {al}: "
          f"{e_ball(np.zeros(3), al)[0] - 3 / (2 * al):.9f}  (expected -2.837297479)")
# eta independence
ETA_SAVE = ETA
vals = []
for eta in (1.6, 2.0, 2.4):
    ETA = eta
    RECIP_COEF = np.exp(-math.pi ** 2 * M2 / ETA ** 2) / (math.pi * M2)
    vals.append(e_ball(np.array([0.13, 0.27, 0.41]), 0.7)[0])
ETA = ETA_SAVE
RECIP_COEF = np.exp(-math.pi ** 2 * M2 / ETA ** 2) / (math.pi * M2)
print(f"   e(v) at v = (0.13, 0.27, 0.41), alpha = 0.7, for eta = 1.6, 2.0, 2.4: spread {max(vals) - min(vals):.1e}")
# trace rule at the symmetric positions
worst = 0.0
for al, v in ((0.45, (0, 0, 0)), (0.6, (0, 0, 0.5)), (0.8, (0, 0.5, 0.5)), (0.95, (0.5, 0.5, 0.5)), (1.45, (0, 0, 0))):
    K = hold_tensor(np.array(v, float), al)
    n = n_inside(np.array(v, float), al)
    yf = 4 * math.pi / 3 * al ** 3
    worst = max(worst, abs(np.trace(K) / 3 - (n / yf - 1) / 3))
print(f"   trace rule: largest |trace(K)/3 - (n_in/y_f - 1)/3| over five cases (finite-difference Hessian): {worst:.1e}")
# against the Fourier series of the energy (trial 5's D1), slowly convergent: E(u) - E(0) in units k/N^2 is -(e(v) - e(0))
for al, v in ((0.5, (0, 0, 0.5)), (0.55, (0, 0.5, 0.5)), (0.9, (0.5, 0.5, 0.5))):
    v = np.array(v, float)
    mine = -(e_ball(v, al)[0] - e_ball(np.zeros(3), al)[0])
    four = -(1 / math.pi) * np.sum(form_ball(2 * math.pi * MFN * al) * (np.cos(2 * math.pi * MF @ v) - 1) / MFN ** 2)
    print(f"   E(u) - E(0) (units k/N^2) at v = {tuple(v)}, alpha = {al}: Ewald route {mine:+.6e}, Fourier series (|m| <= 70) {four:+.6e}")
print("   (the seventh reviewer printed, for alpha = 0.50 at the edge midpoint and N = 4, +1.616388e-02 by Fourier and +1.616468e-02 by Ewald"
      " in the lock's units k/(pi N^2) x pi, i.e. 0.2586/16 = 0.016164: the same value)")
print(f"   {time.time() - T0:.0f} s")

# ---------------------------------------------------------------- B. the scan at Aspden's radius
print("\nB. Where the quon rests at Aspden's radius (b/d = 0.036135562), N = 2..80, point finer quons; the hold tensor there")
print("     N   alpha    rest position           n_in   trace/3   (n/y_f-1)/3   eigenvalues                 share   isotropic  5 tests")
passing = []
rows = {}
for N in range(2, 81):
    alpha = A_ASPDEN * N
    if alpha < 0.3:
        # tiny balls: the finer quon is certainly the rest position (its Coulomb well); use the formula directly
        v = np.zeros(3)
    else:
        v, _ = rest_position(alpha)
    K = hold_tensor(v, alpha)
    lam = np.linalg.eigvalsh(K)
    n = n_inside(v, alpha)
    yf = 4 * math.pi / 3 * alpha ** 3
    kt = np.trace(K) / 3
    iso = (lam[2] - lam[0]) < 1e-3 * max(1.0, abs(kt))
    symmetric = name(v) in NAMES.values()
    cubic = name(v) in ("on a finer quon", "cube centre")
    ok = symmetric and kt > 0 and cubic and iso and lam[0] >= SC_MIN
    rows[N] = (name(v), n, kt, lam, cubic)
    if ok:
        passing.append(N)
    print(f"   {N:3d}  {alpha:6.4f}   {name(v):22s} {n:4d}   {kt:+.4f}   {(n/yf-1)/3:+.4f}      {lam[0]:+.4f} {lam[1]:+.4f} {lam[2]:+.4f}   "
          f"{1/(1+kt):.3f}    {str(iso):5s}    {'pass' if ok else '-'}", flush=True)
print(f"   whole numbers passing the five tests, 2 to 80: {passing}")
print(f"   {time.time() - T0:.0f} s")

# ---------------------------------------------------------------- C. the second window: the N/2 mapping, finite widths, the second resting place
print("\nC. The second window (cube centre, eight finer quons): the N/2 mapping; finite-width finer quons; a second resting place at u = 0")
print("   hold at the cube centre for N (points) against the hold on a finer quon for N/2 (formula (1/y_f(N/2) - 1)/3):")
for N in range(24, 34):
    alpha = A_ASPDEN * N
    kc = np.trace(hold_tensor(np.full(3, 0.5), alpha)) / 3
    yh = 4 * math.pi / 3 * (A_ASPDEN * N / 2) ** 3
    print(f"     N = {N}: cube centre (Ewald route, points) {kc:+.4f};  (8/y_f(N) - 1)/3 = {(8/(4*math.pi/3*alpha**3) - 1)/3:+.4f};  "
          f"(1/y_f(N/2) - 1)/3 = {(1/yh - 1)/3:+.4f};  margin of the corner finer quons inside the ball: {alpha - math.sqrt(3)/2:+.4f}")
print("\n   finite widths at the cube centre and at u = 0 (points: the Ewald route; Gaussian s2 N = 0.02 and a smaller copy, a uniform")
print("   finer ball of radius b/N = 0.0361 finer spacings: the Fourier series, |m| <= 70, which converges for these shapes):")
print("     N    cube centre: points   Gaussian s2N=0.02   smaller copy (ball b/N)   |   u = 0: points   Gaussian   smaller copy   second resting place?")
for N in range(24, 34):
    alpha = A_ASPDEN * N
    cc = [np.trace(hold_tensor(np.full(3, 0.5), alpha)) / 3] + [hold_fourier((0.5, 0.5, 0.5), alpha, f) for f in ("gauss", "copy")]
    z0 = [np.trace(hold_tensor(np.zeros(3), alpha)) / 3] + [hold_fourier((0, 0, 0), alpha, f) for f in ("gauss", "copy")]
    print(f"    {N:3d}    {cc[0]:+.4f}               {cc[1]:+.4f}              {cc[2]:+.4f}                 |   {z0[0]:+.4f}        {z0[1]:+.4f}    {z0[2]:+.4f}       "
          f"{'yes (points)' if z0[0] > 0 else 'no (points)'}, {'yes' if z0[1] > 0 else 'no'} (Gaussian)")
print("   (section 9.1: 24 and 25 give 0.64 and 0.53 as points, 0.17 and 0.50 with the trial's width; 26 to 30 agree to 1e-4;"
      " a second resting place on a finer quon at 28 to 30)")
# is u = 0 a local minimum of the energy (not only a positive trace)? by finite differences, points
print("   u = 0 as a local minimum with point finer quons (all three eigenvalues of the hold tensor positive):")
for N in range(27, 34):
    alpha = A_ASPDEN * N
    lam = np.linalg.eigvalsh(hold_tensor(np.zeros(3), alpha))
    print(f"     N = {N}: eigenvalues {lam[0]:+.4f} {lam[1]:+.4f} {lam[2]:+.4f}; n_in = {n_inside(np.zeros(3), alpha)}; "
          f"E(0) - E(cube centre) in units k/N^2 = {-(e_ball(np.zeros(3), alpha)[0] - e_ball(np.full(3, 0.5), alpha)[0]):+.4e} (positive: the finer quon is the higher place)")

# ---------------------------------------------------------------- D. the first window's table rows and R2c
print("\nD. The first window, 2 to 15, as section 9.1 states it (hold (1/y_f - 1)/3 on a finer quon; share; stable?)")
for N in (1, 2, 3, 12, 13, 14, 15, 16, 17):
    yf = 4 * math.pi / 3 * (A_ASPDEN * N) ** 3
    kt = (1 / yf - 1) / 3
    print(f"   N = {N:2d}: y_f = {yf:.6f}, hold {kt:+.4f}, share {1/(1+kt):.4f}, stable (>= 0.0927): {kt >= SC_MIN}")
nstar = (3 / (8 * math.pi)) ** (1 / 3) / A_ASPDEN
print(f"   N* (f = 1/4, y_f = 1/2) = {nstar:.4f}; twice: {2*nstar:.4f}")
# ---------------------------------------------------------------- E. the rest position with the trial's finer-quon width
print("\nE. Rest position and hold tensor with finer quons of the trial's Gaussian width (s2 N = 0.02), by the Fourier series:")
print("   energy E(u) - E(0) = -(1/pi) sum F1 F2 (cos 2 pi m.v - 1)/m^2 on the wedge (|m| <= 30), K_ij = sum F1 F2 m_i m_j cos(2 pi m.v)/m^2 (|m| <= 50)")
ME = MF[MFN <= 30]; MEN = MFN[MFN <= 30]
MH = MF[MFN <= 50]; MHN = MFN[MFN <= 50]


def energy_gauss(V, alpha, s2=0.02):
    coef = form_ball(2 * math.pi * MEN * alpha) * np.exp(-0.5 * (2 * math.pi * MEN * s2) ** 2) / (math.pi * MEN ** 2)
    out = np.empty(len(V))
    for i0 in range(0, len(V), 200):
        out[i0:i0 + 200] = -((np.cos(2 * math.pi * V[i0:i0 + 200] @ ME.T) - 1) @ coef)
    return out


def tensor_gauss(v, alpha, s2=0.02):
    coef = form_ball(2 * math.pi * MHN * alpha) * np.exp(-0.5 * (2 * math.pi * MHN * s2) ** 2) * np.cos(2 * math.pi * MH @ v) / MHN ** 2
    return np.einsum("n,ni,nj->ij", coef, MH, MH)


print("     N    rest position (Gaussian finer quons)   trace/3    eigenvalues                  share   5 tests (Gaussian)")
for N in (24, 25, 31, 40, 41, 42, 46, 47, 48, 49, 50, 51, 68):
    alpha = A_ASPDEN * N
    ev = energy_gauss(WEDGE, alpha)
    best_v, best_e = None, np.inf
    for st in WEDGE[np.argsort(ev)[:4]]:
        res = minimize(lambda x: energy_gauss(np.clip(x, 0, 0.5)[None, :], alpha)[0], st, method="Nelder-Mead",
                       options=dict(xatol=1e-7, fatol=1e-14, maxiter=3000))
        x = np.clip(res.x, 0, 0.5)
        val = energy_gauss(x[None, :], alpha)[0]
        if val < best_e:
            best_v, best_e = np.sort(np.abs(x)), val
    v = np.where(best_v < 2e-5, 0.0, np.where(np.abs(best_v - 0.5) < 2e-5, 0.5, best_v))
    K = tensor_gauss(v, alpha)
    lam = np.linalg.eigvalsh(K)
    kt = np.trace(K) / 3
    cubic = name(v) in ("on a finer quon", "cube centre")
    ok = cubic and kt > 0 and lam[0] >= SC_MIN
    print(f"    {N:3d}    {name(v):30s}       {kt:+.4f}    {lam[0]:+.4f} {lam[1]:+.4f} {lam[2]:+.4f}     {1/(1+kt):.3f}   {'pass' if ok else '-'}", flush=True)
print(f"\nrun time {time.time() - T0:.0f} s")