# Natural isomorphisms between functors between categories

Content created by Fredrik Bakke and Egbert Rijke.

Created on 2023-09-27.

module category-theory.natural-isomorphisms-functors-categories where

Imports
open import category-theory.categories
open import category-theory.functors-categories
open import category-theory.isomorphisms-in-categories
open import category-theory.natural-isomorphisms-functors-precategories
open import category-theory.natural-transformations-functors-categories

open import foundation.dependent-pair-types
open import foundation.equivalences
open import foundation.function-types
open import foundation.homotopies
open import foundation.identity-types
open import foundation.propositions
open import foundation.sets
open import foundation.subtypes
open import foundation.universe-levels


## Idea

A natural isomorphism γ from functor F : C → D to G : C → D is a natural transformation from F to G such that the morphism γ F : hom (F x) (G x) is an isomorphism, for every object x in C.

## Definition

### Families of isomorphisms between functors

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G : functor-Category C D)
where

iso-family-functor-Category : UU (l1 ⊔ l4)
iso-family-functor-Category =
iso-family-functor-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)


### The predicate of being an isomorphism in a category

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G : functor-Category C D)
where

is-natural-isomorphism-Category :
natural-transformation-Category C D F G → UU (l1 ⊔ l4)
is-natural-isomorphism-Category =
is-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G : functor-Category C D)
(f : natural-transformation-Category C D F G)
where

hom-inv-family-is-natural-isomorphism-Category :
is-natural-isomorphism-Category C D F G f →
hom-family-functor-Category C D G F
hom-inv-family-is-natural-isomorphism-Category =
hom-inv-family-is-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)
( f)

is-section-hom-inv-family-is-natural-isomorphism-Category :
(is-iso-f : is-natural-isomorphism-Category C D F G f) →
(x : obj-Category C) →
comp-hom-Category D
( hom-family-natural-transformation-Category C D F G f x)
( hom-inv-is-iso-Category D (is-iso-f x)) ＝
id-hom-Category D
is-section-hom-inv-family-is-natural-isomorphism-Category =
is-section-hom-inv-family-is-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)
( f)

is-retraction-hom-inv-family-is-natural-isomorphism-Category :
(is-iso-f : is-natural-isomorphism-Category C D F G f) →
(x : obj-Category C) →
comp-hom-Category D
( hom-inv-is-iso-Category D (is-iso-f x))
( hom-family-natural-transformation-Category C D F G f x) ＝
id-hom-Category D
is-retraction-hom-inv-family-is-natural-isomorphism-Category =
is-retraction-hom-inv-family-is-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)
( f)

iso-family-is-natural-isomorphism-Category :
is-natural-isomorphism-Category C D F G f →
iso-family-functor-Category C D F G
iso-family-is-natural-isomorphism-Category =
iso-family-is-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)
( f)

inv-iso-family-is-natural-isomorphism-Category :
is-natural-isomorphism-Category C D F G f →
iso-family-functor-Category C D G F
inv-iso-family-is-natural-isomorphism-Category =
inv-iso-family-is-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)
( f)


### Natural isomorphisms in a category

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G : functor-Category C D)
where

natural-isomorphism-Category : UU (l1 ⊔ l2 ⊔ l4)
natural-isomorphism-Category =
natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G : functor-Category C D)
(f : natural-isomorphism-Category C D F G)
where

natural-transformation-natural-isomorphism-Category :
natural-transformation-Category C D F G
natural-transformation-natural-isomorphism-Category =
natural-transformation-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)
( f)

hom-family-natural-isomorphism-Category :
hom-family-functor-Category C D F G
hom-family-natural-isomorphism-Category =
hom-family-natural-transformation-Category C D F G
( natural-transformation-natural-isomorphism-Category)

coherence-square-natural-isomorphism-Category :
is-natural-transformation-Category C D F G
( hom-family-natural-transformation-Category C D F G
( natural-transformation-natural-isomorphism-Category))
coherence-square-natural-isomorphism-Category =
naturality-natural-transformation-Category C D F G
( natural-transformation-natural-isomorphism-Category)

is-natural-isomorphism-natural-isomorphism-Category :
is-natural-isomorphism-Category C D F G
( natural-transformation-natural-isomorphism-Category)
is-natural-isomorphism-natural-isomorphism-Category = pr2 f

hom-inv-family-natural-isomorphism-Category :
hom-family-functor-Category C D G F
hom-inv-family-natural-isomorphism-Category =
hom-inv-family-is-natural-isomorphism-Category C D F G
( natural-transformation-natural-isomorphism-Category)
( is-natural-isomorphism-natural-isomorphism-Category)

is-section-hom-inv-family-natural-isomorphism-Category :
(x : obj-Category C) →
comp-hom-Category D
( hom-family-natural-isomorphism-Category x)
( hom-inv-family-natural-isomorphism-Category x) ＝
id-hom-Category D
is-section-hom-inv-family-natural-isomorphism-Category =
is-section-hom-inv-family-is-natural-isomorphism-Category C D F G
( natural-transformation-natural-isomorphism-Category)
( is-natural-isomorphism-natural-isomorphism-Category)

is-retraction-hom-inv-family-natural-isomorphism-Category :
(x : obj-Category C) →
comp-hom-Category D
( hom-inv-family-natural-isomorphism-Category x)
( hom-family-natural-isomorphism-Category x) ＝
id-hom-Category D
is-retraction-hom-inv-family-natural-isomorphism-Category =
is-retraction-hom-inv-family-is-natural-isomorphism-Category C D F G
( natural-transformation-natural-isomorphism-Category)
( is-natural-isomorphism-natural-isomorphism-Category)

iso-family-natural-isomorphism-Category :
iso-family-functor-Category C D F G
iso-family-natural-isomorphism-Category =
iso-family-is-natural-isomorphism-Category C D F G
( natural-transformation-natural-isomorphism-Category)
( is-natural-isomorphism-natural-isomorphism-Category)

inv-iso-family-natural-isomorphism-Category :
iso-family-functor-Category C D G F
inv-iso-family-natural-isomorphism-Category =
inv-iso-family-is-natural-isomorphism-Category C D F G
( natural-transformation-natural-isomorphism-Category)
( is-natural-isomorphism-natural-isomorphism-Category)


## Examples

### The identity natural isomorphism

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
where

id-natural-isomorphism-Category :
(F : functor-Category C D) → natural-isomorphism-Category C D F F
id-natural-isomorphism-Category =
id-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)


### Equalities induce natural isomorphisms

An equality between functors F and G gives rise to a natural isomorphism between them. This is because, by the J-rule, it is enough to construct a natural isomorphism given refl : F ＝ F, from F to itself. We take the identity natural transformation as such an isomorphism.

natural-isomorphism-eq-Category :
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G : functor-Category C D) →
F ＝ G → natural-isomorphism-Category C D F G
natural-isomorphism-eq-Category C D F .F refl =
id-natural-isomorphism-Category C D F


## Propositions

### Being a natural isomorphism is a proposition

That a natural transformation is a natural isomorphism is a proposition. This follows from the fact that being an isomorphism is a proposition.

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G : functor-Category C D)
where

is-prop-is-natural-isomorphism-Category :
(f : natural-transformation-Category C D F G) →
is-prop (is-natural-isomorphism-Category C D F G f)
is-prop-is-natural-isomorphism-Category =
is-prop-is-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)

is-natural-isomorphism-prop-hom-Category :
(f : natural-transformation-Category C D F G) → Prop (l1 ⊔ l4)
is-natural-isomorphism-prop-hom-Category =
is-natural-isomorphism-prop-hom-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)


### Equality of natural isomorphisms is equality of their underlying natural transformations

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G : functor-Category C D)
where

extensionality-natural-isomorphism-Category :
(f g : natural-isomorphism-Category C D F G) →
(f ＝ g) ≃
( hom-family-natural-isomorphism-Category C D F G f ~
hom-family-natural-isomorphism-Category C D F G g)
extensionality-natural-isomorphism-Category =
extensionality-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)

eq-eq-natural-transformation-natural-isomorphism-Category :
(f g : natural-isomorphism-Category C D F G) →
( natural-transformation-natural-isomorphism-Category C D F G f ＝
natural-transformation-natural-isomorphism-Category C D F G g) →
f ＝ g
eq-eq-natural-transformation-natural-isomorphism-Category f g =
eq-type-subtype (is-natural-isomorphism-prop-hom-Category C D F G)

eq-htpy-hom-family-natural-isomorphism-Category :
(f g : natural-isomorphism-Category C D F G) →
( hom-family-natural-isomorphism-Category C D F G f ~
hom-family-natural-isomorphism-Category C D F G g) →
f ＝ g
eq-htpy-hom-family-natural-isomorphism-Category =
eq-htpy-hom-family-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)


### The type of natural isomorphisms form a set

The type of natural isomorphisms between functors F and G is a subtype of the set natural-transformation F G since being an isomorphism is a proposition.

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G : functor-Category C D)
where

is-set-natural-isomorphism-Category :
is-set (natural-isomorphism-Category C D F G)
is-set-natural-isomorphism-Category =
is-set-type-subtype
( is-natural-isomorphism-prop-hom-Category C D F G)
( is-set-natural-transformation-Category C D F G)

natural-isomorphism-set-Category : Set (l1 ⊔ l2 ⊔ l4)
pr1 natural-isomorphism-set-Category =
natural-isomorphism-Category C D F G
pr2 natural-isomorphism-set-Category =
is-set-natural-isomorphism-Category


### Inverses of natural isomorphisms are natural isomorphisms

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G : functor-Category C D)
(f : natural-transformation-Category C D F G)
where

natural-transformation-inv-is-natural-isomorphism-Category :
is-natural-isomorphism-Category C D F G f →
natural-transformation-Category C D G F
natural-transformation-inv-is-natural-isomorphism-Category =
natural-transformation-inv-is-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)
( f)

is-section-natural-transformation-inv-is-natural-isomorphism-Category :
(is-iso-f : is-natural-isomorphism-Category C D F G f) →
comp-natural-transformation-Category C D G F G
( f)
( natural-transformation-inv-is-natural-isomorphism-Category
( is-iso-f)) ＝
id-natural-transformation-Category C D G
is-section-natural-transformation-inv-is-natural-isomorphism-Category
is-iso-f =
eq-htpy-hom-family-natural-transformation-Category C D G G _ _
( is-section-hom-inv-is-iso-Category D ∘ is-iso-f)

is-retraction-natural-transformation-inv-is-natural-isomorphism-Category :
(is-iso-f : is-natural-isomorphism-Category C D F G f) →
comp-natural-transformation-Category C D F G F
( natural-transformation-inv-is-natural-isomorphism-Category is-iso-f)
( f) ＝
id-natural-transformation-Category C D F
is-retraction-natural-transformation-inv-is-natural-isomorphism-Category
is-iso-f =
eq-htpy-hom-family-natural-transformation-Category C D F F _ _
( is-retraction-hom-inv-is-iso-Category D ∘ is-iso-f)

is-natural-isomorphism-inv-is-natural-isomorphism-Category :
(is-iso-f : is-natural-isomorphism-Category C D F G f) →
is-natural-isomorphism-Category C D G F
( natural-transformation-inv-is-natural-isomorphism-Category is-iso-f)
is-natural-isomorphism-inv-is-natural-isomorphism-Category is-iso-f =
is-iso-inv-is-iso-Category D ∘ is-iso-f


### Inverses of natural isomorphisms

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G : functor-Category C D)
(f : natural-isomorphism-Category C D F G)
where

natural-transformation-inv-natural-isomorphism-Category :
natural-transformation-Category C D G F
natural-transformation-inv-natural-isomorphism-Category =
natural-transformation-inv-is-natural-isomorphism-Category C D F G
( natural-transformation-natural-isomorphism-Category C D F G f)
( is-natural-isomorphism-natural-isomorphism-Category C D F G f)

is-section-natural-transformation-inv-natural-isomorphism-Category :
( comp-natural-transformation-Category C D G F G
( natural-transformation-natural-isomorphism-Category C D F G f)
( natural-transformation-inv-natural-isomorphism-Category)) ＝
( id-natural-transformation-Category C D G)
is-section-natural-transformation-inv-natural-isomorphism-Category =
is-section-natural-transformation-inv-is-natural-isomorphism-Category
C D F G
( natural-transformation-natural-isomorphism-Category C D F G f)
( is-natural-isomorphism-natural-isomorphism-Category C D F G f)

is-retraction-natural-transformation-inv-natural-isomorphism-Category :
( comp-natural-transformation-Category C D F G F
( natural-transformation-inv-natural-isomorphism-Category)
( natural-transformation-natural-isomorphism-Category C D F G f)) ＝
( id-natural-transformation-Category C D F)
is-retraction-natural-transformation-inv-natural-isomorphism-Category =
is-retraction-natural-transformation-inv-is-natural-isomorphism-Category
C D F G
( natural-transformation-natural-isomorphism-Category C D F G f)
( is-natural-isomorphism-natural-isomorphism-Category C D F G f)

is-natural-isomorphism-inv-natural-isomorphism-Category :
is-natural-isomorphism-Category C D G F
( natural-transformation-inv-natural-isomorphism-Category)
is-natural-isomorphism-inv-natural-isomorphism-Category =
is-natural-isomorphism-inv-is-natural-isomorphism-Category C D F G
( natural-transformation-natural-isomorphism-Category C D F G f)
( is-natural-isomorphism-natural-isomorphism-Category C D F G f)

inv-natural-isomorphism-Category :
natural-isomorphism-Category C D G F
pr1 inv-natural-isomorphism-Category =
natural-transformation-inv-natural-isomorphism-Category
pr2 inv-natural-isomorphism-Category =
is-natural-isomorphism-inv-natural-isomorphism-Category


### Natural isomorphisms are closed under composition

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G H : functor-Category C D)
(g : natural-transformation-Category C D G H)
(f : natural-transformation-Category C D F G)
where

is-natural-isomorphism-comp-is-natural-isomorphism-Category :
is-natural-isomorphism-Category C D G H g →
is-natural-isomorphism-Category C D F G f →
is-natural-isomorphism-Category C D F H
( comp-natural-transformation-Category C D F G H g f)
is-natural-isomorphism-comp-is-natural-isomorphism-Category
is-iso-g is-iso-f x =
is-iso-comp-is-iso-Category D (is-iso-g x) (is-iso-f x)


### The composition operation on natural isomorphisms

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G H : functor-Category C D)
(g : natural-isomorphism-Category C D G H)
(f : natural-isomorphism-Category C D F G)
where

hom-comp-natural-isomorphism-Category :
natural-transformation-Category C D F H
hom-comp-natural-isomorphism-Category =
comp-natural-transformation-Category C D F G H
( natural-transformation-natural-isomorphism-Category C D G H g)
( natural-transformation-natural-isomorphism-Category C D F G f)

is-natural-isomorphism-comp-natural-isomorphism-Category :
is-natural-isomorphism-Category C D F H
( hom-comp-natural-isomorphism-Category)
is-natural-isomorphism-comp-natural-isomorphism-Category =
is-natural-isomorphism-comp-is-natural-isomorphism-Category C D F G H
( natural-transformation-natural-isomorphism-Category C D G H g)
( natural-transformation-natural-isomorphism-Category C D F G f)
( is-natural-isomorphism-natural-isomorphism-Category C D G H g)
( is-natural-isomorphism-natural-isomorphism-Category C D F G f)

comp-natural-isomorphism-Category : natural-isomorphism-Category C D F H
pr1 comp-natural-isomorphism-Category =
hom-comp-natural-isomorphism-Category
pr2 comp-natural-isomorphism-Category =
is-natural-isomorphism-comp-natural-isomorphism-Category

natural-transformation-inv-comp-natural-isomorphism-Category :
natural-transformation-Category C D H F
natural-transformation-inv-comp-natural-isomorphism-Category =
natural-transformation-inv-natural-isomorphism-Category C D F H
( comp-natural-isomorphism-Category)

is-section-inv-comp-natural-isomorphism-Category :
( comp-natural-transformation-Category C D H F H
( hom-comp-natural-isomorphism-Category)
( natural-transformation-inv-comp-natural-isomorphism-Category)) ＝
( id-natural-transformation-Category C D H)
is-section-inv-comp-natural-isomorphism-Category =
is-section-natural-transformation-inv-natural-isomorphism-Category
C D F H comp-natural-isomorphism-Category

is-retraction-inv-comp-natural-isomorphism-Category :
( comp-natural-transformation-Category C D F H F
( natural-transformation-inv-comp-natural-isomorphism-Category)
( hom-comp-natural-isomorphism-Category)) ＝
( id-natural-transformation-Category C D F)
is-retraction-inv-comp-natural-isomorphism-Category =
is-retraction-natural-transformation-inv-natural-isomorphism-Category
C D F H comp-natural-isomorphism-Category


### Groupoid laws of natural isomorphisms in categories

#### Composition of natural isomorphisms satisfies the unit laws

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G : functor-Category C D)
(f : natural-isomorphism-Category C D F G)
where

left-unit-law-comp-natural-isomorphism-Category :
comp-natural-isomorphism-Category C D F G G
( id-natural-isomorphism-Category C D G)
( f) ＝
f
left-unit-law-comp-natural-isomorphism-Category =
left-unit-law-comp-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)
( f)

right-unit-law-comp-natural-isomorphism-Category :
comp-natural-isomorphism-Category C D F F G f
( id-natural-isomorphism-Category C D F) ＝
f
right-unit-law-comp-natural-isomorphism-Category =
right-unit-law-comp-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)
( f)


#### Composition of natural isomorphisms is associative

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G H I : functor-Category C D)
(f : natural-isomorphism-Category C D F G)
(g : natural-isomorphism-Category C D G H)
(h : natural-isomorphism-Category C D H I)
where

associative-comp-natural-isomorphism-Category :
( comp-natural-isomorphism-Category C D F G I
( comp-natural-isomorphism-Category C D G H I h g)
( f)) ＝
( comp-natural-isomorphism-Category C D F H I h
( comp-natural-isomorphism-Category C D F G H g f))
associative-comp-natural-isomorphism-Category =
associative-comp-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)
( H)
( I)
( f)
( g)
( h)


#### Composition of natural isomorphisms satisfies inverse laws

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G : functor-Category C D)
(f : natural-isomorphism-Category C D F G)
where

left-inverse-law-comp-natural-isomorphism-Category :
( comp-natural-isomorphism-Category C D F G F
( inv-natural-isomorphism-Category C D F G f)
( f)) ＝
( id-natural-isomorphism-Category C D F)
left-inverse-law-comp-natural-isomorphism-Category =
left-inverse-law-comp-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)
( f)

right-inverse-law-comp-natural-isomorphism-Category :
( comp-natural-isomorphism-Category C D G F G
( f)
( inv-natural-isomorphism-Category C D F G f)) ＝
( id-natural-isomorphism-Category C D G)
right-inverse-law-comp-natural-isomorphism-Category =
right-inverse-law-comp-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)
( f)


### When the type of natural transformations is a proposition, the type of natural isomorphisms is a proposition

The type of natural isomorphisms between functors F and G is a subtype of natural-transformation F G, so when this type is a proposition, then the type of natural isomorphisms from F to G form a proposition.

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G : functor-Category C D)
where

is-prop-natural-isomorphism-Category :
is-prop (natural-transformation-Category C D F G) →
is-prop (natural-isomorphism-Category C D F G)
is-prop-natural-isomorphism-Category =
is-prop-natural-isomorphism-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)

natural-isomorphism-prop-Category :
is-prop (natural-transformation-Category C D F G) → Prop (l1 ⊔ l2 ⊔ l4)
natural-isomorphism-prop-Category =
natural-isomorphism-prop-Precategory
( precategory-Category C)
( precategory-Category D)
( F)
( G)


### Functoriality of natural-isomorphism-eq

module _
{l1 l2 l3 l4 : Level}
(C : Category l1 l2)
(D : Category l3 l4)
(F G H : functor-Category C D)
where

preserves-concat-natural-isomorphism-eq-Category :
(p : F ＝ G) (q : G ＝ H) →
natural-isomorphism-eq-Category C D F H (p ∙ q) ＝
comp-natural-isomorphism-Category C D F G H
( natural-isomorphism-eq-Category C D G H q)
( natural-isomorphism-eq-Category C D F G p)
preserves-concat-natural-isomorphism-eq-Category refl q =
inv
( right-unit-law-comp-natural-isomorphism-Category C D F H
( natural-isomorphism-eq-Category C D G H q))