Skip to content

Commit

Permalink
coerce VarFuns to FinFuns for SubobjectHom as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Brown committed Jul 17, 2024
1 parent da6b62c commit 66f1f40
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
5 changes: 3 additions & 2 deletions src/categorical_algebra/CSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1123,9 +1123,10 @@ end
const SubCSet{S} = Subobject{<:StructCSet{S}}
const SubACSet{S} = Subobject{<:StructACSet{S}}

# Componentwise subobjects
# Componentwise subobjects: coerce VarFunctions to FinFunctions
components(A::SubACSet{S}) where S =
NamedTuple(k => Subobject(vs) for (k,vs) in pairs(components(hom(A)))
NamedTuple(k => Subobject(k ob(S) ? vs : FinFunction(vs)) for (k,vs) in
pairs(components(hom(A)))
)

force(A::SubACSet) = Subobject(force(hom(A)))
Expand Down
2 changes: 1 addition & 1 deletion src/categorical_algebra/FinSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ VarFunction(f::AbstractVector{Int},cod::Int) = VarFunction(FinFunction(f,cod))
VarFunction(f::FinDomFunction) = VarFunction{Union{}}(AttrVar.(collect(f)),codom(f))
VarFunction{T}(f::FinDomFunction,cod::FinSet) where T = VarFunction{T}(collect(f),cod)
FinFunction(f::VarFunction{T}) where T = FinFunction(
[f.fun(i) isa AttrVar ? f.fun(i).val : error("Cannot cast to FinFunction")
[f(i) isa AttrVar ? f(i).val : error("Cannot cast to FinFunction")
for i in dom(f)], f.codom)
FinDomFunction(f::VarFunction{T}) where T = f.fun
Base.length(f::AbsVarFunction{T}) where T = length(collect(f.fun))
Expand Down
50 changes: 28 additions & 22 deletions test/categorical_algebra/CSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -733,29 +733,35 @@ X = @acset VES begin V=6; E=5; Label=5
src=[1,2,3,4,4]; tgt=[3,3,4,5,6];
vlabel=[:a,:b,:c,:d,:e,:f]; elabel=AttrVar.(1:5)
end
A, B = Subobject(X, V=1:4, E=1:3, Label=1:3), Subobject(X, V=3:6, E=3:5, Label=3:5)
@test A B |> force == Subobject(X, V=3:4, E=3:3, Label=3:3) |> force
expected = @acset VES begin V=2; E=1; Label=1;
src=1; tgt=2; vlabel=[:c,:d]; elabel=[AttrVar(1)]
end
@test is_isomorphic(dom(hom(A B )), expected)
@test A B |> force == Subobject(X, V=1:6, E=1:5, Label=1:5) |> force
@test (X) |> force == A B |> force
@test (X) |> force == Subobject(X, V=1:0, E=1:0, Label=1:0) |> force
@test force(implies(A, B)) == force(¬(A) B)
@test ¬(A B) == ¬(A) ¬(B)
@test ¬(A B) != ¬(A) B
@test (A implies(A,B)) == B (A implies(A,B))
@test (B implies(B,A)) == A (B implies(B,A))
@test ¬(A (¬B)) == ¬(A) ¬(¬(B))
@test ¬(A (¬B)) == ¬(A) B
@test A ¬(¬(A)) == ¬(¬(A))
@test implies((AB), A) == AB
@test dom(hom(subtract(A,B))) == @acset VES begin V=3; E=2; Label=2
src=[1,2]; tgt=3; vlabel=[:a,:b,:c]; elabel=AttrVar.(1:2)
end

@test nv(dom(hom(~A))) == 3
A′ = Subobject(X, V=1:4, E=1:3, Label=1:3) # component-wise representation
B′ = Subobject(X, V=3:6, E=3:5, Label=3:5)
A′′, B′′ = Subobject.(hom.([A′,B′])) # hom representation

for (A,B) in [A′=>B′, A′′ =>B′′]
@test A B |> force == Subobject(X, V=3:4, E=3:3, Label=3:3) |> force
expected = @acset VES begin V=2; E=1; Label=1;
src=1; tgt=2; vlabel=[:c,:d]; elabel=[AttrVar(1)]
end
@test is_isomorphic(dom(hom(A B )), expected)
@test A B |> force == Subobject(X, V=1:6, E=1:5, Label=1:5) |> force
@test (X) |> force == A B |> force
@test (X) |> force == Subobject(X, V=1:0, E=1:0, Label=1:0) |> force
@test force(implies(A, B)) == force(¬(A) B)
@test ¬(A B) == ¬(A) ¬(B)
@test ¬(A B) != ¬(A) B
@test (A implies(A,B)) == B (A implies(A,B))
@test (B implies(B,A)) == A (B implies(B,A))
@test ¬(A (¬B)) == ¬(A) ¬(¬(B))
@test ¬(A (¬B)) == ¬(A) B
@test A ¬(¬(A)) == ¬(¬(A))
@test implies((AB), A) == AB
@test dom(hom(subtract(A,B))) == @acset VES begin V=3; E=2; Label=2
src=[1,2]; tgt=3; vlabel=[:a,:b,:c]; elabel=AttrVar.(1:2)
end

@test nv(dom(hom(~A))) == 3
end

# Limits of CSetTransformations between ACSets
#---------------------------------------------
Expand Down

0 comments on commit 66f1f40

Please sign in to comment.