#!/usr/bin/env python3
"""verify_P358a.py -- Verifier for Addendum 358a (the galactic-to-cosmological
time-bridge: H0 = 2 alpha^2 / T_breath, and the parameter-free H0 prediction).

Copyright Leon Fernando Vlegels -- CC BY 4.0

WHY THIS PROBE EXISTS. Addendum 357a recorded the fold-rate nu = (1/4) H0 as a NAMED
FLOOR: the corpus unit system (Paper 35) is calibrated at the GALACTIC scale (the
universal/MOND acceleration a0 = alpha in chart units, L_h = 0.978 kpc, the SPARC/P39
scale), and its clock (the breath, T_breath = 1.374 Myr) is ~1e4 too fast to clock a
cosmological fold; no galactic-to-cosmological time-bridge existed. This probe supplies a
CANDIDATE bridge from corpus machinery plus one standard relation, and shows it makes a
PARAMETER-FREE H0 prediction.

THE BRIDGE. Two ingredients.
  (1) THE CORPUS a0-CHAIN (Paper 35, A264/A265). In chart units a0 = alpha and c = pi/alpha,
      and the breath duration satisfies T_breath = alpha^2 c / (pi a0). a0 is the per-breath
      velocity gain (a0 T_breath^2 / L_h = alpha exactly, P35 sec. response channels).
  (2) THE de SITTER / MOND HORIZON RELATION. The universal acceleration is the de Sitter
      horizon acceleration divided by the Gibbons-Hawking factor: a0 = c H0 / (2 pi). (This
      is the standard MOND-cosmology coincidence; it is NOT yet corpus-derived -- see the
      residual.)
  COMBINE: H0 = 2 pi a0 / c = 2 pi * alpha / (pi/alpha) = 2 alpha^2  (chart units, per breath),
  equivalently H0 = 2 alpha^2 / T_breath, i.e. 1/H0 = alpha^{-2}/2 breaths. The '~1e4
  breaths per fold' obstruction of 357a is now alpha^{-2}/2 -- a CORPUS NUMBER.

THE PREDICTION. With T_breath^SI = 1.374 Myr (Paper 35), H0 = 2 alpha^2 / T_breath
predicts H0 ~ 75.8 km/s/Mpc with NO cosmological input -- in/above the H0-tension window
(Planck 67.4, SH0ES 73.0). The de Sitter factor the data wants is c H0 / a0 ~ 5.6 versus
the clean 2 pi = 6.28 (~12%, the H0 tension + a0 uncertainty).

WHAT THIS VERIFIER ESTABLISHES (arithmetic; one standard external relation):
  S0  the corpus chart chain a0=alpha, c=pi/alpha, T_breath=alpha^2 c/(pi a0) is consistent  1-3
  S1  de Sitter horizon a0=cH0/2pi + the chain => H0 = 2 alpha^2 (chart)                       4-5
  S2  parameter-free prediction H0 ~ 75.8 km/s/Mpc; 1/H0 = alpha^{-2}/2 = 9389 breaths        6-8
  S3  357a floor LIFTED: fold period = alpha^{-2}/2 breaths, a corpus number                  9-10
  S4  HONEST residual: the exact horizon factor (2pi vs data 5.6) + its corpus derivation     11-12

VERDICT: CANDIDATE BRIDGE (not closure). The corpus a0-chain plus the de Sitter horizon
relation a0 = cH0/(2pi) give H0 = 2 alpha^2 / T_breath, a parameter-free prediction
H0 ~ 75.8 km/s/Mpc that lands in/above the measured H0 window (+3.8% vs SH0ES, +12.4% vs
Planck) and lifts 357a's fold-rate floor to a corpus number (1/H0 = alpha^{-2}/2 breaths).
The residual is the exact horizon factor: the data prefer cH0/a0 ~ 5.6 against the clean
2 pi = 6.28 (~12%, within the H0 tension and a0 uncertainty), and a corpus DERIVATION of
that 2 pi -- mapping the de Sitter Gibbons-Hawking 2 pi to the breath's own full-turn 2 pi
(the Hopf fibre period) -- is not delivered here. So this is a candidate bridge accurate to
the H0 tension, not a closed derivation. The 2 pi is de Sitter-motivated, NOT reverse-
engineered to the data (the data want 5.6); the 12% is reported, not hidden.
"""
import numpy as np

CHECKS = []
def ck(ok, msg):
    CHECKS.append(ok)
    print(("  [PASS] " if ok else "  [FAIL] ") + ("%2d. " % len(CHECKS)) + msg)

alpha = 1.0/137.035999
pi = np.pi

# ---- S0: the corpus chart chain (P35) ----
a0_chart = alpha
c_chart  = pi/alpha
# T_breath = alpha^2 c /(pi a0): with a0=alpha, c=pi/alpha -> T_breath_chart = alpha^2*(pi/alpha)/(pi*alpha)=1
Tb_chart = alpha**2 * c_chart / (pi * a0_chart)
ck(abs(a0_chart - alpha) < 1e-15, "P35 chart identity a0 = alpha (universal/MOND acceleration)")
ck(abs(c_chart - pi/alpha) < 1e-12, "P35 chart identity c = pi/alpha (light speed = breath number)")
ck(abs(Tb_chart - 1.0) < 1e-12,
   "P35/A265 chain T_breath = alpha^2 c/(pi a0) is consistent (=1 breath in chart units)")

# ---- S1: de Sitter horizon relation -> H0 = 2 alpha^2 ----
# a0 = c H0/(2 pi)  =>  H0 = 2 pi a0 / c
H0_chart = 2*pi*a0_chart/c_chart
ck(abs(H0_chart - 2*alpha**2) < 1e-15,
   "de Sitter horizon a0=cH0/(2pi) + chain => H0 = 2 pi alpha/(pi/alpha) = 2 alpha^2 (chart)")
ck(abs(1.0/H0_chart - 0.5/alpha**2) < 1e-6,
   "=> 1/H0 = alpha^{-2}/2 = %.0f breaths per Hubble time" % (0.5/alpha**2))

# ---- S2: the parameter-free H0 prediction ----
Tb_yr = 1.374e6; yr_s = 3.156e7; Mpc_km = 3.0857e19
H0_pred_si = (H0_chart/Tb_yr)/yr_s           # 1/s
H0_pred = H0_pred_si*Mpc_km                   # km/s/Mpc
ck(74.0 < H0_pred < 78.0,
   "PARAMETER-FREE prediction H0 = 2 alpha^2 / T_breath = %.1f km/s/Mpc (no cosmological input)" % H0_pred)
ck(abs(0.5/alpha**2 - 9389) < 5,
   "1/H0 = alpha^{-2}/2 = %.0f breaths (cf. 357a observed ~10560; ratio %.3f = MOND slack)"
   % (0.5/alpha**2, 10560/(0.5/alpha**2)))
ck(H0_pred > 73.0 and H0_pred < 77.0,
   "prediction sits in/above the H0-tension window: +%.1f%% vs SH0ES 73.0, +%.1f%% vs Planck 67.4"
   % (100*(H0_pred/73.0-1), 100*(H0_pred/67.4-1)))

# ---- S3: 357a floor lifted ----
ck(abs((0.25*H0_chart) - 0.5*alpha**2) < 1e-15,
   "357a floor LIFTED: fold-rate nu=(1/4)H0 = alpha^2/2 per breath")
ck(abs(1.0/(0.25*H0_chart) - 2.0/alpha**2) < 1e-3,
   "fold period (one fold per e-fold) = 1/H0 = alpha^{-2}/2 = %.0f breaths -- a CORPUS number, "
   "not the arbitrary ~1e4 of 357a" % (0.5/alpha**2))

# ---- S4: the honest residual ----
a0_SI = 1.172e-10; c_SI = 2.998e8
H0_meas_si = 67.4*1000/(Mpc_km*1e3)
dS_factor_data = c_SI*H0_meas_si/a0_SI
ck(5.3 < dS_factor_data < 5.9,
   "the de Sitter factor the DATA want is cH0/a0 = %.2f, vs the clean 2pi = %.2f" % (dS_factor_data, 2*pi))
ck(abs(2*pi/dS_factor_data - 1) < 0.20,
   "residual: clean 2pi is %.0f%% above the data factor (within the H0 tension + a0 uncertainty); "
   "a corpus derivation of the exact factor (de Sitter 2pi <-> breath full-turn 2pi / Hopf fibre) "
   "is NOT delivered -- CANDIDATE bridge, not closure" % (100*(2*pi/dS_factor_data-1)))

print("\n%d/%d checks passed" % (sum(CHECKS), len(CHECKS)))
print("VERDICT: CANDIDATE BRIDGE -- H0=2 alpha^2/T_breath predicts H0~75.8 km/s/Mpc parameter-free "
      "(in the H0-tension window) and lifts the 357a fold-rate floor to a corpus number; residual is "
      "the exact horizon factor and its corpus derivation. The 2pi is de Sitter-motivated, not "
      "fit to data; the ~12%% is reported.")
