-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kris Brown
committed
Jan 22, 2025
1 parent
5ea5b7e
commit 69f163b
Showing
11 changed files
with
256 additions
and
145 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/04_categorical_algebra/01_cats/05_freediagrams/FreeDiagrams.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
src/04_categorical_algebra/01_cats/12_slice/LimitsColimits.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
module SliceLimitsColimits | ||
|
||
using StructEquality | ||
using GATlab | ||
|
||
using ...Cats | ||
import ...Cats: limit, colimit, universal | ||
using ..SliceCategories | ||
|
||
############ | ||
# Colimits # | ||
############ | ||
|
||
@instance ThCategoryWithInitial{SliceOb{ObT, HomT}, HomT, AbsSet, AbsColimit, | ||
Multicospan, EmptyDiagram} [model::SliceC{ObT, HomT, C}] where {ObT, HomT, C} begin | ||
|
||
colimit(::EmptyDiagram)::AbsColimit = | ||
InitialColimit{SliceOb{<:ObT, <:HomT}, HomT}( | ||
SliceOb(apex(initial[model.cat]()), create[model.cat](model.over))) | ||
|
||
universal(::AbsColimit, ::EmptyDiagram, a::Multicospan) = | ||
FinFunction(Int[], FinSet(apex[model](a))) | ||
end | ||
|
||
@instance ThCategoryUnbiasedCoproducts{SliceOb{ObT, HomT}, HomT, AbsSet, AbsColimit, | ||
Multicospan, DiscreteDiagram} [model::SliceC{ObT, HomT, C}] where {ObT, HomT, C} begin | ||
|
||
colimit(d::DiscreteDiagram)::AbsColimit = colimit_slice(model, FreeDiagram(d)) | ||
|
||
universal(colim::AbsColimit, diag::DiscreteDiagram, csp::Multicospan) = | ||
slice_colimit_universal(model, colim, diag, csp) | ||
end | ||
|
||
@instance ThCategoryWithPushouts{SliceOb{ObT, HomT}, HomT, AbsSet, AbsColimit, | ||
Multicospan, Multispan} [model::SliceC{ObT, HomT, C}] where {ObT, HomT, C} begin | ||
|
||
colimit(d::Multispan)::AbsColimit = colimit_slice(model, FreeDiagram(d)) | ||
|
||
universal(colim::AbsColimit, diag::Multispan, csp::Multicospan) = | ||
slice_colimit_universal(model, colim, diag, csp) | ||
end | ||
|
||
@instance ThCategoryWithBipartiteColimits{SliceOb{ObT, HomT}, HomT, AbsSet, AbsColimit, | ||
Multicospan, BipartiteFreeDiagram} [model::SliceC{ObT, HomT, C}] where {ObT, HomT, C} begin | ||
|
||
colimit(d::BipartiteFreeDiagram)::AbsColimit = colimit_slice(model, FreeDiagram(d)) | ||
|
||
universal(colim::AbsColimit, diag::BipartiteFreeDiagram, csp::Multicospan) = | ||
slice_colimit_universal(model, colim, FreeDiagram(diag), csp) | ||
end | ||
|
||
|
||
""" | ||
Convert colimit in slice category into computation in the underlying category | ||
""" | ||
function colimit_slice(model::SliceC, diagram::FreeDiagram) | ||
𝒞, D = model.cat, getvalue(diagram) | ||
Ob, Hom = impl_type(𝒞, ThCategory, :Ob), impl_type(𝒞, ThCategory, :Hom) | ||
# discard all the slice info in the colimit diagram - it's irrelevant | ||
colim = colimit[𝒞](fmap(D, x -> x.ob, identity, Ob, Hom)) | ||
|
||
# compute new apex using the universal property of colimits | ||
csp = Multicospan(model.over, map(x -> x.hom, | ||
cocone_objects(D)); | ||
cat=𝒞) | ||
new_apex = SliceOb(ob(colim), universal[𝒞](colim, csp)) | ||
cocone = Multicospan(new_apex, legs(colim), cocone_objects(D)) | ||
return ColimitCocone(cocone, diagram) | ||
end | ||
|
||
########## | ||
# Limits # | ||
########## | ||
@instance ThCategoryUnbiasedProducts{SliceOb{ObT, HomT}, HomT, AbsSet, AbsLimit, | ||
Multispan, DiscreteDiagram} [model::SliceC{ObT, HomT, C}] where {ObT, HomT, C} begin | ||
|
||
limit(d::DiscreteDiagram)::AbsLimit = limit_slice(model, FreeDiagram(d)) | ||
|
||
universal(colim::AbsLimit, diag::DiscreteDiagram, csp::Multispan) = | ||
slice_limit_universal(model, colim, FreeDiagram(diag), csp) | ||
end | ||
|
||
""" | ||
A limit cone in a slice category 𝒞/X contains the limit cone data (where | ||
objects are SliceOb and morphisms are Homs in 𝒞) in addition to caching the | ||
limit in 𝒞 (which has a diagram with one extra object) in order to easily | ||
apply the universal property. | ||
""" | ||
@struct_hash_equal struct SliceLimitCone <: AbsLimit | ||
cone::Multispan | ||
diagram::FreeDiagram | ||
underlying::AbsLimit # in underlying 𝒞: `diagram` + 1 extra object | ||
end | ||
|
||
""" | ||
Convert a limit problem in the slice category to a limit problem of the | ||
underlying category. | ||
Encode the base of slice as the first object in the new diagram | ||
""" | ||
function limit_slice(model, diagram::FreeDiagram) | ||
𝒞 = model.cat | ||
obs = [model.over, [x.ob for x in ob(diagram)]...] # one extra object | ||
|
||
# assumes that the Ob/Hom sets of `diagram` are Int! | ||
# fix by making a Dict{Int,Ob} for input diagram | ||
homs = map(obset(diagram)) do o | ||
(obmap(diagram, o).hom,o+1,1) | ||
end ∪ map(homset(diagram)) do h | ||
(hommap(diagram, h), src(diagram, h)+1, tgt(diagram, h)+1) | ||
end |> Vector{Tuple{impl_type(𝒞, ThCategory, :Hom), Int, Int}} | ||
|
||
FG = FreeGraph(obs,homs) | ||
lim = limit[𝒞](FG) | ||
|
||
new_apex = SliceOb(apex(lim), first(legs(lim.cone))) | ||
spn = Multispan(new_apex, legs(lim.cone)[2:end], FG[:ob][2:end]) | ||
SliceLimitCone(spn, diagram, lim) | ||
end | ||
|
||
""" Use the universal property of the underlying category. """ | ||
function slice_limit_universal(model, lim::AbsLimit, diag::FreeDiagram, sp::Multispan) | ||
𝒞, apx = model.cat, apex(sp) | ||
universal[𝒞](lim.underlying, Multispan(apx.ob, [apx.hom, sp...]; cat=𝒞)) | ||
end | ||
|
||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
""" | ||
This largely copies the `GATlab.Stdlib` version of Slice categories, except it | ||
uses `ThCategoryExplicitSets` rather than `ThCategory`. | ||
""" | ||
module SliceCategories | ||
|
||
include("SliceCategories.jl") | ||
include("LimitsColimits.jl") | ||
|
||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.