Yoneda¶
Yoneda embeddings and the Yoneda lemma in enriched categories.
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)
In our finite V-enriched setting, this becomes a computable end.
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
dataclass
¶
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 a mutable dict[int, torch.Tensor] of values that grows during
yoneda extension; not a value type.
| 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:
|
quantale
|
The enrichment algebra. Defaults to PRODUCT_FUZZY.
TYPE:
|
evaluate
¶
evaluate(index: int) -> Tensor
Evaluate the presheaf at object index.
| PARAMETER | DESCRIPTION |
|---|---|
index
|
Index into the objects list.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The value F(objects[index]). |
Source code in src/quivers/enriched/yoneda.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
representable_profunctor
¶
representable_profunctor(obj: SetObject, quantale: Quantale | None = None) -> 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 just the identity morphism viewed as a profunctor A ↛ A.
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The representing object A.
TYPE:
|
quantale
|
The enrichment algebra. Defaults to PRODUCT_FUZZY.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Profunctor
|
The representable profunctor y(A) = C(-, A). |
Source code in src/quivers/enriched/yoneda.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
corepresentable_profunctor
¶
corepresentable_profunctor(obj: SetObject, quantale: Quantale | None = None) -> 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:
|
quantale
|
The enrichment algebra. Defaults to PRODUCT_FUZZY.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Profunctor
|
The corepresentable profunctor C(A, -). |
Source code in src/quivers/enriched/yoneda.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
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 just 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
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
yoneda_lemma
¶
yoneda_lemma(presheaf: Presheaf, obj_index: int, hom_tensors: Sequence[Tensor], quantale: Quantale | None = None) -> 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 result should be isomorphic to F(A) (the Yoneda lemma).
| 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:
|
quantale
|
The enrichment algebra. Defaults to PRODUCT_FUZZY.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The Yoneda end, which should be ≅ F(A). |
Source code in src/quivers/enriched/yoneda.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 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 | |
yoneda_density
¶
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 is just the statement 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:
|
quantale
|
The enrichment algebra. Defaults to PRODUCT_FUZZY.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The coend result, which should equal morph.tensor. |
Source code in src/quivers/enriched/yoneda.py
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 | |
verify_yoneda_fully_faithful
¶
Verify that the Yoneda embedding is full and faithful.
Check that the profunctor morphism y(f) composed with y(g) equals y(f >> g), i.e., the embedding preserves composition.
| 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
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |