Traced Monoidal¶
A trace feeds an output component of a
morphism back into a matching input component (Joyal et al., 1996). On finite tensors,
CompactClosedTrace identifies the two axes and reduces the diagonal
with the Algebra's \(\oplus\). It is the trace that compact closure induces, and it satisfies the
trace axioms when the Algebra is a Semiring, which its constructor requires. The module also
gives the trace and partial_trace functions.
KleeneStarTrace takes coproducts
as its monoidal product and sums paths through a feedback block. It is a
partial trace: its method is
defined only when the entire feedback closure is finite
(Malherbe et al., 2012). It accepts a semiring by its capability: any
Semiring with a Star that establishes the
least-solution law, which includes the Boolean, Gödel, tropical, max-plus, log,
counting, and Markov semirings. Matrices are float32 or float64 in the
algebra's carrier. An undefined closure raises
DivergentClosureError,
and a loop that rounding cannot decide raises
UndecidedClosureError.
traced
¶
Traced monoidal categories and the canonical trace of V-relations.
A traced monoidal category is a symmetric monoidal category (C, ⊗, I) equipped with a trace operator
Tr^U_{A,B}: C(A ⊗ U, B ⊗ U) → C(A, B)
satisfying naturality, dinaturality, vanishing, superposing, and yanking [Joyal, Street and Verity (1996)].
V-valued matrices with the monoidal structure given by the cartesian product of sets form a compact closed category when V is a commutative semiring, and every compact closed category has a canonical trace,
Tr^U(f) = (id_B ⊗ ε_U) ∘ (f ⊗ id_U) ∘ (id_A ⊗ η_U),
which for V-matrices is the sum over the feedback variable:
Tr^U(f)(a, b) = ⋁_u f((a, u), (b, u)).
For Boolean relations this is the existential trace of Rel, and for
real matrices the partial trace. The trace axioms need V to be a
Semiring, so the classes and functions here require one.
This module provides:
TracedMonoidal (abstract)
└── CompactClosedTrace — the canonical trace of V-matrices
trace() — apply the trace operator
partial_trace() — trace over a subset of feedback wires
KleeneStarTrace — partial coproduct trace from finite path closure
References
Joyal, A., Street, R., and Verity, D. (1996). Traced monoidal categories. Mathematical Proceedings of the Cambridge Philosophical Society, 119(3), 447-468. doi:10.1017/S0305004100074338
DivergentClosureError
¶
Bases: ValueError
A path closure has no value in the declared carrier.
KleeneStarTrace
¶
KleeneStarTrace(algebra: Semiring)
Partial trace of matrices under coproduct, defined by path closure.
For a matrix f: A + U -> B + U in row-to-column convention,
the result is f_AB + f_AU (f_UU)* f_UB, with addition and
multiplication taken in the declared semiring. The star includes
paths of every finite length, including the empty path.
Boolean, Gödel and tropical closures are always finite. Counting closure is finite on acyclic feedback graphs. Markov and log-probability closure require spectral radius below one in the nonnegative representation. Max-plus closure excludes positive cycles. Divergent feedback is undefined even when no external path reaches that component.
Nonnegative path sums can be regrouped without cancellation. This
gives the partial trace axioms, including the definedness condition
for nested feedback. Signed real matrices are excluded: convergence
of an individual feedback block does not establish those axioms on
the signed matrix category. This partial operator is independent of
the total cartesian TracedMonoidal interface.
The algebra is accepted by its capability: it must be a Semiring
with a Star whose least-solution law it establishes (see
quivers.core.laws.Lawful.establishes), so a subclass that replaces
an operation without its own argument is refused. The shipped
members are the Boolean, Gödel, tropical, max-plus, log, counting
and Markov semirings.
| PARAMETER | DESCRIPTION |
|---|---|
algebra
|
A semiring that establishes the closure law.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the algebra has no established closure. |
References
Malherbe, O., Scott, P. J., and Selinger, P. (2012). Partially traced categories. Journal of Pure and Applied Algebra, 216(12), 2563-2585. DOI: 10.1016/j.jpaa.2012.03.026. Definition 3.2 gives the partial trace axioms; Proposition 3.10 gives the obstruction for a convergence-based star on signed real matrices.
Source code in src/quivers/categorical/traced.py
algebra
property
¶
algebra: Semiring
The semiring whose finite path weights are combined.
| RETURNS | DESCRIPTION |
|---|---|
Semiring
|
The algebra. |
monoidal
property
¶
monoidal: CoproductMonoidal
The coproduct monoidal structure used by this partial trace.
| RETURNS | DESCRIPTION |
|---|---|
CoproductMonoidal
|
The structure. |
trace
¶
trace(morph: Morphism, feedback: SetObject, domain: SetObject, codomain: SetObject) -> ObservedMorphism
Sum all paths through the feedback block when its closure is finite.
| PARAMETER | DESCRIPTION |
|---|---|
morph
|
Matrix
TYPE:
|
feedback
|
Feedback object
TYPE:
|
domain
|
External domain
TYPE:
|
codomain
|
External codomain
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ObservedMorphism
|
Matrix |
| RAISES | DESCRIPTION |
|---|---|
DivergentClosureError
|
If the feedback closure has no finite value. |
TypeError
|
If the input tensor is not float32 or float64. |
ValueError
|
If objects, algebra, tensor shape, or carrier values disagree, or a finite mathematical result exceeds the numeric carrier. |
Source code in src/quivers/categorical/traced.py
verify_yanking
¶
verify_yanking(feedback: SetObject, atol: float = 1e-06) -> bool
Check that tracing the coproduct swap returns the identity.
| PARAMETER | DESCRIPTION |
|---|---|
feedback
|
Object whose swap is traced.
TYPE:
|
atol
|
Absolute comparison tolerance, with zero relative tolerance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether the yanking equation holds. |
Source code in src/quivers/categorical/traced.py
__repr__
¶
Identify the semiring used for coproduct feedback.
| RETURNS | DESCRIPTION |
|---|---|
str
|
Constructor name and declared algebra. |
TracedMonoidal
¶
TracedMonoidal(monoidal: MonoidalStructure, algebra: Semiring)
Bases: ABC
Abstract traced monoidal category.
Provides the trace operator Tr^U_{A,B} on a monoidal structure.
| PARAMETER | DESCRIPTION |
|---|---|
monoidal
|
The underlying monoidal structure.
TYPE:
|
algebra
|
The enrichment algebra.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
Source code in src/quivers/categorical/traced.py
monoidal
property
¶
monoidal: MonoidalStructure
The underlying monoidal structure.
| RETURNS | DESCRIPTION |
|---|---|
MonoidalStructure
|
The structure. |
algebra
property
¶
algebra: Semiring
The enrichment algebra.
| RETURNS | DESCRIPTION |
|---|---|
Semiring
|
The algebra. |
trace
abstractmethod
¶
Apply the trace operator.
Given f: A ⊗ U → B ⊗ U, compute Tr^U(f): A → B.
| PARAMETER | DESCRIPTION |
|---|---|
morph
|
The morphism f: A ⊗ U → B ⊗ U.
TYPE:
|
feedback
|
The feedback object U.
TYPE:
|
domain
|
The external domain A.
TYPE:
|
codomain
|
The external codomain B.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Morphism
|
The traced morphism Tr^U(f): A → B. |
Source code in src/quivers/categorical/traced.py
verify_yanking
¶
verify_yanking(feedback: SetObject, atol: float = 1e-05) -> bool
Verify the yanking axiom: Tr^U(σ_{U,U}) = id_U.
The trace of the braiding/swap should be the identity.
| PARAMETER | DESCRIPTION |
|---|---|
feedback
|
The object U to test.
TYPE:
|
atol
|
Absolute tolerance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if yanking holds within tolerance. |
Source code in src/quivers/categorical/traced.py
__repr__
¶
The class and its monoidal structure.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The representation. |
CompactClosedTrace
¶
CompactClosedTrace(algebra: Semiring)
Bases: TracedMonoidal
The canonical trace of V-matrices under the cartesian product of sets.
For a morphism f: A × U → B × U,
Tr^U(f)(a, b) = ⋁_u f((a, u), (b, u)),
the join over the feedback dimensions of the tensor's diagonal
(where the U components of domain and codomain agree). It is the
trace that compact closure induces, and it satisfies the trace
axioms when the algebra is a Semiring.
| PARAMETER | DESCRIPTION |
|---|---|
algebra
|
The enrichment algebra.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
Source code in src/quivers/categorical/traced.py
trace
¶
Compute the cartesian trace via diagonal extraction and join.
| PARAMETER | DESCRIPTION |
|---|---|
morph
|
f: A × U → B × U.
TYPE:
|
feedback
|
The feedback object U.
TYPE:
|
domain
|
The external domain A.
TYPE:
|
codomain
|
The external codomain B.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ObservedMorphism
|
Tr^U(f): A → B. |
Source code in src/quivers/categorical/traced.py
trace
¶
trace(morph: Morphism, feedback: SetObject, domain: SetObject, codomain: SetObject, algebra: Algebra | None = None) -> Morphism
Apply the canonical trace CompactClosedTrace.
Given f: A × U → B × U, compute Tr^U(f): A → B using the CompactClosedTrace.
| PARAMETER | DESCRIPTION |
|---|---|
morph
|
The morphism f: A × U → B × U.
TYPE:
|
feedback
|
The feedback object U.
TYPE:
|
domain
|
The external domain A.
TYPE:
|
codomain
|
The external codomain B.
TYPE:
|
algebra
|
The enrichment algebra, a
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Morphism
|
The traced morphism Tr^U(f): A → B. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the algebra is not a |
Source code in src/quivers/categorical/traced.py
partial_trace
¶
partial_trace(morph: Morphism, feedback_indices: tuple[int, ...], algebra: Algebra | None = None) -> Morphism
Trace over a subset of feedback wires in a product.
Given f: (A₁ × ... × Aₙ) → (B₁ × ... × Bₙ) where some pairs (Aᵢ, Bᵢ) are feedback wires (Aᵢ = Bᵢ), compute the partial trace over the specified pairs.
| PARAMETER | DESCRIPTION |
|---|---|
morph
|
The morphism.
TYPE:
|
feedback_indices
|
Indices of the product components to trace over. These components must have matching shapes in domain and codomain.
TYPE:
|
algebra
|
The enrichment algebra, a
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ObservedMorphism
|
The partially traced morphism. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the algebra is not a |
ValueError
|
If the domain and codomain differ in their number of components or in a traced component. |
Source code in src/quivers/categorical/traced.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 | |
Cited sources¶
André Joyal, Ross Street, and Dominic Verity. Traced Monoidal Categories. Mathematical Proceedings of the Cambridge Philosophical Society, 119(3):447–468, 1996. URL: https://www.cambridge.org/core/journals/mathematical-proceedings-of-the-cambridge-philosophical-society/article/abs/traced-monoidal-categories/2BE85628D269D9FABAB41B6364E117C8, doi:10.1017/S0305004100074338.
Octavio Malherbe, Philip J. Scott, and Peter Selinger. Partially traced categories. Journal of Pure and Applied Algebra, 216(12):2563–2585, 2012. URL: https://doi.org/10.1016/j.jpaa.2012.03.026, doi:10.1016/j.jpaa.2012.03.026.