Architecture & Invariants¶
This page summarizes the living architectural laws that govern src/algebrax/. For historical design rationale and the multi-phase roadmap, see the Enhancement Proposals and EP-0099.
1. Core Design Laws¶
The Unboxed Sparse Carrier Invariant¶
AlgebraX treats native Python dict (and Mapping) as the canonical sparse carrier — never wrapping vectors, matrices, polynomials, or chains inside heavy boxed container classes (EP-0001).
- Sparse Vectors & Matrices:
dict[K, V]anddict[K, dict[K, V]]. - Multivariate Polynomials:
dict[tuple[int, ...], V](SparseMPoly[V]) — the exact same carrier powers classical Gröbner ideals (MultivariatePolynomialAlgebra) and piecewise-linear tropical hypersurfaces (TropicalHypersurface). - Tensors, Chains & Cochains:
dict[tuple[K, ...], V]. - Sparsity Principle: Missing keys represent the active algebraic structure's additive identity (
zero), never hardcoded0.0(e.g.,+infforTropicalSemiring,-infforArcticSemiring).
Zero Heavy Core Dependencies¶
The core runtime depends solely on Python >=3.11 and mappingtools — zero C/C++ compilation required. Optional bridges (numpy, scipy, PIL) live strictly behind lazy imports in algebrax.converters and differential verification tests.
The Law of Flat Protocol Composition¶
All algebraic, categorical, and geometric protocols in algebrax.algebra, algebrax.category, and algebrax.variety are @runtime_checkable typing.Protocol definitions composed flatly from 41 orthogonal atomic operational mixins (28 algebraic + 9 categorical + 4 geometric) with zero diamond inheritance (EP-0005).
- Structural over Nominal: Concrete structures never inherit from a monolithic
Structurebase class; conformance is checked structurally viaisinstance(obj, Protocol). - Law Markers (
Law*): Semantic axioms that cannot be expressed as method signatures (e.g.,LawCommutative,LawIdempotent,LawAssociative) are declared via marker protocols and verified empirically byalgebrax.verification.
2. Module Dependency Boundaries¶
AlgebraX enforces strict acyclic layer direction across src/algebrax/, automatically audited in CI by tests/algebrax/test_hygiene.py and tests/algebrax/test_registry_invariants.py:
flowchart TD
Core["algebra / display\n(Zero-dependency Protocols & Mixins)"] --> Semiring["semiring / group / lattice"]
Semiring --> Matrix["matrix / tensor / trie"]
Matrix --> Domains["clifford / lie / rep / galois / variety / topology / category / automata / transforms / analysis / probability / metrics"]
Domains --> Registry["registry\n(Pure-data 0-cell catalog, lazy verification)"]
Domains --> Verification["verification\n(Axiom checkers & registry bridge)"]
Registry --> CLI["cli / __main__\n(catalog, describe, inspect, verify)"]
Verification --> CLI
Enforced Isolation Rules¶
| Rule | Enforced By | Rationale |
|---|---|---|
algebra and display never import registry |
test_ast_isolation_algebra_and_display_never_import_registry |
Keeps foundational protocols and rich display helpers cycle-free. |
Importing algebrax.registry loads zero verification modules |
test_fresh_process_registry_import_loads_zero_verification_modules |
Preserves fast startup and keeps the catalog pure data. |
algebrax.rep never imports algebrax.verification |
test_rep_has_zero_verification_imports |
Prevents production computation modules from depending on test/verification helpers. |
Zero EP-XXXX references in src/algebrax/ or docs/guide/ |
test_no_ep_references_in_src, test_no_ep_references_in_user_guide |
Keeps production source and end-user guides decoupled from internal proposal numbering. |
3. Unified Registry Invariants (I-1–I-5)¶
algebrax.registry exposes an immutable MappingProxyType catalog of all built-in concrete 0-cell algebraic structures (classes and canonical factory families), governed by five CI-enforced invariants (EP-0255):
I-1— Reified Protocol & Law Types: EveryStructureEntry.protocolsandStructureEntry.lawstuple holds livetypeobjects, never raw strings.I-2— Protocol & Law Honesty (Anti-Vacuity): Every registered structure must passverify_structure(key)with zero vacuous checks, including explicit Popper negative controls confirming false law claims fail.I-3— Full AMDS Signature Coverage: Every registered structure's docstring includes anAlgebraic Signature:block conforming toEP-0002.I-4— Completeness Audit: Every public exported 0-cell class acrossalgebrax.*must appear inalgebrax.registryor be explicitly classified inEXPLICIT_EXCLUSIONS(for carriers, 1-cell morphisms/functors, ideals, or solvers) intests/algebrax/test_registry_invariants.py.I-5— Bidirectional Zero-Arg Contract:zero_arg=Trueentries instantiate with zero arguments; parameterized (zero_arg=False) entries provide a canonicalexample=factory and produce descriptiveTypeErrordiagnostics when invoked without parameters.
4. Verification Architecture¶
Mathematical correctness follows a 5-layer verification cascade (EP-0003, live traceability in Verification & Stamp of Trust):
- Runtime Axiom Checkers (
algebrax.verification): Executable law verifiers (verify_semiring_laws,verify_field_laws,verify_hopf_algebra_laws,verify_groebner_basis_laws,verify_tropical_hypersurface_laws, etc.) plusverify_structure()bridge dispatch. - Property-Based Fuzzing (
hypothesis): Randomized algebraic law stress-testing across domains. - Differential Oracles (
numpy,scipy,sympy): Cross-checking exact solvers, Gröbner bases, SVD/QR, homology, and tropical lower/upper convex hulls against independent reference engines. - Probabilistic & Formal Proofs: Schwartz–Zippel polynomial identity testing and
z3-solverSMT proofs for semiring/lattice laws. - Executable Recipes (
nbmake): Every Golden Source script inrecipes/and its synced.ipynbnotebook executes end-to-end as an integration test.
Every *.py::test_* reference in docs/verification.md is AST-verified in CI by test_verification_doc_traceability_paths_resolve.