diff --git a/src/categorical_algebra/CSets.jl b/src/categorical_algebra/CSets.jl index 80fd4b28d..f94c9abb1 100644 --- a/src/categorical_algebra/CSets.jl +++ b/src/categorical_algebra/CSets.jl @@ -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 @@ -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 ############################### diff --git a/src/categorical_algebra/DPO.jl b/src/categorical_algebra/DPO.jl index 81a799159..2a5fb3b9c 100644 --- a/src/categorical_algebra/DPO.jl +++ b/src/categorical_algebra/DPO.jl @@ -34,8 +34,8 @@ 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) @@ -43,9 +43,8 @@ function pushout_complement( 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 diff --git a/test/categorical_algebra/CSets.jl b/test/categorical_algebra/CSets.jl index 2a9acf96d..4adf91aeb 100644 --- a/test/categorical_algebra/CSets.jl +++ b/test/categorical_algebra/CSets.jl @@ -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 #-------