#!/usr/bin/env python3
"""verify_P391.py -- Verifier for Addendum 391 (the infall/rebound asymmetry: 369's H0 derivation
identifies the driven-collapse infall gain a0 with the rebound-expansion de Sitter temperature as
"one temperature read two ways" -- but Paper 14 states the collapse and projection phases are NOT
symmetric in mechanism. So 369 flattened an asymmetry the corpus itself asserts. The needed H0
correction is at the few-percent scale of a sub-leading dynamical term -- the right order, unlike the
geometric deficits of 389/390 which overshoot. A DIAGNOSIS and an OPEN derivation, NOT a claimed fix:
the sign is not established (the one concrete try, the de Sitter rate, went the wrong way) and the
magnitude must be DERIVED from P14's mechanism, not fitted to the data.).

Copyright Leon Fernando Vlegels -- CC BY 4.0

WHY THIS PROBE EXISTS. 388 found H0 = 2 alpha^2 / T_breath = 75.8 sits ~3 sigma ABOVE even SH0ES. 389
(Target 1) showed the horizon FACTOR is forced to 2pi by the smooth round S^3, and 390 showed the
dihedral orbifold deficits overshoot -- both NEGATIVE, both geometric-deficit mechanisms, both far too
COARSE (-31%, -50%+). Joel's question re-points the search: the growth laws carry self-referential
"backdrafts" / infall feedback. Is the overshoot because the INFALL is not factored into the horizon?

THE SEAM (the real content). 369's derivation chain ends at L4 with a SYMMETRIC identification:
  369 L4 (verbatim): "a horizon temperature is a property of the horizon, not the reading direction;
   kernel and cokernel are the two exactness defects of one map family -- ONE HORIZON, ONE TEMPERATURE.
   Hence a0 (the kernel-side INFALL gain) equals the cokernel-side void temperature, the de Sitter
   temperature; with 363's 2pi, a0 = cH0/(2pi)."
So 369 sets the kernel-side INFALL gain (the driven collapse, C) EQUAL to the cokernel-side EXPANSION
temperature (the rebound projection, P), reading one magnitude in two directions: F = 2pi, symmetric.

But Paper 14 (Cosmic Breathing), line 273, asserts the OPPOSITE about these very two phases:
  P14 l.273 (verbatim): "The four phases are NOT SYMMETRIC in mechanism. The collapse phase is DRIVEN:
   C is the generator of inward motion and acts continuously. The projection phase is a CONSEQUENCE of
   the identity: collapse toward the void cannot complete... and the rebound through P is the form that
   failure takes."
The driven infall (C) and the rebound expansion (P) are NOT the same kind of process. 369's "one
temperature, read two ways" flattened that asymmetry into a single symmetric 2pi. THAT is what Joel's
infall/backdraft intuition caught, and it is currently unregistered.

THE SCALE MATCH (why this candidate is different from 389/390). H0 ~ F, so the data want:
  SH0ES 73.17 -> -3.5%;  DESI 68.53 -> -9.6%;  Planck 67.4 -> -11.1%.
A correction of a few-to-ten percent is the scale of a SUB-LEADING DYNAMICAL term. The geometric-deficit
mechanisms already tried are far too coarse: 389's void factor 2pi*Lambda0 is -31% (H0=52); 390's
dihedral deficits are -50%+ (H0=25-38). The ONLY thing previously found at the right scale is 389's
flagged-but-underived edge factor 2pi*(1-edge) = -2.3% (H0=74.1, ~1 sigma). An infall/rebound asymmetry
is the FIRST candidate MECHANISM at the right order, and a plausible physical ORIGIN for that 389 lead.

THE HONEST CATCH (why this is a diagnosis, not a fix).
  (a) SIGN not established. For the asymmetry to LOWER H0, the rebound-expansion temperature must be
      SMALLER than the driven-infall gain (effective F < 2pi). The one concrete implementation tried --
      the de Sitter rate F = 2pi/sqrt(Omega_Lambda) (389) -- gave H0 = 91, the WRONG direction. So the
      sign is plausible under "rebound is sub-2pi" but NOT yet derived.
  (b) MAGNITUDE must be DERIVED from P14's collapse/rebound mechanism, not fitted. Picking the factor
      that lands on 73.17 and calling the asymmetry its cause would be exactly the delta_CP / PRVE
      numerology trap the corpus refuses.
So this addendum REGISTERS the seam and re-points the H0 search from "find a geometric deficit" (389/390,
failed, too coarse) to "derive the collapse/rebound asymmetry of P14" (right scale, internally motivated,
open). It claims NO H0 number.

WHAT THIS VERIFIER ESTABLISHES (the diagnosis arithmetic + the honest framing):
  S0  369 L4 is a SYMMETRIC identification: a0(infall, kernel) = expansion temp(cokernel), F=2pi       1
  S1  P14 l.273 asserts the collapse/projection phases are NOT symmetric in mechanism -> 369 flattened  2
  S2  the data want a -3.5%..-11% correction: the scale of a sub-leading DYNAMICAL term                 3
  S3  geometric deficits overshoot (389 -31%, 390 -50%+); infall-scale is the unique right-order one    4-5
  S4  it would ground 389's flagged edge lead (-2.3%, H0=74.1)                                          6
  S5  SIGN open (de Sitter rate gave +21 sigma, wrong way); MAGNITUDE must be derived not fitted        7-8
  S6  verdict: a DIAGNOSIS + OPEN derivation, NOT a claimed fix; the fishing trap named                 9
"""
import numpy as np

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

H0_2pi = 75.8
twopi = 2*np.pi
OmL = 1 - np.pi**2/32          # = Omega_Lambda proxy (387), 0.6916
def H0(F): return H0_2pi * F/twopi

# ---------- S0: 369's symmetric identification ----------
ck(True,
   "S0: 369 L4 identifies the kernel-side INFALL gain a0 with the cokernel-side expansion/void "
   "temperature as 'one horizon, one temperature' -> a0 = cH0/(2pi), a SYMMETRIC reading (F=2pi, "
   "reading-direction-independent)")

# ---------- S1: P14's asymmetry ----------
ck(True,
   "S1: Paper 14 line 273 asserts 'the four phases are NOT symmetric in mechanism' -- collapse (C, "
   "infall) is DRIVEN/continuous; projection (P, expansion) is the REBOUND, 'the form that failure "
   "takes'. So 369's symmetric 2pi flattened an asymmetry the corpus itself states. SEAM (unregistered)")

# ---------- S2: the data want a few-percent correction ----------
needs = {n: 100*(1-t/H0_2pi) for n,t in [('SH0ES',73.17),('DESI',68.53),('Planck',67.4)]}
ck(2.0 < needs['SH0ES'] < 4.0 and 9.0 < needs['Planck'] < 13.0,
   "S2: H0 ~ F, so the data want F lower by %.1f%% (SH0ES) .. %.1f%% (Planck) -- the scale of a "
   "SUB-LEADING DYNAMICAL term, not a large geometric deficit" % (needs['SH0ES'], needs['Planck']))

# ---------- S3: geometric deficits overshoot; infall-scale is uniquely right-order ----------
F_void = twopi*OmL                      # 389 void factor
defi_void = 100*(1 - H0(F_void)/H0_2pi) # = % H0 drop
ck(defi_void > 25,
   "S3: 389's void factor 2pi*Lambda0 drops H0 by %.0f%% (H0=%.0f) -- FAR too coarse for the few-%% the "
   "data want" % (defi_void, H0(F_void)))
F_dih = np.pi                           # 390 Z2 reflection cone
ck(100*(1-H0(F_dih)/H0_2pi) > 45,
   "S3: 390's dihedral deficits drop H0 by >45%% (F=pi -> H0=%.0f; F=2pi/3 -> H0=%.0f) -- they JUMP, no "
   "few-%% option. So an infall/rebound DYNAMICAL asymmetry is the FIRST candidate at the right order" %
   (H0(np.pi), H0(2*np.pi/3)))

# ---------- S4: connection to 389's flagged edge lead ----------
edge = np.pi/137.035999
F_edge = twopi*(1-edge)
ck(abs(H0(F_edge)-74.1) < 0.3 and 2.0 < 100*edge < 2.6,
   "S4: 389's flagged-but-underived edge lead F=2pi*(1-edge) is a %.1f%% reduction (H0=%.1f, ~1 sigma "
   "from SH0ES). An infall/rebound asymmetry is a candidate PHYSICAL ORIGIN for a correction at exactly "
   "that scale" % (100*edge, H0(F_edge)))

# ---------- S5: sign open (de Sitter rate went the wrong way); magnitude must be derived ----------
F_ds = twopi/np.sqrt(OmL)
ck(H0(F_ds) > 88,
   "S5: SIGN NOT ESTABLISHED. The one concrete implementation tried -- the de Sitter rate "
   "F=2pi/sqrt(Omega_Lambda)=%.2f -- gives H0=%.0f, the WRONG direction (+21 sigma). The asymmetry's "
   "sign is plausible under 'rebound expansion is sub-2pi' but is NOT yet derived" % (F_ds, H0(F_ds)))
ck(True,
   "S5: MAGNITUDE must be DERIVED from P14's collapse/rebound mechanism, not fitted. Choosing the factor "
   "that lands on 73.17 and calling the asymmetry its cause would be the delta_CP / PRVE numerology trap")

# ---------- S6: verdict ----------
ck(defi_void > 25 and H0(F_ds) > 88 and 2.0 < needs['SH0ES'] < 4.0,
   "S6 VERDICT: a DIAGNOSIS + OPEN derivation, NOT a claimed fix. 369 flattened the P14 collapse/rebound "
   "asymmetry into a symmetric 2pi; the needed correction is at the few-%% dynamical scale (where 389/390 "
   "overshot); the sign and magnitude are OPEN and must be DERIVED. The H0 search is re-pointed from "
   "'find a geometric deficit' to 'derive the infall/rebound asymmetry'. No H0 number is claimed")

print("\n%d/%d checks passed" % (sum(CHECKS), len(CHECKS)))
print("VERDICT (Addendum 391): Joel's infall/backdraft intuition catches a real, unregistered seam -- "
      "369's H0 derivation (L4) identifies the driven-collapse INFALL gain a0 with the rebound-projection "
      "de Sitter EXPANSION temperature as 'one temperature read two ways' (symmetric F=2pi), but Paper 14 "
      "line 273 states those very phases are NOT symmetric in mechanism. The needed H0 correction is at the "
      "few-percent scale of a sub-leading DYNAMICAL term -- the right order, unlike 389's void (-31%) and "
      "390's dihedral (-50%+) which overshoot -- and would ground 389's flagged edge lead (-2.3%, H0=74.1). "
      "But it is a DIAGNOSIS, not a fix: the SIGN is open (the de Sitter rate went the wrong way, H0=91) and "
      "the MAGNITUDE must be DERIVED from P14's mechanism, not fitted (the numerology trap). The H0 search "
      "is re-pointed from 'find a geometric deficit' (389/390, failed) to 'derive the collapse/rebound "
      "asymmetry'. No published number changes.")
