Metadata-Version: 2.5
Name: algebrax
Version: 0.15.0
Summary: Algebraic primitives over sparse data structures in pure Python
Project-URL: Homepage, https://github.com/erivlis/algebrax
Project-URL: Source Code, https://github.com/erivlis/algebrax.git
Project-URL: Bug Tracker, https://github.com/erivlis/algebrax/issues
Project-URL: Documentation, https://erivlis.github.io/algebrax
Author-email: Eran Rivlis <eran@rivlis.info>
Maintainer-email: Eran Rivlis <eran@rivlis.info>
License-Expression: MIT
License-File: LICENSE
Keywords: algebra,clifford,field,group,hopf-algebra,lie-algebra,mapping,math,mathematics,matrix,monoid,ring,semiring,sparse,topology
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: mappingtools>=0.10.0
Description-Content-Type: text/markdown

# **AlgebraX - Algebraic primitives over sparse data structures in pure Python**

<p style="text-align: center; align-content: center">
  <img src="docs/assets/images/banner.png" alt="AlgebraX Banner" style="display: block; width: 100%; max-width: 100%; height: auto;">
</p>

<table>
  <tr style="vertical-align: middle;">
    <td>Package</td>
    <td>
      <img alt="PyPI - Version" class="off-glb" loading="lazy" src="https://img.shields.io/pypi/v/algebrax.svg?logo=pypi&logoColor=lightblue">
      <img alt="PyPI - Status" class="off-glb" loading="lazy" src="https://img.shields.io/pypi/status/algebrax.svg?logo=pypi&logoColor=lightblue">
      <img alt="PyPI - Python Version" class="off-glb" loading="lazy" src="https://img.shields.io/pypi/pyversions/algebrax.svg?logo=python&label=Python&logoColor=lightblue">
      <img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dd/algebrax?logo=pypi&logoColor=lightblue">
      <img alt="PyPI - Dependents" src="https://dependents.info/erivlis/algebrax/badge?logo=pypi&logoColor=lightblue">
      <img alt="Libraries.io SourceRank" src="https://img.shields.io/librariesio/sourcerank/pypi/algebrax.svg?logo=Libraries.io&label=SourceRank">
    </td>
  </tr>
  <tr>
    <td>Code</td>
    <td>
      <img alt="GitHub" src="https://img.shields.io/github/license/erivlis/algebrax">
      <img alt="GitHub repo size" src="https://img.shields.io/github/repo-size/erivlis/algebrax.svg?label=Size&logo=git">
      <img alt="GitHub last commit (by committer)" src="https://img.shields.io/github/last-commit/erivlis/algebrax.svg?&logo=git">
      <a href="https://github.com/erivlis/algebrax/graphs/contributors"><img alt="Contributors" src="https://img.shields.io/github/contributors/erivlis/algebrax.svg?&logo=git"></a>
    </td>
  </tr>
  <tr>
    <td>Tools</td>
    <td>
      <a href="https://www.jetbrains.com/pycharm/"><img alt="PyCharm" src="https://img.shields.io/badge/PyCharm-FCF84A.svg?logo=PyCharm&logoColor=black&labelColor=21D789&color=FCF84A"></a>
      <a href="https://github.com/astral-sh/uv"><img alt="uv" src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json" style="max-width:100%;"></a>
      <a href="https://github.com/astral-sh/ruff"><img alt="Ruff" src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" style="max-width:100%;"></a>
      <a href="https://hatch.pypa.io"><img alt="Hatch project" class="off-glb" loading="lazy" src="https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg"></a>
      <a href="https://commitizen-tools.github.io/commitizen"><img alt="commitizen" src="https://custom-icon-badges.demolab.com/badge/commitizen-7e56c2?logo=commitizen&labelColor=grey"></a>
      <a href="https://zensical.org/"><img alt="Zensical" src="https://custom-icon-badges.demolab.com/badge/zensical-ff9100?logo=zensical&labelColor=grey"></a>
      <a href="https://jupytext.org/"><img alt="Jupytext" src="https://img.shields.io/badge/Jupytext-FF6F61?logo=jupyter&labelColor=grey"></a>
      <a href="https://library-skills.io"><img alt="agentskills" src="https://img.shields.io/badge/agentskills-white?logo=agentskills&labelColor=grey"></a>
    </td>
  </tr>
  <tr>
    <td>CI/CD</td>
    <td>
      <a href="https://github.com/erivlis/algebrax/actions/workflows/test.yml"><img alt="Test" src="https://github.com/erivlis/algebrax/actions/workflows/test.yml/badge.svg"></a>
      <a href="https://github.com/erivlis/algebrax/actions/workflows/test-beta.yml"><img alt="Publish" src="https://github.com/erivlis/algebrax/actions/workflows/test-beta.yml/badge.svg"></a>
      <a href="https://github.com/erivlis/algebrax/actions/workflows/benchmark.yml"><img alt="Benchmarks" src="https://github.com/erivlis/algebrax/actions/workflows/benchmark.yml/badge.svg"></a>
      <a href="https://github.com/erivlis/algebrax/actions/workflows/publish.yml"><img alt="Publish" src="https://github.com/erivlis/algebrax/actions/workflows/publish.yml/badge.svg"></a>
      <a href="https://github.com/erivlis/algebrax/actions/workflows/publish-docs.yml"><img alt="Publish Docs" src="https://github.com/erivlis/algebrax/actions/workflows/publish-docs.yml/badge.svg"></a>
    </td>
  </tr>
  <tr>
    <td>Scans</td>
    <td>
      <a href="https://codecov.io/gh/erivlis/algebrax"><img alt="Coverage" src="https://codecov.io/gh/erivlis/algebrax/graph/badge.svg?token=POODT8M9NV"/></a>
      <a href="https://sonarcloud.io/summary/new_code?id=erivlis_algebrax"><img alt="Quality Gate Status" src="https://sonarcloud.io/api/project_badges/measure?project=erivlis_algebrax&metric=alert_status"></a>
      <a href="https://sonarcloud.io/summary/new_code?id=erivlis_algebrax"><img alt="Security Rating" src="https://sonarcloud.io/api/project_badges/measure?project=erivlis_algebrax&metric=security_rating"></a>
      <a href="https://sonarcloud.io/summary/new_code?id=erivlis_algebrax"><img alt="Maintainability Rating" src="https://sonarcloud.io/api/project_badges/measure?project=erivlis_algebrax&metric=sqale_rating"></a>
      <a href="https://sonarcloud.io/summary/new_code?id=erivlis_algebrax"><img alt="Reliability Rating" src="https://sonarcloud.io/api/project_badges/measure?project=erivlis_algebrax&metric=reliability_rating"></a>
      <a href="https://sonarcloud.io/summary/new_code?id=erivlis_algebrax"><img alt="Lines of Code" src="https://sonarcloud.io/api/project_badges/measure?project=erivlis_algebrax&metric=ncloc"></a>
      <a href="https://sonarcloud.io/summary/new_code?id=erivlis_algebrax"><img alt="Vulnerabilities" src="https://sonarcloud.io/api/project_badges/measure?project=erivlis_algebrax&metric=vulnerabilities"></a>
      <a href="https://sonarcloud.io/summary/new_code?id=erivlis_algebrax"><img alt="Bugs" src="https://sonarcloud.io/api/project_badges/measure?project=erivlis_algebrax&metric=bugs"></a>
      <a href="https://app.codacy.com/gh/erivlis/algebrax/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade"><img alt="Codacy Quality" src="https://app.codacy.com/project/badge/Grade/8b83a99f939b4883ae2f37d7ec3419d1"></a>
      <a href="https://app.codacy.com/gh/erivlis/algebrax/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage"><img alt="Codacy Coverage" src="https://app.codacy.com/project/badge/Coverage/8b83a99f939b4883ae2f37d7ec3419d1"/></a>
      <a href="https://www.codefactor.io/repository/github/erivlis/algebrax/overview/main"><img src="https://www.codefactor.io/repository/github/erivlis/algebrax/badge/main" alt="CodeFactor" /></a>
      <a href="https://snyk.io/test/github/erivlis/algebrax"><img alt="Snyk" src="https://snyk.io/test/github/erivlis/algebrax/badge.svg"></a>
      <a href="https://app.codspeed.io/erivlis/algebrax?utm_source=badge"><img src="https://img.shields.io/endpoint?url=https://codspeed.io/badge.json" alt="CodSpeed"/></a>
      <a href="https://scorecard.dev/viewer/?uri=github.com/erivlis/algebrax"><img src="https://api.scorecard.dev/projects/github.com/erivlis/algebrax/badge" alt="OpenSSF Scorecard"/></a>
    </td>
  </tr>
  <tr>
    <td>Mentions</td>
    <td>
      <!-- <a href="https://www.youtube.com/live/k01G0b0Y0Jg?si=030OT8sK3BqPyy8r&t=1028"><img alt="PythonBytes Podcast" src="https://img.shields.io/badge/Python_Bytes-Ep. 361-D7F9FF?logo=applepodcasts&labelColor=blue"></a> -->
      <!-- a href="https://pythonhub.dev/digest/2024-08-06/"><img alt="Static Badge" src="https://img.shields.io/badge/PythonHub-2024.08.06-gold?labelColor=blue"></a -->
      <a href="https://pythonhub.dev/digest/2026-08-09/"><img alt="Python Hub" src="https://custom-icon-badges.demolab.com/badge/Python%20Hub-2026.08.09-gold?logo=pythonhub&labelColor=grey"></a>
      <a href="https://x.com/PythonHub/status/2085323880172749251"><img alt="X" src="https://img.shields.io/twitter/url?url=https%3A%2F%2Fx.com%2FPythonHub%2Fstatus%2F2085323880172749251"></a>
    </td>
  </tr>
</table>


---

`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.

## Key Features

* ⚡ **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`)**: Lean 4 / Mathlib-aligned `@runtime_checkable` protocols
  composed from **22 orthogonal atomic mixins** (`Has*`) — spanning `Magma`, `Monoid`, `Group`, `Lattice` &
  `BooleanAlgebra`, `Semiring` / `StarSemiring` / `KleeneAlgebra`, `Ring` / `Field`, `Ideal` / `QuotientRing`,
  `Module` / `Algebra`, and dual `Coalgebra` / `Bialgebra` / `HopfAlgebra`.
* 🔄 **Polymorphic Semiring Computing (`algebrax.semiring`)**: 33 built-in semirings and algebras. Swap $(\oplus, \otimes)$
  in `matrix.dot`, `tensor.einsum`, or `AlgebraicTrie` to switch seamlessly between linear algebra, tropical shortest paths,
  Viterbi probabilities, statistical moments, or symbolic rule provenance.
* 🎯 **Exact Drift-Free Linear Solvers (`algebrax.matrix`)**: Gaussian elimination, LU, QR, SVD, Cholesky, determinants,
  and matrix inversion parameterized over any `Field[V]` — including exact rationals (`StandardField(Fraction)`) and
  finite prime fields (`ModularField(p)`).
* 🌌 **Geometry, Symmetry & Algebraic Topology**: Multivector Clifford algebras $Cl(p,q,r)$ (`clifford`), classical &
  exceptional Lie algebras (`lie`), finite fields $\mathrm{GF}(p^m)$ (`galois`), and unified algebraic topology
  (`topology`: homology, cohomology cup products, persistent barcodes, DEC, and cellular sheaves).
* 🧪 **Axiomatic Law Verification & Interactive Lab**: Automated algebraic axiom checkers (`verification`) backed by
  property-based testing and Z3 verification, plus a 12-module [DearPyGui](https://github.com/hoffstadt/DearPyGui)
  desktop laboratory (`recipes/lab.py`).

---

## Installation

```bash
# Using uv (recommended)
uv add algebrax

# Using pip
pip install algebrax
```

---

## 5-Minute Quickstart

### 1. Polymorphic Semiring Matrix Multiplication

By changing the `semiring` parameter in `matrix.dot`, the exact same sparse matrix multiplication computes standard
linear combinations, tropical shortest paths, or symbolic rule derivations:

```python
import algebrax as ax

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

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

# 2. 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))

# 3. 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:

```python
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}
```

---

## Architecture & Module Map

| Pillar | Submodules | Highlights |
|:-------|:-----------|:-----------|
| **Algebraic Foundations** | `algebra`, `semiring`, `group`, `lattice` | 22 orthogonal mixins, `Semiring`/`StarSemiring`/`KleeneAlgebra`, `Ring`/`Field`, `HopfAlgebra`, `ActionAlgebra`, `Ideal` & `QuotientRing` |
| **Linear & Tensor Computing** | `matrix`, `tensor`, `trie` | Sparse `dot`/`power`/`closure`, LU/QR/SVD/Cholesky, exact `Field` solvers, `einsum`, `AlgebraicTrie` |
| **Geometry, Symmetry & Topology** | `clifford`, `lie`, `galois`, `topology` | Clifford $Cl(p,q,r)$ rotors, Lie algebras ($\mathfrak{so}(3)$, $\mathfrak{e}_8$, BCH), $\mathrm{GF}(p^m)$, homology, cohomology, persistence, DEC & sheaves |
| **Dynamics, Categories & Tools** | `category`, `automata`, `transforms`, `analysis`, `probability`, `metrics`, `converters`, `display`, `verification` | Kleisli composition, DFA/NFA, DFT/Walsh–Hadamard/Z-transform, Fiedler/curvature, entropy, NumPy/SciPy bridges, Jupyter HTML/LaTeX cards, axiom verifiers |

---

## Recipe Highlights & Jupyter Notebooks

The [`recipes/`](recipes) directory includes **38** runnable CLI scripts and synced `.ipynb` notebooks. Here is a curated
sample across domains — see the full catalog in [**Recipes & Applications**](docs/recipes.md):

| Domain | Recipe & Notebook | Algebraic Components |
|:-------|:------------------|:---------------------|
| **Graphs & Optimization** | **Traffic Resilience** — [`🐍`](recipes/traffic_network_resilience.py) [`📓`](recipes/traffic_network_resilience.ipynb) | `TropicalSemiring`, `matrix.power`, `analysis.forman_ricci_curvature`, `markov_steady_state` |
| **Spectral & Graph ML** | **Spectral Graph Clustering** — [`🐍`](recipes/spectral_graph_clustering.py) [`📓`](recipes/spectral_graph_clustering.ipynb) | `matrix.laplacian_matrix`, `analysis.fiedler_vector`, `analysis.laplacian_spectrum` |
| **Topology & Deep Learning** | **Topological Neural Networks** — [`🐍`](recipes/topological_neural_network.py) [`📓`](recipes/topological_neural_network.ipynb) | `topology.SimplicialComplex`, `helmholtz_hodge_decomposition`, Hodge 1-Laplacians |
| **Duality & Quantum Symmetry** | **Coalgebras & Hopf Algebras** — [`🐍`](recipes/coalgebras_and_hopf_symmetries.py) [`📓`](recipes/coalgebras_and_hopf_symmetries.ipynb) | `Coalgebra`, `Bialgebra`, `HopfAlgebra`, `GroupHopfAlgebra`, `SimplicialChainCoalgebra`, `cup_product` |
| **Geometric Physics** | **Relativistic Dirac Spinors** — [`🐍`](recipes/relativistic_dirac_spinor.py) [`📓`](recipes/relativistic_dirac_spinor.ipynb) | `clifford.CliffordAlgebra(1, 3)`, even subalgebra $Cl^+(1,3)$, $4\pi$ periodicity, Lorentz boosts |
| **Automatic Differentiation** | **Forward-Mode Autodiff** — [`🐍`](recipes/forward_mode_autodiff.py) [`📓`](recipes/forward_mode_autodiff.ipynb) | `StandardSemiring(DualNumber)`, quotient ring $\mathbb{R}[\epsilon]/(\epsilon^2)$, `matrix.dot` |
| **Group Theory & Combinatorics** | **Rubik's Cube Solver** — [`🐍`](recipes/rubiks_cube_group_solver.py) [`📓`](recipes/rubiks_cube_group_solver.ipynb) | `group.compose`, `group.invert`, `group.signature`, commutator surgery |
| **Information & NLP** | **CYK Provenance Parser** — [`🐍`](recipes/nlp_provenance_parser.py) [`📓`](recipes/nlp_provenance_parser.ipynb) | `matrix.dot`, `semiring.ProvenanceSemiring`, `probability.entropy` |
| **Cryptography & Finite Fields** | **Galois Finite Fields** — [`🐍`](recipes/galois_field_cryptography.py) [`📓`](recipes/galois_field_cryptography.ipynb) | `galois.GaloisFieldSemiring`, `galois.gf_matrix_mul`, `QuotientMonoidAlgebraSemiring` |
| **Distributed Systems** | **Vector Clocks & CRDTs** — [`🐍`](recipes/distributed_vector_clocks.py) [`📓`](recipes/distributed_vector_clocks.ipynb) | `lattice.combine`, `ArcticSemiring`, `BooleanSemiring`, causal DAG contractions |

Run any recipe directly using `uv`:

```bash
uv run recipes/coalgebras_and_hopf_symmetries.py
```

---

## Graphical Desktop Laboratory

Launch the interactive [DearPyGui](https://github.com/hoffstadt/DearPyGui) laboratory application featuring 12
interactive modules, live image convolution texture previews, force-directed graph canvases, signal transforms, and
information theory calculators:

```bash
uv run recipes/lab.py
```

---

## Documentation

Full documentation is published at **[erivlis.github.io/algebrax](https://erivlis.github.io/algebrax)** and structured in `docs/`:

* 🚀 [**Start & Concepts**](docs/index.md): Installation, quickstart, [Periodic Table of Mixins](docs/concepts.md), [Library Comparison](docs/comparison.md), and [Axiomatic Verification](docs/verification.md).
* 📖 [**7-Tier User Guide**](docs/guide/index.md): Deductive tour from Magmas & Monoids to Semirings, Rings, Exact Fields, Clifford & Lie Algebras, Hopf Algebras, Categories, and Topological Sheaves.
* 🍳 [**All 38 Recipes & GUI Lab**](docs/recipes.md): Complete index of runnable scripts, Jupyter notebooks, and the DearPyGui laboratory.
* 📜 [**Enhancement Proposals**](docs/eps.md): Architectural design records and roadmap (`EP-0099`+).

---

## Development & Contributing

### Golden Source Recipes & Jupytext Sync

All recipes in `recipes/` are authored as Python scripts (`.py`) using **Jupytext Percent format** (`# %%` cell markers)
as the canonical **Golden Source**. Corresponding Jupyter Notebooks (`.ipynb`) are auto-generated from these scripts.

#### Pre-Commit Hook Setup

Install the `pre-commit` hook to automatically sync `.ipynb` notebooks whenever you modify a `.py` recipe script:

```bash
# Ensure local repository hooks directory is active (recommended if global hooksPath is set)
git config --local core.hooksPath .git/hooks

# Install pre-commit hook
uvx pre-commit install
```

#### Manual Sync & Testing

```bash
# Refresh all Jupyter notebooks from Golden Source scripts
uvx jupytext --to notebook recipes/*.py

# Run unit tests (or notebook execution tests)
uv run --group test pytest
uv run --group test pytest --nbmake recipes/
```

---

## License

Distributed under the MIT License. See [`LICENSE`](LICENSE) for more information.
