#!/usr/bin/env python3
"""
Computation 93 -- M_* off-by-one: re-examination of rescue (b) under the
                  doublet-self-loop / eigenmode-sum decomposition
==========================================================================
Open-research item 1.2 (the M_* = 4 pi m_h zero-mode off-by-one).
Comp 67 identified the off-by-one in eq:pairing-cancel; Comp 69 walked
three rescues and concluded none closes it.  This computation re-examines
Comp 69's analysis of rescue (b) (zero-mode included in the eigenmode
sum) with explicit attention to whether the paper's two contributions

  (1) Higgs doublet self-loop:        delta m_h^2|_Phi = C_H * M_*^2/(16 pi^2)
                                       with C_H = 4 lambda_PST = 1 (eq:ch-exact)
  (2) PST scalar eigenmode sum:        delta m_h^2|_eig = (N_B - N_F) * M_*^2/(16 pi^2)
                                       (eq:pairing-cancel)

are conceptually independent contributions to be ADDED, or whether they
overlap (double-counting the Higgs as both doublet component and zero
mode of the Boolean Laplacian).

WHY THIS MATTERS
----------------
If they ADD independently:
  total = (M_*^2/16pi^2) * (C_H + N_B - N_F)
  with zero mode INCLUDED: N_B - N_F = 0, total = M_*^2/(16 pi^2)
                            => m_h = M_* / (4 pi) ✓
  with zero mode EXCLUDED: N_B - N_F = -1, total = 0
                            => m_h = 0 ✗
  Resolution: include zero mode; rescue (b) closes off-by-one.

If they overlap (zero mode = Higgs = doubly-counted):
  Including zero mode in N_B double-counts the Higgs (already in C_H),
  inflating the bosonic count by 1, giving N_B - N_F = 0 only because
  of the double count.  After removing double-count: net = -1, total = 0.
  This matches Comp 69's verdict (rescue b is a no-op).

THE STRUCTURAL QUESTION
-----------------------
- C_H = 4 lambda_PST captures the Higgs DOUBLET self-loop with quartic
  vertex lambda |H|^4 / 4.  This counts the 4-component complex
  doublet (4 real DoFs) self-interacting via the quartic vertex.
- N_B counts BOSONIC eigenmodes of the Boolean Laplacian L^B on the
  substrate's modal field psi.  The zero mode (S = empty) is the
  uniform constant-mode profile.
- Are these the same Higgs or different?

In PST, psi = Pi(phi_Higgs) is the substrate's MODAL ORDER PARAMETER, a
single scalar (or scalar-valued) field on substrate configurations.  The
4-component doublet structure arises POST-PROJECTION via inner
fluctuations of the Dirac operator on M x F, generating the H^+, H^0
doublet.

Conjecture for re-examination
-----------------------------
The substrate-side modal field psi is a SINGLE scalar; its Boolean
Laplacian eigenmodes are PST-internal scalars.  After projection Pi,
the emergent Standard-Model Higgs doublet H has 4 real components,
each from a DIFFERENT structural sector of the spectral triple
(A_F = C (+) H (+) M_3(C)) -- so the 4-component doublet self-loop
(C_H) is NOT in correspondence with substrate eigenmodes (N_B, N_F).

Under this reading:
  - C_H counts EMERGENT 4-real-component doublet self-loops.
  - (N_B, N_F) count SUBSTRATE-internal Boolean modes orthogonal to the
    Higgs identification.
  - The zero mode S = empty is the "average / constant" substrate mode,
    distinct from the emergent doublet.
  - Including the zero mode in N_B is NOT double-counting the Higgs;
    it counts the substrate-side constant-mode contribution which is
    a separate object from the post-projection doublet.

Under this reading, rescue (b) closes the off-by-one structurally:
  total = (M_*^2/16pi^2)(C_H + N_B^full - N_F)
        = (M_*^2/16pi^2)(1 + 0) = M_*^2/(16 pi^2)
        => m_h = M_*/(4 pi) ✓

CAVEAT
------
This rescue depends on the structural distinction between:
  (a) substrate-side modal field psi (single scalar; Boolean modes)
  (b) emergent SM Higgs doublet H (4-component; doublet self-loop)
The paper currently couples them via phi_Higgs = Pi(psi), with the
zero mode of L^B = the constant profile = the order-parameter
"background".  Whether the zero mode is identified WITH the Higgs (in
which case rescue b double-counts) or DISTINCT from the Higgs (in
which case rescue b closes) is a foundational reading that Comps 67/69
did not separate.

This computation does NOT decide the question; it identifies that the
key foundational reading was implicit in Comps 67/69 and explicit
resolution requires going back to the substrate-side / emergent-side
distinction in the PST projection chain.
"""
from math import comb, pi, exp


def even_odd_counts(D: int) -> tuple[int, int, int]:
    """Returns (N_B_with_zero, N_B_nonzero, N_F)."""
    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 93 -- M_* off-by-one: re-examination of rescue (b)")
    print("=" * 100)
    print()

    print("THE PAPER's TWO CONTRIBUTIONS")
    print("-" * 100)
    print()
    print("  (1) Higgs DOUBLET self-loop (eq:ch-exact):")
    print("        delta m_h^2 |_Phi  =  C_H * M_*^2/(16 pi^2)")
    print("        with C_H = 4 lambda_PST = 4 * (1/4) = 1.")
    print()
    print("  (2) PST scalar eigenmode sum (eq:pairing-cancel):")
    print("        delta m_h^2 |_eig  =  (N_B - N_F) * M_*^2/(16 pi^2)")
    print("        with N_B, N_F from Boolean-Laplacian eigenmode counting.")
    print()
    print("  TOTAL (if independent):")
    print("        delta m_h^2  =  (C_H + N_B - N_F) * M_*^2/(16 pi^2)")
    print()

    print("PAPER's EXISTING COUNTING:")
    print("-" * 100)
    print()
    print(f"  {'D':>3}  {'N_B (incl 0)':>14}  {'N_B (excl 0)':>14}  {'N_F':>8}  "
          f"{'C_H + N_B^full - N_F':>23}  {'C_H + N_B^nz - N_F':>22}")
    for D in (4, 6, 8, 10, 12, 14, 16):
        NB_full, NB_nz, NF = even_odd_counts(D)
        with_zero = 1 + (NB_full - NF)
        without_zero = 1 + (NB_nz - NF)
        print(f"  {D:>3}  {NB_full:>14}  {NB_nz:>14}  {NF:>8}  "
              f"{with_zero:>+23}  {without_zero:>+22}")
    print()
    print("  Two readings of the total scalar contribution (C_H + N_B - N_F):")
    print()
    print("    * With zero mode in N_B:        total = +1, m_h^2 = M_*^2/(16 pi^2)")
    print("                                              ==> m_h = M_* / (4 pi). ✓")
    print()
    print("    * With zero mode excluded:      total = 0,  m_h^2 = 0")
    print("                                              ==> m_h = 0.        ✗")
    print()

    print("THE FOUNDATIONAL READING QUESTION (rescue b re-examined)")
    print("-" * 100)
    print()
    print("  Comp 69 dismissed rescue (b) (zero mode in N_B) because it interpreted")
    print("  the eigenmode imbalance as the SOURCE of the Higgs self-mass.  Under that")
    print("  reading, N_B - N_F = 0 leaves no leftover for m_h^2, so total = 0.")
    print()
    print("  But the paper's eq:ch-exact derives delta m_h^2|_Phi = M_*^2/(16 pi^2)")
    print("  separately, from the 4-component doublet self-loop with C_H = 4 lambda.")
    print("  This is INDEPENDENT of the eigenmode sum: C_H counts the EMERGENT doublet")
    print("  self-interactions, while (N_B, N_F) counts SUBSTRATE-internal Boolean")
    print("  eigenmodes orthogonal to the emergent Higgs identification.")
    print()
    print("  Under the 'independent contributions' reading:")
    print("    - C_H = 1 (emergent doublet, always)")
    print("    - N_B - N_F = 0 (include zero mode = substrate constant-mode)")
    print("    - Total = 1 + 0 = 1, giving m_h^2 = M_*^2/(16 pi^2)")
    print("    - m_h = M_* / (4 pi) ✓")
    print()
    print("  This is the FOURTH RESCUE: re-interpret rescue (b) as 'include zero mode")
    print("  in N_B, where the zero mode is the substrate-side constant-mode (NOT")
    print("  double-counting the emergent Higgs doublet, which is in C_H).'")
    print()

    print("STATUS")
    print("-" * 100)
    print()
    print("  This re-examination identifies that Comp 69's dismissal of rescue (b)")
    print("  rests on a specific foundational reading (the zero mode IS the Higgs,")
    print("  so including it in N_B double-counts).  An alternative reading -- the")
    print("  zero mode is a substrate-side constant-mode DISTINCT from the emergent")
    print("  doublet -- closes the off-by-one structurally and recovers M_* = 4 pi m_h")
    print("  as a parameter-free one-loop derivation.")
    print()
    print("  Which reading is correct depends on the precise PST projection chain")
    print("  psi (substrate scalar) -> phi_Higgs (emergent 4-component doublet).")
    print("  The substrate-side modal field psi is a SINGLE scalar function on P(D);")
    print("  its Boolean-Laplacian eigenmodes are PST-internal SCALAR modes.  The")
    print("  emergent 4-component doublet structure arises POST-PROJECTION via inner")
    print("  fluctuations on M x F, generating H^+, H^0 from the A_F = C (+) H (+)")
    print("  M_3(C) factor.")
    print()
    print("  If the projection Pi: psi -> phi_Higgs maps the substrate-side single")
    print("  scalar to the EMERGENT 4-component doublet via inner-fluctuation lift,")
    print("  then the zero mode of L^B (substrate-side constant-mode) is NOT the")
    print("  emergent doublet -- they live at different layers in the projection chain.")
    print("  Including the substrate-side zero mode in N_B does not double-count")
    print("  the emergent doublet (which is captured by C_H).  Rescue (b) closes")
    print("  the off-by-one under this reading.")
    print()
    print("  This re-examination DOES NOT settle the question definitively; it")
    print("  identifies the foundational reading on which Comp 69's dismissal rests,")
    print("  and shows that an alternative reading recovers the parameter-free")
    print("  M_* = 4 pi m_h relation.  Further computations to validate the")
    print("  substrate-vs-emergent distinction in the projection chain would close")
    print("  this open research item.")


if __name__ == "__main__":
    main()
