definition example

Let be a Category. Its opposite has the same objects, , and hom-sets ; identities are as in and composition is reversed: . “Take any category you already have and reverse all its morphisms; the result is again a category.”

Sources: 7 Sketches Example 3.27, Exercise 3.101, Definition 3.102; DaoFP §8.1 (“Opposite categories”), §5.2 (“Duality”); Kittenlab Lecture 13 (“Duals”); CTfS Definition 4.6.1.1, Lemma 4.6.1.4, Example 4.6.1.6

Docs: Categories & functors — Kittenlab Lecture 13

Builds on: Category (Category) — run that note’s Julia code first.

# Kittenlab-style: the opposite of any Category value
struct OppositeCat{Ob,Hom,C<:Category{Ob,Hom}} <: Category{Ob,Hom}
  c::C
end
Categories.dom(o::OppositeCat, f) = codom(o.c, f)
Categories.codom(o::OppositeCat, f) = dom(o.c, f)
Categories.compose(o::OppositeCat, f, g) = compose(o.c, g, f)    # reversed
Categories.id(o::OppositeCat, x) = id(o.c, x)

Catlab version (run in a fresh Julia session — Catlab exports its own compose, id, FinFunction, …):

# Catlab: `op(C)` for a FinCat, and `op` on presentations/GAT expressions
using Catlab
#check CategoryTheory.Opposite      -- Cᵒᵖ, with objects `op X` and morphisms `f.op`
#check @CategoryTheory.Functor.op   -- F.op : Cᵒᵖ ⥤ Dᵒᵖ
example (C : Type) [CategoryTheory.Category C] (X Y : C) (f : X ⟶ Y) :
    (CategoryTheory.Opposite.op Y ⟶ CategoryTheory.Opposite.op X) := f.op
-- Data.Functor.Contravariant / Control.Category: the opposite of a category
newtype Op cat a b = Op (cat b a)
 
instance Category cat => Category (Op cat) where
  id = Op id
  Op g . Op f = Op (f . g)      -- reversed composition