module Cat.Internal.Opposite {o β„“} {C : Precategory o β„“} where

Opposites of internal categoriesπŸ”—

We can take the opposite of an internal category, by flipping the source and target morphisms. We begin by defining a little helper function that flips internal morphisms.

op-ihom
  : βˆ€ {Cβ‚€ C₁ Ξ“} {src tgt : Hom C₁ Cβ‚€} {x y : Hom Ξ“ Cβ‚€}
  β†’ Internal-hom src tgt x y
  β†’ Internal-hom tgt src y x
op-ihom f .ihom = f .ihom
op-ihom f .has-src = f .has-tgt
op-ihom f .has-tgt = f .has-src

op-ihom-nat
  : βˆ€ {Cβ‚€ C₁ Ξ“ Ξ”} {src tgt : Hom C₁ Cβ‚€} {x y : Hom Ξ” Cβ‚€}
  β†’ (f : Internal-hom src tgt x y)
  β†’ (Οƒ : Hom Ξ“ Ξ”)
  β†’ op-ihom f [ Οƒ ] ≑ op-ihom (f [ Οƒ ])
op-ihom-nat f _ = Internal-hom-path refl

Showing that this operation yields an internal category is a routine calculation.

Internal-cat-on-opi
  : βˆ€ {Cβ‚€ C₁} {src tgt : Hom C₁ Cβ‚€}
  β†’ Internal-cat-on src tgt β†’  Internal-cat-on tgt src
Internal-cat-on-opi β„‚ = icat-opi-on  where
  open Internal-cat-on
  module β„‚ = Internal-cat-on β„‚

  icat-opi-on : Internal-cat-on _ _
  icat-opi-on .idi x = op-ihom (β„‚.idi x)
  icat-opi-on ._∘i_ f g = op-ihom (op-ihom g β„‚.∘i op-ihom f)
  icat-opi-on .idli f = ap op-ihom (β„‚.idri _)
  icat-opi-on .idri f = ap op-ihom (β„‚.idli _)
  icat-opi-on .associ f g h = ap op-ihom (sym (β„‚.associ _ _ _))
  icat-opi-on .idi-nat Οƒ =
    op-ihom-nat (β„‚.idi _) Οƒ βˆ™ ap op-ihom (β„‚.idi-nat Οƒ)
  icat-opi-on .∘i-nat f g Οƒ =
    op-ihom-nat (op-ihom g β„‚.∘i op-ihom f) Οƒ
    βˆ™ ap op-ihom ((β„‚.∘i-nat (op-ihom g) (op-ihom f) Οƒ)
      βˆ™ apβ‚‚ β„‚._∘i_ (op-ihom-nat g Οƒ) (op-ihom-nat f Οƒ))

_^opi : Internal-cat β†’ Internal-cat
β„‚ ^opi = op-icat where
  open Internal-cat

  op-icat : Internal-cat
  op-icat .Cβ‚€ = β„‚ .Cβ‚€
  op-icat .C₁ = β„‚ .C₁
  op-icat .src = β„‚ .tgt
  op-icat .tgt = β„‚ .src
  op-icat .has-internal-cat = Internal-cat-on-opi (β„‚ .has-internal-cat)

infixl 60 _^opi