Equivalence-Induction

Martin Escardo 1st May 2020.

This is ported from the Midlands Graduate School 2019 lecture notes

 https://www.cs.bham.ac.uk/~mhe/HoTT-UF.in-Agda-Lecture-Notes/HoTT-UF-Agda.html
 https://github.com/martinescardo/HoTT-UF.Agda-Lecture-Notes


{-# OPTIONS --safe --without-K #-}

module MGS.Equivalence-Induction where

open import MGS.Univalence public
open import MGS.Solved-Exercises public

equiv-singleton-lemma : {X : ๐“ค ฬ‡ } {A : X โ†’ ๐“ฅ ฬ‡ } (x : X)
                        (f : (y : X) โ†’ x ๏ผ y โ†’ A y)
                      โ†’ ((y : X) โ†’ is-equiv (f y))
                      โ†’ is-singleton (ฮฃ A)

equiv-singleton-lemma {๐“ค} {๐“ฅ} {X} {A} x f i = ฮณ
 where
  e : (y : X) โ†’ (x ๏ผ y) โ‰ƒ A y
  e y = (f y , i y)

  d : singleton-type' x โ‰ƒ ฮฃ A
  d = ฮฃ-cong e

  abstract
   ฮณ : is-singleton (ฮฃ A)
   ฮณ = equiv-to-singleton (โ‰ƒ-sym d) (singleton-types'-are-singletons X x)

singleton-equiv-lemma : {X : ๐“ค ฬ‡ } {A : X โ†’ ๐“ฅ ฬ‡ } (x : X)
                        (f : (y : X) โ†’ x ๏ผ y โ†’ A y)
                      โ†’ is-singleton (ฮฃ A)
                      โ†’ (y : X) โ†’ is-equiv (f y)

singleton-equiv-lemma {๐“ค} {๐“ฅ} {X} {A} x f i = ฮณ
 where
  g : singleton-type' x โ†’ ฮฃ A
  g = Natฮฃ f

  e : is-equiv g
  e = maps-of-singletons-are-equivs g (singleton-types'-are-singletons X x) i

  abstract
   ฮณ : (y : X) โ†’ is-equiv (f y)
   ฮณ = Natฮฃ-equiv-gives-fiberwise-equiv f e

univalenceโ‡’ : is-univalent ๐“ค
            โ†’ (X : ๐“ค ฬ‡ ) โ†’ is-singleton (ฮฃ Y ๊ž‰ ๐“ค ฬ‡ , X โ‰ƒ Y)

univalenceโ‡’ ua X = equiv-singleton-lemma X (Idโ†’Eq X) (ua X)

โ‡’univalence : ((X : ๐“ค ฬ‡ ) โ†’ is-singleton (ฮฃ Y ๊ž‰ ๐“ค ฬ‡ , X โ‰ƒ Y))
            โ†’ is-univalent ๐“ค

โ‡’univalence i X = singleton-equiv-lemma X (Idโ†’Eq X) (i X)

univalenceโ†’ : is-univalent ๐“ค
            โ†’ (X : ๐“ค ฬ‡ ) โ†’ is-subsingleton (ฮฃ Y ๊ž‰ ๐“ค ฬ‡ , X โ‰ƒ Y)

univalenceโ†’ ua X = singletons-are-subsingletons
                    (ฮฃ (X โ‰ƒ_)) (univalenceโ‡’ ua X)

โ†’univalence : ((X : ๐“ค ฬ‡ ) โ†’ is-subsingleton (ฮฃ Y ๊ž‰ ๐“ค ฬ‡ , X โ‰ƒ Y))
            โ†’ is-univalent ๐“ค

โ†’univalence i = โ‡’univalence (ฮป X โ†’ pointed-subsingletons-are-singletons
                                    (ฮฃ (X โ‰ƒ_)) (X , id-โ‰ƒ X) (i X))

๐”พ-โ‰ƒ : is-univalent ๐“ค
    โ†’ (X : ๐“ค ฬ‡ ) (A : (ฮฃ Y ๊ž‰ ๐“ค ฬ‡ , X โ‰ƒ Y) โ†’ ๐“ฅ ฬ‡ )
    โ†’ A (X , id-โ‰ƒ X) โ†’ (Y : ๐“ค ฬ‡ ) (e : X โ‰ƒ Y) โ†’ A (Y , e)

๐”พ-โ‰ƒ {๐“ค} ua X A a Y e = transport A p a
 where
  t : ฮฃ Y ๊ž‰ ๐“ค ฬ‡ , X โ‰ƒ Y
  t = (X , id-โ‰ƒ X)

  p : t ๏ผ (Y , e)
  p = univalenceโ†’ {๐“ค} ua X t (Y , e)

๐”พ-โ‰ƒ-equation : (ua : is-univalent ๐“ค)
             โ†’ (X : ๐“ค ฬ‡ ) (A : (ฮฃ Y ๊ž‰ ๐“ค ฬ‡ , X โ‰ƒ Y) โ†’ ๐“ฅ ฬ‡ ) (a : A (X , id-โ‰ƒ X))
             โ†’ ๐”พ-โ‰ƒ ua X A a X (id-โ‰ƒ X) ๏ผ a

๐”พ-โ‰ƒ-equation {๐“ค} {๐“ฅ} ua X A a =

  ๐”พ-โ‰ƒ ua X A a X (id-โ‰ƒ X) ๏ผโŸจ refl _ โŸฉ
  transport A p a         ๏ผโŸจ ap (ฮป - โ†’ transport A - a) q โŸฉ
  transport A (refl t) a  ๏ผโŸจ refl _ โŸฉ
  a                       โˆŽ

 where
  t : ฮฃ Y ๊ž‰ ๐“ค ฬ‡ , X โ‰ƒ Y
  t = (X , id-โ‰ƒ X)

  p : t ๏ผ t
  p = univalenceโ†’ {๐“ค} ua X t t

  q : p ๏ผ refl t
  q = subsingletons-are-sets (ฮฃ Y ๊ž‰ ๐“ค ฬ‡ , X โ‰ƒ Y)
       (univalenceโ†’ {๐“ค} ua X) t t p (refl t)

โ„-โ‰ƒ : is-univalent ๐“ค
    โ†’ (X : ๐“ค ฬ‡ ) (A : (Y : ๐“ค ฬ‡ ) โ†’ X โ‰ƒ Y โ†’ ๐“ฅ ฬ‡ )
    โ†’ A X (id-โ‰ƒ X) โ†’ (Y : ๐“ค ฬ‡ ) (e : X โ‰ƒ Y) โ†’ A Y e

โ„-โ‰ƒ ua X A = ๐”พ-โ‰ƒ ua X (ฮฃ-induction A)

โ„-โ‰ƒ-equation : (ua : is-univalent ๐“ค)
             โ†’ (X : ๐“ค ฬ‡ ) (A : (Y : ๐“ค ฬ‡ ) โ†’ X โ‰ƒ Y โ†’ ๐“ฅ ฬ‡ ) (a : A X  (id-โ‰ƒ X))
             โ†’ โ„-โ‰ƒ ua X A a X (id-โ‰ƒ X) ๏ผ a

โ„-โ‰ƒ-equation ua X A = ๐”พ-โ‰ƒ-equation ua X (ฮฃ-induction A)

๐•-โ‰ƒ : is-univalent ๐“ค
    โ†’ (A : (X Y : ๐“ค ฬ‡ ) โ†’ X โ‰ƒ Y โ†’ ๐“ฅ ฬ‡ )
    โ†’ ((X : ๐“ค ฬ‡ ) โ†’ A X X (id-โ‰ƒ X))
    โ†’ (X Y : ๐“ค ฬ‡ ) (e : X โ‰ƒ Y) โ†’ A X Y e

๐•-โ‰ƒ ua A ฯ† X = โ„-โ‰ƒ ua X (A X) (ฯ† X)

๐•-โ‰ƒ-equation : (ua : is-univalent ๐“ค)
             โ†’ (A : (X Y : ๐“ค ฬ‡ ) โ†’ X โ‰ƒ Y โ†’ ๐“ฅ ฬ‡ )
             โ†’ (ฯ† : (X : ๐“ค ฬ‡ ) โ†’ A X X (id-โ‰ƒ X))
             โ†’ (X : ๐“ค ฬ‡ ) โ†’ ๐•-โ‰ƒ ua A ฯ† X X (id-โ‰ƒ X) ๏ผ ฯ† X

๐•-โ‰ƒ-equation ua A ฯ† X = โ„-โ‰ƒ-equation ua X (A X) (ฯ† X)

โ„-equiv : is-univalent ๐“ค
        โ†’ (X : ๐“ค ฬ‡ ) (A : (Y : ๐“ค ฬ‡ ) โ†’ (X โ†’ Y) โ†’ ๐“ฅ ฬ‡ )
        โ†’ A X (๐‘–๐‘‘ X) โ†’ (Y : ๐“ค ฬ‡ ) (f : X โ†’ Y) โ†’ is-equiv f โ†’ A Y f

โ„-equiv {๐“ค} {๐“ฅ} ua X A a Y f i = ฮณ (f , i)
 where
  B : (Y : ๐“ค ฬ‡ ) โ†’ X โ‰ƒ Y โ†’ ๐“ฅ ฬ‡
  B Y (f , i) = A Y f

  b : B X (id-โ‰ƒ X)
  b = a

  ฮณ : (e : X โ‰ƒ Y) โ†’ B Y e
  ฮณ = โ„-โ‰ƒ ua X B b Y

๐•-equiv : is-univalent ๐“ค
        โ†’ (A : (X Y : ๐“ค ฬ‡ ) โ†’ (X โ†’ Y) โ†’ ๐“ฅ ฬ‡ )
        โ†’ ((X : ๐“ค ฬ‡ ) โ†’ A X X (๐‘–๐‘‘ X))
        โ†’ (X Y : ๐“ค ฬ‡ ) (f : X โ†’ Y) โ†’ is-equiv f โ†’ A X Y f

๐•-equiv ua A ฯ† X = โ„-equiv ua X (A X) (ฯ† X)

๐•-invertible : is-univalent ๐“ค
             โ†’ (A : (X Y : ๐“ค ฬ‡ ) โ†’ (X โ†’ Y) โ†’ ๐“ฅ ฬ‡ )
             โ†’ ((X : ๐“ค ฬ‡ ) โ†’ A X X (๐‘–๐‘‘ X))
             โ†’ (X Y : ๐“ค ฬ‡ ) (f : X โ†’ Y) โ†’ invertible f โ†’ A X Y f

๐•-invertible ua A ฯ† X Y f i = ๐•-equiv ua A ฯ† X Y f (invertibles-are-equivs f i)

automatic-equiv-functoriality :

      (F : ๐“ค ฬ‡ โ†’ ๐“ค ฬ‡ )
      (๐“• : {X Y : ๐“ค ฬ‡ }  โ†’ (X โ†’ Y) โ†’ F X โ†’ F Y)
      (๐“•-id : {X : ๐“ค ฬ‡ } โ†’ ๐“• (๐‘–๐‘‘ X) ๏ผ ๐‘–๐‘‘ (F X))
      {X Y Z : ๐“ค ฬ‡ }
      (f : X โ†’ Y)
      (g : Y โ†’ Z)

    โ†’ is-univalent ๐“ค โ†’ is-equiv f + is-equiv g โ†’ ๐“• (g โˆ˜ f) ๏ผ ๐“• g โˆ˜ ๐“• f

automatic-equiv-functoriality {๐“ค} F ๐“• ๐“•-id {X} {Y} {Z} f g ua = ฮณ
  where
   ฮณ :  is-equiv f + is-equiv g โ†’ ๐“• (g โˆ˜ f) ๏ผ ๐“• g โˆ˜ ๐“• f
   ฮณ (inl i) = โ„-equiv ua X A a Y f i g
    where
     A : (Y : ๐“ค ฬ‡ ) โ†’ (X โ†’ Y) โ†’ ๐“ค ฬ‡
     A Y f = (g : Y โ†’ Z) โ†’ ๐“• (g โˆ˜ f) ๏ผ ๐“• g โˆ˜ ๐“• f

     a : (g : X โ†’ Z) โ†’ ๐“• g ๏ผ ๐“• g โˆ˜ ๐“• id
     a g = ap (๐“• g โˆ˜_) (๐“•-id โปยน)

   ฮณ (inr j) = โ„-equiv ua Y B b Z g j f
    where
     B : (Z : ๐“ค ฬ‡ ) โ†’ (Y โ†’ Z) โ†’ ๐“ค ฬ‡
     B Z g = (f : X โ†’ Y) โ†’ ๐“• (g โˆ˜ f) ๏ผ ๐“• g โˆ˜ ๐“• f

     b : (f : X โ†’ Y) โ†’ ๐“• f ๏ผ ๐“• (๐‘–๐‘‘ Y) โˆ˜ ๐“• f
     b f = ap (_โˆ˜ ๐“• f) (๐“•-id โปยน)

ฮฃ-change-of-variable' : is-univalent ๐“ค
                      โ†’ {X : ๐“ค ฬ‡ } {Y : ๐“ค ฬ‡ } (A : X โ†’ ๐“ฅ ฬ‡ ) (f : X โ†’ Y)
                      โ†’ (i : is-equiv f)
                      โ†’ (ฮฃ x ๊ž‰ X , A x) ๏ผ (ฮฃ y ๊ž‰ Y , A (inverse f i y))

ฮฃ-change-of-variable' {๐“ค} {๐“ฅ} ua {X} {Y} A f i = โ„-โ‰ƒ ua X B b Y (f , i)
 where
   B : (Y : ๐“ค ฬ‡ ) โ†’ X โ‰ƒ Y โ†’  (๐“ค โŠ” ๐“ฅ)โบ ฬ‡
   B Y (f , i) = ฮฃ A ๏ผ (ฮฃ (A โˆ˜ inverse f i))

   b : B X (id-โ‰ƒ X)
   b = refl (ฮฃ A)

ฮฃ-change-of-variable'' : is-univalent ๐“ค
                       โ†’ {X : ๐“ค ฬ‡ } {Y : ๐“ค ฬ‡ } (A : Y โ†’ ๐“ฅ ฬ‡ ) (f : X โ†’ Y)
                       โ†’ is-equiv f
                       โ†’ (ฮฃ y ๊ž‰ Y , A y) ๏ผ (ฮฃ x ๊ž‰ X , A (f x))

ฮฃ-change-of-variable'' ua A f i = ฮฃ-change-of-variable' ua A
                                  (inverse f i)
                                  (inverses-are-equivs f i)

transport-map-along-๏ผ : {X Y Z : ๐“ค ฬ‡ }
                        (p : X ๏ผ Y) (g : X โ†’ Z)
                      โ†’ transport (ฮป - โ†’ - โ†’ Z) p g
                      ๏ผ g โˆ˜ Idโ†’fun (p โปยน)

transport-map-along-๏ผ (refl X) = refl

transport-map-along-โ‰ƒ : (ua : is-univalent ๐“ค) {X Y Z : ๐“ค ฬ‡ }
                        (e : X โ‰ƒ Y) (g : X โ†’ Z)
                      โ†’ transport (ฮป - โ†’ - โ†’ Z) (Eqโ†’Id ua X Y e) g
                      ๏ผ g โˆ˜ โŒœ โ‰ƒ-sym e โŒ

transport-map-along-โ‰ƒ {๐“ค} ua {X} {Y} {Z} = ๐•-โ‰ƒ ua A a X Y
 where
  A : (X Y : ๐“ค ฬ‡ ) โ†’ X โ‰ƒ Y โ†’ ๐“ค ฬ‡
  A X Y e = (g : X โ†’ Z) โ†’ transport (ฮป - โ†’ - โ†’ Z) (Eqโ†’Id ua X Y e) g
                        ๏ผ g โˆ˜ โŒœ โ‰ƒ-sym e โŒ
  a : (X : ๐“ค ฬ‡ ) โ†’ A X X (id-โ‰ƒ X)
  a X g = transport (ฮป - โ†’ - โ†’ Z) (Eqโ†’Id ua X X (id-โ‰ƒ X)) g ๏ผโŸจ q โŸฉ
          transport (ฮป - โ†’ - โ†’ Z) (refl X) g                ๏ผโŸจ refl _ โŸฉ
          g                                                 โˆŽ
    where
     p : Eqโ†’Id ua X X (id-โ‰ƒ X) ๏ผ refl X
     p = inverses-are-retractions (Idโ†’Eq X X) (ua X X) (refl X)

     q = ap (ฮป - โ†’ transport (ฮป - โ†’ - โ†’ Z) - g) p