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

s3_engine_validation.py

In the investigation at sim/m8_engine/s3_engine_validation.py · last changed in commit a66cab2, 25 November 2026 · 9,697 bytes · runnable copies in the scripts zip


#!/usr/bin/env python3
"""Trial 25 (run S3): the wheel-and-band engine with M2's held charges. Lock: papers/Lock_S3_engine_2026-11-25.md, committed with this script
before the run. Author seat (Claude Opus 5.5), 25 November 2026, at Doug Westmoreland's word ("ok to run").
A validation of the engine against laws derived beforehand. It tests the code and the derivations, not nature."""
import math
import subprocess
import sys
import time

import numpy as np
from scipy.optimize import curve_fit

sys.path.insert(0, ".")
from engine import Lattice, curl_e2f, curl_f2e, div_e, plane_wave_E, static_field_of, prony_frequencies, edge_positions  # noqa: E402

print("Trial 25 (run S3): the wheel-and-band engine with held charges. Lock: papers/Lock_S3_engine_2026-11-25.md")
print("git HEAD:", subprocess.run(["git", "rev-parse", "HEAD"], capture_output=True, text=True).stdout.strip())
print("python", sys.version.split()[0], "numpy", np.__version__)
t_start = time.time()
res = {}
code_ok = []


def project(lat, k, pol):
    pos = edge_positions(lat.shape)
    return sum(pol[a] * np.sum(lat.E[a] * np.cos(k[0] * pos[a][0] + k[1] * pos[a][1] + k[2] * pos[a][2])) for a in range(3))


def stepped(Omt, dt):
    return 2 / dt * math.asin(Omt * dt / 2)


# ---------------------------------------------------------------------------------------------------------------------
print("\nCode checks (not locked)")
rng = np.random.default_rng(25)
A, B = rng.normal(size=(3, 6, 6, 6)), rng.normal(size=(3, 6, 6, 6))
c1 = abs(np.sum(curl_e2f(A) * B) - np.sum(A * curl_f2e(B))) < 1e-9
c2 = np.abs(div_e(curl_f2e(B))).max() < 1e-12
print(f"   K1 curl_e2f is the transpose of curl_f2e: {c1}; K2 no wheel motion makes charge: {c2}")
code_ok += [c1, c2]

# ---------------------------------------------------------------------------------------------------------------------
print("\nP1. The empty lattice: one standing wave in each of three directions; its frequency against the stepped law")
dt = 0.1
N = 48
P1 = []
for name, m, pol in (("axis", (4, 0, 0), (0, 1, 0)), ("axis", (8, 0, 0), (0, 1, 0)), ("face diagonal", (3, 3, 0), (0, 0, 1)), ("face diagonal", (6, 6, 0), (0, 0, 1)),
                     ("cube diagonal", (2, 2, 2), (1, -1, 0)), ("cube diagonal", (4, 4, 4), (1, -1, 0))):
    k = [2 * math.pi * mm / N for mm in m]
    pol = np.array(pol, float) / np.linalg.norm(pol)
    shape = (N, N if m[1] else 2, N if m[2] else 2)
    lat = Lattice(shape, dt)
    lat.E = plane_wave_E(shape, k, pol)
    x = [project(lat, k, pol)]
    for _ in range(300):
        lat.step(); x.append(project(lat, k, pol))
    w, _ = prony_frequencies(np.array(x), dt, 1)
    lam = sum(4 * math.sin(kk / 2) ** 2 for kk in k)
    pred = stepped(math.sqrt(lam), dt)
    kabs = math.sqrt(sum(kk * kk for kk in k)); n_ = np.array(k) / kabs; S4 = float((n_**4).sum())
    wc = math.sqrt(lam)                                   # continuous-time frequency
    grain = (kabs - wc) / wc / (kabs**2 * S4 / 24)
    rel = abs(w[0] / pred - 1)
    P1.append(rel)
    print(f"   {name:14s} m = {m}: |k|d = {kabs:.4f}; run {w[0]:.12f}; stepped law {pred:.12f}; difference {rel:.1e}; (n - 1)/((kd)^2 S4/24) = {grain:.4f}")
res["P1"] = max(P1) < 1e-8
print(f"   P1: largest difference {max(P1):.1e} (mark 1e-8): {'PASS' if res['P1'] else 'MISS'}")

# ---------------------------------------------------------------------------------------------------------------------
print("\nP2. A held charge on every band (wb2 = 0.25, wp2 = 0.75): two branches at each k, nothing between 0.5 and 1.0")
N = 32
wb2, wp2 = 0.25, 0.75
P2, gapok = [], True
for m in (1, 3, 6, 10, 16):
    k = (2 * math.pi * m / N, 0, 0)
    shape = (N, 2, 2)
    lat = Lattice(shape, dt, wb2=wb2, wp2=wp2, occ=np.ones((3, *shape)))
    lat.E = plane_wave_E(shape, k, (0, 1, 0))
    d0 = div_e(lat.E + lat.P).copy()
    e0 = lat.energy()
    x = [project(lat, k, (0, 1, 0))]
    for _ in range(600):
        lat.step(); x.append(project(lat, k, (0, 1, 0)))
    w, _ = prony_frequencies(np.array(x), dt, 2)
    lam = 4 * math.sin(k[0] / 2) ** 2
    bq = wb2 + wp2 + lam
    roots = sorted([(bq - math.sqrt(bq * bq - 4 * lam * wb2)) / 2, (bq + math.sqrt(bq * bq - 4 * lam * wb2)) / 2])
    pred = [stepped(math.sqrt(r), dt) for r in roots]
    rel = max(abs(w[i] / pred[i] - 1) for i in range(2))
    P2.append(rel)
    wt = [2 / dt * math.sin(ww * dt / 2) for ww in w]
    inside = any(0.5 < v < 1.0 for v in wt)
    gapok &= not inside
    code_ok.append(np.abs(div_e(lat.E + lat.P) - d0).max() < 1e-12)
    print(f"   m = {m:2d} (kd = {k[0]:.4f}): run {w[0]:.10f}, {w[1]:.10f}; law {pred[0]:.10f}, {pred[1]:.10f}; difference {rel:.1e}; any in the stop band: {inside}")
res["P2"] = max(P2) < 1e-7 and gapok
print(f"   P2: largest difference {max(P2):.1e} (mark 1e-7); none in the stop band: {gapok}: {'PASS' if res['P2'] else 'MISS'}")

# ---------------------------------------------------------------------------------------------------------------------
print("\nP6. A free charge on every band (wb2 = 0, wp2 = 0.3): Omega~^2 = wp2 + lambda; nothing below sqrt(wp2)")
P6 = []
for m in (1, 3, 6, 10, 16):
    k = (2 * math.pi * m / N, 0, 0)
    shape = (N, 2, 2)
    lat = Lattice(shape, dt, wb2=0.0, wp2=0.3, occ=np.ones((3, *shape)))
    lat.E = plane_wave_E(shape, k, (0, 1, 0))
    x = [project(lat, k, (0, 1, 0))]
    for _ in range(400):
        lat.step(); x.append(project(lat, k, (0, 1, 0)))
    w, _ = prony_frequencies(np.array(x), dt, 1)
    lam = 4 * math.sin(k[0] / 2) ** 2
    pred = stepped(math.sqrt(0.3 + lam), dt)
    rel = abs(w[0] / pred - 1)
    P6.append(rel)
    print(f"   m = {m:2d}: run {w[0]:.10f}; law {pred:.10f}; difference {rel:.1e}")
res["P6"] = max(P6) < 1e-7
print(f"   P6: largest difference {max(P6):.1e} (mark 1e-7): {'PASS' if res['P6'] else 'MISS'}")

# ---------------------------------------------------------------------------------------------------------------------
print("\nP4. One held charge alone on a 64^3 lattice: its frequency and its loss by radiation")
N = 64
G_N = 0.249203                                            # s3_prep_out.txt
pred4 = {0.5: (0.576611, 8.495173e-03, 0.600090, 8.140655e-03), 0.25: (0.587999, 4.601142e-03, 0.600090, 4.401434e-03)}


def ring(t, A_, gam, om, ph):
    return A_ * np.exp(-gam * t) * np.cos(om * t + ph)


P4ok = True
for wp2 in (0.5, 0.25):
    wb2 = 0.36 - wp2 / 3
    shape = (N, N, N)
    occ = np.zeros((3, *shape)); occ[0, 32, 32, 32] = 1
    lat = Lattice(shape, dt, wb2=wb2, wp2=wp2, occ=occ)
    lat.P[0, 32, 32, 32] = 1e-3
    lat.E = static_field_of(lat.P)
    e0 = lat.energy()
    ts, ps = [0.0], [lat.P[0, 32, 32, 32]]
    for _ in range(600):
        lat.step(); ts.append(lat.t); ps.append(lat.P[0, 32, 32, 32])
    ts, ps = np.array(ts), np.array(ps)
    sel = (ts >= 5) & (ts <= 55)
    om0, Gam, om_alt, Gam_L = pred4[wp2]
    popt, _ = curve_fit(ring, ts[sel], ps[sel], p0=(1e-3, Gam / 2, om0, 0.0), maxfev=20000)
    om_run, Gam_run = popt[2], 2 * popt[1]
    ok_om = abs(om_run / om0 - 1) < 0.005
    ok_g = abs(Gam_run / Gam - 1) < 0.10
    P4ok &= ok_om and ok_g
    resid = np.abs(ps[sel] - ring(ts[sel], *popt)).max() / 1e-3
    print(f"   wp2 = {wp2}: frequency run {om_run:.6f}, predicted {om0:.6f} ({om_run/om0-1:+.2e}; without the field's inertia {om_alt:.6f}, {om_run/om_alt-1:+.2e}); "
          f"loss rate run {Gam_run:.4e}, predicted {Gam:.4e} ({Gam_run/Gam-1:+.3f}; Larmor's alone {Gam_run/Gam_L-1:+.3f}); fit residual {resid:.1e} of the start")
res["P4"] = P4ok
print(f"   P4 (marks: frequency 0.5%, loss rate 10%): {'PASS' if P4ok else 'MISS'}")

# ---------------------------------------------------------------------------------------------------------------------
print("\nP3. Bands filled at random (all three families, a fraction p of each), the steady state reached by the engine with losses")
N = 24
wb2 = 1.0
own = (1 - 1 / N**3) / 3
P3 = {}
for y in (0.05, 0.1, 0.2):
    alpha = 3 * y
    ab = 1 / (1 / alpha - own)
    for p in (0.2, 0.5):
        rats = []
        for seed in range(12):
            r = np.random.default_rng(1000 * seed + int(100 * p) + int(1000 * y))
            nfill = round(p * N**3)
            occ = np.stack([(r.permutation(N**3) < nfill).reshape(N, N, N) for _ in range(3)]).astype(float)
            q = nfill / N**3
            lat = Lattice((N, N, N), dt, wb2=wb2, wp2=ab * wb2, occ=occ, g=0.5, sigma_m=0.5)
            lat.E[0] += 1.0
            last = None
            for it in range(6000):
                lat.step()
                if it % 200 == 199:
                    em = lat.E[0].mean()
                    if last is not None and abs(em - last) < 1e-12:
                        break
                    last = em
            eps = 1.0 / lat.E[0].mean()
            cm = (1 + 2 * q * y) / (1 - q * y)
            dep = 6 * q * q * (1 - q) * y**3
            rats.append((eps - cm) / dep)
        rats = np.array(rats)
        P3[(y, p)] = (rats.mean(), rats.std(ddof=1) / math.sqrt(len(rats)))
        print(f"   y = {y:<5} p = {p:<4} (departure/6 p^2 (1-p) y^3) = {rats.mean():.3f} +- {P3[(y, p)][1]:.3f}  (last step {it}, |dE| {abs(em-last) if last is not None else float('nan'):.1e})")
res["P3"] = all(0.8 <= P3[(y, p)][0] <= 1.3 for y in (0.05, 0.1) for p in (0.2, 0.5))
print(f"   P3 (mark: 0.8 to 1.3 at y = 0.05 and 0.1; y = 0.2 measured, no mark): {'PASS' if res['P3'] else 'MISS'}")

print(f"\nCode checks: {sum(code_ok)} of {len(code_ok)} pass (the corners' charge stays as it was in every P2 run, and the transposes).")
print("Verdicts by the lock:", ", ".join(f"{k} {'PASS' if v else 'MISS'}" for k, v in res.items()))
print(f"(run took {time.time() - t_start:.0f} s)")