Does light charge the quons? › Files cited on the page › check_m8_fable/
b1_p3_third_order.py
#!/usr/bin/env python3
"""Phase B check of OUTLINE.md 15.5 P3 (by hand, not run there): with bands filled at random (fraction p, all three edge families),
n^2 exceeds Clausius-Mossotti by 6 p^2 (1-p) y^3 to lowest order, y = alpha_iso/(3 eps0 d^3). Here: solve the steady lattice for random
fillings (32^3, several samples), all three families occupied independently with probability p, each charge responding along its own edge.
Also the lattice sum the outline quotes: sum over all other bands of the squared relaxed field of one band's dipole = 2/9."""
import subprocess, numpy as np
print("git HEAD:", subprocess.run(["git", "rev-parse", "HEAD"], capture_output=True, text=True).stdout.strip())
N = 32
k = 2 * np.pi * np.fft.fftfreq(N)
KX, KY, KZ = np.meshgrid(k, k, k, indexing="ij")
lam = -4 * (np.sin(KX / 2)**2 + np.sin(KY / 2)**2 + np.sin(KZ / 2)**2)
def grad(V): return np.stack([np.roll(V, -1, axis=a) - V for a in range(3)])
def div(s): return sum(s[a] - np.roll(s[a], 1, axis=a) for a in range(3))
def P_grad(s):
Q = np.fft.fftn(div(s)); Q[0, 0, 0] = 0
with np.errstate(divide="ignore", invalid="ignore"):
V = np.real(np.fft.ifftn(np.where(lam != 0, Q / lam, 0)))
return grad(V)
# lattice sum
s_p = np.zeros((3, N, N, N)); s_p[0, 5, 5, 5] = 1.0
s_rel = P_grad(s_p)
tot = np.sum(s_rel**2); own = s_rel[0, 5, 5, 5]**2
print(f"\nlattice sums: total sum of squared relaxed field = {tot:.6f} (1/3 expected), own edge {own:.6f} (1/9), all other bands {tot-own:.6f} (outline: 2/9 = 0.222222);"
f" other x-bands only {np.sum(s_rel[0]**2)-own:.6f}, y- and z-bands {np.sum(s_rel[1:]**2):.6f}")
def solve_eps(mask3, a, sw=1.0, iters=3000):
s_p = np.zeros((3, N, N, N)); s_p[0] = -a * sw * mask3[0] / (1 + a)
for it in range(iters):
s_edge = P_grad(s_p); s_edge[0] += sw + s_p[0].mean(); s_edge[1] += s_p[1].mean(); s_edge[2] += s_p[2].mean()
s_new = -a * mask3 * s_edge
if np.abs(s_new - s_p).max() < 1e-13: s_p = s_new; break
s_p = 0.5 * s_p + 0.5 * s_new
return sw / (sw + s_p[0].mean()), it
def cm(x): return (1 + 2 * x / 3) / (1 - x / 3)
print("\nall three families filled at random. y = alpha_iso/(3 eps0 d^3) = a_iso/3. residual = n^2(lattice) - CM(p a_iso); outline: 6 p^2 (1-p) y^3")
print(" p a y mean residual (6 samples) std outline 6p^2(1-p)y^3 ratio residual/outline")
for p in (0.5, 0.2):
for a in (0.5, 1.0, 2.0):
a_iso = a / (1 + a / 3); y = a_iso / 3
res = []
for seed in range(6):
rng = np.random.default_rng(200 + seed)
mask3 = (rng.uniform(size=(3, N, N, N)) < p).astype(float)
p_act = mask3[0].mean()
eps, it = solve_eps(mask3, a)
res.append(eps - cm(p_act * a_iso))
res = np.array(res); pred = 6 * p**2 * (1 - p) * y**3
print(f" {p} {a:.1f} {y:.4f} {res.mean():+.3e} {res.std(ddof=1):.1e} {pred:+.3e} {res.mean()/pred:.3f}")
print("\nx-family only (my blind set-up), for comparison:")
for p in (0.5,):
for a in (1.0, 2.0):
a_iso = a / (1 + a / 3); y = a_iso / 3
res = []
for seed in range(6):
rng = np.random.default_rng(300 + seed)
mask3 = np.zeros((3, N, N, N)); mask3[0] = (rng.uniform(size=(N, N, N)) < p).astype(float)
eps, it = solve_eps(mask3, a)
res.append(eps - cm(mask3[0].mean() * a_iso))
res = np.array(res); pred = 6 * p**2 * (1 - p) * y**3
print(f" {p} {a:.1f} {y:.4f} {res.mean():+.3e} {res.std(ddof=1):.1e} {pred:+.3e} {res.mean()/pred:.3f}")