The category of elements (also ) of a set-valued functor has as objects pairs with and as morphisms the morphisms with . The projection is a discrete opfibration. Dually for a presheaf (with ).
Sources: 7 Sketches Remark 3.100 (the pullback of instances along a functor is a pullback in via categories of elements), §3.3.3 (an instance as a “bunch of tables” — its rows are the elements); DaoFP §9.8 (every presheaf is a colimit of representables, indexed by its category of elements), §11.2 (fibrations); Kittenlab Lecture 6 (C-Set instances); CTfS §4.6.2 (Definition 4.6.2.1, Example 4.6.2.2, Application 4.6.2.3, Exercises 4.6.2.4–4.6.2.5), Example 4.6.4.2
- A C-Set is recovered from : the elements over are the rows of table , and is what the foreign key does to rows. In Catlab an ACSet is stored as its category of elements (parts and subpart functions).
- Density: — every co-presheaf is a colimit of representables indexed by its elements (Yoneda Lemma, co-Yoneda).
- is the Comma Category (with the point), and a slice of the presheaf category: .
- RDF triple stores (CTfS Application 4.6.2.3). The web’s Resource Description Framework stores data schema-free as triples , e.g.
⟨A01 occurredOn D13114⟩,⟨D13114 hasYear 2013⟩,⟨P44 FirstName Barack⟩. Converting a database instance into a triple store is the category of elements: every arrow of gives the triple . For the employee database of Database Schema this yields⟨101 manager 103⟩,⟨102 first Bertrand⟩,⟨q10 secretary 101⟩, … - Histograms and indexed sets (CTfS Example 4.6.2.2). For a set viewed as a discrete category, a functor is an -indexed set and with sending each element to its index — e.g. people binned by city: , , , . The construction converts indexed sets into sets over (a slice).
- State machines (CTfS Exercise 4.6.2.5): for a Finite State Machine, i.e. a functor , the category of elements has the states as objects and a morphism for every input word — it is the free category on the familiar state-transition picture.
- Grothendieck construction: for the same recipe produces a (non-discrete) fibration (Dependent Type).
Docs: ACSets API · Graphs · Vignette: category of elements — Kittenlab Lecture 6
using Catlab
G = path_graph(Graph, 3)
# the category of elements of the graph G (as a C-set): its objects are the parts
elems = [(ob, i) for ob in (:V, :E) for i in parts(G, ob)] # 5 objects
# morphisms: for each edge e, src: (E,e) → (V, src(e)) and tgt: (E,e) → (V, tgt(e))
arrows = [((:E, e), :src, (:V, G[e, :src])) for e in parts(G, :E)] ∪
[((:E, e), :tgt, (:V, G[e, :tgt])) for e in parts(G, :E)]
length(elems), length(arrows) # (5, 4)import Mathlib
open CategoryTheory
#check @CategoryTheory.Functor.Elements -- F.Elements for F : C ⥤ Type
#check @CategoryTheory.CategoryOfElements.π -- the projection to C
#check @CategoryTheory.Grothendieck -- Grothendieck construction for F : C ⥤ Cat-- the category of elements of a finite Set-valued functor, by enumeration
data Elem c x = Elem c x -- an object (c, x) with x ∈ F c
-- a morphism (c, x) -> (c', x') is an f : c -> c' with fmapF f x == x'