Skip to content

Introduction

AlgebraX Banner

Algebraic Primitives for Sparse Data Structures in Python

algebrax treats Python's native dict (and Mapping) as a first-class sparse algebraic object, unifying linear algebra, abstract algebra, graph algorithms, discrete geometry & topology, signal transforms, and information metrics under a single pure-Python polymorphic framework.


Quickstart

Install algebrax using your favorite package manager:

# Using uv (recommended)
uv add algebrax

# Using pip
pip install algebrax

Core Philosophy

  • ⚡ Zero Heavy Dependencies: Pure-Python core requiring no C++ compilation (mappingtools is the sole core runtime dependency), with optional bridges to NumPy, SciPy, and PIL.
  • 🧱 Deductive Algebraic Hierarchy (algebrax.algebra, algebrax.category, algebrax.variety): Lean 4 / Mathlib-aligned @runtime_checkable protocols composed from 41 orthogonal atomic mixins (28 algebraic Has* + 9 categorical Has* + 4 geometric Has*) — spanning Magma, Monoid, Group, Lattice & BooleanAlgebra, Semiring / StarSemiring / KleeneAlgebra, Ring / Field / GaloisField / PAdicField, Ideal / GroebnerIdeal / QuotientRing, MultivariatePolynomialAlgebra, GeometricVariety / SmoothableVariety, Module / Algebra / NormedSpace / InnerProductSpace, dual Coalgebra / Bialgebra / HopfAlgebra, and Category / Groupoid / CartesianClosedCategory.
  • 🔄 Polymorphic Semiring Computing (algebrax.semiring): 33 built-in semirings and algebras. Swap \((\oplus, \otimes)\) in matrix.dot, tensor.einsum, or AlgebraicTrie to compute linear algebra, tropical shortest paths, Viterbi probabilities, statistical moments, or symbolic rule provenance with identical code.
  • 🎯 Exact Drift-Free Linear Solvers, Gröbner Ideals, Varieties & \(p\)-Adic Fields (algebrax.matrix, algebrax.algebra, algebrax.variety): Gaussian elimination, LU, QR, SVD, Cholesky, determinants, matrix inversion, multivariate polynomials \(k[x_1, \dots, x_n]\), exact Gröbner bases (Buchberger & Faugère \(F_4\)), affine algebraic varieties (AffineVariety, PolynomialMap, Stickelberger companion matrix root solvers, finite-field elliptic curves, CoordinateHopfAlgebra, and algebraic \(K\)-theory bridges), and piecewise-linear tropical varieties (TropicalPolynomialAlgebra, TropicalHypersurface, dual Newton polytope subdivisions, Noether/Minkowski balancing, and Dressian \(\operatorname{Trop}(\operatorname{Gr}(k, n))\) Plücker relations) — parameterized over exact Field[V] implementations including rationals (StandardField(Fraction)), prime fields (ModularField(p)), finite extension fields (GaloisField), and non-archimedean \(p\)-adic numbers (PAdicField(p)).
  • 🌌 Geometry, Symmetry, Representation Theory & Algebraic Topology: Multivector Clifford algebras \(Cl(p,q,r)\) (clifford), classical & exceptional Lie algebras, Langlands dual root systems & IwahoriHeckeAlgebra (lie), finite fields \(\operatorname{GF}(p^m)\) (algebra.GaloisField, galois), full representation theory (rep: finite-group characters, Frobenius induction, Clebsch–Gordan tensors, Molien invariants, \(U_q(\mathfrak{sl}_2)\) quantum groups, Jones knot invariants, quivers & Gabriel's ADE theorem), and unified algebraic topology (topology: homology, cohomology cup products, persistent barcodes, DEC, cellular sheaves, fiber bundles, topological K-theory & Chern classes, and path groupoids \(\Pi_1(K)\)).
  • 🧪 Unified 100-Structure Registry, CLI & Axiomatic Verification (algebrax.registry, algebrax.verification): Discover, inspect, and verify all 100 built-in 0-cell algebraic structures via ax.registry or the python -m algebrax CLI (catalog, describe, inspect, verify), cross-checked against NumPy, SciPy, SymPy, Hypothesis, Schwartz–Zippel PIT, Ramanujan expander checks, and z3-solver SMT proofs.

Overview

1. Polymorphic Semiring Matrix Multiplication

By changing the semiring parameter in matrix.dot, the exact same sparse algorithm switches seamlessly between Standard Linear Algebra, Tropical Shortest Paths, and Symbolic Provenance Tracking:

import algebrax as ax

# 1. Define a Sparse Graph Adjacency / Distance Matrix
graph = {
    0: {1: 2.0, 2: 10.0},
    1: {2: 3.0},
}

# Standard Linear Matrix Multiplication (+, *)
linear_mult = ax.matrix.dot(graph, graph, semiring=ax.semiring.StandardSemiring())
print('Linear Multiplication (0->2):', linear_mult[0][2])
# Output: 6.0 (2.0 * 3.0)

# Tropical Shortest Path (min, +)
shortest_path = ax.matrix.dot(graph, graph, semiring=ax.semiring.TropicalSemiring())
print('Shortest Path Cost (0->1->2):', shortest_path[0][2])
# Output: 5.0 (min(2.0 + 3.0, 10.0 + inf))

# Symbolic Provenance Rule Tracking
provenance_graph = {
    0: {1: {('rule_A',): 1}, 2: {('rule_C',): 1}},
    1: {2: {('rule_B',): 1}},
}
provenance_mult = ax.matrix.dot(provenance_graph, provenance_graph, semiring=ax.semiring.ProvenanceSemiring())
print('Symbolic Derivation Polynomial:', provenance_mult[0][2])
# Output: {('rule_A', 'rule_B'): 1}

2. Exact Drift-Free Solvers over Rational & Finite Fields

Parameterize sparse linear solvers over any Field[V] to eliminate IEEE-754 floating-point cancellation:

from fractions import Fraction
from algebrax.algebra import ModularField, StandardField
from algebrax.matrix import det, solve

# Exact rational Hilbert matrix determinant over Q
h2 = {0: {0: Fraction(1, 1), 1: Fraction(1, 2)}, 1: {0: Fraction(1, 2), 1: Fraction(1, 3)}}
print(det(h2, field=StandardField(Fraction)))
# Output: Fraction(1, 12)

# Exact sparse linear system over prime field F_11
a = {'eq1': {'x': 3, 'y': 2}, 'eq2': {'x': 4, 'y': 9}}
b = {'eq1': 5, 'eq2': 1}
print(solve(a, b, field=ModularField(11)))
# Output: {'x': 4, 'y': 2}

3. Explore & Verify the 100-Structure Registry (Python & CLI)

Browse, inspect, and empirically verify all 100 built-in 0-cell algebraic structures from Python or the terminal:

import algebrax as ax

print(len(ax.registry.catalog()))  # 100 concrete 0-cell structures
entry = ax.registry.get('TropicalHypersurface')
print(entry.domain, [p.__name__ for p in entry.protocols])
python -m algebrax catalog --domain variety
python -m algebrax describe TropicalHypersurface
python -m algebrax verify TropicalHypersurface

Architecture & Module Map

Pillar Submodules Highlights
Algebraic Foundations algebra, semiring, group, lattice 28 algebraic mixins, Semiring/StarSemiring/KleeneAlgebra, Ring/Field/GaloisField/PAdicField, MultivariatePolynomialAlgebra, GroebnerIdeal (\(F_4\) & Buchberger), GrothendieckRing, HopfAlgebra, PathAlgebra, ActionAlgebra, Ideal & QuotientRing
Linear & Tensor Computing matrix, tensor, trie Sparse dot/power/closure, LU/QR/SVD/Cholesky, exact Field solvers, einsum, Clebsch–Gordan 3-tensors, AlgebraicTrie
Geometry, Symmetry, Representations & Topology variety, clifford, lie, rep, galois, topology Classical & tropical varieties (AffineVariety, PolynomialMap, Stickelberger solvers, CoordinateHopfAlgebra, TropicalHypersurface, TropicalPolynomialAlgebra, Newton polytopes & Dressians \(\operatorname{Trop}(\operatorname{Gr}(k, n))\)), Clifford \(Cl(p,q,r)\) rotors, Lie algebras (\(\mathfrak{so}(3)\), \(\mathfrak{e}_8\), BCH, Langlands duals, IwahoriHeckeAlgebra), group/induced/Lie/invariant/quantum (\(U_q(\mathfrak{sl}_2)\), Jones)/quiver (Gabriel ADE) representations, \(\operatorname{GF}(p^m)\), homology, cohomology, persistence, DEC, sheaves, K-theory & path groupoids \(\Pi_1(K)\)
Dynamics, Categories, Registry & Tools category, automata, transforms, analysis, probability, metrics, converters, display, registry, verification 9 categorical mixins, Cartesian Closed Categories, semiring coeffects, Kleisli composition, DFA/NFA, DFT/Walsh–Hadamard/Z-transform, Fiedler/curvature/Ramanujan expanders & RKHS, entropy, NumPy/SciPy bridges, 100-structure registry & python -m algebrax CLI, axiom verifiers

Next Steps

Explore the documentation sections:

  • 💡 Core Concepts & Periodic Table of Mixins: Learn the mathematical foundations of Atomic Mixins, Magmas, Monoids, Groups, Lattices, Semirings, Rings, Fields, Modules, Algebras, Varieties, and Hopf Duality.
  • ⚖️ Library Comparison: Feature matrix and trade-off analysis comparing AlgebraX vs SciPy, NumPy, Pandas, NetworkX, and SymPy.
  • 🛡️ Mathematical Verification & Stamp of Trust: Traceability matrix across differential NumPy/SciPy/SymPy oracles, Hypothesis axioms, Schwartz–Zippel PIT, and Z3 formal proofs.
  • 📖 7-Tier User Guide: Deductive tour from single-operation Magmas and Monoids to Semirings, Rings, Exact Field Solvers, Classical & Tropical Varieties, Clifford & Lie Algebras, Coalgebras & Hopf Algebras, Categories, Topological Sheaves, and the 100-Structure Registry & CLI.
  • 🍳 51 Use Cases, Recipes & GUI Lab: Executable real-world scripts, synced Jupyter notebooks, and the interactive 12-module DearPyGui laboratory.
  • 📜 Enhancement Proposals: Architectural design records and project roadmap.