Skip to content

Instantly share code, notes, and snippets.

@gaxiiiiiiiiiiii
Created May 4, 2025 15:34
Show Gist options
  • Save gaxiiiiiiiiiiii/1b55aff0fae4b6d1c3135126081685c4 to your computer and use it in GitHub Desktop.
Save gaxiiiiiiiiiiii/1b55aff0fae4b6d1c3135126081685c4 to your computer and use it in GitHub Desktop.
import Mathlib.tactic
import Mathlib.CategoryTheory.Limits.HasLimits
open CategoryTheory
open Limits
structure Elm [Category.{u, v} 𝓐] (X : 𝓐ᡒᡖ β₯€ Type w) where
obj : 𝓐
elm : X.obj (Opposite.op obj)
@[ext]
structure ElmHom [Category.{u, v} 𝓐] (X : 𝓐ᡒᡖ β₯€ Type w) (A B : Elm X) where
hom : A.obj ⟢ B.obj
w : X.map (Quiver.Hom.op hom) B.elm = A.elm
instance Category [Category.{u, v} 𝓐] (X : 𝓐ᡒᡖ β₯€ Type w) : Category (Elm X)
where
Hom := ElmHom X
id A := {
hom := πŸ™ A.obj
w := by rw [op_id, X.map_id, types_id_apply]
}
comp {A B C} f g := {
hom := f.hom ≫ g.hom
w := by
rw [op_comp, X.map_comp, types_comp_apply]
rw [g.w, f.w]
}
id_comp {A B} f := by ext; simp
comp_id {A B} f := by ext; simp
assoc {A B C D} f g h := by ext; simp
def ElmP [Category.{u, v} 𝓐] (X : 𝓐ᡒᡖ β₯€ Type w) :
Elm X β₯€ 𝓐
where
obj A := A.obj
map {A B} f := f.hom
map_id f := by
conv => arg 1; unfold CategoryStruct.id Category.toCategoryStruct _root_.Category; simp
map_comp {A B C} f g := by
conv => arg 1; unfold CategoryStruct.comp Category.toCategoryStruct _root_.Category; simp
def PresheafCocone [Category.{u, v} 𝓐] (X : 𝓐ᡒᡖ β₯€ Type u) :
Cocone (ElmP X β‹™ yoneda)
:= {
pt := X
ΞΉ := {
app z := {
app A' := Ξ» F => X.map (Quiver.Hom.op F) z.elm
naturality i j u := by simp [yoneda]; ext f; simp
}
naturality z z' f := by
simp; ext A' g; simp at g; simp [ElmP]
rw [f.w]
}
}
def PresheafCocone_isColimit [Category.{u, v} 𝓐] (X : 𝓐ᡒᡖ β₯€ Type u) :
IsColimit (PresheafCocone X)
:= {
desc C := {
app A' := by
simp [PresheafCocone]; intro XA'
exact (C.ΞΉ.app ⟨A'.unop, XA'⟩).app A' (πŸ™ A'.unop)
naturality A' B' f := by
simp [PresheafCocone]; ext XA'; simp
set a : Elm X := ⟨A'.unop, XA'⟩
set b : Elm X := ⟨B'.unop, X.map f XA'⟩
change (C.ΞΉ.app b).app B' (πŸ™ (Opposite.unop B')) = C.pt.map f ((C.ΞΉ.app a).app A' (πŸ™ (Opposite.unop A')))
let ab : b ⟢ a := {
hom := f.unop
w := by
simp [a, b]
}
have EC := (C.ΞΉ.app a).naturality f
conv at EC => arg 1; arg 1; simp [ElmP, yoneda]
conv at EC => arg 2; simp
have E := congr_fun EC (πŸ™ _); simp at E
have E' := C.ΞΉ.naturality ab
injection E' with E'
have EB' := congr_fun E' B'; simp [yoneda, ElmP, ab] at EB'
have := congr_fun EB' (πŸ™ B'.unop); simp at this
rw [<- E, this]
}
fac C a := by
simp; ext B' f; simp [ElmP] at f; simp [PresheafCocone]
set b : Elm X := { obj := Opposite.unop B', elm := X.map f.op a.elm }
change (C.ΞΉ.app b).app B' (πŸ™ (Opposite.unop B')) = (C.ΞΉ.app a).app B' f
let ab : b ⟢ a := {
hom := f
w := by
simp [b]
}
have E' := C.ΞΉ.naturality ab
injection E' with E'
have EB' := congr_fun E' B'; simp [yoneda, ElmP, ab] at EB'
have E' := congr_fun EB' (πŸ™ B'.unop); simp at E'; clear EB'
rw [E']
uniq C m Hm := by
ext A' XA'; simp [PresheafCocone] at XA'; simp
have E := Hm ⟨A'.unop, XA'⟩
rw [<- E]
simp [PresheafCocone]
rw [X.map_id A']; simp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment