Skip to content

EP-0198: Generalized Closure Operators — Kleene Plus, Matrix Star Closure & Action Algebras

Field Value
EP 0198
Title Generalized Closure Operators — Kleene Plus, Matrix Star Closure & Action Algebras
Author Eran Rivlis eran@algebrax.org, Antigravity AI
Sponsor ⚖️ Noether (Symmetry & Invariance), 🧩 Russell (Taxonomy & Consistency)
Delegate 🔬 Popper (Falsifiability & Multi-Layered Testing)
Status Final
Type Standards Track
Created 2026-11-13
Updated 2026-11-13
Replaces None
Superseded-By None

Abstract

Building upon the foundations of EP-0197 (which decoupled pure semirings from unary Kleene star closure), this proposal formalizes the broader taxonomy of algebraic closure mechanisms within AlgebraX. Specifically, it introduces:

  1. Strict Non-Empty Iteration (Kleene Plus, \(a^+\)): A default operator on StarSemiring satisfying \(a^+ = a \cdot a^* = a^* \cdot a\), essential for strict transitive reachability and cycle detection without spurious self-loops.
  2. Universal Matrix Star Closure (ax.matrix.star, \(A^*\)): Lifting scalar star closure to matrices over any Conway/Star semiring via recursive \(2 \times 2\) block Conway identities, unifying all-pairs shortest paths (Tropical), transitive reachability (Boolean), and chart parsing (Grammar).
  3. Residuated Lattices & Action Algebras (ActionAlgebra, \(a \backslash b\) and \(b / a\)): Adjoint division operators enabling equational axiomatization of Kleene algebra without Horn clauses, weakest precondition reasoning, and language quotients (Brzozowski derivatives).
  4. Taxonomic Demarcation: Explicit boundary definitions for infinite iteration (\(\omega\)-iteration) and modal fixed-point operators (\(\mu, \nu\)), establishing why finite-carrier computational algebra treats them as coinductive limits outside core scalar protocols.

Motivation

In theoretical computer science and abstract algebra, repetition and reachability take multiple forms:

  • Kleene Star (\(a^*\)) models finite reachability (0 or more steps).
  • Kleene Plus (\(a^+\)) models strict non-empty progress (1 or more steps).
  • Matrix Star (\(A^*\)) models all-pairs reachability and shortest paths in networks.
  • Residuals (\(a \backslash b, b / a\)) model backward inference and weakest preconditions.
  • Omega Iteration (\(a^\omega\)) models perpetual reactive behavior and liveness.
  • Least/Greatest Fixed Points (\(\mu, \nu\)) model inductive generation vs coinductive safety.

The Current Limitations in AlgebraX

While EP-0197 cleanly separated Semiring, StarSemiring, and KleeneAlgebra, three concrete limitations remain:

  1. No First-Class Strict Transitive Closure (\(a^+\)): Users modeling graph reachability or grammar derivations frequently need paths of length \(\ge 1\) (\(A^+\)). Without a plus primitive, users manually implement ad-hoc multiplications (\(A \cdot A^*\)), or erroneously use \(A^*\), introducing false reflexive self-loops (\(d(u, u) = 0\)).
  2. Missing Matrix-Level Closure Primitive: Scalar semirings define .star(a), but algebrax.matrix lacks an algorithmic primitive matrix.star(M, semiring) and matrix.plus(M, semiring). Users must resort to manual matrix power loops (\(I + A + A^2 + \dots\)), which do not converge for general Conway semirings (such as StandardSemiring or DualNumberAlgebra) and are computationally inefficient (\(O(k \cdot n^3)\)).
  3. Absence of Backward Reasoning & Language Quotients: Action algebras (Vaughan Pratt, 1991) augment Kleene algebras with residuals \(a \backslash b\) and \(b / a\). In programming language semantics and automata theory, residuals compute Dijkstra weakest preconditions and Brzozowski derivatives. Currently, AlgebraX has lattices and semirings, but no residuated algebraic layer.

Rationale

Council Alignment

  • ⚖️ Noether (Symmetry & Invariance): Preserves exact mathematical adjunctions. Residuals are defined strictly as Galois adjoints to multiplication: $\(a \cdot x \le b \iff x \le a \backslash b \qquad\text{and}\qquad x \cdot b \le a \iff x \le a / b\)$ This duality guarantees that backward inference is the exact algebraic reflection of forward progression.
  • 🧩 Russell (Taxonomy & Consistency): Orthogonalizes operational mixins. We introduce atomic capability protocols HasPlus[V] and HasResiduals[V] without diamond-inheritance conflicts, ensuring seamless structural subtyping.
  • ⚡ Shannon (Efficiency & Zero-Boxing): Matrix closure is implemented via Conway's \(2 \times 2\) block decomposition. This reduces matrix star computation to standard matrix additions and multiplications, operating directly on unboxed sparse coordinate structures in \(O(n^{\log_2 7})\) or \(O(n^3)\) without iterative convergence loops.
  • 🔬 Popper (Falsifiability & Multi-Layered Testing): Introduces explicit verification suites in algebrax.verification:
  • verify_star_plus_consistency(s, a): Checks \(a^+ = a \cdot a^* = a^* \cdot a\).
  • verify_residuation_laws(s, a, b): Checks \(a \cdot (a \backslash b) \le b\) and \(b \le a \backslash (a \cdot b)\).
  • verify_matrix_conway_laws(M, semiring): Verifies sum-star and product-star identities on matrix blocks.

Specification

1. Atomic Mixins (src/algebrax/algebra/_mixins.py)

Add atomic operational mixins for non-empty iteration and residuation:

@runtime_checkable
class HasPlus(Protocol[V]):
    r"""Strict non-empty iteration closure $a^+ = a \cdot a^* = a^* \cdot a$."""

    def plus(self, a: V) -> V:
        ...


@runtime_checkable
class HasResiduals(Protocol[V]):
    r"""Left and right residuation / division operators adjoint to multiplication:
    $a \cdot x \le b \iff x \le a \backslash b$ (left residual: `ldiv(a, b)`)
    $x \cdot b \le a \iff x \le a / b$ (right residual: `rdiv(a, b)`)
    """

    def ldiv(self, a: V, b: V) -> V:
        ...

    def rdiv(self, a: V, b: V) -> V:
        ...

2. Default plus on StarSemiring (src/algebrax/algebra/_semiring.py)

Enhance StarSemiring with a default implementation of plus(a):

@runtime_checkable
class StarSemiring(HasZero[V], HasAdd[V], HasOne[V], HasMul[V], HasStar[V], Protocol):
    ...

    def plus(self, a: V) -> V:
        r"""Strict positive iteration: $a^+ = a \cdot a^*$.

        In any unital star semiring, $a^+ = a \cdot a^* = a^* \cdot a$.
        """
        return self.mul(a, self.star(a))

3. Action Algebra Protocol (src/algebrax/algebra/_action.py)

Define ActionAlgebra[V] as an extension of KleeneAlgebra[V] equipped with left and right residuals:

@runtime_checkable
class ActionAlgebra(
    KleeneAlgebra[V],
    HasResiduals[V],
    Protocol[V],
):
    r"""An Action Algebra $\langle V, \mathbf{0}, +, \mathbf{1}, \cdot, ^*, \backslash, / \rangle$.

    An action algebra is a Kleene algebra with left and right residuals satisfying:
        $a \cdot (a \backslash b) \le b$
        $b \le a \backslash (a \cdot b)$
        $(b / a) \cdot a \le b$
        $b \le (b \cdot a) / a$
        $(a \backslash a)^* \le a \backslash a \quad\text{and}\quad (a / a)^* \le a / a$
    """

    ...

4. Matrix Star & Plus Closure (src/algebrax/matrix/closure.py)

Provide universal matrix star and plus closure using Conway's block matrix recursion:

def matrix_star(
    matrix: Matrix[K, V],
    semiring: StarSemiring[V],
) -> Matrix[K, V]:
    r"""Compute the Kleene star closure $A^*$ of a square matrix $A$ over a StarSemiring.

    Uses Conway's recursive block decomposition:
        For $A = \begin{pmatrix} A_{11} & A_{12} \\ A_{21} & A_{22} \end{pmatrix}$:
            $E = (A_{11} + A_{12} A_{22}^* A_{21})^*$
            $A^*_{11} = E$
            $A^*_{12} = E \cdot A_{12} \cdot A_{22}^*$
            $A^*_{21} = A_{22}^* \cdot A_{21} \cdot E$
            $A^*_{22} = A_{22}^* + A_{22}^* \cdot A_{21} \cdot E \cdot A_{12} \cdot A_{22}^*$
    Base Case ($1 \times 1$):
        $[a]^* = [a^*]$
    """
    ...


def matrix_plus(
    matrix: Matrix[K, V],
    semiring: StarSemiring[V],
) -> Matrix[K, V]:
    r"""Compute the strict transitive closure $A^+ = A \cdot A^*$ of a square matrix."""
    a_star = matrix_star(matrix, semiring)
    return dot(matrix, a_star, semiring=semiring)

5. Architectural Demarcation of Omega (\(\omega\)) and Fixed Points (\(\mu, \nu\))

To preserve computational integrity and termination guarantees:

  1. Omega Iteration (\(a^\omega\)): Models infinite streams (\(a^\omega \in \Sigma^\omega\)). Because AlgebraX operates over finite, unboxed computational carriers, infinite sequences require coinductive generators or topology/metric completions (as explored in EP-0205). It is not part of the standard finite matrix/algebra suite.
  2. Least/Greatest Fixed Points (\(\mu, \nu\)): In finite lattices, least fixed points (\(\mu\)) and greatest fixed points (\(\nu\)) are computed constructively via monotone iteration: $\(\mu X. f(X) = \bigsqcup_{k \ge 0} f^k(\bot) \qquad\text{and}\qquad \nu X. f(X) = \bigsqcap_{k \ge 0} f^k(\top)\)$ AlgebraX exposes these via algebrax.analysis.contractive_fixed_point and algebrax.lattice monotone solvers rather than symbolic \(\mu\)-calculus formulas.

Backwards Compatibility

  • Non-Breaking Protocol Extensions: Adding plus(a) to StarSemiring with a default implementation ensures all existing StarSemiring implementations immediately satisfy the protocol without modification.
  • Isolated Matrix Additions: matrix_star and matrix_plus are purely additive functions in algebrax.matrix and do not alter existing matrix multiplication or decomposition APIs.
  • Zero Disruption to Existing EPs: Fully compatible with EP-0197 and EP-0200.

How to Teach This / Documentation Plan

  1. User Guide:
  2. Add a section on Transitive & Reflexive-Transitive Closures in docs/guide/algebra/semirings_overview.md, contrasting \(a^*\) (reflexive paths) and \(a^+\) (strict paths).
  3. Update docs/guide/matrix/core.md with examples of ax.matrix.star(adj_matrix, ax.semiring.Tropical()) for all-pairs shortest paths.
  4. Automata & Parsing Guide:
  5. Update docs/guide/discrete/automata.md showing how CYK chart parsing maps directly to ax.matrix.plus.
  6. Formal Recipes:
  7. Add a graph reachability and cycle detection recipe in docs/recipes.md demonstrating why \(A^+\) avoids false self-loops on directed acyclic graphs (DAGs).

Reference Implementation

# Proof of Concept: Conway Block Matrix Star
def _block_star_2x2(a11, a12, a21, a22, s: StarSemiring[V]):
    # A22*
    a22_star = matrix_star(a22, s)
    # E = (A11 + A12 · A22* · A21)*
    schur_prod = dot(dot(a12, a22_star, semiring=s), a21, semiring=s)
    e = matrix_star(add(a11, schur_prod, semiring=s), s)

    # Blocks of A*
    r11 = e
    r12 = dot(dot(e, a12, semiring=s), a22_star, semiring=s)
    r21 = dot(dot(a22_star, a21, semiring=s), e, semiring=s)
    r22 = add(a22_star, dot(r21, dot(a12, a22_star, semiring=s), semiring=s), semiring=s)

    return combine_blocks([[r11, r12], [r21, r22]])

Rejected Ideas

  1. Requiring plus as an abstract method without default:
  2. Rejected: Would break existing custom star semirings and require unnecessary boilerplate when \(a^+ = a \cdot a^*\) holds universally.
  3. Adding \(a^\omega\) to StarSemiring:
  4. Rejected: Most computational semirings (e.g. Standard \(\mathbb{R}\), Dual Numbers) have no sensible finite representation for infinite iteration. Omega iteration belongs to specialized \(\omega\)-algebras and Büchi automata engines.
  5. Folding Residuals directly into Semiring:
  6. Rejected: Distributive lattices and Boolean semirings admit residuals (Heyting/Boolean algebras), but general arithmetic semirings (e.g., \((\mathbb{N}, +, \cdot)\)) do not possess exact residuals. Residuation must remain a dedicated mixin (HasResiduals).

Open Questions

  • [ ] Should ax.matrix.star default to Floyd–Warshall Gauss–Jordan elimination for dense matrices and Conway block decomposition for sparse block matrices, based on carrier density?
  • [ ] Should ActionAlgebra provide a high-level helper weakest_precondition(action, postcondition) as an ergonomic alias for rdiv / ldiv?

Change Log

  • 2026-11-13:
  • Implemented and validated via multi-tier verification suites (tests/algebrax/test_action.py).
  • Promoted to Final status following consensus and complete quality gate pass.
  • 2026-11-13:
  • Initial Draft authored by Eran Rivlis and Antigravity AI following architectural consensus on generalized closure mechanisms.