Does light charge the quons? › Files cited on the page › the trials
cubic_lattices.py
"""cubic_lattices.py - trial 7 of the charging-quons work: Doug's body-centred or face-centred quon lattice, with the finer
grid a smaller copy of the same lattice (13 November 2026, afternoon).
Lock: papers/Lock_cubic_lattices_2026-11-13.md, committed with this script before the run.
Finer units: one finer quon per unit volume; the quon's charge fills a ball of radius alpha = b N / d; the finer quons are
points. e(v) = Phi_L(v) + sum over finer quons p inside the ball of [(3 a^2 - rho^2)/(2 a^3) - 1/rho], with Phi_L the zero-mean
Ewald potential of the unit-volume lattice L. The quon rests where e is greatest; the hold tensor there is K = -(1/4 pi) Hess e,
in units of 4 pi n q^2. This is the real-space route of reflection_grid_review7_check.py, generalized from the simple cubic
lattice to any Bravais lattice.
Run: ~/aspden-review-venv/bin/python3 cubic_lattices.py > cubic_lattices_out.txt 2> cubic_lattices_err.txt
Run 2 (13 November, after run 1): the rest search made robust against saddle points (see rest()); nothing else changed.
Run 3 (after run 2): every trial point is folded into the primitive cell centred on the origin (fold()), because run 2's
refinement once wandered beyond the lattice-point list (fcc N = 40, caught by the trace rule); R5 skips a window holding none.
"""
import itertools, math, re, time
import numpy as np
from scipy.optimize import minimize
from scipy.special import erf, erfc
T0 = time.time()
SQPI = math.sqrt(math.pi)
B = 0.036135562 # Aspden's b/d (Part 1 U05), d = (volume per quon)^(1/3)
NSTAR = (3 / (8 * math.pi)) ** (1 / 3) / B
RS = (3 / (4 * math.pi)) ** (1 / 3) # Wigner-Seitz radius at unit volume
WS = {"sc": -0.880059, "bcc": -0.895929, "fcc": -0.895874} # Madelung coefficients, from memory (the lock)
KINDS = ("sc", "bcc", "fcc")
def basis(kind):
if kind == "sc":
ac = 1.0; A = np.eye(3); C = [np.zeros(3)]
elif kind == "bcc":
ac = 2 ** (1 / 3); A = ac / 2 * np.array([[-1, 1, 1], [1, -1, 1], [1, 1, -1]], float)
C = [np.zeros(3), np.full(3, 0.5)]
else:
ac = 4 ** (1 / 3); A = ac / 2 * np.array([[0, 1, 1], [1, 0, 1], [1, 1, 0]], float)
C = [np.zeros(3), np.array([0, .5, .5]), np.array([.5, 0, .5]), np.array([.5, .5, 0])]
return ac, A, C
SPECIAL = {
"sc": {"on a finer quon": (0, 0, 0), "edge midpoint": (0, 0, .5), "face centre": (0, .5, .5), "cube centre": (.5, .5, .5)},
"bcc": {"on a finer quon": (0, 0, 0), "octahedral hole": (.5, .5, 0), "tetrahedral hole": (.5, .25, 0)},
"fcc": {"on a finer quon": (0, 0, 0), "octahedral hole": (.5, 0, 0), "tetrahedral hole": (.25, .25, .25)},
}
CUBIC = {"sc": {"on a finer quon", "cube centre"}, "bcc": {"on a finer quon"},
"fcc": {"on a finer quon", "octahedral hole", "tetrahedral hole"}}
class Lat:
def __init__(self, kind, eta=2.5, rcut=5.0):
self.kind, self.eta, self.rcut = kind, eta, rcut
self.ac, self.A, self.C = basis(kind)
n = 12
P = np.array([i * self.A[0] + j * self.A[1] + l * self.A[2] for i, j, l in itertools.product(range(-n, n + 1), repeat=3)])
self.P = P[np.linalg.norm(P, axis=1) <= rcut + 3.0] # covers rcut around any point of the primitive cell
self.Bm = 2 * np.pi * np.linalg.inv(self.A).T
self.Ainv = np.linalg.inv(self.A)
gcut = 13 * eta
m = 10
idx = np.array([v for v in itertools.product(range(-m, m + 1), repeat=3) if any(v)])
G = idx @ self.Bm
G2 = np.einsum("ni,ni->n", G, G)
outer = np.max(np.abs(idx), axis=1) == m
assert np.sqrt(G2[outer].min()) > gcut, "reciprocal shell too small"
keep = G2 <= gcut ** 2
self.G, self.G2 = G[keep], G2[keep]
self.CG = 4 * np.pi / self.G2 * np.exp(-self.G2 / (4 * eta ** 2))
self.canon_special = {name: self.canon(np.array(s) * self.ac) for name, s in SPECIAL[kind].items()}
def e_val(self, V, alpha):
V = np.atleast_2d(V); out = np.empty(len(V)); eta = self.eta
for c0 in range(0, len(V), 256):
Vc = V[c0:c0 + 256]
r = np.linalg.norm(Vc[:, None, :] - self.P[None, :, :], axis=2)
ins = r < alpha
rs = np.where(r < 1e-12, 1.0, r)
outside = np.where(ins | (r >= self.rcut), 0.0, erfc(eta * r) / rs)
gin = np.where(r < 1e-12, 2 * eta / SQPI, erf(eta * r) / rs)
inside = np.where(ins, (3 * alpha ** 2 - r ** 2) / (2 * alpha ** 3) - gin, 0.0)
out[c0:c0 + 256] = outside.sum(1) + inside.sum(1) + np.cos(Vc @ self.G.T) @ self.CG - np.pi / eta ** 2
return out
def grad_hess(self, v, alpha):
eta = self.eta
D = v[None, :] - self.P
rho = np.linalg.norm(D, axis=1)
sel = (rho < self.rcut) | (rho < alpha)
D, rho = D[sel], rho[sel]
ctr = rho < 1e-9
r = np.where(ctr, 1.0, rho)
A_ = erfc(eta * r); A1 = -2 * eta / SQPI * np.exp(-(eta * r) ** 2); A2 = 4 * eta ** 3 * r / SQPI * np.exp(-(eta * r) ** 2)
f1 = A1 / r - A_ / r ** 2
f2 = A2 / r - 2 * A1 / r ** 2 + 2 * A_ / r ** 3
ins = rho < alpha
f1 = f1 + np.where(ins, -r / alpha ** 3 + 1 / r ** 2, 0.0)
f2 = f2 + np.where(ins, -1 / alpha ** 3 - 2 / r ** 3, 0.0)
f1[ctr] = 0.0; f2[ctr] = 0.0
nv = D / r[:, None]
g = (f1[:, None] * nv).sum(0)
H = np.einsum("n,ni,nj->ij", f2 - f1 / r, nv, nv) + np.sum(f1 / r) * np.eye(3)
if ctr.any():
H += (4 * eta ** 3 / (3 * SQPI) - 1 / alpha ** 3) * np.eye(3)
ph = self.G @ v
g += -(self.CG * np.sin(ph)) @ self.G
H += -np.einsum("n,ni,nj->ij", self.CG * np.cos(ph), self.G, self.G)
return g, H
def psi(self):
r = np.linalg.norm(self.P, axis=1); r = r[(r > 1e-9) & (r < self.rcut)]
return erfc(self.eta * r).dot(1 / r) - 2 * self.eta / SQPI + self.CG.sum() - np.pi / self.eta ** 2
def canon(self, v):
w = v / self.ac; best = None
for c in self.C:
u = np.mod(w + c, 1.0); u = np.minimum(u, 1.0 - u); u = np.sort(u)
t = tuple(np.round(u, 6))
if best is None or t < best:
best = t
return np.array(best)
def name(self, v):
cv = self.canon(v)
for nm, cs in self.canon_special.items():
if np.max(np.abs(cv - cs)) < 1e-4:
return nm
return "general (%.4f, %.4f, %.4f)" % tuple(cv)
def n_in(self, v, alpha):
return int(np.sum(np.linalg.norm(self.P - v[None, :], axis=1) < alpha))
GRID = np.array(list(itertools.product(range(16), repeat=3)), float) / 16
def fold(lat, x):
"""The same point of the periodic energy, moved into the primitive cell centred on the origin (run 3: keeps every
evaluation inside the region the lattice-point list covers)."""
f = np.asarray(x, float) @ lat.Ainv
return (f - np.round(f)) @ lat.A
def _refine(lat, alpha, x0):
res = minimize(lambda x: -lat.e_val(fold(lat, x), alpha)[0], fold(lat, x0), jac=lambda x: -lat.grad_hess(fold(lat, x), alpha)[0],
method="L-BFGS-B", options=dict(ftol=1e-15, gtol=1e-11, maxiter=500))
x = fold(lat, res.x)
return x, lat.e_val(x, alpha)[0]
RNG_REST = np.random.default_rng(11)
def rest(lat, alpha):
"""The quon's lowest-energy place (greatest e). Run 2 (after check (v) of run 1 found a saddle on a symmetry line at sc
N = 67): the best 12 grid points are refined twice each, once as they are and once with a small random jitter that
breaks symmetry; then, while the hold at the best point is not positive in every direction (a saddle of e), the search
steps off along the softest direction both ways and refines again."""
V = GRID @ lat.A
ev = lat.e_val(V, alpha)
best = None
for st in V[np.argsort(-ev)[:12]]:
for x0 in (st, st + RNG_REST.normal(size=3) * 2e-3):
x, val = _refine(lat, alpha, x0)
if best is None or val > best[1]:
best = (x, val)
for _ in range(6):
_, H = lat.grad_hess(best[0], alpha)
lam, vec = np.linalg.eigh(-H / (4 * np.pi))
if lam[0] > 1e-9:
break
improved = False
for sgn in (1.0, -1.0):
x, val = _refine(lat, alpha, best[0] + sgn * 0.02 * vec[:, 0])
if val > best[1] + 1e-12:
best, improved = (x, val), True
if not improved:
break
v = best[0]
nm = lat.name(v)
if nm in SPECIAL[lat.kind]: # snap to the exact special site (same orbit), for a clean Hessian
cand = np.array(SPECIAL[lat.kind][nm]) * lat.ac
v = cand if abs(lat.e_val(cand, alpha)[0] - best[1]) < 1e-9 else v
_, H = lat.grad_hess(v, alpha)
K = -H / (4 * np.pi)
lam = np.linalg.eigvalsh(K)
return v, nm, lam, lat.n_in(v, alpha)
def hess_short(Rv, eta):
r = np.linalg.norm(Rv, axis=1)
ex = np.exp(-(eta * r) ** 2) * 2 * eta / SQPI
f1 = -erfc(eta * r) / r ** 2 - ex / r
f2 = 2 * erfc(eta * r) / r ** 3 + ex * (2 / r ** 2 + 2 * eta ** 2)
xx = np.einsum("ni,nj->nij", Rv, Rv) / r[:, None, None] ** 2
return (f2 - f1 / r)[:, None, None] * xx + (f1 / r)[:, None, None] * np.eye(3)
class Dyn:
"""Dynamical matrix of point charges on the unit-volume lattice in a rigid uniform continuum (Part 1's lattice_dynamics.py,
generalized), in units of w_p^2 = 4 pi n q^2/m."""
def __init__(self, lat, eta=1.6, n=6):
A = lat.A; self.eta = eta
R = np.array([i * A[0] + j * A[1] + l * A[2] for i, j, l in itertools.product(range(-n, n + 1), repeat=3) if (i, j, l) != (0, 0, 0)])
self.R = R; self.HS = hess_short(R, eta)
self.G = np.array([i * lat.Bm[0] + j * lat.Bm[1] + l * lat.Bm[2] for i, j, l in itertools.product(range(-n, n + 1), repeat=3)])
def D(self, k):
eta = self.eta; k = np.asarray(k, float)
s_real = np.einsum("n,nij->ij", np.cos(self.R @ k), self.HS)
K = self.G + k; K2 = np.einsum("ni,ni->n", K, K); m = K2 > 1e-12
s_rec = -np.einsum("n,ni,nj->ij", 4 * np.pi * np.exp(-K2[m] / (4 * eta ** 2)) / K2[m], K[m], K[m])
s_self = 4 * eta ** 3 / (3 * SQPI) * np.eye(3)
return ((4 * np.pi / 3) * np.eye(3) - (s_real + s_rec + s_self)) / (4 * np.pi)
def zone_points(lat):
a = lat.ac; t = 2 * np.pi / a
sp = {"sc": {"X": (.5, 0, 0), "M": (.5, .5, 0), "R": (.5, .5, .5)},
"bcc": {"H": (1, 0, 0), "N": (.5, .5, 0), "P": (.5, .5, .5)},
"fcc": {"X": (1, 0, 0), "L": (.5, .5, .5), "W": (1, .5, 0), "K": (.75, .75, 0)}}[lat.kind]
pts = {k: t * np.array(v) for k, v in sp.items()}
if lat.kind == "sc":
pts = {k: 2 * np.pi * np.array(v) for k, v in sp.items()}
return pts
print("Trial 7: a body-centred or face-centred quon lattice, with the finer grid a smaller copy (lock papers/Lock_cubic_lattices_2026-11-13.md)")
print(f" Aspden's b/d = {B}; N* (f = 1/4 on a finer quon holding only it) = {NSTAR:.4f}; finer units: one finer quon per unit volume")
LAT = {k: Lat(k) for k in KINDS}
ok_all = True
# ---- checks (i) and (ii)
print("\nChecks")
rng = np.random.default_rng(7)
for k in KINDS:
l2, l3 = Lat(k, eta=2.0), Lat(k, eta=3.0)
V = rng.uniform(0, 1, (6, 3)) @ LAT[k].A
d = np.max(np.abs(l2.e_val(V, 0.7) - l3.e_val(V, 0.7)))
psi = LAT[k].psi(); psi_ref = 2 * WS[k] / RS
ok = d < 1e-10 and abs(psi - psi_ref) < 1e-5 * 2 / RS
ok_all &= ok
print(f" {k}: (i) e at eta 2.0 vs 3.0: {d:.1e}; (ii) psi = {psi:.6f} against 2 x {WS[k]} / r_s = {psi_ref:.6f}: {'pass' if ok else 'MISS'}")
# ---- R2: the quon lattice's own waves
print("\nR2. The quon lattice's own waves: lowest eigenvalue of the dynamical matrix (units of w_p^2; continuum held)")
LMIN = {}
for k in KINDS:
dy = Dyn(LAT[k]); dy2 = Dyn(LAT[k], eta=2.2)
kr = rng.uniform(0, 1, (4, 3)) @ LAT[k].Bm
tr = max(abs(np.trace(dy.D(q)) - 1) for q in kr)
ed = max(np.max(np.abs(dy.D(q) - dy2.D(q))) for q in kr)
lam_min, where = 9.0, None
pts = [(f"({i},{j},{l})/16", np.array([i, j, l]) / 16 @ LAT[k].Bm) for i, j, l in itertools.product(range(16), repeat=3) if (i, j, l) != (0, 0, 0)]
pts += list(zone_points(LAT[k]).items())
pts += [(f"small k [{s}]", 1e-3 * np.array(v) / np.linalg.norm(v)) for s, v in (("100", (1, 0, 0)), ("110", (1, 1, 0)), ("111", (1, 1, 1)))]
special = {}
for lab, q in pts:
w = np.linalg.eigvalsh(dy.D(q))
if w[0] < lam_min:
lam_min, where = w[0], lab
if not lab.startswith("("):
special[lab] = w
LMIN[k] = lam_min
ok = tr < 1e-8 and ed < 1e-8
ok_all &= ok
print(f" {k}: trace - 1 {tr:.1e}, eta 1.6 vs 2.2 {ed:.1e} ({'pass' if ok else 'MISS'}); lowest eigenvalue {lam_min:+.5f} at {where}")
print(" " + "; ".join(f"{lab}: " + " ".join(f"{x:+.5f}" for x in w) for lab, w in special.items()))
ok4 = abs(LMIN["sc"] + 0.0927) < 5e-5
ok_all &= ok4
print(f" (iv) sc's lowest eigenvalue {LMIN['sc']:+.5f} against Part 1 U28's -0.0927: {'pass' if ok4 else 'MISS'}")
# ---- R3: where the quon leaves its finer quon
print("\nR3. Where the quon's rest leaves its finer quon, against the ball's radius alpha (finer units)")
for k in KINDS:
lat = LAT[k]; prev = None; first = None; seq = []
for a in np.arange(0.30, 1.7001, 0.01):
v, nm, lam, n = rest(lat, a)
tag = (nm, n)
if not seq or seq[-1][1] != tag:
seq.append((round(a, 2), tag))
if first is None and nm != "on a finer quon":
first = (prev, a)
prev = a
lo, hi = first
while hi - lo > 1e-5:
mid = (lo + hi) / 2
if rest(lat, mid)[1] == "on a finer quon":
lo = mid
else:
hi = mid
print(f" {k}: the rest leaves its finer quon at alpha = {(lo + hi) / 2:.5f} (N = {(lo + hi) / 2 / B:.3f} at Aspden's radius)")
print(" sequence (from alpha, site, finer quons inside): " + "; ".join(f"{a:.2f} {t[0]} {t[1]}" for a, t in seq))
# ---- R4: at Aspden's radius
print("\nR4. At Aspden's radius, N = 2 to 80 (alpha = b N / d)")
PASS, ROWS = {}, {}
for k in KINDS:
lat = LAT[k]; PASS[k] = []
print(f"\n {k} (stability needs K_T >= {-LMIN[k]:+.5f})")
print(" N a*N rest n in eigenvalues of K share trace rule five tests")
for N in range(2, 81):
a = B * N
v, nm, lam, n = rest(lat, a)
kt = lam.mean()
rule = (n / (4 * np.pi / 3 * a ** 3) - 1) / 3
tr_ok = abs(kt - rule) < 1e-6
ok_all &= tr_ok
iso = (lam[2] - lam[0]) < 1e-6 * max(1.0, abs(kt))
cubic = nm in CUBIC[k] and iso
ok = cubic and lam[0] > 0 and lam[0] >= -LMIN[k]
if ok:
PASS[k].append(N)
ROWS[(k, N)] = (nm, n, lam, ok)
print(f" {N:3d} {a:.4f} {nm:24s} {n:4d} {lam[0]:+.4f} {lam[1]:+.4f} {lam[2]:+.4f} {1 / (1 + kt):.3f} {'ok' if tr_ok else 'MISS'} {'pass' if ok else 'fail'}",
flush=True)
def groups(xs):
out, s = [], None
for a, b in zip(xs, xs[1:] + [None]):
if s is None:
s = a
if b != a + 1:
out.append(f"{s}" if s == a else f"{s}-{a}"); s = None
return ", ".join(out)
print()
for k in KINDS:
print(f" passing whole numbers, {k}: {groups(PASS[k])}")
# ---- check (v): sc against the earlier scan
old = {}
for line in open("questions_review8_check_out.txt", encoding="utf-8"):
m = re.match(r"\s+(\d+)\s+(\d\.\d{4})\s+(.+?)\s+(\d+)\s+([+-]\d+\.\d{4}) ([+-]\d+\.\d{4}) ([+-]\d+\.\d{4})\s+(\d\.\d{3})\s+(pass|fail)", line)
if m:
old[int(m.group(1))] = (m.group(3).strip(), int(m.group(4)), tuple(float(m.group(i)) for i in (5, 6, 7)), m.group(9) == "pass")
bad = []
for N, (onm, on, olam, opass) in old.items():
nm, n, lam, ok = ROWS[("sc", N)]
same_name = (onm == nm) or (onm.startswith("(") and nm.startswith("general"))
if not (same_name and on == n and all(abs(x - y) < 6e-5 for x, y in zip(olam, lam)) and opass == ok):
bad.append(N)
ok5 = (not bad) and groups(PASS["sc"]) == "2-15, 24-31, 40-42, 47-50, 68"
ok_all &= ok5
print(f" (v) sc against questions_review8_check_out.txt: {len(old)} rows compared, differing {bad}; passing set {'as before' if ok5 else 'DIFFERENT'}: {'pass' if ok5 else 'MISS'}")
# ---- R5: the ratio for f = 1/4
print("\nR5. The ratio for f = 1/4 in each cubic window (alpha* = (3 n / 8 pi)^(1/3); N* = alpha*/(b/d) at Aspden's radius)")
for k in KINDS:
lat = LAT[k]
wins = sorted({(ROWS[(k, N)][0], ROWS[(k, N)][1]) for N in range(2, 81) if ROWS[(k, N)][0] in CUBIC[k]}, key=lambda t: t[1])
for nm, n in wins:
if n == 0:
continue
astar = (3 * n / (8 * np.pi)) ** (1 / 3)
v, nm2, lam, n2 = rest(lat, astar)
there = (nm2 == nm and n2 == n)
Ns = astar / B
near = [N for N in (math.floor(Ns), math.ceil(Ns)) if N in PASS[k]]
shares = ", ".join(f"{N}: {1 / (1 + ROWS[(k, N)][2].mean()):.3f}" for N in near)
print(f" {k}: {nm}, {n} finer quons inside: alpha* = {astar:.4f}, N* = {Ns:.3f}; rests there at alpha*: {there}"
f" ({nm2}, {n2}); nearest passing whole numbers: {shares if shares else 'none'}")
print(f"\nChecks (i) to (v), and the trace rule at every rest: {'all pass' if ok_all else 'SOME MISS'}")
print(f"run time {time.time() - T0:.0f} s")