module Cat.Cartesian where

Cartesian categoriesπŸ”—

A Cartesian category is one that admits all binary products and a terminal object, hence all finite products.

record Cartesian-category {o β„“} (C : Precategory o β„“) : Type (o βŠ” β„“) where
  field
    products : has-products C
    terminal : Terminal C

If is a functor between Cartesian categories, we can define a product comparison map which is an isomorphism precisely when preserves products, in the coherent sense that the image under of a product diagram in i.e.Β the span becomes a product diagram in We say that is a Cartesian functor if it preserves the terminal object, and its product comparison map is an isomorphism.

  product-comparison : βˆ€ a b β†’ D.Hom (F.β‚€ (a C.βŠ—β‚€ b)) (F.β‚€ a D.βŠ—β‚€ F.β‚€ b)
  product-comparison a b = D.⟨ F.₁ C.π₁ , F.₁ C.Ο€β‚‚ ⟩

  record Cartesian-functor : Type (o βŠ” o' βŠ” β„“ βŠ” β„“') where
    field
      pres-products : βˆ€ a b β†’ D.is-invertible (product-comparison a b)
      pres-terminal : is-terminal D (F.β‚€ C.top)

    image-is-product
      : βˆ€ {a b} β†’ is-product D {A = F.β‚€ a} {B = F.β‚€ b} (F.₁ C.π₁) (F.₁ C.Ο€β‚‚)
    image-is-product = is-product-iso-apex (pres-products _ _)
      D.Ο€β‚βˆ˜βŸ¨βŸ© D.Ο€β‚‚βˆ˜βŸ¨βŸ© D.has-is-product

We can establish some useful algebraic properties of the inverse of the comparison map, namely that composing it with the projections and recovers the product projections in This is a corollary of image-is-product.

    π₁inv : βˆ€ {a} {b} β†’ F.₁ C.π₁ D.∘ comparison.inv {a} {b} ≑ D.π₁
    π₁inv =
      F.₁ C.π₁ D.∘ comparison.inv                       β‰‘βŸ¨ apβ‚‚ D._∘_ refl (D.intror (sym (D.⟨⟩-unique (D.idr _) (D.idr _)))) βŸ©β‰‘
      F.₁ C.π₁ D.∘ comparison.inv D.∘ D.⟨ D.π₁ , D.Ο€β‚‚ ⟩ β‰‘βŸ¨ preserved.Ο€β‚βˆ˜βŸ¨βŸ© βŸ©β‰‘
      D.π₁                                              ∎

    Ο€β‚‚inv : βˆ€ {a} {b} β†’ F.₁ C.Ο€β‚‚ D.∘ comparison.inv {a} {b} ≑ D.Ο€β‚‚
    Ο€β‚‚inv =
      F.₁ C.Ο€β‚‚ D.∘ comparison.inv                       β‰‘βŸ¨ apβ‚‚ D._∘_ refl (D.intror (sym (D.⟨⟩-unique (D.idr _) (D.idr _)))) βŸ©β‰‘
      F.₁ C.Ο€β‚‚ D.∘ comparison.inv D.∘ D.⟨ D.π₁ , D.Ο€β‚‚ ⟩ β‰‘βŸ¨ preserved.Ο€β‚‚βˆ˜βŸ¨βŸ© βŸ©β‰‘
      D.Ο€β‚‚                                              ∎

Finally, we can show that, if each product comparison map is an isomorphism, then this becomes a natural isomorphism between the two functors obtained by respectively taking a product in and applying and applying and taking a product in

    comparison-nat : is-natural-transformation
      (D.Γ—-functor F∘ (F FΓ— F)) (F F∘ C.Γ—-functor)
      Ξ» (a , b) β†’ comparison.inv {a} {b}

    comparison-nat (a , b) (a' , b') (f , g) = Product.uniqueβ‚‚
      record { has-is-product = image-is-product }
      preserved.Ο€β‚βˆ˜βŸ¨βŸ© preserved.Ο€β‚‚βˆ˜βŸ¨βŸ©
      (F.extendl C.Ο€β‚βˆ˜βŸ¨βŸ© βˆ™ apβ‚‚ D._∘_ refl π₁inv)
      (F.extendl C.Ο€β‚‚βˆ˜βŸ¨βŸ© βˆ™ apβ‚‚ D._∘_ refl Ο€β‚‚inv)