EP-0003: Axiomatic Verification, Falsification & Multi-Layered Testing¶
| Field | Value |
|---|---|
| EP | 0003 |
| Title | Axiomatic Verification, Falsification & Multi-Layered Testing |
| Author | Eran Rivlis eran@rivlis.info, Antigravity |
| Sponsor | The Grand Council |
| Delegate | 🔬 Karl Popper (Falsifiability) & ⚖️ Emmy Noether (Symmetry) |
| Status | Active |
| Type | Standards Track |
| Created | 2026-11-12 |
| Updated | 2026-11-29 |
| Replaces | EP-0131, EP-0180 |
| Superseded-By | — |
Abstract¶
In foundational mathematical computing, software correctness is not an aspirational goal; it is a mathematical imperative. As mandated by EP-0001, every mathematical structure must be accompanied by an executable, property-based falsification oracle.
This proposal establishes the universal Axiomatic Verification & Testing Architecture across AlgebraX:
1. The Public Verification Engine (algebrax.verification): Over 40 public law verification oracles testing mathematical axioms (groups, rings, fields, modules, Lie algebras, Jordan algebras, alternative algebras, sheaves, bundles, varieties) with rigorous floating-point equivalence predicates (semiring_elements_equal) and non-vacuous Popper sample guards (hardened in Phase 8.5 EP-0253).
2. The 8-Layer Multi-Tier Verification Test Suite (tests/verifications/):
- Empirical & Metamorphic Tier: Cross-library differential testing (NumPy, SciPy, NetworkX, SymPy), metamorphic symmetry relations, and Hypothesis property-based testing.
- Exact & Semi-Formal Tier: Schwartz–Zippel randomized polynomial identity testing (PIT) to defeat monomial explosion, and the Method of Manufactured Solutions (MMS) for discrete calculus.
- Deductive & Certified Tier: SMT/Z3 formal proofs and \(O(\operatorname{nnz})\) proof-carrying solver certificates.
This proposal elevates, generalizes, and supersedes EP-0131 and EP-0180 into the single-digit foundational canon.
Motivation¶
Standard software unit tests check only known "happy paths" against hardcoded expected values. In abstract algebra and discrete differential geometry, this produces catastrophic blind spots:
- The Test Oracle Problem: For high-dimensional non-associative structures (octonions, exceptional Lie algebras \(E_8\)) or discrete Laplacians on unstructured simplicial meshes, closed-form analytical solutions do not exist for arbitrary topologies.
- Monomial Explosion: Expanding symbolic expressions \((x \cdot y) \cdot z - x \cdot (y \cdot z)\) symbolically leads to combinatorial blowup (\(O(2^N)\) monomials), causing symbolic CAS engines to hang.
- Floating-Point Non-Associativity vs. Bug Masking: IEEE 754 floating-point addition is non-associative (\((a + b) + c \neq a + (b + c)\)). Naive equality checks report false alarms, whereas loose epsilons mask genuine implementation defects.
- Dependency Bleed: Testing against mature external libraries (NumPy, SciPy, NetworkX, SymPy, Z3) is vital for comparative correctness, but importing them inside
src/algebraxviolates the Shannon Zero-Dependency Carrier Invariant.
Rationale & Council Alignment¶
- 🔬 Karl Popper (Falsifiability & Randomized Search): "Assume the happy path is a lie." Every algebraic structure is subjected to property-based fuzzing across millions of edge cases (degenerate simplices, empty matrices, infinite weights, zero divisors) to aggressively attempt to falsify its claimed axioms.
- ⚖️ Emmy Noether (Symmetries & Metamorphic Invariants): Where input-output oracles do not exist, tests verify fundamental symmetry conservation laws:
- Hodge star involution: \(\star \star \omega = (-1)^{k(n-k)} s \omega\).
- Boundary nilpotency: \(\partial_k \circ \partial_{k+1} = \mathbf{0}\) and coboundary nilpotency \(d^{k+1} \circ d^k = \mathbf{0}\).
- Connection parallel transport inversion: \(U_{ij} U_{ji} = I\).
- Gauge transformation covariance: \(d_{\tilde{A}}(\tilde{\phi}) = g \cdot (d_A \phi)\).
- ⚡ Claude Shannon (Efficiency & Schwartz–Zippel PIT): Replaces exponential monomial expansion with \(O(N)\) randomized polynomial identity testing over finite fields or integers, bounding the false-negative probability to \(< 10^{-15}\).
- 🛡️ The Golem (Safety & Self-Certifying Solvers): High-complexity solvers (\(O(N^3)\) Hodge decomposition, spectral graph partitioning) emit lightweight \(O(E)\) proof certificates (orthogonality residuals, harmonicity norms), preventing corrupt states from leaking across architectural boundaries.
- The Steward (Harmony & Zero Runtime Bleed):
Application code in
src/algebraxremains 100% pure Python with zero heavy dependencies. All heavy external tools (NumPy, SciPy, NetworkX, SymPy, Z3) are strictly isolated intests/verifications/as optional dev-dependencies.
Specification¶
1. The Public Verification Engine (algebrax.verification)¶
The public engine src/algebrax/verification/ (modularized by domain into _common.py, _semiring.py, _magma_group.py, _ring_field.py, _groebner.py, _hopf_normed.py, _rep_group_lie.py, _rep_quantum_quiver.py, _topology.py, _variety.py, and __main__.py, and re-exported from algebrax.verification) exports standardized, deterministic verifiers for every algebraic variety in AlgebraX:
def verify_semiring_laws(semiring: Semiring[T], samples: Iterable[T], tol: float = 1e-7) -> dict[str, bool]: ...
def verify_group_laws(group: Group[V], samples: Iterable[V], tol: float = 1e-7, min_count: int = 3) -> dict[str, bool]: ...
def verify_ring_laws(ring: Ring[V], samples: Iterable[V], tol: float = 1e-7, min_count: int = 3) -> dict[str, bool]: ...
def verify_field_laws(field: Field[V], samples: Iterable[V], tol: float = 1e-7, min_count: int = 2) -> dict[str, bool]: ...
def verify_module_laws(module: Module[R, M], ring: Ring[R], r_samples: Iterable[R], m_samples: Iterable[M], tol: float = 1e-7, min_count: int = 3) -> dict[str, bool]: ...
def verify_jordan_laws(jordan: JordanAlgebra[R, M], samples: Iterable[M], tol: float = 1e-7, min_count: int = 3) -> dict[str, bool]: ...
def verify_alternative_laws(alt: AlternativeAlgebra[R, M], samples: Iterable[M], tol: float = 1e-7, min_count: int = 3) -> dict[str, bool]: ...
def verify_malcev_laws(malcev: MalcevAlgebra[R, M], samples: Iterable[M], tol: float = 1e-7, min_count: int = 3) -> dict[str, bool]: ...
def verify_coboundary_nilpotency(sheaf: Any, k: int = 0, tol: float = 1e-12) -> bool: ...
def verify_gauge_covariance(connection: Any, adjacency: Any, gauge_transform: dict[Any, Any], tol: float = 1e-9) -> bool: ...
1.1 Precondition vs. Falsification Contract¶
Every verifier in algebrax.verification enforces a strict two-outcome contract so broken implementations can never pass vacuously:
- Invalid caller preconditions (empty/insufficient sample sets, empty matrices or sheaves, zero-dimensional algebras, all-zero field/division-ring/normed-space sample sets, or categories with zero composable morphism triples) must raise ValueError.
- Broken algebraic structures (violated equations, NaN or non-finite outputs, NotImplementedError/unexpected exceptions, or loops whose skip-guards leave tested_count == 0) must return False for the affected axiom key(s) rather than silently skipping checks.
1.2 Single-Use Iterable Safety & Finite-Domain-Safe min_count Tiering¶
- Every verifier accepting sample collections must accept
Iterable[T]and materialize each iterable once at entry via_require_samples(samples, min_count=...)before iterating or forwarding to inner verifiers. Single-use generators(x for x in ...)must produce identical results to lists. - Minimum witness thresholds respect the smallest mathematically valid finite domain of each algebraic variety:
| Verifier Family | Default min_count |
Rationale |
|---|---|---|
Semiring / Star / Kleene / Action (_semiring.py) & standalone unary coalgebra/Hopf axioms |
1 |
Supports valid 1-element (KCollapsedSemiring(0), ModularSemiring(1)) and 2-element (BooleanSemiring) structures while rejecting empty inputs. |
| Fields, division rings, Boolean algebras, contractions | 2 |
Supports minimal 2-element domains (\(\mathbb{F}_2 = \{0, 1\}\), \(\mathbb{B} = \{\text{False}, \text{True}\}\)). Fields, division rings, and normed spaces additionally require \(\ge 1\) non-zero sample so inverse and positive-definiteness checks are never skipped. |
Binary / ternary algebraic hierarchy (_magma_group.py, _ring_field.py, _groebner.py, _hopf_normed.py) |
3 (configurable kwarg) |
Preserves non-trivial 3-element witness coverage by default while forwarding min_count down the call hierarchy so callers may explicitly pass min_count=1 or 2 for tiny finite domains (e.g., the trivial group or \(\mathbb{Z}_2\)). |
1.3 Four-Layer NaN & Non-Finite Invariance¶
Because IEEE 754 evaluates every comparison involving NaN to False, all verification primitives enforce four mandatory layers of NaN safety:
1. Strict Scalar Equality: semiring_elements_equal(a, b, tol=1e-7) returns False whenever either operand is NaN (float, complex, or Decimal)—NaN never equals NaN.
2. Container-First Recursion: Container types (tuple, list, set, frozenset, and Mapping—including read-only MappingProxyType) are inspected recursively before any Python a == b identity short-circuit, preventing (nan,) == (nan,) and {'a': nan} == {'a': nan} bypasses.
3. Positive Finite-Aware Inequalities: All order, norm, contraction, ultrametric, energy, and residual checks must be written in positive finite-aware form (not (math.isfinite(x) and x >= -tol)) rather than negative form (if x < -tol), ensuring NaN and ±inf always fail.
4. NaN-Preserving Sparse Pruning: Sparse zero-pruning inside verifiers and coboundary/matrix assembly must preserve NaN entries (_contains_nan(v) / math.isnan(v)) rather than dropping them under abs(v) > tol.
def semiring_elements_equal(a: Any, b: Any, tol: float = 1e-7) -> bool:
"""NaN-strict equivalence for scalars, complex numbers, exact rationals, sequences, sets, and Mappings."""
...
1.4 Independent Sibling Axiom Reporting¶
When a verifier evaluates multiple sibling axioms within a shared loop (e.g., left_conway/right_conway, left_distributivity/right_distributivity, meet/join absorption, or left/right residuation), failing one axiom must never trigger an early break that leaves unevaluated sibling keys falsely True. Loops may exit early only once all sibling axioms tracked by that loop have failed.
2. The 8-Layer Multi-Tier Test Suite (tests/verifications/)¶
The multi-layered verification harness is organized into three distinct tiers, with domain-focused subpackages under differential/ and mms/ and module-level pytest.importorskip(...) guards:
tests/
├── algebrax/ # Core fast regression tests (< 2s, zero heavy deps)
│ └── test_verification.py # In-tree smoke & adversarial falsification suite for algebrax.verification
└── verifications/ # The 8-Layer Verification Test Suite
├── conftest.py # Pytest markers and dynamic skip-guards
│
│ ── TIER 1: EMPIRICAL, DIFFERENTIAL & MMS ──
├── test_axiomatic_properties.py # Hypothesis randomized property fuzzing (EP-0185)
├── test_metamorphic_invariants.py # Invariant relation tests (Stokes, dualities)
├── differential/ # Comparative oracle suites (EP-0181–EP-0184, split in EP-0254)
│ ├── _helpers.py # Shared lazy NumPy/SymPy sparse conversion adapters
│ ├── test_linalg_and_tensors.py # Matrix core, decompositions, tensors, norms, RKHS vs NumPy/SciPy
│ ├── test_transforms.py # DFT/IDFT, Hilbert, WHT, Z-transform, Lorentz, Gelfand/Fenchel
│ ├── test_path_semirings.py # Tropical, Boolean, Arctic, Bottleneck, Viterbi, Log vs CSGraph/NX
│ ├── test_spectral_graphs.py # Laplacians, Fiedler, PageRank, calculus, Forman-Ricci vs NX/SciPy
│ ├── test_statistical_semirings.py # Streaming moments, expectation, covariance vs NumPy/SciPy
│ ├── test_lie_galois_and_clifford.py # Exact Q matrices, Lie, Galois, Clifford, octonions, groups vs SymPy
│ ├── test_representations.py # Character tables, CG, Molien, U_q(sl_2), quivers vs SymPy/SciPy
│ ├── test_polynomials_and_varieties.py # Polynomials, autodiff, Gröbner, varieties vs SymPy
│ ├── test_topology.py # Homology, Hodge, Stokes, Helmholtz-Hodge, persistence, cohomology
│ └── test_probability_and_discrete.py # Information theory, moments, Bayes/Markov, automata, metrics
├── mms/ # Method of Manufactured Solutions & categorical laws
│ ├── test_sheaves_and_geometry.py # Sheaf harmonic extension, connections, K-theory, Langlands/p-adic
│ └── test_categories_and_algebra.py # Kleisli/Kan, lattices, tries, MatrixCategory, Lawvere, quotients
│
│ ── TIER 2: EXACT & SEMI-FORMAL ──
├── test_pit_symbolic.py # Schwartz–Zippel Randomized PIT (EP-0186)
│
│ ── TIER 3: DEDUCTIVE & CERTIFIED ──
├── test_smt_z3_proofs.py # Two-tier grounded formal proofs via Z3 SMT solver
└── test_certificates.py # O(nnz) proof-carrying solver witnesses
2.1 Two-Tier Grounded Formal Verification & Meta-Falsification (SMT / Z3)¶
Deductive SMT proofs must never prove disconnected hand-transcribed formulas that stay green when production code breaks, nor may they leak solver imports into src/algebrax/:
- Tier 1 — Direct Symbolic Execution: Execute live algebrax implementations directly on symbolic z3.ArithRef values (using test-local symbolic carrier semirings with is_zero = lambda _: False for sparse matrix and category kernels—zero Z3 hooks in src/).
- Tier 2 — Grounded Spec-to-Implementation Bridge: For branching structures whose Python operators (min/max/and/or) cannot accept symbolic ASTs directly, pair universal check(Not(Law)) == unsat proofs with mandatory live-code conformance checks (exhaustive over small finite domains such as \(\mathbb{B}^3\); Z3 model extraction + Hypothesis differential sampling over continuous domains).
- Meta-Falsification & Bounded CI Budgets: Every formal suite must enforce bounded solver timeouts (solver.set('timeout', 5000)) and include meta-falsification tests proving that injected bugs yield concrete z3.sat counterexamples that also falsify the live Python implementation.
3. Pytest Markers & Dependency Isolation¶
All verification tests use dedicated markers defined in tests/verifications/conftest.py:
- @pytest.mark.axiomatic: Hypothesis property-based tests.
- @pytest.mark.differential: Cross-library comparison (skipped if library missing).
- @pytest.mark.metamorphic: Metamorphic symmetry invariance.
- @pytest.mark.pit: Polynomial Identity Testing.
- @pytest.mark.smt: Z3 SMT formal proofs.
- @pytest.mark.certificates: Proof-carrying solver verification.
Backwards Compatibility¶
- Fully Backwards-Compatible: All public verification routines in
algebrax.verificationmaintain identical signatures and behavior. - Replaces EP-0131 & EP-0180: Both earlier proposals are formally superseded by this unified foundational standard.
How to Teach This / Documentation Plan¶
- User Guides:
docs/guide/verification/documents how users can test custom algebraic structures usingalgebrax.verification.- Developer Standards:
- Any new Layer 2 protocol or concrete algebra must add a corresponding
verify_*_lawsoracle insrc/algebrax/verification/(following Phase 8.5 EP-0253 non-vacuous sample contracts) and a test file intests/algebrax/ortests/verifications/.
Reference Implementation¶
- Verification Engine:
src/algebrax/verification/(modular package re-exported viaalgebrax.verification). - Multi-Layered Harness:
tests/verifications/. - Precedent & Hardening Proposals:
docs/proposals/EP-0131-algebraic-law-verification.mddocs/proposals/EP-0180-multi-layered-verification-suite.mddocs/proposals/EP-0253-verification-engine-hardening-and-grounded-proofs.md(Phase 8.5 hardening)docs/proposals/EP-0254-ergonomics-state-safety-ecosystem-bridges-and-hygiene.md(Phase 8.5 module & test-suite decomposition)
Rejected Ideas¶
- Placing Heavy Dependencies in
src/algebrax: Rejected: Violates the Shannon Carrier Invariant. External solvers belong strictly in optional test harnesses. - Relying Exclusively on SymPy for Axiom Proofs: Rejected: Symbolic expansion suffers from exponential monomial blowup. Schwartz–Zippel randomized PIT provides a rigorous, fast alternative.
- Treating
NaN == NaNasTrueor Short-Circuitinga == bBefore Container Recursion: Rejected: Under IEEE-754 and recursive container inspection, treatingNaN == NaNasTrue(or short-circuiting Pythona == bbefore descending into mappings/sequences/arrays) masks bugs that emitNaNidentically on both sides of an axiom. Both scalar and container comparisons MUST treat anyNaNas unequal to everything, including itself. - Injecting Z3 Symbolic-Dispatch Hooks into Production
src/algebrax/Classes: Rejected: Violates the Shannon zero-dependency carrier invariant and leaks verification tooling into production carriers. Two-Tier Grounded Formal Verification (test-local Z3-backed carriers inheriting production logic plus meta-falsification tests) achieves production-grounded formal proofs with zero Z3 code insrc/. - Enforcing a Global Hardcoded
min_count=3(or>= 2Non-Zero Samples) Across All Verifiers: Rejected: Breaks legitimate 1- and 2-element finite algebraic domains such as \(\mathbb{F}_2\),BooleanSemiring,KCollapsedSemiring(0), and the trivial group. Structure-awaremin_counttiering (1for algebraic domains,2for linear/representation checks,3for trilinear/associativity-critical spaces, plus non-empty cell/basis guards) prevents vacuous passes without rejecting valid finite structures.
Open Questions¶
None. The verification engine and test suite are actively running in CI across all platforms.
Change Log¶
- 2026-08-02: Initial verification engine specified as EP-0131.
- 2026-10-24: Multi-layered test architecture specified as EP-0180.
- 2026-11-12: Unified and elevated to single-digit foundational canon as EP-0003.
- 2026-11-26: Updated stale
src/algebrax/verification.pypaths to modularsrc/algebrax/verification/package, linked Phase 8.5 hardening (EP-0253), and promoted toActivestatus as living foundational canon. - 2026-11-29: Elevated Phase 8.5 (
EP-0253) verification invariants into living canon: added §1.1 (Precondition vs. Falsification Contract), §1.2 (Single-UseIterableSafety & Finite-Domain-Safemin_countTiering), §1.3 (Four-LayerNaN& Non-Finite Invariance), §1.4 (Independent Sibling Axiom Reporting), and §2.1 (Two-Tier Grounded Formal Verification & Meta-Falsification); updated module inventory, public verifier signatures, and Rejected Ideas. - 2026-11-29: Synchronized §1 module inventory (
_magma_group.py,_ring_field.py,_groebner.py,_hopf_normed.py,_rep_group_lie.py,_rep_quantum_quiver.py) and §2tests/verifications/layout (differential/andmms/domain subpackages with module-levelpytest.importorskipguards) per EP-0254.