Skip to content

Commit

Permalink
ENH: Wiring diagrams for bicategories of relations (#49).
Browse files Browse the repository at this point in the history
  • Loading branch information
epatters committed Jan 5, 2020
1 parent 5294f55 commit 86b0f02
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/wiring_diagrams/Algebraic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ module AlgebraicWiringDiagrams
export Ports, Junction, PortOp, BoxOp,
functor, dom, codom, id, compose, , , otimes, , munit, braid, permute,
mcopy, delete, Δ, ◇, mmerge, create, ∇, □, dual, dunit, dcounit, mate, dagger,
ocompose, junction_diagram, junction_caps, junction_cups, add_junctions,
add_junctions!, rem_junctions, merge_junctions
meet, top, ocompose, junction_diagram, junction_caps, junction_cups,
add_junctions, add_junctions!, rem_junctions, merge_junctions

using AutoHashEquals
using LightGraphs

using ...GAT, ...Doctrines
import ...Doctrines: dom, codom, id, compose, , , otimes, , munit, braid,
mcopy, delete, Δ, ◇, mmerge, create, ∇, □, dual, dunit, dcounit, mate, dagger
mcopy, delete, Δ, ◇, mmerge, create, ∇, □, dual, dunit, dcounit, mate, dagger,
meet, top
import ...Syntax: functor
using ..WiringDiagramCore, ..WiringLayers
import ..WiringDiagramCore: Box, WiringDiagram, input_ports, output_ports
Expand Down Expand Up @@ -269,6 +270,25 @@ dagger(f::WiringDiagram{DaggerCompactCategory.Hom}) =
mate(f::WiringDiagram{DaggerCompactCategory.Hom}) =
functor(f, dual, mate, contravariant=true, monoidal_contravariant=true)

# Bicategory of relations
#------------------------

mcopy(A::Ports{BicategoryRelations.Hom}, n::Int) = junctioned_mcopy(A, n)
mmerge(A::Ports{BicategoryRelations.Hom}, n::Int) = junctioned_mmerge(A, n)
delete(A::Ports{BicategoryRelations.Hom}) = junctioned_delete(A)
create(A::Ports{BicategoryRelations.Hom}) = junctioned_create(A)

dagger(f::WiringDiagram{BicategoryRelations.Hom}) =
functor(f, identity, dagger, contravariant=true)

dunit(A::Ports{BicategoryRelations.Hom}) = junction_caps(A)
dcounit(A::Ports{BicategoryRelations.Hom}) = junction_cups(A)

meet(f::WiringDiagram{BicategoryRelations.Hom}, g::WiringDiagram{BicategoryRelations.Hom}) =
compose(mcopy(dom(f)), otimes(f,g), mmerge(codom(f)))
top(A::Ports{BicategoryRelations.Hom}, B::Ports{BicategoryRelations.Hom}) =
compose(delete(A), create(B))

# Operadic interface
####################

Expand Down
17 changes: 17 additions & 0 deletions test/wiring_diagrams/Algebraic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,23 @@ g = singleton_diagram(CompactClosedCategory.Hom, Box(:g,[:B],[:A]))
@test mate(mate(compose(f,g))) == compose(f,g)
@test mate(mate(otimes(f,g))) == otimes(f,g)

# Bicategory of relations
#------------------------

A, B = [ Ports{BicategoryRelations.Hom}([sym]) for sym in [:A, :B] ]
R = singleton_diagram(BicategoryRelations.Hom, Box(:R,[:A],[:B]))
S = singleton_diagram(BicategoryRelations.Hom, Box(:S,[:A],[:B]))

# Domains and codomains
@test dom(meet(R,S)) == A
@test codom(meet(R,S)) == B
@test dom(top(A,B)) == A
@test codom(top(A,B)) == B

# Units and counits
@test dunit(A) == merge_junctions(compose(create(A), mcopy(A)))
@test dcounit(A) == merge_junctions(compose(mmerge(A), delete(A)))

# Operadic interface
####################

Expand Down

0 comments on commit 86b0f02

Please sign in to comment.