#!/usr/bin/env python3
"""
SCOPE NOTE, 2026-10-11 (comp 202).  Where this file quotes lambda_SM(M_*) ~ 0.0927
(Buttazzo et al. 2013), the 0.8 percent agreement, the one-sigma Higgs match or comp 176's
0.4 sigma, that is the anchor of its day and is kept as found.  comp 202 computes the number
at three loops on current inputs: 0.0932 +- 0.0008, 1.6 sigma from e^-1/4, which is what the
book states from v32.137.  Nothing here is re-run; the substrate side is unaffected.

PROVENANCE: PROOF

Computation 117 -- Bridge Premise (B), milestone M8(a):
                   the embedding-norm selection is STRUCTURAL, not empirical
=========================================================================
STATUS (v26.19+): M8(a) of the wave-function attack on Bridge Premise (B).
After the v26.15 referee (P1, accepted), the open content of (B) is the
substrate->SM-coupling matching, and one sub-caveat inside the substrate
side was that the embedding-norm-vs-2pt-residue selection (Comp 114 / M5)
"rests partly on the empirical finiteness of lambda_SM, not a theorem
alone".  This computation removes that empirical crutch.

THE TWO READINGS (recap, Comp 114)
==================================
The wave-function renormalisation is lambda_SM(M_*) = b * Z_phi^2.  Two
candidate substrate objects for Z_phi^2:
  (A) embedding norm   Z_phi^2 = E_mu[exp(-beta_KO X_bar)] -> e^-1   (O(1));
  (B) 2-pt residue     Z_phi^2 = Var_mu(X_bar) = 1/(4D) -> 0.
Comp 114 selected (A) and excluded (B) by noting (B) gives lambda_SM -> 0,
"excluded by the finiteness of the observed quartic" -- an EMPIRICAL
exclusion.

THE STRUCTURAL ARGUMENT (M8a)
=============================
The order parameter X_bar = (1/D) sum_a C_a is an INTENSIVE average.  Its
2-pt residue is its variance, and that variance vanishes as 1/(4D) by the
LAW OF LARGE NUMBERS (P1: the C_a are i.i.d., so the intensive average
self-averages to its mean 1/2 with fluctuations O(1/sqrt(D))).  This
vanishing is a generic large-D effect, not a field-strength.

A field-strength Z_phi is the normalisation relating the substrate field
to the CANONICALLY-NORMALISED emergent field; it must be finite and
non-zero (O(1)) for a canonical emergent field to exist at all.  Reading
(B) sets Z_phi^2 = (an intensive variance) -> 0, i.e. it identifies the
field-strength with a quantity the LLN drives to zero.  That is
structurally inadmissible: a vanishing Z_phi^2 means lambda_SM -> 0 in the
substrate limit D->inf -- a FREE emergent Higgs, no canonical interacting
field.  An intensive order parameter cannot play the role of a
fundamental field whose propagator residue is its susceptibility.

Reading (A) sets Z_phi^2 = the embedding norm (the tempered-vacuum
amplitude of the order-parameter sector, Comp 100), which is O(1) -> e^-1
and DOES normalise a canonical emergent field, giving an interacting
lambda_SM = b e^-1.

The emergent EFT below M_* is the (interacting) Standard Model -- this is
framework premise F4, a STRUCTURAL claim of PST, independent of the
measured value of lambda_SM.  An interacting emergent Higgs requires
Z_phi^2 = O(1); the LLN excludes (B)'s vanishing susceptibility; so the
field-strength is the O(1) embedding norm (A).  The selection is forced
by F4 + the LLN, NOT by the empirical value 0.0927.

This computation verifies the numerics underlying the argument and states
honestly what it does and does not remove.
=========================================================================
"""

import math


def var_xbar(D, p=0.5):
    """2-pt residue reading: Var_mu(X_bar) = p(1-p)/D = 1/(4D) at p=1/2."""
    return p * (1.0 - p) / D


def embedding_norm(D, beta=2.0):
    """Embedding-norm reading: E_mu[exp(-beta X_bar)] = ((1+e^{-beta/D})/2)^D."""
    return ((1.0 + math.exp(-beta / D)) / 2.0) ** D


def main():
    print("=" * 72)
    print("Computation 117: M8(a) -- embedding-norm selection is structural")
    print("=" * 72)
    print()

    b = 0.25            # bare PST quartic (doublet convention)
    e_inv = math.exp(-1.0)

    # ---- 1. the susceptibility vanishes by the LLN (intensive average) ----
    print("1.  THE 2-PT RESIDUE IS AN INTENSIVE VARIANCE -> 0 BY THE LLN")
    print("-" * 72)
    print("    X_bar = (1/D) sum_a C_a, C_a i.i.d. Bernoulli(1/2).")
    print("    Var(X_bar) = 1/(4D); D * Var -> 1/4 (pure self-averaging).")
    print(f"    {'D':>7} {'Var(X_bar)':>14} {'D*Var':>8} {'lambda_SM=b*Var':>18}")
    for D in (10, 100, 1000, 10000):
        v = var_xbar(D)
        print(f"    {D:>7} {v:>14.3e} {D*v:>8.4f} {b*v:>18.3e}")
    print(f"    {'limit':>7} {0.0:>14.3e} {0.25:>8.4f} {0.0:>18.3e}")
    print()
    print("    Reading (B) Z_phi^2 = Var(X_bar) -> 0, so lambda_SM -> 0:")
    print("    a FREE emergent Higgs in the substrate limit. The vanishing")
    print("    is the law of large numbers, not a field-strength.")
    print()

    # ---- 2. the embedding norm is O(1) ----
    print("2.  THE EMBEDDING NORM IS O(1) -> e^-1")
    print("-" * 72)
    print(f"    {'D':>7} {'E_mu[e^-2Xbar]':>16} {'lambda_SM=b*norm':>18}")
    for D in (10, 100, 1000, 10000):
        z = embedding_norm(D)
        print(f"    {D:>7} {z:>16.6f} {b*z:>18.6f}")
    print(f"    {'limit':>7} {e_inv:>16.6f} {b*e_inv:>18.6f}")
    print()
    print("    Reading (A) Z_phi^2 = embedding norm -> e^-1 (O(1)), so")
    print("    lambda_SM -> b e^-1 = 0.0920: an INTERACTING emergent Higgs.")
    print()

    # ---- 3. the structural distinction: variance vs amplitude ----
    print("3.  THE TWO OBJECTS ARE STRUCTURALLY DIFFERENT KINDS")
    print("-" * 72)
    print("    Var(X_bar)        = connected 2-pt function of an INTENSIVE")
    print("                        average; an O(1/D) self-averaging quantity")
    print("                        (LLN); -> 0.  Measures fluctuation SIZE.")
    print("    E_mu[exp(-bX_bar)] = the tempered-vacuum amplitude / MGF of")
    print("                        the order-parameter sector (Comp 100);")
    print("                        O(1); -> e^-1.  Normalises the FIELD.")
    print()
    print("    For a FUNDAMENTAL scalar the field-strength equals the 2-pt")
    print("    residue -- but only because that residue is O(1). For an")
    print("    INTENSIVE order parameter the 2-pt residue is the variance,")
    print("    which the LLN sends to 0; it therefore cannot be a")
    print("    field-strength. The emergent Higgs is the PROJECTED field,")
    print("    normalised by the embedding norm (A), not a fundamental field")
    print("    with residue = susceptibility (B).")
    print()

    # ---- 4. assessment ----
    print("=" * 72)
    print("ASSESSMENT: does M8(a) remove the empirical crutch?")
    print("=" * 72)
    print()
    print("  THE SELECTION, RESTATED STRUCTURALLY:")
    print("   - Reading (B) sets the field-strength to the intensive")
    print("     susceptibility, which -> 0 by the LLN (P1's independence);")
    print("     lambda_SM -> 0, a FREE emergent Higgs. A vanishing Z_phi^2")
    print("     defines no canonical emergent field.")
    print("   - Reading (A) sets it to the O(1) embedding norm; lambda_SM ->")
    print("     b e^-1, a canonical INTERACTING emergent Higgs.")
    print("   - Framework premise F4 (the emergent EFT below M_* is the")
    print("     interacting Standard Model) requires an interacting Higgs,")
    print("     hence Z_phi^2 = O(1), hence reading (A). This uses F4 + the")
    print("     LLN, NOT the measured value lambda_SM = 0.0927.")
    print()
    print("  WHAT THIS REMOVES:")
    print("   The Comp 114 exclusion of (B) said 'lambda_SM is finite")
    print("   (observed), so not (B)'. That empirical-VALUE dependence is")
    print("   removed: (B) is now excluded because it makes the emergent")
    print("   theory free in the substrate limit, contradicting F4 -- a")
    print("   structural premise, not a measurement. The value 0.0927 is no")
    print("   longer an input to the SELECTION (it remains the empirical")
    print("   TEST of the resulting prediction b e^-1 = 0.0920).")
    print()
    print("  WHAT THIS DOES NOT DO (honest residual):")
    print("   - It still rests on F4 (emergent EFT = interacting SM), a")
    print("     framework premise. F4 is structural, but it is a premise;")
    print("     M8(a) trades 'empirical value of lambda_SM' for 'F4', not for")
    print("     nothing.")
    print("   - It does not derive the matching equation lambda_SM(M_*) =")
    print("     b Z_phi^2 itself (Wilsonian threshold matching, F4-F7) from")
    print("     the SM side -- that remains the open step of (B). M8(a)")
    print("     sharpens the substrate-side field-strength selection only.")
    print()
    print("  NET: sub-caveat (a) is closed at the substrate-side level. The")
    print("  embedding-norm reading is forced by P1's LLN + F4, with the")
    print("  measured lambda_SM demoted from an INPUT (to the selection) to")
    print("  a TEST (of the prediction). The remaining open content of (B)")
    print("  is the matching equation to the SM-measured coupling (F4-F7)")
    print("  and the F11 all-orders rigour write-up.")


if __name__ == "__main__":
    main()
