Functors¶
A functor maps objects and arrows while preserving
identities and composition (Mac Lane, 1998). Mapping a function over a list
is the familiar case: mapping \(f\) and then \(g\) gives the same list as mapping their composite. The
module gives the Functor interface and its identity, composite, and word (free monoid) instances,
and an implementation must satisfy the functor equations for its objects and arrows. The word
functor maps words of each length to words of the same length and satisfies those equations when
the Algebra is a Semiring.
functors
¶
Endofunctors on V-enriched FinSet.
A functor F maps objects to objects and morphisms to morphisms, preserving composition and identities. This module provides:
Functor (abstract)
├── IdentityFunctor — Id: A ↦ A, f ↦ f
├── ComposedFunctor — F ∘ G: applies G then F
└── FreeMonoidFunctor — A ↦ A*, f ↦ f* (block-diagonal, componentwise)
Functor
¶
Bases: ABC
Abstract endofunctor on V-enriched FinSet.
Subclasses must implement map_object, map_morphism, and map_tensor.
map_object
abstractmethod
¶
map_morphism
abstractmethod
¶
map_morphism(morph: Morphism) -> FunctorMorphism
Apply the functor to a morphism.
Returns a lazy FunctorMorphism that recomputes its tensor from the inner morphism, preserving gradient flow.
| PARAMETER | DESCRIPTION |
|---|---|
morph
|
Source morphism.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FunctorMorphism
|
Image morphism. |
Source code in src/quivers/categorical/functors.py
map_tensor
abstractmethod
¶
Apply the functor's action on the raw tensor level.
This is the computational core used by FunctorMorphism.tensor.
| PARAMETER | DESCRIPTION |
|---|---|
tensor
|
The inner morphism's tensor.
TYPE:
|
algebra
|
The enrichment algebra.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The image tensor. |
Source code in src/quivers/categorical/functors.py
IdentityFunctor
¶
Bases: Functor
The identity endofunctor Id: C → C.
Maps every object and morphism to itself. Needed as the source or target of natural transformations (e.g., monad unit η: Id ⇒ T).
map_object
¶
map_morphism
¶
map_morphism(morph: Morphism) -> FunctorMorphism
Identity on morphisms: f ↦ f (wrapped as FunctorMorphism).
ComposedFunctor
¶
Bases: Functor
Composition of two endofunctors: F ∘ G.
Applies G first, then F. Preserves functoriality: (F ∘ G)(f) = F(G(f)).
| PARAMETER | DESCRIPTION |
|---|---|
outer
|
The functor applied second (F).
TYPE:
|
inner
|
The functor applied first (G).
TYPE:
|
Source code in src/quivers/categorical/functors.py
map_object
¶
map_morphism
¶
map_morphism(morph: Morphism) -> FunctorMorphism
F(G(f)) as a lazy FunctorMorphism.
Source code in src/quivers/categorical/functors.py
map_tensor
¶
F's tensor action applied to G's tensor action.
Source code in src/quivers/categorical/functors.py
FreeMonoidFunctor
¶
Bases: Functor
The length-bounded word functor A ↦ A^{≤L} on V-matrices.
On objects: A ↦ FreeMonoid(generators=A, max_length=max_length) On morphisms: f ↦ f* (block-diagonal, componentwise on each stratum)
The morphism action assembles a block-diagonal tensor where the k-th block is componentwise_lift(f, k) reshaped to 2D. This means strings of length k map to strings of length k via componentwise application of the underlying morphism.
Words of each length are mapped to words of the same length, so the
bound never cuts a word and the functor laws hold whenever the
algebra is a Semiring (the block for length k is the
k-fold tensor power, and tensor powers commute with composition
by distributivity). The truncated free monoid is not closed under
concatenation, so this functor carries no monad structure.
| PARAMETER | DESCRIPTION |
|---|---|
max_length
|
Maximum string length for the truncated free monoid.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/categorical/functors.py
map_object
¶
map_object(obj: SetObject) -> FreeMonoid
Apply functor to an object: A ↦ FreeMonoid(generators=A, max_length=max_length).
For FinSet inputs, uses obj directly as generators. For other SetObject types (e.g., FreeMonoid, CoproductSet), creates a proxy FinSet with the same cardinality — this is needed for iterated application (e.g., the triangle identities of an adjunction require F(F(A)) = (A)).
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The generator set. Typically a FinSet, but any SetObject is accepted by treating it as a flat set.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FreeMonoid
|
The free monoid on obj. |
Source code in src/quivers/categorical/functors.py
map_morphism
¶
map_morphism(morph: Morphism) -> FunctorMorphism
Apply functor to a morphism: f ↦ f* (block-diagonal).
| PARAMETER | DESCRIPTION |
|---|---|
morph
|
A morphism between FinSets.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FunctorMorphism
|
Lazy image preserving gradient flow. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the morphism's algebra is not a |
Source code in src/quivers/categorical/functors.py
map_tensor
¶
Build the block-diagonal tensor for the free monoid action.
For each k=0..max_length, computes componentwise_lift(f, k), reshapes the result to 2D (n_a^k × n_b^k), and assembles all blocks via torch.block_diag.
| PARAMETER | DESCRIPTION |
|---|---|
tensor
|
The inner morphism's 2D tensor of shape (n_a, n_b).
TYPE:
|
algebra
|
The enrichment algebra (passed to componentwise_lift).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Block-diagonal tensor of shape (total_a, total_b). |
Source code in src/quivers/categorical/functors.py
Package constants¶
The singletons of quivers.categorical.
Categorical structures: functors, natural transformations, adjunctions, monoidal, and traced categories.
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.