Yoneda¶
A representable presheaf records every map into one object. The Yoneda lemma says that a natural transformation out of it is determined by its value at that object's identity map (Kelly, 1982) (Yoneda). The module represents these maps as finite tensors and evaluates the corresponding equations.
yoneda
¶
Yoneda embedding and representable profunctors.
The Yoneda lemma states that for any V-presheaf F: C^op → V and object A in C:
∫_X [C(X, A), F(X)] ≅ F(A)
The routines below compute this end over a finite V-category whose
objects are the elements of the given finite sets. The end is a meet of
internal homs, so V must be a complete lattice with a residuum (an
IdempotentSemiring); the isomorphism then holds whenever the hom
tensors form a V-category and F is a V-presheaf on it, which the test
suite checks on small examples.
The Yoneda embedding y: C → Prof(C) sends each object A to the representable profunctor C(-, A): C^op → V. The embedding is full and faithful:
C(A, B) ≅ [C^op, V](C(-, A), C(-, B))
This module provides:
Presheaf — V-valued presheaf on finite objects
yoneda_embedding() — object to representable profunctor
yoneda_lemma() — compute the end ∫_X [C(X,A), F(X)]
yoneda_density() — decompose F via Yoneda density
representable_profunctor()— hom profunctor C(-, A)
corepresentable_profunctor() — hom profunctor C(A, -)
Presheaf
didactic-model
¶
Presheaf(*, objects: Sequence[SetObject] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), values: dict[int, 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 collection of finite objects.
Represents a functor F: C^op → V where C is a finite category (collection of objects with hom-sets between them). In the simplest case, F assigns a V-tensor to each object.
Holds the object sequence, tensor mapping, and algebra by identity.
The mapping remains mutable during Yoneda extension, and its tensors
retain their autograd histories. Record fields change through with_.
| PARAMETER | DESCRIPTION |
|---|---|
objects
|
The objects of the finite category C.
TYPE:
|
values
|
Maps object index → V-tensor. The tensor at index i represents F(objects[i]), a V-valued "set" of shape (*objects[i].shape,).
TYPE:
|
algebra
|
The enrichment algebra, a complete lattice.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValidationError
|
If the runtime fields have incompatible types or |
representable_profunctor
¶
representable_profunctor(obj: SetObject, algebra: IdempotentSemiring) -> Profunctor
The representable profunctor C(-, A) as a self-profunctor.
This is the Yoneda image of A: the profunctor from A to A given by the identity (hom from A to itself).
For a single-object view, this is the identity morphism viewed as a profunctor A ↛ A.
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The representing object A.
TYPE:
|
algebra
|
The enrichment algebra, a complete lattice.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Profunctor
|
The representable profunctor y(A) = C(-, A). |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the algebra is not an |
Source code in src/quivers/enriched/yoneda.py
corepresentable_profunctor
¶
corepresentable_profunctor(obj: SetObject, algebra: IdempotentSemiring) -> Profunctor
The corepresentable profunctor C(A, -) as a self-profunctor.
Dual to the representable. Also the identity viewed differently.
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The corepresenting object A.
TYPE:
|
algebra
|
The enrichment algebra, a complete lattice.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Profunctor
|
The corepresentable profunctor C(A, -). |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the algebra is not an |
Source code in src/quivers/enriched/yoneda.py
yoneda_embedding
¶
yoneda_embedding(morph: Morphism) -> Profunctor
Apply the Yoneda embedding to a morphism.
Given f: A → B, the Yoneda embedding produces a profunctor morphism y(f): y(A) → y(B), which is the profunctor view of f.
This is equivalent to Profunctor.from_morphism but makes the categorical origin explicit.
| PARAMETER | DESCRIPTION |
|---|---|
morph
|
A morphism f: A → B.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Profunctor
|
The profunctor A ↛ B corresponding to f. |
Source code in src/quivers/enriched/yoneda.py
yoneda_lemma
¶
yoneda_lemma(presheaf: Presheaf, obj_index: int, hom_tensors: Sequence[Tensor], algebra: IdempotentSemiring) -> Tensor
Compute the Yoneda lemma: ∫_X [C(X, A), F(X)] ≅ F(A).
Given a presheaf F and an object A (identified by index), with hom tensors C(X_i, A) provided for each object X_i, computes the end ∫_X [C(X, A), F(X)].
The mathematical Yoneda lemma identifies this end with F(A) under its hypotheses. The routine does not check all of those hypotheses or construct a general categorical isomorphism.
| PARAMETER | DESCRIPTION |
|---|---|
presheaf
|
The V-presheaf F.
TYPE:
|
obj_index
|
The index of object A in the presheaf's object list.
TYPE:
|
hom_tensors
|
For each object X_i in the presheaf, the hom tensor C(X_i, A) of shape (*X_i.shape, *A.shape).
TYPE:
|
algebra
|
The enrichment algebra, a complete lattice.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The finite internal-hom reduction described above. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the algebra is not an |
Source code in src/quivers/enriched/yoneda.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
yoneda_density
¶
yoneda_density(morph: Morphism, algebra: IdempotentSemiring) -> Tensor
Verify Yoneda density: f ≅ ∫^X C(A, X) ⊗ f(X, -).
For a morphism f: A → B, the Yoneda density theorem says f can be recovered as the coend:
f(a, b) = ∫^x C(a, x) ⊗ f(x, b) = ⋁_x δ(a,x) ⊗ f(x, b)
which states that composing with the identity gives back f. This function computes the coend and verifies it.
| PARAMETER | DESCRIPTION |
|---|---|
morph
|
The morphism f: A → B.
TYPE:
|
algebra
|
The enrichment algebra, a complete lattice.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The coend result, which should equal morph.tensor. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the algebra is not an |
Source code in src/quivers/enriched/yoneda.py
verify_yoneda_preserves_composition
¶
Check preservation of one supplied composite numerically.
Check that the profunctor morphism y(f) composed with y(g) equals y(f >> g), one instance of the functoriality of the Yoneda embedding.
| PARAMETER | DESCRIPTION |
|---|---|
f
|
First morphism f: A → B.
TYPE:
|
g
|
Second morphism g: B → C.
TYPE:
|
atol
|
Absolute tolerance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if y(f >> g) ≈ y(f) ; y(g). |
Source code in src/quivers/enriched/yoneda.py
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.