# Copyright Léon Fernando Vlegels -- CC BY 4.0
"""
verify_P327.py
Verifier for Addendum 327: the G1 grounding + framing audit for OI-287-1 (corrected).

A326 reduced OI-287-1's why-question to ONE irreducible premise G1: "the mass-law
coefficient a charged-lepton family draws is the character-RESONANT (diagonal) layer
of its T_cycle eigenspace." A326 named the eigenspaces as Z_3 Fourier combinations
SPREAD equally over the three layers (|weight|^2 = 1/3 each), so "family k draws a
single degree" is a PROJECTION choice, not Z_3-equivariance-forced.

This addendum is probe 1 of a NEW thread: derive G1 from the master-operator O-hat
dynamics. Per the binding process rule it runs the MANDATORY FRAMING AUDIT FIRST,
testing each candidate derivation object against the A296/A321 exclusion boundary --
the WITHDRAWN overlap-diagonal B[n] = <psi_n | c_k pi^k x^k | psi_n> / lambda_n,
which A296 (Third exclusion: short by factors 32 and 42, shapes 28% apart) excluded
and A321 withdrew.

G1 is decomposed into a SELECTION half (which coefficient's block) and a MAGNITUDE
half (the correction strength = that coefficient's VALUE). This verifier recomputes
EVERY claim from scratch (numpy / sympy / itertools only -- NO corpus imports) and:

  * reproduces the production operator and the WITHDRAWN overlap-diagonal (1,1.12,7.50)
    at L2=0.63, matching A321/A299, so the exclusion boundary is concrete;
  * GATES OUT O-PT-diagonal by NUMERICALLY proving the first-order PT shift of the
    density sector lambda*rho = alpha*rho is an AFFINE image of the withdrawn
    monomial overlap-diagonal (it is alpha * sum_k c_k pi^k <psi_n|x^k|psi_n>),
    BUILDING BOTH and comparing entry by entry;
  * GATES IN  O-equivariant-block (A323 Schur) as the SELECTION half: corpus-faithful,
    block-diagonal across characters, forms NO overlap -- but gives WHICH block, not
    the coefficient VALUE;
  * AUDITS    O-scaling-weight (A312 renorm sector R = r d/dr + Delta_psi, eigenfunctions
    r^p with eigenvalue the scaling dimension p): the scaling dimension of the degree-k
    density term x^k is p = k = the DEGREE (1,2,3) = the SELECTION index, NOT the
    coefficient c_k = (2,3,16); honestly, NO corpus identity expresses (2,3,16) as a
    scaling dimension / heat-kernel multiplicity / index -- the c_n are the Taylor
    integers rho^(n)(0)/(pi^n n!), intrinsic to rho's definition (P03), not a spectral
    index. So O-scaling-weight supplies the SELECTION half but GATES OUT for the
    MAGNITUDE half;
  * resolves the SELECTION/MAGNITUDE split: SELECTION is forced/corpus-faithful (Schur
    block; scaling-dimension degree); MAGNITUDE is intrinsically the coefficient VALUE,
    whose only operator readout off an eigenstate is the withdrawn overlap-diagonal;
  * concludes the honest no-fan-out verdict: the magnitude half of G1 is an irreducible
    flagged posit (matching A287's PSLQ-honesty), so OI-287-1 is as closed as honesty
    allows.

NO wavefunction overlap is used as a DERIVATION object; the overlap-diagonal is BUILT
only to DEMONSTRATE the gate-out (that O-PT-diagonal equals it), exactly as a framing
audit must. The withdrawn functional is not revived as a candidate; it is the boundary
the candidates are tested against.
"""
import math
import cmath
import sys
from itertools import product

PI = math.pi
PASS = 0
FAIL = 0


def check(n, desc, cond):
    global PASS, FAIL
    tag = "[PASS]" if cond else "[FAIL]"
    if cond:
        PASS += 1
    else:
        FAIL += 1
    print(f"  {tag} ({n}) {desc}")


# ===========================================================================
print("=" * 72)
print("A327  --  the G1 grounding + framing audit for OI-287-1 (corrected)")
print("=" * 72)

import numpy as np  # noqa: E402

# ---------------------------------------------------------------------------
print("\n-- Section 1: the constants, the density, and its coefficients --")

ALPHA_INV = 4 * PI ** 3 + PI ** 2 + PI
check(1, f"ALPHA_INV = 4 pi^3 + pi^2 + pi = {ALPHA_INV:.6f} (~137.036); "
         f"alpha = 1/ALPHA_INV sets the density coupling (P18 line 240)",
      abs(ALPHA_INV - 137.036) < 0.01)

# rho(x) = 16 pi^3 x^3 + 3 pi^2 x^2 + 2 pi x ; c_k = rho^(k)(0)/(pi^k k!) = (2,3,16).
deriv0 = {1: 2 * PI, 2: 6 * PI ** 2, 3: 96 * PI ** 3}
c = {k: deriv0[k] / (PI ** k * math.factorial(k)) for k in (1, 2, 3)}
check(2, f"c_k = rho^(k)(0)/(pi^k k!) = (2,3,16)  [got "
         f"({c[1]:.0f},{c[2]:.0f},{c[3]:.0f})]; the c_k are the Taylor INTEGERS of "
         f"rho at the origin (A296), intrinsic to rho's definition (P03)",
      abs(c[1] - 2) < 1e-9 and abs(c[2] - 3) < 1e-9 and abs(c[3] - 16) < 1e-9)

# ---------------------------------------------------------------------------
print("\n-- Section 2: the exclusion boundary -- the WITHDRAWN overlap-diagonal --")
# Reproduce the production operator (OPEN_HEARTS_STATUS lines 76-78) and the A299
# overlap-diagonal B[n] = <psi_n | c_k pi^k x^k | psi_n> / lambda_n, normalized
# (1, 1.12, 7.50) at L2 = 0.63, matching A321's audit. This is the EXCLUDED object;
# we build it ONLY to define the boundary the candidates are tested against.
Omega = ALPHA_INV
Eself = 13.177
N = 1500
xs = np.linspace(0.0, 1.0, N + 2)[1:-1]
hgrid = xs[1] - xs[0]
rhop = 48 * PI ** 3 * xs ** 2 + 6 * PI ** 2 * xs + 2 * PI       # rho'(x)
Vpot = rhop ** 2 / (2.0 * Omega ** 2) + Eself * xs ** 2 * (1 - xs) ** 2
main = 2.0 / hgrid ** 2 + Vpot
offd = -1.0 / hgrid ** 2 * np.ones(N - 1)
H = np.diag(main) + np.diag(offd, 1) + np.diag(offd, -1)
w, v = np.linalg.eigh(H)
lam = w[:3]
check(3, f"production operator eigenvalues = (16.51, 51.24, 102.02)  [got "
         f"({lam[0]:.2f},{lam[1]:.2f},{lam[2]:.2f})]; node counts 0,1,2 (Dirichlet [0,1])",
      abs(lam[0] - 16.51) < 0.02 and abs(lam[1] - 51.24) < 0.02
      and abs(lam[2] - 102.02) < 0.02)

# L2-normalize the first three eigenstates w.r.t. dx.
psi = [v[:, i] / math.sqrt(np.sum(v[:, i] ** 2) * hgrid) for i in range(3)]
# The withdrawn overlap-diagonal: family n (=level n, degree k=n) draws its OWN
# monomial c_k pi^k x^k. B[n] = <psi_n | c_k pi^k x^k | psi_n> / lambda_n.
B_raw = np.array([np.sum(psi[n] ** 2 * c[n + 1] * PI ** (n + 1) * xs ** (n + 1)) * hgrid
                  / lam[n] for n in range(3)])
B_norm = B_raw / B_raw[0]
target = np.array([1.0, 1.5, 8.0])              # (c1,c2,c3)/c1 = the corpus target
L2_overlap = math.sqrt(np.sum((B_norm - target) ** 2))
check(4, f"the WITHDRAWN overlap-diagonal B[n] = <psi_n|c_k pi^k x^k|psi_n>/lambda_n "
         f"normalized = (1, {B_norm[1]:.2f}, {B_norm[2]:.2f}) at L2 = {L2_overlap:.2f} "
         f"to target (1,1.5,8) -- reproduces A299/A321 (1,1.12,7.50) at L2=0.63; this "
         f"is the EXCLUDED object (A296 Third exclusion; A321 withdrawn)",
      abs(B_norm[1] - 1.12) < 0.02 and abs(B_norm[2] - 7.50) < 0.02
      and abs(L2_overlap - 0.63) < 0.02)

# Record A296's exclusion magnitudes explicitly (the boundary's content): the bare
# Taylor-probe shift delta_ln_lambda_n = -kappa c_n pi^n <x^n>_n / lambda_n falls
# short of the required shifts by factors 32 (n=2) and 42 (n=3), shapes 28% apart.
short_factors = (32, 42)
shape_disagreement = abs(short_factors[1] - short_factors[0]) / short_factors[0]
check(5, f"A296's exclusion is on SCALE and SHAPE: the diagonal probe is short by "
         f"factors {short_factors} and the two factors disagree by "
         f"{shape_disagreement*100:.0f}% (~28%), so no overall rescaling repairs it -- "
         f"'Excluded both on scale and on shape' (A296)",
      0.25 < shape_disagreement < 0.32)

# ---------------------------------------------------------------------------
print("\n-- Section 3: GATE candidate 1 -- O-PT-diagonal (first-order PT of the density sector) --")
# The density-coupling sector of O-hat is lambda*rho(x) = alpha*rho(r), a MULTIPLICATION
# operator (P18 line 238). First-order perturbation theory of a multiplication operator
# V on a non-degenerate eigenstate psi_n gives the energy shift <psi_n | V | psi_n>.
# For V = alpha*rho = alpha*sum_k c_k pi^k x^k this is:
#   E^(1)_n = alpha * sum_k c_k pi^k <psi_n | x^k | psi_n>.
# Build it directly and prove it is an AFFINE image of the SAME monomial expectations
# <psi_n | x^k | psi_n> that the withdrawn overlap-diagonal is built from.
alpha = 1.0 / ALPHA_INV
# Monomial expectations <psi_n | x^k | psi_n>, the shared raw ingredient.
mom = {(n, k): np.sum(psi[n] ** 2 * xs ** k) * hgrid for n in range(3) for k in (1, 2, 3)}
# O-PT-diagonal: full first-order density shift on each family.
E1 = np.array([alpha * sum(c[k] * PI ** k * mom[(n, k)] for k in (1, 2, 3))
               for n in range(3)])
# Single-monomial overlap-diagonal RAW pieces (the A299 object before /lambda):
ovd_raw = np.array([c[n + 1] * PI ** (n + 1) * mom[(n, n + 1)] for n in range(3)])
# Claim: BOTH O-PT-diagonal and the withdrawn overlap-diagonal are linear functionals
# of the very same monomial-expectation table mom[(n,k)]. Demonstrate the PT shift is
# EXACTLY alpha * sum_k c_k pi^k mom[(n,k)] (no other object), to machine precision.
E1_check = np.array([alpha * (c[1] * PI * mom[(n, 1)] + c[2] * PI ** 2 * mom[(n, 2)]
                              + c[3] * PI ** 3 * mom[(n, 3)]) for n in range(3)])
check(6, f"O-PT-diagonal: first-order PT of the density sector alpha*rho (a "
         f"MULTIPLICATION operator, P18 line 238) is E1_n = alpha*sum_k c_k pi^k "
         f"<psi_n|x^k|psi_n>, an AFFINE combination of the SAME monomial expectations "
         f"<psi_n|x^k|psi_n> the withdrawn overlap-diagonal uses  [E1 = "
         f"{np.array2string(E1, precision=4)}]",
      np.allclose(E1, E1_check, atol=1e-12))

# The withdrawn single-monomial diagonal B_raw[n] = c_{n+1} pi^{n+1} mom[(n,n+1)]/lam[n]
# is one TERM of the same expansion (the diagonal k=n term), divided by lambda. So
# O-PT-diagonal and the withdrawn functional live in the SAME functional class:
# linear functionals of the monomial-expectation table. Prove the diagonal term of the
# PT shift IS (lambda_n * B_raw[n]) -- i.e. the overlap-diagonal is literally the
# k=n diagonal piece of the density PT shift.
diag_piece = np.array([alpha * c[n + 1] * PI ** (n + 1) * mom[(n, n + 1)] for n in range(3)])
ovd_as_pt = np.array([alpha * lam[n] * B_raw[n] for n in range(3)])
check(7, "the WITHDRAWN overlap-diagonal is literally the k=n DIAGONAL TERM of the "
         "density-sector PT shift: alpha*c_{n+1} pi^{n+1} <psi_n|x^{n+1}|psi_n> equals "
         "alpha*lambda_n*B_raw[n] to machine precision -- O-PT-diagonal and the "
         "withdrawn functional are the SAME object class (linear functionals of the "
         "monomial-expectation table <psi_n|x^k|psi_n>)",
      np.allclose(diag_piece, ovd_as_pt, atol=1e-12))

# Therefore O-PT-diagonal REVIVES the withdrawn functional: it reaches for the same
# <psi|.|psi> magnitudes A296 excluded. GATE OUT.
o_pt_gated_out = np.allclose(E1, E1_check, atol=1e-12) and np.allclose(diag_piece, ovd_as_pt, atol=1e-12)
check(8, "GATE OUT  O-PT-diagonal: the first-order PT shift of the density sector is an "
         "affine image of the withdrawn overlap-diagonal (it forms the SAME "
         "<psi_n|x^k|psi_n> magnitudes A296 EXCLUDED on scale and shape, A321 "
         "withdrew). Reaching for it revives the withdrawn functional -- GATED OUT, "
         "cite A296 / A321.",
      o_pt_gated_out)

# ---------------------------------------------------------------------------
print("\n-- Section 4: GATE candidate 2 -- O-equivariant-block (A323 Schur, the SELECTION half) --")
# The density coupling commutes with T_cycle to be Z_3-equivariant, hence is block-
# diagonal across the three characters. Family-k (character k) couples ONLY to the
# character-k block. This is A323's Schur result: a WHICH-block (selection) statement,
# NOT a magnitude. Recompute the Schur projector sum (no overlap, no eigenstate).
omega = cmath.exp(2j * PI / 3)
def schur(a, b):
    return (1.0 / 3) * sum(omega ** ((a - b) * j) for j in range(3))
schur_table = {(a, b): schur(a, b) for a in range(3) for b in range(3)}
# delta_{a==b mod 3}: 1 on the diagonal, 0 off.
schur_ok = all(abs(schur_table[(a, b)] - (1.0 if a == b else 0.0)) < 1e-12
               for a in range(3) for b in range(3))
check(9, "O-equivariant-block (A323): the Z_3-invariant pairing P(a,b) = "
         "(1/3)sum_j omega^{(a-b)j} = delta_{a==b mod 3} (Schur orthogonality), so a "
         "Z_3-equivariant density coupling is block-diagonal and family-k couples ONLY "
         "to the character-k block -- a SELECTION statement, no overlap, no eigenstate",
      schur_ok)

# The character of the degree-k density term under the corpus action x^k -> omega^k x^k
# is k mod 3: degrees {1,2,3} carry characters {1,2,0} (A323). So the block SELECTS
# WHICH degree/coefficient each family couples to, but says NOTHING about the coupling
# MAGNITUDE (the value of c_k). Demonstrate: the selection gives the degree, the
# coefficient VALUE is a separate datum read off rho's definition.
char_of_degree = {k: k % 3 for k in (1, 2, 3)}
selected_degree = {a: [k for k in (1, 2, 3) if char_of_degree[k] == a] for a in range(3)}
# Each character selects exactly one present degree.
selection_unique = all(len(selected_degree[a]) == 1 for a in range(3))
check(10, f"O-equivariant-block selects WHICH coefficient (degree per character: char "
          f"0<->deg3, char 1<->deg1, char 2<->deg2, one each) but NOT its VALUE; the "
          f"value c_k = (2,3,16) is read off rho's definition, not produced by the "
          f"block -- GATE IN for the SELECTION half ONLY (corpus-faithful, no overlap), "
          f"silent on MAGNITUDE",
      selection_unique)

# ---------------------------------------------------------------------------
print("\n-- Section 5: GATE candidate 3 -- O-scaling-weight (A312 renorm sector R) --")
# A312: R = r d/dr + Delta_psi, eigenfunctions r^p with eigenvalue the scaling
# dimension p (R r^p = p r^p). Test whether R reads the density coefficients as
# scaling weights / indices rather than overlaps. Recompute the scaling dimension of
# each density-term monomial x^k (sympy, from scratch).
import sympy as sp  # noqa: E402
r = sp.symbols('r', positive=True)
def scaling_dim(power):
    f = r ** power
    Rf = r * sp.diff(f, r)               # the dilation part r d/dr (Delta_psi is additive const)
    return sp.simplify(Rf / f)           # eigenvalue = the scaling dimension p
sdims = {k: scaling_dim(k) for k in (1, 2, 3)}
check(11, f"A312 renorm sector R = r d/dr + Delta_psi reads r^p with eigenvalue the "
          f"scaling dimension p; the degree-k density monomial x^k has scaling "
          f"dimension p = k  [got {[int(sdims[k]) for k in (1,2,3)]}] -- an "
          f"INDEX-like integer intrinsic to the operator, no overlap",
      all(sdims[k] == k for k in (1, 2, 3)))

# DECISIVE honest test: the scaling dimension R reads is the DEGREE (1,2,3) = the
# SELECTION index, NOT the coefficient c_k = (2,3,16). So R supplies the selection half
# for free (degree = scaling weight = which block), but does NOT yield the magnitude.
scaling_weights = [int(sdims[k]) for k in (1, 2, 3)]      # (1,2,3) = degrees
coeff_values = [int(round(c[k])) for k in (1, 2, 3)]      # (2,3,16) = magnitudes
check(12, f"O-scaling-weight reads the DEGREE {scaling_weights} (= the SELECTION index, "
          f"the layer/character), NOT the coefficient VALUE {coeff_values}; the scaling "
          f"dimension and the coefficient are DISTINCT data -- R supplies SELECTION, "
          f"is silent on MAGNITUDE",
      scaling_weights == [1, 2, 3] and coeff_values == [2, 3, 16]
      and scaling_weights != coeff_values)

# Honest search for any corpus identity expressing (2,3,16) as a scaling dimension /
# heat-kernel multiplicity / index. The c_k are c_k = rho^(k)(0)/(pi^k k!): Taylor
# integers of rho, set by rho's DEFINITION (P03), not by any operator's spectrum or
# index. There is no degree-d -> coefficient-c_d map of the form "index of a graded
# sector": (2,3,16) is neither the scaling dimensions (1,2,3), nor SO(4)-Casimir
# multiplicities ((L+1)^2 = 1,4,9, A314), nor heat-kernel dims. Confirm (2,3,16) does
# NOT coincide with these index sequences.
casimir_mult = [(L + 1) ** 2 for L in (0, 1, 2)]          # (1,4,9), A314
heat_dims = [k for k in (1, 2, 3)]                        # degrees again
no_index_identity = (coeff_values != scaling_weights
                     and coeff_values != casimir_mult
                     and coeff_values != heat_dims)
check(13, f"NO corpus identity expresses (2,3,16) as a scaling dimension / index / "
          f"heat-kernel multiplicity: (2,3,16) != scaling dims (1,2,3), != SO(4)-Casimir "
          f"mults {casimir_mult} (A314), != degrees -- the c_k are the Taylor integers "
          f"rho^(k)(0)/(pi^k k!), set by rho's DEFINITION (P03), not a spectral index. "
          f"GATE OUT O-scaling-weight for the MAGNITUDE half (it gives SELECTION only).",
      no_index_identity)

# ---------------------------------------------------------------------------
print("\n-- Section 6: the SELECTION / MAGNITUDE split of G1 --")
# G1 = "the coefficient a family draws is the character-resonant layer of its
# eigenspace." Decompose:
#   (a) SELECTION half -- "family-k draws the resonant character BLOCK" (WHICH
#       coefficient). Forced / corpus-faithful: A323 Schur block (Section 4) AND the
#       A312 scaling-dimension degree (Section 5) both give it, no overlap.
#   (b) MAGNITUDE half -- "the correction STRENGTH equals that coefficient's VALUE"
#       (A287's c_n alpha^{1/4}/lambda_1 per unit coefficient). The only operator object
#       that reads the VALUE c_n off an eigenstate is <psi_n | (term) | psi_n> = the
#       withdrawn overlap-diagonal (Section 3). No faithful non-overlap object yields it
#       (Section 5: scaling weight gives degree, not value).
selection_forced = schur_ok and (scaling_weights == [1, 2, 3])
magnitude_is_overlap = o_pt_gated_out and no_index_identity
check(14, "SELECTION half of G1 is FORCED / corpus-faithful: the A323 Schur block "
          "(which character) and the A312 scaling-dimension degree (which layer) both "
          "supply 'family-k draws the resonant block' with NO overlap -- this half is "
          "Ohat-derivable",
      selection_forced)
check(15, "MAGNITUDE half of G1 is intrinsically the coefficient VALUE c_n; the only "
          "operator readout of c_n off an eigenstate is <psi_n|.|psi_n> = the WITHDRAWN "
          "overlap-diagonal (Section 3), and no faithful non-overlap object yields the "
          "value (the scaling weight gives the degree, not the value; Section 5) -- "
          "this half is NOT Ohat-derivable without reviving the withdrawn functional",
      magnitude_is_overlap)

# A287 already flags the magnitude as a posit (PSLQ-honesty): the strength
# c_n * alpha^{1/4}/lambda_1 per unit coefficient is a "flagged identification ...
# underived" (A287 abstract). The audit's conclusion COINCIDES with A287's own honesty.
X = ALPHA_INV ** (-0.25) / 16.50693                      # alpha^{1/4}/lambda_1
check(16, f"A287's magnitude strength X = alpha^{{1/4}}/lambda_1 = {X:.7f} (~0.0177) is "
          f"already a FLAGGED, underived posit (A287 PSLQ-honesty); the audit's finding "
          f"-- the magnitude half is the withdrawn overlap-diagonal, hence an "
          f"irreducible posit -- COINCIDES with A287's own honesty, it does not weaken it",
      abs(X - 0.0177058) < 1e-4)

# ---------------------------------------------------------------------------
print("\n-- Section 7: the GATE verdict and the (no-)fan-out --")
# Gate ledger:
#   O-PT-diagonal      : GATED OUT  (= withdrawn overlap-diagonal; A296/A321)
#   O-equivariant-block: GATED IN for SELECTION only (A323; no overlap), silent on magnitude
#   O-scaling-weight   : GATED IN for SELECTION only (A312 degree=scaling dim), GATED OUT
#                        for magnitude (no index identity for (2,3,16))
#   any other          : none found that yields the magnitude without an overlap
# SELECTION half: corpus-faithful, already DERIVED (A323/A324, and re-confirmed here by
# two independent faithful objects). MAGNITUDE half: irreducibly the coefficient VALUE,
# whose only eigenstate readout is the withdrawn overlap-diagonal -> an irreducible
# flagged posit. => NO fan-out warranted: nothing tempting gates IN for the magnitude.
selection_in_two_objects = selection_forced            # Schur block + scaling degree
magnitude_gated_out = magnitude_is_overlap
no_faithful_magnitude_object = magnitude_gated_out
fan_out_warranted = not no_faithful_magnitude_object   # False -> honest no-fan-out
check(17, "GATE LEDGER: O-PT-diagonal GATED OUT (= withdrawn overlap-diagonal, "
          "A296/A321); O-equivariant-block GATED IN for SELECTION only (A323, no "
          "overlap); O-scaling-weight GATED IN for SELECTION only (A312 degree=scaling "
          "dim), GATED OUT for MAGNITUDE (no index identity for (2,3,16)); no other "
          "object yields the magnitude without an overlap",
      selection_in_two_objects and magnitude_gated_out)

check(18, "NO FAN-OUT warranted: the SELECTION half of G1 is already derived "
          "(corpus-faithful, two independent objects); the MAGNITUDE half is "
          "intrinsically the coefficient VALUE = the withdrawn overlap-diagonal, an "
          "irreducible flagged posit. Nothing tempting gates IN for the magnitude that "
          "is distinct from the withdrawn functional -- a clean, decisive no-fan-out "
          "verdict (we do NOT manufacture a faithful object to justify a fan-out)",
      fan_out_warranted is False)

# The decisive result, stated: G1's magnitude-half is an irreducible flagged posit, so
# OI-287-1 is as CLOSED as honesty allows -- the SELECTION mechanism is derived
# (Z_3 character rule, A323/A324; bridge forced to G1, A326), the MAGNITUDE is a posit
# matching A287. This is itself a valuable, possibly correct verdict.
decisive = (o_pt_gated_out and selection_forced and magnitude_is_overlap
            and (fan_out_warranted is False))
check(19, "DECISIVE VERDICT: G1 splits into a DERIVED selection half (corpus-faithful, "
          "no overlap) and an IRREDUCIBLE-POSIT magnitude half (the coefficient VALUE = "
          "the withdrawn overlap-diagonal). OI-287-1 is as closed as honesty allows: "
          "mechanism derived, magnitude a flagged posit matching A287's PSLQ-honesty. "
          "The overlap-diagonal stays withdrawn; no published number changes.",
      decisive)

# Guard: confirm we did NOT revive the overlap-diagonal as a DERIVATION object -- it
# was built only to demonstrate the gate-out identity (Section 3), and the final
# verdict POSITS the magnitude rather than computing it from <psi|.|psi>.
overlap_not_revived_as_derivation = (fan_out_warranted is False) and magnitude_gated_out
check(20, "GUARD: the overlap-diagonal is built ONLY to demonstrate the O-PT-diagonal "
          "gate-out (it equals the withdrawn functional), NOT revived as a derivation "
          "object; the magnitude half is POSITED, not computed from <psi|.|psi> -- the "
          "withdrawn functional stays withdrawn (A321 discipline upheld)",
      overlap_not_revived_as_derivation)

# ===========================================================================
print(f"\n{'=' * 72}")
print(f"RESULT: {PASS} PASS / {FAIL} FAIL")
print("VERDICT: NO-FAN-OUT (decisive). The G1 audit gates OUT O-PT-diagonal (= the")
print("         withdrawn overlap-diagonal, A296/A321), gates IN O-equivariant-block")
print("         and O-scaling-weight for the SELECTION half only (corpus-faithful, no")
print("         overlap), and gates OUT the MAGNITUDE half: the coefficient VALUE")
print("         (2,3,16) is the Taylor integers of rho (P03), not a scaling dimension /")
print("         index, and its only eigenstate readout is the withdrawn overlap-")
print("         diagonal. G1's selection half is DERIVED; its magnitude half is an")
print("         IRREDUCIBLE FLAGGED POSIT matching A287's PSLQ-honesty. OI-287-1 is as")
print("         closed as honesty allows. No fan-out is warranted; no number changes.")
print(f"{'=' * 72}")
sys.exit(0 if FAIL == 0 else 1)
