Does light charge the quons? › Files cited on the page › check_reflection_fable/

check_pball.py

In the investigation at sim/charge_wave/check_reflection_fable/check_pball.py · last changed in commit 87fc6d0, 12 November 2026 · 1,709 bytes · the folder as a zip


"""check_pball.py - the share of a 3D isotropic Gaussian (rms s per axis, centre at distance r0 from a ball's centre) inside a
ball of radius a: the trial's closed form against direct numerical quadrature (own derivation: integrate the Gaussian over the
ball in spherical coordinates about the ball's centre; the angular integral is analytic)."""
import math
import numpy as np
from scipy.special import erf
from scipy.integrate import quad

def p_closed(r0, a, s):
    r0 = max(r0, 1e-12)
    t1 = 0.5 * (erf((a - r0) / (math.sqrt(2) * s)) + erf((a + r0) / (math.sqrt(2) * s)))
    t2 = s / (r0 * math.sqrt(2 * math.pi)) * (math.exp(-(a - r0) ** 2 / (2 * s * s)) - math.exp(-(a + r0) ** 2 / (2 * s * s)))
    return t1 - t2

def p_quad(r0, a, s):
    # density (2 pi s^2)^-3/2 exp(-|r - r0 e_z|^2/(2 s^2)); shell at radius r: angular integral over cos(theta) analytic
    norm = (2 * math.pi * s * s) ** -1.5
    def shell(r):
        if r0 < 1e-12:
            return 4 * math.pi * r * r * norm * math.exp(-r * r / (2 * s * s))
        # int_{-1}^{1} exp(-(r^2 + r0^2 - 2 r r0 mu)/(2 s^2)) dmu = exp(-(r^2+r0^2)/(2s^2)) * (s^2/(r r0)) * 2 sinh(r r0/s^2)
        return 2 * math.pi * r * r * norm * math.exp(-(r * r + r0 * r0) / (2 * s * s)) * (s * s / (r * r0)) * 2 * math.sinh(r * r0 / (s * s))
    return quad(shell, 0, a, limit=200)[0]

print("   r0      a       s        closed form        quadrature         diff")
for r0, a, s in [(0.0, 0.1, 0.02), (0.05, 0.1, 0.02), (0.09, 0.1, 0.02), (0.12, 0.1, 0.02), (0.25, 0.15, 0.0125), (0.0, 0.025, 0.005), (0.3, 0.2, 0.05)]:
    c, qd = p_closed(r0, a, s), p_quad(r0, a, s)
    print(f"  {r0:.3f}  {a:.3f}  {s:.4f}   {c:.12f}   {qd:.12f}   {abs(c-qd):.1e}")