Natural Transformations

Morphisms between functors that preserve categorical structure naturally.

natural_transformations

Natural transformations between endofunctors.

A natural transformation η: F ⇒ G is a family of morphisms {η_A: F(A) → G(A)} indexed by objects, satisfying the naturality condition:

η_B ∘ F(f) = G(f) ∘ η_A   for all f: A → B

This module provides:

NaturalTransformation (abstract)
└── ComponentwiseNT — defined by a callable producing components

NaturalTransformation

NaturalTransformation(source: Functor, target: Functor)

Bases: ABC

Abstract natural transformation η: F ⇒ G.

Subclasses must implement component to produce η_A for each object A.

PARAMETER DESCRIPTION
source

The source functor F.

TYPE: Functor

target

The target functor G.

TYPE: Functor

Source code in src/quivers/categorical/natural_transformations.py
43
44
45
def __init__(self, source: Functor, target: Functor) -> None:
    self._source = source
    self._target = target

source property

source: Functor

The source functor F.

target property

target: Functor

The target functor G.

component abstractmethod

component(obj: SetObject) -> Morphism

Return the component η_A: F(A) → G(A).

PARAMETER DESCRIPTION
obj

The object A.

TYPE: SetObject

RETURNS DESCRIPTION
Morphism

The morphism η_A: F(A) → G(A).

Source code in src/quivers/categorical/natural_transformations.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
@abstractmethod
def component(self, obj: SetObject) -> Morphism:
    """Return the component η_A: F(A) → G(A).

    Parameters
    ----------
    obj : SetObject
        The object A.

    Returns
    -------
    Morphism
        The morphism η_A: F(A) → G(A).
    """
    ...

verify_naturality

verify_naturality(f: Morphism, atol: float = 1e-05) -> bool

Verify the naturality condition for a given morphism.

Checks that η_B ∘ F(f) ≈ G(f) ∘ η_A for f: A → B.

PARAMETER DESCRIPTION
f

A morphism f: A → B to check naturality against.

TYPE: Morphism

atol

Absolute tolerance for tensor comparison.

TYPE: float DEFAULT: 1e-05

RETURNS DESCRIPTION
bool

True if the naturality square commutes within tolerance.

Source code in src/quivers/categorical/natural_transformations.py
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def verify_naturality(self, f: Morphism, atol: float = 1e-5) -> bool:
    """Verify the naturality condition for a given morphism.

    Checks that η_B ∘ F(f) ≈ G(f) ∘ η_A for f: A → B.

    Parameters
    ----------
    f : Morphism
        A morphism f: A → B to check naturality against.
    atol : float
        Absolute tolerance for tensor comparison.

    Returns
    -------
    bool
        True if the naturality square commutes within tolerance.
    """
    a = f.domain
    b = f.codomain

    eta_a = self.component(a)
    eta_b = self.component(b)

    # left path: η_B ∘ F(f)
    f_mapped = self._source.map_morphism(f)
    left = (f_mapped >> eta_b).tensor

    # right path: G(f) ∘ η_A
    g_mapped = self._target.map_morphism(f)
    right = (eta_a >> g_mapped).tensor

    return torch.allclose(left, right, atol=atol)

ComponentwiseNT

ComponentwiseNT(source: Functor, target: Functor, component_fn: Callable[[SetObject], Morphism])

Bases: NaturalTransformation

A natural transformation defined by a callable.

Wraps a function obj ↦ morphism into a NaturalTransformation. Useful for constructing natural transformations from explicit component definitions.

PARAMETER DESCRIPTION
source

The source functor F.

TYPE: Functor

target

The target functor G.

TYPE: Functor

component_fn

A function that, given an object A, returns η_A: F(A) → G(A).

TYPE: Callable[[SetObject], Morphism]

Source code in src/quivers/categorical/natural_transformations.py
128
129
130
131
132
133
134
135
def __init__(
    self,
    source: Functor,
    target: Functor,
    component_fn: Callable[[SetObject], Morphism],
) -> None:
    super().__init__(source, target)
    self._component_fn = component_fn

component

component(obj: SetObject) -> Morphism

Return η_A by calling the stored function.

Source code in src/quivers/categorical/natural_transformations.py
137
138
139
def component(self, obj: SetObject) -> Morphism:
    """Return η_A by calling the stored function."""
    return self._component_fn(obj)