| title | Concepts |
|---|---|
| description | Theoretical overview of the algebraic structures used in `algebrax`, including monoids, groups, semirings, and their applications in graph analysis, logic, and probability. |
| icon | lucide/lightbulb |
This document provides a theoretical overview of the algebraic structures used in algebrax. Understanding these
concepts helps clarify why certain operations are grouped together and how they generalize across different domains
(graphs, logic, probability).
Tip
Semiring Mental Model
Think of a Semiring as an arithmetic engine where you swap out standard Addition (+) and
Multiplication (×) for any custom rules — like dot) then solves completely
different problems just by switching the semiring!
Hierarchy of Structures (Ordered by Complexity)
A set
-
Closure: If
$a, b \in M$ , then$a \cdot b \in M$ . -
Associativity:
$(a \cdot b) \cdot c = a \cdot (b \cdot c)$ . -
Identity: There exists
$e \in M$ such that$a \cdot e = e \cdot a = a$ .
Example:
- Natural numbers under addition
$(\mathbb{N}, +)$ . Identity is 0. - Strings under concatenation. Identity is
"".
A Monoid where every element has an Inverse.
-
Inverse: For every
$a \in G$ , there exists$a^{-1}$ such that$a \cdot a^{-1} = e$ .
Example in Library:
- Permutations (
algebra.group): The set of bijective mappings forms a group under composition.- Operation:
compose(f, g) - Inverse:
invert(f) - Identity:
{k: k}
- Operation:
A Group where the operation is also Commutative:
-
$a \cdot b = b \cdot a$ .
Example: Integers under addition
A Groupoid generalizes a Group to multi-state systems. It can be defined as a small Category in which every morphism is an isomorphism (invertible), or as a set equipped with a partial binary composition
-
Partial Composition:
$g \circ f$ is defined only when the codomain (target) of$f$ equals the domain (source) of$g$ . -
Associativity:
$(h \circ g) \circ f = h \circ (g \circ f)$ whenever composable. -
Identities: For every state/object
$A$ , there exists an identity morphism$\text{id}_A$ . -
Inverses: For every morphism
$f: A \to B$ , there exists an inverse morphism$f^{-1}: B \to A$ such that:$$f \circ f^{-1} = \text{id}_B \quad \text{and} \quad f^{-1} \circ f = \text{id}_A$$
Examples & Applications:
- Group vs Groupoid: A Group is a Groupoid with only one object (all elements are everywhere composable).
-
Patch Theory (Darcs VCS): Repository states are objects; diff patches
$P: \text{State}_1 \to \text{State}_2$ are groupoid morphisms. Every patch has a formal inverse$P^{-1}$ , and patches compose along valid execution paths. -
Topological Fundamental Groupoid
$\Pi_1(X)$ : Continuous path transformations in point clouds and simplicial complexes (algebrax.homology). -
Permutations (
algebrax.group): Full permutations form a single-object groupoid (a Group), while partial bijection transformations form a multi-object groupoid.
A set
-
$(S, \oplus)$ is a Commutative Monoid (Identity$\mathbf{0}$ ). -
$(S, \otimes)$ is a Monoid (Identity$\mathbf{1}$ ). - Distributivity: Multiplication distributes over Addition.
-
Annihilation:
$a \otimes \mathbf{0} = \mathbf{0}$ .
Crucially: Semirings do not require additive inverses (subtraction) or multiplicative inverses (division).
Examples in Library (algebrax.semiring):
Semirings are organized into categorical sub-modules under algebrax.semiring:
-
arithmetic:StandardSemiringover real numbers$(\mathbb{R}, +, \times)$ or complex amplitudes$(\mathbb{C}, +, \times)$ (quantum path integrals, discrete wave interference). -
optimization:TropicalSemiring$(\mathbb{R} \cup {\infty}, \min, +)$ ,ArcticSemiring,ViterbiSemiring,ReliabilitySemiring,BottleneckSemiring,MinTimesSemiring. Shortest path and capacity algorithms. -
logic:BooleanSemiring$({T, F}, \lor, \land)$ ,LukasiewiczSemiring,DigitalSemiring. Reachability, fuzzy logic, and post-quantum digital operations. -
statistical:LogSemiring,ExpectationSemiring,VarianceSemiring,SkewnessSemiring,KurtosisSemiring,StatisticalMomentSemiring,BivariateVarianceSemiring,MultivariateMomentSemiring. Probabilistic inference, higher-order statistical moments, multivariate covariance matrices. -
structures:StringSemiring,KCollapsedSemiring. Formal path languages, bounded counting. -
algebraic:DualNumberSemiring,BinomialConvolutionSemiring,MultivariateBinomialConvolutionSemiring,MonoidAlgebraSemiring,PolynomialSemiring,KnotSemiring,ProvenanceSemiring,QuotientMonoidAlgebraSemiring,CliffordSemiring($Cl(p,q,r)$ geometric algebras and Spacetime Dirac spinors),GeneralizedCliffordSemiring,QuantumCliffordSemiring,GaloisFieldSemiring. Free & quotient monoid algebras, divided power polynomial rings, skein modules, Clifford multivectors, finite fields.
A Semiring that has additive inverses.
-
$(R, +)$ is an Abelian Group (Subtraction is defined).
Example: Integers
Note
Why the Graph Laplacian Requires a Ring/Field
While reachability (
A Ring where multiplication has inverses (for non-zero elements).
-
$(F \setminus {0}, \cdot)$ is an Abelian Group (Division is defined).
Example: Real Numbers
A Vector Space equipped with a bilinear product.
- Elements can be added and scaled (Vector Space).
- Elements can be multiplied (Ring-like).
Example: The set of
A subset
- If
$x \in I$ and$r \in R$ , then$r \cdot x \in I$ . - Used to define Quotient Rings (e.g., Modular Arithmetic).
An associative algebra equipped with a quadratic form or root-of-unity commutation rule, unifying scalars, vectors, and higher-order blades (bivectors, trivectors).
-
Standard Clifford / Geometric Algebra
$Cl(p, q, r)$ :$\mathbf{e}_i \mathbf{e}_j = -\mathbf{e}_j \mathbf{e}_i$ ($i \ne j$ ),$\mathbf{e}_i^2 \in {+1, -1, 0}$ , with geometric product$ab = a \cdot b + a \wedge b$ . Generalizes complex numbers, quaternions, and Dirac spinors. -
Generalized Clifford Algebra (GCA)
$C_n^{(m)}$ : Clock-and-shift commutation$\mathbf{e}_j \mathbf{e}_k = \omega \mathbf{e}_k \mathbf{e}_j$ ($j < k$ ) where$\omega = \exp(2\pi i / n)$ is a primitive$n$ -th root of unity and$\mathbf{e}_j^n = \alpha_j \mathbf{1}$ . -
$q$ -Deformed Quantum Clifford Algebra$Cl_q(m)$ : Braided quantum deformation$\mathbf{e}_j \mathbf{e}_k = -q \mathbf{e}_k \mathbf{e}_j$ ($j < k$ ).
The algebrax.analysis and algebrax.homology modules implement concepts from DEC and Topological Homology on graphs
and
| Concept | Mathematical Object | Library Type / Function | Example / Application |
|---|---|---|---|
| 0-form | Scalar Field (on nodes) | SparseVector |
Temperature at each city |
| 1-form | Vector Field (on edges) | SparseMatrix |
Traffic flow between cities |
| Gradient ( |
gradient() |
Difference in temp between cities | |
| Divergence ( |
divergence() |
Net traffic flow out of a city | |
| Laplacian ( |
laplacian() |
Heat diffusion rate | |
|
|
SimplicialComplex |
Triangles, tetrahedra, cliques | |
| Boundary ( |
boundary_matrix() |
Face boundary alternating sums | |
| Nilpotency | verify_nilpotency() |
Fundamental homology boundary law | |
| Hodge-Laplacian | hodge_laplacian() |
|
|
| Betti Numbers ( |
betti_numbers() |
Hole count ( |
The algebrax.clifford module implements Clifford Geometric Algebra over QuotientMonoidAlgebraSemiring.
Multivectors unify scalars, vectors, bivectors, and pseudoscalars into a single sparse mapping {blade_tuple: coeff}.
-
Geometric Product:
$A B = A \cdot B + A \wedge B$ (computed viageometric_product()). -
Canonical Blade Reduction:
$\mathbf{e}_i \mathbf{e}_j = -\mathbf{e}_j \mathbf{e}_i$ and$\mathbf{e}_i^2 = +1$ ($i \le p$ ),$-1$ ($p < i \le p+q$ ),$0$ ($i > p+q$ ). -
Rotor Sandwiching (
$v' = R v R^\dagger$ ): Smooth 3D spatial rotations$R = \exp (-\theta/2 \mathbf{B})$ viarotor_rotation()without gimbal lock or matrix conversions.
The algebrax.galois module provides finite field arithmetic over QuotientMonoidAlgebraSemiring. Elements are
represented as sparse polynomial vectors {exponent: coeff} modulo an irreducible polynomial
-
Polynomial Modulo Reduction: Polynomial multiplication in
$\mathbb{F}_p[x]$ reduced modulo$P (x)$ (e.g.$x^8 + x^4 + x^3 + x + 1$ for AES $\text{GF} (2^8)$). -
Matrix Arithmetic:
gf_matrix_mul()computes sparse matrix multiplication for cryptographic MixColumns transformations and Reed-Solomon generator matrices.
The algebrax.category module formalizes category-theoretic compositions.
-
Morphisms as Matrices: Hom-sets
$\text{Hom} (A, B)$ are sparse matrices$M[A][B]$ . -
Kleisli Monadic Composition: Effectful morphisms
$f: A \to T (B)$ and$g: B \to T (C)$ compose via Kleisli matrix multiplication ($g \circ_T f = \text{dot} (f, g, \text{semiring})$) over probabilistic (Viterbi), cost-metric (Tropical), or reachability (Boolean) monad semirings. -
Kan Extensions: Left Kan extensions
$\text{Lan}_P F$ computed over sparse category graphs.
The following table categorizes the functions in the algebrax module by their Domain (Meaning) and Operation
Type.
- Structural: Transforms the shape or content of the data (returns a
Mapping). - Metric: Reduces the data to a single number (returns
float/int). - Predicate: Checks a property (returns
bool). - Generator: Creates a new structure from scratch.
Input: Sparse Vectors/Matrices (representing physical systems or geometric transformations)
| Function | Type | Meaning |
|---|---|---|
add |
Structural | Element-wise addition ( |
dot |
Structural | Matrix Multiplication ( |
mat_vec, vec_mat
|
Structural | Matrix-Vector multiplication (Transformation). |
transpose |
Structural | Flips rows and columns ( |
inverse |
Structural | Finds |
power |
Structural | Matrix exponentiation ( |
adjoint |
Structural | Transpose of cofactor matrix. |
cofactor |
Structural | Matrix of cofactors. |
inner |
Metric | Dot product of two vectors (Similarity). |
determinant |
Metric | Volume scaling factor of the transformation. |
trace |
Metric | Sum of diagonal elements (Invariant). |
kronecker_delta |
Generator | Creates an Identity Matrix ( |
Input: Mappings as Sets or Fuzzy Sets (Values represent membership/intensity)
| Function | Type | Meaning |
|---|---|---|
join |
Structural | Union / Max ( |
meet |
Structural | Intersection / Min ( |
difference |
Structural | Set Difference ( |
symmetric_difference |
Structural | XOR ( |
combine |
Structural | Generalized element-wise operation. |
mask |
Structural | Keep keys in A that are also in B. |
exclude |
Structural | Keep keys in A that are NOT in B. |
product |
Structural | Element-wise product (Hadamard). |
ratio |
Structural | Element-wise division. |
average, geometric_mean, harmonic_mean
|
Structural | Element-wise means. |
Input: Mappings as Probability Distributions (Values sum to 1)
| Function | Type | Meaning |
|---|---|---|
bayes_update |
Structural | Posterior |
markov_step |
Structural | Advance state by |
markov_steady_state |
Structural | Find equilibrium distribution ( |
marginalize |
Structural | Sum over rows/cols (Joint |
normalize |
Structural | Scale values to sum to 1. |
entropy |
Metric | Uncertainty ($H(X)$). |
cross_entropy |
Metric | Difference between distributions ($H(P, Q)$). |
kl_divergence |
Metric | Information Gain ($D_{KL}(P | Q)$). |
mutual_information |
Metric | Dependence between variables ($I(X; Y)$). |
expected_value |
Metric | Mean of the distribution ( |
variance, skewness, kurtosis
|
Metric | Higher-order moments. |
mode |
Metric | Most probable outcome. |
Input: Mappings as Adjacency Matrices (Graphs)
| Function | Type | Meaning |
|---|---|---|
laplacian |
Structural | Graph Laplacian ( |
gradient |
Structural | Edge-based difference operator. |
divergence |
Structural | Node-based flow operator. |
eigen_centrality |
Structural | Node importance ranking. |
forman_ricci_curvature |
Metric | Local curvature of the graph (Geometry). |
Input: Mappings as Time Series or Signals
| Function | Type | Meaning |
|---|---|---|
convolve |
Structural | Discrete convolution / polynomial multiplication ( |
dft / idft
|
Structural | Discrete Fourier Transform (Time |
walsh_hadamard |
Structural | Walsh-Hadamard Transform (Orthogonal Hadamard mapping). |
gelfand_transform |
Structural | Generalized character evaluation over monoid algebras. |
legendre_fenchel |
Structural | Fenchel-Legendre transform (Slope transform). |
z_transform |
Structural | Z-Transform (Discrete Laplace / Semiring power series). |
hilbert |
Structural | Hilbert Transform (Analytic Signal). |
lorentz_boost |
Structural | Relativistic coordinate transformation. |
box_counting_dimension |
Metric | Fractal dimension of the signal. |
Input: Mappings as Permutations (Bijective Functions)
| Function | Type | Meaning |
|---|---|---|
compose |
Structural | Function composition ( |
invert |
Structural | Inverse function ( |
signature |
Metric | Parity of permutation (+1 or -1). |
Input: Any Mapping
| Function | Type | Meaning |
|---|---|---|
sparsity |
Metric | Fraction of zero elements ( |
density |
Metric | Fraction of non-zero elements ( |
deepness |
Metric | Maximum nesting depth. |
wideness |
Metric | Maximum branching factor. |
uniformness |
Metric | Variance of value distribution (0 = uniform). |
is_sparse |
Predicate | Checks if density < threshold. |
Input: State Machines (Transition Functions)
| Function | Type | Meaning |
|---|---|---|
dfa_step, nfa_step |
Structural | Single transition. |
simulate_dfa, simulate_nfa |
Structural | Full execution trace. |
Input: Tries & Higher-Order Structures
| Function/Class | Type | Meaning |
|---|---|---|
AlgebraicTrie |
Structure | Sparse Tensor / Prefix Tree over a Semiring. |