Composition and Category instance
Now we have some notion of objects and morphisms between them, we can move on to defining composition of morphisms.
def comp : {X Y Z : BoolCat} → BCHom Y Z → BCHom X Y → BCHom X Z
| _, _, _, id _, f => f
| _, _, _, f, id _ => f
| _, _, _, swapInv, swap => id _
| _, _, _, swap, swapInv => id _
This defines composition by pattern matching on the possible morphism combinations. Note that we have to explicitly handle the cases where we compose \(\texttt {swap}\) and \(\texttt {swapInv}\) to get the identity morphism on the respective objects. To construct our category we have to provide proofs for the category axioms, namely associativity and identity.
@[simp] theorem id_comp' {X Y : BoolCat} (f : BCHom X Y)
: comp (id Y) f = f := by
cases f <;> rfl
@[simp] theorem comp_id' {X Y : BoolCat} (f : BCHom X Y)
: comp f (id X) = f := by
cases f <;> rfl
theorem assoc' (f : BCHom W X) (g : BCHom X Y) (h : BCHom Y Z) :
comp h (comp g f) = comp (comp h g) f := by
cases f <;> cases g <;> cases h <;> rfl
With all this in place we can finally define our category instance:
instance : Category BoolCat where
-- The data
Hom := BCHom
id := BCHom. id
comp := fun f g => BCHom. comp g f
-- Category laws
id_comp := fun f => BCHom.comp_id' f
comp_id := fun f => BCHom.id_comp' f
assoc := fun f g h => BCHom.assoc' f g h