#!/usr/bin/env python3
"""
Computation 67 -- One-loop Higgs-mass cancellation: scope check of eq:pairing-cancel
====================================================================================
Verifies the combinatorial structure of the PST scalar-sector cancellation argument
(paper Section 7.20, equations eq:ch-exact and eq:pairing-cancel), and identifies
an off-by-one issue in the as-stated counting that the paper's prediction
M_* = 4 pi m_h relies on being resolved.

Paper claim:
  N_B = #{S subset of [D],  S != empty,  |S| even} = 2^(D-1)
  N_F = #{S subset of [D],  |S| odd}                = 2^(D-1)
  delta m_h^2|_PST_scalar = (M_*^2 / (16 pi^2)) * (N_B - N_F) = 0.

Plus the Higgs self-loop:
  delta m_h^2|_self      = (M_*^2 / (16 pi^2)) * C_H,  with C_H = 4 lambda_PST = 1
                         = M_*^2 / (16 pi^2).

Combined, the paper claims:
  delta m_h^2 = M_*^2 / (16 pi^2)   =>   m_h = M_* / (4 pi).

This script verifies the combinatorics and isolates the residual.
"""
from math import comb, pi


def even_odd_counts(D):
    """Returns (N_B_with_zero, N_B_nonzero, N_F).

    N_B_with_zero  = #{S subset of [D],  |S| even, including empty set}
                   = sum_{k even} binomial(D, k)
                   = 2^(D-1).

    N_B_nonzero    = N_B_with_zero - 1  (the empty set is the zero-mode / Higgs).

    N_F            = #{S subset of [D],  |S| odd}
                   = sum_{k odd} binomial(D, k)
                   = 2^(D-1).
    """
    NB_full = sum(comb(D, k) for k in range(0, D + 1, 2))
    NF      = sum(comb(D, k) for k in range(1, D + 1, 2))
    return NB_full, NB_full - 1, NF


def main():
    print("=" * 100)
    print("  Computation 67  --  PST one-loop Higgs cancellation: counting verification")
    print("=" * 100)
    print()
    print("  Eigenmodes of the Boolean Laplacian L^B at substrate size D are indexed by")
    print("  subsets S of [D], with eigenvalue |S| * M_*^2 and Higgs coupling c_k = 1")
    print("  (universal, from the LG quartic).  The S = empty mode is the Higgs zero mode.")
    print()
    print(f"  {'D':>3}  {'N_B (incl 0)':>14}  {'N_B (excl 0)':>14}  {'N_F':>8}  "
          f"{'N_B(excl) - N_F':>18}")
    for D in (4, 6, 8, 10, 12, 14, 16):
        NB_full, NB_nz, NF = even_odd_counts(D)
        diff = NB_nz - NF
        print(f"  {D:>3}  {NB_full:>14}  {NB_nz:>14}  {NF:>8}  {diff:>+18}")

    print()
    print("=" * 100)
    print("  Finding")
    print("=" * 100)
    print()
    print("  Two binomial identities are exact for all D:")
    print()
    print("    sum_{k even} binomial(D, k)  =  sum_{k odd} binomial(D, k)  =  2^(D-1).")
    print()
    print("  Including the zero mode (S = empty) in the bosonic count:")
    print("    N_B_full - N_F = 0.")
    print()
    print("  Excluding the zero mode (per paper line 4661: 'The Higgs zero mode (S =")
    print("  empty, eigenvalue 0 of L^B) is excluded because it is the order parameter'):")
    print("    N_B_nonzero - N_F = -1.")
    print()
    print("  Plugging the excluded count into eq:pairing-cancel gives")
    print()
    print("    delta m_h^2|_PST_scalar  =  (M_*^2 / (16 pi^2)) * (-1)")
    print("                             =  - M_*^2 / (16 pi^2),")
    print()
    print("  not 0.  When this is added to the Higgs self-loop")
    print()
    print("    delta m_h^2|_self  =  M_*^2 / (16 pi^2)   (eq:ch-exact, with C_H = 1),")
    print()
    print("  the combined one-loop result is")
    print()
    print("    delta m_h^2 = M_*^2 / (16 pi^2)  +  (- M_*^2 / (16 pi^2))  =  0,")
    print()
    print("  i.e. m_h = 0 from one-loop self + scalar-sector contributions.  This")
    print("  contradicts the paper's prediction m_h = M_* / (4 pi), and means the")
    print("  prediction does not survive the straightforward reading of eq:pairing-cancel.")
    print()
    print("=" * 100)
    print("  Three structural resolutions, each of which would restore the prediction")
    print("=" * 100)
    print()
    print("  The paper's prediction m_h = M_*/(4 pi) is recovered if exactly one extra")
    print("  bosonic dof exists at the cancellation level, balancing the count.  Three")
    print("  candidate mechanisms, each currently not made explicit:")
    print()
    print("  (a) Higgs-doublet structure.  At the electroweak scale, psi is enriched to")
    print("      the SM doublet H = (H+, H0) with 4 real dofs; three angular Goldstones")
    print("      are eaten by W^+/-, Z, leaving the physical Higgs.  If the substrate-level")
    print("      cancellation is to be matched at the H level, the three eaten Goldstones")
    print("      may contribute as additional bosonic modes, restoring N_B = N_F+1 at the")
    print("      doublet level (one for the Higgs self, three from eaten Goldstones, exactly")
    print("      compensating the -1 of the substrate-level count).  This is plausible but")
    print("      is not the argument the paper currently makes.")
    print()
    print("  (b) Alternate convention.  If the zero mode IS counted in the cancellation sum")
    print("      (i.e. the cancellation N_B - N_F = 0 holds *including* the Higgs zero mode),")
    print("      and the self-loop eq:ch-exact is interpreted as something separate from the")
    print("      zero-mode bosonic-loop contribution, the cancellation closes.  This requires")
    print("      eq:ch-exact and eq:pairing-cancel to refer to distinct diagrams with no")
    print("      double-counting; currently the paper's framing of the zero mode as both")
    print("      'the order parameter' (excluded from cancellation) and 'the field whose mass")
    print("      receives delta m_h^2' (subject to self-loop) is ambiguous.")
    print()
    print("  (c) Structural pairing argument.  A deeper one-to-one pairing of bosonic and")
    print("      fermionic eigenmodes (analogous to SUSY but sourced from complementation /")
    print("      parity, not super-translations) might exist at the spectral level and make")
    print("      the cancellation exact non-trivially.  This would require explicit")
    print("      construction; it is currently asserted in the paper's line 4663 ('cancel")
    print("      by the equal-weighting postulate applied to those sectors') but not shown.")
    print()
    print("=" * 100)
    print("  Conclusion")
    print("=" * 100)
    print()
    print("  The paper's eq:pairing-cancel as written gives -M_*^2/(16 pi^2), not 0, when")
    print("  the Higgs zero mode is excluded per the paper's own prescription.  The")
    print("  prediction M_* = 4 pi m_h then holds only if one of (a)--(c) is supplied as")
    print("  the missing structural argument.")
    print()
    print("  This computation does NOT refute the prediction.  It identifies the structural")
    print("  step the paper currently does not make explicit, and which the review of v23.32")
    print("  (New-1d) requested.  The honest status of M_* = 1.573 TeV is:")
    print()
    print("     - Combinatorially: counts are correct as stated WITH zero mode included")
    print("       (N_B = N_F = 2^(D-1)); off by -1 when zero mode is excluded.")
    print("     - Coupling universality C_H = 4 lambda_PST = 1: exact at the LG level.")
    print("     - Sign assignment via CAR-algebra spin-statistics: structurally clean.")
    print("     - Closure of the eq:pairing-cancel argument as written: requires one of")
    print("       the three structural mechanisms above to be made explicit.")
    print()
    print("  Numerical value M_* = 4 pi * 125.25 GeV =", 4 * pi * 125.25, "GeV")
    print("  is unchanged as a candidate prediction conditional on (a), (b), or (c).")


if __name__ == "__main__":
    main()
