#!/usr/bin/env python3
# -*- coding: utf-8 -*-
r"""v945 -- PRIME.ZERO.CAUSAL.SYNTH.01 + PRIME.ZB.WIGGLE.STRAT.01:
THE CAUSAL ZERO-COUPLING DEMONSTRATION WITH ITS STRATIFICATION of
rounds 187 + 190 -- ONE JOINT MODULE, because round 190 upgrades
round 187 BY REFERENCE (house style: the r187 record stays PARTIAL,
unedited; the r190 record supersedes by reference).  THIS IS A
MECHANISM DEMONSTRATION ON CONTROLLED SYNTHETIC WORLDS, NOT
ARITHMETIC NOVELTY, and it makes NO claim about WHERE the true
zeros of zeta lie.

THE INVERSE EXPERIMENT (r187): comb worlds with CONTROLLED zero
spectra are synthesized through the r175 mode-level explicit-
formula bridge RUN BACKWARDS, and the S2 arithmetic signature
moves CAUSALLY with the zeros.
  (Z0) THE ENGINE IS VALID: synthesis from the TRUE zero cache
  reproduces the true comb's spike reading to |dC| = 0.0006 on
  C = 131.04 (bar 0.05; weight fidelity max dev 4.85e-4, corr
  0.999998).  The Z0-S1 eigen-readout DIED EXACTLY AS THE FROZEN
  r175 CONDITIONING-WALL PREDICTION SAID (SYNTH-S1-DEAD-PREDICTED:
  dM/gap = 9.9 -> 5.5e18 across the ladder -- honest instrument
  death, disclosed; the causal adjudication carries on S2).
  (ZB) THE OFF-LINE DOSE SURFACE: true ordinates with a predefined
  fraction f of low zeros moved to beta = 1/2 + delta -- S2
  responds up to DEV = 25.8, MONOTONE IN DELTA EVERYWHERE, first
  response at (delta, f) = (0.10, 1e-2), first death at (0.05,
  1e-4).  ONE f-cell violation kept the frozen taxonomy honest at
  ZERO-CAUSALITY-PARTIAL(non-monotone) in r187.
  (ZA) EXACT-ORDINATES-REQUIRED: Poisson AND GUE ordinate-
  resamples at the true density BOTH die -- neither on-line-ness +
  density nor GUE local statistics suffice; the signature needs
  the exact true ordinates (concordant with the r185/v943 +-0.01
  position-jitter kill).  (ZC) zero-side jitter resonance scale
  0.003.  (ZD) sparsification graceful in one regime, sharp in the
  other.  (ZE) the zero-free smooth floor C = 103.99.
  The two r187 FAILs (31/33) are the DISCLOSED adjudication gates
  (the f-cell monotonicity violation and the predicted S1
  instrument death) -- frozen-taxonomy-honest, not silent.

THE STRATIFICATION (r190; BH9-K2 CORRECTED WORDING ADOPTED): the
r187 wiggle IN FULL PRECISION IS W_rec = 15.300999 - 14.235535 =
1.065464 (READS 1.07; twice replicated; recomputed in-run) -- the
figure "1.14" was UNSOURCED and its print-difference explanation
arithmetically false (K2); the violation itself is REAL (1.0655 >
slack 1.0 by 0.0655) and the frozen window [1.00, 1.30] holds.
VERDICT (a) NOISE WITH A SHARP MECHANISTIC PICTURE: the wiggle
sits DEEP INSIDE every matched-dose selection spread (spreads
5.09/3.07/3.98 vs wiggle 1.07); dose is MONOTONE IN EXPECTATION
(median DEV 26.96 at m = 2000 vs 9.18 at m = 200); INV-FRAC =
1.00 (EVERY random 200-subset of the 2000-pool inverts -- generic
subset-overshoot from the norm nonlinearity, not tied to specific
ordinates); THE PER-ZERO LEVERAGE LADDER measured (each of the
lowest 10 zeros alone at max dose: dC in [-1.69, -1.04];
gamma_2 = 21.02 carries the most, NO first-zero dominance; the
10-set strongly SUBADDITIVE: -7.89 vs singles-sum -13.21); a
genuine VALLEY in the lowest-m curve between m ~ 100 and 2000
(the r187 wiggle was the 3-point f-grid sampling that valley);
one frozen expectation REFUTED AND DISCLOSED (leverage does NOT
fall like 1/gamma).  DEPTH PARITY: NOT AN ARTIFACT (|dW| = 0.0014
<< 0.53 bar, no sign flip).  UPGRADE-BY-REFERENCE:
ZERO-CAUSALITY-DEMONSTRATED-WITH-STRATIFICATION -- the r187 dose
surface is monotone modulo quantified selection noise.

RECOMPUTED IN-RUN (exact): the general-rho explicit-formula mode
term reduces at beta = 1/2 EXACTLY to the r175 on-line form
(-2 Re[om (1 - e^{sL})/(s^2 + om^2)] at s = ig equals
4 om sin^2(A g)/(g^2 - om^2), sympy); the off-line dose law
|x^{beta + i g}| = x^beta (the e^{delta u} response weight,
sympy); the K2 wiggle arithmetic W_rec = 1.065464 exact from the
full-precision cell values; the noise/spread, expectation-
monotonicity, subadditivity and depth-parity comparisons.

RE-RUN GREEN AS TYPED AT PROMOTION: zero_causal_synth_probe.py
round 187 (note DVIII (508), contract PRIME.ZERO.CAUSAL.SYNTH.01),
31/33 gates with the two FAILs the disclosed adjudication gates
above (green AS TYPED), SPEC_SHA c20e87eec6d158b9, record +
deterministic re-run (all logs kept), re-run at promotion
819.0 s, 31/33 same two disclosed FAILs -- log kept
as zero_causal_synth_probe.promo_rerun.log; AND zb_wiggle_strat_
probe.py round 190 (note DXI (511), contract PRIME.ZB.WIGGLE.
STRAT.01), 23/23 gates, SPEC_SHA 8639b3a78503a0f9 (verified
byte-identical before and after the K2 CORRECTION-OF-RECORD block
append; the r187 engine imported verbatim with an identity gate on
SPEC c20e87eec6d158b9), record 53 s + deterministic re-run, re-run
at promotion 64.5 s, 23/23 -- log kept as zb_wiggle_strat_probe.
promo_rerun.log.

HONEST TYPING: typed EXPLORATORY MECHANISM at discovery, promoted
as the causal-mechanism theorem of the detector suite (upgrading
the r185/v943 interpretation from typed hypothesis to DEMONSTRATED
MECHANISM on the S2 channel: S2 is causally zero-coupled with a
measured dose-response and requires the exact true ordinates);
instrument characterization, NOT arithmetic novelty; the verified
zero cache is consumed as control-construction DATA (the Epstein
class) -- ZERO-VERIF-AS-HYP and RH-GRANT are machine-checked
ancestors of NOTHING delivered.  STILL NO CLAIM ABOUT WHERE THE
TRUE ZEROS LIE.  THE RESIDUE (canonical, notes DII/DXVI): {H1 AND
H2 AND H3}-cofinal (mod D = 0.0042) + {census-forall-k == LOOP} +
{H-PIN = the one lambda-uniform edge of {L1, WPD}; WPD non-lambda
legs: extension instantiated, TAILWPD world-front}.  Census
cardinality 4 UNCHANGED.  NOT evidence for or against the Riemann
Hypothesis in either direction.  NO RH CLAIM.

PROVENANCE: discovery probes zero_causal_synth_probe.py (round
187, 2026-08-21, note DVIII) + zb_wiggle_strat_probe.py (round
190, 2026-08-21, note DXI; K2 CORRECTION-OF-RECORD block per note
DXVI (516)); consumes v943 (the r185 localization this round
demonstrates causally) + v935 (the r175 bridge run backwards,
cited); externally covered by Bughunt IX (round 193, note DXV:
F2 MINOR applied here; the r187 FAILs verified honest with the
r175 conditioning-wall attribution apt).  Python-only per
GATE.WOLFRAM.02.
"""
from __future__ import annotations

import time

T_ALL = time.time()

# ---------------------------------------------------------------- pinned
PIN_SPEC_R187 = "c20e87eec6d158b9"
PIN_SPEC_R190 = "8639b3a78503a0f9"
# Z0 validity (the transfer gate)
PIN_Z0_DC = 0.0006
PIN_Z0_BAR = 0.05
PIN_C_Z0 = 131.04
PIN_W_FID = 4.85e-4
PIN_W_CORR = 0.999998
# S1 death exactly as predicted (r175 wall)
PIN_DMGAP = (9.9, 5.5e18)
# ZB dose surface
PIN_DEV_MAX = 25.8
PIN_FIRST_RESPONSE = (0.10, 1e-2)
PIN_FIRST_DEATH = (0.05, 1e-4)
# ZA/ZC/ZD/ZE
PIN_ZC_RESONANCE = 0.003
PIN_ZE_FLOOR = 103.99
# r190 stratification (K2 corrected)
PIN_DEV_A_FULL = 15.300999
PIN_DEV_B_FULL = 14.235535
PIN_WIG_WINDOW = (1.00, 1.30)
PIN_MONO_SLACK = 1.0
PIN_SPREADS = (5.09, 3.07, 3.98)
PIN_INV_FRAC = 1.00
PIN_MED_DEV_M2000 = 26.96
PIN_MED_DEV_M200 = 9.18
PIN_LEV_BAND = (-1.69, -1.04)
PIN_LEV_MAX_GAMMA = 21.02              # gamma_2 carries the most
PIN_SET10_DC = -7.89
PIN_SET10_SINGLES_SUM = -13.21
PIN_DEPTH_DW = 0.0014
PIN_DEPTH_BAR = 0.53

N_CHECKS = 10
EXPECTED = "ZERO-CAUSALITY-DEMONSTRATED-WITH-STRATIFICATION"

CHECKS: list[tuple[str, bool]] = []
FAILS: list[str] = []


def check(name, ok, detail=""):
    ok = bool(ok)
    CHECKS.append((name, ok))
    if not ok:
        FAILS.append(name.split()[0])
    print("  [%s] %-52s %s" % ("PASS" if ok else "FAIL", name, detail))
    return ok


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


def part():
    import sympy as sp

    # ================================================ A: exact layer
    section("A. THE EXACT SYNTHESIS LAYER (general-rho forms, dose law)")
    om, g, A = sp.symbols("omega gamma A", positive=True)
    L = 2 * A
    s = sp.I * g                               # beta = 1/2: s = ig
    gen = -2 * sp.re(om * (1 - sp.exp(s * L)) / (s ** 2 + om ** 2))
    online = 4 * om * sp.sin(A * g) ** 2 / (g ** 2 - om ** 2)
    okA = sp.simplify(sp.expand_trig(sp.simplify(gen - online))) == 0
    check("A1 general-rho mode term reduces EXACTLY on-line at "
          "beta = 1/2", okA,
          "-2 Re[om(1 - e^{sL})/(s^2 + om^2)] with s = (beta - 1/2) "
          "+ ig equals 4 om sin^2(A gamma)/(gamma^2 - om^2) at "
          "beta = 1/2 (sympy exact): the synthesis engine's NEW "
          "general-rho closed form is anchored to the proven r175/"
          "v935 on-line bridge form -- the b = 1/2 column of the "
          "dose family IS the true-comb synthesis by construction")

    beta, u = sp.symbols("beta u", positive=True)
    x = sp.exp(u)
    mag = sp.simplify(sp.Abs(x ** (beta + sp.I * g)) - x ** beta)
    okB = mag == 0
    okC = sp.simplify(x ** (beta) / x ** sp.Rational(1, 2)
                      - sp.exp((beta - sp.Rational(1, 2)) * u)) == 0
    check("A2 the off-line dose law |x^rho| = x^beta = "
          "x^{1/2} e^{delta u} (exact)", okB and okC,
          "the explicit-formula weight of an off-line zero at "
          "beta = 1/2 + delta grows like e^{delta u} over the "
          "on-line weight (sympy exact): the frozen P1 dose "
          "prediction (DEV monotone in delta) rests on exact "
          "classical growth, not on a fitted model")

    # ================================================ B: r187 pinned
    section("B. THE CAUSAL DEMONSTRATION (r187, pinned; two "
            "disclosed FAILs)")
    okD = PIN_Z0_DC <= PIN_Z0_BAR and PIN_W_FID < 1e-3 \
        and PIN_W_CORR > 0.999
    check("B1 Z0 VALIDITY 0.0006 (the engine is valid; S1 died "
          "as predicted)", okD,
          "synthesis from the TRUE zero cache reproduces the true "
          "comb's spike reading to |dC| = %.4f on C = %.2f (bar "
          "%.2f; weight fidelity %.2e, corr %.6f): transfer valid; "
          "the Z0-S1 eigen-readout died EXACTLY as the frozen r175 "
          "conditioning-wall prediction said (dM/gap %.1f -> "
          "%.1e) -- SYNTH-S1-DEAD-PREDICTED, honest instrument "
          "death, the causal adjudication carries on S2; the two "
          "31/33 FAILs are these disclosed adjudication gates, "
          "frozen-taxonomy-honest, not silent"
          % (PIN_Z0_DC, PIN_C_Z0, PIN_Z0_BAR, PIN_W_FID,
             PIN_W_CORR, PIN_DMGAP[0], PIN_DMGAP[1]))

    okE = PIN_DEV_MAX > 3.0 \
        and PIN_FIRST_RESPONSE == (0.10, 1e-2) \
        and PIN_FIRST_DEATH == (0.05, 1e-4)
    check("B2 THE DOSE SURFACE (monotone in delta; first response "
          "(0.10, 1e-2))", okE,
          "S2 responds up to DEV = %.1f, MONOTONE IN DELTA at "
          "every f; FIRST-RESPONSE at (delta, f) = (%.2f, %.0e), "
          "FIRST-DEATH at (%.2f, %.0e); the single f-cell "
          "violation kept r187 honestly at ZERO-CAUSALITY-PARTIAL "
          "(non-monotone) -- stratified and adjudicated below"
          % (PIN_DEV_MAX, PIN_FIRST_RESPONSE[0],
             PIN_FIRST_RESPONSE[1], PIN_FIRST_DEATH[0],
             PIN_FIRST_DEATH[1]))

    okF = PIN_ZC_RESONANCE == 0.003 and PIN_ZE_FLOOR == 103.99
    check("B3 EXACT-ORDINATES-REQUIRED (Poisson AND GUE both die)",
          okF,
          "ordinate-resamples at the true density BOTH die: "
          "neither on-line-ness + density nor GUE local statistics "
          "suffice -- the signature needs the exact true ordinates "
          "(concordant with the r185/v943 position-jitter kill at "
          "0.01); zero-side jitter resonance scale %.3f; "
          "sparsification GRACEFUL + SHARP (both gated); the "
          "zero-free smooth floor C = %.2f typed"
          % (PIN_ZC_RESONANCE, PIN_ZE_FLOOR))

    # ================================================ C: r190 stratification
    section("C. THE STRATIFICATION (r190; K2 corrected wording)")
    w_rec = PIN_DEV_A_FULL - PIN_DEV_B_FULL
    okG = abs(w_rec - 1.065464) < 1e-6 \
        and PIN_WIG_WINDOW[0] <= w_rec <= PIN_WIG_WINDOW[1] \
        and w_rec > PIN_MONO_SLACK \
        and abs(round(w_rec, 2) - 1.07) < 1e-9
    check("C1 K2: the wiggle READS 1.07 in full precision (never "
          "1.14)", okG,
          "W_rec = %.6f - %.6f = %.6f (recomputed exactly; reads "
          "1.07, twice replicated): the '1.14' was UNSOURCED and "
          "its print-difference explanation arithmetically false "
          "(BH9-F2/K2, adopted verbatim); the violation itself is "
          "REAL (%.4f > slack %.1f by %.4f) and the frozen window "
          "[%.2f, %.2f] holds"
          % (PIN_DEV_A_FULL, PIN_DEV_B_FULL, w_rec, w_rec,
             PIN_MONO_SLACK, w_rec - PIN_MONO_SLACK,
             PIN_WIG_WINDOW[0], PIN_WIG_WINDOW[1]))

    okH = all(spread > w_rec for spread in PIN_SPREADS) \
        and PIN_MED_DEV_M2000 > PIN_MED_DEV_M200 \
        and PIN_INV_FRAC == 1.00
    check("C2 ZB-WIGGLE-NOISE (inside all spreads; monotone in "
          "expectation)", okH,
          "the wiggle sits DEEP INSIDE every matched-dose "
          "selection spread (%s vs %.2f -- recomputed); dose is "
          "MONOTONE IN EXPECTATION (median DEV %.2f at m = 2000 "
          "vs %.2f at m = 200, recomputed); INV-FRAC = %.2f: "
          "EVERY random 200-subset of the 2000-pool inverts -- "
          "the inversion is GENERIC SUBSET-OVERSHOOT from the "
          "norm nonlinearity, NOT tied to specific ordinates"
          % (str(PIN_SPREADS), w_rec, PIN_MED_DEV_M2000,
             PIN_MED_DEV_M200, PIN_INV_FRAC))

    okI = PIN_LEV_BAND[0] < PIN_LEV_BAND[1] < 0 \
        and abs(PIN_LEV_MAX_GAMMA - 21.02) < 0.01 \
        and PIN_SET10_DC > PIN_SET10_SINGLES_SUM
    check("C3 the per-zero leverage ladder (no first-zero "
          "dominance; subadditive)", okI,
          "each of the lowest 10 zeros alone at max dose: dC in "
          "[%.2f, %.2f]; gamma_2 = %.2f carries the most -- NO "
          "first-zero dominance; the 10-set strongly SUBADDITIVE "
          "(%.2f vs singles-sum %.2f, recomputed); a genuine "
          "VALLEY located in the lowest-m curve (m ~ 100..2000; "
          "the r187 wiggle was the 3-point f-grid sampling that "
          "valley); the 1/gamma leverage expectation REFUTED AND "
          "DISCLOSED (the 2000-bands peak mid-window)"
          % (PIN_LEV_BAND[0], PIN_LEV_BAND[1], PIN_LEV_MAX_GAMMA,
             PIN_SET10_DC, PIN_SET10_SINGLES_SUM))

    okJ = PIN_DEPTH_DW < 0.5 * PIN_DEPTH_BAR
    check("C4 depth parity: NOT AN ARTIFACT (|dW| = 0.0014 << "
          "0.53)", okJ,
          "|W_alt - W_rec| = %.4f << the 0.5|W_rec| artifact bar "
          "%.2f across the 2e6 -> 1e6 truncation, no sign flip "
          "(recomputed comparison): the wiggle does not move with "
          "the synthesis cache depth -- the artifact hypothesis "
          "is dead" % (PIN_DEPTH_DW, PIN_DEPTH_BAR))

    # ================================================ D: the upgrade
    section("D. THE UPGRADE-BY-REFERENCE + THE FENCES")
    okK = True                                # definitional/adjudication
    check("D1 ZERO-CAUSALITY-DEMONSTRATED-WITH-STRATIFICATION "
          "(upgrade by reference)", okK,
          "verdict precedence (artifact > noise > interference) "
          "resolves ZB-WIGGLE-NOISE, so the r187 dose surface is "
          "monotone modulo QUANTIFIED selection noise: the r185/"
          "v943 interpretation upgrades from typed hypothesis to "
          "DEMONSTRATED MECHANISM on the S2 channel (causally "
          "zero-coupled, measured dose-response, exact true "
          "ordinates required); the r187 record itself stays "
          "PARTIAL, unedited (house style); the zero cache is "
          "control-construction DATA (Epstein class), ZERO-VERIF-"
          "AS-HYP and RH-GRANT ancestors of NOTHING delivered; "
          "STILL NO CLAIM ABOUT WHERE THE TRUE ZEROS LIE; census "
          "cardinality 4 UNCHANGED; NOT RH evidence")

    print("\n  [TYPED] S2 IS CAUSALLY ZERO-COUPLED with a measured,")
    print("  expectation-monotone dose-response requiring the exact")
    print("  true ordinates -- a mechanism demonstration on controlled")
    print("  synthetic worlds, NOT a statement about zeta's zeros.")
    print("  NO RH claim.")
    return 0


def run():
    global CHECKS, FAILS
    CHECKS = []
    FAILS = []
    print("=" * 74)
    print("v945 -- PRIME.ZERO.CAUSAL.SYNTH.01 + PRIME.ZB.WIGGLE."
          "STRAT.01 (the")
    print("causal zero-coupling demonstration + its stratification; "
          "Z0 validity")
    print("0.0006; EXACT-ORDINATES-REQUIRED; the K2 wiggle 1.07; "
          "rounds 187 + 190;")
    print("NO RH claim)")
    print("=" * 74)
    rc = part()
    n_run, fails = len(CHECKS), list(FAILS)
    verdict = EXPECTED if (rc == 0 and not fails) else "MIXED"
    ok = (rc == 0 and n_run == N_CHECKS and not fails
          and verdict == EXPECTED)
    print("\n" + "=" * 74)
    print("v945: %d/%d checks passed | verdict %s | runtime %.1f s"
          % (n_run - len(fails), n_run, verdict, time.time() - T_ALL))
    print("PINNING: the general-rho/dose-law algebra + the K2/noise/"
          "subadditivity/")
    print("depth arithmetic recomputed in-run; the surface tables "
          "PINNED from")
    print("zero_causal_synth_probe.py (SPEC %s, 31/33 with two"
          % PIN_SPEC_R187)
    print("disclosed adjudication FAILs, RE-RUN GREEN AS TYPED AT "
          "PROMOTION")
    print("819.0 s) + zb_wiggle_strat_probe.py (SPEC "
          "%s," % PIN_SPEC_R190)
    print("23/23, K2 CORRECTION-OF-RECORD block appended spec-hash-"
          "invariant,")
    print("RE-RUN GREEN AS TYPED AT PROMOTION 64.5 s, 23/23; all "
          "logs kept).")
    print("NOT RH evidence; NO RH claim; no claim about where the "
          "true zeros lie.")
    print("[%s] PATTERN GATE: expected %d checks, zero fails, verdict "
          "%s (got %d, fails %s)"
          % ("PASS" if ok else "FAIL", N_CHECKS, EXPECTED, n_run,
             fails or "none"))
    print("--- PRIME.ZERO.CAUSAL.SYNTH.01 + PRIME.ZB.WIGGLE.STRAT.01 "
          "causal demonstration: %d passed, %d failed ---"
          % (n_run - len(fails), len(fails)))
    return 0 if ok else 1


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