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:
- Iterator Exhaustion, Early-Break Masking & Exception Swallowing (
verification/_semiring.py,_algebra.py): verify_semiring_lawshas no minimum-sample guard (samples=[]passes all 9 axioms).verify_star_semiring_laws,verify_kleene_algebra_laws,verify_action_algebra_laws, andverify_hopf_algebra_lawspass rawIterablesamplesto inner verifiers (consuming generators), then iteratesamplesagain—evaluating to[]and vacuously passing all laws.except (ValueError, ZeroDivisionError, OverflowError, NotImplementedError): continueandisinf/isnanskips lack atested_countguard, so stubs raisingNotImplementedErroror returningNaNvacuously pass.- Early-
breakbugs (left_conway = False; breakandor/ negated-conjunction breaks inverify_star_plus_consistency,verify_residuation_laws,verify_lattice_laws,verify_distributive_lattice_laws, andverify_non_assoc_ring_laws) exit on the first failing law, leaving sibling laws falselyTrue. - NaN Bypasses, Missing Axioms & Vacuous Witnesses (
_common.py,_algebra.py,_rep.py,_topology.py): _float_equalreturnsTruefor(nan, nan),semiring_elements_equalshort-circuitsif a == b: return Truebefore container recursion (passing identical-object tuples/dicts containingNaN), and negated float inequalities (< -tol,> bound + tol) silently passNaNin_algebra.pyand_topology.py.verify_bialgebra_lawsomits \(\Delta(a \cdot b) = \Delta(a) \cdot \Delta(b)\), checks onlysum(delta_one.values()) == 1instead of \(\Delta(1) = 1 \otimes 1\), usescombinations(c_elements, 2)instead of ordered pairs, and omits ring distributivity / scalar bilinearity.verify_normed_space_lawsomits positive definiteness (accepting the zero seminormnorm(v) = 0.0) and hardcodesr_mag = 1.0forFraction/Decimal;verify_inner_product_space_lawspinsw = v_elements[0]and crashes onFraction/Decimalscalar multiplication.- 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), andverify_padic_ultrametric_inequality. - Disconnected SMT Proof Suite (
tests/verifications/test_smt_z3_proofs.py): - All 343 lines contain zero imports or calls to
algebrax, proving hand-transcribed formulas and a pure tautology forLawvereMetricCategory. Breaking every semiring insrc/algebrax/leaves all SMT tests green. - Happy-Path-Only Test Blind Spots:
tests/algebrax/test_verification.pylacks generator-exhaustion and adversarial falsification tests across_semiring,_algebra,_rep,_topology, and_variety.test_galois.pytested only monic \(p=2\);test_clifford.pytested onlyCl(3, 0, 0)without callinggeometric_product;test_matrix_decompose.pytested only \(n \le 3\);test_langlands_and_padic.pynever 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) raiseValueError; broken structures (exceptions,NaN, or violated axioms) returnFalsein the axiom dict. - 🧪 Francis Bacon (Empiricism): Grounding Z3 proofs in live
algebraxcode (via direct symbolic execution where operators permit, paired with Z3-model/Hypothesis differential bridges and a meta-falsification test) makesdocs/verification.md's Stamp of Trust empirically honest without polluting productionsemiring/hot paths with Z3 hooks.
Specification¶
1. Universal Verifier Guards & NaN Safety (src/algebrax/verification/)¶
_common.py:- Fix
_float_equal(a, b, tol)somath.isnan(a) or math.isnan(b)always returnsFalse. - Fix
semiring_elements_equal(a, b, tol)so containers (tuple,list,Mapping) are checked recursively before anya == bidentity short-circuit (preventing(nan,) == (nan,)and{'a': nan} == {'a': nan}bypasses), and widendictchecks (line45) toMapping(supportingMappingProxyTypematrices inEP-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=1for_semiring.pyverifiers (KCollapsedSemiring(0),ModularSemiring(1),BooleanSemiring) and standalone unary Hopf/coalgebra verifiers (verify_coassociativity,verify_counitality,verify_antipode_axiom).min_count=2for pairwiseverify_contraction_constant,verify_field_laws, andverify_boolean_algebra_laws(\(\mathbb{F}_2 = \{0, 1\}\), \(\mathbb{B} = \{\text{False}, \text{True}\}\)).- Expose optional
min_count: int = 3on binary/ternary_algebra.pyhierarchy verifiers (preserving existingtest_popper_minimum_witness_guardwhile allowing callers to passmin_count=1or2for trivial/2-element structures).
_semiring.py:- Guard all verifiers with
_require_samples(samples, min_count=1); inverify_matrix_conway_laws(matrix, semiring=None, tol=1e-7), raiseValueErroron emptymatrix/ empty key set. - Track
tested_countinside every loop skipping boundary infinities/overflows/exceptions; iftested_count == 0, set the axiom result toFalse. - Evaluate all sibling laws independently without early-
breakmasking inverify_star_semiring_laws(left_conway/right_conway),verify_star_plus_consistency, andverify_residuation_laws. _algebra.py:- Update
verify_groebner_basis_laws(_algebra.py:1061-1063) to instantiateCommQuotientRing(ring, ideal)(aligned withEP-0250). - Complete
verify_bialgebra_laws:- 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 frombialgebra.mul,bialgebra.add,bialgebra.smul,bialgebra.zero—no privateCoordinateHopfAlgebra._tensor_muldependency; basis keys in \(\Delta(x)\) are lifted via_carrier_basisunder AlgebraX's sparse-dict coalgebra/bialgebra carrier convention, consistent withverify_coassociativityandverify_antipode_axiom). - Verify exact unit comultiplication \(\Delta(1) = 1 \otimes 1\).
- Verify
counit_homomorphismoveritertools.product(c_elements, repeat=2)and include ring distributivity & scalar bilinearity checks.
- Verify \(\Delta(a \cdot b) = \Delta(a) \cdot \Delta(b)\) across ordered pairs
- Materialize
c_samplesonce inverify_hopf_algebra_lawsbefore forwarding; apply_require_samples(..., min_count=1)inverify_coassociativity,verify_counitality, andverify_antipode_axiom. - In
verify_normed_space_laws: check positive definiteness (norm_v > 0.0 and not math.isnan(norm_v)) for every non-zero vectornot semiring_elements_equal(v, space.zero, tol)(do not call non-existentspace.is_zero(v)and do not reject tiny valid vectors withnorm_v <= tol), require \(\ge 1\) non-zero vector, computer_mag = float(abs(r))forFraction/Decimal, and rewrite< -tol/> bound + tolcomparisons in positive finite-aware form (not (x >= -tol)). - In
verify_inner_product_space_laws: checkfirst_argument_linearityacross allwinv_elements(requiring \(\ge 1\) non-zerow), and fix scalar arithmetic on line1402forFraction/Decimalscalars. - In
verify_division_ring_lawsandverify_field_laws: require \(\ge 1\) non-zero sample (so \(\mathbb{F}_2 = \{0, 1\}\) passes while all-zero samples raiseValueError). - Guard
verify_contraction_constantwith_require_samples(samples, min_count=2)and positive finite-aware inequality checks; fix early-breakmasking inverify_lattice_laws,verify_distributive_lattice_laws, andverify_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 emptyposet_category.cellswhile returningTruefor valid 1D complexes with \(\delta^{k+1} = 0\)),verify_connection_inversion,verify_chern_character_additivity, andverify_category_laws(require \(\ge 1\) composable triple). - In
verify_sheaf_laplacian_properties: auto-generate deterministic non-zero probe cochains (\(O(|V|)\) sparse probes) whensample_cochainsis omitted, and use positive finite-awarenot (energy >= -tol). - In
verify_padic_ultrametric_inequality: use positive finite-aware comparisons and fail if a non-zero product yieldsval == 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:
- Tier 1 — Direct Z3 Symbolic Execution Over Live
algebraxCode: - Execute
DualNumberAlgebra(add/mul, excluding branchingstar),ExpectationSemiring,BinomialConvolutionSemiring, andmatrix.transposedirectly onz3.ArithRefexpressions. - Execute
matrix.dotandMatrixCategory.composedirectly on \(2 \times 2\) Z3 symbolic matrices using a test-local Z3-carrierSemiring(is_zero=lambda _: Falseso symbolic zero-pruning never raisesZ3Exception). - Tier 2 — Grounded Spec-to-Implementation Bridge & Meta-Falsification:
- For branching structures whose Python operators (
or/and/min/max) cannot castz3.ExprRef(BooleanSemiring,TropicalSemiring,ArcticSemiring,BottleneckSemiring,LukasiewiczSemiring, andalgebrax.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\) forBooleanSemiring; Z3-model + Hypothesis differential sampling against livealgebraxmethods for the rest). - Include a meta-falsification test proving that injecting a broken semiring or broken
dotproducessat(counterexample found). - Update
docs/verification.mdto 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.pywith: - 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 failsverify_normed_space_laws;NaNinside tuples/dicts failssemiring_elements_equal;NaN-returning andNotImplementedErrorstubs fail_semiringverifiers; finite 1–2 element domains (\(\mathbb{F}_2\),BooleanSemiring,KCollapsedSemiring(0)) still pass. - Add targeted regression suites for
EP-0250andEP-0251fixes: - Non-monic and reducible
GaloisFieldmoduli (test_galois.py&test_differential_sympy.py). - Mixed-signature
CliffordAlgebra(0, 1, 0),Cl(0, 0, 1),Cl(1, 1, 0)andgeometric_product(test_clifford.py). - \(n \ge 12\) integer-indexed
solve_triangular, asymmetriccholesky, rank-deficientqr, negativekinsvd, and disjoint-keylu_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, andgroup.permutationlive inEP-0254alongside their implementations.)
Acceptance Criteria¶
semiring_elements_equal(float('nan'), float('nan')),semiring_elements_equal((nan,), (nan,)), andsemiring_elements_equal({'a': nan}, {'a': nan})all returnFalse.- Passing single-use generators
(x for x in ...)toverify_star_semiring_laws,verify_kleene_algebra_laws,verify_action_algebra_laws, andverify_hopf_algebra_lawsproduces identical results to passing lists (never silently returningTrueon broken structures). ModularField(2)(\(\mathbb{F}_2\)),BooleanSemiring(), andKCollapsedSemiring(0)pass their respective verifiers; empty samples raiseValueError; broken \(\Delta(ab)\), zero seminorms, andNotImplementedError/NaNstubs returnFalse.- Early-
breakregression tests confirm failingleft_conwaystill accurately evaluatesright_conway(and likewise for lattice/residuation/non-assoc ring laws). tests/verifications/test_smt_z3_proofs.pyimports and executes livealgebraxcode, includes a passing meta-falsification test, enforcestimeout=5000, and finishes in< 5s.- Full verification suite (
pytest) passes with zero regressions.
Backwards Compatibility¶
- Intentional breaking changes (falsifiability bug fixes):
semiring_elements_equal(float('nan'), float('nan'))now returnsFalseinstead ofTrue(updatingtests/algebrax/test_verification.py:23).- Callers passing empty lists, empty matrices, or all-zero field samples to verifiers that previously returned vacuous
Truenow receiveValueError(invalid preconditions) orFalse(broken structures). - Additive improvement: Single-use generators now work reliably across all nested verifiers.
How to Teach This / Documentation Plan¶
- Update
docs/verification.mdto reflect Tier-1 vs. Tier-2 grounded Z3 SMT proofs (LawvereMetricCategory) and the expanded falsification matrix. - Update
docs/guide/semirings/verification.mdwith guidance on Popper's non-vacuous witness rule (ValueErrorvs.False), finite-domainmin_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¶
- Keeping
NaN == NaNasTruein_float_equal: - Rejected: Masks
NaN-producing bugs on both sides of an identity. - Adding Z3 Symbolic-Dispatch Hooks Inside Production
src/algebrax/semiring/Classes: - 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.
- Hardcoding
min_count=3or>= 2Non-Zero Elements Globally: - 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 beforeEP-0254split, reused_require_sampleswith finite-domain-safe thresholds (\(\mathbb{F}_2\),BooleanSemiring), fixed misnamedverify_matrix_conway_laws/LawvereMetricCategoryand non-existentspace.is_zero(v), closed container-identityNaN, negated-inequalityNaN, early-break, and additional vacuous verifier holes, finalized two-tier Z3 grounding (timeout=5000,< 5s, no production Z3 hooks), movedEP-0254boundary tests toEP-0254, disclosedNaNbreaking change, added Acceptance Criteria, and promoted status toAccepted. - 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(negativekguard insvd),src/algebrax/topology/sheaf.py(NaNpreservation inbuild_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 toFinal.