Skip to content

Weighted Limits

A weighted limit of a diagram describes the compatible ways of mapping into it, with a weight saying how much each object of the diagram contributes (Kelly, 1982). For a family of parallel morphisms \(f_j : A \to B\) indexed by a finite set \(J\) and a weight \(W\), the weighted limit is the pointwise meet \(\bigwedge_j [W(j), f_j]\) of residua and the weighted colimit the pointwise join \(\bigvee_j W(j) \otimes f_j\). weighted_limit_morphisms and weighted_colimit_morphisms compute them when the Algebra is an IdempotentSemiring, so that its values form a complete lattice, and the results then have the universal property (weighted limits).

weighted_limits

Weighted (co)limits for V-enriched categories.

In a V-enriched category, the correct notion of limit is the weighted limit. Given a V-functor D: J → C (diagram) and a V-functor W: J → V (weight), the weighted limit {W, D} is characterized by:

C(X, {W, D}) ≅ [J, V](W, C(X, D-))

and the weighted colimit W ⊗_J D by:

C(W ⊗_J D, X) ≅ [J, V](W, C(D-, X))

For a discrete indexing set J and a diagram of parallel morphisms f_j: A → B, viewed as objects of the V-category of V-valued matrices A → B (the power V^{A×B}, complete when V is a complete lattice), these reduce to the pointwise end and coend

{W, f} = ⋀_j [W(j), f_j]      (weighted limit)
W ⊗_J f = ⋁_j W(j) ⊗ f_j      (weighted colimit)

where [-, -] is V's residuum (internal hom) [Kelly (1982), §3]. They are characterized by g ≤ {W, f} ⟺ W(j) ⊗ g ≤ f_j for every j, and W ⊗_J f ≤ g ⟺ W(j) ⊗ f_j ≤ g for every j, which needs V to be an IdempotentSemiring with its IdempotentSemiring.residuum.

This module provides:

Weight                       — a V-valued weight on a finite set
weighted_limit_morphisms()   — compute {W, f}
weighted_colimit_morphisms() — compute W ⊗_J f
representable_weight()       — weight represented by an index
terminal_weight()            — constant weight at the unit
References

Kelly, G. M. (1982). Basic Concepts of Enriched Category Theory. Cambridge University Press. Reprinted in Reprints in Theory and Applications of Categories, 10 (2005). TAC reprint

Weight didactic-model

Weight(*, values: Tensor = field(opaque=True, extras=OPAQUE_BY_IDENTITY), algebra: IdempotentSemiring = field(opaque=True, extras=OPAQUE_BY_IDENTITY))

Bases: ValueModel

A V-valued presheaf on a finite indexing category.

Represents a weight functor W: J → V where J is a finite set of indices, and W assigns a V-value (scalar in the algebra's lattice) to each index.

The tensor and algebra are held by identity. Immutable record updates retain the live tensor and its autograd history.

PARAMETER DESCRIPTION
values

A 1D tensor of shape (|J|,) with values in L (the algebra's lattice). W(j) = values[j].

TYPE: Tensor DEFAULT: field(opaque=True, extras=OPAQUE_BY_IDENTITY)

algebra

The enrichment algebra, a complete lattice.

TYPE: IdempotentSemiring DEFAULT: field(opaque=True, extras=OPAQUE_BY_IDENTITY)

RAISES DESCRIPTION
ValidationError

If algebra is not an IdempotentSemiring or values is not a one-dimensional tensor.

size property

size: int

Number of indices in J.

weighted_limit_morphisms

weighted_limit_morphisms(weight: Weight, morphisms: Sequence[Morphism], algebra: IdempotentSemiring) -> Tensor

Compute a weighted limit from a family of morphisms.

Given morphisms f_j: X → A_j and weights W(j), computes the weighted meet:

result[x, ...] = ⋀_j [W(j), f_j(x, ...)]

This is the tensor-level computation of the weighted limit of a cone.

PARAMETER DESCRIPTION
weight

The weight W.

TYPE: Weight

morphisms

The morphisms f_j comprising the cone.

TYPE: Sequence[Morphism]

algebra

The enrichment algebra, a complete lattice.

TYPE: IdempotentSemiring

RETURNS DESCRIPTION
Tensor

The weighted limit tensor.

RAISES DESCRIPTION
TypeError

If the algebra is not an IdempotentSemiring.

ValueError

If the weight and the family differ in size or the family is empty.

Source code in src/quivers/enriched/weighted_limits.py
def weighted_limit_morphisms(
    weight: Weight,
    morphisms: Sequence[Morphism],
    algebra: IdempotentSemiring,
) -> torch.Tensor:
    """Compute a weighted limit from a family of morphisms.

    Given morphisms f_j: X → A_j and weights W(j), computes the
    weighted meet:

        result[x, ...] = ⋀_j [W(j), f_j(x, ...)]

    This is the tensor-level computation of the weighted limit
    of a cone.

    Parameters
    ----------
    weight : Weight
        The weight W.
    morphisms : Sequence[Morphism]
        The morphisms f_j comprising the cone.
    algebra : IdempotentSemiring
        The enrichment algebra, a complete lattice.

    Returns
    -------
    torch.Tensor
        The weighted limit tensor.

    Raises
    ------
    TypeError
        If the algebra is not an `IdempotentSemiring`.
    ValueError
        If the weight and the family differ in size or the family is
        empty.
    """
    q = require_lattice(algebra, "a weighted (co)limit")

    if weight.size != len(morphisms):
        raise ValueError(
            f"weight size {weight.size} != number of morphisms {len(morphisms)}"
        )

    n = len(morphisms)

    if n == 0:
        raise ValueError("need at least one morphism")

    # compute [W(j), f_j] for each j and meet over j
    components: list[torch.Tensor] = []

    for j in range(n):
        w_j = weight.values[j]
        f_j = morphisms[j].tensor
        hom = q.residuum(w_j, f_j)
        components.append(hom)

    # meet over all components (they should all have the same shape)
    stacked = torch.stack(components, dim=0)
    return q.meet(stacked, dim=0)

weighted_colimit_morphisms

weighted_colimit_morphisms(weight: Weight, morphisms: Sequence[Morphism], algebra: IdempotentSemiring) -> Tensor

Compute a weighted colimit from a family of morphisms.

Given morphisms f_j: A_j → X and weights W(j), computes the weighted join:

result[..., x] = ⋁_j W(j) ⊗ f_j(..., x)
PARAMETER DESCRIPTION
weight

The weight W.

TYPE: Weight

morphisms

The morphisms f_j comprising the cocone.

TYPE: Sequence[Morphism]

algebra

The enrichment algebra, a complete lattice.

TYPE: IdempotentSemiring

RETURNS DESCRIPTION
Tensor

The weighted colimit tensor.

RAISES DESCRIPTION
TypeError

If the algebra is not an IdempotentSemiring.

ValueError

If the weight and the family differ in size or the family is empty.

Source code in src/quivers/enriched/weighted_limits.py
def weighted_colimit_morphisms(
    weight: Weight,
    morphisms: Sequence[Morphism],
    algebra: IdempotentSemiring,
) -> torch.Tensor:
    """Compute a weighted colimit from a family of morphisms.

    Given morphisms f_j: A_j → X and weights W(j), computes the
    weighted join:

        result[..., x] = ⋁_j W(j) ⊗ f_j(..., x)

    Parameters
    ----------
    weight : Weight
        The weight W.
    morphisms : Sequence[Morphism]
        The morphisms f_j comprising the cocone.
    algebra : IdempotentSemiring
        The enrichment algebra, a complete lattice.

    Returns
    -------
    torch.Tensor
        The weighted colimit tensor.

    Raises
    ------
    TypeError
        If the algebra is not an `IdempotentSemiring`.
    ValueError
        If the weight and the family differ in size or the family is
        empty.
    """
    q = require_lattice(algebra, "a weighted (co)limit")

    if weight.size != len(morphisms):
        raise ValueError(
            f"weight size {weight.size} != number of morphisms {len(morphisms)}"
        )

    n = len(morphisms)

    if n == 0:
        raise ValueError("need at least one morphism")

    components: list[torch.Tensor] = []

    for j in range(n):
        w_j = weight.values[j]
        f_j = morphisms[j].tensor
        scaled = q.tensor_op(f_j, w_j)
        components.append(scaled)

    stacked = torch.stack(components, dim=0)
    return q.join(stacked, dim=0)

representable_weight

representable_weight(index_set: FinSet, represented_at: int, algebra: IdempotentSemiring) -> Weight

Create a representable weight (Yoneda-style).

The representable weight at index k is W(j) = I if j == k, and W(j) = ⊥ otherwise. Weighted limits with representable weights recover evaluation: {y(k), D} ≅ D(k).

PARAMETER DESCRIPTION
index_set

The indexing set J.

TYPE: FinSet

represented_at

The representing index k.

TYPE: int

algebra

The enrichment algebra, a complete lattice.

TYPE: IdempotentSemiring

RETURNS DESCRIPTION
Weight

The representable weight at k.

RAISES DESCRIPTION
TypeError

If the algebra is not an IdempotentSemiring.

Source code in src/quivers/enriched/weighted_limits.py
def representable_weight(
    index_set: FinSet,
    represented_at: int,
    algebra: IdempotentSemiring,
) -> Weight:
    """Create a representable weight (Yoneda-style).

    The representable weight at index k is W(j) = I if j == k,
    and W(j) = ⊥ otherwise. Weighted limits with representable
    weights recover evaluation: {y(k), D} ≅ D(k).

    Parameters
    ----------
    index_set : FinSet
        The indexing set J.
    represented_at : int
        The representing index k.
    algebra : IdempotentSemiring
        The enrichment algebra, a complete lattice.

    Returns
    -------
    Weight
        The representable weight at k.

    Raises
    ------
    TypeError
        If the algebra is not an `IdempotentSemiring`.
    """
    q = require_lattice(algebra, "a weighted (co)limit")

    values = torch.full((index_set.cardinality,), q.zero)
    values[represented_at] = q.unit

    return Weight(values=values, algebra=q)

terminal_weight

terminal_weight(index_set: FinSet, algebra: IdempotentSemiring) -> Weight

Create the terminal (constant unit) weight.

W(j) = I for all j. Weighted limits with the terminal weight recover ordinary (conical) limits.

PARAMETER DESCRIPTION
index_set

The indexing set J.

TYPE: FinSet

algebra

The enrichment algebra, a complete lattice.

TYPE: IdempotentSemiring

RETURNS DESCRIPTION
Weight

The terminal weight.

RAISES DESCRIPTION
TypeError

If the algebra is not an IdempotentSemiring.

Source code in src/quivers/enriched/weighted_limits.py
def terminal_weight(
    index_set: FinSet,
    algebra: IdempotentSemiring,
) -> Weight:
    """Create the terminal (constant unit) weight.

    W(j) = I for all j. Weighted limits with the terminal weight
    recover ordinary (conical) limits.

    Parameters
    ----------
    index_set : FinSet
        The indexing set J.
    algebra : IdempotentSemiring
        The enrichment algebra, a complete lattice.

    Returns
    -------
    Weight
        The terminal weight.

    Raises
    ------
    TypeError
        If the algebra is not an `IdempotentSemiring`.
    """
    q = require_lattice(algebra, "a weighted (co)limit")
    values = torch.full((index_set.cardinality,), q.unit)

    return Weight(values=values, algebra=q)

Cited sources

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.