Does light charge the quons? › Files cited on the page › check_reflection_fable/
check_ewald_fable.py
"""check_ewald_fable.py - the seventh reviewer's own check of trial 5's R3 (is the even grid at rest; its stability at N = 2;
the trace identity; the quon's hold from the dynamical matrix), R3b (springs), and the relaxed hold with springs.
Own Ewald sums (fable_tools.py), different eta and cutoffs from the trial's; plus a Bloch finite-difference check of
Phi at X, M, R from forces in a 2 x 2 x 2 supercell, which uses no analytic Hessian at all.
Run: ~/aspden-review-venv/bin/python3 check_ewald_fable.py > check_ewald_fable_out.txt
"""
import itertools, math, time
import numpy as np
from fable_tools import Ewald, gauss_overlap_sum, stack, theta3
t0 = time.time()
NSS = 0.32169013 # N*S* for K_T = 1/3 (my own bisection in check_closed_forms.py agrees to 8 digits)
print("Seventh reviewer: own Ewald check of R3/R3b (N = 2 stack, K_T = 1/3, s2 = 0.05)\n")
pos, q, s = stack(2, NSS)
n = len(q)
print(f"charges: {n}; s1 = {s[0]:.6f}, s2 = {s[1]:.4f}; q = {q}")
ewA = Ewald(1.0, q, s, eta=1.8, rcells=5, gmax=9)
ewB = Ewald(1.0, q, s, eta=3.2, rcells=5, gmax=14)
kpts = {"Gamma": (0, 0, 0), "(1e-3,0,0)": (1e-3, 0, 0), "X": (math.pi, 0, 0), "M": (math.pi, math.pi, 0),
"R": (math.pi, math.pi, math.pi), "(0.3,0.7,1.1)": (0.3, 0.7, 1.1), "(0.9,0.2,2.5)": (0.9, 0.2, 2.5)}
trial = {"Gamma": (-5.708082, 14.47945, 12), "(1e-3,0,0)": (-5.708082, 23.51176, 11), "X": (-5.735751, 24.35233, 13),
"M": (-5.761732, 18.43264, 13), "R": (-3.517366, 16.42437, 12), "(0.3,0.7,1.1)": (-5.644361, 22.71650, 12)}
# ------------------------------------------------------------------ R3: eigenvalues, trace identity, blocks
print("\nA. Phi(k) by my Ewald (eta 1.8 vs 3.2), eigenvalues, trace identity, non-partner blocks")
print(" k lowest highest negatives |eta diff|/sum|lam| trace identity block traces (max |dev|) lowest non-partner block trial (lowest, highest, neg)")
PG = None
for kn, kv in kpts.items():
k = np.array(kv, float)
PA = ewA.phi(pos, k)
PB = ewB.phi(pos, k)
PA = 0.5 * (PA + PA.conj().T)
PB = 0.5 * (PB + PB.conj().T)
lamA = np.linalg.eigvalsh(PA)
lamB = np.linalg.eigvalsh(PB)
Ssum = np.sum(np.abs(lamA))
deta = np.max(np.abs(lamA - lamB)) / Ssum
tr_total, shares = gauss_overlap_sum(pos, q, s, 1.0, k, rcells=5)
dtr = abs(np.trace(PA).real - tr_total) / Ssum
dblk = max(abs(np.trace(PA[3*i:3*i+3, 3*i:3*i+3]).real - shares[i]) for i in range(n)) / Ssum
low_blk = min(np.linalg.eigvalsh(PA[3*i:3*i+3, 3*i:3*i+3])[0] for i in range(2, n))
neg = int(np.sum(lamA < -1e-9 * Ssum))
tr = trial.get(kn)
trs = f"({tr[0]:+.6f}, {tr[1]:+.5f}, {tr[2]})" if tr else "(not in the trial)"
print(f" {kn:14s} {lamA[0]:+.6e} {lamA[-1]:+.6e} {neg:3d} {deta:.1e} {dtr:.1e} {dblk:.1e} {low_blk:+.4f} {trs}")
if kn == "Gamma":
PG = PA.real.copy()
# common translation of every charge
U = np.tile(np.eye(3), n)
print(f" at Gamma: energy of moving every charge together, / sum|lam| = {np.max(np.abs(U @ PG @ U.T))/Ssum:.1e}; zero eigenvalues: {int(np.sum(np.abs(lamA) < 1e-9*Ssum))}")
if kn == "(1e-3,0,0)":
pyy = PA[1, 1].real
kt_closed = (theta3(math.exp(-2 * math.pi ** 2 * NSS ** 2)) ** 3 - 1) / 3
print(f" quon's y-y entry at k = (1e-3,0,0): {pyy:.8f}; 4 pi K_T (closed form) = {4*math.pi*kt_closed:.8f}; relative {pyy/(4*math.pi*kt_closed) - 1:+.1e}")
print(f" quon's x-x entry (along k, includes the k+G = 0 term): {PA[0,0].real:.6f}; expected 4 pi (K_T + 1) = {4*math.pi*(kt_closed+1):.6f} "
f"(trial 2's sum rule: longitudinal = transverse + 4 pi n q^2)")
# ------------------------------------------------------------------ B. Bloch finite differences in a 2x2x2 supercell (no analytic Hessian)
print("\nB. Phi(k) at Gamma, X, M, R by finite differences of my Ewald FORCES in a 2x2x2 supercell (Bloch phases e^{ik.R} = +-1)")
L = 2.0
cells = np.array(list(itertools.product(range(2), repeat=3)), float)
posS = np.vstack([pos + c for c in cells])
qS = np.tile(q, 8)
sS = np.tile(s, 8)
ewS = Ewald(L, qS, sS, eta=2.2, rcells=2, gmax=14)
h = 1e-5
E0, F0 = ewS.energy_forces(posS)
print(f" supercell: {len(qS)} charges; largest force at the even arrangement {np.max(np.abs(F0)):.1e} (should be ~0: every site is a centre of inversion)")
# force check vs finite differences of the energy at a random configuration
rng = np.random.default_rng(3)
xr = posS + 0.03 * rng.standard_normal(posS.shape)
Er, Fr = ewS.energy_forces(xr)
Ffd = np.zeros_like(Fr)
for i in range(len(qS)):
for a in range(3):
xp, xm = xr.copy(), xr.copy()
xp[i, a] += h
xm[i, a] -= h
Ffd[i, a] = -(ewS.energy_forces(xp)[0] - ewS.energy_forces(xm)[0]) / (2 * h)
print(f" my forces vs finite differences of my energy (random configuration): max rel {np.max(np.abs(Ffd - Fr))/np.max(np.abs(Fr)):.1e}")
for kn in ("Gamma", "X", "M", "R"):
k = np.array(kpts[kn], float)
phases = np.cos(cells @ k) # +-1
Pfd = np.zeros((3 * n, 3 * n))
for j in range(n):
for b in range(3):
xp, xm = posS.copy(), posS.copy()
for c in range(8):
xp[c * n + j, b] += h * phases[c]
xm[c * n + j, b] -= h * phases[c]
dF = -(ewS.energy_forces(xp)[1] - ewS.energy_forces(xm)[1]) / (2 * h) # d(-F)/du = Phi u
Pfd[:, 3 * j + b] = dF[:n].ravel() # forces on the charges of cell 0
PA = ewA.phi(pos, k).real
PA = 0.5 * (PA + PA.T)
print(f" {kn:6s}: max |Phi_fd - Phi_Ewald| / max |Phi| = {np.max(np.abs(Pfd - PA))/np.max(np.abs(PA)):.1e}; lowest eigenvalue fd {np.linalg.eigvalsh(0.5*(Pfd+Pfd.T))[0]:+.6f} vs Ewald {np.linalg.eigvalsh(PA)[0]:+.6f}")
# ------------------------------------------------------------------ C. Is the even grid at rest for N = 3, 4, 5?
print("\nC. Forces on the finer quons at the even arrangement (my Ewald), N = 3, 4, 5, same widths as R3 (N S = N S*, s2 = 0.1/N)")
for N in (3, 4, 5):
p3, q3, s3 = stack(N, NSS)
ew3 = Ewald(1.0, q3, s3, eta=2.4, rcells=3, gmax=10)
E3, F3 = ew3.energy_forces(p3)
fn = np.linalg.norm(F3[1:], axis=1)
sites = p3[1:]
inv = np.all(np.abs(2 * sites - np.round(2 * sites)) < 1e-9, axis=1)
big = int(np.argmax(fn))
to_q = -(sites[big] - np.round(sites[big]))
cosv = F3[1 + big] @ to_q / (np.linalg.norm(F3[1 + big]) * np.linalg.norm(to_q))
# a point-charge estimate of the pull of the nearest quon alone on a finer quon at distance 1/N: q_f / r^2 = (1/N^3) N^2 = 1/N
print(f" N = {N}: largest |F| = {fn[big]:.6f} at site {tuple(np.round(sites[big]*N).astype(int))}, cosine toward the nearest quon {cosv:+.6f}; "
f"{int(np.sum(fn > 1e-6*fn[big]))} of {N**3} feel more than 1e-6 of it; {int(np.sum(~inv))} are not at a centre of inversion; "
f"largest at a centre {np.max(fn[inv]) if np.any(inv) else 0:.1e}; nearest quon's bare pull 1/N = {1/N:.4f}")
print(f" trial: N = 3: 2.563537e-01 at (0,0,1), 26 of 27; N = 4: 2.251100e-01 at (3,0,0), 56 of 64")
# ------------------------------------------------------------------ D. springs: stability threshold and the relaxed hold
print("\nD. Springs between nearest and next-nearest finer neighbours (central, stiffness kappa) as the trial's stand-in [P]")
def spring_bonds(N):
"""(a, b, R, e): finer quon a bonded to the image of finer quon b displaced by lattice vector R; unit vector e from a to b+R."""
ax = np.arange(N) / N
fin = np.array(list(itertools.product(ax, ax, ax)))
half = [np.array(v, float) / N for v in ((1, 0, 0), (0, 1, 0), (0, 0, 1), (1, 1, 0), (1, -1, 0), (1, 0, 1), (1, 0, -1), (0, 1, 1), (0, 1, -1))]
out = []
for a, ra in enumerate(fin):
for dv in half:
rb = ra + dv
fr = rb - np.floor(rb + 1e-12)
b = int(np.argmin(np.linalg.norm(fin - fr, axis=1)))
out.append((a, b, np.round(rb - fin[b]), dv / np.linalg.norm(dv)))
return out
def phi_springs(nq, bonds, kappa, k):
P = np.zeros((3 * nq, 3 * nq), complex)
for a, b, R, e in bonds:
i, j = 1 + a, 1 + b
D = kappa * np.outer(e, e)
P[3*i:3*i+3, 3*i:3*i+3] += D
P[3*j:3*j+3, 3*j:3*j+3] += D
P[3*i:3*i+3, 3*j:3*j+3] -= D * np.exp(1j * (k @ R))
P[3*j:3*j+3, 3*i:3*i+3] -= D * np.exp(-1j * (k @ R))
return P
bonds = spring_bonds(2)
print(f" bonds per cell: {len(bonds)} (18 per finer quon, each counted once); on-site spring stiffness per direction with neighbours fixed: 6 kappa")
PE = {kn: 0.5 * (ewA.phi(pos, np.array(kv, float)) + ewA.phi(pos, np.array(kv, float)).conj().T) for kn, kv in kpts.items()}
print(" lowest eigenvalue of Phi + springs:")
print(" kappa " + " ".join(f"{kn:>13s}" for kn in kpts))
for kappa in (0.0, 1.0, 2.0, 3.0, 5.0, 10.0, 100.0, 1000.0):
row = []
for kn, kv in kpts.items():
P = PE[kn] + phi_springs(n, bonds, kappa, np.array(kv, float))
row.append(np.linalg.eigvalsh(0.5 * (P + P.conj().T))[0])
print(f" {kappa:6.0f} " + " ".join(f"{x:+.6e}" for x in row))
# threshold kappa_c over a k grid (lowest eigenvalue, zero modes at Gamma excluded)
kgrid = [np.array(v, float) for v in itertools.product(np.linspace(0, np.pi, 5), repeat=3)]
kgrid = [k for k in kgrid if np.linalg.norm(k) > 1e-9]
PK = [0.5 * (ewA.phi(pos, k) + ewA.phi(pos, k).conj().T) for k in kgrid]
def min_eig(kappa):
return min(np.linalg.eigvalsh(P + 0.5 * (phi_springs(n, bonds, kappa, k) + phi_springs(n, bonds, kappa, k).conj().T))[0] for P, k in zip(PK, kgrid))
lo, hi = 1.0, 10.0
for _ in range(40):
mid = 0.5 * (lo + hi)
if min_eig(mid) < 0:
lo = mid
else:
hi = mid
print(f" threshold for stability over a 5x5x5 k grid (Gamma excluded): kappa_c = {0.5*(lo+hi):.3f} (the trial reported kappa = 1 unstable, 10 stable)")
print(f" the largest negative electric stiffness of a finer quon's own block at these k: {min(min(np.linalg.eigvalsh(P[3*i:3*i+3, 3*i:3*i+3])[0] for i in range(2, n)) for P in PK):+.4f}")
# relaxed (static) hold: the quon against the finer grid when the grid may deform, at k -> 0 transverse (Gamma matrix, which omits the k+G = 0 term)
print("\n Relaxed hold at long wavelength: light's force q_i E on every charge; solve (Phi + springs) x = q E for the static response;")
print(" dipole per cell p = sum q_i x_i; K_relaxed = E/p (units 4 pi: divide by 4 pi); rigid-level value 4 pi K_T = 4.18879")
for kappa in (3.0, 10.0, 30.0, 100.0, 1000.0, 1e4, 1e5):
P = PG + phi_springs(n, bonds, kappa, np.zeros(3)).real
# remove the 3 zero modes (common translation) by a pseudo-inverse on the orthogonal complement
Fy = np.zeros(3 * n)
Fy[1::3] = q # E along y, unit field
x = np.linalg.lstsq(P, Fy, rcond=1e-10)[0]
p = np.sum(q * x[1::3])
Krel = 1 / p
print(f" kappa = {kappa:8.0f}: K_relaxed = {Krel:.6f} absolute = {Krel/(4*math.pi):.6f} in units of 4 pi; quons' share of light 1/(1 + K) = {1/(1 + Krel/(4*math.pi)):.4f}"
f" (rigid: {1/(1+1/3):.4f})")
# the partner's own stiffness against the quon (for the text 'springs about as stiff as the electric forces ... next to them')
blk = PG[3:6, 3:6]
print(f"\n the partner finer quon's own block at Gamma (diagonal): {np.diag(blk)}; a finer quon next to the quon: {np.diag(PG[6:9, 6:9])}")
print(f" quon-partner pair stiffness (absolute) ~ (1/8)(4 pi/3)(2 pi S^2)^-1.5 = {(1/8)*(4*math.pi/3)*(2*math.pi*(NSS/2)**2)**-1.5:.4f}")
print(f"\nrun time {time.time() - t0:.0f} s")