Skip to content

MGS.More-FunExt-Consequences

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.More-FunExt-Consequences where

open import MGS.HAE public
open import MGS.Subsingleton-Theorems public

being-subsingleton-is-subsingleton : dfunext š“¤ š“¤
                                   →  {X : š“¤ ̇ }
                                   → is-subsingleton (is-subsingleton X)

being-subsingleton-is-subsingleton fe {X} i j = c
 where
  l : is-set X
  l = subsingletons-are-sets X i

  a : (x y : X) → i x y ļ¼ j x y
  a x y = l x y (i x y) (j x y)

  b : (x : X) → i x ļ¼ j x
  b x = fe (a x)

  c : i ļ¼ j
  c = fe b

being-center-is-subsingleton : dfunext š“¤ š“¤
                             → {X : š“¤ ̇ } (c : X)
                             → is-subsingleton (is-center X c)

being-center-is-subsingleton fe {X} c φ γ = k
 where
  i : is-singleton X
  i = c , φ

  j : (x : X) → is-subsingleton (c ļ¼ x)
  j x = singletons-are-sets X i c x

  k : φ ļ¼ γ
  k = fe (Ī» x → j x (φ x) (γ x))

Ī -is-set : hfunext š“¤ š“„
         → {X : š“¤ ̇ } {A : X → š“„ ̇ }
         → ((x : X) → is-set (A x)) → is-set (Ī  A)

Ī -is-set hfe s f g = b
 where
  a : is-subsingleton (f ∼ g)
  a p q = γ
   where
    h : āˆ€ x →  p x ļ¼ q x
    h x = s x (f x) (g x) (p x) (q x)
    γ : p ļ¼  q
    γ = hfunext-gives-dfunext hfe h

  e : (f ļ¼ g) ā‰ƒ (f ∼ g)
  e = (happly f g , hfe f g)

  b : is-subsingleton (f ļ¼ g)
  b = equiv-to-subsingleton e a

being-set-is-subsingleton : dfunext š“¤ š“¤
                          → {X : š“¤ ̇ }
                          → is-subsingleton (is-set X)

being-set-is-subsingleton fe = Ī -is-subsingleton fe
                                (Ī» x → Ī -is-subsingleton fe
                                (Ī» y → being-subsingleton-is-subsingleton fe))

hlevel-relation-is-subsingleton : dfunext š“¤ š“¤
                                → (n : ā„•) (X : š“¤ ̇ )
                                → is-subsingleton (X is-of-hlevel n)

hlevel-relation-is-subsingleton {š“¤} fe zero X =
 being-singleton-is-subsingleton fe

hlevel-relation-is-subsingleton fe (succ n) X =
 Ī -is-subsingleton fe
  (Ī» x → Ī -is-subsingleton fe
  (Ī» x' → hlevel-relation-is-subsingleton fe n (x ļ¼ x')))

ā—-assoc : dfunext š“£ (š“¤ āŠ” š“£) → dfunext (š“¤ āŠ” š“£) (š“¤ āŠ” š“£)
        → {X : š“¤ ̇ } {Y : š“„ ̇ } {Z : š“¦ ̇ } {T : š“£ ̇ }
          (α : X ā‰ƒ Y) (β : Y ā‰ƒ Z) (γ : Z ā‰ƒ T)
        → α ā— (β ā— γ) ļ¼ (α ā— β) ā— γ

ā—-assoc fe fe' (f , a) (g , b) (h , c) = ap (h ∘ g ∘ f ,_) q
 where
  d e : is-equiv (h ∘ g ∘ f)
  d = ∘-is-equiv (∘-is-equiv c b) a
  e = ∘-is-equiv c (∘-is-equiv b a)

  q : d ļ¼ e
  q = being-equiv-is-subsingleton fe fe' (h ∘ g ∘ f) _ _

ā‰ƒ-sym-involutive : dfunext š“„ (š“¤ āŠ” š“„) → dfunext (š“¤ āŠ” š“„) (š“¤ āŠ” š“„) →
                   {X : š“¤ ̇ } {Y : š“„ ̇ } (α : X ā‰ƒ Y)
                 → ā‰ƒ-sym (ā‰ƒ-sym α) ļ¼ α

ā‰ƒ-sym-involutive fe fe' (f , a) = to-subtype-ļ¼
                                   (being-equiv-is-subsingleton fe fe')
                                   (inversion-involutive f a)

ā‰ƒ-sym-is-equiv : dfunext š“„ (š“¤ āŠ” š“„) → dfunext š“¤ (š“¤ āŠ” š“„) → dfunext (š“¤ āŠ” š“„) (š“¤ āŠ” š“„)
               → {X : š“¤ ̇ } {Y : š“„ ̇ }
               → is-equiv (ā‰ƒ-sym {š“¤} {š“„} {X} {Y})

ā‰ƒ-sym-is-equiv feā‚€ fe₁ feā‚‚ = invertibles-are-equivs ā‰ƒ-sym
                              (ā‰ƒ-sym ,
                               ā‰ƒ-sym-involutive feā‚€ feā‚‚ ,
                               ā‰ƒ-sym-involutive fe₁ feā‚‚)

ā‰ƒ-sym-ā‰ƒ : dfunext š“„ (š“¤ āŠ” š“„) → dfunext š“¤ (š“¤ āŠ” š“„) → dfunext (š“¤ āŠ” š“„) (š“¤ āŠ” š“„)
        → (X : š“¤ ̇ ) (Y : š“„ ̇ )
        → (X ā‰ƒ Y) ā‰ƒ (Y ā‰ƒ X)

ā‰ƒ-sym-ā‰ƒ feā‚€ fe₁ feā‚‚ X Y = ā‰ƒ-sym , ā‰ƒ-sym-is-equiv feā‚€ fe₁ feā‚‚

Ī -cong : dfunext š“¤ š“„ → dfunext š“¤ š“¦
       → {X : š“¤ ̇ } {Y : X → š“„ ̇ } {Y' : X → š“¦ ̇ }
       → ((x : X) → Y x ā‰ƒ Y' x) → Ī  Y ā‰ƒ Ī  Y'

Ī -cong fe fe' {X} {Y} {Y'} φ = invertibility-gives-ā‰ƒ F (G , GF , FG)
 where
  f : (x : X) → Y x → Y' x
  f x = ⌜ φ x āŒ

  e : (x : X) → is-equiv (f x)
  e x = āŒœāŒ-is-equiv (φ x)

  g : (x : X) → Y' x → Y x
  g x = inverse (f x) (e x)

  fg : (x : X) (y' : Y' x) → f x (g x y') ļ¼ y'
  fg x = inverses-are-sections (f x) (e x)

  gf : (x : X) (y : Y x) → g x (f x y) ļ¼ y
  gf x = inverses-are-retractions (f x) (e x)

  F : ((x : X) → Y x) → ((x : X) → Y' x)
  F φ x = f x (φ x)

  G : ((x : X) → Y' x) → (x : X) → Y x
  G γ x = g x (γ x)

  FG : (γ : ((x : X) → Y' x)) → F (G γ) ļ¼ γ
  FG γ = fe' (Ī» x → fg x (γ x))

  GF : (φ : ((x : X) → Y x)) → G (F φ) ļ¼ φ
  GF φ = fe (Ī» x → gf x (φ x))

hfunext-ā‰ƒ : hfunext š“¤ š“„
          → {X : š“¤ ̇ } {A : X → š“„ ̇ } (f g : Ī  A)
          → (f ļ¼ g) ā‰ƒ (f ∼ g)

hfunext-ā‰ƒ hfe f g = (happly f g , hfe f g)

hfunextā‚‚-ā‰ƒ : hfunext š“¤ (š“„ āŠ” š“¦) → hfunext š“„ š“¦
           → {X : š“¤ ̇ } {Y : X → š“„ ̇ } {A : (x : X) → Y x → š“¦ ̇ }
             (f g : (x : X) (y : Y x) → A x y)
           → (f ļ¼ g) ā‰ƒ (āˆ€ x y → f x y ļ¼ g x y)

hfunextā‚‚-ā‰ƒ fe fe' {X} f g =

 (f ļ¼ g)                  ā‰ƒāŸØ i ⟩
 (āˆ€ x → f x ļ¼ g x)        ā‰ƒāŸØ ii ⟩
 (āˆ€ x y → f x y ļ¼ g x y)  ā– 

 where
  i  = hfunext-ā‰ƒ fe f g
  ii = Ī -cong
        (hfunext-gives-dfunext fe)
        (hfunext-gives-dfunext fe)
        (Ī» x → hfunext-ā‰ƒ fe' (f x) (g x))

precomp-invertible : dfunext š“„ š“¦ → dfunext š“¤ š“¦
                   → {X : š“¤ ̇ } {Y : š“„ ̇ } {Z : š“¦ ̇ } (f : X → Y)
                   → invertible f
                   → invertible (Ī» (h : Y → Z) → h ∘ f)

precomp-invertible fe fe' {X} {Y} {Z} f (g , η , ε) = (g' , η' , ε')
 where
  f' : (Y → Z) → (X → Z)
  f' h = h ∘ f

  g' : (X → Z) → (Y → Z)
  g' k = k ∘ g

  Ī·' : (h : Y → Z) → g' (f' h) ļ¼ h
  Ī·' h = fe (Ī» y → ap h (ε y))

  ε' : (k : X → Z) → f' (g' k) ļ¼ k
  ε' k = fe' (Ī» x → ap k (Ī· x))

dprecomp : {X : š“¤ ̇ } {Y : š“„ ̇ } (A : Y → š“¦ ̇ ) (f : X → Y)
         → Ī  A → Ī  (A ∘ f)

dprecomp A f = _∘ f

dprecomp-is-equiv : dfunext š“¤ š“¦
                  → dfunext š“„ š“¦
                  → {X : š“¤ ̇ } {Y : š“„ ̇ } (A : Y → š“¦ ̇ ) (f : X → Y)
                  → is-equiv f
                  → is-equiv (dprecomp A f)

dprecomp-is-equiv fe fe' {X} {Y} A f i = invertibles-are-equivs φ (ψ , ĻˆĻ† , Ļ†Ļˆ)
 where
  g = inverse f i
  Ī· = inverses-are-retractions f i
  ε = inverses-are-sections f i

  Ļ„ : (x : X) → ap f (Ī· x) ļ¼ ε (f x)
  Ļ„ = half-adjoint-condition f i

  φ : Ī  A → Ī  (A ∘ f)
  φ = dprecomp A f

  ψ : Ī  (A ∘ f) → Ī  A
  ψ k y = transport A (ε y) (k (g y))

  Ļ†Ļˆā‚€ : (k : Ī  (A ∘ f)) (x : X) → transport A (ε (f x)) (k (g (f x))) ļ¼ k x
  Ļ†Ļˆā‚€ k x = transport A (ε (f x))   (k (g (f x))) ļ¼āŸØ a ⟩
            transport A (ap f (Ī· x))(k (g (f x))) ļ¼āŸØ b ⟩
            transport (A ∘ f) (Ī· x) (k (g (f x))) ļ¼āŸØ c ⟩
            k x                                   āˆŽ
    where
     a = ap (Ī» - → transport A - (k (g (f x)))) ((Ļ„ x)⁻¹)
     b = (transport-ap A f (η x) (k (g (f x))))⁻¹
     c = apd k (Ī· x)

  Ļ†Ļˆ : φ ∘ ψ ∼ id
  Ļ†Ļˆ k = fe (Ļ†Ļˆā‚€ k)

  ĻˆĻ†ā‚€ : (h : Ī  A) (y : Y) → transport A (ε y) (h (f (g y))) ļ¼ h y
  ĻˆĻ†ā‚€ h y = apd h (ε y)

  ĻˆĻ† : ψ ∘ φ ∼ id
  ĻˆĻ† h = fe' (ĻˆĻ†ā‚€ h)

Ī -change-of-variable : dfunext š“¤ š“¦
                     → dfunext š“„ š“¦
                     → {X : š“¤ ̇ } {Y : š“„ ̇ } (A : Y → š“¦ ̇ ) (f : X → Y)
                     → is-equiv f
                     → (Ī  y źž‰ Y , A y) ā‰ƒ (Ī  x źž‰ X , A (f x))

Ī -change-of-variable fe fe' A f i = dprecomp A f , dprecomp-is-equiv fe fe' A f i

at-most-one-section : dfunext š“„ š“¤ → hfunext š“„ š“„
                    → {X : š“¤ ̇ } {Y : š“„ ̇ } (f : X → Y)
                    → has-retraction f
                    → is-subsingleton (has-section f)

at-most-one-section {š“„} {š“¤} fe hfe {X} {Y} f (g , gf) (h , fh) = d
 where
  fe' : dfunext š“„ š“„
  fe' = hfunext-gives-dfunext hfe

  a : invertible f
  a = joyal-equivs-are-invertible f ((h , fh) , (g , gf))

  b : is-singleton (fiber (Ī» h →  f ∘ h) id)
  b = invertibles-are-equivs (Ī» h → f ∘ h) (postcomp-invertible fe fe' f a) id

  r : fiber (Ī» h →  f ∘ h) id → has-section f
  r (h , p) = (h , happly (f ∘ h) id p)

  s : has-section f → fiber (Ī» h → f ∘ h) id
  s (h , Ī·) = (h , fe' Ī·)

  rs : (σ : has-section f) → r (s σ) ļ¼ σ
  rs (h , Ī·) = to-Ī£-ļ¼' q
   where
    q : happly (f ∘ h) id (inverse (happly (f ∘ h) id) (hfe (f ∘ h) id) Ī·) ļ¼ Ī·
    q = inverses-are-sections (happly (f ∘ h) id) (hfe (f ∘ h) id) η

  c : is-singleton (has-section f)
  c = retract-of-singleton (r , s , rs) b

  d : (σ : has-section f) → h , fh ļ¼ σ
  d = singletons-are-subsingletons (has-section f) c (h , fh)

at-most-one-retraction : hfunext š“¤ š“¤ → dfunext š“„ š“¤
                       → {X : š“¤ ̇ } {Y : š“„ ̇ } (f : X → Y)
                       → has-section f
                       → is-subsingleton (has-retraction f)

at-most-one-retraction {š“¤} {š“„} hfe fe' {X} {Y} f (g , fg) (h , hf) = d
 where
  fe : dfunext š“¤ š“¤
  fe = hfunext-gives-dfunext hfe

  a : invertible f
  a = joyal-equivs-are-invertible f ((g , fg) , (h , hf))

  b : is-singleton (fiber (Ī» h →  h ∘ f) id)
  b = invertibles-are-equivs (Ī» h → h ∘ f) (precomp-invertible fe' fe f a) id

  r : fiber (Ī» h →  h ∘ f) id → has-retraction f
  r (h , p) = (h , happly (h ∘ f) id p)

  s : has-retraction f → fiber (Ī» h →  h ∘ f) id
  s (h , Ī·) = (h , fe Ī·)

  rs : (σ : has-retraction f) → r (s σ) ļ¼ σ
  rs (h , Ī·) = to-Ī£-ļ¼' q
   where
    q : happly (h ∘ f) id (inverse (happly (h ∘ f) id) (hfe (h ∘ f) id) Ī·) ļ¼ Ī·
    q = inverses-are-sections (happly (h ∘ f) id) (hfe (h ∘ f) id) η

  c : is-singleton (has-retraction f)
  c = retract-of-singleton (r , s , rs) b

  d : (ρ : has-retraction f) → h , hf ļ¼ ρ
  d = singletons-are-subsingletons (has-retraction f) c (h , hf)

being-joyal-equiv-is-subsingleton : hfunext š“¤ š“¤ → hfunext š“„ š“„ → dfunext š“„ š“¤
                                  → {X : š“¤ ̇ } {Y : š“„ ̇ }
                                  → (f : X → Y)
                                  → is-subsingleton (is-joyal-equiv f)

being-joyal-equiv-is-subsingleton feā‚€ fe₁ feā‚‚ f = Ɨ-is-subsingleton'
                                                   (at-most-one-section    feā‚‚ fe₁ f ,
                                                    at-most-one-retraction feā‚€ feā‚‚ f)

being-hae-is-subsingleton : dfunext š“„ š“¤ → hfunext š“„ š“„ → dfunext š“¤ (š“„ āŠ” š“¤)
                          → {X : š“¤ ̇ } {Y : š“„ ̇ } (f : X → Y)
                          → is-subsingleton (is-hae f)

being-hae-is-subsingleton feā‚€ fe₁ feā‚‚ {X} {Y} f = subsingleton-criterion' γ
 where
  a = λ g ε x
    → ((g (f x) , ε (f x)) ļ¼ (x , refl (f x)))                                   ā‰ƒāŸØ i  g ε x ⟩
      (Ī£ p źž‰ g (f x) ļ¼ x , transport (Ī» - → f - ļ¼ f x) p (ε (f x)) ļ¼ refl (f x)) ā‰ƒāŸØ ii g ε x ⟩
      (Ī£ p źž‰ g (f x) ļ¼ x , ap f p ļ¼ ε (f x))                                     ā– 
   where
    i  = Ī» g ε x → Ī£-ļ¼-ā‰ƒ (g (f x) , ε (f x)) (x , refl (f x))
    ii = Ī» g ε x → Ī£-cong (Ī» p → transport-ap-ā‰ƒ f p (ε (f x)))

  b = (Ī£ (g , ε) źž‰ has-section f , āˆ€ x → (g (f x) , ε (f x)) ļ¼ (x , refl (f x)))         ā‰ƒāŸØ i ⟩
      (Ī£ (g , ε) źž‰ has-section f , āˆ€ x → Ī£  p źž‰ g (f x) ļ¼ x , ap f p ļ¼ ε (f x))          ā‰ƒāŸØ ii ⟩
      (Ī£ g źž‰ (Y → X) , Ī£ ε źž‰ f ∘ g ∼ id , āˆ€ x → Ī£  p źž‰ g (f x) ļ¼ x , ap f p ļ¼ ε (f x))   ā‰ƒāŸØ iii ⟩
      (Ī£ g źž‰ (Y → X) , Ī£ ε źž‰ f ∘ g ∼ id , Ī£ Ī· źž‰ g ∘ f ∼ id , āˆ€ x → ap f (Ī· x) ļ¼ ε (f x)) ā‰ƒāŸØ iv ⟩
      is-hae f                                                                           ā– 
   where
    i   = Ī£-cong (Ī» (g , ε) → Ī -cong feā‚‚ feā‚‚ (a g ε))
    ii  = Σ-assoc
    iii = Ī£-cong (Ī» g → Ī£-cong (Ī» ε → ΠΣ-distr-ā‰ƒ))
    iv  = Ī£-cong (Ī» g → Ī£-flip)

  γ : is-hae f → is-subsingleton (is-hae f)
  γ (gā‚€ , ε₀ , Ī·ā‚€ , τ₀) = i
   where
    c : (x : X) → is-set (fiber f (f x))
    c x = singletons-are-sets (fiber f (f x)) (haes-are-equivs f (gā‚€ , ε₀ , Ī·ā‚€ , τ₀) (f x))

    d : ((g , ε) : has-section f) → is-subsingleton (āˆ€ x → (g (f x) , ε (f x)) ļ¼ (x , refl (f x)))
    d (g , ε) = Ī -is-subsingleton feā‚‚ (Ī» x → c x (g (f x) , ε (f x)) (x , refl (f x)))

    e : is-subsingleton (Ī£ (g , ε) źž‰ has-section f , āˆ€ x → (g (f x) , ε (f x)) ļ¼ (x , refl (f x)))
    e = Ī£-is-subsingleton (at-most-one-section feā‚€ fe₁ f (gā‚€ , ε₀)) d

    i : is-subsingleton (is-hae f)
    i = equiv-to-subsingleton (ā‰ƒ-sym b) e

emptiness-is-subsingleton : dfunext š“¤ š“¤ā‚€ → (X : š“¤ ̇ )
                          → is-subsingleton (is-empty X)

emptiness-is-subsingleton fe X f g = fe (Ī» x → !šŸ˜ (f x ļ¼ g x) (f x))

+-is-subsingleton : {P : š“¤ ̇ } {Q : š“„ ̇ }
                  → is-subsingleton P
                  → is-subsingleton Q
                  → (P → Q → šŸ˜) → is-subsingleton (P + Q)

+-is-subsingleton {š“¤} {š“„} {P} {Q} i j f = γ
 where
  γ : (x y : P + Q) → x ļ¼ y
  γ (inl p) (inl p') = ap inl (i p p')
  γ (inl p) (inr q)  = !šŸ˜ (inl p ļ¼ inr q) (f p q)
  γ (inr q) (inl p)  = !šŸ˜ (inr q ļ¼ inl p) (f p q)
  γ (inr q) (inr q') = ap inr (j q q')

+-is-subsingleton' : dfunext š“¤ š“¤ā‚€
                   → {P : š“¤ ̇ } → is-subsingleton P → is-subsingleton (P + ¬ P)

+-is-subsingleton' fe {P} i = +-is-subsingleton i
                               (emptiness-is-subsingleton fe P)
                               (Ī» p n → n p)

EM-is-subsingleton : dfunext (š“¤ ⁺) š“¤ → dfunext š“¤ š“¤ → dfunext š“¤ š“¤ā‚€
                   → is-subsingleton (EM š“¤)

EM-is-subsingleton fe⁺ fe feā‚€ = Ī -is-subsingleton fe⁺
                                 (Ī» P → Ī -is-subsingleton fe
                                         (Ī» i → +-is-subsingleton' feā‚€ i))