"""v163 -- F_transfer scale-tagging: the TFPT lepton-mixing predictions are
RG-STABLE outputs, while the quark mass-ratio readouts carry a scale tag.

The compiler reads its flavor observables as dimensionless seeds (phi0-ladder).
A fair confrontation with experiment must ask at WHICH renormalization scale a
seed is a prediction, and whether RG transport between that scale and the
measurement scale shifts it. PyR@TE makes the answer structural: every Yukawa
beta is proportional to its own coupling, and the only mixing-ROTATING term is
(3/2) Y Y^dagger Y, whose size is the largest Yukawa eigenvalue squared
(verification/pyrate/sm_yukawa_betas.txt). Hence:

  [I] 1. LEPTON MIXING IS y_tau^2-SUPPRESSED.  The PMNS angles run only through
         the charged-lepton Y_e Y_e^dagger eigenvalue gap = y_tau^2 ~ 1.0e-4.
         The natural one-loop running scale from the seam/scalaron scale
         (M_scal = c3^{7/2} Mbar ~ 3e13 GeV) down to M_Z is
         kappa_tau = y_tau^2/(16 pi^2) * ln(M_scal/M_Z) ~ 1.8e-5.
  [I] 2. THE LEPTON PREDICTIONS ARE RG-STABLE.  With the TFPT spectrum (normal
         ordering, hierarchical => no quasi-degenerate enhancement, factor O(1)),
         |Delta sin^2 theta_ij| <~ kappa_tau is two to three orders below current
         precision (sin^2 th12 +-0.013, sin^2 th13 +-0.0007). So the seeds
         sin^2 th12 = 1/3 - phi0/2 = 0.3067 and sin^2 th13 = phi0 e^{-5/6} = 0.0231
         are SCALE-INDEPENDENT F_transfer outputs: seam value = measured value.
  [I] 3. QUARK MASS RATIOS ARE SCALE-TAGGED.  The up-sector runs through y_t^2 ~
         0.9, so kappa_t = y_t^2/(16 pi^2) * ln ~ 0.15 = O(10-15%). The
         m_t/m_b ~ 41 readout is therefore NOT scale-free; it is defined at a
         specific scale (the EW/M_Z readout) and must be transported, unlike the
         lepton angles. (Honest asymmetry, not a defect.)
  [P] 4. F_transfer TYPING.  The lepton-mixing sector of the transfer functor is
         trivial (no scale ambiguity); the quark-mass sector is a genuine running
         map. Both beta-structures are the PyR@TE-confirmed SM Yukawa RGEs.

Scope: one-loop magnitude bound (the y^2-suppression argument), not a precision
PMNS evolution; the conclusion (lepton angles stable to << precision; quark
ratios O(10%) scale-dependent) is robust to the O(1) spectrum factor. External
backing: verification/pyrate/sm_yukawa_betas.txt (regenerated by reproduce.sh).
Ref: Antusch-Kersten-Lindner-Ratz-Schmidt 2005 (SM PMNS running). Python-only.
"""
import math
import os

from tfpt_constants import check, summary, reset, phi0, c3, Mbar

V_EW = 246.0            # GeV, Higgs vev
M_TAU = 1.77686         # GeV
MT_RUN = 163.0          # GeV, m_t(m_t) MS-bar (running mass for y_t)
M_Z = 91.1876           # GeV
LOOP = 1.0 / (16 * math.pi**2)


def run():
    reset()
    print("v163 F_transfer scale-tagging (lepton angles RG-stable; quark ratios tagged)")

    y_tau = math.sqrt(2) * M_TAU / V_EW
    y_t = math.sqrt(2) * MT_RUN / V_EW
    M_scal = float(c3)**(3.5) * float(Mbar)             # seam/scalaron scale
    t = math.log(M_scal / M_Z)
    kappa_tau = y_tau**2 * LOOP * t
    kappa_t = y_t**2 * LOOP * t

    # 1. lepton mixing is y_tau^2-suppressed
    check("LEPTON MIXING y_tau^2-SUPPRESSED: y_tau^2 ~ 1.0e-4, so the one-loop "
          "PMNS running scale kappa_tau = y_tau^2/(16pi^2) ln(M_scal/M_Z) ~ 1.8e-5 "
          "(M_scal = c3^{7/2} Mbar ~ 3e13 GeV)",
          abs(y_tau**2 - 1.04e-4) < 1e-5 and 1e-5 < kappa_tau < 3e-5)

    # 2. the lepton predictions are RG-stable (well below precision)
    prec_th13 = 7e-4         # PDG/NuFIT sin^2 th13 uncertainty (the tightest)
    prec_th12 = 1.3e-2
    enh = 5.0                # generous O(1)-O(few) spectrum enhancement for NO
    delta_max = kappa_tau * enh
    sin2_th12 = 1.0/3 - float(phi0)/2
    sin2_th13 = float(phi0) * math.exp(-5.0/6)
    check("LEPTON PREDICTIONS RG-STABLE: |Delta sin^2| <~ 5 kappa_tau ~ 9e-5 is "
          "below even the tightest precision (sin^2 th13 +-7e-4) and ~100x below "
          "sin^2 th12 +-0.013 -> the seeds sin^2 th12 = 1/3 - phi0/2 = 0.3067 and "
          "sin^2 th13 = phi0 e^{-5/6} = 0.0231 are scale-independent F_transfer outputs",
          delta_max < prec_th13 and delta_max < prec_th12
          and abs(sin2_th12 - 0.3067) < 1e-3 and abs(sin2_th13 - 0.0231) < 1e-3)

    # 3. quark mass ratios are scale-tagged (NOT scale-free)
    check("QUARK RATIOS SCALE-TAGGED: y_t^2 ~ 0.9 gives kappa_t = "
          "y_t^2/(16pi^2) ln ~ 0.15 = O(10-15%) -- 4 orders larger than the lepton "
          "running, so the m_t/m_b ~ 41 readout carries a scale tag (EW/M_Z), "
          "unlike the lepton angles",
          0.10 < kappa_t < 0.20 and kappa_t / kappa_tau > 1000)

    # 4. F_transfer typing: lepton sector trivial, quark sector a running map
    check("F_transfer TYPING [P]: the lepton-mixing transfer is trivial (no scale "
          "ambiguity, ratio kappa_t/kappa_tau = %.0f); the quark-mass transfer is a "
          "genuine running map; both are the PyR@TE-confirmed SM Yukawa RGEs"
          % (kappa_t / kappa_tau), kappa_t / kappa_tau > 1000)

    # external backing present
    here = os.path.dirname(os.path.abspath(__file__))
    ev = os.path.join(here, "pyrate", "sm_yukawa_betas.txt")
    backing = os.path.isfile(ev) and "beta_Ye" in open(ev).read()
    check("EXTERNAL BACKING: verification/pyrate/sm_yukawa_betas.txt records the "
          "PyR@TE SM Yukawa betas; the mixing-rotating term (3/2) Y Y^+ Y carries "
          "y_max^2 (y_tau^2 leptons, y_t^2 up-quarks) -- the structural source of "
          "the asymmetry", backing)

    return summary("v163 F_transfer scale-tagging")


if __name__ == "__main__":
    raise SystemExit(1 if run() else 0)
