#!/usr/bin/env python3 """ Independent Mathematical Verification Suite The Neon Spacetime & Relativity Planetarium ------------------------------------------- Zero external dependencies (Python 3 standard library only). Verifies all 5 interactive chambers across 25 exact checks: Suite 1: Minkowski Spacetime, SO+(1,1) Lorentz Group & Twin Paradox Suite 2: Schwarzschild Black Hole, Photon Sphere & Gravitational Lensing Suite 3: Rotating Kerr Black Hole, Ergosphere & Penrose Extraction Suite 4: Gravitational Waves (h+/hx), Peters-Mathews Inspiral & LIGO Chirp Suite 5: FLRW Expanding Universe, Cosmic Horizons & Redshift """ import math import sys PASSED = 0 FAILED = 0 def check(name, cond, detail=""): global PASSED, FAILED if cond: PASSED += 1 print(f" [PASS] {name}" + (f" :: {detail}" if detail else "")) else: FAILED += 1 print(f" [FAIL] {name}" + (f" :: {detail}" if detail else "")) def simpson(f, a, b, n=2000): if n % 2 == 1: n += 1 h = (b - a) / n s = f(a) + f(b) for i in range(1, n): s += (4.0 if i % 2 == 1 else 2.0) * f(a + i * h) return s * h / 3.0 # ============================================================================ # SUITE 1: MINKOWSKI SPACETIME, LORENTZ BOOSTS & TWIN PARADOX # ============================================================================ def verify_suite_1(): print("\n=== SUITE 1: Minkowski Spacetime, Lorentz Boosts & Twin Paradox ===") def lorentz_matrix(beta): g = 1.0 / math.sqrt(1.0 - beta * beta) return ((g, -g * beta), (-g * beta, g)) def mat_mul(A, B): return ( (A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]), (A[1][0] * B[0][0] + A[1][1] * B[1][0], A[1][0] * B[0][1] + A[1][1] * B[1][1]), ) def mat_T(A): return ((A[0][0], A[1][0]), (A[0][1], A[1][1])) eta = ((1.0, 0.0), (0.0, -1.0)) # 1.1 Metric invariance Lambda^T eta Lambda = eta max_eta_err = 0.0 for beta in (-0.95, -0.8, -0.6, 0.0, 0.35, 0.75, 0.95): L = lorentz_matrix(beta) prod = mat_mul(mat_mul(mat_T(L), eta), L) for i in range(2): for j in range(2): max_eta_err = max(max_eta_err, abs(prod[i][j] - eta[i][j])) check("1.1 Lorentz metric invariance (Lambda^T eta Lambda = eta)", max_eta_err < 1e-13, f"max_err = {max_eta_err:.3e}") # 1.2 Velocity addition & rapidity group homomorphism max_comp_err = 0.0 max_rap_err = 0.0 pairs = [(0.6, 0.6), (0.8, -0.5), (-0.75, 0.9), (0.9, 0.9)] for b1, b2 in pairs: b12 = (b1 + b2) / (1.0 + b1 * b2) b12_rap = math.tanh(math.atanh(b1) + math.atanh(b2)) max_rap_err = max(max_rap_err, abs(b12 - b12_rap)) Lprod = mat_mul(lorentz_matrix(b1), lorentz_matrix(b2)) Lcomp = lorentz_matrix(b12) for i in range(2): for j in range(2): max_comp_err = max(max_comp_err, abs(Lprod[i][j] - Lcomp[i][j])) check("1.2 Einstein velocity addition & rapidity additivity", max_comp_err < 1e-13 and max_rap_err < 1e-14, f"mat_err = {max_comp_err:.3e}, rap_err = {max_rap_err:.3e}") # 1.3 Spacetime interval s^2 = t^2 - x^2 invariance (timelike, null, spacelike) vectors = [(5.0, 3.0), (4.0, 4.0), (2.0, 7.0), (-6.0, 2.5)] max_int_err = 0.0 for beta in (-0.85, 0.6, 0.92): L = lorentz_matrix(beta) for t, x in vectors: s2 = t * t - x * x tp = L[0][0] * t + L[0][1] * x xp = L[1][0] * t + L[1][1] * x max_int_err = max(max_int_err, abs((tp * tp - xp * xp) - s2)) check("1.3 Spacetime interval s^2 = t^2 - x^2 invariance", max_int_err < 1e-12, f"max_err = {max_int_err:.3e}") # 1.4 Bondi k-calculus Twin Paradox exact accounting # Stay twin A spans t in [0, 2T]; traveler B goes out at +v and back at -v T = 5.0 max_bondi_err = 0.0 for v in (0.3, 0.6, 0.8, 0.95): gamma = 1.0 / math.sqrt(1.0 - v * v) k = math.sqrt((1.0 + v) / (1.0 - v)) tau_half = T / gamma # traveler proper time per leg # Pulses per unit proper time = 1. # B receives from A: tau_half/k outbound + tau_half*k inbound n_A_to_B = tau_half / k + tau_half * k # A receives from B: B sends 2*tau_half pulses; A receives first half over k*tau_half, second over tau_half/k t_A_span = k * tau_half + tau_half / k ratio = (2.0 * tau_half) / (2.0 * T) max_bondi_err = max( max_bondi_err, abs(n_A_to_B - 2.0 * T), abs(t_A_span - 2.0 * T), abs(ratio - 1.0 / gamma), ) check("1.4 Bondi k-calculus Twin Paradox pulse & proper-time identity", max_bondi_err < 1e-13, f"max_err = {max_bondi_err:.3e}") # 1.5 Reverse Triangle Inequality on smooth curved worldline x(t) = A sin(pi t / T) # Inertial geodesic maximizes proper time: tau_curved < tau_inertial = T T_curve = 10.0 A = 2.4 # v_max = pi*A/T = 0.75398 < 1 tau_curved = simpson( lambda t: math.sqrt(1.0 - (A * (math.pi / T_curve) * math.cos(math.pi * t / T_curve)) ** 2), 0.0, T_curve, 4000 ) # Compare with midpoint-piecewise triangle leg (strictly shorter than inertial, distinct from sine) # Exact complete elliptic integral E(k) relation: tau_curved = (2*T/pi) * E(v_max) vmax = A * math.pi / T_curve ellip_E = simpson(lambda th: math.sqrt(1.0 - (vmax * math.sin(th)) ** 2), 0.0, math.pi / 2.0, 4000) tau_ellip = (2.0 * T_curve / math.pi) * ellip_E check("1.5 Reverse Triangle Inequality (smooth curved worldline vs inertial)", tau_curved < T_curve and abs(tau_curved - tau_ellip) < 1e-12, f"tau_curved = {tau_curved:.9f} < T = {T_curve:.1f}, ellip_err = {abs(tau_curved - tau_ellip):.3e}") # ============================================================================ # SUITE 2: SCHWARZSCHILD BLACK HOLE, PHOTON SPHERE & GRAVITATIONAL LENSING # ============================================================================ def verify_suite_2(): print("\n=== SUITE 2: Schwarzschild Black Hole, Photon Sphere & Gravitational Lensing ===") M = 1.0 b_c = 3.0 * math.sqrt(3.0) * M def trace_null_geodesic(b, r_start=120.0, dphi=0.001, max_steps=60000): """Integrate u''(phi) + u = 3 M u^2 with RK4 from incoming asymptote.""" u = 1.0 / r_start # Exact first integral: (du/dphi)^2 = 1/b^2 - u^2 (1 - 2 M u) disc = 1.0 / (b * b) - u * u * (1.0 - 2.0 * M * u) du = math.sqrt(max(0.0, disc)) phi = math.asin(min(1.0, b / r_start)) u_max = u captured = False for _ in range(max_steps): def f(u_val, du_val): return du_val, 3.0 * M * u_val * u_val - u_val k1u, k1v = f(u, du) k2u, k2v = f(u + 0.5 * dphi * k1u, du + 0.5 * dphi * k1v) k3u, k3v = f(u + 0.5 * dphi * k2u, du + 0.5 * dphi * k2v) k4u, k4v = f(u + dphi * k3u, du + dphi * k3v) u_next = u + (dphi / 6.0) * (k1u + 2.0 * k2u + 2.0 * k3u + k4u) du_next = du + (dphi / 6.0) * (k1v + 2.0 * k2v + 2.0 * k3v + k4v) phi_next = phi + dphi if u_next > u_max: u_max = u_next if u_next >= 0.5 / M: # crossed event horizon r <= 2M captured = True return captured, phi_next, u_max if du_next < 0.0 and u_next <= 0.0: # Linear interpolate exact u=0 root frac = u / (u - u_next) phi_inf = phi + frac * dphi return False, phi_inf - math.pi, u_max u, du, phi = u_next, du_next, phi_next return captured, phi - math.pi, u_max # 2.1 Critical impact parameter b_c = 3*sqrt(3)*M photon sphere capture/escape cap_in, _, _ = trace_null_geodesic(b_c * (1.0 - 1e-5), r_start=80.0, dphi=0.001) cap_out, dphi_crit, umax_crit = trace_null_geodesic(b_c * (1.0 + 1e-5), r_start=80.0, dphi=0.0005) check("2.1 Photon sphere critical threshold b_c = 3*sqrt(3)*M", cap_in and (not cap_out) and dphi_crit > 2.0 * math.pi and abs(1.0 / umax_crit - 3.0) < 0.02, f"b_c={b_c:.6f}, inside->captured={cap_in}, outside->deflection={dphi_crit:.3f} rad (>2pi), r_min={1/umax_crit:.5f}M") # 2.2 Turning-point cubic r_min^3 - b^2 r_min + 2 M b^2 = 0 vs RK4 def exact_umax(b): # Solve 2 M u^3 - u^2 + 1/b^2 = 0 for smallest positive root u in (0, 1/(3M)) lo, hi = 0.0, 1.0 / (3.0 * M) for _ in range(100): mid = 0.5 * (lo + hi) val = 2.0 * M * mid ** 3 - mid ** 2 + 1.0 / (b * b) if val > 0.0: lo = mid else: hi = mid return 0.5 * (lo + hi) max_turn_err = 0.0 for b in (5.3, 6.0, 8.0, 15.0): u_exact = exact_umax(b) r_exact = 1.0 / u_exact cubic_res = abs(r_exact ** 3 - b * b * r_exact + 2.0 * M * b * b) _, _, u_rk4 = trace_null_geodesic(b, r_start=200.0, dphi=0.0005) max_turn_err = max(max_turn_err, cubic_res, abs(u_rk4 - u_exact)) check("2.2 Turning-point cubic r_min^3 - b^2 r_min + 2 M b^2 = 0 vs RK4", max_turn_err < 1e-8, f"max_err = {max_turn_err:.3e}") # 2.3 Strong-field deflection: RK4 vs exact transformed elliptic quadrature def exact_deflection(b): um = exact_umax(b) # Substitute u = um * sin^2(theta) -> du = 2 um sin(theta) cos(theta) dtheta # Denominator: sqrt((um - u) * (um + u - 2 M (um^2 + um u + u^2))) # With um - u = um cos^2(theta), cos(theta) cancels cleanly! def integrand(th): s = math.sin(th) u = um * s * s # 1/b^2 - u^2(1-2Mu) = (um - u) * (um + u - 2*M*(um^2 + um*u + u^2)) q = um + u - 2.0 * M * (um * um + um * u + u * u) return 2.0 * math.sqrt(um) * s / math.sqrt(q) return 2.0 * simpson(integrand, 0.0, math.pi / 2.0, 4000) - math.pi max_defl_err = 0.0 for b in (5.5, 7.0, 12.0): d_ex = exact_deflection(b) _, d_rk4, _ = trace_null_geodesic(b, r_start=2000.0, dphi=0.001) # Account for finite start distance r_start: asymptotically O((M/r_start)^2) ~ 1e-6 -> use tiny exact correction # Incoming angle already initialized at asin(b/r_start); remaining residual from u_start = 1/r_start is ~ 2*M/(r_start*sqrt(r_start^2/b^2 - 1)) ~ 2*M*b/r_start^2 max_defl_err = max(max_defl_err, abs(d_rk4 - d_ex)) check("2.3 Strong-field deflection angle (RK4 vs exact elliptic integral)", max_defl_err < 5e-5, f"max_abs_err = {max_defl_err:.3e} rad across b in {{5.5, 7, 12}}M") # 2.4 Weak-field Einstein + Epstein-Shapiro 2nd & 3rd order asymptotic law max_weak_rel = 0.0 for b in (100.0, 200.0): d_ex = exact_deflection(b) d_asym = 4.0 * M / b + 15.0 * math.pi * M * M / (4.0 * b * b) + 128.0 * M ** 3 / (3.0 * b ** 3) + 3465.0 * math.pi * M ** 4 / (64.0 * b ** 4) + 3584.0 * M ** 5 / (5.0 * b ** 5) max_weak_rel = max(max_weak_rel, abs(d_ex - d_asym) / d_ex) check("2.4 Weak-field Einstein + Epstein-Shapiro expansion (b=100M, 200M)", max_weak_rel < 1e-6, f"max_rel_err = {max_weak_rel:.3e}") # 2.5 Timelike perihelion precession: u'' + u = M/L^2 + 3 M u^2 vs 6 pi M^2 / L^2 L = 100.0 * M e = 0.2 u0 = (M / (L * L)) * (1.0 + e) # start at perihelion (du/dphi = 0) u, du, phi = u0, 0.0, 0.0 h = 0.001 prev_du = -1.0 phi_peri = None for step in range(1, 20000): def ft(uv, dv): return dv, M / (L * L) + 3.0 * M * uv * uv - uv k1u, k1v = ft(u, du) k2u, k2v = ft(u + 0.5 * h * k1u, du + 0.5 * h * k1v) k3u, k3v = ft(u + 0.5 * h * k2u, du + 0.5 * h * k2v) k4u, k4v = ft(u + h * k3u, du + h * k3v) u_n = u + (h / 6.0) * (k1u + 2.0 * k2u + 2.0 * k3u + k4u) du_n = du + (h / 6.0) * (k1v + 2.0 * k2v + 2.0 * k3v + k4v) phi_n = phi + h # Detect return to perihelion: du crosses from >0 to <=0 after phi > 3 if phi > 3.0 and du > 0.0 and du_n <= 0.0: frac = du / (du - du_n) phi_peri = phi + frac * h break u, du, phi = u_n, du_n, phi_n dphi_num = phi_peri - 2.0 * math.pi dphi_gr = 6.0 * math.pi * M * M / (L * L) rel_prec_err = abs(dphi_num - dphi_gr) / dphi_gr check("2.5 Timelike perihelion precession vs Einstein 6 pi M^2 / L^2", rel_prec_err < 2e-3, f"num={dphi_num:.8f} rad, Einstein={dphi_gr:.8f} rad, rel_err={rel_prec_err:.3e}") # ============================================================================ # SUITE 3: ROTATING KERR BLACK HOLE, ERGOSPHERE & PENROSE EXTRACTION # ============================================================================ def verify_suite_3(): print("\n=== SUITE 3: Rotating Kerr Black Hole, Ergosphere & Penrose Extraction ===") M = 1.0 # 3.1 Exact horizon Delta(r_pm)=0 and ergosphere g_tt(r_E(theta), theta)=0 max_hor_err = 0.0 max_ergo_err = 0.0 for a in (0.0, 0.5, 0.68, 0.95, 0.998): rp = M + math.sqrt(M * M - a * a) rm = M - math.sqrt(M * M - a * a) max_hor_err = max(max_hor_err, abs(rp * rp - 2 * M * rp + a * a), abs(rm * rm - 2 * M * rm + a * a)) for th in (0.0, 0.4, math.pi / 4.0, 1.1, math.pi / 2.0): rE = M + math.sqrt(M * M - (a * math.cos(th)) ** 2) sigma = rE * rE + (a * math.cos(th)) ** 2 g_tt = -(1.0 - 2.0 * M * rE / sigma) max_ergo_err = max(max_ergo_err, abs(g_tt)) check("3.1 Kerr horizons Delta(r_pm)=0 & ergosphere g_tt(r_E(theta))=0", max_hor_err < 1e-14 and max_ergo_err < 1e-14, f"hor_err={max_hor_err:.3e}, ergo_err={max_ergo_err:.3e}") # 3.2 Exact equatorial photon circular orbits r_ph^pm max_ph_err = 0.0 for a in (0.0, 0.4, 0.68, 0.95, 0.9999): for sign in (-1.0, +1.0): # -1 prograde, +1 retrograde r_ph = 2.0 * M * (1.0 + math.cos((2.0 / 3.0) * math.acos(sign * a / M))) # Exact cubic: r*(r - 3M)^2 - 4 M a^2 = 0 cubic = r_ph * (r_ph - 3.0 * M) ** 2 - 4.0 * M * a * a max_ph_err = max(max_ph_err, abs(cubic)) check("3.2 Equatorial Kerr photon spheres r_ph^pm satisfy r(r-3M)^2 = 4 M a^2", max_ph_err < 1e-13, f"max_cubic_res = {max_ph_err:.3e}") # 3.3 Exact Bardeen-Press-Teukolsky (1972) prograde/retrograde ISCO radii def bpt_isco(a, prograde=True): s = a / M z1 = 1.0 + (1.0 - s * s) ** (1.0 / 3.0) * ((1.0 + s) ** (1.0 / 3.0) + (1.0 - s) ** (1.0 / 3.0)) z2 = math.sqrt(3.0 * s * s + z1 * z1) if prograde: return M * (3.0 + z2 - math.sqrt((3.0 - z1) * (3.0 + z1 + 2.0 * z2))) else: return M * (3.0 + z2 + math.sqrt((3.0 - z1) * (3.0 + z1 + 2.0 * z2))) max_isco_err = 0.0 for a in (0.0, 0.5, 0.68, 0.95, 0.998): r_pro = bpt_isco(a, True) r_ret = bpt_isco(a, False) # Exact algebraic ISCO equation: r^2 - 6 M r +- 8 a sqrt(M r) - 3 a^2 = 0 # (+ for prograde, - for retrograde) res_pro = r_pro * r_pro - 6.0 * M * r_pro + 8.0 * a * math.sqrt(M * r_pro) - 3.0 * a * a res_ret = r_ret * r_ret - 6.0 * M * r_ret - 8.0 * a * math.sqrt(M * r_ret) - 3.0 * a * a max_isco_err = max(max_isco_err, abs(res_pro), abs(res_ret)) lim_ok = abs(bpt_isco(0.0, True) - 6.0) < 1e-14 and abs(bpt_isco(1.0, True) - 1.0) < 1e-14 and abs(bpt_isco(1.0, False) - 9.0) < 1e-14 check("3.3 Bardeen-Press-Teukolsky prograde/retrograde ISCO exact identity", max_isco_err < 1e-12 and lim_ok, f"max_res={max_isco_err:.3e}, limits (a=0: 6M; a=1: 1M pro, 9M ret) exact") # 3.4 Rigid horizon rotation: frame-dragging omega(r_+, theta) == Omega_H for all theta max_omega_err = 0.0 for a in (0.3, 0.68, 0.95, 0.998): rp = M + math.sqrt(M * M - a * a) omega_H = a / (2.0 * M * rp) for th in (0.05, 0.5, 1.0, math.pi / 2.0): s2 = math.sin(th) ** 2 delta = rp * rp - 2.0 * M * rp + a * a # 0 omega = (2.0 * M * a * rp) / ((rp * rp + a * a) ** 2 - a * a * delta * s2) max_omega_err = max(max_omega_err, abs(omega - omega_H)) check("3.4 Rigid Kerr horizon rotation omega(r_+, theta) == a / (2 M r_+)", max_omega_err < 1e-15, f"max_err = {max_omega_err:.3e}") # 3.5 Christodoulou irreducible mass, 29.289% bound & explicit Penrose split inside ergosphere def m_irr(a): return math.sqrt(0.5 * (M * M + M * math.sqrt(M * M - a * a))) eta_ext = 1.0 - m_irr(M) / M eta_exact = 1.0 - 1.0 / math.sqrt(2.0) # Explicit equatorial Penrose split at a = 0.95, r = 1.5 (strictly inside ergosphere: r_+ = 1.31225 < 1.5 < 2.0) a = 0.95 r = 1.5 # Equatorial Boyer-Lindquist metric components at theta = pi/2 g_tt = -(1.0 - 2.0 * M / r) # > 0 inside ergosphere! g_tphi = -2.0 * M * a / r g_phiphi = r * r + a * a + 2.0 * M * a * a / r g_rr = r * r / (r * r - 2.0 * M * r + a * a) # Inverse (t, phi) 2x2 block det2 = g_tt * g_phiphi - g_tphi * g_tphi # = -Delta < 0 gtt_inv = g_phiphi / det2 gtphi_inv = -g_tphi / det2 gpp_inv = g_tt / det2 # Zero-radial-momentum rest-at-infinity particle falling to r=1.5 has E0 = 1, L0 = 0 # Wait: check its radial momentum squared p_r^2 via g^{mu nu} p_mu p_nu = -m0^2 = -1 # p_t = -E0 = -1, p_phi = L0 = 0 m0 = 1.0 E0, L0 = 1.0, 0.0 pr0_sq = (-m0 * m0 - gtt_inv * (E0 * E0)) * (1.0 / g_rr) # Wait: g^{rr} p_r^2 = -m0^2 - g^{tt} p_t^2 -> p_r^2 = g_rr * (-m0^2 - g^{tt} E0^2) pr0_sq = g_rr * (-m0 * m0 - gtt_inv * E0 * E0) pr0 = -math.sqrt(pr0_sq) # ingoing # Split at r=1.5 into two photons (m1=m2=0) at radial turning points or with p_r1 + p_r2 = pr0: # Choose photon 1 retrograde (L1 < 0) with p_r1 = 0 (tangential retrograde) and solve null condition for E1! # Null condition for p_r1 = 0: g^{tt} E1^2 - 2 g^{tphi} E1 L1 + g^{phiphi} L1^2 = 0 # Note inside ergosphere g^{phiphi} = g_tt / (-Delta) < 0, g^{tt} < 0, g^{tphi} < 0! # Wait: g_tphi < 0, det2 < 0 => gtphi_inv = -g_tphi / det2 < 0. # For a future-directed null ray, p^t = g^{tt}(-E) + g^{tphi} L > 0! # Solve for E1/L1 with L1 = -0.12: L1 = -0.12 # Quadratic in E1: gtt_inv * E1^2 - 2 * gtphi_inv * L1 * E1 + gpp_inv * L1^2 = 0 qa = gtt_inv qb = -2.0 * gtphi_inv * L1 qc = gpp_inv * L1 * L1 disc = qb * qb - 4.0 * qa * qc # Choose the future-directed root (p^t > 0) roots = [(-qb + s * math.sqrt(disc)) / (2.0 * qa) for s in (-1.0, +1.0)] E1 = None for cand in roots: pt_up = gtt_inv * (-cand) + gtphi_inv * L1 if pt_up > 0.0: E1 = cand break # By 4-momentum conservation: E2 = E0 - E1, L2 = L0 - L1, pr2 = pr0 - 0 E2 = E0 - E1 L2 = L0 - L1 pr2 = pr0 # Check fragment 2 is timelike (m2^2 = -g^{mu nu} p2_mu p2_nu > 0) and future-directed (p2^t > 0) m2_sq = -(gtt_inv * E2 * E2 - 2.0 * gtphi_inv * E2 * L2 + gpp_inv * L2 * L2 + (1.0 / g_rr) * pr2 * pr2) pt2_up = gtt_inv * (-E2) + gtphi_inv * L2 # Also check null condition of fragment 1 null1_res = abs(gtt_inv * E1 * E1 - 2.0 * gtphi_inv * E1 * L1 + gpp_inv * L1 * L1) check("3.5 Extremal Penrose bound (29.289%) & explicit negative-energy split", abs(eta_ext - eta_exact) < 1e-15 and E1 < 0.0 and E2 > E0 and m2_sq > 0.0 and pt2_up > 0.0 and null1_res < 1e-14, f"eta_max={eta_ext*100:.6f}%, split@r=1.5M: E0=1.0 -> E1={E1:.4f} (<0!) + E2={E2:.4f} (gain +{(E2-E0)*100:.2f}%, m2={math.sqrt(m2_sq):.4f})") # ============================================================================ # SUITE 4: GRAVITATIONAL WAVES (h+/hx), BINARY INSPIRAL CHIRP & LIGO # ============================================================================ def verify_suite_4(): print("\n=== SUITE 4: Gravitational Waves (h+/hx), Binary Inspiral Chirp & LIGO ===") G = 6.67430e-11 c = 2.99792458e8 M_sun = 1.98847e30 # 4.1 Transverse-traceless gauge & area preservation to O(h^2) max_tt_err = 0.0 for hp, hx in ((0.01, 0.0), (0.0, 0.01), (0.008, -0.006), (1e-4, 2e-4)): # 2D transverse perturbation M = I + 0.5 * [[hp, hx], [hx, -hp]] tr_h = hp + (-hp) det_M = (1.0 + 0.5 * hp) * (1.0 - 0.5 * hp) - (0.5 * hx) ** 2 expected_det = 1.0 - 0.25 * (hp * hp + hx * hx) max_tt_err = max(max_tt_err, abs(tr_h), abs(det_M - expected_det)) check("4.1 TT-gauge tracelessness & exact area preservation det = 1 - (h+^2+hx^2)/4", max_tt_err < 1e-15, f"max_err = {max_tt_err:.3e}") # 4.2 Peters-Mathews orbital decay RK4 vs exact a(t) = a0 (1 - t/tau_c)^(1/4) m1, m2 = 36.0 * M_sun, 29.0 * M_sun beta_pm = (64.0 / 5.0) * (G ** 3) * m1 * m2 * (m1 + m2) / (c ** 5) a0 = 1.5e6 # 1,500 km separation tau_c = (a0 ** 4) / (4.0 * beta_pm) # Integrate to 0.90 * tau_c t_end = 0.90 * tau_c steps = 10000 dt = t_end / steps a_val = a0 for _ in range(steps): k1 = -beta_pm / (a_val ** 3) k2 = -beta_pm / ((a_val + 0.5 * dt * k1) ** 3) k3 = -beta_pm / ((a_val + 0.5 * dt * k2) ** 3) k4 = -beta_pm / ((a_val + dt * k3) ** 3) a_val += (dt / 6.0) * (k1 + 2.0 * k2 + 2.0 * k3 + k4) a_exact = a0 * (1.0 - t_end / tau_c) ** 0.25 rel_pm_err = abs(a_val - a_exact) / a_exact check("4.2 Peters-Mathews quadrupole decay RK4 vs a0*(1 - t/tau_c)^(1/4)", rel_pm_err < 1e-11, f"tau_c={tau_c:.4f}s, rel_err = {rel_pm_err:.3e}") # 4.3 Chirp mass exact recovery from df/dt = (96/5) pi^(8/3) (G Mc / c^3)^(5/3) f^(11/3) Mc = ((m1 * m2) ** 0.6) / ((m1 + m2) ** 0.2) Mc_sun = Mc / M_sun coeff = (96.0 / 5.0) * (math.pi ** (8.0 / 3.0)) * ((G * Mc / (c ** 3)) ** (5.0 / 3.0)) def f_gw(tau): return (1.0 / math.pi) * ((5.0 / (256.0 * tau)) ** (3.0 / 8.0)) * ((G * Mc / (c ** 3)) ** (-5.0 / 8.0)) max_mc_rel = 0.0 for tau in (0.5, 0.1, 0.02): h = 1e-4 * tau # 4th-order central difference for df/dt = -df/dtau df_dt = -(-f_gw(tau + 2 * h) + 8 * f_gw(tau + h) - 8 * f_gw(tau - h) + f_gw(tau - 2 * h)) / (12.0 * h) f_now = f_gw(tau) # Invert for Mc gmc_c3 = ((5.0 / 96.0) * df_dt * (math.pi ** (-8.0 / 3.0)) * (f_now ** (-11.0 / 3.0))) ** (3.0 / 5.0) Mc_rec = gmc_c3 * (c ** 3) / G max_mc_rel = max(max_mc_rel, abs(Mc_rec - Mc) / Mc) check("4.3 Exact chirp mass recovery from frequency sweep df/dt ~ f^(11/3)", max_mc_rel < 1e-11, f"GW150914 Mc = {Mc_sun:.6f} M_sun, max_rel_err = {max_mc_rel:.3e}") # 4.4 GW150914 exact benchmark (36 + 29 M_sun) eta_sym = (m1 * m2) / ((m1 + m2) ** 2) f_isco = (c ** 3) / ((6.0 ** 1.5) * math.pi * G * (m1 + m2)) # Verify Mc = (m1+m2) * eta^(3/5) mc_alt = (m1 + m2) * (eta_sym ** 0.6) check("4.4 GW150914 (36+29 M_sun) chirp mass, symmetric mass ratio & f_ISCO", abs(Mc - mc_alt) / Mc < 1e-14 and abs(Mc_sun - 28.095556) < 1e-5 and 67.0 < f_isco < 68.5, f"Mc={Mc_sun:.6f} M_sun, eta={eta_sym:.6f}, f_ISCO={f_isco:.3f} Hz") # 4.5 Quadrupole chirp phase derivative dPhi/dt == 2 pi f_GW(t) def phi_gw(tau): return -2.0 * ((5.0 * G * Mc / (c ** 3)) ** (-5.0 / 8.0)) * (tau ** (5.0 / 8.0)) max_ph_rel = 0.0 for tau in (0.4, 0.08, 0.015): h = 1e-4 * tau dphi_dt = -(-phi_gw(tau + 2 * h) + 8 * phi_gw(tau + h) - 8 * phi_gw(tau - h) + phi_gw(tau - 2 * h)) / (12.0 * h) target = 2.0 * math.pi * f_gw(tau) max_ph_rel = max(max_ph_rel, abs(dphi_dt - target) / target) check("4.5 Inspiral phase derivative dPhi/dt == 2 pi f_GW(t)", max_ph_rel < 1e-11, f"max_rel_err = {max_ph_rel:.3e}") # ============================================================================ # SUITE 5: FLRW EXPANDING UNIVERSE, COSMIC HORIZONS & REDSHIFT # ============================================================================ def verify_suite_5(): print("\n=== SUITE 5: FLRW Expanding Universe, Cosmic Horizons & Redshift ===") # Units: c = 1, Hubble time t_H = 1/H_0; Planck H_0 = 67.4 km/s/Mpc # 1 Mpc = 3.085677581491367e22 m, 1 Julian year = 31557600 s Mpc_m = 3.085677581491367e22 yr_s = 31557600.0 H0_kms_Mpc = 67.4 t_H_Gyr = (Mpc_m / (H0_kms_Mpc * 1000.0)) / (yr_s * 1e9) # 14.5072... Gyr def E_func(a, Om, Ol, Or=0.0): Ok = 1.0 - Om - Ol - Or val = Or / (a ** 4) + Om / (a ** 3) + Ok / (a ** 2) + Ol return math.sqrt(val) def cosmic_age_dimless(a_target, Om, Ol, Or=0.0, n=4000): # Substitute a = x^2 -> da = 2 x dx to remove a -> 0 singularity! def integrand(x): a = x * x if a == 0.0: return 0.0 return 2.0 * x / (a * E_func(a, Om, Ol, Or)) return simpson(integrand, 0.0, math.sqrt(a_target), n) def comoving_dist_dimless(a_min, a_max, Om, Ol, Or=0.0, n=4000): # chi = int_{a_min}^{a_max} da / (a^2 E(a)); substitute a = x^2 -> 2 dx / (x^3 E(x^2)) # For Or=0, a^2 E(a) ~ sqrt(Om * a) = sqrt(Om) * x -> 2 x dx / (x^3 * sqrt(Om)/x^3) -> finite! def integrand(x): a = x * x if a == 0.0: return 2.0 / math.sqrt(Om) if Om > 0.0 and Or == 0.0 else 0.0 return 2.0 * x / (a * a * E_func(a, Om, Ol, Or)) return simpson(integrand, math.sqrt(a_min), math.sqrt(a_max), n) # 5.1 Einstein-de Sitter (Om=1, Ol=0): exact t0*H0 = 2/3, d_P = 2 c/H0 = 3 c t0 t0_eds = cosmic_age_dimless(1.0, 1.0, 0.0) dp_eds = comoving_dist_dimless(0.0, 1.0, 1.0, 0.0) a_half_t = cosmic_age_dimless(0.5 ** (2.0 / 3.0), 1.0, 0.0) eds_err = max(abs(t0_eds - 2.0 / 3.0), abs(dp_eds - 2.0), abs(a_half_t - 1.0 / 3.0)) check("5.1 Einstein-de Sitter exact age (2/3 H0^-1) & particle horizon (3 c t0)", eds_err < 1e-12, f"t0*H0={t0_eds:.12f}, d_P*H0/c={dp_eds:.12f}, err={eds_err:.3e}") # 5.2 Flat Planck LambdaCDM (Om=0.315, Ol=0.685): exact analytic sinh^(2/3) vs quadrature Om, Ol = 0.315, 0.685 t0_lcdm = cosmic_age_dimless(1.0, Om, Ol) # Exact flat LambdaCDM analytic formula: H0*t(a) = (2 / (3*sqrt(Ol))) * asinh(sqrt(Ol/Om) * a^(3/2)) t0_exact = (2.0 / (3.0 * math.sqrt(Ol))) * math.asinh(math.sqrt(Ol / Om)) age_Gyr = t0_lcdm * t_H_Gyr # Acceleration onset: a_acc = (Om / (2*Ol))^(1/3), z_acc = 1/a_acc - 1 a_acc = (Om / (2.0 * Ol)) ** (1.0 / 3.0) z_acc = 1.0 / a_acc - 1.0 # Particle horizon today (in Gly, numerically equal to t_H_Gyr * dimless chi since c = 1 Gly/Gyr) dP_Gly = comoving_dist_dimless(0.0, 1.0, Om, Ol) * t_H_Gyr # Cosmic event horizon today: chi_E = int_1^inf da / (a^2 E(a)); substitute u = 1/a in [0, 1] dE_dimless = simpson(lambda u: 1.0 / E_func(1.0 / u, Om, Ol) if u > 0.0 else 1.0 / math.sqrt(Ol), 0.0, 1.0, 4000) dE_Gly = dE_dimless * t_H_Gyr check("5.2 Planck LambdaCDM exact sinh^(2/3) age, z_acc, Particle & Event Horizons", abs(t0_lcdm - t0_exact) < 1e-12 and 13.7 < age_Gyr < 13.9 and 46.9 < dP_Gly < 47.1 and 16.5 < dE_Gly < 16.8, f"age={age_Gyr:.3f} Gyr (err={abs(t0_lcdm-t0_exact):.2e}), z_acc={z_acc:.4f}, d_P={dP_Gly:.2f} Gly, d_E={dE_Gly:.2f} Gly") # 5.3 Closed Matter Big Crunch cycloid (Om=2, Ol=0, Ok=-1): a_max = 2, T_crunch * H0 = 2 pi # Substitute a = a_max * sin^2(theta) for theta in [0, pi/2] to handle both a=0 and a=a_max cleanly! Om_c = 2.0 a_max = Om_c / (Om_c - 1.0) # t_half * H0 = int_0^{a_max} da / sqrt(Om_c/a - (Om_c-1)) # With a = a_max sin^2(th), da = 2 a_max sin(th) cos(th) dth, sqrt(Om_c/a - (Om_c-1)) = sqrt(Om_c-1) * cos(th)/sin(th) t_half = simpson( lambda th: 2.0 * a_max * (math.sin(th) ** 2) / math.sqrt(Om_c - 1.0), 0.0, math.pi / 2.0, 4000 ) T_crunch_exact = math.pi * Om_c / ((Om_c - 1.0) ** 1.5) crunch_err = abs(2.0 * t_half - T_crunch_exact) check("5.3 Closed Matter Big-Crunch exact cycloid (a_max=2, T_crunch*H0=2*pi)", abs(a_max - 2.0) < 1e-15 and crunch_err < 1e-13, f"a_max={a_max:.1f}, T_crunch*H0={2*t_half:.12f}, err={crunch_err:.3e}") # 5.4 Pure de Sitter (Om=0, Ol=1) & Empty Milne (Om=0, Ol=0, Ok=1) # de Sitter: d_E = c/H0 (dimless 1.0), a(t)=exp(H0 t) -> int_1^e da/(a E) = 1 dt_ds = simpson(lambda a: 1.0 / (a * E_func(a, 0.0, 1.0)), 1.0, math.e, 4000) dE_ds = simpson(lambda u: 1.0 / E_func(1.0 / u, 0.0, 1.0) if u > 0.0 else 1.0, 0.0, 1.0, 4000) # Milne: E(a) = 1/a -> a*E(a) = 1 -> t0*H0 = 1.0 t0_milne = simpson(lambda a: 1.0 / (a * E_func(a, 0.0, 0.0)), 0.0001, 1.0, 4000) + 0.0001 ds_milne_err = max(abs(dt_ds - 1.0), abs(dE_ds - 1.0), abs(t0_milne - 1.0)) check("5.4 Pure de Sitter (d_E = c/H0) & Empty Milne (t0 = 1/H0)", ds_milne_err < 1e-12, f"max_err = {ds_milne_err:.3e}") # 5.5 Second Friedmann Acceleration Equation: q0 = -a''/(a H0^2) == Om/2 - Ol via RK4 max_q0_err = 0.0 for Om_t, Ol_t in ((0.315, 0.685), (1.0, 0.0), (2.0, 0.0), (0.3, 1.2)): # Integrate da/dtau = a * E(a) around a=1 for small +-dtau dtau = 1e-4 def step_a(a_init, h): def rhs(av): return av * E_func(av, Om_t, Ol_t) k1 = rhs(a_init) k2 = rhs(a_init + 0.5 * h * k1) k3 = rhs(a_init + 0.5 * h * k2) k4 = rhs(a_init + h * k3) return a_init + (h / 6.0) * (k1 + 2.0 * k2 + 2.0 * k3 + k4) ap = step_a(1.0, +dtau) am = step_a(1.0, -dtau) a_dd = (ap - 2.0 + am) / (dtau * dtau) q0_num = -a_dd q0_exact = 0.5 * Om_t - Ol_t max_q0_err = max(max_q0_err, abs(q0_num - q0_exact)) check("5.5 Second Friedmann deceleration parameter q0 = Om/2 - Ol", max_q0_err < 1e-7, f"max_err = {max_q0_err:.3e}") def main(): print("==========================================================================") print(" THE NEON SPACETIME & RELATIVITY PLANETARIUM — MATHEMATICAL VERIFICATION") print("==========================================================================") verify_suite_1() verify_suite_2() verify_suite_3() verify_suite_4() verify_suite_5() print("\n==========================================================================") print(f" SUMMARY: {PASSED} PASSED, {FAILED} FAILED (5 Relativity Suites)") print("==========================================================================") sys.exit(0 if FAILED == 0 else 1) if __name__ == "__main__": main()