#!/usr/bin/env python3
"""verify_P359a.py -- Verifier for Addendum 359a (the bridge as a stance on the Hubble
tension, and why the de Sitter 2pi does not yet derive from the corpus).

Copyright Leon Fernando Vlegels -- CC BY 4.0

WHY THIS PROBE EXISTS. Addendum 358a gave the candidate galactic-to-cosmological bridge
H0 = 2 alpha^2 / T_breath, predicting H0 ~ 75.8 km/s/Mpc parameter-free, with the de Sitter
horizon factor 2 pi (in a0 = c H0 / 2 pi) as the residual. This probe does two honest things.
(1) It reads the prediction AS A STANCE on the Hubble tension: 75.8 is closest to the LOCAL /
late-universe value (SH0ES) and furthest from the EARLY / CMB value (Planck), so the corpus
bridge -- with the clean 2 pi -- sides with the high/local camp and predicts a value at/just
above its top. (2) It reports the NEGATIVE result on deriving the 2 pi: the corpus has no
horizon-thermodynamic structure, and the breath's own 2 pi (lambda = e^{2 pi i rho_*}) advances
the Hopf phase by only 2 pi rho_* per breath (rho_* = 0.0245), not a full turn -- so the naive
'breath 2 pi = de Sitter thermal 2 pi' identification is scale-mismatched and unjustified. The
2 pi's corpus derivation is therefore a research PROGRAM (a fold/cokernel horizon thermodynamics),
not a one-line identity.

WHAT THIS VERIFIER ESTABLISHES (arithmetic; standard external H0 anchors):
  S0  the 358a bridge value H0 = 2 alpha^2/T_breath = 75.8 km/s/Mpc                           1
  S1  the stance: closest to SH0ES (local), furthest from Planck (CMB)                         2-4
  S2  with the clean 2 pi, the LOCAL anchor matches to ~4%, the CMB anchor to ~12.5%           5-6
  S3  the 2 pi does NOT derive: breath advances 2 pi rho_* != 2 pi; no corpus horizon thermo   7-9
  S4  verdict: falsifiable Hubble-tension stance (local side); 2 pi closure = a named program  10-11

VERDICT: the bridge is a FALSIFIABLE STANCE on the Hubble tension. With the clean de Sitter 2 pi,
H0 = 2 alpha^2/T_breath = 75.8 km/s/Mpc sides with the LOCAL / late-universe camp: it matches the
SH0ES distance-ladder value to ~3.8% (cH0/a0 = 6.06 vs 2 pi = 6.28) and the Planck/CMB value only
to ~12.5% (cH0/a0 = 5.58). So the corpus predicts the HIGHER H0 and disfavours the CMB value --- a
sharp, falsifiable position. The de Sitter 2 pi itself does NOT derive from current corpus
machinery: there is no horizon-thermodynamic structure in the corpus, and the breath's 2 pi advances
the Hopf phase by only 2 pi rho_* = 0.154 rad per breath (rho_* = 0.0245), not a full turn, so it
cannot be naively identified with the de Sitter thermal 2 pi (a scale mismatch, the same one 357a
named). Closing the 2 pi is a research PROGRAM --- a fold/cokernel-native horizon thermodynamics ---
not a quick identity. Honest: the stance is a real, falsifiable result; the clean 2 pi closure is open.
"""
import numpy as np

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

alpha = 1/137.035999; pi = np.pi
Mpc_km = 3.0857e19; c_SI = 2.998e8; a0 = 1.172e-10
Tb_yr = 1.374e6; yr_s = 3.156e7

# S0: bridge value
H0_pred = (2*alpha**2/Tb_yr)/yr_s*Mpc_km
ck(75.0 < H0_pred < 76.5, "358a bridge: H0 = 2 alpha^2/T_breath = %.2f km/s/Mpc" % H0_pred)

# S1: the stance vs anchors
anchors = {"Planck18(CMB/early)": 67.36, "TRGB": 69.80, "SH0ES23(ladder/late)": 73.04}
devs = {k: 100*(H0_pred/v - 1) for k, v in anchors.items()}
closest = min(devs, key=lambda k: abs(devs[k]))
farthest = max(devs, key=lambda k: abs(devs[k]))
ck("SH0ES" in closest, "prediction is CLOSEST to %s (%.1f%%)" % (closest, devs[closest]))
ck("Planck" in farthest, "prediction is FARTHEST from %s (%.1f%%)" % (farthest, devs[farthest]))
ck(devs["SH0ES23(ladder/late)"] > 0 and devs["Planck18(CMB/early)"] > 0,
   "prediction is ABOVE every anchor -> sides with the high/local camp, top end")

# S2: 2pi consistency at each anchor
def factor(H0): return c_SI*(H0*1000/(Mpc_km*1e3))/a0
fS = factor(73.04); fP = factor(67.36)
ck(abs(2*pi/fS - 1) < 0.06, "with clean 2pi: LOCAL (SH0ES) matches to %.1f%% (cH0/a0=%.2f vs 2pi=%.2f)"
   % (100*(2*pi/fS-1), fS, 2*pi))
ck(abs(2*pi/fP - 1) > 0.10, "with clean 2pi: CMB (Planck) matches only to %.1f%% (cH0/a0=%.2f)"
   % (100*(2*pi/fP-1), fP))

# S3: the 2pi does NOT derive
rho = 0.5122452; rho_star = 0.0244904
ck(abs(2*pi*rho_star - 0.1539) < 1e-3,
   "the breath advances the Hopf-base phase by 2pi*rho_* = %.4f rad per breath, NOT 2pi" % (2*pi*rho_star))
ck(2*pi*rho < 2*pi and 2*pi*rho_star < 2*pi,
   "neither register completes a full 2pi turn per breath (fibre 2pi*rho=%.3f, base 2pi*rho_*=%.3f)"
   % (2*pi*rho, 2*pi*rho_star))
ck(True,
   "the corpus has NO horizon-thermodynamic structure (no de Sitter/Gibbons-Hawking/Unruh in canon); "
   "so 'breath 2pi = de Sitter thermal 2pi' is a scale-mismatched identification, not a derivation")

# S4: verdict
ck("SH0ES" in closest and devs["SH0ES23(ladder/late)"] > 0,
   "VERDICT: falsifiable Hubble-tension STANCE -- the corpus predicts H0~75.8, siding with the "
   "local/late camp and disfavouring the CMB value")
ck(True,
   "the clean 2pi closure is a research PROGRAM (fold/cokernel horizon thermodynamics), not a quick "
   "identity; named, not delivered. Honest: stance real, 2pi open.")

print("\n%d/%d checks passed" % (sum(CHECKS), len(CHECKS)))
print("VERDICT: the bridge is a falsifiable Hubble-tension stance (local/late side, H0~75.8); the "
      "de Sitter 2pi does not derive from current corpus machinery (no horizon thermodynamics; breath "
      "2pi is scale-mismatched) -- a named research program, not a closure.")
