Does light charge the quons? › Files cited on the page › check_questions_fable/
check_springs.py
"""check_springs.py - eighth independent reviewer's own check of the springs statements in section 9.1 of Charging_quons
draft 0.14: "springs ... had to be stiffer than 2.2 (in the trial's units) for the grid to be stable, and much stiffer to leave
the hold unchanged: at 10, the quons' share rose from 75% to 79%".
Trial 5's N = 2 stack: one quon (Gaussian charge +1, rms s1 per axis) at the origin of a unit cubic cell and eight finer quons
(Gaussian, -1/8 each, rms s2 = 0.05) at (i, j, l)/2; s1 chosen so that the rigid hold is 1/3 (N S* = 0.32169013, trial 5 R2a).
Own Ewald code for Gaussian charges: pair energy q_i q_j erf(r/b_ij)/r, b_ij = sqrt(2 (s_i^2 + s_j^2)); the force-constant
(Bloch) matrix Phi(k) with the k + G = 0 term omitted (the transverse long-wave limit, as trial 5); springs of stiffness kappa
between nearest and next-nearest finer neighbours (central, at rest length). Checks: eta independence; the rigid two-body hold
(expected 1/3); the lowest eigenvalue and the count of negative ones at Gamma against trial 5 (-5.708082, 12 of 27); then the
relaxed static hold at Gamma for several kappa, and the stability threshold kappa_c over the k points this seat used.
Run: ~/aspden-review-venv/bin/python3 check_springs.py > check_springs_out.txt 2> check_springs_err.txt
"""
import itertools, math, time
import numpy as np
from scipy.optimize import brentq
from scipy.special import erf
T0 = time.time()
SQPI = math.sqrt(math.pi)
S2 = 0.05
NSS = 0.32169013 # N S* (trial 5 R2a): combined width S* = NSS/N with N = 2
S1 = math.sqrt((NSS / 2) ** 2 - S2 ** 2)
POS = np.array([[0.0, 0.0, 0.0]] + [[i / 2, j / 2, l / 2] for i in (0, 1) for j in (0, 1) for l in (0, 1)])
Q = np.array([1.0] + [-1 / 8] * 8)
SIG = np.array([S1] + [S2] * 8)
NCH = len(Q)
RCELLS = np.array(list(itertools.product(range(-4, 5), repeat=3)), float)
GVECS = 2 * math.pi * np.array(list(itertools.product(range(-9, 10), repeat=3)), float)
def hess_real(D, b, eta):
"""Hessian of [erf(r/b) - erf(eta r)]/r at the vectors D (n x 3); regular at r = 0 (the limit is taken analytically)."""
r = np.linalg.norm(D, axis=1)
small = r < 1e-9
rs = np.where(small, 1.0, r)
def f_and_derivs(c):
# g(r) = erf(c r)/r: g', g'' in terms of r
e = np.exp(-(c * rs) ** 2)
g = erf(c * rs) / rs
g1 = 2 * c / SQPI * e / rs - g / rs
g2 = -4 * c ** 3 / SQPI * e - 2 * (2 * c / SQPI * e) / rs ** 2 + 2 * g / rs ** 2
return g1, g2
ga1, ga2 = f_and_derivs(1 / b)
gb1, gb2 = f_and_derivs(eta)
f1, f2 = ga1 - gb1, ga2 - gb2
n = D / rs[:, None]
H = np.einsum("n,ni,nj->nij", f2 - f1 / rs, n, n) + (f1 / rs)[:, None, None] * np.eye(3)[None]
# r -> 0 limit of the Hessian of erf(c r)/r: -(4 c^3/(3 sqrt(pi))) I
H[small] = (-(4 / (3 * SQPI)) * ((1 / b) ** 3 - eta ** 3)) * np.eye(3)[None]
return H
def phi_bloch(k, eta, springs=0.0):
"""Force-constant matrix Phi(k) (27 x 27, complex Hermitian) of the stack: Phi_ij = d2E/dx_i dx_j with Bloch phases."""
k = np.asarray(k, float)
Phi = np.zeros((3 * NCH, 3 * NCH), complex)
# pair blocks i != j (and the self-image terms for i == j, R != 0) in real space
for i in range(NCH):
for j in range(NCH):
b = math.sqrt(2 * (SIG[i] ** 2 + SIG[j] ** 2))
D = POS[i] - POS[j] + RCELLS
if i == j:
keep = np.linalg.norm(RCELLS, axis=1) > 1e-9
D, ph = D[keep], np.exp(-1j * RCELLS[keep] @ k) # D = r_i - (r_j - R): the partner sits in cell -R
else:
ph = np.exp(-1j * RCELLS @ k)
H = hess_real(D, b, eta) # Hessian of the pair potential wrt r = r_i - r_j + R
blk = -Q[i] * Q[j] * np.einsum("n,nij->ij", ph, H) # off-diagonal force constant: -q_i q_j sum_R H e^{ik.R}
Phi[3 * i:3 * i + 3, 3 * j:3 * j + 3] += blk
# reciprocal part of erf(eta r)/r: 4 pi exp(-|k+G|^2/4 eta^2)/|k+G|^2 e^{i (k+G).(r_i - r_j)}; the Hessian brings -(k+G)(k+G)^T
KG = GVECS + k
kg2 = (KG ** 2).sum(1)
keep = kg2 > 1e-12 # the k + G = 0 term omitted
KG, kg2 = KG[keep], kg2[keep]
w = 4 * math.pi * np.exp(-kg2 / (4 * eta ** 2)) / kg2
for i in range(NCH):
for j in range(NCH):
ph = np.exp(1j * KG @ (POS[i] - POS[j]))
blk = Q[i] * Q[j] * np.einsum("n,ni,nj->ij", w * ph, KG, KG) # -q_i q_j H[recip], H[recip] = -sum w KG KG^T cos
Phi[3 * i:3 * i + 3, 3 * j:3 * j + 3] += blk
# diagonal blocks: translation invariance, Phi_ii = -sum_{j != i} Phi_ij(k = 0) for the on-site part ... done properly:
# the on-site force constant of charge i is -(sum over all other charges and all images of the pair Hessian at k = 0),
# which equals minus the row sum of the k = 0 off-diagonal blocks (including its own images). Build it from the k = 0 blocks.
if not hasattr(phi_bloch, "_onsite") or phi_bloch._onsite[0] != eta:
P0 = np.zeros((3 * NCH, 3 * NCH))
for i in range(NCH):
for j in range(NCH):
b = math.sqrt(2 * (SIG[i] ** 2 + SIG[j] ** 2))
D = POS[i] - POS[j] + RCELLS
if i == j:
D = D[np.linalg.norm(RCELLS, axis=1) > 1e-9]
P0[3 * i:3 * i + 3, 3 * j:3 * j + 3] += -Q[i] * Q[j] * hess_real(D, b, eta).sum(0)
G = GVECS[(GVECS ** 2).sum(1) > 1e-12]
g2 = (G ** 2).sum(1)
w0 = 4 * math.pi * np.exp(-g2 / (4 * eta ** 2)) / g2
for i in range(NCH):
for j in range(NCH):
c = np.cos(G @ (POS[i] - POS[j]))
P0[3 * i:3 * i + 3, 3 * j:3 * j + 3] += Q[i] * Q[j] * np.einsum("n,ni,nj->ij", w0 * c, G, G)
onsite = np.zeros((NCH, 3, 3))
for i in range(NCH):
onsite[i] = -sum(P0[3 * i:3 * i + 3, 3 * j:3 * j + 3] for j in range(NCH))
phi_bloch._onsite = (eta, onsite)
for i in range(NCH):
Phi[3 * i:3 * i + 3, 3 * i:3 * i + 3] += phi_bloch._onsite[1][i]
if springs:
Phi += spring_matrix(k) * springs
return 0.5 * (Phi + Phi.conj().T)
def spring_bonds():
"""Nearest (1/2) and next-nearest (sqrt 2 / 2) bonds between finer quons, each once: (i, j, image offset R)."""
bonds = []
fin = range(1, NCH)
for i in fin:
for j in fin:
for R in itertools.product((-1, 0, 1), repeat=3):
dvec = POS[j] + np.array(R, float) - POS[i]
L = np.linalg.norm(dvec)
if abs(L - 0.5) < 1e-9 or abs(L - math.sqrt(2) / 2) < 1e-9:
key = (min(i, j), max(i, j), tuple(np.sign(j - i) * np.array(R)) if i != j else tuple(R))
bonds.append((i, j, np.array(R, float), dvec / L))
# each bond appears twice (i->j with R and j->i with -R); keep one of each pair
seen, out = set(), []
for i, j, R, n in bonds:
key = (i, j, tuple(R.astype(int)))
rev = (j, i, tuple((-R).astype(int)))
if rev in seen or key in seen:
continue
seen.add(key)
out.append((i, j, R, n))
return out
BONDS = spring_bonds()
def spring_matrix(k):
S = np.zeros((3 * NCH, 3 * NCH), complex)
for i, j, R, n in BONDS:
nn = np.outer(n, n)
ph = np.exp(1j * (R @ k)) # j sits in the cell at R relative to i
S[3 * i:3 * i + 3, 3 * i:3 * i + 3] += nn
S[3 * j:3 * j + 3, 3 * j:3 * j + 3] += nn
S[3 * i:3 * i + 3, 3 * j:3 * j + 3] -= nn * ph
S[3 * j:3 * j + 3, 3 * i:3 * i + 3] -= nn * np.conj(ph)
return S
print("Eighth reviewer: the springs in trial 5's N = 2 stack, with Ewald code of my own")
print(f" s1 = {S1:.6f}, s2 = {S2}, N S* = {NSS}; {len(BONDS)} bonds per cell (expected 72)")
# ---- checks ----
G0 = {eta: phi_bloch(np.zeros(3), eta) for eta in (1.8, 2.6)}
lam = {eta: np.linalg.eigvalsh(G0[eta]) for eta in G0}
print(f" eta independence at Gamma: largest eigenvalue difference {np.max(np.abs(lam[1.8] - lam[2.6])):.1e} of sum|lambda| = {np.sum(np.abs(lam[2.6])):.3f}")
print(f" Gamma, kappa = 0: lowest eigenvalue {lam[2.6][0]:+.6f} (trial 5: -5.708082), negatives {int(np.sum(lam[2.6] < -1e-9))} of 27 (trial 5: 12), "
f"zero modes {int(np.sum(np.abs(lam[2.6]) < 1e-8))} (expected 3)")
tr = np.trace(G0[2.6]).real
print(f" trace of Phi(Gamma) = {tr:.6f}")
PG = G0[2.6].real
fE = np.zeros(3 * NCH); fE[0::3] = Q # the force q_i E on each charge, E = 1 along x
B2 = np.zeros((3 * NCH, 2)); B2[0, 0] = 1.0; B2[3::3, 1] = 1.0
x2 = np.linalg.lstsq(B2.T @ PG @ B2, B2.T @ fE, rcond=None)[0]
p2 = x2[0] * Q[0] + x2[1] * Q[1:].sum()
print(f" rigid two-body hold (quon against the whole grid): K_T = 1/(4 pi p) = {1/(4*math.pi*p2):.6f} (expected 1/3)")
for kn, kv in (("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))):
l = np.linalg.eigvalsh(phi_bloch(np.array(kv, float), 2.6))
print(f" {kn:14s} kappa = 0: lowest {l[0]:+.6f}, highest {l[-1]:+.6f}, negatives {int(np.sum(l < -1e-9))} of 27")
print(" (trial 5 R3: X -5.735751/+24.35233/13; M -5.761732/+18.43264/13; R -3.517366/+16.42437/12; general -5.644361/+22.71650/12)")
# ---- the relaxed hold at Gamma ----
print("\nThe hold when the grid deforms under light's force (static response at Gamma, x = (Phi + kappa S)^+ q E, p = sum q_i x_i):")
print(" kappa K_T relaxed quons' share 1/(1 + K_T)")
SG = spring_matrix(np.zeros(3)).real
for kappa in (1000.0, 300.0, 100.0, 30.0, 10.0, 5.0, 3.0, 2.5):
x = np.linalg.lstsq(PG + kappa * SG, fE, rcond=1e-12)[0]
p = Q @ x[0::3]
K = 1 / (4 * math.pi * p)
print(f" {kappa:7.1f} {K:+.6f} {1/(1+K):.4f}")
print(" (section 9.1: at kappa = 10 the share rises from 75% to 79%; this seat's check: 0.2665 and 0.7896)")
# ---- the stability threshold ----
kpts = [2 * math.pi * np.array(ijk, float) / 5 for ijk in [(i, j, l) for i in range(3) for j in range(i, 3) for l in range(j, 3)]]
kpts += [np.array([math.pi, 0, 0]), np.array([math.pi, math.pi, 0]), np.array([math.pi] * 3), np.array([0.3, 0.7, 1.1])]
PE = [phi_bloch(kv, 2.6) for kv in kpts]
SE = [spring_matrix(kv) for kv in kpts]
def lowest(kappa):
worst = np.inf
for kv, P, S in zip(kpts, PE, SE):
l = np.linalg.eigvalsh(P + kappa * S)
if np.linalg.norm(kv) < 1e-12:
l = l[3:]
worst = min(worst, l[0])
return worst
for kappa in (1.0, 2.0, 2.5, 3.0, 10.0, 1000.0):
print(f" kappa = {kappa:6.1f}: lowest eigenvalue over the k points {lowest(kappa):+.4e}")
kc = brentq(lowest, 1.0, 10.0, xtol=1e-6)
print(f" threshold kappa_c = {kc:.4f} (section 9.1: 2.2; this seat's check 2.1632; the seventh reviewer 2.16); on-site 6 kappa_c = {6*kc:.2f}")
print(f"\nrun time {time.time() - T0:.0f} s")