Given finite sets and , a corelation is an Equivalence Relation on (drawn as dashed loops encircling equivalent elements). is the Category with finite sets as objects and corelations as morphisms; the composite of and relates two elements of iff one can travel from one to the other staying within equivalence classes of or . Formally: — push both relations forward to , take the join (transitive closure of the union) in the preorder of equivalence relations, and pull back to (using the pushforward and pullback of §1.4).
Sources: 7 Sketches Example 4.61, Exercise 4.62, footnote 2; Example 6.64 ( as a Hypergraph Category).
is a Symmetric Monoidal Category under and is compact closed with every finite set its own dual: the unit and the counit are both the equivalence relation on whose parts are the pairs ; the snake equations hold because composing two such pairings along the middle copy of yields the pairing again (7S Exercise 4.62 for ). Corelations are the “connectivity” of cospans of finite sets (a cospan induces the equivalence “same image in ”), and is the prototypical Hypergraph Category used for electrical circuits: a corelation says which terminals are wired together.
Docs: Limits & colimits
# corelations A → B as equivalence relations on A ⊔ B (elements 1..nA are A, nA+1..nA+nB are B),
# composed by union-find on A ⊔ B ⊔ C and restriction to A ⊔ C
using DataStructures
struct Corel
nA::Int; nB::Int
pairs::Vector{Tuple{Int,Int}} # generating pairs of the equivalence relation
end
function compose(α::Corel, β::Corel)
n = α.nA + α.nB + β.nB
uf = IntDisjointSets(n)
for (x, y) in α.pairs; union!(uf, x, y); end
for (x, y) in β.pairs; union!(uf, x + α.nA, y + α.nA); end # B ⊔ C sits after A
keep = vcat(1:α.nA, α.nA + α.nB + 1 : n) # restrict to A ⊔ C
relabel = Dict(x => i for (i, x) in enumerate(keep))
pairs = [(relabel[x], relabel[y]) for x in keep for y in keep if x < y && in_same_set(uf, x, y)]
Corel(α.nA, β.nB, pairs)
end
# the unit/counit corelation on A = 3: pair (a,1) with (a,2)
η3 = Corel(0, 6, [(1, 4), (2, 5), (3, 6)]) # ∅ → 3 ⊔ 3
ε3 = Corel(6, 0, [(1, 4), (2, 5), (3, 6)]) # 3 ⊔ 3 → ∅-- a corelation A -> B as a partition of Either a b; composition = join of partitions then restrict
type Corel a b = [[Either a b]]