{-# OPTIONS --without-K --safe #-}
open import Categories.Category using (Category; module Definitions)
module Categories.Morphism.HeterogeneousIdentity {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Relation.Binary.PropositionalEquality
import Categories.Morphism as Morphism
import Categories.Morphism.Reasoning.Iso as Reasoning
open Category C
open Definitions C
open Morphism C
open Reasoning C using (switch-tofromʳ)
hid : ∀ {A B} (p : A ≡ B) → A ⇒ B
hid {A} p = subst (A ⇒_) p id
hid-refl : ∀ {A : Obj} → hid refl ≈ id {A}
hid-refl = Equiv.refl
hid-trans : ∀ {A B C} (p : B ≡ C) (q : A ≡ B) →
hid p ∘ hid q ≈ hid (trans q p)
hid-trans refl refl = identityˡ
hid-symˡ : ∀ {A B} (p : A ≡ B) → hid (sym p) ∘ hid p ≈ id {A}
hid-symˡ refl = identityˡ
hid-symʳ : ∀ {A B} (p : A ≡ B) → hid p ∘ hid (sym p) ≈ id {B}
hid-symʳ refl = identityˡ
hid-sym-sym : ∀ {A B} (p : A ≡ B) → hid (sym (sym p)) ≈ hid p
hid-sym-sym refl = Equiv.refl
hid-iso : ∀ {A B} (p : A ≡ B) → Iso (hid p) (hid (sym p))
hid-iso p = record { isoˡ = hid-symˡ p ; isoʳ = hid-symʳ p }
hid-≅ : ∀ {A B} (p : A ≡ B) → A ≅ B
hid-≅ p = record { from = hid p ; to = hid (sym p) ; iso = hid-iso p }
hid-cong : ∀ {A B} {p q : A ≡ B} → p ≡ q → hid p ≈ hid q
hid-cong refl = Equiv.refl
hid-subst-dom : ∀ {A B C} (p : A ≡ B) (f : B ⇒ C) →
subst (_⇒ C) (sym p) f ≈ f ∘ hid p
hid-subst-dom refl f = Equiv.sym identityʳ
hid-subst-cod : ∀ {A B C} (f : A ⇒ B) (p : B ≡ C) →
subst (A ⇒_) p f ≈ hid p ∘ f
hid-subst-cod f refl = Equiv.sym identityˡ
hid-subst₂ : ∀ {A B C D} (p : A ≡ B) (q : C ≡ D) (f : A ⇒ C) →
subst₂ (_⇒_) p q f ≈ hid q ∘ f ∘ hid (sym p)
hid-subst₂ refl refl f = Equiv.sym (Equiv.trans identityˡ identityʳ)
hid-square : ∀ {A B C D} {f : A ⇒ B} {p : A ≡ C} {q : B ≡ D} {g : C ⇒ D} →
(subst₂ _⇒_ p q f ≈ g) →
CommutativeSquare f (hid p) (hid q) g
hid-square {f = f} {p} {q} {g} eq = switch-tofromʳ (hid-≅ p) (begin
(hid q ∘ f) ∘ hid (sym p) ≈⟨ assoc ⟩
hid q ∘ f ∘ hid (sym p) ≈˘⟨ hid-subst₂ p q f ⟩
subst₂ _⇒_ p q f ≈⟨ eq ⟩
g ∎)
where open HomReasoning