#!/usr/bin/env python3
"""
Computation 103 -- Bridge Premise (B) attack: explicit path-integral Jacobian
                   of the matched-scaling map Pi
=========================================================================
Following Comp 101's reduction of bridge premise (B) to two sub-questions:
  (1) Is the matched-scaling Pi's path-integral Jacobian equal to
      exp(-beta_KO * H_Higgs(C)) on substrate configurations?
  (2) Why is the vertex renormalisation trivial (Z_Gamma4 = 1)?

Comp 103 attacks sub-question (1) by setting up the framework explicitly
and computing the Jacobian where possible.

FRAMEWORK SETUP
================
Substrate side:
  - Configuration space P(D) with Bernoulli measure mu = (x)_i Bern(1/2)
  - Substrate field psi : P(D) -> R
  - Walsh basis decomposition: psi = sum_S c_S chi_S
  - Inner product: <psi_1, psi_2>_mu = E_mu[psi_1 psi_2] = sum_S c_S(1) c_S(2)
  - Path-integral measure: D_psi = prod_S dc_S (Lebesgue on Walsh
    coefficients)
  - Bare action: S_substrate[psi] = b * E_mu[psi^4] with b = 1/4

SM side at matched scale M_*:
  - Spacetime M = R x S^3
  - SM Higgs field phi : M -> R
  - Mode decomposition: phi = sum_k phi_k psi_k(x) with {psi_k} orthonormal
    in L^2(M, dvol)
  - Inner product: <phi_1, phi_2>_M = integral phi_1 phi_2 dvol
  - Path-integral measure: D_phi = prod_k dphi_k (Lebesgue on SM modes)
  - Renormalised action: S_SM[phi] = lambda_SM(M_*) * <phi^2, phi^2>_M + ...

MATCHED-SCALING MAP Pi
=======================
The Mosco-convergence projection (paper sec:mosco-conditional) identifies
substrate field psi at substrate scale Lambda = sqrt(D) with SM field phi
at scale M_*.  Per the Walsh-shell analysis of Comp 98:
  - H_Higgs = X_bar is supported on V_0 + V_1 (lowest two shells)
  - Substrate zero mode chi_empty (V_0) <-> constant function on M
    (vacuum direction)
  - Substrate singleton modes chi_{i} (V_1) <-> SM Higgs perturbations
    eta_k around the vacuum

So Pi acts on the Higgs content of psi as a finite-dimensional linear map
between substrate V_0 + V_1 and SM-side vacuum + first-mode-shell.

The PATH-INTEGRAL JACOBIAN |dPsi/dPhi| of this map relates the Lebesgue
measures: prod_S dc_S = J(Pi) * prod_k dphi_k.

CONJECTURE (Comp 101): J(Pi) = exp(-beta_KO * H_Higgs(C))

OBSTRUCTION TO DIRECT COMPUTATION
==================================
The map Pi is structurally defined via Mosco convergence (operator-level)
but not as an explicit measure-preserving map between specific finite-
dimensional Lebesgue spaces.  The "path-integral Jacobian" is not
manifest in the Mosco framework.

Two natural attempts:

(A) Linear-map determinant.  If Pi: V_0+V_1 -> SM_low is a linear map
    between matched finite-dimensional spaces, |det Pi| is a constant
    (Jacobian doesn't depend on the point).  This gives J(Pi) = const,
    which can be absorbed into the normalisation -- it doesn't deliver
    exp(-beta_KO * X_bar(C)).

(B) Saddle-point / large-deviation form.  If Pi is a SADDLE-POINT
    projection in the asymptotic D -> infinity limit, the Jacobian can
    pick up a non-trivial position-dependence from the saddle-point
    weight.  For Bernoulli mu with X_bar = (1/D) sum_i C_i, the
    large-deviation rate function around X_bar = 1/2 is:
      I(x) = x ln(2x) + (1-x) ln(2(1-x))   for x in [0,1]
    The Cramer-Bernoulli LDP gives:
      mu({X_bar approx x}) ~ exp(-D * I(x))

    Under Pi at matched scaling, configurations with X_bar = x contribute
    with the LDP weight, not the Bernoulli weight.  The "effective"
    weight under Pi at large D:
      mu_eff(C) ~ exp(-D * I(X_bar(C)))

    THIS IS THE LARGE-DEVIATION JACOBIAN.  At leading order near
    x = 1/2 (the vacuum):
      I(x) approx 2*(x - 1/2)^2  for x near 1/2
    so the LDP weight is Gaussian around the vacuum, NOT
    exp(-beta_KO * X_bar(C)) directly.

Neither (A) nor (B) directly delivers J(Pi) = exp(-beta_KO * X_bar(C)).
The conjecture of Comp 101 sub-question (1) does NOT hold in the
direct/saddle-point sense.

WHAT THIS REVEALS
==================
The multiplicative matching form lambda_SM(M_*) = b * Z_H(beta_KO) cannot
be derived from a path-integral Jacobian computation in the standard
sense (linear-map determinant OR large-deviation saddle-point).

This is the same finding as the original peer-review concern, now
sharpened: the multiplicative matching is genuinely a structural
hypothesis of the partition-function-level CC correspondence, not a
derivable consequence of measure-theoretic change-of-variable.

REFRAMING (Comp 103 honest finding)
====================================
Comp 101's sub-question (1) is reformulated:

  (1')  Is there ANY natural object on the substrate path-integral
        whose value at matched scaling equals e^(-1) and which CAN
        be identified with Z_phi^2 in standard wave-function
        renormalisation?

Comp 100 already supplies one candidate: the normalised spectral
action (1/2^D) Tr exp(-Delta/Lambda^2) -> e^(-1).  This is NOT a
path-integral Jacobian -- it's a normalised trace of a spectral
operator.

The "bridge" from this trace to Z_phi^2 is then asserted at the level
of the partition-function-level CC correspondence: the normalised
spectral action plays the role of Z_phi^2 in the substrate-to-SM
matching at M_*.

This is the FINAL HONEST POSITION of bridge premise (B):
  - The substrate-side normalised spectral action -> e^(-1) is derived
    from P1-P3 (Comp 100).
  - Identifying this trace with the SM-side Z_phi^2 (or with the ratio
    lambda_R/lambda_B) is the partition-function-level analogue of
    the CC inner-fluctuation correspondence: a STRUCTURAL POSTULATE
    of the framework at the same level as the spectral-action
    principle in standard CC.

Comp 103 status: sub-question (1) does NOT have a direct
measure-theoretic answer.  The multiplicative matching IS a structural
hypothesis; the substrate-side closure (Comp 100) reduces what's open
to ONE specific structural identification, and that identification
remains the irreducible open content.

SUB-QUESTION (2) STATUS
========================
Sub-question (2) -- why Z_Gamma4 = 1 -- is automatically true at tree
level in standard CC: inner fluctuations contribute to gauge bosons and
the Higgs, not to additional vertex structures.  At one-loop, Z_Gamma4
deviates from 1 by the standard QFT corrections.  PST inherits this
status: Z_Gamma4 = 1 at tree level, with loop corrections following
standard SM RGE (which is what the Buttazzo 2013 calculation accounts
for).

So sub-question (2) is structurally satisfied at the matched-scaling
identification (tree level); the 5-7%% precision deviation noted in
Comp 91 reflects the one-loop SM RGE truncation, not an unresolved
structural issue with Z_Gamma4.

CLOSURE STATUS OF ITEM 1.1
============================
After Comp 103:

  Sub-question (1): SHOWN NOT TO HAVE a direct path-integral Jacobian
    interpretation in standard measure-theoretic sense.  The "Z_phi^2"
    reading of the substrate-side e^(-1) is a structural identification,
    not a derivable Jacobian.
  Sub-question (2): SATISFIED at tree level (standard CC inner
    fluctuations + standard QFT loop corrections).

Net result: Comp 101's hope of "deriving (B) from standard
renormalisation" via path-integral Jacobian DOES NOT CLOSE (B).  The
multiplicative matching is a structural feature of the partition-
function-level CC correspondence, not a consequence of standard QFT.

This is an HONEST NEGATIVE RESULT: closing (B) requires the structural
postulate of partition-function-level CC, just as the peer review
correctly identified.  Comp 103 confirms the peer reviewer's diagnosis.

ITEM 1.1 (bridge premise B) remains OPEN as a STRUCTURAL framework
postulate at the level of CC's spectral-action principle.  The honest
position is to acknowledge (B) as a framework input of partition-
function-level CC, analogous to the spectral-action principle in
standard CC.

WHAT IS POSITIVE FROM COMP 103
================================
1. The structural reduction of Comp 101 is now sharper: sub-question
   (1) does NOT have a measure-theoretic answer.  The open content
   is concentrated in ONE structural identification (the substrate
   trace = SM Z_phi^2).
2. Sub-question (2) is resolved by tree-level CC + standard QFT loop
   running.
3. The closing-act work establishes that PST's PARTITION-FUNCTION-LEVEL
   CC framework adds exactly ONE structural postulate beyond the
   substrate's P1-P3 derivation: the identification of the normalised
   spectral action trace with the SM-side coupling-renormalisation
   ratio.

This is the cleanest statement of where PST stands on the Higgs sector:
P1-P3 + partition-function-level CC postulate -> SM coupling at M_*.
The total postulate count is P1, P2, P3, plus the partition-function-
level CC postulate.  Whether this last postulate has any standing in
the spectral-action literature is the external-validation question
the peer reviewer flagged.
"""
import math


def main():
    print("=" * 100)
    print("  Computation 103 -- Path-integral Jacobian of matched-scaling Pi: explicit attempt")
    print("=" * 100)
    print()

    print("FRAMEWORK")
    print("-" * 100)
    print("  Substrate: psi : P(D) -> R, Bernoulli mu, Walsh basis psi = sum_S c_S chi_S")
    print("  SM-side:   phi : M -> R at matched scale M_* = 4 pi m_h")
    print("  Pi: substrate V_0 + V_1 -> SM vacuum + first mode shell")
    print()
    print("  CONJECTURE (Comp 101 sub-question 1):")
    print("    J(Pi) = exp(-beta_KO * H_Higgs(C))   on substrate configurations")
    print()

    print("DIRECT-COMPUTATION ATTEMPTS")
    print("-" * 100)
    print()
    print("  (A) Linear-map determinant.")
    print("      Pi as a linear map V_0+V_1 -> SM_low has constant |det Pi|.")
    print("      => J(Pi) = constant.  Does NOT depend on configuration C.")
    print("      => Cannot equal exp(-beta_KO * X_bar(C)), which varies with C.")
    print()
    print("  (B) Large-deviation / saddle-point.")
    print("      Bernoulli mu has Cramer-Bernoulli LDP:")
    print("        mu({X_bar approx x}) ~ exp(-D * I(x))")
    print("      with rate function I(x) = x ln(2x) + (1-x) ln(2(1-x)).")
    print()
    print("      Near x = 1/2:  I(x) approx 2 * (x - 1/2)^2  (Gaussian, not exp(-beta * x))")
    print()
    print("      So the LDP weight is Gaussian in (X_bar - 1/2), not exponential in X_bar.")
    print("      => Saddle-point Jacobian does NOT equal exp(-beta_KO * X_bar(C)) either.")
    print()

    # Numerical verification of LDP rate function near 1/2
    print("  Numerical check: LDP rate function I(x) near x = 1/2:")
    print()
    print(f"    {'x':>10} {'I(x) exact':>15} {'2(x-1/2)^2':>15} {'diff':>12}")
    for x in [0.45, 0.48, 0.49, 0.495, 0.499, 0.5, 0.501, 0.505, 0.51, 0.52, 0.55]:
        if x in (0.0, 1.0):
            continue
        I_exact = x * math.log(2*x) + (1-x) * math.log(2*(1-x))
        I_approx = 2 * (x - 0.5)**2
        print(f"    {x:>10.3f} {I_exact:>15.8f} {I_approx:>15.8f} {abs(I_exact - I_approx):>12.2e}")
    print()
    print("  Confirms I(x) is QUADRATIC near 1/2, not linear -- so LDP weight is")
    print("  Gaussian in (X_bar - 1/2), not exponential in X_bar.")
    print()

    print("HONEST FINDING")
    print("-" * 100)
    print()
    print("  Sub-question (1) of Comp 101 -- 'Is Pi's path-integral Jacobian = exp(-beta_KO * X_bar)?'")
    print("  -- has NO direct measure-theoretic answer:")
    print("    - Linear-map determinant gives constant Jacobian, not exp(-beta_KO * X_bar)")
    print("    - LDP saddle-point gives Gaussian weight in (X_bar - 1/2), not exp(-beta_KO * X_bar)")
    print()
    print("  The multiplicative matching form lambda_SM(M_*) = b * Z_H(beta_KO) is therefore")
    print("  NOT derivable from a path-integral change-of-variable.  Comp 101's reframing as")
    print("  wave-function renormalisation was a useful structural reduction but does not")
    print("  close (B) at the measure-theoretic level.")
    print()
    print("  (B) IS the structural postulate of partition-function-level CC, just as the peer")
    print("  reviewer correctly diagnosed.  Comp 103 confirms this diagnosis with a concrete")
    print("  negative result.")
    print()

    print("REVISED STATUS OF ITEM 1.1")
    print("-" * 100)
    print()
    print("  After Comp 103, item 1.1 is RE-CHARACTERISED, not closed:")
    print()
    print("  - Sub-question (1) [Jacobian = exp(-beta_KO * X_bar)]: NEGATIVE result, no direct")
    print("    measure-theoretic answer.")
    print("  - Sub-question (2) [Z_Gamma4 = 1]: satisfied at tree level (standard CC).")
    print()
    print("  Net: (B) remains a STRUCTURAL POSTULATE at the partition-function-level CC")
    print("  framework, at the same level as the spectral-action principle in standard CC.")
    print("  The substrate-side derivation of e^(-1) is real (Comp 100); the matching to")
    print("  SM-side coupling is the structural input.")
    print()
    print("  Honest position: PST has P1-P3 + partition-function-level CC postulate.  The")
    print("  partition-function-level CC postulate is the partition-function analogue of the")
    print("  spectral-action principle in standard CC, with the substrate's Bernoulli measure")
    print("  providing the natural structural inputs.  Whether this postulate has independent")
    print("  standing in the spectral-action literature is an external-validation question.")


if __name__ == "__main__":
    main()
