#!/usr/bin/env python3 """Radial harmonics and Poisson extension for the three real spheres. Python 3, standard library only. Keep coltrane.py in the same directory. Examples: python3 mozart.py python3 mozart.py --dimension 4 --degree 20 --radius 0.8 python3 mozart.py --check python3 mozart.py --tikz The positive spherical Laplacian has eigenvalues lambda_k, lambda_1=1. The boundary normal derivative has eigenvalues alpha_k, with alpha_k*(alpha_k+N-2)=(N-1)*lambda_k. Harmonic extension multiplies angular degree k by radius**alpha_k. These are radial decay exponents; wave frequencies, computed by coltrane.py, are sqrt(lambda_k). """ import argparse from math import exp, isclose, pi, sqrt from pathlib import Path import sys # Some managed Python runtimes omit the script directory from sys.path. sys.path.insert(0, str(Path(__file__).resolve().parent)) from coltrane import spectra NAMES = ('classical', 'half', 'free') def exponent(n, eigenvalue): """Positive root, rationalized to avoid cancellation near zero.""" if eigenvalue == 0: return 0.0 value = (n - 1) * float(eigenvalue) return 2 * value / (sqrt((n - 2) ** 2 + 4 * value) + n - 2) def integrate(f, left, right, tolerance=2e-11, depth=26): """Adaptive Simpson quadrature; raise if the error budget is exhausted.""" def refine(a, b, fa, fm, fb, estimate, tol, remaining): middle = (a + b) / 2 fl = f((a + middle) / 2) fr = f((middle + b) / 2) left_value = (middle - a) * (fa + 4 * fl + fm) / 6 right_value = (b - middle) * (fm + 4 * fr + fb) / 6 correction = left_value + right_value - estimate if abs(correction) <= 15 * tol: return left_value + right_value + correction / 15 if remaining == 0: raise ArithmeticError('Quadrature did not reach its requested tolerance') return (refine(a, middle, fa, fl, fm, left_value, tol / 2, remaining - 1) + refine(middle, b, fm, fr, fb, right_value, tol / 2, remaining - 1)) middle = (left + right) / 2 fa, fm, fb = f(left), f(middle), f(right) estimate = (right - left) * (fa + 4 * fm + fb) / 6 return refine(left, right, fa, fm, fb, estimate, tolerance, depth) def subordinated(n, eigenvalue, time): """Numerically integrate the positive heat mixture, after v=t^2/(4z^2).""" b = (n - 2) / 2 coefficient = (b * b + (n - 1) * float(eigenvalue)) * time * time / 4 def integrand(z): if z == 0: return exp(b * time) if coefficient == 0 else 0.0 return exp(b * time - z * z - coefficient / (z * z)) # At the test parameters the omitted Gaussian tail beyond 12 is < 1e-60. return 2 / sqrt(pi) * integrate(integrand, 0, 12) def radial_energy(n, eigenvalue, alpha, perturbation=0.0): """Integrate the energy of v(r)=r^alpha*(1+epsilon*(1-r)), k >= 1.""" if alpha < 1: raise ValueError('This numerical energy test uses positive angular degrees') def integrand(radius): factor = 1 + perturbation * (1 - radius) derivative_factor = alpha * factor - perturbation * radius return n * radius ** (n + 2 * alpha - 3) * ( derivative_factor ** 2 + (n - 1) * float(eigenvalue) * factor ** 2) return integrate(integrand, 0, 1) def check(): count = 0 for n in (2, 3, 5): rows = spectra(n, 24) for kind, row in zip(NAMES, rows): for k, eigenvalue in enumerate(row): alpha = exponent(n, eigenvalue) assert isclose(alpha * (alpha + n - 2), (n - 1) * float(eigenvalue), rel_tol=4e-14, abs_tol=4e-14) if kind == 'classical' or k <= 2: assert isclose(alpha, k, abs_tol=3e-14) count += 1 for k in (0, 1, 3, 8): alpha = exponent(n, row[k]) for time in (0.2, 0.8): actual = subordinated(n, row[k], time) expected = exp(-time * alpha) assert isclose(actual, expected, rel_tol=2e-8, abs_tol=3e-10), ( n, kind, k, time, actual, expected) count += 1 for k in (1, 3, 8): alpha = exponent(n, row[k]) minimum = radial_energy(n, row[k], alpha) assert isclose(minimum, n * alpha, rel_tol=3e-10, abs_tol=3e-10) for epsilon in (-0.4, 0.7): perturbed = radial_energy(n, row[k], alpha, epsilon) defect = integrate(lambda r: n * epsilon ** 2 * r ** (n + 2 * alpha - 1), 0, 1) assert defect > 0 assert isclose(perturbed - minimum, defect, rel_tol=2e-8, abs_tol=3e-10) count += 1 assert 2 < exponent(n, rows[1][3]) < 3 assert exponent(n, rows[1][3]) == exponent(n, rows[2][3]) for k in range(4, 25): assert exponent(n, rows[2][k]) <= exponent(n, rows[1][k]) < k print(f'{count} checks passed: roots, heat subordination, and radial energy.') print('Numerical checks support the implementation; proofs are in Section 6.') def tikz(): """Reproduce the manuscript's degree-eight radial attenuation figure.""" rows = spectra(3, 8) print(r'\begin{tikzpicture}[x=10cm,y=4.2cm,font=\small]') print(r'\draw[->] (0,0)--(1.06,0) node[right] {$\rho$};') print(r'\draw[->] (0,0)--(0,1.10) node[above] {$\rho^{\alpha_8}$};') print(r'\foreach \x in {.25,.5,.75,1} {\draw (\x,0)--(\x,-.018) node[below] {$\x$};}') print(r'\foreach \y in {.5,1} {\draw (0,\y)--(-.008,\y) node[left] {$\y$};}') for row, style in zip(rows, ('black,dashed', 'blue!65!black,densely dotted', 'magenta!80!black')): alpha = exponent(3, row[8]) points = ' '.join(f'({i/40:.3f},{(i/40)**alpha:.6f})' for i in range(41)) print(r'\draw[' + style + r',line width=.9pt] plot coordinates {' + points + '};') for y, style, label in ((.9, 'black,dashed', 'Classical'), (.77, 'blue!65!black,densely dotted', 'Half-liberated'), (.64, 'magenta!80!black', 'Free')): print(r'\draw[' + style + ',line width=.9pt] (.12,' + str(y) + ')--(.20,' + str(y) + ');') print(r'\node[anchor=west] at (.22,' + str(y) + ') {' + label + '};') print(r'\end{tikzpicture}') def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--dimension', type=int, default=3, metavar='N') parser.add_argument('--degree', type=int, default=12, metavar='K') parser.add_argument('--radius', type=float, default=0.75) parser.add_argument('--check', action='store_true') parser.add_argument('--tikz', action='store_true') args = parser.parse_args() if args.dimension < 2 or args.degree < 1 or not 0 <= args.radius <= 1: parser.error('Need N >= 2, K >= 1, and radius between 0 and 1') if args.check: check() return if args.tikz: tikz() return rows = spectra(args.dimension, args.degree) print(f'N={args.dimension}; radius={args.radius}; alpha_k are boundary eigenvalues') print('degree,geometry,lambda,alpha,radial_attenuation') for k in range(args.degree + 1): for kind, row in zip(NAMES, rows): alpha = exponent(args.dimension, row[k]) attenuation = args.radius ** alpha if k else 1.0 print(f'{k},{kind},{row[k]},{alpha:.12f},{attenuation:.12f}') if __name__ == '__main__': main()