Algebras¶
An Algebra fixes how composition
combines weights:
a product \(\otimes\) along a path and a reduction \(\oplus\) across alternative paths. Each built-in
instance is a semiring (Goodman, 1999; Mohri, 2002), a t-norm with its t-conorm
(Klement et al., 2000), or a product with capped sum. Multiplication with summation gives the
ordinary matrix product, and addition with minimum gives shortest path costs. Composition is
associative only when \(\otimes\) is associative and distributes over \(\oplus\) (Kelly, 1982).
The instances whose operations satisfy the semiring laws are of class Semiring, and those whose
\(\oplus\) is also idempotent of class IdempotentSemiring. The default product t-norm with noisy-OR
reduction does not distribute, so it is an Algebra only, and with it a change of grouping can
change the result.
algebras
¶
Algebras: the operations that parameterize tensor composition.
A commutative algebra Q = (L, ⊗, ⋁, ⋀, ¬, I, ⊥) defines the composition of L-valued matrices
(g ∘ f)(a, c) = ⋁_b f(a, b) ⊗ g(b, c)
and the identity matrix (I on the diagonal, ⊥ elsewhere). Composition
is associative exactly when the operations satisfy the semiring laws;
those algebras are instances of Semiring, and for them finite sets
and L-valued matrices form a category (for instance Rel under
BooleanAlgebra, or finite stochastic matrices under MarkovAlgebra).
The remaining algebras, such as the default ProductFuzzyAlgebra
(product with noisy-OR), fail distributivity, so their composition is
unital but depends on bracketing. join names the implemented
reduction and is a lattice supremum only for an IdempotentSemiring.
The classes form one hierarchy. Each class states the laws its members
satisfy as quivers.core.laws.Law records, and every member reports,
for each law it claims, a quivers.core.laws.LawClaim whose evidence
is a written argument, a decision procedure, a test on finite data, or
a declaration.
Executors ask for a capability by type: Selective sums return one of
their operands, ZeroSumFree and NoZeroDivisors make support a
homomorphism, a Semifield divides, a Ring subtracts, and a
Semimodule is acted on by a semiring. A Carrier gives the zero (and
a UnitalCarrier the unit) in the shape, dtype and device a computation
needs, decides membership, and returns the zero for a reduction over no
terms.
References
Golan, J. S. (1999). Semirings and their Applications. Springer. doi:10.1007/978-94-015-9333-5
Carrier
¶
Bases: Lawful
A set of values held in tensors, with a zero and a sum.
One element of the carrier occupies the trailing element_shape
axes of a tensor; the leading axes index elements. A scalar carrier
has element_shape == (). The zero is given in the shape, dtype
and device a computation needs, so no computation makes it in the
default dtype. join reduces index axes by the sum, and a
reduction over no terms is the zero, with a derivative that is a
number.
element_shape
abstractmethod
property
¶
The trailing axes of one element.
| RETURNS | DESCRIPTION |
|---|---|
tuple of int
|
|
zero_like
abstractmethod
¶
The zero at every index of shape.
| PARAMETER | DESCRIPTION |
|---|---|
shape
|
The index shape.
TYPE:
|
like
|
The tensor whose dtype and device the zero takes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The zero with shape |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the dtype of |
Source code in src/quivers/core/algebras.py
contains
abstractmethod
¶
Whether each element of t lies in the carrier.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Elements with trailing
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
A Boolean tensor of the index shape of |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the entries are complex, or the carrier is not declared. |
Source code in src/quivers/core/algebras.py
join
abstractmethod
¶
The sum ⊕ over index axes.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Elements with trailing
TYPE:
|
dim
|
Index axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The reduction with the named axes removed. |
Source code in src/quivers/core/algebras.py
join_pair
¶
The binary sum a ⊕ b, with a first in declared order.
| PARAMETER | DESCRIPTION |
|---|---|
a
|
The first operand.
TYPE:
|
b
|
The second operand, broadcastable with
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The sum, computed as |
Source code in src/quivers/core/algebras.py
is_zero
¶
Whether each element of t is exactly the zero.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Elements with trailing
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
A Boolean tensor of the index shape of |
Source code in src/quivers/core/algebras.py
validate
¶
validate(t: Tensor) -> None
Require every element of t to lie in the carrier.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Elements with trailing
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the entries are complex, or the carrier is not declared. |
ValueError
|
If an element lies outside the carrier. |
Source code in src/quivers/core/algebras.py
empty_join
¶
The join over normalized axes one of which has size zero.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Elements with trailing
TYPE:
|
axes
|
Normalized index axes, one of size zero.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The zero of the remaining index shape in the dtype and device
of |
Source code in src/quivers/core/algebras.py
UnitalCarrier
¶
Bases: Carrier
A carrier with a product ⊗ and its unit.
The unit, like the zero, is given in the shape, dtype and device a computation needs.
tensor_op
abstractmethod
¶
The product ⊗ of elements, broadcast over index axes.
| PARAMETER | DESCRIPTION |
|---|---|
a
|
The left factor.
TYPE:
|
b
|
The right factor.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
Source code in src/quivers/core/algebras.py
unit_like
abstractmethod
¶
The unit at every index of shape.
| PARAMETER | DESCRIPTION |
|---|---|
shape
|
The index shape.
TYPE:
|
like
|
The tensor whose dtype and device the unit takes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The unit with shape |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the dtype of |
Source code in src/quivers/core/algebras.py
identity_tensor
¶
identity_tensor(obj_shape: tuple[int, ...], *, dtype: dtype | None = None, device: device | str | None = None) -> Tensor
The identity matrix of an object of the given shape.
| PARAMETER | DESCRIPTION |
|---|---|
obj_shape
|
The shape of the object, for instance
TYPE:
|
dtype
|
The dtype;
TYPE:
|
device
|
The device;
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Shape |
Source code in src/quivers/core/algebras.py
CompositionRule
¶
Bases: Lawful
A binary tensor contraction that promises no algebraic law.
Defines the V-enriched composition kernel
(f >> g)[i, k] = ⋁_j f[i, j] ⊗ g[j, k] from the two
primitive operations tensor_op (binary ⊗) and join
(reduction ⋁). No identity element is required at this level.
The hierarchy below this class records which laws composition satisfies:
Magmoid: composition is declared to satisfy no law, so the caller fixes every association order.Semigroupoid: composition is associative.OrderPreservingSemiring: a semiring whose product need not commute, so composition is associative and unital but keeps the order of its factors.Algebra: a scalar carrier withunitandzero(and meet and negation), so composition has two-sided identities. Associativity is not implied.Semiring: anAlgebrawhose operations satisfy the commutative-semiring laws, which makes composition associative and unital, so finite sets and tensors form a category.IdempotentSemiring: aSemiringwhosejoinis idempotent.
Operations that need identity check at runtime that the
composition rule is at least an Algebra; a clear
error is raised if a non-algebra rule is fed in.
tensor_op
abstractmethod
¶
join
abstractmethod
¶
Join ⋁, the reduction of composition.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Input tensor.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The reduction with the named axes removed. |
Source code in src/quivers/core/algebras.py
join_pair
¶
The binary join a ⋁ b, with a first in declared order.
| PARAMETER | DESCRIPTION |
|---|---|
a
|
The first operand.
TYPE:
|
b
|
The second operand, broadcastable with
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The join over a new leading axis holding |
Source code in src/quivers/core/algebras.py
compose
¶
V-enriched composition of scalar-valued tensors.
Computes result[d..., c...] = ⋁_{s...} m[d..., s...] ⊗ n[s..., c...].
| PARAMETER | DESCRIPTION |
|---|---|
m
|
Left tensor of shape
TYPE:
|
n
|
Right tensor of shape
TYPE:
|
n_contract
|
Number of shared axes to contract.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Composed tensor of shape |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/core/algebras.py
is_compatible
¶
is_compatible(other: CompositionRule) -> bool
Whether two rules compose: the same type, or the same name.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The other rule.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when morphisms over the two rules may compose; a custom instance built independently matches by name. |
Source code in src/quivers/core/algebras.py
Semigroupoid
¶
Bases: CompositionRule
A composition rule whose composition is associative.
A semigroupoid is a category without the requirement of identity
morphisms: composition is defined for composable pairs and is
associative [Tilson (1987)]. A CompositionRule belongs here
when (f >> g) >> h == f >> (g >> h) for all composable
tensors. Associativity of the scalar tensor_op alone does not
suffice: matrix composition also needs join to be associative
and commutative and tensor_op to distribute over it.
References
Tilson, B. (1987). Categories as algebra: an essential ingredient in the theory of monoids. Journal of Pure and Applied Algebra, 48(1-2), 83-198. doi:10.1016/0022-4049(87)90108-3
Magmoid
¶
Bases: CompositionRule
A composition rule declared to satisfy no law.
A magmoid is a quiver with a binary composition operation and no
further axioms: neither associativity nor identities are required
[Arnold and Dauchet (1978)]. It is to a category what a magma is to
a monoid. (f >> g) >> h may differ from f >> (g >> h), so
callers fix an association order explicitly, and the type records
that composition chains may not be reordered.
Examples include signed-dot-product compositions, top-k
truncating compositions, and the material-implication rule of
material_implication. A rule that is associative should be
declared as a Semigroupoid instead.
References
Arnold, A., and Dauchet, M. (1978). Théorie des magmoïdes (I). RAIRO Informatique théorique, 12(3), 235-257. doi:10.1051/ita/1978120302351
OrderPreservingSemiring
¶
Bases: Semigroupoid, UnitalCarrier
A semiring whose product need not commute.
(L, ⊕, 0) is a commutative monoid, (L, ⊗, 1) a monoid,
⊗ distributes over ⊕ on both sides and 0 annihilates
⊗ [Golan (1999)]. Matrices over it compose
associatively and unitally, but a composite keeps the order of its
factors: a plan over such weights may reorder sums and may not
exchange factors. Elements may have shape, as the square matrices
of MatrixSemiring do; composition contracts index axes and keeps
each element's trailing axes.
References
Golan, J. S. (1999). Semirings and their Applications. Springer. doi:10.1007/978-94-015-9333-5
compose
¶
Composition of element-valued tensors, keeping factor order.
Computes result[d..., c...] = ⊕_{s...} m[d..., s...] ⊗ n[s..., c...]
with m's element on the left of every product.
| PARAMETER | DESCRIPTION |
|---|---|
m
|
Shape
TYPE:
|
n
|
Shape
TYPE:
|
n_contract
|
Number of shared index axes to contract.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Shape |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/core/algebras.py
Algebra
¶
Bases: CompositionRule, UnitalCarrier
Abstract commutative algebra for V-enriched composition.
An algebra supplies the operations (⊗, ⋁, ⋀, ¬) and the
elements I (unit) and ⊥ (zero) on a scalar carrier.
Every shipped algebra satisfies I ⊗ a = a, ⊥ ⊗ a = ⊥ and
⋁(a, ⊥) = a, so the identity tensor is a two-sided identity for
composition. Associativity of composition is a further property,
held exactly by the Semiring subclasses; an Algebra that is not
a Semiring (PRODUCT_FUZZY, LUKASIEWICZ, PROBABILITY and
their duals) composes with identities but not associatively.
unit and zero are the scalar constants; unit_like and
zero_like give them in a requested shape, dtype and device.
Subclasses implement the primitive operations and contains.
element_shape
property
¶
The empty shape: one element is one entry.
| RETURNS | DESCRIPTION |
|---|---|
tuple of int
|
|
unit
abstractmethod
property
¶
Unit element I of the monoidal product ⊗.
| RETURNS | DESCRIPTION |
|---|---|
float
|
The unit. |
zero
abstractmethod
property
¶
Bottom element ⊥, the identity of ⋁.
| RETURNS | DESCRIPTION |
|---|---|
float
|
The zero. |
meet
abstractmethod
¶
Meet ⋀, the reduction for universal quantification (∀).
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Input tensor with values in L.
TYPE:
|
dim
|
Dimension(s) to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Reduced tensor. |
Source code in src/quivers/core/algebras.py
negate
abstractmethod
¶
zero_like
¶
The zero in a requested shape, dtype and device.
| PARAMETER | DESCRIPTION |
|---|---|
shape
|
The shape.
TYPE:
|
like
|
The tensor whose dtype and device the zero takes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
A constant tensor holding |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the dtype cannot hold the zero. |
Source code in src/quivers/core/algebras.py
unit_like
¶
The unit in a requested shape, dtype and device.
| PARAMETER | DESCRIPTION |
|---|---|
shape
|
The shape.
TYPE:
|
like
|
The tensor whose dtype and device the unit takes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
A constant tensor holding |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the dtype cannot hold the unit. |
Source code in src/quivers/core/algebras.py
dual
¶
dual() -> Algebra
The role-swapped dual algebra.
The dual uses the base join (as a binary operation) for its
tensor_op, the base tensor_op (folded as a reduction)
for its join, and swaps unit and zero:
tensor_op^op(a, b) = a ⋁ b
join^op(a_1, ..., a_n) = a_1 ⊗ ... ⊗ a_n
1^op = 0, 0^op = 1.
When ⊗ is a t-norm T and ⋁ is its De Morgan dual
t-conorm S(a, b) = N(T(N(a), N(b))) under the strong negation
N(a) = 1 - a, the swap exchanges a t-norm with its dual
t-conorm. For ProductFuzzyAlgebra this yields the pair
(⊗ = probabilistic sum, ⋁ = product reduction).
| RETURNS | DESCRIPTION |
|---|---|
Algebra
|
The dual. |
Source code in src/quivers/core/algebras.py
Semiring
¶
Bases: Algebra, OrderPreservingSemiring
An algebra whose operations form a commutative semiring.
A commutative semiring (L, ⊕, ⊗, 0, 1) has (L, ⊕, 0) and
(L, ⊗, 1) commutative monoids, ⊗ distributing over ⊕
on both sides, and 0 annihilating ⊗ [Golan (1999)]. Here
⊕ is the binary form of join, 0 is zero and 1 is
unit. These laws make the composition
(f >> g)[i, k] = ⊕_j f[i, j] ⊗ g[j, k] associative and unital,
so finite sets with tensors over L form a category (the
category of L-valued matrices). Membership in this class is a
claim that the laws hold; claims reports the status of each, and
the law grid of the evidence harness checks every shipped instance.
References
Golan, J. S. (1999). Semirings and their Applications. Springer. doi:10.1007/978-94-015-9333-5
IdempotentSemiring
¶
Bases: Semiring
A commutative semiring whose addition is idempotent.
Additive idempotence, a ⊕ a = a for every a, makes ⊕ the
join of the partial order a ≤ b ⟺ a ⊕ b = b [Golan (1999)].
On finite carriers of composition this is the structure that a
quantale restricts to, and it is what the fuzzy powerset monad
needs (see quivers.monadic.monads.FuzzyPowersetMonad). In the
shipped instances meet is the infimum of that order and top
is its greatest element, so each is a bounded distributive lattice
under (join, meet).
References
Golan, J. S. (1999). Semirings and their Applications. Springer. doi:10.1007/978-94-015-9333-5
top
abstractmethod
property
¶
The greatest element of the order a ≤ b ⟺ a ⊕ b = b.
It absorbs the join (a ⊕ ⊤ = ⊤) and is the meet of the empty
family.
| RETURNS | DESCRIPTION |
|---|---|
float
|
The top. |
residuum
abstractmethod
¶
The residuum [w, x], the greatest v with v ⊗ w ≤ x.
The order is a ≤ b ⟺ a ⊕ b = b. Residuation,
v ⊗ w ≤ x ⟺ v ≤ [w, x], makes [w, -] right adjoint to
- ⊗ w; it is the internal hom that weighted limits and
the Yoneda lemma use.
| PARAMETER | DESCRIPTION |
|---|---|
w
|
The left argument, broadcastable with
TYPE:
|
x
|
The right argument.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
Source code in src/quivers/core/algebras.py
Selection
didactic-model
¶
Selection(*, value: Tensor = field(opaque=True, extras=OPAQUE_BY_IDENTITY), witness: Tensor = field(opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: ValueModel
The result of a selective reduction and the operand it selected.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The selected operand at every remaining index.
TYPE:
|
witness
|
The flat position of the selected operand in row-major order of
the reduced axes, as
TYPE:
|
Selective
¶
Bases: Carrier
A carrier whose sum returns one of its operands.
a ⊕ b is a or b: the sum selects the operand that is
best under the order rank defines. The tie rule is one for every
operation: the first best operand, in row-major order of the reduced
axes (a before b in join_pair), is the value's witness and
receives the whole derivative. Splitting the derivative over tied
operands is another element of the subdifferential; using it in
one operation and not in another would make a derivative depend on
bracketing.
rank
abstractmethod
¶
select
¶
The best operand over index axes and its witness.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Elements of the carrier.
TYPE:
|
dim
|
Index axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Selection
|
The best operand and the flat position of the first one. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a reduced axis has size zero, since nothing is selected, or the carrier is not scalar. |
Source code in src/quivers/core/algebras.py
join
¶
The selective sum over index axes.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Elements of the carrier.
TYPE:
|
dim
|
Index axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The first best operand at every remaining index, or the zero for a reduction over no terms. |
Source code in src/quivers/core/algebras.py
ZeroSumFree
¶
Bases: Carrier
A carrier in which a sum is zero only when every term is.
With NoZeroDivisors this makes the support map onto the Boolean
semiring a homomorphism: a sum is nonzero exactly when some term is
[Golan (1999), "zerosumfree"].
References
Golan, J. S. (1999). Semirings and their Applications. Springer. doi:10.1007/978-94-015-9333-5
NoZeroDivisors
¶
Bases: UnitalCarrier
A carrier in which a product is zero only when a factor is.
Golan (1999) calls such a semiring entire. With ZeroSumFree it
makes the support map a homomorphism.
References
Golan, J. S. (1999). Semirings and their Applications. Springer. doi:10.1007/978-94-015-9333-5
Semifield
¶
Bases: NoZeroDivisors
A carrier in which every element other than zero has an inverse.
divide(a, b) is a ⊗ b⁻¹ for b other than the zero, so
(a ⊗ b) ⊘ b = a. A semifield has no zero divisors: if
a ⊗ b = 0 and b is not zero then a = (a ⊗ b) ⊘ b = 0.
Executors that eliminate by division (directed spanning trees,
weight pushing) ask for this capability.
References
Golan, J. S. (1999). Semirings and their Applications. Springer. doi:10.1007/978-94-015-9333-5
divide
abstractmethod
¶
The quotient a ⊘ b.
| PARAMETER | DESCRIPTION |
|---|---|
a
|
The dividend.
TYPE:
|
b
|
The divisor, broadcastable with
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
| RAISES | DESCRIPTION |
|---|---|
ZeroDivisionError
|
If an element of |
Source code in src/quivers/core/algebras.py
require_nonzero
¶
require_nonzero(b: Tensor) -> None
Refuse a divisor holding the zero.
| PARAMETER | DESCRIPTION |
|---|---|
b
|
The divisor.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ZeroDivisionError
|
If an element of |
Source code in src/quivers/core/algebras.py
Ring
¶
Bases: Carrier
A carrier whose sum has inverses.
subtract(a, b) is a ⊕ (−b), where −b is the additive
inverse, so a ⊕ (0 ⊖ a) = 0. Algorithms that cancel terms, such
as a determinant by elimination, need this capability; it gives up
the relative accuracy of sums of nonnegative terms.
Semimodule
¶
Bases: Carrier
A commutative monoid acted on by an order-preserving semiring.
A left semimodule over K is a commutative monoid (M, ⊕, 0)
with an action K × M → M that is associative, unital, and
distributes over both sums, and in which the zero of either side
annihilates [Golan (1999)]. Expectation carriers, whose
second component is acted on by probabilities, are built from this
capability; FreeSemimodule is the module of vectors over K.
References
Golan, J. S. (1999). Semirings and their Applications. Springer. doi:10.1007/978-94-015-9333-5
scalars
abstractmethod
property
¶
scalars: OrderPreservingSemiring
The semiring that acts.
| RETURNS | DESCRIPTION |
|---|---|
OrderPreservingSemiring
|
The scalars. |
act
abstractmethod
¶
The action k · m.
| PARAMETER | DESCRIPTION |
|---|---|
k
|
Scalars, with the scalars' element axes trailing.
TYPE:
|
m
|
Module elements with the same index shape (or one that broadcasts with it).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
Source code in src/quivers/core/algebras.py
DivergentClosureError
¶
Bases: ValueError
A path closure has no value in the declared carrier.
UndecidedClosureError
¶
Bases: ValueError
Rounding leaves open whether a path closure converges.
The weight of a cycle lies within the bound on rounding of the value at which its series stops converging, so the computed numbers cannot tell a convergent closure from a divergent one. No value is returned.
ClosureWork
didactic-model
¶
Bases: Model
The work of one closure, counted in elements of the algebra.
| PARAMETER | DESCRIPTION |
|---|---|
pivots
|
States eliminated.
TYPE:
|
sums
|
Binary sums of elements.
TYPE:
|
products
|
Binary products of elements.
TYPE:
|
exact
|
Operations of the exact or enclosed decision of the loops, which runs only when a loop weight lies within the rounding bound of the boundary: rational updates of an entry, or interval updates of an entry. Zero when no loop entered the band.
TYPE:
|
RealEmbedding
¶
Bases: Carrier
A carrier embedded in the nonnegative reals.
to_reals maps each element to a nonnegative real so that sums and
products are those of the reals and the natural order is that of the
reals, and from_reals maps a real of the image back. A monotone
polynomial system over such a carrier is one over [0, ∞), whose
least fixed point lies in [0, ∞]^n [Etessami and Yannakakis
(2009)]; it can be bounded from both sides in interval arithmetic,
which certifies it, and the solution is in the carrier exactly when
it is finite.
References
Etessami, K., and Yannakakis, M. (2009). Recursive Markov chains, stochastic grammars, and monotone systems of nonlinear equations. Journal of the ACM 56(1), 1-66. doi:10.1145/1462153.1462154
embedding_rounding
abstractmethod
property
¶
Units in the last place each map may be off by in float arithmetic.
| RETURNS | DESCRIPTION |
|---|---|
int
|
Zero for a map computed exactly. |
to_reals
abstractmethod
¶
Star
¶
Bases: UnitalCarrier
A carrier whose square matrices have a closure.
star(A) is the least solution X of X = I ⊕ A X on the
declared domain, the sum I ⊕ A ⊕ A² ⊕ ... of the weights of all
paths, including the empty one [Lehmann (1977)]. Outside the domain
the series has no value and star raises DivergentClosureError;
when rounding cannot decide which side of the boundary a cycle lies
on it raises UndecidedClosureError. The shipped closures eliminate
one state after another, so they cost n³ operations of the
algebra and keep every entry on the autograd graph.
References
Lehmann, D. J. (1977). Algebraic structures for transitive closure. Theoretical Computer Science, 4(1), 59-76. doi:10.1016/0304-3975(77)90056-1
star_domain
abstractmethod
property
¶
The matrices whose closure has a value.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The domain in words. |
star_with_work
abstractmethod
¶
star_with_work(matrix: Tensor) -> tuple[Tensor, ClosureWork]
The closure A* = I ⊕ A ⊕ A² ⊕ ... of a square matrix, and its work.
| PARAMETER | DESCRIPTION |
|---|---|
matrix
|
Shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of (torch.Tensor, ClosureWork)
|
The closure, of the same shape, and the pivots, sums, products and exact operations it took. |
| RAISES | DESCRIPTION |
|---|---|
DivergentClosureError
|
If the matrix lies outside |
UndecidedClosureError
|
If rounding cannot decide whether it lies inside. |
Source code in src/quivers/core/algebras.py
star
¶
The closure A* = I ⊕ A ⊕ A² ⊕ ... of a square matrix.
| PARAMETER | DESCRIPTION |
|---|---|
matrix
|
Shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The closure, of the same shape. |
| RAISES | DESCRIPTION |
|---|---|
DivergentClosureError
|
If the matrix lies outside |
UndecidedClosureError
|
If rounding cannot decide whether it lies inside. |
Source code in src/quivers/core/algebras.py
DualAlgebra
¶
Bases: Algebra
The role-swapped dual of a commutative algebra.
For a t-norm / t-conorm pair (T, S) related by the strong
negation N (S(a, b) = N(T(N(a), N(b)))), the dual
algebra carries the role-swapped pair:
tensor_op^op = base.join (as a binary operation)
join^op = base.tensor_op (folded as a reduction)
meet^op = base.join
unit^op = base.zero
zero^op = base.unit
negate^op = base.negate
Concretely for the built-in pairs:
PRODUCT_FUZZY.dual(): ⊗ = probabilistic sum (a + b - ab), ⋁ = product reduction (∏ a_i).LUKASIEWICZ.dual(): ⊗ = bounded sum (min(1, a + b)), ⋁ = folded Łukasiewicz t-norm.GODEL.dual(): ⊗ = max, ⋁ = min.BOOLEAN.dual(): ⊗ = OR, ⋁ = AND.
The dual of a semiring need not be a semiring: the dual of
PRODUCT_FUZZY composes with identities but not associatively.
The Boolean and Gödel duals are distributive lattices with the
roles of join and meet exchanged, and are returned as the
DualIdempotentSemiring subclass. The carrier is the base's.
| PARAMETER | DESCRIPTION |
|---|---|
base
|
The algebra whose operations are swapped.
TYPE:
|
proof
|
The argument for the dual's laws about the carrier, given by the base that knows it; without one those laws are assumed.
TYPE:
|
Source code in src/quivers/core/algebras.py
base
property
¶
base: Algebra
The underlying algebra this is the dual of.
| RETURNS | DESCRIPTION |
|---|---|
Algebra
|
The base. |
subject
property
¶
subject: ClaimSubject
What the dual's claims are about: the dual of its base.
| RETURNS | DESCRIPTION |
|---|---|
ClaimSubject
|
The qualified class name with the base's name. |
evidence
¶
evidence(law: Law) -> LawEvidence
The evidence for a law: the base's argument for laws about the carrier.
| PARAMETER | DESCRIPTION |
|---|---|
law
|
A law the dual claims.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LawEvidence
|
The argument given at construction, or what the class declares. |
Source code in src/quivers/core/algebras.py
tensor_op
¶
join
¶
The base product folded over axes.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Operands.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The fold, or the base unit over no terms. |
Source code in src/quivers/core/algebras.py
meet
¶
The base join, which the dual uses as its meet.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Operands.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The base join. |
Source code in src/quivers/core/algebras.py
negate
¶
contains
¶
DualIdempotentSemiring
¶
Bases: DualAlgebra, IdempotentSemiring
The dual of a distributive-lattice algebra.
Returned by BooleanAlgebra.dual and GodelAlgebra.dual. Swapping
the join and meet of a distributive lattice yields a distributive
lattice, so the dual is again an idempotent commutative semiring:
max (or OR) distributes over min (or AND), the unit of
max is the bottom and the bottom of the reversed order, the old
top, annihilates max.
The constructor takes the parameters of DualAlgebra, whose
proof should argue that the base is a bounded distributive
lattice under its join and product.
Source code in src/quivers/core/algebras.py
top
property
¶
The greatest element of the join order, the base zero.
| RETURNS | DESCRIPTION |
|---|---|
float
|
The top. |
residuum
¶
[w, x] = 0 if w ≥ x (real order), else x.
The dual order reverses the reals and its tensor is max, so
max(v, w) ≥ x on the reals; its least real solution is
0 when w ≥ x and x otherwise.
| PARAMETER | DESCRIPTION |
|---|---|
w
|
The left argument.
TYPE:
|
x
|
The right argument.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The residuum. |
Source code in src/quivers/core/algebras.py
CustomAlgebra
¶
CustomAlgebra(name: str, tensor_op: Callable[[Tensor, Tensor], Tensor], join: Callable[[Tensor, int | tuple[int, ...]], Tensor], unit: float, zero: float, negate: Callable[[Tensor], Tensor] | None = None, meet: Callable[[Tensor, int | tuple[int, ...]], Tensor] | None = None, verify: bool = True, contains: Callable[[Tensor], Tensor] | None = None)
Bases: Algebra
User-defined algebra built from callable operations.
Construct a fresh algebra from the primitive operations as Python
functions, rather than subclassing Algebra for each variant.
The constructor only stores the operations; the user is
responsible for ensuring they satisfy the algebra axioms
(associativity, identity, distributivity of ⊗ over ⋁,
de-Morgan duality between ⊗ and ⋁ via negate for
involutive lattices), so every law about the carrier is assumed.
Basic structural axioms are sanity-checked at construction time
against a handful of fixed sample inputs. A join over no terms is
the zero whatever join does, and membership is decided by
contains when it is given.
The DSL surface algebra name { tensor_op(a, b) = …;
join(t) = …; unit = …; zero = …; } compiles to this class
under the hood, with verify=False (user expressions are
arithmetic and routinely violate one of the canned samples
used by _sanity_check).
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Human-readable name.
TYPE:
|
tensor_op
|
Binary product.
TYPE:
|
join
|
Reduction along axes, called on nonempty axes only.
TYPE:
|
unit
|
Unit of the product.
TYPE:
|
zero
|
Identity of the join.
TYPE:
|
negate
|
Negation, if any.
TYPE:
|
meet
|
Universal reduction, if any.
TYPE:
|
verify
|
Whether to run the sample checks.
TYPE:
|
contains
|
The carrier's membership predicate, if declared.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/core/algebras.py
tensor_op
¶
join
¶
The given join, or the zero over no terms.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Operands.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The reduction. |
Source code in src/quivers/core/algebras.py
meet
¶
The given meet.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Operands.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The reduction. |
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If no meet was given. |
Source code in src/quivers/core/algebras.py
negate
¶
The given negation.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Operands.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If no negation was given. |
Source code in src/quivers/core/algebras.py
contains
¶
The given membership predicate.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Entries.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Whether each entry is in the carrier. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the entries are complex or no predicate was given. |
Source code in src/quivers/core/algebras.py
CustomSemigroupoid
¶
CustomSemigroupoid(name: str, tensor_op: Callable[[Tensor, Tensor], Tensor], join: Callable[[Tensor, int | tuple[int, ...]], Tensor], verify_associative: bool = True)
Bases: Semigroupoid
User-defined Semigroupoid built from callable operations.
Use for composition rules whose composition is associative but
which lack an identity element, for instance weighted shortest
paths over a semiring without a multiplicative unit. Callers who
want a full algebra (with identity, dagger, compact-closed
structure) should use CustomAlgebra instead. Associativity of
composition is assumed: the optional sample check covers the scalar
product only, which does not suffice for it.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Human-readable name.
TYPE:
|
tensor_op
|
Binary monoidal product.
TYPE:
|
join
|
Reduction along an axis.
TYPE:
|
verify_associative
|
When
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/core/algebras.py
tensor_op
¶
CustomMagmoid
¶
CustomMagmoid(name: str, tensor_op: Callable[[Tensor, Tensor], Tensor], join: Callable[[Tensor, int | tuple[int, ...]], Tensor])
Bases: Magmoid
User-defined Magmoid built from callable operations.
Use for composition rules whose composition is not associative,
for instance signed-dot-product or top-k truncating rules. Callers
must pin an association order explicitly when chaining; the
runtime does not promise that (f >> g) >> h == f >> (g >> h).
No associativity smoke test runs because a magmoid satisfies no law.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Human-readable name.
TYPE:
|
tensor_op
|
Binary product (need not be associative).
TYPE:
|
join
|
Reduction along an axis.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/core/algebras.py
tensor_op
¶
ProductFuzzyAlgebra
¶
Bases: ZeroSumFree, NoZeroDivisors, Algebra
[0,1] with product t-norm and probabilistic sum (noisy-OR).
The product t-norm does not distribute over the probabilistic
sum (0.5 · (0.5 ⊕ 0.5) = 0.375 while
(0.5 · 0.5) ⊕ (0.5 · 0.5) = 0.4375), so this algebra is not a
semiring and composition is unital but not associative: chains of
>> depend on their bracketing. The operations are
⊗ = product: a ⊗ b = a * b
⋁ = noisy-OR: ⋁_i x_i = 1 - ∏_i (1 - x_i)
⋀ = product: ⋀_i x_i = ∏_i x_i
¬ = complement: ¬a = 1 - a
I = 1.0
⊥ = 0.0
A noisy-OR is 0 only when every term is, and a product only when a
factor is, so support is a homomorphism from this algebra. The join
is computed in log space, with each term below 1 - EPS.
tensor_op
¶
join
¶
Noisy-OR in log space: 1 - exp(∑ log(1 - t)).
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Operands in
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The noisy-OR, which is 0 over no terms. |
Source code in src/quivers/core/algebras.py
meet
¶
negate
¶
contains
¶
compose
¶
Composition by a noisy-OR of products, in log space.
| PARAMETER | DESCRIPTION |
|---|---|
m
|
Left tensor of shape
TYPE:
|
n
|
Right tensor of shape
TYPE:
|
n_contract
|
Number of shared axes to contract.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The composite of shape |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/core/algebras.py
BooleanAlgebra
¶
Bases: Selective, Semifield, ZeroSumFree, Star, IdempotentSemiring
{0, 1} with logical AND and OR.
The enrichment for the category Rel of crisp binary relations:
⊗ = AND: a ⊗ b = a ∧ b
⋁ = OR: ⋁_i x_i = max_i x_i
⋀ = AND: ⋀_i x_i = min_i x_i
¬ = NOT: ¬a = 1 - a
I = 1.0
⊥ = 0.0
The join selects an operand (OR of truth values is their maximum), and 1, the only element other than 0, is its own inverse, so the Boolean semiring is a selective semifield.
star_domain
property
¶
Every matrix: no loop is better than the unit.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The domain. |
star_with_work
¶
star_with_work(matrix: Tensor) -> tuple[Tensor, ClosureWork]
The closure by elimination; every loop weight closes to the unit.
| PARAMETER | DESCRIPTION |
|---|---|
matrix
|
Shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of (torch.Tensor, ClosureWork)
|
|
Source code in src/quivers/core/algebras.py
tensor_op
¶
rank
¶
meet
¶
Logical AND as a minimum; true over no terms.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Truth values.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The conjunction. |
Source code in src/quivers/core/algebras.py
negate
¶
divide
¶
a ⊘ 1 = a.
| PARAMETER | DESCRIPTION |
|---|---|
a
|
The dividend.
TYPE:
|
b
|
The divisor, every element true.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
| RAISES | DESCRIPTION |
|---|---|
ZeroDivisionError
|
If an element of |
Source code in src/quivers/core/algebras.py
contains
¶
dual
¶
dual() -> Algebra
The dual algebra, an idempotent commutative semiring.
| RETURNS | DESCRIPTION |
|---|---|
Algebra
|
A |
Source code in src/quivers/core/algebras.py
residuum
¶
[w, x] = ¬w ∨ x, Boolean implication.
| PARAMETER | DESCRIPTION |
|---|---|
w
|
The left argument.
TYPE:
|
x
|
The right argument.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The implication. |
Source code in src/quivers/core/algebras.py
StandardMVAlgebra
¶
Bases: ZeroSumFree, Algebra
The standard MV-algebra on [0, 1].
The standard MV-algebra is [0, 1] with x ⊕ y = min(1, x + y)
and ¬x = 1 - x, the real-valued semantics of Łukasiewicz logic
[Chang (1958); Cignoli, D'Ottaviano and Mundici (2000)]. Its derived
product is the Łukasiewicz t-norm and its lattice meet is min:
⊗ = Łukasiewicz t-norm: a ⊗ b = max(a + b - 1, 0)
⋁ = bounded sum: ⋁_i x_i = min(1, ∑_i x_i)
⋀ = min: ⋀_i x_i = min_i x_i
¬ = strong negation: ¬a = 1 - a
I = 1.0
⊥ = 0.0
The Łukasiewicz t-norm does not distribute over the bounded sum
(0.5 ⊗ (0.5 ⊕ 0.5) = 0.5 while (0.5 ⊗ 0.5) ⊕ (0.5 ⊗ 0.5) = 0),
so this algebra is not a semiring and composition depends on its
bracketing. The product has zero divisors (0.5 ⊗ 0.5 = 0), so
support is not a homomorphism from it. The name follows the
standard terminology: a "Łukasiewicz algebra" in the literature is
Moisil's distinct Łukasiewicz-Moisil algebra.
References
Chang, C. C. (1958). Algebraic analysis of many valued logics. Transactions of the American Mathematical Society, 88(2), 467-490. doi:10.1090/S0002-9947-1958-0094302-9
Cignoli, R. L. O., D'Ottaviano, I. M. L., and Mundici, D. (2000). Algebraic Foundations of Many-Valued Reasoning. Springer. doi:10.1007/978-94-015-9480-6
tensor_op
¶
join
¶
The bounded sum min(1, ∑_i t_i).
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Operands.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The bounded sum, which is 0 over no terms. |
Source code in src/quivers/core/algebras.py
meet
¶
The minimum, which is 1 over no terms.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Operands.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The minimum. |
Source code in src/quivers/core/algebras.py
negate
¶
contains
¶
GodelAlgebra
¶
Bases: Selective, ZeroSumFree, NoZeroDivisors, Star, IdempotentSemiring
[0,1] with Gödel (min) t-norm.
⊗ = min, ⋁ = max, ⋀ = min, ¬ = Gödel neg (1 if a == 0 else 0), I = 1.0, ⊥ = 0.0.
The join selects the larger operand.
star_domain
property
¶
Every matrix: no loop is better than the unit.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The domain. |
star_with_work
¶
star_with_work(matrix: Tensor) -> tuple[Tensor, ClosureWork]
The closure by elimination; every loop weight closes to the unit.
| PARAMETER | DESCRIPTION |
|---|---|
matrix
|
Shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of (torch.Tensor, ClosureWork)
|
|
Source code in src/quivers/core/algebras.py
tensor_op
¶
rank
¶
meet
¶
The minimum; the top over no terms.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Elements.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The minimum. |
Source code in src/quivers/core/algebras.py
negate
¶
contains
¶
dual
¶
dual() -> Algebra
The dual algebra, an idempotent commutative semiring.
| RETURNS | DESCRIPTION |
|---|---|
Algebra
|
A |
Source code in src/quivers/core/algebras.py
residuum
¶
[w, x] = 1 if w ≤ x, else x: the Gödel implication.
| PARAMETER | DESCRIPTION |
|---|---|
w
|
The left argument.
TYPE:
|
x
|
The right argument.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The implication. |
Source code in src/quivers/core/algebras.py
TropicalAlgebra
¶
Bases: Selective, ZeroSumFree, NoZeroDivisors, Star, IdempotentSemiring
[0, ∞] with (+, min), the enrichment of Lawvere metric spaces.
⊗ = addition (distances compose),
⋁ = infimum (shortest path),
⋀ = supremum (longest path),
I = 0.0, ⊥ = ∞.
Composition is the tropical / (min, +) matrix product. The join selects the smaller operand. Negation is undefined. The carrier has no negative numbers, so an element other than 0 has no inverse and the algebra is not a semifield.
star_domain
property
¶
Every matrix: no distance is shorter than zero.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The domain. |
star_with_work
¶
star_with_work(matrix: Tensor) -> tuple[Tensor, ClosureWork]
The closure by elimination; every loop weight closes to the unit.
| PARAMETER | DESCRIPTION |
|---|---|
matrix
|
Shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of (torch.Tensor, ClosureWork)
|
|
Source code in src/quivers/core/algebras.py
tensor_op
¶
rank
¶
meet
¶
The supremum of distances; the top 0 over no terms.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Distances.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The maximum. |
Source code in src/quivers/core/algebras.py
negate
¶
Refuse: negation is not defined here.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Distances.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Never returns. |
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
Always. |
Source code in src/quivers/core/algebras.py
contains
¶
residuum
¶
[w, x] = max(x - w, 0), truncated subtraction.
The order reverses the reals (a ≤ b ⟺ min(a, b) = b), so
v + w ≤ x there means v + w ≥ x on the reals, whose
least real solution is max(x - w, 0); w = ∞ gives 0.
| PARAMETER | DESCRIPTION |
|---|---|
w
|
The left argument.
TYPE:
|
x
|
The right argument.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The residuum. |
Source code in src/quivers/core/algebras.py
MaxPlusAlgebra
¶
Bases: Selective, Semifield, ZeroSumFree, Star, IdempotentSemiring
Max-plus (Viterbi) semifield on ℝ ∪ {-∞}.
Distinct from TropicalAlgebra (which is min-plus,
suited to shortest-path aggregations): the join here is max
and the tensor is +. The canonical algebra for MAP decoding
in HMMs, CRFs, and weighted automata.
⊗ = +, ⋁ = max, ⋀ = min,
I = 0, ⊥ = -∞.
The join selects the larger operand, and every finite score a
has the inverse -a. top and the residuum live in the
completion ℝ ∪ {±∞}; +∞ is not in the semiring's carrier,
where -∞ must annihilate.
star_domain
property
¶
The matrices without a cycle of positive score.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The domain. |
top
property
¶
The greatest element of the completed order.
| RETURNS | DESCRIPTION |
|---|---|
float
|
|
star_with_work
¶
star_with_work(matrix: Tensor) -> tuple[Tensor, ClosureWork]
The best path scores, by elimination with a decided loop test.
A computed loop score above the rounding bound of its path proves a positive cycle, and one below minus the bound proves the loop is not positive. In between, the sign of the exact sum of the float64 or float32 weights decides: the cycles are tested in exact rational arithmetic on the given weights.
| PARAMETER | DESCRIPTION |
|---|---|
matrix
|
Shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of (torch.Tensor, ClosureWork)
|
|
| RAISES | DESCRIPTION |
|---|---|
DivergentClosureError
|
If a cycle has positive score. |
Source code in src/quivers/core/algebras.py
4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 | |
tensor_op
¶
rank
¶
meet
¶
The minimum; the top +∞ of the completion over no terms.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Scores.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The minimum. |
Source code in src/quivers/core/algebras.py
negate
¶
Refuse: negation is not defined here.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Scores.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Never returns. |
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
Always. |
Source code in src/quivers/core/algebras.py
divide
¶
The quotient a - b.
| PARAMETER | DESCRIPTION |
|---|---|
a
|
The dividend.
TYPE:
|
b
|
The divisor, every element finite.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
| RAISES | DESCRIPTION |
|---|---|
ZeroDivisionError
|
If an element of |
Source code in src/quivers/core/algebras.py
contains
¶
residuum
¶
[w, x] = x - w, with [-∞, x] = +∞ and [w, +∞] = +∞.
| PARAMETER | DESCRIPTION |
|---|---|
w
|
The left argument.
TYPE:
|
x
|
The right argument.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The residuum. |
Source code in src/quivers/core/algebras.py
LogProbAlgebra
¶
Bases: Semifield, ZeroSumFree, Star, RealEmbedding, Semiring
Log-space sum-product semifield on [-∞, ∞).
Tensor is real addition (probability multiplication in log-
space) and join is torch.logsumexp (probability
summation in log-space). exp is an isomorphism onto the
probability semiring ([0, ∞), +, ·), so the carrier must
contain positive values: logsumexp(0, 0) = log 2. The join is
not idempotent, so this is a semiring and not a lattice. Division
is subtraction of log weights.
⊗ = +, ⋁ = logsumexp, ⋀ = min,
I = 0 (log 1), ⊥ = -∞ (log 0).
A join of terms that are all -∞ is -∞ with derivative zero:
the log of a sum of absent alternatives is -∞ near them, so no
mass moves. The binary sum agrees with the join over the pair in
value and in first and second derivatives at every point; its
derivative is not torch.logaddexp's, whose second derivative is
not a number at an operand -∞. The meet has no value over no terms, since the carrier
has no greatest element.
embedding_rounding
property
¶
The rounding of exp and log that the certificates assume.
| RETURNS | DESCRIPTION |
|---|---|
int
|
Two units in the last place; the law grid checks it on its samples against arithmetic in fifty digits. |
star_domain
property
¶
The matrices of probabilities whose spectral radius is below one.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The domain. |
to_reals
¶
from_reals
¶
star_with_work
¶
star_with_work(matrix: Tensor) -> tuple[Tensor, ClosureWork]
The log of (I - A)⁻¹, by elimination of states in log space.
| PARAMETER | DESCRIPTION |
|---|---|
matrix
|
Shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of (torch.Tensor, ClosureWork)
|
Log weights of all paths, including empty paths, and the work. |
| RAISES | DESCRIPTION |
|---|---|
DivergentClosureError
|
If an effective return weight is at least one. |
UndecidedClosureError
|
If convergence or a usable pivot cannot be established in the working precision. |
ValueError
|
If the matrix contains NaN or positive infinity. |
Source code in src/quivers/core/algebras.py
4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 | |
tensor_op
¶
join
¶
The log of a sum of exponentials, stable and with zero masked.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Log weights.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The reduction with the named axes removed. A reduction over
no terms, or over terms that are all |
Source code in src/quivers/core/algebras.py
join_pair
¶
The binary sum log(e^a + e^b), equal to join over the pair.
| PARAMETER | DESCRIPTION |
|---|---|
a
|
The first log weight.
TYPE:
|
b
|
The second log weight, broadcastable with
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The sum. It agrees with |
Source code in src/quivers/core/algebras.py
meet
¶
The minimum, refused over no terms.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Log weights.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The minimum. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a reduced axis has size zero. |
Source code in src/quivers/core/algebras.py
negate
¶
Refuse: negation is not defined here.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Log weights.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Never returns. |
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
Always. |
Source code in src/quivers/core/algebras.py
divide
¶
The quotient a - b of log weights.
| PARAMETER | DESCRIPTION |
|---|---|
a
|
The dividend.
TYPE:
|
b
|
The divisor, every element finite.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
| RAISES | DESCRIPTION |
|---|---|
ZeroDivisionError
|
If an element of |
Source code in src/quivers/core/algebras.py
RealAlgebra
¶
Bases: Semifield, Ring, Semiring
The field of real numbers (ℝ, +, ·).
The canonical numeric semiring: addition is the semiring sum (not a lattice join, since it is not idempotent), multiplication the tensor. Use when entries are unbounded real weights with no probability interpretation. Subtraction and division are available, and sums may cancel, so support is not a homomorphism from it.
tensor_op
¶
join
¶
The sum over axes.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Operands.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The sum, which is 0 over no terms. |
Source code in src/quivers/core/algebras.py
meet
¶
The minimum, refused over no terms.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Operands.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The minimum. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a reduced axis has size zero. |
Source code in src/quivers/core/algebras.py
negate
¶
subtract
¶
divide
¶
The quotient a / b.
| PARAMETER | DESCRIPTION |
|---|---|
a
|
The dividend.
TYPE:
|
b
|
The divisor, with no zero element.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
| RAISES | DESCRIPTION |
|---|---|
ZeroDivisionError
|
If an element of |
Source code in src/quivers/core/algebras.py
BoundedSumProductAlgebra
¶
Bases: ZeroSumFree, NoZeroDivisors, Algebra
[0, 1] with the product t-norm and the bounded sum.
The tensor is the product t-norm a · b and the join is the
bounded sum min(1, ∑_i x_i), the Łukasiewicz t-conorm
[Klement, Mesiar and Pap (2000)]. Truncating the sum at 1 breaks
distributivity (0.5 · min(1, 1 + 1) = 0.5 while
min(1, 0.5 + 0.5) over the products is 1), so this algebra is
not a semiring and composition depends on its bracketing. The
probability semiring ([0, ∞), +, ·) is MarkovAlgebra; this class
is not a probability algebra in the measure-theoretic sense (a
Boolean algebra carrying a measure) either.
References
Klement, E. P., Mesiar, R., and Pap, E. (2000). Triangular Norms. Springer. doi:10.1007/978-94-015-9540-7
tensor_op
¶
join
¶
The bounded sum min(1, ∑_i t_i).
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Operands.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The bounded sum, which is 0 over no terms. |
Source code in src/quivers/core/algebras.py
meet
¶
The minimum, which is 1 over no terms.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Operands.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The minimum. |
Source code in src/quivers/core/algebras.py
negate
¶
CountingAlgebra
¶
Bases: ZeroSumFree, NoZeroDivisors, Star, Semiring
Sum-product semiring on the non-negative integers (ℕ, +, ·).
Counting algebra: composition counts the number of distinct paths
through a structure. Tensors may be floating (autograd requires
it) or integer; either way the entries must be natural numbers. The
naturals have no inverses, so this is not a semifield; the
nonnegative reals are MarkovAlgebra.
star_domain
property
¶
The matrices of counts without a cycle.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The domain. |
star_with_work
¶
star_with_work(matrix: Tensor) -> tuple[Tensor, ClosureWork]
The number of paths, by elimination of states.
Counts below 2 / eps of the dtype are exact in floating point and elimination only adds and multiplies them, so
a loop count is decided exactly.
| PARAMETER | DESCRIPTION |
|---|---|
matrix
|
Shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of (torch.Tensor, ClosureWork)
|
|
| RAISES | DESCRIPTION |
|---|---|
DivergentClosureError
|
If a cycle has a nonzero count. |
UndecidedClosureError
|
If a count reaches |
Source code in src/quivers/core/algebras.py
tensor_op
¶
join
¶
The sum of counts.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Counts.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The sum, which is 0 over no terms. |
Source code in src/quivers/core/algebras.py
meet
¶
The minimum, refused over no terms.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Counts.
TYPE:
|
dim
|
Axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The minimum. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a reduced axis has size zero. |
Source code in src/quivers/core/algebras.py
negate
¶
Refuse: negation is not defined here.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Counts.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Never returns. |
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
Always. |
Source code in src/quivers/core/algebras.py
contains
¶
Membership in ℕ.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Entries.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Whether each entry is a finite nonnegative integer. |
Source code in src/quivers/core/algebras.py
MarkovAlgebra
¶
Bases: Semifield, ZeroSumFree, Star, RealEmbedding, Semiring
Sum-product composition for stochastic matrices.
Implements the composition rule of FinStoch:
(g ∘ f)(a, c) = Σ_b f(a, b) · g(b, c)
standard matrix multiplication on row-stochastic matrices. Formally:
⊗ = product, ⋁ = sum, ⋀ = product,
¬ = complement (1 - p),
I = 1.0, ⊥ = 0.0.
The operations form the probability semifield ([0, ∞), +, ·);
its sum is not idempotent, so it is a semiring and not a lattice.
Composition is ordinary matrix multiplication, and the composite
of row-stochastic matrices is row-stochastic.
embedding_rounding
property
¶
The rounding of the identity.
| RETURNS | DESCRIPTION |
|---|---|
int
|
Zero. |
star_domain
property
¶
The nonnegative matrices of spectral radius below one.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The domain. |
to_reals
¶
from_reals
¶
star_with_work
¶
star_with_work(matrix: Tensor) -> tuple[Tensor, ClosureWork]
(I - A)⁻¹ by elimination of states, without subtraction.
| PARAMETER | DESCRIPTION |
|---|---|
matrix
|
Shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of (torch.Tensor, ClosureWork)
|
|
| RAISES | DESCRIPTION |
|---|---|
DivergentClosureError
|
If the spectral radius is at least one. |
UndecidedClosureError
|
If a loop weight is within the rounding bound of one. |
Source code in src/quivers/core/algebras.py
tensor_op
¶
join
¶
meet
¶
negate
¶
divide
¶
The quotient a / b.
| PARAMETER | DESCRIPTION |
|---|---|
a
|
The dividend.
TYPE:
|
b
|
The divisor, with no zero element.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
| RAISES | DESCRIPTION |
|---|---|
ZeroDivisionError
|
If an element of |
Source code in src/quivers/core/algebras.py
MatrixSemiring
¶
MatrixSemiring(base: OrderPreservingSemiring, size: int)
Bases: OrderPreservingSemiring
Square matrices over a scalar semiring, a semiring that does not commute.
An element is an n × n matrix over base. The sum is the
entrywise sum, the product the matrix product of base, the zero
the zero matrix, and the unit the identity matrix. Matrices over a
semiring form a semiring [Golan (1999)], and for
n ≥ 2 its product does not commute, so a computation over these
weights has to keep the order of its factors.
| PARAMETER | DESCRIPTION |
|---|---|
base
|
The scalar semiring of the entries.
TYPE:
|
size
|
The order
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
References
Golan, J. S. (1999). Semirings and their Applications. Springer. doi:10.1007/978-94-015-9333-5
Source code in src/quivers/core/algebras.py
base
property
¶
base: OrderPreservingSemiring
The scalar semiring of the entries.
| RETURNS | DESCRIPTION |
|---|---|
OrderPreservingSemiring
|
The base. |
element_shape
property
¶
(n, n).
| RETURNS | DESCRIPTION |
|---|---|
tuple of int
|
The shape of one matrix. |
subject
property
¶
subject: ClaimSubject
What the claims are about: the construction over its base.
| RETURNS | DESCRIPTION |
|---|---|
ClaimSubject
|
The qualified class name with the structure's name. |
evidence
¶
evidence(law: Law) -> LawEvidence
The evidence for a law; laws about the carrier hold by a theorem.
| PARAMETER | DESCRIPTION |
|---|---|
law
|
A law the structure claims.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LawEvidence
|
The theorem's argument when the base's laws are established. |
Source code in src/quivers/core/algebras.py
tensor_op
¶
The matrix product a b over the base, a on the left.
| PARAMETER | DESCRIPTION |
|---|---|
a
|
Left matrices.
TYPE:
|
b
|
Right matrices, broadcastable over index axes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If an operand lacks the matrix axes. |
Source code in src/quivers/core/algebras.py
join
¶
The entrywise sum over index axes.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Matrices.
TYPE:
|
dim
|
Index axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The sum, which is the zero matrix over no terms. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/core/algebras.py
zero_like
¶
The zero matrix at every index.
| PARAMETER | DESCRIPTION |
|---|---|
shape
|
The index shape.
TYPE:
|
like
|
The tensor whose dtype and device are used.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Shape |
Source code in src/quivers/core/algebras.py
unit_like
¶
The identity matrix at every index.
| PARAMETER | DESCRIPTION |
|---|---|
shape
|
The index shape.
TYPE:
|
like
|
The tensor whose dtype and device are used.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Shape |
Source code in src/quivers/core/algebras.py
contains
¶
Whether every entry of each matrix is in the base carrier.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Matrices.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
One truth value per matrix. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/core/algebras.py
StarMatrixSemiring
¶
StarMatrixSemiring(base: OrderPreservingSemiring, size: int)
Bases: MatrixSemiring, Star
Square matrices over a semiring with a closure, closed as one flat matrix.
MatrixSemiring returns this class when its base is a Star. An
n × n matrix A whose entries are k × k matrices is the
nk × nk matrix φ(A)[(i, a), (j, b)] = A[i, j][a, b] of the
base, and φ is an isomorphism of semirings from M_n(M_k(S))
onto M_nk(S). The closure of A is therefore
φ⁻¹(star(φ(A))): it exists exactly when the base's closure of the
flat matrix does, and it is the least solution of X = I ⊕ A X
because φ maps solutions to solutions and preserves the order of
sums. This is the first closure whose product does not commute; it
solves both X = I ⊕ A X and X = I ⊕ X A.
| PARAMETER | DESCRIPTION |
|---|---|
base
|
The scalar semiring of the entries, which has a closure.
TYPE:
|
size
|
The order
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the base has no closure. |
Source code in src/quivers/core/algebras.py
star_domain
property
¶
The matrices whose flat matrix lies in the base's closure domain.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The domain. |
star_with_work
¶
star_with_work(matrix: Tensor) -> tuple[Tensor, ClosureWork]
The closure of a matrix of blocks, through its flat matrix.
| PARAMETER | DESCRIPTION |
|---|---|
matrix
|
Shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of (torch.Tensor, ClosureWork)
|
|
| RAISES | DESCRIPTION |
|---|---|
DivergentClosureError
|
If the base's closure of the flat matrix diverges. |
UndecidedClosureError
|
If rounding cannot decide it. |
ValueError
|
If the matrix is not square in its blocks. |
Source code in src/quivers/core/algebras.py
FreeSemimodule
¶
FreeSemimodule(scalars: OrderPreservingSemiring, size: int)
Bases: Semimodule
Vectors of a fixed length over an order-preserving semiring.
An element is a vector of n scalars. The sum is entrywise, the
zero is the zero vector, and a scalar acts on the left of every
entry. These operations make K^n a left semimodule over K
[Golan (1999)].
| PARAMETER | DESCRIPTION |
|---|---|
scalars
|
The semiring that acts.
TYPE:
|
size
|
The length
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
References
Golan, J. S. (1999). Semirings and their Applications. Springer. doi:10.1007/978-94-015-9333-5
Source code in src/quivers/core/algebras.py
scalars
property
¶
scalars: OrderPreservingSemiring
The semiring that acts.
| RETURNS | DESCRIPTION |
|---|---|
OrderPreservingSemiring
|
The scalars. |
element_shape
property
¶
(n, *scalars.element_shape).
| RETURNS | DESCRIPTION |
|---|---|
tuple of int
|
The shape of one vector. |
subject
property
¶
subject: ClaimSubject
What the claims are about: the construction over its base.
| RETURNS | DESCRIPTION |
|---|---|
ClaimSubject
|
The qualified class name with the structure's name. |
evidence
¶
evidence(law: Law) -> LawEvidence
The evidence for a law; laws about the carrier hold by a theorem.
| PARAMETER | DESCRIPTION |
|---|---|
law
|
A law the structure claims.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LawEvidence
|
The theorem's argument when the base's laws are established. |
Source code in src/quivers/core/algebras.py
join
¶
The entrywise sum over index axes.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Vectors.
TYPE:
|
dim
|
Index axes to reduce.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The sum, which is the zero vector over no terms. |
Source code in src/quivers/core/algebras.py
act
¶
The scalar k on the left of every entry of m.
| PARAMETER | DESCRIPTION |
|---|---|
k
|
Scalars, with the scalars' element axes trailing.
TYPE:
|
m
|
Vectors.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
Source code in src/quivers/core/algebras.py
zero_like
¶
The zero vector at every index.
| PARAMETER | DESCRIPTION |
|---|---|
shape
|
The index shape.
TYPE:
|
like
|
The tensor whose dtype and device are used.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Shape |
Source code in src/quivers/core/algebras.py
semigroupoid
¶
semigroupoid(name: str, tensor_op: Callable[[Tensor, Tensor], Tensor], join: Callable[[Tensor, int | tuple[int, ...]], Tensor], *, verify_associative: bool = True) -> CustomSemigroupoid
Convenience constructor for CustomSemigroupoid.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Human-readable name.
TYPE:
|
tensor_op
|
Binary monoidal product.
TYPE:
|
join
|
Reduction along an axis.
TYPE:
|
verify_associative
|
When
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CustomSemigroupoid
|
The composition rule built from the callables. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/core/algebras.py
magmoid
¶
magmoid(name: str, tensor_op: Callable[[Tensor, Tensor], Tensor], join: Callable[[Tensor, int | tuple[int, ...]], Tensor]) -> CustomMagmoid
Convenience constructor for CustomMagmoid.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Human-readable name.
TYPE:
|
tensor_op
|
Binary product, which need not be associative.
TYPE:
|
join
|
Reduction along an axis.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CustomMagmoid
|
The composition rule built from the callables. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/core/algebras.py
material_implication
¶
material_implication() -> CustomMagmoid
Reichenbach material-implication composition as a Magmoid.
The tensor product is the Reichenbach implication
a → b = 1 - a + a*b and the join is the product reduction, so
(f >> g)[i, k] = ∏_j (1 - f[i, j] + f[i, j] g[j, k]). Neither
the scalar implication nor this composition is associative, and
no element is a two-sided identity, so the rule is a magmoid.
| RETURNS | DESCRIPTION |
|---|---|
CustomMagmoid
|
The material-implication composition rule. |
Source code in src/quivers/core/algebras.py
The algebra singletons, such as PRODUCT_FUZZY, are documented on the
core overview.
Cited sources¶
Joshua Goodman. Semiring Parsing. Computational Linguistics, 25(4):573–606, 1999. URL: https://aclanthology.org/J99-4004/.
Mehryar Mohri. Semiring Frameworks and Algorithms for Shortest-Distance Problems. Journal of Automata, Languages and Combinatorics, 7(3):321–350, 2002. doi:10.25596/jalc-2002-321.
Erich Peter Klement, Radko Mesiar, and Endre Pap. Triangular Norms. Trends in Logic. Springer, 2000. doi:10.1007/978-94-015-9540-7.
G. M. Kelly. Basic Concepts of Enriched Category Theory. Cambridge University Press, 1982. Reprinted in Reprints in Theory and Applications of Categories 10 (2005), 1–136. URL: https://www.tac.mta.ca/tac/reprints/articles/10/tr10abs.html.