#!/usr/bin/env python3
"""
Independent verification of the chi post-inflation result (appendix_chi_matter Step 5b).
Confirms: H_inf = 8*pi*f_chi (exact, alpha^3 rung); delta_theta = 4 > pi (pre-inflation excluded);
post-inflation rms misalignment overshoot ~44x; string tension G*mu = alpha^6.
All numbers reproduced to the figures quoted in the appendix.

RESOLVED (2026-06-30): the continuum pi^2/3 "44x overshoot" below uses the WRONG measure
(a uniform classical angle on a circle S^1). The actual chi state space is the finite
SU(2)_60 modular Hilbert space (61 integrable sectors), and the no-boundary closed-S^3
vacuum (Heegaard surgery) forces p_j=|S_0j|^2 -> Omega_chi h^2 = 0.1182. The continuum S^1
measure is EXCLUDED: the closed S^3 has no internal boundary on which a Cardy/annulus
weight could live (appendix_chi_matter Bricks 1-2). Reproducible: chi_modular_measure.py.
This selection is conditional on DFD's no-boundary Wheeler-DeWitt postulate.
"""
import math

# Locked constants (DFD alpha-tower)
MP    = 1.220910e19          # non-reduced Planck mass, GeV
MbarP = MP / math.sqrt(8*math.pi)   # reduced Planck mass = 2.435e18 GeV
alpha = 1.0 / 137.035999

a3    = alpha**3
f_chi = MbarP * a3                  # decay constant (Lemma chi-O4)
M_R   = MP * a3                     # Majorana rung (inflation sector)
H_star= math.sqrt(8*math.pi) * M_R  # inflationary Hubble scale

print("=== rungs ===")
print(f"alpha          = {alpha:.6e}")
print(f"f_chi          = {f_chi:.3e} GeV   (appendix 9.46e11)")
print(f"M_R            = {M_R:.3e} GeV   (appendix 4.74e12)")
print(f"H_star         = {H_star:.3e} GeV (appendix 2.38e13)")

print("\n=== the exact relation H_inf = 8 pi f_chi ===")
ratio = H_star / f_chi
print(f"H_star/f_chi   = {ratio:.4f}   8pi = {8*math.pi:.4f}   (exact: sqrt(8pi)*sqrt(8pi)=8pi)")
assert abs(ratio - 8*math.pi) / (8*math.pi) < 1e-3

print("\n=== pre-inflation EXCLUDED ===")
dtheta = H_star / (2*math.pi*f_chi)
print(f"delta_theta    = H_inf/(2 pi f_chi) = {dtheta:.4f}   (> pi = {math.pi:.4f}? {dtheta>math.pi})")
print("  => angle randomized during inflation; single homogeneous theta_i impossible.")

print("\n=== abundance: continuum pi^2/3 'overshoot' -- the EXCLUDED wrong measure ===")
theta_i   = math.sqrt(0.12/1.62)
Omega_pre = 1.62 * theta_i**2
mean_th2  = math.pi**2 / 3.0          # <theta^2> for uniform angle on (-pi,pi]
Omega_post= 1.62 * mean_th2
print(f"theta_i (pre, tuned)            = {theta_i:.3f}  -> Omega_chi h^2 = {Omega_pre:.4f} (target 0.12)")
print(f"<theta^2>_post = pi^2/3         = {mean_th2:.4f}")
print(f"Omega_chi h^2 (post, rms)       = {Omega_post:.3f}")
print(f"OVERSHOOT factor               = {Omega_post/0.12:.1f}x  (continuum S^1 measure -- EXCLUDED;")
print(f"                                          forced value 0.1182 in chi_modular_measure.py)")

print("\n=== string tension (safe) ===")
Gmu = (f_chi/MbarP)**2
print(f"G*mu = (f_chi/MbarP)^2 = alpha^6 = {Gmu:.3e}   (PTA/CMB bound ~1e-11 => safe)")

print("\n=== domain-wall number ===")
print("N_DW = anomaly index of chi F Fdual = S^3 winding int_{S^3} omega_3 = 1  => N_DW = 1 (safe)")
print("\nAll appendix Step-5b numbers reproduced. The continuum pi^2/3 overshoot is the EXCLUDED")
print("wrong measure (chi state space is finite SU(2)_60, not S^1); the forced Omega_chi h^2=0.1182")
print("is in chi_modular_measure.py, conditional on DFD's no-boundary Wheeler-DeWitt postulate.")
