Skip to content

EP-0253: Verification Engine Hardening, Falsifiability & Grounded Formal Proofs

Field Value
EP 0253
Title Verification Engine Hardening, Falsifiability & Grounded Formal Proofs
Author Eran Rivlis eran@rivlis.info, Antigravity
Sponsor Core Maintainers
Delegate 🔬 Popper (Falsifiability) & 🧪 Bacon (Empiricism)
Status Final
Type Standards Track
Created 2026-11-26
Updated 2026-11-29
Replaces —
Superseded-By —

Prerequisites: Depends on EP-0250 (CommQuotientRing, GaloisField, CliffordAlgebra, HasStar), EP-0251 (matrix/spectral regressions), and EP-0252 (GroupHopfAlgebra). Must land before EP-0254's internal split of verification/_algebra.py, verification/_rep.py, and tests/verifications/.


Abstract

This proposal hardens algebrax.verification and the multi-layered verification test suite so that every verifier is genuinely falsifiable across both infinite and tiny finite structures (including \(\mathbb{F}_2\), BooleanSemiring, and the trivial group). It eliminates vacuous True passes caused by iterator exhaustion, empty/all-zero sample sets, NaN == NaN / container-identity / negated-inequality bypasses, swallowed exceptions, early-break masking, and missing axiom checks (notably \(\Delta(ab) = \Delta(a)\Delta(b)\) in verify_bialgebra_laws and positive-definiteness in verify_normed_space_laws), grounds the Z3 SMT proof suite in live algebrax code with bounded CI timeouts, and closes critical falsification test blind spots across finite fields, Clifford algebras, matrix decompositions, and spectral graphs.


Motivation

A verification engine that can silently return True on broken implementations undermines the entire "Stamp of Trust" promised by AlgebraX. The Second Grand Council Audit uncovered systemic falsifiability holes:

  1. Iterator Exhaustion, Early-Break Masking & Exception Swallowing (verification/_semiring.py, _algebra.py):
  2. verify_semiring_laws has no minimum-sample guard (samples=[] passes all 9 axioms).
  3. verify_star_semiring_laws, verify_kleene_algebra_laws, verify_action_algebra_laws, and verify_hopf_algebra_laws pass raw Iterable samples to inner verifiers (consuming generators), then iterate samples again—evaluating to [] and vacuously passing all laws.
  4. except (ValueError, ZeroDivisionError, OverflowError, NotImplementedError): continue and isinf/isnan skips lack a tested_count guard, so stubs raising NotImplementedError or returning NaN vacuously pass.
  5. Early-break bugs (left_conway = False; break and or / negated-conjunction breaks in verify_star_plus_consistency, verify_residuation_laws, verify_lattice_laws, verify_distributive_lattice_laws, and verify_non_assoc_ring_laws) exit on the first failing law, leaving sibling laws falsely True.
  6. NaN Bypasses, Missing Axioms & Vacuous Witnesses (_common.py, _algebra.py, _rep.py, _topology.py):
  7. _float_equal returns True for (nan, nan), semiring_elements_equal short-circuits if a == b: return True before container recursion (passing identical-object tuples/dicts containing NaN), and negated float inequalities (< -tol, > bound + tol) silently pass NaN in _algebra.py and _topology.py.
  8. verify_bialgebra_laws omits \(\Delta(a \cdot b) = \Delta(a) \cdot \Delta(b)\), checks only sum(delta_one.values()) == 1 instead of \(\Delta(1) = 1 \otimes 1\), uses combinations(c_elements, 2) instead of ordered pairs, and omits ring distributivity / scalar bilinearity.
  9. verify_normed_space_laws omits positive definiteness (accepting the zero seminorm norm(v) = 0.0) and hardcodes r_mag = 1.0 for Fraction/Decimal; verify_inner_product_space_laws pins w = v_elements[0] and crashes on Fraction/Decimal scalar multiplication.
  10. Empty or zero-witness vacuous passes exist in verify_matrix_conway_laws, verify_coassociativity, verify_counitality, verify_antipode_axiom, verify_division_ring_laws, verify_contraction_constant, verify_quantum_sl2_relations, verify_artin_braid_relations, verify_lie_representation_homomorphism, verify_sheaf_laplacian_properties, verify_sheaf_functoriality, verify_connection_inversion, verify_chern_character_additivity, verify_category_laws (0 composable triples), and verify_padic_ultrametric_inequality.
  11. Disconnected SMT Proof Suite (tests/verifications/test_smt_z3_proofs.py):
  12. All 343 lines contain zero imports or calls to algebrax, proving hand-transcribed formulas and a pure tautology for LawvereMetricCategory. Breaking every semiring in src/algebrax/ leaves all SMT tests green.
  13. Happy-Path-Only Test Blind Spots:
  14. tests/algebrax/test_verification.py lacks generator-exhaustion and adversarial falsification tests across _semiring, _algebra, _rep, _topology, and _variety.
  15. test_galois.py tested only monic \(p=2\); test_clifford.py tested only Cl(3, 0, 0) without calling geometric_product; test_matrix_decompose.py tested only \(n \le 3\); test_langlands_and_padic.py never tested disconnected \(d\)-regular graphs.

Rationale

  • 🔬 Karl Popper (Falsifiability): "Assume the happy path is a lie." Every verifier obeys one clean contract: invalid caller preconditions (empty / < min_count / all-zero field samples) raise ValueError; broken structures (exceptions, NaN, or violated axioms) return False in the axiom dict.
  • 🧪 Francis Bacon (Empiricism): Grounding Z3 proofs in live algebrax code (via direct symbolic execution where operators permit, paired with Z3-model/Hypothesis differential bridges and a meta-falsification test) makes docs/verification.md's Stamp of Trust empirically honest without polluting production semiring/ hot paths with Z3 hooks.

Specification

1. Universal Verifier Guards & NaN Safety (src/algebrax/verification/)

  • _common.py:
  • Fix _float_equal(a, b, tol) so math.isnan(a) or math.isnan(b) always returns False.
  • Fix semiring_elements_equal(a, b, tol) so containers (tuple, list, Mapping) are checked recursively before any a == b identity short-circuit (preventing (nan,) == (nan,) and {'a': nan} == {'a': nan} bypasses), and widen dict checks (line 45) to Mapping (supporting MappingProxyType matrices in EP-0254).
  • Reuse the existing _require_samples(samples, min_count=...) helper as the first line of every verifier so single-use iterators/generators are materialized once and forwarded as sequences.
  • Finite-domain-safe thresholds:
    • min_count=1 for _semiring.py verifiers (KCollapsedSemiring(0), ModularSemiring(1), BooleanSemiring) and standalone unary Hopf/coalgebra verifiers (verify_coassociativity, verify_counitality, verify_antipode_axiom).
    • min_count=2 for pairwise verify_contraction_constant, verify_field_laws, and verify_boolean_algebra_laws (\(\mathbb{F}_2 = \{0, 1\}\), \(\mathbb{B} = \{\text{False}, \text{True}\}\)).
    • Expose optional min_count: int = 3 on binary/ternary _algebra.py hierarchy verifiers (preserving existing test_popper_minimum_witness_guard while allowing callers to pass min_count=1 or 2 for trivial/2-element structures).
  • _semiring.py:
  • Guard all verifiers with _require_samples(samples, min_count=1); in verify_matrix_conway_laws(matrix, semiring=None, tol=1e-7), raise ValueError on empty matrix / empty key set.
  • Track tested_count inside every loop skipping boundary infinities/overflows/exceptions; if tested_count == 0, set the axiom result to False.
  • Evaluate all sibling laws independently without early-break masking in verify_star_semiring_laws (left_conway/right_conway), verify_star_plus_consistency, and verify_residuation_laws.
  • _algebra.py:
  • Update verify_groebner_basis_laws (_algebra.py:1061-1063) to instantiate CommQuotientRing(ring, ideal) (aligned with EP-0250).
  • Complete verify_bialgebra_laws:
    1. Verify \(\Delta(a \cdot b) = \Delta(a) \cdot \Delta(b)\) across ordered pairs itertools.product(c_elements, repeat=2) using generic bilinear tensor-product multiplication in \(B \otimes B\) (built solely from bialgebra.mul, bialgebra.add, bialgebra.smul, bialgebra.zero—no private CoordinateHopfAlgebra._tensor_mul dependency; basis keys in \(\Delta(x)\) are lifted via _carrier_basis under AlgebraX's sparse-dict coalgebra/bialgebra carrier convention, consistent with verify_coassociativity and verify_antipode_axiom).
    2. Verify exact unit comultiplication \(\Delta(1) = 1 \otimes 1\).
    3. Verify counit_homomorphism over itertools.product(c_elements, repeat=2) and include ring distributivity & scalar bilinearity checks.
  • Materialize c_samples once in verify_hopf_algebra_laws before forwarding; apply _require_samples(..., min_count=1) in verify_coassociativity, verify_counitality, and verify_antipode_axiom.
  • In verify_normed_space_laws: check positive definiteness (norm_v > 0.0 and not math.isnan(norm_v)) for every non-zero vector not semiring_elements_equal(v, space.zero, tol) (do not call non-existent space.is_zero(v) and do not reject tiny valid vectors with norm_v <= tol), require \(\ge 1\) non-zero vector, compute r_mag = float(abs(r)) for Fraction/Decimal, and rewrite < -tol / > bound + tol comparisons in positive finite-aware form (not (x >= -tol)).
  • In verify_inner_product_space_laws: check first_argument_linearity across all w in v_elements (requiring \(\ge 1\) non-zero w), and fix scalar arithmetic on line 1402 for Fraction/Decimal scalars.
  • In verify_division_ring_laws and verify_field_laws: require \(\ge 1\) non-zero sample (so \(\mathbb{F}_2 = \{0, 1\}\) passes while all-zero samples raise ValueError).
  • Guard verify_contraction_constant with _require_samples(samples, min_count=2) and positive finite-aware inequality checks; fix early-break masking in verify_lattice_laws, verify_distributive_lattice_laws, and verify_non_assoc_ring_laws.
  • _rep.py & _topology.py:
  • Guard empty-dimension / empty-sample inputs in verify_quantum_sl2_relations, verify_artin_braid_relations, verify_lie_representation_homomorphism (alg.dim == 0), verify_sheaf_functoriality, verify_coboundary_nilpotency (reject empty poset_category.cells while returning True for valid 1D complexes with \(\delta^{k+1} = 0\)), verify_connection_inversion, verify_chern_character_additivity, and verify_category_laws (require \(\ge 1\) composable triple).
  • In verify_sheaf_laplacian_properties: auto-generate deterministic non-zero probe cochains (\(O(|V|)\) sparse probes) when sample_cochains is omitted, and use positive finite-aware not (energy >= -tol).
  • In verify_padic_ultrametric_inequality: use positive finite-aware comparisons and fail if a non-zero product yields val == inf.

2. Two-Tier Grounded Z3 SMT Suite (tests/verifications/test_smt_z3_proofs.py)

Do not add Z3 hooks to production src/algebrax/semiring/ code. Ground test_smt_z3_proofs.py via two clean tiers, with solver.set('timeout', 5000) on every solver and bounded matrix sizes (\(n \le 2\) nonlinear, \(n \le 3\) linear tropical) keeping total suite runtime < 5s:

  1. Tier 1 — Direct Z3 Symbolic Execution Over Live algebrax Code:
  2. Execute DualNumberAlgebra (add/mul, excluding branching star), ExpectationSemiring, BinomialConvolutionSemiring, and matrix.transpose directly on z3.ArithRef expressions.
  3. Execute matrix.dot and MatrixCategory.compose directly on \(2 \times 2\) Z3 symbolic matrices using a test-local Z3-carrier Semiring (is_zero=lambda _: False so symbolic zero-pruning never raises Z3Exception).
  4. Tier 2 — Grounded Spec-to-Implementation Bridge & Meta-Falsification:
  5. For branching structures whose Python operators (or/and/min/max) cannot cast z3.ExprRef (BooleanSemiring, TropicalSemiring, ArcticSemiring, BottleneckSemiring, LukasiewiczSemiring, and algebrax.category.enriched.LawvereMetricCategory), pair the Z3 universal proof (replacing the Lawvere tautology with a genuine 3-node tropical closure \((I \oplus D)^{\otimes 2}\) triangle-inequality proof) with mandatory live-code conformance checks (exhaustive on \(\mathbb{B}^3\) for BooleanSemiring; Z3-model + Hypothesis differential sampling against live algebrax methods for the rest).
  6. Include a meta-falsification test proving that injecting a broken semiring or broken dot produces sat (counterexample found).
  7. Update docs/verification.md to distinguish Tier-1 direct symbolic execution from Tier-2 grounded specification proofs accurately.

3. Adversarial Falsification & Phase 8.5 Regression Tests (tests/)

  • Expand tests/algebrax/test_verification.py with:
  • Generator/iterator-exhaustion tests for every verifier family (_semiring, _algebra, _rep, _topology, _variety).
  • Adversarial falsification tests proving: broken \(\Delta(ab)\) fails verify_bialgebra_laws; zero seminorm fails verify_normed_space_laws; NaN inside tuples/dicts fails semiring_elements_equal; NaN-returning and NotImplementedError stubs fail _semiring verifiers; finite 1–2 element domains (\(\mathbb{F}_2\), BooleanSemiring, KCollapsedSemiring(0)) still pass.
  • Add targeted regression suites for EP-0250 and EP-0251 fixes:
  • Non-monic and reducible GaloisField moduli (test_galois.py & test_differential_sympy.py).
  • Mixed-signature CliffordAlgebra(0, 1, 0), Cl(0, 0, 1), Cl(1, 1, 0) and geometric_product (test_clifford.py).
  • \(n \ge 12\) integer-indexed solve_triangular, asymmetric cholesky, rank-deficient qr, negative k in svd, and disjoint-key lu_decompose/det (test_matrix_decompose.py).
  • Disconnected \(d\)-regular graphs (\(K_4 \sqcup K_4\)) in is_ramanujan_graph (test_langlands_and_padic.py).
  • (Boundary regression tests for transforms, probability, lattice, and group.permutation live in EP-0254 alongside their implementations.)

Acceptance Criteria

  1. semiring_elements_equal(float('nan'), float('nan')), semiring_elements_equal((nan,), (nan,)), and semiring_elements_equal({'a': nan}, {'a': nan}) all return False.
  2. Passing single-use generators (x for x in ...) to verify_star_semiring_laws, verify_kleene_algebra_laws, verify_action_algebra_laws, and verify_hopf_algebra_laws produces identical results to passing lists (never silently returning True on broken structures).
  3. ModularField(2) (\(\mathbb{F}_2\)), BooleanSemiring(), and KCollapsedSemiring(0) pass their respective verifiers; empty samples raise ValueError; broken \(\Delta(ab)\), zero seminorms, and NotImplementedError/NaN stubs return False.
  4. Early-break regression tests confirm failing left_conway still accurately evaluates right_conway (and likewise for lattice/residuation/non-assoc ring laws).
  5. tests/verifications/test_smt_z3_proofs.py imports and executes live algebrax code, includes a passing meta-falsification test, enforces timeout=5000, and finishes in < 5s.
  6. Full verification suite (pytest) passes with zero regressions.

Backwards Compatibility

  • Intentional breaking changes (falsifiability bug fixes):
  • semiring_elements_equal(float('nan'), float('nan')) now returns False instead of True (updating tests/algebrax/test_verification.py:23).
  • Callers passing empty lists, empty matrices, or all-zero field samples to verifiers that previously returned vacuous True now receive ValueError (invalid preconditions) or False (broken structures).
  • Additive improvement: Single-use generators now work reliably across all nested verifiers.

How to Teach This / Documentation Plan

  • Update docs/verification.md to reflect Tier-1 vs. Tier-2 grounded Z3 SMT proofs (LawvereMetricCategory) and the expanded falsification matrix.
  • Update docs/guide/semirings/verification.md with guidance on Popper's non-vacuous witness rule (ValueError vs. False), finite-domain min_count, and adversarial falsification testing.

Reference Implementation

Target files verified in the Second Grand Council Audit & Review: - src/algebrax/verification/{_common.py,_semiring.py,_algebra.py,_rep.py,_topology.py} - tests/verifications/test_smt_z3_proofs.py - tests/algebrax/{test_verification.py,test_galois.py,test_clifford.py,test_matrix_decompose.py,test_langlands_and_padic.py}


Rejected Ideas

  1. Keeping NaN == NaN as True in _float_equal:
  2. Rejected: Masks NaN-producing bugs on both sides of an identity.
  3. Adding Z3 Symbolic-Dispatch Hooks Inside Production src/algebrax/semiring/ Classes:
  4. Rejected: Pollutes pure-Python production hot paths with test-framework awareness; test-local Z3 adapters and two-tier grounded verification achieve full falsifiability with zero production overhead.
  5. Hardcoding min_count=3 or >= 2 Non-Zero Elements Globally:
  6. Rejected: Mathematically breaks valid small domains (\(\mathbb{F}_2\), BooleanSemiring, KCollapsedSemiring(0), trivial group).

Open Questions

None. Z3 grounding architecture, finite-domain thresholds, and EP-0254 test sequencing are resolved.


Change Log

  • 2026-11-26:
  • Initial Draft authored from the Second Grand Council Codebase Audit (Popper, Bacon).
  • 2026-11-27:
  • Incorporated Grand Council Pre-Implementation Review revisions: declared prerequisites (EP-0250–EP-0252) and sequencing before EP-0254 split, reused _require_samples with finite-domain-safe thresholds (\(\mathbb{F}_2\), BooleanSemiring), fixed misnamed verify_matrix_conway_laws/LawvereMetricCategory and non-existent space.is_zero(v), closed container-identity NaN, negated-inequality NaN, early-break, and additional vacuous verifier holes, finalized two-tier Z3 grounding (timeout=5000, < 5s, no production Z3 hooks), moved EP-0254 boundary tests to EP-0254, disclosed NaN breaking change, added Acceptance Criteria, and promoted status to Accepted.
  • 2026-11-29:
  • Implemented across src/algebrax/verification/ (_common.py, _semiring.py, _algebra.py, _rep.py, _topology.py, _variety.py), src/algebrax/matrix/decompose.py (negative k guard in svd), src/algebrax/topology/sheaf.py (NaN preservation in build_sheaf_coboundary_matrix), tests/verifications/test_smt_z3_proofs.py (Two-Tier grounded Z3 suite + meta-falsification, < 2s), tests/algebrax/test_verification.py, Phase 8.5 regression suites (test_galois.py, test_clifford.py, test_matrix_decompose.py, test_langlands_and_padic.py, test_differential_sympy.py), and documentation (docs/verification.md, docs/guide/semirings/verification.md). Promoted status to Final.