Skip to content

Monoidal Structures

A monoidal structure combines objects and morphisms side by side (Mac Lane, 1998). The cartesian product pairs values, and the coproduct selects a tagged alternative. Associators regroup nested combinations and braidings exchange their order. These operations arrange inputs and outputs, and the chosen Algebra separately fixes how their weights combine. The module gives the MonoidalStructure interface with the instances CartesianProductMonoidal and CoproductMonoidal. On weighted relations the Cartesian product is a symmetric monoidal product, not a categorical product.

monoidal

Monoidal structures on V-enriched FinSet.

A monoidal structure (C, ⊗, I) consists of a bifunctor ⊗, a unit object I, and coherence isomorphisms (associator, unitors, braiding).

This module provides:

MonoidalStructure (abstract)
├── CartesianProductMonoidal  — (FinSet, ×, 1)
└── CoproductMonoidal  — (FinSet, +, ∅)

On finite sets and functions the cartesian product is a categorical product, but the morphisms here are V-valued matrices, on which × is a symmetric tensor product and not a product: V-matrices have no natural diagonals. The disjoint union + is a biproduct of V-matrices over a semiring.

MonoidalStructure

Bases: ABC

Abstract monoidal structure on a category.

Provides the monoidal product, unit object, and coherence isomorphisms that witness the monoidal laws.

unit abstractmethod property

unit: SetObject

The monoidal unit I.

product abstractmethod

product(a: SetObject, b: SetObject) -> SetObject

The monoidal product A ⊗ B.

PARAMETER DESCRIPTION
a

Left object.

TYPE: SetObject

b

Right object.

TYPE: SetObject

RETURNS DESCRIPTION
SetObject

The product object.

Source code in src/quivers/categorical/monoidal.py
@abstractmethod
def product(self, a: SetObject, b: SetObject) -> SetObject:
    """The monoidal product A ⊗ B.

    Parameters
    ----------
    a : SetObject
        Left object.
    b : SetObject
        Right object.

    Returns
    -------
    SetObject
        The product object.
    """
    ...

associator abstractmethod

associator(a: SetObject, b: SetObject, c: SetObject) -> ObservedMorphism

The associator (A ⊗ B) ⊗ C → A ⊗ (B ⊗ C).

PARAMETER DESCRIPTION
a

Three objects.

TYPE: SetObject

b

Three objects.

TYPE: SetObject

c

Three objects.

TYPE: SetObject

RETURNS DESCRIPTION
ObservedMorphism

The associator isomorphism.

Source code in src/quivers/categorical/monoidal.py
@abstractmethod
def associator(self, a: SetObject, b: SetObject, c: SetObject) -> ObservedMorphism:
    """The associator (A ⊗ B) ⊗ C → A ⊗ (B ⊗ C).

    Parameters
    ----------
    a, b, c : SetObject
        Three objects.

    Returns
    -------
    ObservedMorphism
        The associator isomorphism.
    """
    ...

left_unitor abstractmethod

left_unitor(a: SetObject) -> ObservedMorphism

The left unitor I ⊗ A → A.

PARAMETER DESCRIPTION
a

The object.

TYPE: SetObject

RETURNS DESCRIPTION
ObservedMorphism

The left unitor isomorphism.

Source code in src/quivers/categorical/monoidal.py
@abstractmethod
def left_unitor(self, a: SetObject) -> ObservedMorphism:
    """The left unitor I ⊗ A → A.

    Parameters
    ----------
    a : SetObject
        The object.

    Returns
    -------
    ObservedMorphism
        The left unitor isomorphism.
    """
    ...

right_unitor abstractmethod

right_unitor(a: SetObject) -> ObservedMorphism

The right unitor A ⊗ I → A.

PARAMETER DESCRIPTION
a

The object.

TYPE: SetObject

RETURNS DESCRIPTION
ObservedMorphism

The right unitor isomorphism.

Source code in src/quivers/categorical/monoidal.py
@abstractmethod
def right_unitor(self, a: SetObject) -> ObservedMorphism:
    """The right unitor A ⊗ I → A.

    Parameters
    ----------
    a : SetObject
        The object.

    Returns
    -------
    ObservedMorphism
        The right unitor isomorphism.
    """
    ...

braiding abstractmethod

braiding(a: SetObject, b: SetObject) -> ObservedMorphism

The braiding A ⊗ B → B ⊗ A.

PARAMETER DESCRIPTION
a

Two objects.

TYPE: SetObject

b

Two objects.

TYPE: SetObject

RETURNS DESCRIPTION
ObservedMorphism

The braiding (swap) isomorphism.

Source code in src/quivers/categorical/monoidal.py
@abstractmethod
def braiding(self, a: SetObject, b: SetObject) -> ObservedMorphism:
    """The braiding A ⊗ B → B ⊗ A.

    Parameters
    ----------
    a, b : SetObject
        Two objects.

    Returns
    -------
    ObservedMorphism
        The braiding (swap) isomorphism.
    """
    ...

CartesianProductMonoidal

CartesianProductMonoidal(algebra: Algebra | None = None)

Bases: MonoidalStructure

The symmetric monoidal structure given by the cartesian product of sets.

The tensor of objects is their cartesian product (ProductSet) and the unit is the one-element set (Unit = FinSet(name="1", cardinality=1)). On V-matrices this is a symmetric tensor product and not a cartesian one: a relation cannot be copied naturally, so × is not the categorical product of V-matrices.

Since ProductSet auto-flattens, the associator (A×B)×C → A×(B×C) is the identity (both sides flatten to ProductSet(A,B,C)). The braiding A×B → B×A is a permutation tensor.

PARAMETER DESCRIPTION
algebra

The enrichment algebra for coherence morphisms.

TYPE: Algebra or None DEFAULT: None

Source code in src/quivers/categorical/monoidal.py
def __init__(self, algebra: Algebra | None = None) -> None:
    self._algebra = algebra if algebra is not None else PRODUCT_FUZZY

unit property

unit: FinSet

Terminal object {*}.

product

product(a: SetObject, b: SetObject) -> ProductSet

Cartesian product A × B.

Source code in src/quivers/categorical/monoidal.py
def product(self, a: SetObject, b: SetObject) -> ProductSet:
    """Cartesian product A × B."""
    return ProductSet(components=(a, b))

associator

associator(a: SetObject, b: SetObject, c: SetObject) -> ObservedMorphism

(A × B) × C → A × (B × C).

Since ProductSet flattens, both sides are ProductSet(A,B,C), so this is the identity morphism.

Source code in src/quivers/categorical/monoidal.py
def associator(self, a: SetObject, b: SetObject, c: SetObject) -> ObservedMorphism:
    """(A × B) × C → A × (B × C).

    Since ProductSet flattens, both sides are ProductSet(A,B,C),
    so this is the identity morphism.
    """
    flat = ProductSet(components=(a, b, c))
    data = self._algebra.identity_tensor(flat.shape)
    return observed(flat, flat, data, algebra=self._algebra)

left_unitor

left_unitor(a: SetObject) -> ObservedMorphism

I × A → A (project out the unit component).

The tensor maps (1, a₁, ..., aₙ) → (a₁, ..., aₙ). Since Unit has size 1, this is a "squeeze" that drops the trivial dimension.

Source code in src/quivers/categorical/monoidal.py
def left_unitor(self, a: SetObject) -> ObservedMorphism:
    """I × A → A (project out the unit component).

    The tensor maps (1, a₁, ..., aₙ) → (a₁, ..., aₙ).
    Since Unit has size 1, this is a "squeeze" that drops
    the trivial dimension.
    """
    source = ProductSet(components=(Unit, a))
    target = a
    data = torch.zeros(*source.shape, *target.shape)
    for idx in itertools.product(*(range(s) for s in target.shape)):
        src = (0,) + idx
        data[src + idx] = self._algebra.unit
    return observed(source, target, data, algebra=self._algebra)

right_unitor

right_unitor(a: SetObject) -> ObservedMorphism

A × I → A (project out the unit component).

The tensor maps (a₁, ..., aₙ, 1) → (a₁, ..., aₙ).

Source code in src/quivers/categorical/monoidal.py
def right_unitor(self, a: SetObject) -> ObservedMorphism:
    """A × I → A (project out the unit component).

    The tensor maps (a₁, ..., aₙ, 1) → (a₁, ..., aₙ).
    """
    source = ProductSet(components=(a, Unit))
    target = a
    data = torch.zeros(*source.shape, *target.shape)
    for idx in itertools.product(*(range(s) for s in target.shape)):
        src = idx + (0,)
        data[src + idx] = self._algebra.unit
    return observed(source, target, data, algebra=self._algebra)

braiding

braiding(a: SetObject, b: SetObject) -> ObservedMorphism

A × B → B × A (swap permutation).

The tensor has shape (*a.shape, *b.shape, *b.shape, *a.shape) with unit on entries where the swap holds.

Source code in src/quivers/categorical/monoidal.py
def braiding(self, a: SetObject, b: SetObject) -> ObservedMorphism:
    """A × B → B × A (swap permutation).

    The tensor has shape (*a.shape, *b.shape, *b.shape, *a.shape)
    with unit on entries where the swap holds.
    """
    source = ProductSet(components=(a, b))
    target = ProductSet(components=(b, a))
    data = torch.full((*source.shape, *target.shape), self._algebra.zero)
    for a_idx in itertools.product(*(range(s) for s in a.shape)):
        for b_idx in itertools.product(*(range(s) for s in b.shape)):
            src = a_idx + b_idx
            tgt = b_idx + a_idx
            data[src + tgt] = self._algebra.unit
    return observed(source, target, data, algebra=self._algebra)

EmptySet didactic-model

EmptySet(*, kind: Literal['empty_set'] = 'empty_set')

Bases: SetObject

The initial object (empty set) with cardinality 0.

Used as the unit for coproduct monoidal structure.

CoproductMonoidal

CoproductMonoidal(algebra: Algebra | None = None)

Bases: MonoidalStructure

Coproduct monoidal structure: (FinSet, +, ∅).

The product is the coproduct (CoproductSet), the unit is the initial object (EmptySet with cardinality 0).

PARAMETER DESCRIPTION
algebra

The enrichment algebra for coherence morphisms.

TYPE: Algebra or None DEFAULT: None

Source code in src/quivers/categorical/monoidal.py
def __init__(self, algebra: Algebra | None = None) -> None:
    self._algebra = algebra if algebra is not None else PRODUCT_FUZZY

unit property

unit: EmptySet

Initial object ∅.

product

product(a: SetObject, b: SetObject) -> CoproductSet

Coproduct A + B.

Source code in src/quivers/categorical/monoidal.py
def product(self, a: SetObject, b: SetObject) -> CoproductSet:
    """Coproduct A + B."""
    return CoproductSet(components=(a, b))

associator

associator(a: SetObject, b: SetObject, c: SetObject) -> ObservedMorphism

(A + B) + C → A + (B + C).

Since CoproductSet flattens, both sides are CoproductSet(A,B,C), so this is the identity.

Source code in src/quivers/categorical/monoidal.py
def associator(self, a: SetObject, b: SetObject, c: SetObject) -> ObservedMorphism:
    """(A + B) + C → A + (B + C).

    Since CoproductSet flattens, both sides are CoproductSet(A,B,C),
    so this is the identity.
    """
    flat = CoproductSet(components=(a, b, c))
    data = self._algebra.identity_tensor(flat.shape)
    return observed(flat, flat, data, algebra=self._algebra)

left_unitor

left_unitor(a: SetObject) -> ObservedMorphism

∅ + A → A.

Since ∅ has size 0, CoproductSet(∅, A) has the same size as A. The unitor is the identity (offset for A starts at 0).

Source code in src/quivers/categorical/monoidal.py
def left_unitor(self, a: SetObject) -> ObservedMorphism:
    """∅ + A → A.

    Since ∅ has size 0, CoproductSet(∅, A) has the same size as A.
    The unitor is the identity (offset for A starts at 0).
    """
    source = CoproductSet(components=(EMPTY, a))
    target = a
    data = self._algebra.identity_tensor(target.shape).reshape(
        target.size, *target.shape
    )
    return observed(source, target, data, algebra=self._algebra)

right_unitor

right_unitor(a: SetObject) -> ObservedMorphism

A + ∅ → A.

Since ∅ has size 0, CoproductSet(A, ∅) has the same size as A.

Source code in src/quivers/categorical/monoidal.py
def right_unitor(self, a: SetObject) -> ObservedMorphism:
    """A + ∅ → A.

    Since ∅ has size 0, CoproductSet(A, ∅) has the same size as A.
    """
    source = CoproductSet(components=(a, EMPTY))
    target = a
    data = self._algebra.identity_tensor(target.shape).reshape(
        target.size, *target.shape
    )
    return observed(source, target, data, algebra=self._algebra)

braiding

braiding(a: SetObject, b: SetObject) -> ObservedMorphism

A + B → B + A (block swap).

Swaps the two coproduct components.

Source code in src/quivers/categorical/monoidal.py
def braiding(self, a: SetObject, b: SetObject) -> ObservedMorphism:
    """A + B → B + A (block swap).

    Swaps the two coproduct components.
    """
    source = CoproductSet(components=(a, b))
    target = CoproductSet(components=(b, a))
    n_a = a.size
    n_b = b.size
    n = n_a + n_b
    data = torch.full((n, n), self._algebra.zero)
    for i in range(n_a):
        data[i, n_b + i] = self._algebra.unit
    for i in range(n_b):
        data[n_a + i, i] = self._algebra.unit
    return observed(source, target, data, algebra=self._algebra)

The EMPTY singleton is documented on the categorical overview.

Cited sources

Saunders Mac Lane. Categories for the Working Mathematician. Volume 5 of Graduate Texts in Mathematics. Springer, 2 edition, 1998. URL: https://link.springer.com/book/10.1007/978-1-4757-4721-8, doi:10.1007/978-1-4757-4721-8.