Skip to content

Commit

Permalink
Merge pull request #461 from epatters/cset-subobjects
Browse files Browse the repository at this point in the history
Function to create subobject of C-set
  • Loading branch information
epatters authored Jul 12, 2021
2 parents 9a5da17 + 47a8976 commit 1b85023
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/categorical_algebra/CSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
module CSets
export ACSetTransformation, CSetTransformation, components, force, is_natural,
homomorphism, homomorphisms, is_homomorphic,
subobject, homomorphism, homomorphisms, is_homomorphic,
isomorphism, isomorphisms, is_isomorphic,
generate_json_acset, parse_json_acset, read_json_acset, write_json_acset

Expand Down Expand Up @@ -156,6 +156,19 @@ map_components(f, α::ACSetTransformation) =
ACSetTransformation(map(f, components(α)), dom(α), codom(α))
force::ACSetTransformation) = map_components(force, α)

""" Construct subobject of C-set from components of inclusion map.
Recall that a *subobject* of a C-set ``X`` is a monomorphism ``α: U → X``. This
function constructs a subobject from the components of the monomorphism, given
as a named tuple or as keyword arguments.
"""
function subobject(X::T, components) where T <: AbstractACSet
U = T()
copy_parts!(U, X, components)
ACSetTransformation(components, U, X)
end
subobject(X::AbstractACSet; components...) = subobject(X, (; components...))

# Finding C-set transformations
###############################

Expand Down
7 changes: 3 additions & 4 deletions src/categorical_algebra/DPO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,17 @@ function pushout_complement(
orphans = Set([ m[c](x) for x in parts(L,c) if x l_image ])
filter(x -> x orphans, parts(G,c))
end)
K = typeof(G)()
copy_parts!(K, G, g_components)
g = subobject(G, g_components)
K = dom(g)

# Construct morphism k: I → K using partial inverse of g.
lm = compose(l, m)
k_components = NamedTuple{ob(CD)}(map(ob(CD)) do c
g_inv = Dict{Int,Int}(zip(g_components[c], parts(K,c)))
[ g_inv[lm[c](x)] for x in parts(I,c) ]
end)

k = ACSetTransformation(k_components, I, K)
g = ACSetTransformation(g_components, K, G)

return k => g
end

Expand Down
6 changes: 6 additions & 0 deletions test/categorical_algebra/CSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ g, h = path_graph(Graph, 4), cycle_graph(Graph, 2)
@test force(compose(id(g), α)) == α
@test force(compose(α, id(h))) == α

# Subobjects.
α = subobject(g, V=[2,3,4], E=[2,3])
@test is_natural(α)
@test dom(α) == path_graph(Graph, 3)
@test codom(α) == g

# Limits
#-------

Expand Down

0 comments on commit 1b85023

Please sign in to comment.