Algebraic Law Verification Engine¶
The algebrax.verification module provides property-based verification of formal algebraic axioms across all
built-in semiring types.
Checked Semiring Axioms¶
| Axiom | Equation |
|---|---|
add_associativity |
\((a + b) + c = a + (b + c)\) |
add_commutativity |
\(a + b = b + a\) |
add_identity |
\(a + \mathbf{0} = a\) |
mul_associativity |
\((a \cdot b) \cdot c = a \cdot (b \cdot c)\) |
mul_identity |
\(a \cdot \mathbf{1} = a\) |
left_distributivity |
\(a \cdot (b + c) = (a \cdot b) + (a \cdot c)\) |
right_distributivity |
\((a + b) \cdot c = (a \cdot c) + (b \cdot c)\) |
left_annihilation |
\(\mathbf{0} \cdot a = \mathbf{0}\) |
right_annihilation |
\(a \cdot \mathbf{0} = \mathbf{0}\) |
Star Semiring & Kleene Algebra Axioms¶
For structures implementing StarSemiring and KleeneAlgebra:
| Axiom | Protocol | Equation |
|---|---|---|
star_left_fixed_point |
StarSemiring |
\(a^* = \mathbf{1} + a \cdot a^*\) |
star_right_fixed_point |
StarSemiring |
\(a^* = \mathbf{1} + a^* \cdot a\) |
additive_idempotence |
KleeneAlgebra |
\(a + a = a\) |
Python Example: Programmatic Verification¶
import algebrax as ax
# Programmatic verification for Tropical Semiring (a Kleene Algebra)
semiring, samples = ax.verification.get_semiring_samples('Tropical')
# 1. Verify standard semiring axioms
res_rig = ax.verification.verify_semiring_laws(semiring, samples)
for axiom, passed in res_rig.items():
print(f'{axiom:25s}: {"PASS" if passed else "FAIL"}')
# 2. Verify star semiring fixed-point closure laws
res_star = ax.verification.verify_star_semiring_laws(semiring, samples)
for axiom, passed in res_star.items():
print(f'{axiom:25s}: {"PASS" if passed else "FAIL"}')
# 3. Verify Kleene algebra laws (idempotence)
res_kleene = ax.verification.verify_kleene_algebra_laws(semiring, samples)
for axiom, passed in res_kleene.items():
print(f'{axiom:25s}: {"PASS" if passed else "FAIL"}')
CLI Audit Command¶
Run the law verification auditor across all 33 semirings from the terminal:
# Verify all 33 catalog semirings
python -m algebrax.verification
# Verify a single semiring
python -m algebrax.verification --semiring GaloisField
Verification Guarantees & Popper Falsifiability Rules¶
Every verifier in algebrax.verification enforces a strict falsifiability contract so broken implementations can never pass vacuously:
- Invalid Preconditions vs. Broken Structures:
- Invalid caller preconditions (empty sample collections, fewer samples than
min_count, empty matrices/sheaves, zero-dimensional Lie algebras, all-zero field/normed-space samples, or zero composable category triples) raiseValueError. - Broken algebraic structures (violated axioms,
NaNoutputs, or unimplementedNotImplementedErrorstubs) returnFalsein the axiom result dictionary rather than silently skipping checks. - Finite-Domain-Safe
min_countThresholds: min_count=1for semiring/star/Kleene verifiers and standalone unary coalgebra/Hopf verifiers (KCollapsedSemiring(0),ModularSemiring(1),BooleanSemiring).min_count=2forverify_field_laws,verify_division_ring_laws,verify_boolean_algebra_laws, andverify_contraction_constant(validating finite domains such as \(\mathbb{F}_2 = \{0, 1\}\) and \(\mathbb{B} = \{\text{False}, \text{True}\}\) while requiring at least one non-zero witness where inverses or positive-definiteness are tested).min_count=3default (configurable viamin_count=...) for binary/ternary hierarchy verifiers inalgebrax.verification._algebra, allowing callers to passmin_count=1or2for tiny finite domains such as the trivial group.NaN-Strict Equality (semiring_elements_equal):NaNnever equalsNaN—not for scalar floats, not inside nested tuples/lists, and not inside sparse mappings (dictor read-onlyMappingProxyType), because container recursion runs before any object-identity short-circuit.- Single-Use Generator Safety:
- Every verifier materializes
Iterablesample arguments once at entry (_require_samples), so passing single-use generators(x for x in ...)yields identical results to lists across nested verifiers (verify_star_semiring_laws,verify_kleene_algebra_laws,verify_action_algebra_laws,verify_hopf_algebra_laws, and variety/topology verifiers). - Independent Sibling Axiom Reporting & Adversarial Falsification:
- Sibling laws (such as
left_conway/right_conway, meet/join lattice laws, residuation soundness/completeness, and left/right distributivity) are evaluated independently without early-breakmasking. verify_bialgebra_lawsverifies full comultiplication multiplicativity \(\Delta(ab) = \Delta(a)\Delta(b)\) over generic \(B \otimes B\) tensors, exact unit comultiplication \(\Delta(1) = 1 \otimes 1\), ordered-pair counit homomorphism, and ring/module compatibility;verify_normed_space_lawsenforces positive definiteness (\(\|v\| > 0\) for \(v \neq 0\)) to reject zero seminorms.
import algebrax as ax
# Finite 2-element field F_2 passes cleanly (min_count=2, >=1 non-zero element)
f2 = ax.algebra.ModularField(2)
assert all(ax.verification.verify_field_laws(f2, [0, 1]).values())
# Single-use generators are materialized once and never exhausted across nested checks
bs = ax.semiring.BooleanSemiring()
assert all(ax.verification.verify_kleene_algebra_laws(bs, (x for x in (False, True))).values())
# NaN never compares equal, even inside identical containers
nan = float('nan')
assert not ax.verification.semiring_elements_equal((nan,), (nan,))
Multi-Layered Verification Suite (tests/verifications/)¶
Beyond semiring law auditing, algebrax maintains a comprehensive Multi-Layered Verification Suite comparing linear algebra, matrix decompositions, tensors, spectral transforms, homology, and Lie algebras against NumPy, SciPy, NetworkX, SymPy, Hypothesis, Schwartz–Zippel PIT, Proof-Carrying Certificates, and Two-Tier Grounded Z3 SMT Proofs.
See the full traceability matrix in Mathematical Verification & Stamp of Trust.