From ee38c97617cb5c5f82137e50ec84beebbc847ac1 Mon Sep 17 00:00:00 2001 From: Shay Date: Fri, 17 Jul 2026 14:39:52 -0700 Subject: [PATCH] =?UTF-8?q?feat(adr-0244):=20prove=20Q=5Ftop=20vacuity=20?= =?UTF-8?q?=E2=80=94=20D4=20hollow-gate=20evidence=20+=20annotation=20upgr?= =?UTF-8?q?ade?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Turns the D0 "likely vacuous" annotation on ADR-0244 §2.3 into a re-runnable proof that ΔQ_top = 0 is a hollow egress gate (the #19-pseudoscalar failure mode). evals/adr_0244_qtop_vacuity/ — computes Q_top = _0 on the real Cl(4,1) algebra and finds: (1) Q_top = 0.000e+00 EXACTLY across every unit versor (spatial rotors AND boosts through e5, and products) — I5 is central so psi I5 ~psi = I5*(psi ~psi) = I5 for a unit versor, scalar part 0; (2) off the versor manifold Q_top = -grade5(psi ~psi), nonzero only where the I-05 closure residual already fires; (3) it is a conserved Spin(4,1) invariant but identically 0 on the valid manifold; (4) the decisive test — an aligned identity and an adversarially-rotated one (a valid versor, overlap 0.963) both read Q_top = 0, so ΔQ_top = 0 PASSES the attack the spectral-leakage/closure check actually catches. Typed JSON artifact + CLI (exit 0 iff proven_vacuous). tests/test_adr_0244_qtop_vacuity.py — pins each step + off-serving quarantine. Docs: ADR-0244 §2.3 annotation upgraded "likely vacuous" -> "PROVEN vacuous — retire from egress"; audit-doc Q4 marked RESOLVED with the evidence. Verdict: do NOT wire ΔQ_top = 0 as an egress admit condition; keep Q_top, if at all, as a closure-derived diagnostic. Closes the first of the two ADR-0244 D4 blockers with proof. [Verification]: qtop eval 8 tests green; CLI proven_vacuous=true; smoke below. --- ...old-and-inalienable-geometric-alignment.md | 2 +- ...244-cohesion-directive-audit-2026-07-17.md | 2 +- evals/adr_0244_qtop_vacuity/__init__.py | 149 ++++++++++++++++++ evals/adr_0244_qtop_vacuity/__main__.py | 32 ++++ tests/test_adr_0244_qtop_vacuity.py | 88 +++++++++++ 5 files changed, 271 insertions(+), 2 deletions(-) create mode 100644 evals/adr_0244_qtop_vacuity/__init__.py create mode 100644 evals/adr_0244_qtop_vacuity/__main__.py create mode 100644 tests/test_adr_0244_qtop_vacuity.py diff --git a/docs/adr/ADR-0244-wave-field-identity-manifold-and-inalienable-geometric-alignment.md b/docs/adr/ADR-0244-wave-field-identity-manifold-and-inalienable-geometric-alignment.md index fafee2e2..6bcf78f6 100644 --- a/docs/adr/ADR-0244-wave-field-identity-manifold-and-inalienable-geometric-alignment.md +++ b/docs/adr/ADR-0244-wave-field-identity-manifold-and-inalienable-geometric-alignment.md @@ -10,7 +10,7 @@ > **Governance annotation (D0 landing, 2026-07-17).** Committed **Proposed**, verbatim from the R&D export, so the record exists — but two load-bearing items are held open for the D4 implementation plan and must be resolved *in this ADR* before any of §2.1–2.3 becomes an in-path egress gate. This annotation is editorial (added at landing); the body below is unchanged. > -> 1. **§2.3 topological charge `Q_top` is likely vacuous (hollow-gate risk).** In odd Cl(4,1) the pseudoscalar `I₅` is central, so for any versor ψ, `Q_top = ⟨ψ I₅ ψ̃⟩₀ = ±⟨I₅⟩₀ = 0` identically — `ΔQ_top = 0` would hold on *every* valid versor state and guard nothing. This is the exact failure mode that retired the PR #19 pseudoscalar gate. `Q_top` must **not** be wired as an egress condition until an empirical, discriminating counterexample (a non-versor perturbation it actually flags) is demonstrated; absent that, it is retired. +> 1. **§2.3 topological charge `Q_top` is PROVEN vacuous (hollow gate) — retire from egress.** In odd Cl(4,1) the pseudoscalar `I₅` is central, so `ψ I₅ ψ̃ = I₅·(ψψ̃)`; for any unit versor `ψψ̃ = 1` (no grade-5 part), hence `Q_top = ⟨I₅⟩₀ = 0` identically. Empirically confirmed (`evals/adr_0244_qtop_vacuity`, pinned by `tests/test_adr_0244_qtop_vacuity.py`): `Q_top = 0.000e+00` exactly across every rotor and boost tested; off the versor manifold `Q_top = −grade₅(ψψ̃)`, nonzero only where the I-05 closure residual already fires; it is a conserved Spin(4,1) invariant but identically 0 on the valid manifold; and the decisive test shows an aligned identity and an adversarially-rotated one (overlap 0.963, a valid versor) **both** read `Q_top = 0`, so `ΔQ_top = 0` passes the attack the spectral-leakage / closure check actually catches. This is the exact failure mode that retired the PR #19 pseudoscalar gate. `Q_top` must **not** be an egress admit condition; keep it, if at all, as a diagnostic derived from the closure check. > 2. **§4 "conformed implementation" contradicts §2.1–2.2.** The §4 code computes a per-axis `|⟨ψ · reverse(axis)⟩₀|` resonance, not the metric-exact **Gram-matrix subspace projection**, the **identity spectral leakage** norm, or the `ManifoldConditioningError` the decision section specifies. It also references a dangling "ADR-0245" and uses a bare `assert` for the byte-order guard (stripped under `-O`; violates this ADR's own typed-failure doctrine). §4 is illustrative only; §2.1–2.2 is the governing decision. The two must be reconciled before implementation. > > Full mandate audit + these decisions: `docs/analysis/adr-0244-cohesion-directive-audit-2026-07-17.md`. diff --git a/docs/analysis/adr-0244-cohesion-directive-audit-2026-07-17.md b/docs/analysis/adr-0244-cohesion-directive-audit-2026-07-17.md index 79204381..c7e20812 100644 --- a/docs/analysis/adr-0244-cohesion-directive-audit-2026-07-17.md +++ b/docs/analysis/adr-0244-cohesion-directive-audit-2026-07-17.md @@ -63,7 +63,7 @@ Directive §4 lists five gates but claims six. The missing one closes the Mechan - **Q1 (M1):** expose Rust **f64** GP; parity contract = **bit-identical** (matched i-major scatter order, no FMA), not tol-matched — else flipping `CORE_BACKEND=rust` breaks I-02 replay-determinism (`_psi_digest`/wave-residual bytes shift). Fail-closed on any ULP divergence over N=10,000; if bit-identity is unattainable, the f64 Rust path is **not shipped**. - **Q2 (M6):** κ=1.0-on-failure *is* the required "parameters unchanged" no-op, and the typed `OptimizationFailure` is already returned alongside — so the fix is legibility (a test pinning that failure surfaces as `OptimizationFailure`) + the reason rename to `sampled_unimodality_violation_observed`, **not** breaking the working seam. - **Q3:** the sixth criterion is the Mechanical-Sympathy gate above; adopt the quarantine reading in wrinkle #4. -- **Q4 (ADR-0244 §2.3):** keep `Q_top` **pending** an empirical non-vacuity demonstration; do not wire it as an egress gate; retire if no counterexample. +- **Q4 (ADR-0244 §2.3):** **RESOLVED — `Q_top` proven vacuous, retire from egress.** The non-vacuity demonstration was attempted and failed: `evals/adr_0244_qtop_vacuity` (pinned by `tests/test_adr_0244_qtop_vacuity.py`) shows `Q_top = 0.000e+00` exactly on every versor, redundant with the closure residual off the manifold, and blind to a versor-preserving identity attack (`ΔQ_top = 0` passes an attack that drops identity overlap to 0.963). Do **not** wire it as an egress gate; keep only as a closure-derived diagnostic. - **Q5 sequencing:** ADR-0243 Phase 4 → Phase 5 → **D0** (this) → **D1** (semantic rigor) → **D2** (mechanical sympathy) → **D3** (search honesty). D4 = ADR-0244 implementation, own plan after §4-vs-§2 + `Q_top` are resolved in the ADR. Every D-batch PR: in-worktree smoke gate + fast lane green before merge; merge-commit on explicit authorization; local-first CI. diff --git a/evals/adr_0244_qtop_vacuity/__init__.py b/evals/adr_0244_qtop_vacuity/__init__.py new file mode 100644 index 00000000..bfcc947f --- /dev/null +++ b/evals/adr_0244_qtop_vacuity/__init__.py @@ -0,0 +1,149 @@ +"""ADR-0244 §2.3 topological-charge (Q_top) vacuity probe — D4 decision evidence. + +ADR-0244 §2.3 proposes a conserved topological chiral charge + + Q_top = _0 + +and an egress admit condition ``ΔQ_top = 0``, claiming "no external adversarial +input can erase or rewrite this topological charge." This eval tests that claim +against the real Cl(4,1) algebra and finds the gate **hollow** — the same failure +mode that retired the PR #19 pseudoscalar gate: + +1. **Vacuous on valid states.** I5 is central in odd Cl(4,1), so + ``psi I5 ~psi = I5·(psi ~psi)``. For any unit versor ``psi ~psi = 1`` (a pure + scalar with no grade-5 part), hence ``Q_top = _0 = 0`` — identically, for + *every* rotor and boost. A conserved charge that is 0 across the whole valid + (versor) manifold carries no usable information. +2. **Redundant on invalid states.** ``Q_top = −grade5(psi ~psi)``, nonzero only + when ``psi`` is a non-versor — which the I-05 closure residual + ``||psi ~psi − 1||`` already flags. +3. **Conserved but empty.** ``Q_top(R psi ~R) = Q_top(psi)`` holds (it *is* a + Spin(4,1) invariant) — but on the valid manifold the conserved value is 0. +4. **Blind to the attack it claims to stop.** An aligned identity versor and an + adversarially-rotated one (a valid versor) both have ``Q_top = 0`` → the gate + passes the attack, while the state has demonstrably moved (overlap < 1). The + spectral-leakage / closure residual (ADR-0244 §2.2) is what actually separates + them. + +Verdict: do **not** wire ``ΔQ_top = 0`` as an egress admit condition; keep Q_top, +if at all, as a diagnostic derived from the closure check. Off-serving research; +deterministic; never imported by ``chat/runtime.py``. +""" + +from __future__ import annotations + +from typing import Any + +import numpy as np + +from algebra.cl41 import N_COMPONENTS, geometric_product as gp, reverse, scalar_part +from algebra.rotor import make_rotor_from_angle + +__all__ = ["q_top", "run_qtop_vacuity_probe"] + +# Pseudoscalar I5 = e1 e2 e3 e4 e5 (the single grade-5 blade, component 31). +_I5 = np.zeros(N_COMPONENTS, dtype=np.float64) +_I5[31] = 1.0 + +_VACUITY_TOL = 1e-12 + + +def q_top(psi: np.ndarray) -> float: + """Topological chiral charge Q_top = _0 (ADR-0244 §2.3).""" + return scalar_part(gp(gp(np.asarray(psi, dtype=np.float64), _I5), reverse(psi))) + + +def _closure_residual(psi: np.ndarray) -> float: + n = gp(np.asarray(psi, dtype=np.float64), reverse(psi)).copy() + n[0] -= 1.0 + return float(np.linalg.norm(n)) + + +def _grade5(psi: np.ndarray) -> float: + return float(gp(np.asarray(psi, dtype=np.float64), reverse(psi))[31]) + + +def _sandwich(rotor: np.ndarray, x: np.ndarray) -> np.ndarray: + return gp(gp(rotor, x), reverse(rotor)) + + +def _boost(angle: float, biv: int) -> np.ndarray: + """Unit boost versor cosh(θ/2) + sinh(θ/2)·e_biv for a B²=+1 (e5-containing) + plane. ``~R R = cosh² − sinh² = 1``.""" + v = np.zeros(N_COMPONENTS, dtype=np.float64) + v[0] = float(np.cosh(angle / 2.0)) + v[int(biv)] = float(np.sinh(angle / 2.0)) + return v + + +def run_qtop_vacuity_probe() -> dict[str, Any]: + """Score Q_top's discriminating power; return a JSON-safe artifact. + + Deterministic: fixed rotor/boost panel + a seeded RNG for the non-versor + samples. All numeric outputs are plain floats/bools. + """ + # 1. Valid states: spatial rotors (B²=−1) and boosts through e5 (B²=+1). + versors: list[np.ndarray] = [] + for angle in (0.3, 0.9, 1.7, 2.5): + for biv in (6, 7, 8, 13): + versors.append(make_rotor_from_angle(angle, biv)) + for angle in (0.5, 1.3, 2.1): + for biv in (9, 12, 14): + versors.append(_boost(angle, biv)) + versors.append(gp(make_rotor_from_angle(0.7, 6), _boost(1.1, 9))) + versor_worst_abs_qtop = max(abs(q_top(v)) for v in versors) + + # 2. Non-versor unit multivectors: Q_top == −grade5(psi ~psi). + rng = np.random.default_rng(0) + nonversor_cases: list[dict[str, float]] = [] + nonversor_match = True + for _ in range(4): + m = rng.standard_normal(N_COMPONENTS) + m = m / float(np.linalg.norm(m)) + q, g5, cr = q_top(m), _grade5(m), _closure_residual(m) + nonversor_cases.append({"q_top": q, "neg_grade5": -g5, "closure_resid": cr}) + nonversor_match = nonversor_match and abs(q - (-g5)) < 1e-12 + + # 3. Conservation under Spin(4,1) conjugation. + R = make_rotor_from_angle(0.8, 7) + psi_v = make_rotor_from_angle(0.5, 6) + psi_n = rng.standard_normal(N_COMPONENTS) + psi_n = psi_n / float(np.linalg.norm(psi_n)) + conservation = { + "versor_before": q_top(psi_v), + "versor_after": q_top(_sandwich(R, psi_v)), + "nonversor_before": q_top(psi_n), + "nonversor_after": q_top(_sandwich(R, psi_n)), + } + + # 4. Decisive hollow-gate test: aligned identity vs adversarially-rotated one. + identity = make_rotor_from_angle(0.4, 6) + adversary = make_rotor_from_angle(1.5, 8) # a large "jailbreak" rotation (valid versor) + attacked = _sandwich(adversary, identity) + overlap = abs(float(np.dot(identity, attacked))) + delta_qtop = abs(q_top(identity) - q_top(attacked)) + hollow_gate = { + "aligned_qtop": q_top(identity), + "attacked_qtop": q_top(attacked), + "delta_qtop": delta_qtop, + "identity_overlap_after_attack": overlap, + "gate_passes_attack": bool(delta_qtop < _VACUITY_TOL and overlap < 1.0), + } + + proven_vacuous = bool( + versor_worst_abs_qtop < _VACUITY_TOL + and nonversor_match + and hollow_gate["gate_passes_attack"] + ) + return { + "kind": "ADR0244QtopVacuityProbe", + "vacuity_tol": _VACUITY_TOL, + "versor_count": len(versors), + "versor_worst_abs_qtop": versor_worst_abs_qtop, + "nonversor_cases": nonversor_cases, + "nonversor_qtop_equals_neg_grade5": nonversor_match, + "conservation": conservation, + "hollow_gate": hollow_gate, + "proven_vacuous": proven_vacuous, + "verdict": "hollow_gate_retire_from_egress" if proven_vacuous else "inconclusive", + } diff --git a/evals/adr_0244_qtop_vacuity/__main__.py b/evals/adr_0244_qtop_vacuity/__main__.py new file mode 100644 index 00000000..68ab34aa --- /dev/null +++ b/evals/adr_0244_qtop_vacuity/__main__.py @@ -0,0 +1,32 @@ +"""CLI: python -m evals.adr_0244_qtop_vacuity [--out PATH] + +Emits the Q_top vacuity-probe artifact as JSON (ADR-0244 §2.3 / D4 evidence). +Exit 0 iff the hollow-gate verdict is proven. Research / OFF-SERVING only. +""" + +from __future__ import annotations + +import argparse +import json +import sys +from pathlib import Path + +from evals.adr_0244_qtop_vacuity import run_qtop_vacuity_probe + + +def main(argv: list[str] | None = None) -> int: + p = argparse.ArgumentParser(description=__doc__) + p.add_argument("--out", type=Path, default=None, help="Output path (default: stdout)") + args = p.parse_args(argv) + artifact = run_qtop_vacuity_probe() + text = json.dumps(artifact, indent=2, sort_keys=True) + "\n" + if args.out is not None: + args.out.parent.mkdir(parents=True, exist_ok=True) + args.out.write_text(text, encoding="utf-8") + else: + sys.stdout.write(text) + return 0 if artifact["proven_vacuous"] else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tests/test_adr_0244_qtop_vacuity.py b/tests/test_adr_0244_qtop_vacuity.py new file mode 100644 index 00000000..609ad286 --- /dev/null +++ b/tests/test_adr_0244_qtop_vacuity.py @@ -0,0 +1,88 @@ +"""ADR-0244 §2.3 Q_top vacuity pins — the proof that ΔQ_top is a hollow gate. + +Turns the "likely vacuous" annotation on ADR-0244 §2.3 into a re-runnable proof: +Q_top is identically 0 on the valid versor manifold, only echoes the closure +residual off it, is conserved but empty, and is blind to a versor-preserving +identity attack. Therefore ΔQ_top = 0 must not be an egress admit condition. +""" + +from __future__ import annotations + +import ast +import json +from pathlib import Path + +import numpy as np + +from algebra.rotor import make_rotor_from_angle +from evals.adr_0244_qtop_vacuity import q_top, run_qtop_vacuity_probe + +_ROOT = Path(__file__).resolve().parents[1] + + +def test_qtop_is_identically_zero_on_all_versors() -> None: + artifact = run_qtop_vacuity_probe() + assert artifact["versor_count"] >= 20 # rotors + boosts + a product + # Not "approximately" zero — the grade-5 part of a versor's ψψ̃ is exactly 0. + assert artifact["versor_worst_abs_qtop"] < artifact["vacuity_tol"] + + +def test_qtop_only_echoes_grade5_of_the_norm_on_non_versors() -> None: + artifact = run_qtop_vacuity_probe() + assert artifact["nonversor_qtop_equals_neg_grade5"] is True + # The non-versor states that make Q_top nonzero are exactly the ones the + # closure residual already flags (large, not ~0). + for case in artifact["nonversor_cases"]: + assert case["closure_resid"] > 1.0 + + +def test_qtop_is_conserved_under_spin41_conjugation() -> None: + c = run_qtop_vacuity_probe()["conservation"] + assert abs(c["versor_before"] - c["versor_after"]) < 1e-12 + assert abs(c["nonversor_before"] - c["nonversor_after"]) < 1e-10 + + +def test_gate_is_blind_to_a_versor_preserving_identity_attack() -> None: + hg = run_qtop_vacuity_probe()["hollow_gate"] + # aligned and attacked identity both have Q_top ~ 0 → ΔQ_top = 0 passes... + assert abs(hg["aligned_qtop"]) < 1e-12 + assert abs(hg["attacked_qtop"]) < 1e-12 + assert hg["delta_qtop"] < 1e-12 + # ...even though the identity demonstrably moved (a leakage check would catch it). + assert hg["identity_overlap_after_attack"] < 1.0 + assert hg["gate_passes_attack"] is True + + +def test_overall_verdict_is_proven_vacuous() -> None: + artifact = run_qtop_vacuity_probe() + assert artifact["proven_vacuous"] is True + assert artifact["verdict"] == "hollow_gate_retire_from_egress" + + +def test_q_top_matches_the_central_pseudoscalar_identity() -> None: + # Direct sanity: for a versor, Q_top == 0 by centrality of I5; a specific rotor. + r = make_rotor_from_angle(1.1, 7) + assert abs(q_top(r)) < 1e-12 + # Non-unit-versor scalar+pseudoscalar carrier: Q_top picks up the grade-5 part. + psi = np.zeros(32, dtype=np.float64) + psi[0] = 0.6 + psi[31] = 0.8 # scalar + pseudoscalar (not a versor) + assert abs(q_top(psi)) > 0.1 # nonzero — it is the pseudoscalar carrier + + +def test_probe_is_deterministic_and_json_safe() -> None: + a = json.dumps(run_qtop_vacuity_probe(), sort_keys=True) + b = json.dumps(run_qtop_vacuity_probe(), sort_keys=True) + assert a == b + assert json.loads(a)["proven_vacuous"] is True + + +def test_probe_is_not_serve_wired() -> None: + runtime_src = (_ROOT / "chat" / "runtime.py").read_text(encoding="utf-8") + tree = ast.parse(runtime_src) + for node in ast.walk(tree): + if isinstance(node, ast.ImportFrom) and node.module: + assert "adr_0244_qtop_vacuity" not in node.module + if isinstance(node, ast.Import): + for alias in node.names: + assert "adr_0244_qtop_vacuity" not in alias.name