#!/usr/bin/env python3
"""
PROVENANCE: EMPIRICAL

SCOPE NOTE, 2026-10-12 (v32.153 re-check).  The first measurement in the bin the R3
exposure names has appeared: ATLAS, boosted H -> tau tau on 140 fb^-1 of Run 2 plus
162 fb^-1 of Run 3 (arXiv:2607.22193).  Above p_T = 650 GeV it reports a signal
deficit in Run 2 and, combined, a 95 percent upper limit of 4.5 times the Standard
Model (6.5 expected); the inclusive p_T > 300 GeV signal strength is 1.16 (+0.42
-0.25 stat.).  That is a limit, not the 15 percent measurement that would exclude R3,
so the exposure stands untested; the numbers below are unchanged.

Computation 205 -- the M_* confrontation: three readings of the modal cutoff against
the LHC, and the one that survives
==============================================================================
WHAT THIS DOES.  The book says in bold that whether M_* = 4 pi m_h sqrt(2/3) = 1.285 TeV
survives the data once PST's own coupling structure is computed has not been performed,
and comp 10's survey assumed a Wilsonian effective theory with O(1) operator coefficients
at a stale M_* = 4 pi m_h = 1.573 TeV.  This file performs the confrontation under the
three readings the book's own sentences admit of what M_* does to the fields below it,
and finds that two are excluded by existing LHC measurements by enormous margins and the
third is consistent and makes near-term predictions.

THE SENTENCES.  sec:renorm: "The substrate grain l_* = hbar c/M_* imposes a physical
momentum cutoff M_* above which no field modes exist ... not a Wilsonian regulator ...
a structural property of the projection Pi."  sec:mstar: "the modal condensate and the
Higgs condensate are the same field."  sec:renorm again: "Below M_* no PST modes
propagate; the beta-functions ... are exactly those of the Standard Model."

THE READINGS.
  R1  LITERAL: no Standard Model field mode with momentum above M_* exists.
  R2  UNIVERSAL FORM FACTOR: every vertex of the projected field theory carries the
      projection's kernel, a Gaussian in momentum transfer of width M_* (the kernel comp 73
      derives for the Casimir projection, here at the grain), so every amplitude at
      momentum transfer q is multiplied by exp(-q^2/(2 M_*^2)) per vertex.
  R3  HIGGS DOUBLET ONLY: the projection acts on the field that IS the projected
      condensate, the Higgs doublet (Goldstones included), and on nothing else: every
      vertex at which the doublet meets the emergent fields carries the kernel in the
      momenta of its legs, and a vertex with no doublet leg carries none.  Gauge and
      fermion fields emerge from the internal algebra and are not projected.  The Standard
      Model below M_* is then exact except at the doublet's vertices.  This is the reading
      under which the book's one-loop Higgs self-energy, every loop of which has a doublet
      vertex, is cut at M_*, so the naturalness result of sec:naturalness-veltman stands;
      a loop with no doublet vertex (Drell-Yan, pure gauge and fermion loops) is not cut
      at M_*.

THE DATA (all 13 TeV, ATLAS).
  Jets, 3.2 fb^-1, JHEP 05 (2018) 195: inclusive jet cross sections measured to
    p_T = 3.5 TeV and dijet masses to 9 TeV, described by NNLO QCD.
  Dileptons, 139 fb^-1, JHEP 11 (2020) 005: signal regions m_ll > 2.2 TeV (ee) and
    > 2.07 TeV (mumu); observed 19 and 6 events against Standard Model backgrounds of
    12.4 +- 1.9 and 9.6 +- 2.1; highest candidate at m_ee = 4.06 TeV; 95 percent lower
    limits on the contact-interaction scale Lambda of 35.8 (LL), 32.5 (LR), 32.3 (RL),
    35.5 (RR) TeV for constructive and 26.0, 28.8, 28.8, 26.5 TeV for destructive
    interference, with g^2/4pi = 1.
  Higgs couplings, 139 fb^-1, Nature 607 (2022) 52: kappa_V = 1.035 +- 0.031,
    kappa_F = 0.95 +- 0.05, global mu = 1.05 +- 0.06.
  Higgs pairs, 126 to 139 fb^-1, Phys. Lett. B 843 (2023) 137745: mu_HH < 2.4
    observed (2.9 expected) at 95 percent.
  Boosted Higgs, 136 fb^-1, Phys. Rev. D 105 (2022) 092003: H -> bb at large p_T,
    95 percent limits of 115 fb above 450 GeV and 9.6 fb above 1 TeV against Standard
    Model predictions of 18.4 fb and 0.13 fb.
  Same-sign WW scattering, 139 fb^-1, JHEP 04 (2024) 026: electroweak fiducial cross
    section 2.92 +- 0.22 (stat) +- 0.19 (syst) fb, consistent with the Standard Model.

RESULTS.
  1. R1 IS EXCLUDED, AND NOT NARROWLY.  R1 predicts zero events with any parton momentum
     above 1.285 TeV.  The dilepton signal regions alone hold 25 observed events above
     2 TeV where the Standard Model expects 22; the Poisson probability of 25 or more
     under a mean of zero is zero to every decimal, and the jet spectra extend to
     seven times M_* in dijet mass with NNLO agreement.  The sentence "no field modes
     above M_*" cannot refer to the momenta of Standard Model quanta.
  2. R2 IS EXCLUDED BY THE SAME SIGNAL REGIONS.  A Gaussian kernel of width M_* on the
     two vertices of Drell-Yan multiplies the yield at m_ll by exp(-m_ll^2/M_*^2):
     0.053 at 2.2 TeV, so the expected 12.4 dielectron events become 0.66 and 19 are
     observed, a deficit the data exclude at p = 1e-20; the same kernel expanded to first
     order is a contact interaction, and matching its coefficient to the paper's
     Lagrangian gives an equivalent Lambda of 13 to 16 TeV against limits of 26 to 36
     TeV, so even the linearised reading fails by a factor four to seven in 1/Lambda^2.  The data
     require any universal form-factor scale to exceed 2.7 M_* (LL, constructive).
  3. R3 IS CONSISTENT WITH EVERYTHING MEASURED, AND PREDICTS.  Every Higgs-doublet line
     carries exp(-q^2/(2 M_*^2)).  At the Higgs pole the coupling modifiers shift by
     exp(-m_h^2/(2 M_*^2)) - 1 = -0.5 percent against kappa_V = 1.035 +- 0.031 and
     kappa_F = 0.95 +- 0.05: consistent at 1.3 and 0.9 sigma.  Higgs production at
     transverse momentum p_T is suppressed by exp(-p_T^2/M_*^2): 0.88 at 450 GeV, 0.77
     at 650 GeV, 0.55 at 1 TeV, against measurements whose uncertainties are of order
     the measured value: the published fiducial limits are 115 fb above 450 GeV and
     9.6 fb above 1 TeV against Standard Model predictions of 18.4 fb and 0.13 fb.
     Higgs-pair production, weighted over the Standard Model m_HH spectrum, is
     suppressed to mu_HH = 0.73, against a limit of 2.4.  Longitudinal
     vector-boson scattering: because the whole doublet carries the kernel, the
     cancellation between gauge and Higgs exchange that keeps W_L W_L -> W_L W_L bounded
     is preserved, and the longitudinal amplitude is suppressed, not enhanced; if only the
     physical h carried it the cancellation would fail and the partial-wave bound
     |a_0| < 1/2 would break at sqrt(s) = 1.5 TeV.  The whole-doublet reading is the one
     sec:mstar states.  And the Higgs self-energy's three loops (scalar, gauge, top)
     each have a doublet vertex, so all are cut at M_* and the fine-tuning parameter
     Delta = 2.3 of sec:naturalness-veltman is unchanged; what R3 gives up is the
     sentence that every loop of the projected theory is finite, which now holds for
     every loop that touches the condensate.
  4. WHAT R3 PREDICTS FOR THE NEXT DATA.  A deficit in the Higgs p_T spectrum growing as
     1 - exp(-p_T^2/M_*^2): 23 percent above 650 GeV and 45 percent above 1 TeV, which
     the high-luminosity LHC's projected 20 to 30 percent precision in those bins can
     see; a 27 percent deficit in Higgs pairs; coupling modifiers within half a percent
     of one.  Those are the numbers the second of the three places the theory meets
     measurement now carries.
  5. comp 10 REVISITED.  Its M_* = 1.573 TeV and l_* = 1.25e-19 m predate the
     off-by-one correction (comps 93, 97); at 1.285 TeV its O(1)-coefficient Wilsonian
     reading is what R2 linearises to and is excluded, while its structural argument
     (custodial-symmetric potential, no new mediators, loop-suppressed four-fermion
     operators) is R3's in different words.  Its conclusion stands under R3 and only
     there; the file carries a scope note.

Tampers: a universal kernel at 3 M_* passes the dilepton limits (Lambda_eff = 40 TeV),
so the exclusion of R2 is a statement about the scale, not the form; and under R3 a
kernel at M_*/2 would already put the 650 GeV Higgs bin at 0.36 of the Standard Model,
which the present measurement disfavours, so R3 is not unfalsifiable either.

Runs in a second with the standard library.
"""
import math

# ---- the theory's numbers ---------------------------------------------------
MH = 125.20
MSTAR = 4 * math.pi * MH * math.sqrt(2.0 / 3.0)       # 1284.8 GeV
V = 246.22
MZ = 91.1876
SW2 = 0.23121
ALPHA = 1 / 127.952

# ---- the data ---------------------------------------------------------------
DY = dict(ee=dict(srmin=2200.0, obs=19, bkg=12.4, dbkg=1.9),
          mumu=dict(srmin=2070.0, obs=6, bkg=9.6, dbkg=2.1))
LAMBDA_LIMITS = dict(constructive=dict(LL=35.8, LR=32.5, RL=32.3, RR=35.5),
                     destructive=dict(LL=26.0, LR=28.8, RL=28.8, RR=26.5))
KAPPA_V, DKAPPA_V = 1.035, 0.031
KAPPA_F, DKAPPA_F = 0.95, 0.05
MU_HH_LIMIT = 2.4
JET_PT_MAX, DIJET_M_MAX = 3500.0, 9000.0


def poisson_tail(n, mu):
    """P(N >= n) for a Poisson of mean mu."""
    if mu == 0:
        return 0.0 if n > 0 else 1.0
    s, term = 0.0, math.exp(-mu)
    for k in range(n):
        s += term
        term *= mu / (k + 1)
    return max(0.0, 1 - s)


def part1():
    print("  PART 1.  R1, the literal reading: no field mode above M_*")
    print(f"      M_* = {MSTAR:.1f} GeV; dijet masses are measured to {DIJET_M_MAX / MSTAR:.1f} M_* and jet p_T to {JET_PT_MAX / MSTAR:.1f} M_*, with NNLO QCD describing them")
    tot_obs = sum(c["obs"] for c in DY.values()); tot_bkg = sum(c["bkg"] for c in DY.values())
    print(f"      dilepton signal regions above {min(c['srmin'] for c in DY.values()) / 1000:.2f} TeV: {tot_obs} observed, {tot_bkg:.1f} expected from the Standard Model; R1 expects 0")
    p = poisson_tail(tot_obs, 0.0)
    print(f"      Poisson probability of {tot_obs} or more events under R1: {p:.0e}; under the Standard Model: {poisson_tail(tot_obs, tot_bkg):.2f}")
    print("      R1 is excluded: the sentence cannot refer to the momenta of Standard Model quanta")
    return p == 0.0 and tot_obs > 0


def form_factor2(q, scale):
    """Two vertices, each a Gaussian kernel of width `scale`: exp(-q^2/scale^2)."""
    return math.exp(-(q * q) / (scale * scale))


def lambda_equivalent(scale, chirality="LL"):
    """A Gaussian kernel expanded to first order multiplies the Drell-Yan amplitude by
    (1 - s/scale^2).  The paper's contact term, g^2/4pi = 1, adds (4 pi / Lambda^2) times
    the current-current operator; the photon-exchange amplitude is e^2 Q_q Q_l / s, so the
    first-order kernel term -e^2 Q_q Q_l / scale^2 is a contact term with
    4 pi / Lambda^2 = e^2 |Q_q Q_l| / scale^2 for the photon piece, plus the Z piece with its
    chiral couplings at s >> m_Z^2.  Lambda_eff = scale * sqrt(4 pi / (e^2 |Q_q Q_l| + g_Z^2 |c_q c_l|)).
    Up quarks, constructive sign."""
    e2 = 4 * math.pi * ALPHA
    gz2 = e2 / (SW2 * (1 - SW2))
    Qq, Ql = 2.0 / 3.0, -1.0
    T3q = 0.5 if chirality[0] == "L" else 0.0
    T3l = -0.5 if chirality[1] == "L" else 0.0
    cq = T3q - Qq * SW2; cl = T3l - Ql * SW2
    coupling = e2 * abs(Qq * Ql) + gz2 * abs(cq * cl)
    return scale * math.sqrt(4 * math.pi / coupling)


def part2():
    print("  PART 2.  R2, a universal Gaussian kernel of width M_* on every vertex")
    ok = True
    for name, c in DY.items():
        f = form_factor2(c["srmin"], MSTAR)
        exp_r2 = c["bkg"] * f
        p = poisson_tail(c["obs"], exp_r2)
        print(f"      {name}: yield factor at the signal-region edge exp(-m^2/M_*^2) = {f:.3f}; expected {c['bkg']:.1f} -> {exp_r2:.2f}, observed {c['obs']}: P(>= obs | R2) = {p:.1e}")
        c["p_r2"] = p
    tot_obs = sum(c["obs"] for c in DY.values()); tot_r2 = sum(c["bkg"] * form_factor2(c["srmin"], MSTAR) for c in DY.values())
    p_comb = poisson_tail(tot_obs, tot_r2)
    print(f"      combined: {tot_obs} observed against {tot_r2:.2f} expected under R2: P = {p_comb:.1e}")
    ok &= p_comb < 1e-10
    print("      the kernel expanded to first order is a contact interaction; its equivalent Lambda against the paper's limits:")
    worst_ratio = 0.0
    for chi, lim in LAMBDA_LIMITS["constructive"].items():
        lam = lambda_equivalent(MSTAR, chi) / 1000
        ratio = (lim / lam) ** 2
        worst_ratio = max(worst_ratio, ratio)
        print(f"          {chi}: Lambda_eff = {lam:.1f} TeV against the observed limit {lim:.1f} TeV (constructive): short by a factor {ratio:.1f} in 1/Lambda^2")
        ok &= lam < lim
    # the scale the data require for a universal kernel
    lo, hi = MSTAR, 10 * MSTAR
    for _ in range(60):
        mid = 0.5 * (lo + hi)
        if lambda_equivalent(mid, "LL") / 1000 < LAMBDA_LIMITS["constructive"]["LL"]: lo = mid
        else: hi = mid
    print(f"      a universal kernel would need a scale of at least {lo / MSTAR:.1f} M_* = {lo / 1000:.1f} TeV to pass the LL limit; R2 at M_* is excluded")
    return ok and lo / MSTAR > 2.0


def hh_suppression(scale):
    """SM gg -> HH m_HH spectrum, a shape adequate for a weighted average: rises from
    threshold 2 m_h, peaks near 400 GeV, falls as a power; normalised numerically."""
    num = den = 0.0
    m = 2 * MH + 1.0
    while m < 3000:
        w = ((m - 2 * MH) ** 1.5) / (m ** 4.5)       # peaks at 2 m_h * 4.5/3 = 375 GeV
        num += w * math.exp(-(m * m) / (scale * scale)); den += w
        m += 2.0
    return num / den


def part3():
    print("  PART 3.  R3, the kernel on the Higgs doublet alone")
    ok = True
    dk = math.exp(-(MH * MH) / (2 * MSTAR * MSTAR)) - 1
    zv = (KAPPA_V - (1 + dk)) / DKAPPA_V; zf = (KAPPA_F - (1 + dk)) / DKAPPA_F
    print(f"      coupling modifiers at the pole shift by {dk * 100:+.2f} percent: kappa_V measured {KAPPA_V} +- {DKAPPA_V} ({zv:+.1f} sigma), kappa_F {KAPPA_F} +- {DKAPPA_F} ({zf:+.1f} sigma)")
    ok &= abs(zv) < 2 and abs(zf) < 2
    for pt in (450, 650, 1000):
        print(f"      Higgs production at p_T > {pt} GeV suppressed by exp(-p_T^2/M_*^2) = {math.exp(-(pt * pt) / (MSTAR * MSTAR)):.2f} (measured there with uncertainties of order the value)")
    mu_hh = hh_suppression(MSTAR)
    print(f"      Higgs pairs, weighted over the m_HH spectrum: mu_HH = {mu_hh:.2f}, against the observed limit {MU_HH_LIMIT}")
    ok &= mu_hh < MU_HH_LIMIT and 0.6 < mu_hh < 0.95
    print(f"      boosted H -> bb: the kernel's 0.88 above 450 GeV and 0.55 above 1 TeV against limits of 115/18.4 = {115 / 18.4:.1f} and 9.6/0.13 = {9.6 / 0.13:.0f} times the Standard Model: invisible at present precision")
    # longitudinal scattering: whole doublet vs physical h only
    def a0_h_only(sqrt_s):
        s = sqrt_s ** 2
        return (s / V ** 2) * (1 - form_factor2(sqrt_s, MSTAR)) / (16 * math.pi)
    lo, hi = 300.0, 10000.0
    for _ in range(60):
        mid = 0.5 * (lo + hi)
        if a0_h_only(mid) < 0.5: lo = mid
        else: hi = mid
    print(f"      if only the physical h carried the kernel, |a_0| of W_L W_L -> W_L W_L would reach 1/2 at sqrt(s) = {lo / 1000:.1f} TeV; with the whole doublet the cancellation is preserved and the amplitude is suppressed, not enhanced")
    ok &= 1.2 < lo / 1000 < 2.5
    return ok


def part4():
    print("  PART 4.  What R3 predicts, and the tampers")
    ok = True
    for pt in (650, 1000):
        print(f"      deficit in the Higgs p_T spectrum above {pt} GeV: {100 * (1 - math.exp(-(pt * pt) / (MSTAR * MSTAR))):.0f} percent")
    print(f"      deficit in Higgs pairs: {100 * (1 - hh_suppression(MSTAR)):.0f} percent; coupling modifiers within half a percent of one")
    lam3 = lambda_equivalent(3 * MSTAR, "LL") / 1000
    print(f"      tamper: a universal kernel at 3 M_* has Lambda_eff = {lam3:.0f} TeV and passes the dilepton limits, so the exclusion of R2 is about the scale, not the form")
    ok &= lam3 > LAMBDA_LIMITS["constructive"]["LL"]
    f_half = math.exp(-(650.0 ** 2) / ((MSTAR / 2) ** 2))
    print(f"      tamper: under R3 a kernel at M_*/2 would put the 650 GeV Higgs bin at {f_half:.2f} of the Standard Model, which the present measurement disfavours; R3 is falsifiable")
    ok &= f_half < 0.5
    return ok


def main():
    print("=" * 100)
    print("Computation 205: the M_* confrontation, three readings of the modal cutoff against the LHC")
    print("=" * 100)
    results = [
        ("R1, no field modes above M_*, excluded by 25 dilepton events above 2 TeV and jets to 7 M_*", part1()),
        ("R2, a universal kernel at M_*, excluded by the dilepton yields and the contact-interaction limits", part2()),
        ("R3, the kernel on the Higgs doublet alone, consistent with couplings, p_T spectra, Higgs pairs and unitarity", part3()),
        ("R3's predictions stated; both tampers behave", part4()),
    ]
    print()
    print("SUMMARY")
    for label, ok in results:
        print(f"  [{'PASS' if ok else 'FAIL'}] {label}")
    print()
    print("  CONCLUSION: M_* = 1.285 TeV survives the LHC in exactly one reading of the book's cutoff sentence,")
    print("  the one sec:mstar states: the projection's kernel sits on the Higgs doublet, the field that is the")
    print("  projected condensate, and on nothing else.  Read as a cutoff on Standard Model momenta, or as a")
    print("  kernel on every vertex, the sentence is excluded by existing data by enormous margins.  The surviving")
    print("  reading predicts a growing deficit in the Higgs p_T spectrum, 23 percent above 650 GeV, that the")
    print("  high-luminosity LHC can see.")
    print("  ALL CHECKS PASSED" if all(ok for _, ok in results) else "  SOME CHECKS FAILED")


if __name__ == "__main__":
    main()
