#!/usr/bin/env python3
# -*- coding: utf-8 -*-
r"""v822 -- PRIME.CONTINUUM.UNSHORTEN.01 (+ PRIME.VACUUM.DILATION.01): the honest kill pair -- the vacuum-completion reading of the continuum is DEAD IN BOTH TRANSCRIPTIONS, with the c* pencil bound as the frozen fence, ONE module from two probes (17/19 + 12/14 checks with the four FAILs being the preregistered PSD deciders themselves; controls 3/3 + 3/3; ~70 s; discovery probes prime_continuum_unshorten_probe.py UNSHORTEN-DEAD and prime_vacuum_dilation_probe.py DILATION-DEAD, both 2026-08-06, first runs after freeze, no repairs).  THE EXACT RM LAYER SURVIVES [E]: 140 2-flats of AG(4,2) = 105 event planes (0 avoided) + 35 origin planes; footprints M^T M = 22I + 6J and N^T N = 6I + J; THE UNSHORTENING IDENTITY A140^T A140 = 28I + 7J = [[35, 7*1],[7*1, (22I+6J) + (6I+J)]] -- the origin planes complete the label Gram ON the label algebra and add the vacuum row; code dims 11/10/11 (ONE origin plane unshortens); Weitzenboeck bookkeeping M^T M = 2B^2 + 14I with complement N^T N integer-exact.  PART 1, THE ONE-SLOT BORDERING: Candidate A (the full continuum lag row in the vacuum slot) dies by the v758 mechanism VERBATIM -- the vacuum principal block is the bare arch+pole Toeplitz, nowhere PSD (GL1 -7.4 -> -212); the predeclared single iteration to Candidate B (counterterm constant kappa I) STILL dies on SCALE (GL1 -5.6 -> -133, f8 -0.52 -> -1.28 on every rung; the u-sector Schur object 7 T_dep - (3/(4 kappa)) T_cont^2 reaches -6.5e+3 against ~1e-5 thin certified-window margins); THE SHAPE THEOREM: ONE vacuum slot induces only a RANK-ONE pure-J label coupling (fit a = -4.7e-16, b = +3.876, residual 3.0e-17) -- the demanded 6I + J repair needs the 35 origin planes as 35 SEPARATE check rows (N (x) legs give N^T N = 6I + J exactly): the corrected target named.  PART 2, THE 35-ROW STINESPRING DILATION (the corrected target, built and decided): the shape is FIXED by construction (construction ward R^T R = w^2 (6I+J) (x) T_cont^2 exact to 7.8e-16; compression ward exact; 50M-dim reduction ward 4.7e-14) and the distribution buys x13.1 vs the one-slot parent -- and STILL dies in both sectors under both frozen normalizations (A/GL1 -2.4 -> -68, B/GL1 -5.6 -> -133, A/f8 -0.056 -> -0.118, B/f8 -0.52 -> -1.28); THE GENERAL OBSTRUCTION QUANTIFIED (the frozen fence): W PSD <=> coupling c <= c* = (2/21) lambda_pencil(T_dep, T_cont^2), with measured deficits x 3.0e7 (GL1, c* = 1.13e-10 at X = 10 vs calibrated c_A = 3.44e-3) and x 2.1e2 (f8) -- the admissible row amplitude is 1.8e-4 (GL1) / 6.9e-2 (f8) of the mass-calibrated one; a sub-calibrated dilation would be PSD but then carries only O(sqrt(c*/c_A)) of the continuum mass -- decorative: THE READING DIES WITH THE CALIBRATION, not the geometry.  ROUTE END (typed plainly): the continuum's completion role is already EXHAUSTED inside T_dep (the explicit-formula balance); the RM vacuum point carries no residual window content; the path-state construction (module 7) is NOT buildable on this gating; the RM integer layer stays certified [E].  Controls fire in both parts (scrambled border/rows break the exact J/6I+J structure, the Epstein x^2+5y^2 window breaks the vacuum/check principal block at -156, the one-slot negative anchor -1.33e+02 is reproduced in-probe).  Deployed machinery READ-ONLY; NO RH/GRH claim (finite-level windows).  Python-only per GATE.WOLFRAM.02.

PROVENANCE: discovery probes prime_continuum_unshorten_probe.py (2026-08-06, 17/19 with the two preregistered PSD-decider FAILs S4.2/S4.3, ~18 s, UNSHORTEN-DEAD) + prime_vacuum_dilation_probe.py (2026-08-06, 12/14 with the two preregistered PSD-decider FAILs S5.1/S5.2, ~48 s, DILATION-DEAD); both re-run identically at promotion.  Merged per the v518/v668 precedent: part 1 verbatim at module level (sibling imports v563/v716/v755 resolve against the verification directory; f8_sector_continuum_probe, conductor_functoriality_probe and epstein_firewall_probe stay read-only discovery imports, v763/v766 precedent); part 2 verbatim inside an isolated function scope (its module-level names are function-local); _LAST1/_LAST2 verdict captures inserted (v791 precedent); numbers unchanged; run() encodes both expected FAIL patterns (v757 precedent).

Original prime_continuum_unshorten_probe.py docstring (verbatim):
prime_continuum_unshorten_probe -- PRIME.CONTINUUM.UNSHORTEN.01:
does the archimedean/pole continuum act as the RM(2,4) vacuum
completion (the 35 origin planes) of the 15-label window objects, and
does the f8 window stay PSD under the combined structure?

THE READING UNDER TEST ([H], frozen): the RM-cascade claim -- the
15-label event checks (the 105 affine planes of AG(4,2) NOT through
0, four labels each) are completed by the 35 ORIGIN planes (0 + a
PG(3,2) line {x, y, x+y}) to the full RM(2,4) check system, the
origin/zero coordinate being the VACUUM point.  Conjecture: the
continuum leg (arch + pole for GL1, arch-only for cuspidal sectors)
plays exactly this completion role -- entering ON the same label
algebra, repairing cross terms, NOT as an additive block (v758
CERT-CONTINUUM-ROOT-DEAD is the binding contrast: arch+pole is
nowhere PSD alone and the additive montage S = S_cont + Delta is
dead; CITED, re-anchored in S2).

REBUILT CONTEXT (integer-exact, no dependence on parallel workers):
  S1 THE RM LAYER: 140 2-flats of AG(4,2) = 105 avoiding 0 + 35
     through 0; label footprints M^T M = 22I + 6J (event checks),
     N^T N = 6I + J (origin planes = the 35 PG(3,2) lines, 3 labels
     each, 7 per label); THE UNSHORTENING IDENTITY
         A140^T A140 = 28I_16 + 7J_16
                     = [[35, 7*1^T], [7*1, (22I+6J) + (6I+J)]]
     -- the origin planes complete the label Gram ON the label
     algebra (the +6I+J cross-term repair) and add the vacuum row
     7*1.  Code layer: the 140 plane indicators span RM(2,4) (F2-dim
     11); the 105 shortened indicators span the vacuum-vanishing
     subcode (dim 10); ONE origin plane unshortens to 11.  Deployed
     label Gram re-anchored: doily B B^T = 4I + 3J (v752/v756
     convention, rebuilt from the symplectic form).
THE CONSTRUCTION RULE (task 1, frozen -- Candidate A):
  per sector s in {GL1 (arch + pole), f8 (arch only, conductor 8)}
  and rung M, on R^M_vac (+) R^{15 M}_lab:
      W(s, M) = [[ V ,           R^T        ],
                 [ R ,  ((4I+3J)/7) (x) T_dep(s) ]]
      R = c_b (1_15 (x) T_cont(s)),   c_b = 7 / sqrt(35 * 28)
                                          = 1/sqrt(20)
      V = T_cont(s)                       (Candidate A: the full
                                           continuum lag row in the
                                           vacuum slot)
  -- label block = THE DEPLOYED 15-label object (doily Gram, unit
  diagonal) times the certified window; vacuum row/column = the
  continuum lags with the RM border weight G16[0,x]/sqrt(G16[0,0]
  G16[x,x]) = 7/sqrt(35*28).  COMPATIBILITY WARD (exact): the
  compression to any single label reproduces T_dep identically
  (diag((4I+3J)/7) = 1).  PREDECLARED ITERATION (task 3): if GL1
  fails PSD under A, iterate ONCE to
      Candidate B: V = kappa I_M, kappa = c_cont(s)[0]  (the c0 /
      counterterm constant in the vacuum slot instead of the full
      lag row) -- documented, no further iteration.
  EXACT SYMMETRY REDUCTION (S15-equivariance, warded once against
  the full 16M-dim matrix at M = 256):
      W ~= [(4/7) T_dep]^{(+)14}  (+)  [[V, (sqrt3/2) T_cont],
                                        [(sqrt3/2) T_cont, 7 T_dep]]
PSD TESTS (task 2, frozen bars -1e-10 ||block||_2, rungs X = 4..10):
  (a) GL1 unshortened window PSD + the compression ward;
  (b) f8 unshortened window PSD (arch-only vacuum slot) -- the kill
      test: measured exactly;
  (c) THE SHAPE DIAGNOSTIC ([H] identification): the vacuum-induced
      label coupling s[x,y] = tr((R R^T)_{xy})/M, fitted to
      a I + b J (frozen least squares); the RM completion demands
      shape 6I + J (a/b = 6, residual 0).  A SINGLE vacuum slot
      induces a rank-one label coupling (pure J, a = 0): if measured
      so, the identification FAILS with a structural lesson -- the
      6I component requires the 35 origin planes as 35 SEPARATE
      check rows (N (x) legs, induced coupling N^T N = 6I + J), a
      35-row Stinespring dilation, not a one-slot bordering; named
      as the corrected target.
CONTROLS (must fire):
  K1 scrambled vacuum row (independent LCG lag permutation per
     label): the induced-coupling shape residual jumps > 0.05;
  K2 the Epstein x^2+5y^2 window in the vacuum slot: the vacuum
     principal block breaks PSD (lambda_min < -10; corpus analogue
     -156);
  K3 a random 16th row (LCG uniform lags per label): fails the
     shape statistic (residual > 0.1).
VERDICT ENUM (frozen):
  UNSHORTEN-CARRIES  : GL1 compatible + f8 PSD + shape matches
                       (res <= 1e-10 and 5.5 <= a/b <= 6.5) -- the
                       vacuum-completion reading gains measured
                       support; the path-state construction then
                       needs the stated dilation data.
  UNSHORTEN-PSD-ONLY : PSD holds, the 6I+J shape fails -- the
                       completion reading stays [H].
  UNSHORTEN-DEAD     : f8 or the GL1 ward/PSD fails after the
                       documented B iteration -- the route's kill,
                       typed plainly.
RESULTS (2026-08-06, first run after freeze, no repairs; 17/19
checks with the two FAILs being the PSD deciders themselves;
controls 3/3; 17.7 s; VERDICT: UNSHORTEN-DEAD -- the route's kill,
typed plainly):
  *  RM layer integer-exact ([E]): 140 = 105 + 35; M^T M = 22I+6J,
     N^T N = 6I+J, A^T A = 28I+7J; code dims 11 / 10 / 11; doily
     B B^T = 4I+3J rebuilt.  The UNSHORTENING IDENTITY holds: the
     origin planes complete ON the label algebra (+6I+J) plus the
     vacuum row 7*1.
  *  v758 contrast re-anchored: bare T_cont nowhere PSD (GL1
     arch+pole -4.97 -> -141 over X = 4..10; f8 arch -0.58 ->
     -0.72); certified T_dep thin-PSD (GL1 +1.2e-5, f8 +3.2e-5 at
     top).
  *  Candidate A: GL1 -7.4 -> -212, f8 -1.24 -> -1.89 (all rungs
     NEG; the vacuum principal block is the bare continuum -- the
     v758 kill transfers verbatim).  Documented single iteration to
     Candidate B (kappa I vacuum slot; kappa = 2.771 GL1 / 7.590
     f8): GL1 -5.6 -> -133, f8 -0.52 -> -1.28 -- STILL NEG on every
     rung; the u-sector Schur object 7 T_dep - (3/(4 kappa))
     T_cont^2 reaches -6.5e+3 (GL1; ||T_cont||^2 = 2.4e+4) against
     ~1e-5 margins.  The wall is SCALE: thin-PSD windows cannot
     absorb any O(1)+ continuum re-entry through a single vacuum
     coordinate.
  *  Shape diagnostic: the vacuum-induced label coupling fits
     a = -4.7e-16, b = +3.876, res = 3.0e-17 -- a RANK-ONE pure-J
     coupling; the RM demand 6I+J is unreachable from one slot (the
     6I component needs 35 separate origin-check rows: N (x) legs
     give N^T N = 6I+J exactly -- the corrected target, a 35-row
     Stinespring dilation, named as the next falsifier).
  *  Reduction ward: full 4096-dim matrix == S15 block reduction to
     6.3e-16 rel.  Compression ward exact (label diag = T_dep).
  *  Controls: K1 scrambled border res 0.066 > 0.05; K2 Epstein
     vacuum block -156 < -10; K3 random row res 0.186 > 0.1.

FENCES: NO RH / GRH claim (finite-level windows); deployed machinery
READ-ONLY; exploration only, ONE new file, writes nothing; no .md,
no commits; AST firewall (no prime tables / zeta symbols).

Run:
    experiments/tfpt-discovery/.venv/bin/python \
        experiments/tfpt-discovery/prime_continuum_unshorten_probe.py

Original prime_vacuum_dilation_probe.py docstring (verbatim):
prime_vacuum_dilation_probe -- PRIME.VACUUM.DILATION.01: the
35-row Stinespring dilation -- the corrected target certified by
PRIME.CONTINUUM.UNSHORTEN.01 (UNSHORTEN-DEAD): the vacuum completion,
if it exists, must enter through the 35 origin planes as SEPARATE
check rows (induced label coupling exactly (6I+J) (x) continuum
Gram), not through one vacuum slot.  This probe builds it and decides
it.

PARENT STATE (2026-08-06, one-slot probe): UNSHORTEN-DEAD -- the
one-slot bordering dies on SCALE (thin ~1e-5 window margins vs O(1)+
continuum re-entry; GL1 -133, f8 -1.28 at top under the counterterm
slot) and on SHAPE (one slot induces a rank-one pure-J coupling; the
RM completion demands 6I+J).  The 35-row form fixes the shape BY
CONSTRUCTION; the open question frozen here is whether distributing
the continuum mass over 35 channels with the 6I+J footprint brings
the re-entry below the window margins (task 2, the quantitative
heart).

THE CONSTRUCTION (frozen):
  space  R^{15 M}_labels (+) R^{35 M}_checks, per sector s in
  {GL1 (arch + pole), f8 (arch only)} and rung M:
      W = [[ L , R^T ],
           [ R ,  V  ]]
      L = ((4I+3J)/7) (x) T_dep(s)     (deployed label block, unit
                                        diagonal: compression ward
                                        mandatory and exact)
      R = w (N (x) T_cont(s))          (N = 35 x 15 origin-plane /
                                        PG(3,2)-line incidence,
                                        chi_P rows, 3 labels each)
      V = I_35 (x) kappa I_M,          kappa = c_cont(s)[0]
  (the check rows are counterterm-flat channels; a T_cont check
  diagonal is excluded A PRIORI: V must be PSD and T_cont is
  certified indefinite -- parent S2.)  CONSTRUCTION WARD (task 3c):
  R^T R = w^2 (6I+J) (x) T_cont^2 exactly -- the continuum enters
  through the RM check geometry.  TWO FROZEN NORMALIZATIONS:
    (A, primary) w_A^2 = 1/105: uniform row weight with the TOTAL
       row mass calibrated to the deployed continuum mass
       (35 rows x |chi_P|^2 = 3 x 1/105 = 1: sum_P ||row_P||_F^2 =
       ||T_cont||_F^2);
    (B) w_B^2 = 1/28: the literal RM parity-check weight (unit-
       diagonal plane-Gram normalization; the Weitzenboeck
       bookkeeping M^T M = 2 B^2 + 14 I with complement
       (28I+7J) - (22I+6J) = 6I+J = N^T N, gated integer-exact).
  EXACT REDUCTION (N's right singular vectors = u (+) mean-zero,
  shared with the label Gram; singular values sqrt(21), sqrt(6)^14):
      W ~= [[7 T_dep, sqrt(21) w T_cont], [., kappa I]]      (u)
       (+) [[(4/7) T_dep, sqrt(6) w T_cont], [., kappa I]]^14 (mz)
       (+) kappa^{(20 M)}                                     (ker N^T)
  warded once against the full 50M-dim matrix at M = 128.
THE SCALE QUESTION (task 2, frozen statistic): W PSD <=> (V > 0 and)
  Schur = L - (w^2/kappa) (6I+J) (x) T_cont^2 >= 0; binding sector =
  label mean-zero: (4/7) T_dep - 6 (w^2/kappa) T_cont^2 >= 0, i.e.
  the coupling c = w^2/kappa must satisfy
      c <= c*(M) = (2/21) lambda_pencil(M),
      lambda_pencil = min gen-eigenvalue of (T_dep, T_cont^2).
  The probe reports per rung: lambda_pencil, c*, the calibrated
  couplings c_A = 1/(105 kappa), c_B = 1/(28 kappa), the DEFICIT
  FACTORS c_A/c*, c_B/c*, and the distribution gain vs the one-slot
  parent (parent u-coupling 3/(4 kappa) vs 35-row 6 w^2/kappa).
PSD DECIDERS (task 3, frozen bars -1e-10 ||block||_2, X = 4..10):
  (a) GL1 dilated PSD + compression ward; (b) f8 dilated PSD (the
  kill test); (c) construction ward (6I+J coupling exact).
ROUTE-END TYPING (task 4, frozen): if both sectors die under both
normalizations, the vacuum-completion reading is DEAD IN BOTH
TRANSCRIPTIONS (one-slot and 35-row); the general obstruction is
quantified: ANY completion re-entering the continuum through the RM
check geometry needs coupling <= c* (measured), i.e. row amplitude
<= sqrt(c* kappa) -- vs the calibrated 1/sqrt(105).  If GL1 carries
and f8 dies: the sector-adapted 35-row form is the next named
object.  If both carry: the path-state construction (module 7)
becomes buildable; its preregistration is stated.
CONTROLS (must fire):
  K1 scrambled plane rows (LCG random 3-subsets): the integer 6I+J
     ward breaks (ell_inf mismatch >= 1);
  K2 the ONE-SLOT form rebuilt in-probe reproduces the parent death
     (GL1 top rung lambda_min < -100; the negative anchor);
  K3 Epstein x^2+5y^2 window as the check-row dynamics: the check
     principal block breaks PSD (lambda_min < -10).
VERDICT ENUM (frozen): DILATION-CARRIES / DILATION-GL1-ONLY /
DILATION-DEAD (with the general scale obstruction quantified).

RESULTS (2026-08-06, first run after freeze, no repairs; 12/14
checks with the two FAILs being the PSD deciders themselves;
controls 3/3; 50 s; VERDICT: DILATION-DEAD -- the route's honest
end, quantified):
  *  Construction exact: 6I+J coupling ward 7.8e-16; Weitzenboeck
     bookkeeping M^T M = 2B^2 + 14I and complement = N^T N integer-
     exact; compression ward exact; 50M-dim reduction ward 4.7e-14.
  *  THE SCALE OBSTRUCTION (the quantitative heart): admissible
     coupling c* = (2/21) lambda_pencil(T_dep, T_cont^2):
       GL1: c* = 1.23e-7 -> 1.13e-10 over X = 4..10 (decaying with
            the rung) vs calibrated c_A = 3.44e-3, c_B = 1.29e-2:
            deficit x 2.8e4 -> x 3.0e7 (A), x 1.1e8 (B, top);
       f8 : c* = 4.13e-5 -> 5.94e-6 (near-saturating) vs c_A =
            1.25e-3: deficit x 30 -> x 211.
     The 35-row distribution buys exactly x 13.12 vs the one-slot
     parent -- orders of magnitude short.  Admissible row amplitude
     = 1.8e-4 (GL1) / 6.9e-2 (f8) of the mass-calibrated amplitude.
     NUANCE (typed): a sub-calibrated dilation with c <= c* is
     PSD-admissible but then carries only O(sqrt(c*/c_A)) of the
     continuum mass -- it no longer REPRESENTS the completion
     (decorative), so the reading dies with the calibration.
  *  PSD deciders: A/GL1 -2.4 -> -68, B/GL1 -5.6 -> -133, A/f8
     -0.056 -> -0.118, B/f8 -0.52 -> -1.28 -- NEG on every rung,
     both sectors, both normalizations.
  *  Controls: K1 scrambled rows break the integer ward (mismatch
     5); K2 one-slot anchor -1.33e+02 reproduced; K3 Epstein check
     dynamics -156.
  *  ROUTE END: the vacuum-completion reading is dead in BOTH
     transcriptions (one-slot bordering + 35-row Stinespring
     dilation); the continuum's completion role is exhausted inside
     T_dep (the explicit-formula balance); the RM integer layer
     stays [E]; the path-state construction (module 7) is NOT
     buildable on this gating.

FENCES: NO RH / GRH claim (finite-level windows); deployed machinery
READ-ONLY; exploration only, ONE new file, writes nothing; no .md,
no commits; AST firewall (no prime tables / zeta symbols).

Run:
    experiments/tfpt-discovery/.venv/bin/python \
        experiments/tfpt-discovery/prime_vacuum_dilation_probe.py
"""

import ast
import hashlib
import math
import os
import sys
import time
from itertools import combinations

import numpy as np
import scipy.linalg as sla

_VERIFY = os.path.dirname(os.path.abspath(__file__))
_DISCOVERY = os.path.abspath(os.path.join(_VERIFY, "..", "experiments",
                                          "tfpt-discovery"))
sys.path.insert(0, _DISCOVERY)
sys.path.insert(0, _VERIFY)

import v563_paper2_readouts as core            # noqa: E402
import v716_moonshot_arch_glue as glue         # noqa: E402
import v755_simpler_schur_recursion as srp     # noqa: E402
import f8_sector_continuum_probe as fsc        # noqa: E402
import conductor_functoriality_probe as cfp    # noqa: E402  (eta_f8)
import epstein_firewall_probe as epx           # noqa: E402

FROZEN_SPEC = """\
PRIME.CONTINUUM.UNSHORTEN.01 spec v1 (frozen 2026-08-06, before the
first run).  Grid D = 1/64, M_TOP = 640, rungs 256..640 step 64
(X = 4..10), N cap 22050, PSD bar -1e-10 ||block||_2.  RM layer:
140 = 105 + 35 flats of AG(4,2), M^T M = 22I+6J, N^T N = 6I+J,
A^T A = 28I+7J, F2-dims 11 / 10 / 11; doily B B^T = 4I+3J.
Construction: label block ((4I+3J)/7) (x) T_dep; border c_b =
1/sqrt(20), R = c_b (1 (x) T_cont); Candidate A vacuum V = T_cont,
Candidate B (one predeclared iteration) V = c_cont[0] I.  Reduction
ward at M = 256 vs the full 16M matrix (<= 1e-8 rel).  Shape
statistic: s[x,y] = tr((R R^T)_{xy})/M, LS fit to aI + bJ;
identification bar res <= 1e-10 and a/b in [5.5, 6.5].  Controls:
K1 scrambled border res > 0.05; K2 Epstein vacuum block < -10;
K3 random row res > 0.1.  LCG seed 20260806.  Verdict enum
UNSHORTEN-CARRIES / -PSD-ONLY / -DEAD.  NO RH/GRH claim; deployed
objects read-only; writes nothing.
"""

DGRID = 1.0 / 64.0
M_TOP = 640
ALPHA_TOP = 0.5 * M_TOP * DGRID
RUNGS = (256, 320, 384, 448, 512, 576, 640)
N_CAP = 22050
PSD_BAR = 1.0e-10
EULER = 0.5772156649015328606
C_BORDER = 7.0 / math.sqrt(35.0 * 28.0)          # = 1/sqrt(20)
CU = math.sqrt(15.0) * C_BORDER                  # = sqrt(3)/2
WARD_M = 256
LCG_SEED = 20260806

BANNED_IDS = ("sympy", "isprime", "primerange", "nextprime", "prevprime",
              "primepi", "zetazero", "nzeros", "mpz_zeta")

CHECKS = []
CONTROL_FIRED = {}
T0 = time.time()
_LCG = [LCG_SEED]
_LAST1 = {}
_LAST2 = {}


def lcg(n):
    _LCG[0] = (1103515245 * _LCG[0] + 12345) % (1 << 31)
    return _LCG[0] % n


def check(name, ok, detail=""):
    CHECKS.append((name, bool(ok)))
    print("  [%s] %s%s" % ("PASS" if ok else "FAIL", name,
                           ("  -- " + detail) if detail else ""), flush=True)
    return bool(ok)


def section(title):
    print("\n" + "=" * 74)
    print(title)
    print("=" * 74, flush=True)


def lam_min_mat(A):
    A = 0.5 * (A + A.T)
    return (float(sla.eigvalsh(A, subset_by_index=[0, 0])[0]),
            float(sla.norm(A, 2)))


# ==================================================================== G0
def g0():
    section("G0 -- SHA-frozen spec + AST firewall")
    print("    FROZEN_SPEC SHA-256 = %s"
          % hashlib.sha256(FROZEN_SPEC.encode()).hexdigest())
    src = open(os.path.abspath(__file__), encoding="utf-8").read()
    bad = []
    for node in ast.walk(ast.parse(src)):
        nm = None
        if isinstance(node, ast.Name):
            nm = node.id
        elif isinstance(node, ast.Attribute):
            nm = node.attr
        elif isinstance(node, (ast.Import, ast.ImportFrom)):
            mods = [al.name for al in node.names]
            if isinstance(node, ast.ImportFrom) and node.module:
                mods.append(node.module)
            bad += [m for m in mods if any(b in m for b in BANNED_IDS)]
            continue
        if nm and nm.lower() in BANNED_IDS:
            bad.append(nm)
    check("G0.1 no prime-table / zeta symbols in this file", not bad,
          "found %s" % bad if bad else "clean")


# ============================================= S1 the RM(2,4) layer
def gf2_rank(vectors, width=16):
    rows = [int(v) for v in vectors]
    rank = 0
    for bit in range(width):
        piv = None
        for i, r in enumerate(rows):
            if (r >> bit) & 1:
                piv = i
                break
        if piv is None:
            continue
        pv = rows.pop(piv)
        rows = [r ^ pv if (r >> bit) & 1 else r for r in rows]
        rank += 1
    return rank


def s1_rm_layer():
    section("S1 -- the RM(2,4) unshortening layer (integer-exact)")
    pts = list(range(16))
    subs = set()
    for x in range(1, 16):
        for y in range(x + 1, 16):
            subs.add(frozenset({0, x, y, x ^ y}))
    subs = sorted(tuple(sorted(s)) for s in subs)
    flats = set()
    for U in subs:
        for a in pts:
            flats.add(frozenset(a ^ u for u in U))
    flats = sorted(tuple(sorted(f)) for f in flats)
    origin = [f for f in flats if 0 in f]
    event = [f for f in flats if 0 not in f]
    check("S1.1 census: 35 subspaces, 140 2-flats = 105 event (0 "
          "avoided, 4 labels) + 35 origin (0 + a PG(3,2) line, 3 "
          "labels)",
          len(subs) == 35 and len(flats) == 140
          and len(event) == 105 and len(origin) == 35
          and all(len(set(f) - {0}) == 3 for f in origin)
          and all(len(f) == 4 for f in event))

    N = np.zeros((35, 15), dtype=np.int64)
    for i, f in enumerate(origin):
        for x in f:
            if x:
                N[i, x - 1] = 1
    M = np.zeros((105, 15), dtype=np.int64)
    for i, f in enumerate(event):
        for x in f:
            M[i, x - 1] = 1
    NtN = N.T @ N
    MtM = M.T @ M
    I15 = np.eye(15, dtype=np.int64)
    J15 = np.ones((15, 15), dtype=np.int64)
    check("S1.2 footprints EXACT: N^T N = 6I + J (origin planes / "
          "PG lines) and M^T M = 22I + 6J (event checks)",
          np.array_equal(NtN, 6 * I15 + J15)
          and np.array_equal(MtM, 22 * I15 + 6 * J15))

    A = np.zeros((140, 16), dtype=np.int64)
    for i, f in enumerate(flats):
        for x in f:
            A[i, x] = 1
    G16 = A.T @ A
    check("S1.3 THE UNSHORTENING IDENTITY: A140^T A140 = 28I + 7J "
          "= [[35, 7*1],[7*1, (22I+6J) + (6I+J)]] -- the 35 origin "
          "planes complete the label Gram ON the label algebra "
          "(cross-term repair +6I+J) and add the vacuum row",
          np.array_equal(G16, 28 * np.eye(16, dtype=np.int64)
                         + 7 * np.ones((16, 16), dtype=np.int64))
          and G16[0, 0] == 35 and np.all(G16[0, 1:] == 7))

    def mask(f):
        m = 0
        for x in f:
            m |= 1 << x
        return m

    mon = [0xFFFF]                                   # the constant 1
    for i in range(4):
        mon.append(sum(1 << p for p in pts if (p >> i) & 1))
    for i, j in combinations(range(4), 2):
        mon.append(sum(1 << p for p in pts
                       if ((p >> i) & 1) and ((p >> j) & 1)))
    rk_code = gf2_rank(mon)
    all_words = mon + [mask(f) for f in flats]
    rk_planes = gf2_rank([mask(f) for f in flats])
    rk_joint = gf2_rank(all_words)
    rk_short = gf2_rank([mask(f) for f in event])
    rk_unsh = gf2_rank([mask(f) for f in event] + [mask(origin[0])])
    check("S1.4 code layer: dim RM(2,4) = 11 (monomials deg <= 2); "
          "the 140 plane indicators SPAN it (rank 11, membership "
          "exact); the 105 shortened checks span the vacuum-"
          "vanishing subcode (rank 10); ONE origin plane unshortens "
          "to 11",
          rk_code == 11 and rk_planes == 11 and rk_joint == 11
          and rk_short == 10 and rk_unsh == 11)

    B = np.zeros((15, 15), dtype=np.int64)
    for x in range(1, 16):
        for y in range(1, 16):
            x1, x2, x3, x4 = (x >> 0) & 1, (x >> 1) & 1, \
                (x >> 2) & 1, (x >> 3) & 1
            y1, y2, y3, y4 = (y >> 0) & 1, (y >> 1) & 1, \
                (y >> 2) & 1, (y >> 3) & 1
            pair = (x1 * y2 + x2 * y1 + x3 * y4 + x4 * y3) % 2
            B[x - 1, y - 1] = int(pair == 0)
    check("S1.5 deployed label Gram re-anchored: doily B (symplectic "
          "perp incidence) has row degree 7, diag 1, B B^T = 4I + 3J "
          "(v752/v756 [E+Lean] convention rebuilt)",
          np.array_equal(B @ B.T, 4 * I15 + 3 * J15)
          and np.all(np.diag(B) == 1)
          and np.all(B.sum(axis=1) == 7))
    return NtN


# ============================================= S2 the window legs
def build_gl1():
    ka = core.atoms_in(ALPHA_TOP)
    cat, _ = core.atom_lags_at(ALPHA_TOP, M_TOP, core.U_ALL[:ka],
                               core.MU_ALL[:ka])
    ccont = core.arch_lags(M_TOP, DGRID) + glue.pole_lags_closed(
        M_TOP, DGRID)
    cdep = ccont + cat
    ka2, masks, devm = srp.channel_masks(ALPHA_TOP)
    c_ref = srp.continuum_lags(M_TOP)
    for cn in ("ro", "re", "sp", "in"):
        c_ref = c_ref + srp.atom_channel_lags(ALPHA_TOP, M_TOP,
                                              masks[cn])
    dev = float(np.max(np.abs(cdep - c_ref)))
    return dict(cont=ccont, dep=cdep, dev=dev)


def build_f8():
    a = cfp.eta_f8(N_CAP)
    spf = np.zeros(N_CAP + 1, dtype=np.int64)
    for p in range(2, N_CAP + 1):
        if spf[p] == 0:
            spf[p::p] = np.where(spf[p::p] == 0, p, spf[p::p])
    primes = [p for p in range(3, N_CAP + 1, 2) if spf[p] == p]
    pos, mas = [], []
    for p in primes:
        u1 = math.log(p)
        if u1 >= 2.0 * ALPHA_TOP:
            break
        t1 = float(a[p]) / p ** 1.5
        tkm1, tkk = 2.0, t1
        k, u = 1, u1
        while u < 2.0 * ALPHA_TOP:
            pos.append(u)
            mas.append(2.0 * tkk * math.log(p) / p ** (0.5 * k))
            tkm1, tkk = tkk, t1 * tkk - tkm1
            k += 1
            u = k * u1
    cat, _ = core.atom_lags_at(ALPHA_TOP, M_TOP, np.array(pos),
                               np.array(mas))
    c0 = math.log(8.0) - 2.0 * math.log(2.0 * math.pi) - 2.0 * EULER
    ccont = fsc.arch_lags_general(M_TOP, DGRID, 2.0, 1.0, c0)
    return dict(cont=ccont, dep=ccont + cat)


def s2_legs():
    section("S2 -- the window legs + the v758 contrast (re-anchored)")
    gl1 = build_gl1()
    f8 = build_f8()
    check("S2.1 GL1 deployed window rebuilt == v755 channel build "
          "(max dev %.1e <= 1e-9)" % gl1["dev"], gl1["dev"] <= 1e-9)
    rows = {}
    for nm, d in (("GL1", gl1), ("f8", f8)):
        dep = [lam_min_mat(sla.toeplitz(d["dep"][:M]))
               for M in RUNGS]
        con = [lam_min_mat(sla.toeplitz(d["cont"][:M]))
               for M in RUNGS]
        rows[nm] = (dep, con)
        print("      %-4s T_dep  lambda_min: %s"
              % (nm, " | ".join("%+.2e" % l for l, _ in dep)))
        print("      %-4s T_cont lambda_min: %s   ||T_cont||(top) "
              "= %.2e" % (nm, " | ".join("%+.2e" % l
                                         for l, _ in con),
                          con[-1][1]))
    ok_dep = all(all(l >= -PSD_BAR * n for l, n in rows[nm][0])
                 for nm in ("GL1", "f8"))
    check("S2.2 certified legs re-anchored: T_dep(GL1) and T_dep(f8) "
          "PSD on all rungs (thin margins)", ok_dep)
    neg_cont = all(rows[nm][1][-1][0] < 0 for nm in ("GL1", "f8"))
    check("S2.3 THE v758 CONTRAST (cited, re-anchored): the bare "
          "continuum Toeplitz is NOT PSD (GL1 arch+pole "
          "lambda_min(top) = %+.2e, f8 arch %+.2e) -- the additive-"
          "block route stays dead; the unshortening must do better "
          "through the vacuum structure"
          % (rows["GL1"][1][-1][0], rows["f8"][1][-1][0]), neg_cont)
    return gl1, f8


# ============================== S3 construction + reduction + ward
def u_block(V, Tc, Td):
    top = np.hstack([V, CU * Tc])
    bot = np.hstack([CU * Tc.T, 7.0 * Td])
    return np.vstack([top, bot])


def sector_ladder(d, cand):
    """lambda_min of W(s, M) per rung by the exact S15 reduction:
    min( (4/7) lam(T_dep), lam(u-block) )."""
    out = []
    for M in RUNGS:
        Td = sla.toeplitz(d["dep"][:M])
        Tc = sla.toeplitz(d["cont"][:M])
        V = Tc if cand == "A" else float(d["cont"][0]) * np.eye(M)
        lu, nu = lam_min_mat(u_block(V, Tc, Td))
        lp, npn = lam_min_mat(Td)
        out.append((min(4.0 / 7.0 * lp, lu), max(nu, 7.0 * npn),
                    lu, 4.0 / 7.0 * lp))
    return out


def s3_construction(gl1):
    section("S3 -- the construction rule, compression ward, "
            "reduction ward")
    print("    RULE (Candidate A): W = [[V, R^T],[R, ((4I+3J)/7) (x) "
          "T_dep]], R = (1/sqrt20)(1_15 (x) T_cont), V = T_cont;")
    print("    Candidate B (predeclared single iteration): V = "
          "c_cont[0] I.  Border weight = G16[0,x]/sqrt(G16[0,0] "
          "G16[x,x]) = 7/sqrt(980).")
    check("S3.1 COMPRESSION WARD (exact): the restriction of the "
          "label block to any single label is 1.0 * T_dep "
          "(diag((4I+3J)/7) = 1) -- the deployed window reproduced "
          "identically", abs((4.0 + 3.0) / 7.0 - 1.0) == 0.0)
    # full-matrix reduction ward at M = 256, candidate B, GL1
    M = WARD_M
    Td = sla.toeplitz(gl1["dep"][:M])
    Tc = sla.toeplitz(gl1["cont"][:M])
    kap = float(gl1["cont"][0])
    G = (4.0 * np.eye(15) + 3.0 * np.ones((15, 15))) / 7.0
    W = np.zeros((16 * M, 16 * M))
    W[:M, :M] = kap * np.eye(M)
    for x in range(15):
        W[:M, (1 + x) * M:(2 + x) * M] = C_BORDER * Tc
        W[(1 + x) * M:(2 + x) * M, :M] = C_BORDER * Tc.T
        for y in range(15):
            W[(1 + x) * M:(2 + x) * M, (1 + y) * M:(2 + y) * M] = \
                G[x, y] * Td
    lam_full, _n = lam_min_mat(W)
    lu, _ = lam_min_mat(u_block(kap * np.eye(M), Tc, Td))
    lp, _ = lam_min_mat(Td)
    lam_red = min(4.0 / 7.0 * lp, lu)
    rel = abs(lam_full - lam_red) / max(abs(lam_full), 1e-300)
    check("S3.2 REDUCTION WARD: full 16M = %d matrix lambda_min = "
          "%+.6e == blockwise reduction %+.6e (rel dev %.1e <= 1e-8) "
          "-- the S15 symmetry reduction is exact"
          % (16 * M, lam_full, lam_red, rel), rel <= 1e-8)
    del W


# ============================================ S4 the PSD deciders
def s4_deciders(gl1, f8):
    section("S4 -- PSD deciders (Candidate A, then the predeclared "
            "B iteration)")
    print("      rung ladder X = 4..10; entries = lambda_min(W) "
          "[u-block | (4/7)T_dep sector]")
    results = {}
    for cand in ("A", "B"):
        for nm, d in (("GL1", gl1), ("f8", f8)):
            lad = sector_ladder(d, cand)
            psd = all(l >= -PSD_BAR * n for l, n, _u, _p in lad)
            results[(cand, nm)] = (psd, lad)
            print("      %s/%-4s: %s  [%s]"
                  % (cand, nm,
                     " | ".join("%+.2e" % l for l, _n, _u, _p in lad),
                     "PSD" if psd else "NEG"))
            print("               u-block leg: %s"
                  % " | ".join("%+.2e" % u for _l, _n, u, _p in lad))
    a_gl1 = results[("A", "GL1")][0]
    check("S4.1 Candidate A / GL1 (full continuum lag row in the "
          "vacuum slot): PSD = %s%s" % (
              a_gl1, "" if a_gl1 else
              " -- the vacuum principal block IS the bare arch+pole "
              "Toeplitz: the v758 kill transfers verbatim; "
              "iterating ONCE to Candidate B as predeclared"),
          True)
    b_gl1, b_f8 = results[("B", "GL1")][0], results[("B", "f8")][0]
    final_gl1 = a_gl1 or b_gl1
    final_f8 = results[("A", "f8")][0] or b_f8
    check("S4.2 FINAL GL1 PSD after the documented iteration "
          "(A: %s, B: %s)" % (a_gl1, b_gl1), final_gl1)
    check("S4.3 FINAL f8 PSD -- the kill test (A: %s, B: %s)"
          % (results[("A", "f8")][0], b_f8), final_f8)
    # anatomy readout: the candidate-B Schur object on the u-sector
    for nm, d in (("GL1", gl1), ("f8", f8)):
        M = M_TOP
        Td = sla.toeplitz(d["dep"][:M])
        Tc = sla.toeplitz(d["cont"][:M])
        kap = float(d["cont"][0])
        S = 7.0 * Td - (CU * CU / kap) * (Tc @ Tc)
        lS, _ = lam_min_mat(S)
        print("    ANATOMY %-4s: kappa = c_cont[0] = %+.4f; u-sector "
              "Schur 7 T_dep - (3/(4 kappa)) T_cont^2: lambda_min = "
              "%+.3e (||T_cont||^2 = %.2e vs thin T_dep margins "
              "~1e-5)" % (nm, kap, lS,
                          float(sla.norm(Tc, 2)) ** 2))
    return results, final_gl1, final_f8


# ============================================= S5 the shape test
def shape_fit(s):
    """LS fit s ~ a I + b J on 15x15; returns (a, b, rel residual)."""
    I15 = np.eye(15)
    J15 = np.ones((15, 15))
    Gm = np.array([[15.0, 15.0], [15.0, 225.0]])
    rhs = np.array([float(np.sum(s * I15)), float(np.sum(s))])
    ab = np.linalg.solve(Gm, rhs)
    fit = ab[0] * I15 + ab[1] * J15
    res = float(np.linalg.norm(s - fit) / max(np.linalg.norm(s),
                                              1e-300))
    return float(ab[0]), float(ab[1]), res


def induced_coupling(blocks, M):
    """s[x,y] = tr(B_x B_y^T)/M for 15 border blocks (M x M)."""
    s = np.zeros((15, 15))
    for x in range(15):
        for y in range(x, 15):
            v = float(np.sum(blocks[x] * blocks[y])) / M
            s[x, y] = s[y, x] = v
    return s


def s5_shape(gl1, NtN):
    section("S5 -- the shape diagnostic ([H] identification test)")
    M = M_TOP
    Tc = sla.toeplitz(gl1["cont"][:M])
    blocks = [C_BORDER * Tc for _ in range(15)]
    s = induced_coupling(blocks, M)
    a, b, res = shape_fit(s)
    ratio = a / b if b != 0 else float("inf")
    match = (res <= 1e-10 and 5.5 <= ratio <= 6.5)
    print("      vacuum-induced label coupling: fit a = %+.4e, "
          "b = %+.4e, a/b = %.3f, residual = %.2e" % (a, b, ratio,
                                                      res))
    print("      RM demand: 6I + J (a/b = 6, residual 0)")
    check("S5.1 shape statistic measured and recorded (frozen "
          "identification bar: res <= 1e-10 AND a/b in [5.5, 6.5]) "
          "-- result: %s" % ("MATCH" if match else
                             "NO MATCH (a = 0: a single vacuum slot "
                             "induces a RANK-ONE pure-J coupling; "
                             "the 6I component is unreachable)"),
          True)
    # the corrected target (readout): 35 separate origin-check rows
    a2, b2, res2 = shape_fit(NtN.astype(float))
    check("S5.2 CORRECTED TARGET (named): 35 origin-check ROWS "
          "(N (x) legs) induce coupling N^T N with fit a = %.1f, "
          "b = %.1f, res = %.1e -- EXACTLY the demanded 6I + J: the "
          "vacuum completion, if it exists, is a 35-row Stinespring "
          "dilation (35 vacuum checks = the origin planes), not a "
          "one-slot bordering" % (a2, b2, res2),
          abs(a2 - 6.0) <= 1e-12 and abs(b2 - 1.0) <= 1e-12
          and res2 <= 1e-12)
    return match


# ================================================== S6 controls
def s6_controls(gl1, f8):
    section("S6 -- controls")
    M = M_TOP
    ccont = gl1["cont"]
    # K1 scrambled vacuum row: independent lag permutation per label
    blocks = []
    for x in range(15):
        cp = ccont[:M].copy()
        for i in range(M - 1, 0, -1):
            j = lcg(i + 1)
            cp[i], cp[j] = cp[j], cp[i]
        blocks.append(C_BORDER * sla.toeplitz(cp))
    a, b, res = shape_fit(induced_coupling(blocks, M))
    CONTROL_FIRED["K1"] = res > 0.05
    check("K1 scrambled vacuum row (independent LCG lag permutation "
          "per label): shape residual %.3f > 0.05 -- the exact "
          "J-structure of the true border is destroyed" % res,
          CONTROL_FIRED["K1"])
    # K2 Epstein window in the vacuum slot
    r1 = epx.lattice_r1(N_CAP)
    bE = np.asarray(r1, float) / 2.0
    lamE = epx.dirichlet_vonmangoldt(bE, N_CAP)
    supp = np.nonzero(np.abs(lamE) > 1e-9)[0]
    supp = supp[supp >= 2]
    posE = np.log(supp.astype(float))
    keep = posE < 2.0 * ALPHA_TOP
    catE, _ = core.atom_lags_at(ALPHA_TOP, M_TOP, posE[keep],
                                (2.0 * lamE[supp]
                                 / np.sqrt(supp.astype(float)))[keep])
    cep = f8["cont"] + catE
    lep, _ = lam_min_mat(sla.toeplitz(cep[:M]))
    CONTROL_FIRED["K2"] = lep < -10.0
    check("K2 the Epstein x^2+5y^2 window in the vacuum slot: the "
          "vacuum principal block breaks PSD (lambda_min = %+.2e < "
          "-10; corpus analogue -156) -- a wrong vacuum object is "
          "detected" % lep, CONTROL_FIRED["K2"])
    # K3 random 16th row
    blocks = []
    for x in range(15):
        rr = np.array([(lcg(2000001) - 1000000) / 1.0e6
                       for _ in range(M)])
        blocks.append(C_BORDER * sla.toeplitz(rr))
    a3, b3, res3 = shape_fit(induced_coupling(blocks, M))
    CONTROL_FIRED["K3"] = res3 > 0.1
    check("K3 random 16th row (LCG uniform lags per label): shape "
          "residual %.3f > 0.1 -- fails the shape statistic as it "
          "must" % res3, CONTROL_FIRED["K3"])


# ================================================================ main
def main():
    print("=" * 74)
    print("PRIME.CONTINUUM.UNSHORTEN.01 -- the continuum as the "
          "RM(2,4) vacuum completion?")
    print("(contrast: v758 CERT-CONTINUUM-ROOT-DEAD; deployed legs: "
          "Gamma_R rule continua + certified windows)")
    print("=" * 74)
    g0()
    NtN = s1_rm_layer()
    gl1, f8 = s2_legs()
    s3_construction(gl1)
    results, final_gl1, final_f8 = s4_deciders(gl1, f8)
    shape_match = s5_shape(gl1, NtN)
    s6_controls(gl1, f8)

    section("VERDICT")
    n_pass = sum(1 for _n, ok in CHECKS if ok)
    n_all = len(CHECKS)
    controls_ok = all(CONTROL_FIRED.get(k, False)
                      for k in ("K1", "K2", "K3"))
    print("%d/%d checks passed; controls %s; runtime %.1f s"
          % (n_pass, n_all, CONTROL_FIRED, time.time() - T0))
    if not (final_gl1 and final_f8):
        v = ("UNSHORTEN-DEAD (GL1 PSD: %s, f8 PSD: %s after the "
             "documented A -> B iteration)" % (final_gl1, final_f8))
        print("""
THE KILL, TYPED PLAINLY (measured above):
  * Candidate A dies by the v758 mechanism VERBATIM: the vacuum
    slot's principal block is the bare continuum Toeplitz, which is
    nowhere PSD (arch+pole for GL1; the arch-only f8 leg measured
    alongside).
  * Candidate B (counterterm constant in the vacuum slot) dies in
    the u-sector Schur object 7 T_dep - (3/(4 kappa)) T_cont^2: the
    certified windows are THIN-PSD (margins ~1e-5) while the border
    re-injects the continuum at O(||T_cont||^2) -- no O(1)-or-larger
    continuum re-entry through a single vacuum coordinate can be
    absorbed.  The scale gap, not the shape, is the wall.
  * The shape diagnostic sharpens the lesson: ONE vacuum slot can
    only induce a rank-one (pure J) label coupling; the RM
    completion demands 6I + J.  The 6I component -- the identity
    part of the repair -- requires the 35 origin planes as 35
    SEPARATE check rows (a Stinespring dilation with border N (x)
    legs, induced coupling N^T N = 6I + J exactly).  The RM integer
    layer itself is EXACT ([E]: 105 + 35 unshortening identity,
    28I + 7J); only its one-slot window transcription is dead.""")
    elif shape_match and controls_ok and n_pass == n_all:
        v = ("UNSHORTEN-CARRIES (GL1 compatible + f8 PSD + 6I+J "
             "shape matched)")
    else:
        v = ("UNSHORTEN-PSD-ONLY (PSD holds; shape %s; the "
             "completion reading stays [H])"
             % ("matched" if shape_match else "FAILS"))
    _LAST1["verdict"] = v
    print("VERDICT: %s" % v)

    section("RECOMMENDED CONTRACT TEXT (report only; nothing written)")
    print("""\
    PRIME.CONTINUUM.UNSHORTEN.01: the RM(2,4) unshortening
    combinatorics is certified integer-exact (140 = 105 event + 35
    origin planes; footprints 22I+6J and 6I+J; completion identity
    28I+7J; code dims 11/10/11; doily 4I+3J re-anchored).  The
    window transcription with the continuum as ONE vacuum
    coordinate is measured as above; the v758 contrast (no additive
    continuum block) is re-anchored and extends: a single-slot
    vacuum bordering re-injects the continuum against thin-margin
    certified windows and cannot carry the 6I component of the
    demanded 6I+J label repair (rank-one obstruction).  NAMED NEXT
    FALSIFIER: the 35-ROW STINESPRING DILATION -- 35 origin-check
    rows N (x) (continuum legs) with induced label coupling
    (6I+J) (x) (leg Gram), where the per-row legs must come from a
    35-fold splitting of the continuum (the Gamma_R rule data per
    origin plane); its PSD question is open and is the corrected
    target shape, exactly parallel to v758's 'cell-wise cascade
    factorization' ending.  NO RH/GRH claim.""")
    return 0 if n_pass == n_all else 1

def _part2():
    # --- prime_vacuum_dilation_probe.py, verbatim inside an isolated function
    # --- scope (v518/v668 merge precedent): its
    # --- module-level names are function-local.
    import ast
    import hashlib
    import math
    import os
    import sys
    import time

    import numpy as np
    import scipy.linalg as sla

    # path swap handled at module level (verification dir first)

    import v563_paper2_readouts as core            # noqa: E402
    import v716_moonshot_arch_glue as glue         # noqa: E402
    import v755_simpler_schur_recursion as srp     # noqa: E402
    import f8_sector_continuum_probe as fsc        # noqa: E402
    import conductor_functoriality_probe as cfp    # noqa: E402  (eta_f8)
    import epstein_firewall_probe as epx           # noqa: E402

    FROZEN_SPEC = """\
    PRIME.VACUUM.DILATION.01 spec v1 (frozen 2026-08-06, before the
    first run).  Grid D = 1/64, M_TOP = 640, rungs 256..640 step 64
    (X = 4..10), N cap 22050, PSD bar -1e-10 ||block||_2.  Construction:
    L = ((4I+3J)/7) (x) T_dep; R = w (N (x) T_cont) with N the 35 x 15
    origin-plane incidence (N^T N = 6I+J); V = kappa I, kappa =
    c_cont[0].  Normalizations: A (primary) w^2 = 1/105 (total mass
    calibration); B w^2 = 1/28 (RM parity-check weight; Weitzenboeck
    gate M^T M = 2B^2 + 14I, complement = N^T N).  Exact reduction
    (u / mean-zero / ker N^T), warded at M = 128 vs the full 50M matrix
    (<= 1e-8 rel).  Scale statistic: lambda_pencil = min gen-eig of
    (T_dep, T_cont^2); c* = (2/21) lambda_pencil; deficits c_A/c*,
    c_B/c*.  Controls: K1 scrambled rows integer mismatch >= 1; K2
    one-slot anchor < -100 (GL1 top); K3 Epstein check dynamics < -10.
    LCG seed 20260806.  Verdict enum DILATION-CARRIES / -GL1-ONLY /
    -DEAD.  NO RH/GRH claim; deployed objects read-only; writes nothing.
    """

    DGRID = 1.0 / 64.0
    M_TOP = 640
    ALPHA_TOP = 0.5 * M_TOP * DGRID
    RUNGS = (256, 320, 384, 448, 512, 576, 640)
    N_CAP = 22050
    PSD_BAR = 1.0e-10
    EULER = 0.5772156649015328606
    W2_A = 1.0 / 105.0
    W2_B = 1.0 / 28.0
    WARD_M = 128
    LCG_SEED = 20260806

    BANNED_IDS = ("sympy", "isprime", "primerange", "nextprime", "prevprime",
                  "primepi", "zetazero", "nzeros", "mpz_zeta")

    CHECKS = []
    CONTROL_FIRED = {}
    T0 = time.time()
    _LCG = [LCG_SEED]


    def lcg(n):
        _LCG[0] = (1103515245 * _LCG[0] + 12345) % (1 << 31)
        return _LCG[0] % n


    def check(name, ok, detail=""):
        CHECKS.append((name, bool(ok)))
        print("  [%s] %s%s" % ("PASS" if ok else "FAIL", name,
                               ("  -- " + detail) if detail else ""), flush=True)
        return bool(ok)


    def section(title):
        print("\n" + "=" * 74)
        print(title)
        print("=" * 74, flush=True)


    def lam_min_mat(A):
        A = 0.5 * (A + A.T)
        return (float(sla.eigvalsh(A, subset_by_index=[0, 0])[0]),
                float(sla.norm(A, 2)))


    # ==================================================================== G0
    def g0():
        section("G0 -- SHA-frozen spec + AST firewall")
        print("    FROZEN_SPEC SHA-256 = %s"
              % hashlib.sha256(FROZEN_SPEC.encode()).hexdigest())
        src = open(os.path.abspath(__file__), encoding="utf-8").read()
        bad = []
        for node in ast.walk(ast.parse(src)):
            nm = None
            if isinstance(node, ast.Name):
                nm = node.id
            elif isinstance(node, ast.Attribute):
                nm = node.attr
            elif isinstance(node, (ast.Import, ast.ImportFrom)):
                mods = [al.name for al in node.names]
                if isinstance(node, ast.ImportFrom) and node.module:
                    mods.append(node.module)
                bad += [m for m in mods if any(b in m for b in BANNED_IDS)]
                continue
            if nm and nm.lower() in BANNED_IDS:
                bad.append(nm)
        check("G0.1 no prime-table / zeta symbols in this file", not bad,
              "found %s" % bad if bad else "clean")


    # ================================= S1 RM / Weitzenboeck integer layer
    def s1_rm():
        section("S1 -- the RM check geometry + Weitzenboeck bookkeeping "
                "(integer-exact)")
        subs = set()
        for x in range(1, 16):
            for y in range(x + 1, 16):
                subs.add(frozenset({0, x, y, x ^ y}))
        origin = sorted(tuple(sorted(s)) for s in subs)
        flats = set()
        for U in origin:
            for a in range(16):
                flats.add(frozenset(a ^ u for u in U))
        event = [f for f in sorted(tuple(sorted(f)) for f in flats)
                 if 0 not in f]
        N = np.zeros((35, 15), dtype=np.int64)
        for i, f in enumerate(origin):
            for x in f:
                if x:
                    N[i, x - 1] = 1
        Mev = np.zeros((105, 15), dtype=np.int64)
        for i, f in enumerate(event):
            for x in f:
                Mev[i, x - 1] = 1
        I15 = np.eye(15, dtype=np.int64)
        J15 = np.ones((15, 15), dtype=np.int64)
        check("S1.1 N^T N = 6I + J (the demanded coupling footprint; 35 "
              "origin rows, 3 labels each, 7 per label)",
              np.array_equal(N.T @ N, 6 * I15 + J15)
              and np.all(N.sum(axis=1) == 3)
              and np.all(N.sum(axis=0) == 7))
        B = np.zeros((15, 15), dtype=np.int64)
        for x in range(1, 16):
            for y in range(1, 16):
                pair = (((x >> 0) & 1) * ((y >> 1) & 1)
                        + ((x >> 1) & 1) * ((y >> 0) & 1)
                        + ((x >> 2) & 1) * ((y >> 3) & 1)
                        + ((x >> 3) & 1) * ((y >> 2) & 1)) % 2
                B[x - 1, y - 1] = int(pair == 0)
        ok_wb = (np.array_equal(Mev.T @ Mev, 2 * (B @ B) + 14 * I15)
                 and np.array_equal(28 * I15 + 7 * J15
                                    - Mev.T @ Mev, N.T @ N))
        check("S1.2 WEITZENBOECK BOOKKEEPING (normalization B anchor): "
              "M^T M = 22I + 6J = 2 B^2 + 14 I (doily complement form) "
              "and (28I + 7J) - M^T M = N^T N -- the 35 rows are the "
              "literal parity-check complement", ok_wb)
        return N


    # ============================================= S2 the window legs
    def build_gl1():
        ka = core.atoms_in(ALPHA_TOP)
        cat, _ = core.atom_lags_at(ALPHA_TOP, M_TOP, core.U_ALL[:ka],
                                   core.MU_ALL[:ka])
        ccont = core.arch_lags(M_TOP, DGRID) + glue.pole_lags_closed(
            M_TOP, DGRID)
        cdep = ccont + cat
        ka2, masks, devm = srp.channel_masks(ALPHA_TOP)
        c_ref = srp.continuum_lags(M_TOP)
        for cn in ("ro", "re", "sp", "in"):
            c_ref = c_ref + srp.atom_channel_lags(ALPHA_TOP, M_TOP,
                                                  masks[cn])
        return dict(cont=ccont, dep=cdep,
                    dev=float(np.max(np.abs(cdep - c_ref))))


    def build_f8():
        a = cfp.eta_f8(N_CAP)
        spf = np.zeros(N_CAP + 1, dtype=np.int64)
        for p in range(2, N_CAP + 1):
            if spf[p] == 0:
                spf[p::p] = np.where(spf[p::p] == 0, p, spf[p::p])
        pos, mas = [], []
        for p in (q for q in range(3, N_CAP + 1, 2) if spf[q] == q):
            u1 = math.log(p)
            if u1 >= 2.0 * ALPHA_TOP:
                break
            t1 = float(a[p]) / p ** 1.5
            tkm1, tkk = 2.0, t1
            k, u = 1, u1
            while u < 2.0 * ALPHA_TOP:
                pos.append(u)
                mas.append(2.0 * tkk * math.log(p) / p ** (0.5 * k))
                tkm1, tkk = tkk, t1 * tkk - tkm1
                k += 1
                u = k * u1
        cat, _ = core.atom_lags_at(ALPHA_TOP, M_TOP, np.array(pos),
                                   np.array(mas))
        c0 = math.log(8.0) - 2.0 * math.log(2.0 * math.pi) - 2.0 * EULER
        ccont = fsc.arch_lags_general(M_TOP, DGRID, 2.0, 1.0, c0)
        return dict(cont=ccont, dep=ccont + cat)


    def s2_legs():
        section("S2 -- the window legs (re-anchored)")
        gl1, f8 = build_gl1(), build_f8()
        check("S2.1 GL1 deployed window rebuilt == v755 channel build "
              "(max dev %.1e <= 1e-9)" % gl1["dev"], gl1["dev"] <= 1e-9)
        ok = True
        for nm, d in (("GL1", gl1), ("f8", f8)):
            ld, _ = lam_min_mat(sla.toeplitz(d["dep"][:M_TOP]))
            lc, nc = lam_min_mat(sla.toeplitz(d["cont"][:M_TOP]))
            d["kappa"] = float(d["cont"][0])
            ok &= ld >= -PSD_BAR
            print("      %-4s: lambda_min(T_dep, top) = %+.2e (thin-PSD); "
                  "lambda_min(T_cont) = %+.2e, ||T_cont|| = %.2e; "
                  "kappa = c_cont[0] = %+.4f"
                  % (nm, ld, lc, nc, d["kappa"]))
        check("S2.2 certified legs PSD; continuum legs indefinite "
              "(parent S2 re-anchored; kappa > 0 both sectors)",
              ok and gl1["kappa"] > 0 and f8["kappa"] > 0)
        return gl1, f8


    # ============================== S3 construction + wards
    def dil_blocks(d, w2, M):
        """Exact reduction blocks of the dilated W at rung M."""
        Td = sla.toeplitz(d["dep"][:M])
        Tc = sla.toeplitz(d["cont"][:M])
        kap = d["kappa"]
        w = math.sqrt(w2)
        bu = np.block([[7.0 * Td, math.sqrt(21.0) * w * Tc],
                       [math.sqrt(21.0) * w * Tc.T, kap * np.eye(M)]])
        bm = np.block([[(4.0 / 7.0) * Td, math.sqrt(6.0) * w * Tc],
                       [math.sqrt(6.0) * w * Tc.T, kap * np.eye(M)]])
        return bu, bm, kap


    def s3_construction(gl1, N):
        section("S3 -- the dilated operator: construction + wards")
        print("    W = [[((4I+3J)/7) (x) T_dep, w (N (x) T_cont)^T],")
        print("         [w (N (x) T_cont),      kappa I_{35M}      ]];")
        print("    normalizations: A (primary) w^2 = 1/105 (mass-"
              "calibrated), B w^2 = 1/28 (RM parity-check weight)")
        check("S3.1 COMPRESSION WARD (exact): the label-block restriction "
              "to any single label is 1.0 * T_dep (diag((4I+3J)/7) = 1)",
              abs((4.0 + 3.0) / 7.0 - 1.0) == 0.0)
        # construction ward at M = 64 (exact structure, cheap numeric)
        M = 64
        Tc = sla.toeplitz(gl1["cont"][:M])
        w = math.sqrt(W2_A)
        R = np.kron(N.astype(float), w * Tc)
        RtR = R.T @ R
        target = np.kron((6.0 * np.eye(15) + np.ones((15, 15))) * W2_A,
                         Tc @ Tc)
        devc = float(np.max(np.abs(RtR - target))
                     / max(1.0, float(np.max(np.abs(target)))))
        check("S3.2 CONSTRUCTION WARD (task 3c): R^T R == w^2 (6I+J) (x) "
              "T_cont^2 exactly (rel dev %.1e <= 1e-12) -- the continuum "
              "enters through the RM check geometry" % devc,
              devc <= 1e-12)
        # reduction ward: full 50M matrix at M = 128, candidate A, GL1
        M = WARD_M
        Td = sla.toeplitz(gl1["dep"][:M])
        Tc = sla.toeplitz(gl1["cont"][:M])
        kap = gl1["kappa"]
        G = (4.0 * np.eye(15) + 3.0 * np.ones((15, 15))) / 7.0
        W = np.zeros((50 * M, 50 * M))
        W[:15 * M, :15 * M] = np.kron(G, Td)
        R = np.kron(N.astype(float), math.sqrt(W2_A) * Tc)
        W[15 * M:, :15 * M] = R
        W[:15 * M, 15 * M:] = R.T
        W[15 * M:, 15 * M:] = kap * np.eye(35 * M)
        lam_full, _ = lam_min_mat(W)
        bu, bm, kap = dil_blocks(gl1, W2_A, M)
        lam_red = min(lam_min_mat(bu)[0], lam_min_mat(bm)[0], kap)
        rel = abs(lam_full - lam_red) / max(abs(lam_full), 1e-300)
        check("S3.3 REDUCTION WARD: full 50M = %d matrix lambda_min = "
              "%+.6e == u/mean-zero/kernel block reduction %+.6e (rel "
              "dev %.1e <= 1e-8)" % (50 * M, lam_full, lam_red, rel),
              rel <= 1e-8)
        del W, R


    # ================================================= S4 the scale table
    def s4_scale(gl1, f8):
        section("S4 -- THE SCALE QUESTION (quantitative heart): "
                "admissible vs calibrated coupling")
        print("      binding sector (label mean-zero): (4/7) T_dep - 6 c "
              "T_cont^2 >= 0  <=>  c <= c* = (2/21) lambda_pencil;")
        print("      lambda_pencil = min gen-eig (T_dep, T_cont^2); "
              "c_A = 1/(105 kappa), c_B = 1/(28 kappa)")
        out = {}
        for nm, d in (("GL1", gl1), ("f8", f8)):
            kap = d["kappa"]
            cA, cB = W2_A / kap, W2_B / kap
            print("      %s (kappa = %.4f, c_A = %.3e, c_B = %.3e):"
                  % (nm, kap, cA, cB))
            print("        rung | lambda_pencil |     c*     | deficit A "
                  "| deficit B")
            worst = None
            for M in RUNGS:
                Td = sla.toeplitz(d["dep"][:M])
                Tc = sla.toeplitz(d["cont"][:M])
                C2 = Tc @ Tc
                lam_p = float(sla.eigh(0.5 * (Td + Td.T),
                                       0.5 * (C2 + C2.T),
                                       subset_by_index=[0, 0],
                                       eigvals_only=True)[0])
                cstar = (2.0 / 21.0) * lam_p
                defA, defB = cA / cstar, cB / cstar
                worst = (M, lam_p, cstar, defA, defB)
                print("        X=%-3d| %11.3e | %10.3e | %9.2e | %9.2e"
                      % (int(M * DGRID), lam_p, cstar, defA, defB))
            out[nm] = dict(cA=cA, cB=cB, top=worst)
            gain = (3.0 / (4.0 * kap)) / (6.0 * cA)
            print("        distribution gain vs the one-slot parent "
                  "(u-coupling 3/(4 kappa) vs 6 w_A^2/kappa): x %.2f"
                  % gain)
        check("S4.1 scale comparison measured and recorded on every rung "
              "(frozen statistic; feeds the verdict and the route-end "
              "typing)", True)
        return out


    # ================================================ S5 PSD deciders
    def s5_deciders(gl1, f8):
        section("S5 -- PSD deciders (both normalizations, both sectors)")
        results = {}
        for cand, w2 in (("A", W2_A), ("B", W2_B)):
            for nm, d in (("GL1", gl1), ("f8", f8)):
                lads = []
                for M in RUNGS:
                    bu, bm, kap = dil_blocks(d, w2, M)
                    lu, nu = lam_min_mat(bu)
                    lm, nmz = lam_min_mat(bm)
                    lads.append((min(lu, lm, kap), max(nu, nmz),
                                 lu, lm))
                psd = all(l >= -PSD_BAR * n for l, n, _u, _m in lads)
                results[(cand, nm)] = (psd, lads)
                print("      %s/%-4s: %s  [%s]"
                      % (cand, nm,
                         " | ".join("%+.2e" % l for l, _n, _u, _m in lads),
                         "PSD" if psd else "NEG"))
                print("               (u | mean-zero at top: %+.2e | "
                      "%+.2e)" % (lads[-1][2], lads[-1][3]))
        gl1_ok = results[("A", "GL1")][0] or results[("B", "GL1")][0]
        f8_ok = results[("A", "f8")][0] or results[("B", "f8")][0]
        check("S5.1 DECIDER (a): GL1 dilated PSD on the ladder "
              "(A: %s, B: %s)" % (results[("A", "GL1")][0],
                                  results[("B", "GL1")][0]), gl1_ok)
        check("S5.2 DECIDER (b): f8 dilated PSD -- the kill test "
              "(A: %s, B: %s)" % (results[("A", "f8")][0],
                                  results[("B", "f8")][0]), f8_ok)
        return results, gl1_ok, f8_ok


    # ================================================== S6 controls
    def s6_controls(gl1, f8, N):
        section("S6 -- controls")
        # K1 scrambled plane rows: LCG random 3-subsets
        Ns = np.zeros((35, 15), dtype=np.int64)
        for i in range(35):
            cols = set()
            while len(cols) < 3:
                cols.add(lcg(15))
            for c in cols:
                Ns[i, c] = 1
        mis = int(np.max(np.abs(Ns.T @ Ns - (6 * np.eye(15, dtype=np.int64)
                                             + np.ones((15, 15),
                                                       dtype=np.int64)))))
        CONTROL_FIRED["K1"] = mis >= 1
        check("K1 scrambled plane rows (LCG random 3-subsets): the "
              "integer 6I+J construction ward breaks (ell_inf mismatch "
              "%d >= 1)" % mis, CONTROL_FIRED["K1"])
        # K2 one-slot negative anchor (parent B/GL1 rebuilt in-probe)
        M = M_TOP
        Td = sla.toeplitz(gl1["dep"][:M])
        Tc = sla.toeplitz(gl1["cont"][:M])
        kap = gl1["kappa"]
        cu = math.sqrt(3.0) / 2.0
        one_slot = np.block([[kap * np.eye(M), cu * Tc],
                             [cu * Tc.T, 7.0 * Td]])
        lam1, _ = lam_min_mat(one_slot)
        CONTROL_FIRED["K2"] = lam1 < -100.0
        check("K2 the ONE-SLOT form rebuilt in-probe: lambda_min(top) = "
              "%+.2e < -100 -- the parent's UNSHORTEN-DEAD anchor "
              "(-1.33e+02) reproduced" % lam1, CONTROL_FIRED["K2"])
        # K3 Epstein window as the check-row dynamics
        r1 = epx.lattice_r1(N_CAP)
        bE = np.asarray(r1, float) / 2.0
        lamE = epx.dirichlet_vonmangoldt(bE, N_CAP)
        supp = np.nonzero(np.abs(lamE) > 1e-9)[0]
        supp = supp[supp >= 2]
        posE = np.log(supp.astype(float))
        keep = posE < 2.0 * ALPHA_TOP
        catE, _ = core.atom_lags_at(ALPHA_TOP, M_TOP, posE[keep],
                                    (2.0 * lamE[supp]
                                     / np.sqrt(supp.astype(float)))[keep])
        lep, _ = lam_min_mat(sla.toeplitz((f8["cont"] + catE)[:M]))
        CONTROL_FIRED["K3"] = lep < -10.0
        check("K3 Epstein x^2+5y^2 window as check-row dynamics: the "
              "check principal block breaks PSD (lambda_min = %+.2e < "
              "-10)" % lep, CONTROL_FIRED["K3"])


    # ================================================================ main
    def main():
        print("=" * 74)
        print("PRIME.VACUUM.DILATION.01 -- the 35-row Stinespring "
              "dilation (the corrected target)")
        print("(parent: PRIME.CONTINUUM.UNSHORTEN.01 = UNSHORTEN-DEAD; "
              "shape fixed by construction, SCALE decided here)")
        print("=" * 74)
        g0()
        N = s1_rm()
        gl1, f8 = s2_legs()
        s3_construction(gl1, N)
        scale = s4_scale(gl1, f8)
        results, gl1_ok, f8_ok = s5_deciders(gl1, f8)
        s6_controls(gl1, f8, N)

        section("VERDICT")
        n_pass = sum(1 for _n, ok in CHECKS if ok)
        n_all = len(CHECKS)
        controls_ok = all(CONTROL_FIRED.get(k, False)
                          for k in ("K1", "K2", "K3"))
        print("%d/%d checks passed; controls %s; runtime %.1f s"
              % (n_pass, n_all, CONTROL_FIRED, time.time() - T0))
        if gl1_ok and f8_ok:
            v = "DILATION-CARRIES"
            print("""
    CONSEQUENCE: the path-state construction (module 7) becomes
    buildable.  Preregistration: path states = the 50-coordinate
    dilation vectors; gates = per-sector PSD persistence, the 6I+J
    coupling ward, and the compression ward on every path composition.""")
        elif gl1_ok:
            v = "DILATION-GL1-ONLY"
            print("""
    CONSEQUENCE: the sector-adapted version of the 35-row form (per-
    sector row normalization from the rule continua) is the next named
    object; the path-state construction stays gated on it.""")
        else:
            v = "DILATION-DEAD"
            tg = scale["GL1"]["top"]
            tf = scale["f8"]["top"]
            print("""
    THE ROUTE'S HONEST END (typed plainly, measured above):
      * The 35-row Stinespring dilation FIXES THE SHAPE (6I+J coupling
        exact, construction ward) and distributes the continuum mass
        over 35 channels (gain x13 vs the one-slot form) -- and STILL
        dies in both sectors under both frozen normalizations.
      * THE GENERAL OBSTRUCTION, QUANTIFIED: any completion re-entering
        the continuum through the RM check geometry needs coupling
        c <= c* = (2/21) lambda_pencil(T_dep, T_cont^2):
          GL1: c* = %.2e at X = 10 vs calibrated c_A = %.2e
               -- deficit x %.1e;
          f8 : c* = %.2e at X = 10 vs calibrated c_A = %.2e
               -- deficit x %.1e.
        Equivalently: the admissible row amplitude is sqrt(c*/c_A) =
        %.1e (GL1) / %.1e (f8) of the mass-calibrated amplitude.  The
        thin-margin certified windows leave NO room for any O(mass)
        continuum re-entry, however it is geometrically distributed:
        the continuum's completion role is already exhausted INSIDE
        T_dep (the explicit-formula balance); the RM vacuum point
        carries no residual window content.
      * VERDICT ON THE READING: the vacuum-completion reading is dead
        in BOTH transcriptions (one-slot bordering, parent; 35-row
        Stinespring dilation, here).  The RM integer layer stays
        certified [E]; the window transcription of the completion is
        closed off.  The path-state construction (module 7) is NOT
        buildable on this gating.""" % (
                tg[2], scale["GL1"]["cA"], tg[3],
                tf[2], scale["f8"]["cA"], tf[3],
                math.sqrt(tg[2] / scale["GL1"]["cA"]),
                math.sqrt(tf[2] / scale["f8"]["cA"])))
        _LAST2["verdict"] = v
        print("VERDICT: %s%s" % (v, "" if controls_ok else
                                 "  (CONTROL VOID: %s)"
                                 % [k for k in ("K1", "K2", "K3")
                                    if not CONTROL_FIRED.get(k, False)]))

        section("RECOMMENDED CONTRACT TEXT (report only; nothing written)")
        print("""\
        PRIME.VACUUM.DILATION.01: the corrected target of the
        unshortening module -- the 35-row Stinespring dilation with
        origin-plane check rows -- is built with the exact 6I+J coupling
        ward (shape closed) and decided on the frozen ladder.  The scale
        statistic c* = (2/21) lambda_pencil(T_dep, T_cont^2) is the
        general admissibility bound for ANY continuum re-entry through
        the RM check geometry; the measured deficit against the mass-
        calibrated coupling decides the reading.  Weitzenboeck
        bookkeeping M^T M = 2B^2 + 14I and complement N^T N = 6I+J are
        integer-certified.  NO RH/GRH claim (finite-level windows).""")
        return 0 if n_pass == n_all else 1
    rc = main()
    return (rc, sum(1 for _n, o in CHECKS if o), len(CHECKS),
            [n.split()[0] for n, o in CHECKS if not o])


def run():
    """run_all entry point (v757 precedent): expected patterns 17/19
    with the two preregistered PSD-decider FAILs S4.2/S4.3 and verdict
    UNSHORTEN-DEAD (part 1), then 12/14 with the two preregistered
    PSD-decider FAILs S5.1/S5.2 and verdict DILATION-DEAD (part 2)."""
    main()
    n1 = sum(1 for _n, ok in CHECKS if ok)
    tot1 = len(CHECKS)
    fails1 = [n.split()[0] for n, ok in CHECKS if not ok]
    v1 = _LAST1.get("verdict", "?")
    print()
    _rc2, n2, tot2, fails2 = _part2()
    v2 = _LAST2.get("verdict", "?")
    ok = (n1 == 17 and tot1 == 19 and fails1 == ["S4.2", "S4.3"]
          and v1.startswith("UNSHORTEN-DEAD")
          and n2 == 12 and tot2 == 14 and fails2 == ["S5.1", "S5.2"]
          and v2 == "DILATION-DEAD")
    print("\n[%s] PATTERN GATE: expected 17/19 (FAILs S4.2 S4.3, "
          "UNSHORTEN-DEAD) + 12/14 (FAILs S5.1 S5.2, DILATION-DEAD); "
          "got %d/%d (fails %s, %s) + %d/%d (fails %s, %s)"
          % ("PASS" if ok else "FAIL", n1, tot1, fails1 or "none", v1,
             n2, tot2, fails2 or "none", v2))
    return 0 if ok else 1


if __name__ == "__main__":
    raise SystemExit(run())
