"""Second reader for The Theory of Everything: the reduced Hamiltonian of the collinear Euler equilibrium (declared below) expanded at the Euler equilibrium (sympy), and its quartic Birkhoff coefficient a recomputed by a Lie transform in 50-digit arithmetic (mpmath). Requires sympy (and its dependency mpmath). No files written. Prints PASS/FAIL/INFO lines and RESULT PASS|FAIL.""" from __future__ import annotations import itertools import sys import mpmath as mp import sympy as sp sys.dont_write_bytecode = True OK = True mp.mp.dps = 50 def line(label, cond): global OK OK = OK and bool(cond) print(("PASS " if cond else "FAIL ") + label) def info(label): print("INFO " + label) r, x, y, p, u, v, rho, t = sp.symbols("r x y p u v rho t", real=True) Hfull = (p**2 + u**2 + v**2) / 2 + (2 - x * v + y * u) ** 2 / (2 * r**2) - sp.Rational(4, 5) * ( 1 / (sp.sqrt(2) * r) + sp.sqrt(2) / sp.sqrt((r - sp.sqrt(3) * x) ** 2 + 3 * y**2) + sp.sqrt(2) / sp.sqrt((r + sp.sqrt(3) * x) ** 2 + 3 * y**2)) E0 = {r: sp.sqrt(2), x: 0, y: 0, p: 0, u: 0, v: 0} print("Second reader: expansion of the reduced Hamiltonian and the quartic coefficient\n") print("1. Reduced Hamiltonian at the Euler equilibrium") line("the gradient of the reduced Hamiltonian vanishes at E = (sqrt 2, 0, 0; 0, 0, 0)", all(sp.simplify(sp.diff(Hfull, w).subs(E0)) == 0 for w in (r, x, y, p, u, v))) Hs = Hfull.subs(r, sp.sqrt(2) + rho) vars6 = [rho, x, y, p, u, v] ser = sp.series(Hs.subs({w: t * w for w in vars6}, simultaneous=True), t, 0, 5).removeO() H2 = sp.expand(sp.simplify(ser.coeff(t, 2))); H3 = sp.expand(sp.simplify(ser.coeff(t, 3))); H4 = sp.expand(sp.simplify(ser.coeff(t, 4))) H2p = (p**2 + rho**2 + u**2 + v**2) / 2 + u * y - v * x - sp.Rational(12, 5) * x**2 + sp.Rational(6, 5) * y**2 H3p = sp.sqrt(2) * rho / 10 * (-5 * rho**2 - 10 * u * y + 10 * v * x + 36 * x**2 - 18 * y**2) line("quadratic part: H_2 = (p^2 + rho^2 + u^2 + v^2)/2 + u y - v x - (12/5) x^2 + (6/5) y^2 (exact)", sp.simplify(H2 - H2p) == 0) line("cubic part: H_3 = (sqrt 2 rho/10)(-5 rho^2 - 10 u y + 10 v x + 36 x^2 - 18 y^2) (exact)", sp.simplify(H3 - H3p) == 0) print("\n2. Quartic Birkhoff coefficient by Lie transform in 50-digit arithmetic") order = vars6 Hess = sp.hessian(H2p, order) J6 = sp.zeros(6, 6) for i in range(3): J6[i, i + 3] = 1; J6[i + 3, i] = -1 A6 = mp.matrix(6, 6) for i in range(6): for j in range(6): A6[i, j] = mp.mpf(sp.Rational((J6 * Hess)[i, j]).p) / mp.mpf(sp.Rational((J6 * Hess)[i, j]).q) E, P = mp.eig(A6) nu = mp.sqrt((1 + 2 * mp.sqrt(51)) / 5); kap = mp.sqrt((2 * mp.sqrt(51) - 1) / 5) want = [nu, -nu, 1j, -1j, 1j * kap, -1j * kap] pool = list(E) matched = True for w_ in want: j_ = min(range(len(pool)), key=lambda q: abs(pool[q] - w_)) matched &= abs(pool[j_] - w_) < mp.mpf(10) ** -40 pool.pop(j_) line("eigenvalues of the linearization are +/- nu, +/- i, +/- i kappa with nu^2 = (1 + 2 sqrt 51)/5, kappa^2 = (2 sqrt 51 - 1)/5 (each matched one-to-one to 1e-40)", matched and not pool) idx_nu = min(range(6), key=lambda i: abs(E[i] - nu)); idx_mnu = min(range(6), key=lambda i: abs(E[i] + nu)) Jm = mp.matrix(6, 6) for i in range(3): Jm[i, i + 3] = 1; Jm[i + 3, i] = -1 Pcols = [P[:, i] for i in range(6)] def omega(a, b): return (a.T * Jm * b)[0] cxi = omega(Pcols[idx_nu], Pcols[idx_mnu]) Pcols[idx_mnu] = Pcols[idx_mnu] / cxi # {xi, eta} = 1 after normalization for i in range(6): P[:, i] = Pcols[i] Pinv = P ** -1 Pi = Pinv * Jm * Pinv.T # {w_i, w_j} lam = [E[i] for i in range(6)] line("hyperbolic pair normalized: {xi, eta} = 1 with xi' = nu xi and eta' = -nu eta; the hyperbolic coordinates are Poisson-orthogonal to the center coordinates", abs(Pi[idx_nu, idx_mnu] - 1) < mp.mpf(10) ** -40 or abs(Pi[idx_nu, idx_mnu] + 1) < mp.mpf(10) ** -40) if abs(Pi[idx_nu, idx_mnu] + 1) < mp.mpf(10) ** -40: info("the sign of the pairing was -1 for this eigenvector order; the coefficient of (xi eta)^2 is unchanged under xi <-> eta") wsym = sp.symbols("w0:6") Pn = sp.Matrix(6, 6, lambda i, j: sp.Float(mp.re(P[i, j]), 50) + sp.I * sp.Float(mp.im(P[i, j]), 50)) zsub = Pn * sp.Matrix(wsym) def to_w(poly): return sp.Poly(sp.expand(poly.subs({vars6[i]: zsub[i] for i in range(6)}, simultaneous=True)), *wsym) H3w = to_w(H3.evalf(50)) H4w = to_w(H4.evalf(50)) Pis = sp.Matrix(6, 6, lambda i, j: sp.Float(mp.re(Pi[i, j]), 50) + sp.I * sp.Float(mp.im(Pi[i, j]), 50)) lam_s = [sp.Float(mp.re(l), 50) + sp.I * sp.Float(mp.im(l), 50) for l in lam] tol = sp.Float(10) ** -35 W3 = {} min_res = None for mon, c in H3w.terms(): if abs(c) < tol: continue d = sum(m * l for m, l in zip(mon, lam_s)) min_res = abs(d) if min_res is None else min(min_res, abs(d)) W3[mon] = c / d W3p = sp.Poly(sum(c * sp.prod([w**m for w, m in zip(wsym, mon)]) for mon, c in W3.items()), *wsym) line("no cubic monomial is resonant: the smallest |m . lambda| over the monomials of H_3 in eigen-coordinates is bounded away from zero", min_res is not None and min_res > sp.Float(10) ** -3) def pb(f, g): out = 0 for i in range(6): for j in range(6): if abs(Pis[i, j]) > tol: out += Pis[i, j] * f.diff(wsym[i]).as_expr() * g.diff(wsym[j]).as_expr() return sp.Poly(sp.expand(out), *wsym) K4 = pb(H3w, W3p) ix = {n: i for i, n in enumerate(order)} ixi, ieta = idx_nu, idx_mnu mon = [0] * 6; mon[ixi] = 2; mon[ieta] = 2; mon = tuple(mon) a_direct = H4w.coeff_monomial(mon); a_cub = K4.coeff_monomial(mon) / 2 to_mp = lambda z: mp.mpc(mp.mpf(str(sp.re(z))), mp.mpf(str(sp.im(z)))) a_direct = to_mp(a_direct); a_cub = to_mp(a_cub) a_closed = -(82891803 + 215881566 * mp.sqrt(51)) / 585841760 print("INFO computed a_direct =", mp.nstr(a_direct.real, 30), " a_cubic =", mp.nstr(a_cub.real, 30), " a =", mp.nstr((a_direct + a_cub).real, 30), " closed form =", mp.nstr(a_closed, 30)) tolp = mp.mpf(10) ** -30 line("a_direct = -1.547622997565423... (coefficient of xi^2 eta^2 in H_4), agreement with the printed value to 1e-15 and zero imaginary part to 1e-30", abs(a_direct.real - mp.mpf("-1.547622997565423")) < mp.mpf(10) ** -15 and abs(a_direct.imag) < tolp) line("a_cubic = -1.225471490664213... (one half of the bracket {H_3, W_3}), agreement with the printed value to 1e-15 and zero imaginary part to 1e-30", abs(a_cub.real - mp.mpf("-1.225471490664213")) < mp.mpf(10) ** -15 and abs(a_cub.imag) < tolp) line("a = a_direct + a_cubic equals -(82891803 + 215881566 sqrt 51)/585841760 evaluated in 50 digits, to 1e-30 (a numerical match of the closed form stated in the text, not a symbolic proof)", abs((a_direct + a_cub).real - a_closed) < tolp and abs((a_direct + a_cub).imag) < tolp) info("this reader reproduces a by an independent Lie transform in 50-digit arithmetic; the closed form stated in the text is matched numerically and not proved symbolically") print("\nRESULT " + ("PASS" if OK else "FAIL")) sys.exit(0 if OK else 1)