#!/usr/bin/env python3 """ Zero-dependency machine-precision mathematical verifier for Volume V: The Neon Celestial & Dynamical Atelier (Orbits, Chaos, Sync, Flight & Zeta). Suites: 1. Three-Body Choreographies (Figure-Eight, Butterfly-I, Lagrange Ring) & Restricted L1-L5 Stability 2. Symplectic/Hamiltonian Double Pendulum (Energy Conservation, Exact No-Flip Barrier & Lyapunov Chaos) 3. Kuramoto Coupled Oscillators (Exact Lorentzian Ott-Antonsen Phase Transition & Finite-N Convergence) 4. Conformal Joukowsky Aerodynamics (Exact Blasius Contour Lift L = rho*U*Gamma, Zero Drag & Kutta Lock) 5. Complex Analytic Continuation & Riemann Zeta Critical Strip (Functional Equation, First 10 Zeros & Winding) """ import cmath import math import sys # ============================================================================= # SUITE 1: THREE-BODY CHOREOGRAPHIES & LAGRANGE EQUILIBRIA # ============================================================================= def threebody_accel(pos): # pos = [(x1,y1), (x2,y2), (x3,y3)], G = m = 1 acc = [[0.0, 0.0] for _ in range(3)] for i in range(3): for j in range(i + 1, 3): dx = pos[j][0] - pos[i][0] dy = pos[j][1] - pos[i][1] r2 = dx * dx + dy * dy inv_r3 = 1.0 / (r2 * math.sqrt(r2)) fx, fy = dx * inv_r3, dy * inv_r3 acc[i][0] += fx; acc[i][1] += fy acc[j][0] -= fx; acc[j][1] -= fy return acc def threebody_invariants(pos, vel): K = 0.5 * sum(v[0]*v[0] + v[1]*v[1] for v in vel) U = 0.0 for i in range(3): for j in range(i + 1, 3): dx = pos[j][0] - pos[i][0] dy = pos[j][1] - pos[i][1] U -= 1.0 / math.hypot(dx, dy) L = sum(pos[i][0]*vel[i][1] - pos[i][1]*vel[i][0] for i in range(3)) return K + U, L def yoshida4_step(pos, vel, dt): # Exact 4th-order symplectic Yoshida coefficients cbrt2 = 2.0 ** (1.0 / 3.0) w1 = 1.0 / (2.0 - cbrt2) w0 = -cbrt2 * w1 c = (0.5 * w1, 0.5 * (w0 + w1), 0.5 * (w0 + w1), 0.5 * w1) d = (w1, w0, w1) p = [[x, y] for x, y in pos] v = [[vx, vy] for vx, vy in vel] for s in range(3): cs = c[s] * dt for i in range(3): p[i][0] += cs * v[i][0] p[i][1] += cs * v[i][1] a = threebody_accel(p) ds = d[s] * dt for i in range(3): v[i][0] += ds * a[i][0] v[i][1] += ds * a[i][1] c3 = c[3] * dt for i in range(3): p[i][0] += c3 * v[i][0] p[i][1] += c3 * v[i][1] return p, v def verify_suite1(): print("=== SUITE 1: THREE-BODY CHOREOGRAPHIES & LAGRANGE EQUILIBRIA ===") # 1A. Chenciner-Montgomery Figure-Eight (Carles Simo high-precision IC) x1, y1 = 0.97000436, -0.24308753 vx3, vy3 = -0.93240737, -0.86473146 T8 = 6.32591398 pos = [[x1, y1], [-x1, -y1], [0.0, 0.0]] vel = [[-0.5*vx3, -0.5*vy3], [-0.5*vx3, -0.5*vy3], [vx3, vy3]] H0, L0 = threebody_invariants(pos, vel) assert abs(L0) < 1e-15, f"Figure-8 L0 != 0: {L0}" # Integrate 3 full periods (18.978 time units) with Yoshida-4 n_per = 3000 dt = T8 / n_per max_dH = 0.0 max_dL = 0.0 pos_T3 = None pos_T = None p, v = [r[:] for r in pos], [r[:] for r in vel] for step in range(1, 3 * n_per + 1): p, v = yoshida4_step(p, v, dt) H, L = threebody_invariants(p, v) max_dH = max(max_dH, abs(H - H0)) max_dL = max(max_dL, abs(L - L0)) if step == n_per // 3: pos_T3 = [r[:] for r in p] if step == n_per: pos_T = [r[:] for r in p] # Exact choreographic T/3 cyclic shift check: body 0->2->1->0 (up to permutation) choreo_err = max( min(math.hypot(pos_T3[i][0] - pos[j][0], pos_T3[i][1] - pos[j][1]) for j in range(3)) for i in range(3) ) period_err = max(math.hypot(pos_T[i][0] - pos[i][0], pos_T[i][1] - pos[i][1]) for i in range(3)) assert max_dH < 1e-10, f"Figure-8 Yoshida dH too large: {max_dH}" assert max_dL < 1e-13, f"Figure-8 Yoshida dL too large: {max_dL}" assert choreo_err < 1e-5, f"Figure-8 T/3 choreography err: {choreo_err}" assert period_err < 1e-5, f"Figure-8 period closure err: {period_err}" # 1B. Exact Lagrange Equilateral Circular Orbit (radius R=1, omega = 1/3^(1/4)) R = 1.0 omega = (1.0 / math.sqrt(3.0)) ** 0.5 # F = 2 * (1/(sqrt(3)R)^2) * cos(30) = 1/(sqrt(3) R^2) = omega^2 R pL = [[R * math.cos(2*math.pi*k/3), R * math.sin(2*math.pi*k/3)] for k in range(3)] vL = [[-omega*R * math.sin(2*math.pi*k/3), omega*R * math.cos(2*math.pi*k/3)] for k in range(3)] TL = 2.0 * math.pi / omega p, v = [r[:] for r in pL], [r[:] for r in vL] max_dr = 0.0 for _ in range(4000): p, v = yoshida4_step(p, v, TL / 4000) for q in p: max_dr = max(max_dr, abs(math.hypot(q[0], q[1]) - R)) assert max_dr < 1e-11, f"Lagrange ring radius drift: {max_dr}" # 1C. Restricted Three-Body Lagrange Points L1..L5 & Gascheau-Routh Stability mu = 0.025 # < mu_c = (1 - sqrt(23/27))/2 = 0.0385208965... mu_crit = 0.5 * (1.0 - math.sqrt(23.0 / 27.0)) assert mu < mu_crit def grad_Ueff(x, y): # U_eff = 0.5*(x^2+y^2) + (1-mu)/r1 + mu/r2; primary1 at (-mu,0), primary2 at (1-mu,0) dx1, dx2 = x + mu, x - (1.0 - mu) r1 = math.hypot(dx1, y) r2 = math.hypot(dx2, y) ux = x - (1.0 - mu) * dx1 / (r1**3) - mu * dx2 / (r2**3) uy = y - (1.0 - mu) * y / (r1**3) - mu * y / (r2**3) return ux, uy def bisect_collinear(a, b): fa = grad_Ueff(a, 0.0)[0] for _ in range(90): m = 0.5 * (a + b) fm = grad_Ueff(m, 0.0)[0] if fa * fm <= 0: b = m else: a, fa = m, fm return 0.5 * (a + b) xL1 = bisect_collinear(-mu + 0.1, 1.0 - mu - 0.05) xL2 = bisect_collinear(1.0 - mu + 0.05, 2.0) xL3 = bisect_collinear(-2.0, -mu - 0.1) L4 = (0.5 - mu, math.sqrt(3.0) / 2.0) L5 = (0.5 - mu, -math.sqrt(3.0) / 2.0) pts = [ (xL1, 0.0), (xL2, 0.0), (xL3, 0.0), L4, L5 ] max_grad = max(math.hypot(*grad_Ueff(x, y)) for x, y in pts) assert max_grad < 1e-13, f"Lagrange equilibrium gradient err: {max_grad}" # Characteristic polynomial at L4/L5: lambda^4 + lambda^2 + (27/4)*mu*(1-mu) = 0 disc = 1.0 - 27.0 * mu * (1.0 - mu) assert disc > 0.0, "L4/L5 should be linearly stable for mu < mu_crit" lam2_1 = (-1.0 + math.sqrt(disc)) / 2.0 lam2_2 = (-1.0 - math.sqrt(disc)) / 2.0 assert lam2_1 < 0 and lam2_2 < 0 # Purely imaginary eigenvalues! # Integrate a Trojan tadpole orbit near L4 and verify Jacobi Constant C_J conservation def cr3bp_deriv(s): x, y, vx, vy = s ux, uy = grad_Ueff(x, y) return (vx, vy, 2.0 * vy + ux, -2.0 * vx + uy) def jacobi_C(s): x, y, vx, vy = s r1 = math.hypot(x + mu, y) r2 = math.hypot(x - (1.0 - mu), y) return (x*x + y*y) + 2.0*(1.0 - mu)/r1 + 2.0*mu/r2 - (vx*vx + vy*vy) st = (L4[0] + 0.03, L4[1] - 0.015, 0.0, 0.0) C0 = jacobi_C(st) max_dC = 0.0 dt_r = 0.01 for _ in range(2500): k1 = cr3bp_deriv(st) k2 = cr3bp_deriv(tuple(st[i] + 0.5*dt_r*k1[i] for i in range(4))) k3 = cr3bp_deriv(tuple(st[i] + 0.5*dt_r*k2[i] for i in range(4))) k4 = cr3bp_deriv(tuple(st[i] + dt_r*k3[i] for i in range(4))) st = tuple(st[i] + (dt_r/6.0)*(k1[i] + 2*k2[i] + 2*k3[i] + k4[i]) for i in range(4)) max_dC = max(max_dC, abs(jacobi_C(st) - C0)) assert max_dC < 1e-10, f"CR3BP Jacobi drift: {max_dC}" print(f" Figure-8 (3 periods, Yoshida-4): max |dH|={max_dH:.2e}, max |dL|={max_dL:.2e}, T/3 shift={choreo_err:.2e}") print(f" Lagrange Equilateral Ring: max |dR|={max_dr:.2e} over full orbit") print(f" CR3BP (mu={mu} < mu_c={mu_crit:.6f}): L1..L5 |grad U|={max_grad:.2e}, Trojan max |dC_J|={max_dC:.2e}") print(" [PASS] SUITE 1\n") # ============================================================================= # SUITE 2: HAMILTONIAN DOUBLE PENDULUM, ENERGY NO-FLIP BARRIER & CHAOS # ============================================================================= def dp_energy(th1, th2, p1, p2): # m1 = m2 = l1 = l2 = g = 1 d = th1 - th2 cd = math.cos(d) den = 2.0 - cd * cd # 1 + sin^2(d) K = (p1*p1 + 2.0*p2*p2 - 2.0*p1*p2*cd) / (2.0 * den) V = -2.0 * math.cos(th1) - math.cos(th2) return K + V def dp_deriv(s): th1, th2, p1, p2 = s d = th1 - th2 sd = math.sin(d) cd = math.cos(d) den = 1.0 + sd * sd # = 2 - cos^2(d) dth1 = (p1 - p2 * cd) / den dth2 = (2.0 * p2 - p1 * cd) / den h1 = (p1 * p2 * sd) / den h2 = ((p1*p1 + 2.0*p2*p2 - 2.0*p1*p2*cd) * sd * cd) / (den * den) dp1 = -2.0 * math.sin(th1) - h1 + h2 dp2 = -math.sin(th2) + h1 - h2 return (dth1, dth2, dp1, dp2) def dp_rk4(s, dt): k1 = dp_deriv(s) k2 = dp_deriv(tuple(s[i] + 0.5*dt*k1[i] for i in range(4))) k3 = dp_deriv(tuple(s[i] + 0.5*dt*k2[i] for i in range(4))) k4 = dp_deriv(tuple(s[i] + dt*k3[i] for i in range(4))) return tuple(s[i] + (dt/6.0)*(k1[i] + 2*k2[i] + 2*k3[i] + k4[i]) for i in range(4)) def verify_suite2(): print("=== SUITE 2: HAMILTONIAN DOUBLE PENDULUM, NO-FLIP BARRIER & LYAPUNOV CHAOS ===") # 2A. Verify Hamiltonian conservation in both chaotic and regular regimes s_chaos = (2.25, -1.85, 0.0, 0.0) H0_c = dp_energy(*s_chaos) max_dH_c = 0.0 dt = 0.0008 s = s_chaos for _ in range(25000): # T = 20 s = dp_rk4(s, dt) max_dH_c = max(max_dH_c, abs(dp_energy(*s) - H0_c)) assert max_dH_c < 1e-10, f"Chaotic double pendulum dH: {max_dH_c}" # 2B. Exact Energy-Barrier No-Flip Theorem: # V(th1, th2) = -2 cos(th1) - cos(th2). Flip requires th2 = +-pi where V >= -2(1) - (-1) = -1. # Thus any rest initial condition with -2 cos(th1) - cos(th2) < -1 can NEVER flip th2! flips_inside = 0 tested_inside = 0 for i in range(-4, 5): for j in range(-4, 5): th1 = i * 0.28 th2 = j * 0.35 E = -2.0 * math.cos(th1) - math.cos(th2) if E < -1.05: tested_inside += 1 st = (th1, th2, 0.0, 0.0) for _ in range(600): st = dp_rk4(st, 0.02) if abs(st[1]) >= math.pi: flips_inside += 1 break assert tested_inside >= 20 and flips_inside == 0, f"Barrier violation: {flips_inside}/{tested_inside}" # 2C. Butterfly-effect divergence (positive finite-time Lyapunov exponent) in chaotic regime eps = 1e-7 sa = (2.25, -1.85, 0.0, 0.0) sb = (2.25 + eps, -1.85, 0.0, 0.0) for _ in range(5000): # T = 25.0 sa = dp_rk4(sa, 0.005) sb = dp_rk4(sb, 0.005) dist = math.sqrt(sum((sa[i] - sb[i])**2 for i in range(4))) lyap_est = math.log(dist / eps) / 25.0 assert dist > 0.1 and lyap_est > 0.5, f"Expected chaotic separation, got dist={dist}, lyap={lyap_est}" print(f" Chaotic Hamiltonian RK4 (T=20): max |dH|={max_dH_c:.2e}") print(f" Energy-Barrier No-Flip Theorem (E < -1): {flips_inside}/{tested_inside} flips (exact barrier)") print(f" Butterfly Divergence (d0=1e-7 -> T=25.0): dist={dist:.4f}, finite-time lambda~{lyap_est:.3f} > 0") print(" [PASS] SUITE 2\n") # ============================================================================= # SUITE 3: KURAMOTO COUPLED OSCILLATORS & EXACT OTT-ANTONSEN TRANSITION # ============================================================================= def kuramoto_order(thetas): N = len(thetas) cx = sum(math.cos(t) for t in thetas) / N cy = sum(math.sin(t) for t in thetas) / N return math.hypot(cx, cy), math.atan2(cy, cx) def kuramoto_rhs(thetas, omegas, K): r, psi = kuramoto_order(thetas) # Exact mean-field rewrite: (K/N) sum sin(th_j - th_i) = K * r * sin(psi - th_i) return [omegas[i] + K * r * math.sin(psi - thetas[i]) for i in range(len(thetas))] def verify_suite3(): print("=== SUITE 3: KURAMOTO COUPLED OSCILLATORS & OTT-ANTONSEN PHASE TRANSITION ===") # Exact Lorentzian distribution g(w) = gamma / (pi * (w^2 + gamma^2)), K_c = 2*gamma gamma = 0.5 Kc = 2.0 * gamma # = 1.0 # 3A. Verify exact 1D Ott-Antonsen ODE dr/dt = -gamma*r + (K/2)*r*(1 - r^2) # converges to exact theoretical r_inf(K) = sqrt(1 - Kc/K) for K > Kc and 0 for K < Kc max_oa_err = 0.0 for K in (0.5, 1.5, 2.5, 4.0): r = 0.35 dt = 0.02 for _ in range(6000): f = lambda rv: -gamma * rv + 0.5 * K * rv * (1.0 - rv * rv) k1 = f(r); k2 = f(r + 0.5*dt*k1); k3 = f(r + 0.5*dt*k2); k4 = f(r + dt*k3) r += (dt/6.0) * (k1 + 2*k2 + 2*k3 + k4) r_exact = 0.0 if K <= Kc else math.sqrt(1.0 - Kc / K) max_oa_err = max(max_oa_err, abs(r - r_exact)) assert max_oa_err < 1e-11, f"Ott-Antonsen steady-state err: {max_oa_err}" # 3B. Direct finite-N = 300 deterministic Cauchy-quantile Kuramoto simulation vs exact r_inf(K) N = 300 omegas = [gamma * math.tan(math.pi * ((i + 0.5) / N - 0.5)) for i in range(N)] # Symmetric initial phases around 0 so mean phase psi stays near 0 th_init = [2.0 * math.pi * (i / N) for i in range(N)] # Verify mean-field identity O(N) == direct O(N^2) pairwise sum on N=40 th_small = [0.3 * i + 0.1 * math.sin(i) for i in range(40)] om_small = [0.05 * (i - 20) for i in range(40)] rhs_fast = kuramoto_rhs(th_small, om_small, 2.3) rhs_pair = [ om_small[i] + (2.3 / 40.0) * sum(math.sin(th_small[j] - th_small[i]) for j in range(40)) for i in range(40) ] mf_err = max(abs(a - b) for a, b in zip(rhs_fast, rhs_pair)) assert mf_err < 1e-14, f"Mean-field trigonometric identity err: {mf_err}" # Test subcritical K=0.4 (incoherent) vs supercritical K=2.0 (r_inf=sqrt(0.5)=0.7071) & K=4.0 (r_inf=sqrt(0.75)=0.8660) results = {} for K in (0.4, 2.0, 4.0): # Start with mild phase spread so supercritical locks cleanly and subcritical relaxes th = [(2.0*math.pi*i/N) if K < Kc else (0.3 * math.sin(2.0 * math.pi * i / N)) for i in range(N)] dt = 0.01 r_acc = 0.0 n_avg = 0 for step in range(1200): k1 = kuramoto_rhs(th, omegas, K) k2 = kuramoto_rhs([th[i] + 0.5*dt*k1[i] for i in range(N)], omegas, K) k3 = kuramoto_rhs([th[i] + 0.5*dt*k2[i] for i in range(N)], omegas, K) k4 = kuramoto_rhs([th[i] + dt*k3[i] for i in range(N)], omegas, K) th = [th[i] + (dt/6.0)*(k1[i] + 2*k2[i] + 2*k3[i] + k4[i]) for i in range(N)] if step >= 900: rv, _ = kuramoto_order(th) r_acc += rv n_avg += 1 r_sim = r_acc / n_avg r_th = 0.0 if K <= Kc else math.sqrt(1.0 - Kc / K) results[K] = (r_sim, r_th) if K < Kc: assert r_sim < 0.12, f"Subcritical K={K} should stay incoherent: r={r_sim}" else: assert abs(r_sim - r_th) < 0.015, f"Supercritical K={K} finite-N mismatch: {r_sim} vs {r_th}" print(f" Mean-field trig identity O(N) vs O(N^2) error: {mf_err:.2e}") print(f" Ott-Antonsen exact thermodynamic ODE vs sqrt(1-Kc/K): max err={max_oa_err:.2e}") for K, (rs, rt) in results.items(): print(f" N={N} Direct Kuramoto (K={K:.1f}, Kc={Kc:.1f}): r_sim={rs:.5f} vs r_inf={rt:.5f}") print(" [PASS] SUITE 3\n") # ============================================================================= # SUITE 4: CONFORMAL JOUKOWSKY AERODYNAMICS, KUTTA LOCK & BLASIUS LIFT # ============================================================================= def verify_suite4(): print("=== SUITE 4: CONFORMAL JOUKOWSKY AERODYNAMICS & BLASIUS LIFT THEOREM ===") c = 1.0 U = 1.0 rho = 1.0 max_kutta_err = 0.0 max_drag_err = 0.0 max_lift_err = 0.0 max_harm_err = 0.0 configs = [ # (mux, muy, alpha_deg) (-0.10, 0.00, 8.0), # Symmetric Joukowsky airfoil (-0.12, 0.14, 6.0), # Cambered airfoil (-0.15, 0.18, 12.0), # High-lift cambered airfoil (-0.08, 0.10, -4.0), # Negative AoA ] for mux, muy, alpha_deg in configs: z0 = complex(mux, muy) R = abs(c - z0) # Circle passes through trailing cusp z = +c alpha = math.radians(alpha_deg) beta = math.asin(muy / R) Gamma = 4.0 * math.pi * U * R * math.sin(alpha + beta) # W(z) = U*((z-z0)e^{-ia} + R^2 e^{ia}/(z-z0)) + (i*Gamma/(2*pi)) * ln((z-z0)/R) def dW_dz(z): dz = z - z0 return U * (cmath.exp(-1j*alpha) - (R*R)*cmath.exp(1j*alpha)/(dz*dz)) + (1j*Gamma/(2.0*math.pi))/dz def dZeta_dz(z): return 1.0 - (c*c)/(z*z) # 4A. Kutta Condition: W'(c) MUST vanish identically so dW/dzeta stays finite at trailing cusp! kutta_res = abs(dW_dz(complex(c, 0.0))) max_kutta_err = max(max_kutta_err, kutta_res) # 4B. Exact Blasius Contour Integral in physical zeta-plane: # Fx - i Fy = (i * rho / 2) * oint (dW/dzeta)^2 dzeta = (i * rho / 2) * oint (dW/dz)^2 / (dzeta/dz) dz # Integrate on circle |z - z0| = R_int = 2.5*R in z-plane (encloses airfoil cleanly) R_int = 2.5 * R M = 256 blasius = 0.0j for k in range(M): th = 2.0 * math.pi * k / M z = z0 + R_int * cmath.exp(1j * th) dz_dth = 1j * R_int * cmath.exp(1j * th) integrand = (dW_dz(z)**2 / dZeta_dz(z)) * dz_dth blasius += integrand * (2.0 * math.pi / M) F_conj = 0.5j * rho * blasius # Fx - i Fy in freestream rotated frame? # Wait: freestream is at angle alpha (U e^{i*alpha}), so drag is along e^{i*alpha}, lift is along i*e^{i*alpha}! Fx = F_conj.real Fy = -F_conj.imag F_vec = complex(Fx, Fy) # Rotate into freestream (drag, lift) frame: F_rot = F_vec * cmath.exp(-1j * alpha) Drag = F_rot.real Lift = F_rot.imag Lift_exact = rho * U * Gamma max_drag_err = max(max_drag_err, abs(Drag)) max_lift_err = max(max_lift_err, abs(Lift - Lift_exact)) # 4C. Exact Cauchy-Riemann / Laplace harmonicity of potential phi = Re(W) & stream psi = Im(W) def W_val(z): dz = z - z0 return U * (dz * cmath.exp(-1j*alpha) + (R*R)*cmath.exp(1j*alpha)/dz) + (1j*Gamma/(2.0*math.pi))*cmath.log(dz/R) zt = complex(1.8, 1.3) h = 2e-3 d2x = (-W_val(zt-2*h) + 16*W_val(zt-h) - 30*W_val(zt) + 16*W_val(zt+h) - W_val(zt+2*h)) / (12*h*h) d2y = (-W_val(zt-2j*h) + 16*W_val(zt-1j*h) - 30*W_val(zt) + 16*W_val(zt+1j*h) - W_val(zt+2j*h)) / (12*h*h) lap_W = d2x + d2y max_harm_err = max(max_harm_err, abs(lap_W)) assert max_kutta_err < 1e-13, f"Kutta trailing-edge residual: {max_kutta_err}" assert max_drag_err < 1e-12, f"d'Alembert zero-drag residual: {max_drag_err}" assert max_lift_err < 1e-12, f"Kutta-Joukowski Lift residual: {max_lift_err}" assert max_harm_err < 1e-8, f"Laplace harmonicity err: {max_harm_err}" print(f" Kutta Trailing-Edge Singularity Cancellation |W'(c)|: {max_kutta_err:.2e}") print(f" Blasius Contour d'Alembert Zero-Drag |F_drag|: {max_drag_err:.2e}") print(f" Blasius Contour Kutta-Joukowski |F_lift - rho*U*G|: {max_lift_err:.2e}") print(f" Complex Potential Harmonicity |Laplacian W|: {max_harm_err:.2e}") print(" [PASS] SUITE 4\n") # ============================================================================= # SUITE 5: RIEMANN ZETA CRITICAL STRIP, FUNCTIONAL EQUATION & FIRST 10 ZEROS # ============================================================================= # Bernoulli numbers B_{2k} / (2k)! for k = 1..7 (exact rationals) BERN_DIV_FACT = [ (1.0 / 6.0) / math.factorial(2), (-1.0 / 30.0) / math.factorial(4), (1.0 / 42.0) / math.factorial(6), (-1.0 / 30.0) / math.factorial(8), (5.0 / 66.0) / math.factorial(10), (-691.0 / 2730.0) / math.factorial(12), (7.0 / 6.0) / math.factorial(14), ] def zeta_em(s, N=None): """High-precision Euler-Maclaurin analytic continuation of Riemann zeta(s).""" s = complex(s) if N is None: N = max(20, int(abs(s.imag)) + 14) if abs(s - 1.0) < 1e-14: return complex(float('inf'), 0.0) total = 0.0j for n in range(1, N): total += n ** (-s) N_ms = N ** (-s) total += (N * N_ms) / (s - 1.0) + 0.5 * N_ms # Asymptotic Bernoulli tail inv_N2 = 1.0 / (N * N) term_pow = N_ms / N # N^{-(s+1)} rising = s # s for k, b_over_f in enumerate(BERN_DIV_FACT, start=1): total += b_over_f * rising * term_pow # Update rising -> rising * (s + 2k - 1) * (s + 2k) for next k rising *= (s + 2*k - 1) * (s + 2*k) term_pow *= inv_N2 return total # Lanczos 9-term complex Gamma (g=7, ~15 digits) LANCZOS_P = [ 0.99999999999980993, 676.5203681218851, -1259.1392167224028, 771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7, ] def cgamma(z): z = complex(z) if z.real < 0.5: return math.pi / (cmath.sin(math.pi * z) * cgamma(1.0 - z)) z -= 1.0 x = LANCZOS_P[0] for i, p in enumerate(LANCZOS_P[1:], start=1): x += p / (z + i) t = z + 7.5 return math.sqrt(2.0 * math.pi) * (t ** (z + 0.5)) * cmath.exp(-t) * x def cloggamma(z): # Principal log Gamma for Re(z) > 0.5 via Lanczos z = complex(z) - 1.0 x = LANCZOS_P[0] for i, p in enumerate(LANCZOS_P[1:], start=1): x += p / (z + i) t = z + 7.5 return 0.5*math.log(2.0*math.pi) + (z + 0.5)*cmath.log(t) - t + cmath.log(x) def hardy_Z(t): # Riemann-Siegel theta(t) = Im(log Gamma(1/4 + i*t/2)) - (t/2)*log(pi) theta = cloggamma(complex(0.25, 0.5 * t)).imag - 0.5 * t * math.log(math.pi) val = cmath.exp(1j * theta) * zeta_em(complex(0.5, t)) return val.real, abs(val.imag) def winding_number(f, center, radius, steps=160): total_darg = 0.0 prev = f(center + radius) for k in range(1, steps + 1): ang = 2.0 * math.pi * k / steps cur = f(center + radius * cmath.exp(1j * ang)) ratio = cur / prev total_darg += cmath.phase(ratio) prev = cur return total_darg / (2.0 * math.pi) def verify_suite5(): print("=== SUITE 5: RIEMANN ZETA CRITICAL STRIP, FUNCTIONAL EQ & FIRST 10 ZEROS ===") # 5A. Exact special values specials = [ (2.0, math.pi**2 / 6.0), (4.0, math.pi**4 / 90.0), (0.0, -0.5), (-1.0, -1.0 / 12.0), (-2.0, 0.0), (-3.0, 1.0 / 120.0), (-4.0, 0.0), ] max_spec = max(abs(zeta_em(s) - exact) for s, exact in specials) assert max_spec < 5e-13, f"Special zeta values err: {max_spec}" # 5B. Gamma reflection formula Gamma(s)*Gamma(1-s) = pi/sin(pi*s) max_gref = max( abs(cgamma(s) * cgamma(1.0 - s) - math.pi / cmath.sin(math.pi * s)) for s in (0.3+1.2j, -1.4+2.7j, 0.5+14.13j, 2.3-4.1j) ) assert max_gref < 1e-12, f"Gamma reflection err: {max_gref}" # 5C. Riemann Functional Equation across critical strip: # zeta(s) = 2^s * pi^(s-1) * sin(pi*s/2) * Gamma(1-s) * zeta(1-s) max_fe = 0.0 for sig in (0.2, 0.35, 0.5, 0.75, 1.3): for t in (1.5, 7.2, 14.13, 25.0, 38.4): s = complex(sig, t) lhs = zeta_em(s) rhs = (2.0**s) * (math.pi**(s - 1.0)) * cmath.sin(0.5*math.pi*s) * cgamma(1.0 - s) * zeta_em(1.0 - s) max_fe = max(max_fe, abs(lhs - rhs)) assert max_fe < 1e-11, f"Riemann Functional Eq err: {max_fe}" # 5D. Locate first 10 non-trivial zeros on Re(s) = 1/2 via Hardy Z(t) bisection brackets = [ (13.5, 14.5), (20.5, 21.5), (24.5, 25.5), (30.0, 31.0), (32.5, 33.5), (37.0, 38.0), (40.5, 41.5), (42.8, 43.8), (47.5, 48.5), (49.3, 50.3), ] zeros = [] max_imag_Z = 0.0 max_zero_res = 0.0 for a, b in brackets: za, ia = hardy_Z(a) zb, ib = hardy_Z(b) max_imag_Z = max(max_imag_Z, ia, ib) assert za * zb < 0.0, f"No sign change in [{a}, {b}]" for _ in range(65): m = 0.5 * (a + b) zm, im = hardy_Z(m) max_imag_Z = max(max_imag_Z, im) if za * zm <= 0.0: b = m else: a, za = m, zm g = 0.5 * (a + b) zeros.append(g) max_zero_res = max(max_zero_res, abs(zeta_em(complex(0.5, g)))) assert max_imag_Z < 1e-11, f"Hardy Z(t) imaginary part too big: {max_imag_Z}" assert max_zero_res < 1e-11, f"Zero residual too big: {max_zero_res}" # 5E. Argument Principle Winding Numbers: +1 around each zero, -1 around pole s=1 w_pole = winding_number(zeta_em, complex(1.0, 0.0), 0.25) assert abs(w_pole - (-1.0)) < 1e-11, f"Pole s=1 winding: {w_pole}" max_w_err = 0.0 for g in zeros: w = winding_number(zeta_em, complex(0.5, g), 0.25) max_w_err = max(max_w_err, abs(w - 1.0)) assert max_w_err < 1e-11, f"Zero winding err: {max_w_err}" print(f" Special values zeta(2,4,0,-1,-2,-3,-4): max err={max_spec:.2e}") print(f" Gamma Reflection Formula: max err={max_gref:.2e}") print(f" Riemann Functional Eq (25 strip pts): max err={max_fe:.2e}") print(f" Hardy Z(t) reality & First 10 Zeros: max |Im Z|={max_imag_Z:.2e}, max |zeta(1/2+ig)|={max_zero_res:.2e}") print(f" Zeros gamma_1..10: {', '.join(f'{g:.6f}' for g in zeros[:5])} ... {zeros[-1]:.6f}") print(f" Argument Principle Winding: pole s=1 -> {w_pole:+.12f}; all 10 zeros -> +1 (err={max_w_err:.2e})") print(" [PASS] SUITE 5\n") if __name__ == "__main__": verify_suite1() verify_suite2() verify_suite3() verify_suite4() verify_suite5() print("ALL 5 CELESTIAL & DYNAMICAL ATELIER SUITES PASSED TO MACHINE PRECISION!")