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
\begin{code}
{-# OPTIONS --safe --without-K #-}
module MGS.Solved-Exercises where
open import MGS.Equivalences public
subsingleton-criterion : {X : π€ Μ }
                       β (X β is-singleton X)
                       β is-subsingleton X
subsingleton-criterion' : {X : π€ Μ }
                        β (X β is-subsingleton X)
                        β is-subsingleton X
retract-of-subsingleton : {X : π€ Μ } {Y : π₯ Μ }
                        β Y β X β is-subsingleton X β is-subsingleton Y
left-cancellable : {X : π€ Μ } {Y : π₯ Μ } β (X β Y) β π€ β π₯ Μ
left-cancellable f = {x x' : domain f} β f x οΌ f x' β x οΌ x'
lc-maps-reflect-subsingletons : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y)
                              β left-cancellable f
                              β is-subsingleton Y
                              β is-subsingleton X
has-retraction : {X : π€ Μ } {Y : π₯ Μ } β (X β Y) β π€ β π₯ Μ
has-retraction s = Ξ£ r κ (codomain s β domain s), r β s βΌ id
sections-are-lc : {X : π€ Μ } {A : π₯ Μ } (s : X β A)
                β has-retraction s β left-cancellable s
equivs-have-retractions : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y)
                        β is-equiv f β has-retraction f
equivs-have-sections : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y)
                     β is-equiv f β has-section f
equivs-are-lc : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y)
              β is-equiv f β left-cancellable f
equiv-to-subsingleton : {X : π€ Μ } {Y : π₯ Μ }
                      β X β Y
                      β is-subsingleton Y
                      β is-subsingleton X
comp-inverses : {X : π€ Μ } {Y : π₯ Μ } {Z : π¦ Μ }
                (f : X β Y) (g : Y β Z)
                (i : is-equiv f) (j : is-equiv g)
                (f' : Y β X) (g' : Z β Y)
              β f' βΌ inverse f i
              β g' βΌ inverse g j
              β f' β g' βΌ inverse (g β f) (β-is-equiv j i)
equiv-to-set : {X : π€ Μ } {Y : π₯ Μ }
             β X β Y
             β is-set Y
             β is-set X
sections-closed-under-βΌ : {X : π€ Μ } {Y : π₯ Μ } (f g : X β Y)
                        β has-retraction f
                        β g βΌ f
                        β has-retraction g
retractions-closed-under-βΌ : {X : π€ Μ } {Y : π₯ Μ } (f g : X β Y)
                           β has-section f
                           β g βΌ f
                           β has-section g
is-joyal-equiv : {X : π€ Μ } {Y : π₯ Μ } β (X β Y) β π€ β π₯ Μ
is-joyal-equiv f = has-section f Γ has-retraction f
one-inverse : (X : π€ Μ ) (Y : π₯ Μ )
              (f : X β Y) (r s : Y β X)
            β (r β f βΌ id)
            β (f β s βΌ id)
            β r βΌ s
joyal-equivs-are-invertible : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y)
                            β is-joyal-equiv f β invertible f
joyal-equivs-are-equivs : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y)
                        β is-joyal-equiv f β is-equiv f
invertibles-are-joyal-equivs : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y)
                             β invertible f β is-joyal-equiv f
equivs-are-joyal-equivs : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y)
                        β is-equiv f β is-joyal-equiv f
equivs-closed-under-βΌ : {X : π€ Μ } {Y : π₯ Μ } {f g : X β Y}
                      β is-equiv f
                      β g βΌ f
                      β is-equiv g
equiv-to-singleton' : {X : π€ Μ } {Y : π₯ Μ }
                    β X β Y β is-singleton X β is-singleton Y
subtypes-of-sets-are-sets' : {X : π€ Μ } {Y : π₯ Μ } (m : X β Y)
                          β left-cancellable m β is-set Y β is-set X
prβ-lc : {X : π€ Μ } {A : X β π₯ Μ }
       β ((x : X) β is-subsingleton (A x))
       β left-cancellable (Ξ» (t : Ξ£ A) β prβ t)
subsets-of-sets-are-sets : (X : π€ Μ ) (A : X β π₯ Μ )
                         β is-set X
                         β ((x : X) β is-subsingleton (A x))
                         β is-set (Ξ£ x κ X , A x)
to-subtype-οΌ : {X : π¦ Μ } {A : X β π₯ Μ }
               {x y : X} {a : A x} {b : A y}
             β ((x : X) β is-subsingleton (A x))
             β x οΌ y
             β (x , a) οΌ (y , b)
prβ-equiv : {X : π€ Μ } {A : X β π₯ Μ }
          β ((x : X) β is-singleton (A x))
          β is-equiv (Ξ» (t : Ξ£ A) β prβ t)
prβ-β : {X : π€ Μ } {A : X β π₯ Μ }
      β ((x : X) β is-singleton (A x))
      β Ξ£ A β X
prβ-β i = prβ , prβ-equiv i
Ξ Ξ£-distr-β : {X : π€ Μ } {A : X β π₯ Μ } {P : (x : X) β A x β π¦ Μ }
           β (Ξ  x κ X , Ξ£ a κ A x , P x a)
           β (Ξ£ f κ Ξ  A , Ξ  x κ X , P x (f x))
Ξ£-assoc : {X : π€ Μ } {Y : X β π₯ Μ } {Z : Ξ£ Y β π¦ Μ }
        β Ξ£ Z β (Ξ£ x κ X , Ξ£ y κ Y x , Z (x , y))
β»ΒΉ-β : {X : π€ Μ } (x y : X) β (x οΌ y) β (y οΌ x)
singleton-types-β : {X : π€ Μ } (x : X) β singleton-type' x β singleton-type x
singletons-β : {X : π€ Μ } {Y : π₯ Μ }
             β is-singleton X β is-singleton Y β X β Y
maps-of-singletons-are-equivs : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y)
                              β is-singleton X β is-singleton Y β is-equiv f
logically-equivalent-subsingletons-are-equivalent : (X : π€ Μ ) (Y : π₯ Μ )
                                                  β is-subsingleton X
                                                  β is-subsingleton Y
                                                  β X β Y
                                                  β X β Y
singletons-are-equivalent : (X : π€ Μ ) (Y : π₯ Μ )
                          β is-singleton X
                          β is-singleton Y
                          β X β Y
NatΞ£-fiber-equiv : {X : π€ Μ } (A : X β π₯ Μ ) (B : X β π¦ Μ ) (Ο : Nat A B)
                   (x : X) (b : B x)
                 β fiber (Ο x) b β fiber (NatΞ£ Ο) (x , b)
NatΞ£-equiv-gives-fiberwise-equiv : {X : π€ Μ } {A : X β π₯ Μ } {B : X β π¦ Μ }
                                   (Ο : Nat A B)
                                 β is-equiv (NatΞ£ Ο)
                                 β ((x : X) β is-equiv (Ο x))
Ξ£-is-subsingleton : {X : π€ Μ } {A : X β π₯ Μ }
                  β is-subsingleton X
                  β ((x : X) β is-subsingleton (A x))
                  β is-subsingleton (Ξ£ A)
Γ-is-singleton : {X : π€ Μ } {Y : π₯ Μ }
                  β is-singleton X
                  β is-singleton Y
                  β is-singleton (X Γ Y)
Γ-is-subsingleton : {X : π€ Μ } {Y : π₯ Μ }
                  β is-subsingleton X
                  β is-subsingleton Y
                  β is-subsingleton (X Γ Y)
Γ-is-subsingleton' : {X : π€ Μ } {Y : π₯ Μ }
                   β ((Y β is-subsingleton X) Γ (X β is-subsingleton Y))
                   β is-subsingleton (X Γ Y)
Γ-is-subsingleton'-back : {X : π€ Μ } {Y : π₯ Μ }
                        β is-subsingleton (X Γ Y)
                        β (Y β is-subsingleton X) Γ (X β is-subsingleton Y)
apβ : {X : π€ Μ } {Y : π₯ Μ } {Z : π¦ Μ } (f : X β Y β Z) {x x' : X} {y y' : Y}
    β x οΌ x' β y οΌ y' β f x y οΌ f x' y'
subsingleton-criterion = sol
 where
  sol : {X : π€ Μ } β (X β is-singleton X) β is-subsingleton X
  sol f x = singletons-are-subsingletons (domain f) (f x) x
subsingleton-criterion' = sol
 where
  sol : {X : π€ Μ } β (X β is-subsingleton X) β is-subsingleton X
  sol f x y = f x x y
retract-of-subsingleton = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ }
      β Y β X β is-subsingleton X β is-subsingleton Y
  sol (r , s , Ξ·) i =  subsingleton-criterion
                        (Ξ» x β retract-of-singleton (r , s , Ξ·)
                                (pointed-subsingletons-are-singletons
                                  (codomain s) (s x) i))
lc-maps-reflect-subsingletons = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y)
      β left-cancellable f β is-subsingleton Y β is-subsingleton X
  sol f l s x x' = l (s (f x) (f x'))
sections-are-lc = sol
 where
  sol : {X : π€ Μ } {A : π₯ Μ } (s : X β A)
      β has-retraction s β left-cancellable s
  sol s (r , Ξ΅) {x} {y} p = x       οΌβ¨ (Ξ΅ x)β»ΒΉ β©
                            r (s x) οΌβ¨ ap r p β©
                            r (s y) οΌβ¨ Ξ΅ y β©
                            y       β
equivs-have-retractions = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) β is-equiv f β has-retraction f
  sol f e = (inverse f e , inverses-are-retractions f e)
equivs-have-sections = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) β is-equiv f β has-section f
  sol f e = (inverse f e , inverses-are-sections f e)
equivs-are-lc = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) β is-equiv f β left-cancellable f
  sol f e = sections-are-lc f (equivs-have-retractions f e)
equiv-to-subsingleton = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } β X β Y β is-subsingleton Y β is-subsingleton X
  sol (f , i) = lc-maps-reflect-subsingletons f (equivs-are-lc f i)
comp-inverses = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } {Z : π¦ Μ }
        (f : X β Y) (g : Y β Z)
        (i : is-equiv f) (j : is-equiv g)
        (f' : Y β X) (g' : Z β Y)
      β f' βΌ inverse f i
      β g' βΌ inverse g j
      β f' β g' βΌ inverse (g β f) (β-is-equiv j i)
  sol f g i j f' g' h k z =
   f' (g' z)                          οΌβ¨ h (g' z) β©
   inverse f i (g' z)                 οΌβ¨ ap (inverse f i) (k z) β©
   inverse f i (inverse g j z)        οΌβ¨ inverse-of-β f g i j z β©
   inverse (g β f) (β-is-equiv j i) z β
equiv-to-set = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } β X β Y β is-set Y β is-set X
  sol e = subtypes-of-sets-are-sets' β e β (equivs-are-lc β e β (ββ-is-equiv e))
sections-closed-under-βΌ = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } (f g : X β Y)
      β has-retraction f β g βΌ f β has-retraction g
  sol f g (r , rf) h = (r ,
                        Ξ» x β r (g x) οΌβ¨ ap r (h x) β©
                              r (f x) οΌβ¨ rf x β©
                              x       β)
retractions-closed-under-βΌ = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } (f g : X β Y)
      β has-section f β g βΌ f β has-section g
  sol f g (s , fs) h = (s ,
                        Ξ» y β g (s y) οΌβ¨ h (s y) β©
                              f (s y) οΌβ¨ fs y β©
                              y β)
one-inverse = sol
 where
  sol : (X : π€ Μ ) (Y : π₯ Μ )
        (f : X β Y) (r s : Y β X)
      β (r β f βΌ id)
      β (f β s βΌ id)
      β r βΌ s
  sol X Y f r s h k y = r y         οΌβ¨ ap r ((k y)β»ΒΉ) β©
                        r (f (s y)) οΌβ¨ h (s y) β©
                        s y         β
joyal-equivs-are-invertible = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y)
      β is-joyal-equiv f β invertible f
  sol f ((s , Ξ΅) , (r , Ξ·)) = (s , sf , Ξ΅)
   where
    sf = Ξ» (x : domain f) β s (f x)       οΌβ¨ (Ξ· (s (f x)))β»ΒΉ β©
                            r (f (s (f x))) οΌβ¨ ap r (Ξ΅ (f x)) β©
                            r (f x)       οΌβ¨ Ξ· x β©
                            x            β
joyal-equivs-are-equivs = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y)
      β is-joyal-equiv f β is-equiv f
  sol f j = invertibles-are-equivs f (joyal-equivs-are-invertible f j)
invertibles-are-joyal-equivs = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y)
      β invertible f β is-joyal-equiv f
  sol f (g , Ξ· , Ξ΅) = ((g , Ξ΅) , (g , Ξ·))
equivs-are-joyal-equivs = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y)
      β is-equiv f β is-joyal-equiv f
  sol f e = invertibles-are-joyal-equivs f (equivs-are-invertible f e)
equivs-closed-under-βΌ = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } {f g : X β Y}
      β is-equiv f β g βΌ f β is-equiv g
  sol {π€} {π₯} {X} {Y} {f} {g} e h = joyal-equivs-are-equivs g
                                      (retractions-closed-under-βΌ f g
                                       (equivs-have-sections f e) h ,
                                      sections-closed-under-βΌ f g
                                       (equivs-have-retractions f e) h)
equiv-to-singleton' = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ }
      β X β Y β is-singleton X β is-singleton Y
  sol e = retract-of-singleton (β-gives-β· e)
subtypes-of-sets-are-sets' = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } (m : X β Y)
      β left-cancellable m β is-set Y β is-set X
  sol {π€} {π₯} {X} m i h = types-with-wconstant-οΌ-endomaps-are-sets X c
   where
    f : (x x' : X) β x οΌ x' β x οΌ x'
    f x x' r = i (ap m r)
    ΞΊ : (x x' : X) (r s : x οΌ x') β f x x' r οΌ f x x' s
    ΞΊ x x' r s = ap i (h (m x) (m x') (ap m r) (ap m s))
    c : wconstant-οΌ-endomaps X
    c x x' = f x x' , ΞΊ x x'
prβ-lc = sol
 where
  sol : {X : π€ Μ } {A : X β π₯ Μ }
      β ((x : X) β is-subsingleton (A x))
      β left-cancellable  (Ξ» (t : Ξ£ A) β prβ t)
  sol i p = to-Ξ£-οΌ (p , i _ _ _)
subsets-of-sets-are-sets = sol
 where
  sol : (X : π€ Μ ) (A : X β π₯ Μ )
     β is-set X
     β ((x : X) β is-subsingleton (A x))
     β is-set (Ξ£ x κ X , A x)
  sol X A h p = subtypes-of-sets-are-sets' prβ (prβ-lc p) h
to-subtype-οΌ = sol
 where
  sol : {X : π€ Μ } {A : X β π₯ Μ }
        {x y : X} {a : A x} {b : A y}
      β ((x : X) β is-subsingleton (A x))
      β x οΌ y
      β (x , a) οΌ (y , b)
  sol {π€} {π₯} {X} {A} {x} {y} {a} {b} s p = to-Ξ£-οΌ (p , s y (transport A p a) b)
prβ-equiv = sol
 where
  sol : {X : π€ Μ } {A : X β π₯ Μ }
      β ((x : X) β is-singleton (A x))
      β is-equiv (Ξ» (t : Ξ£ A) β prβ t)
  sol {π€} {π₯} {X} {A} s = invertibles-are-equivs prβ (g , Ξ· , Ξ΅)
   where
    g : X β Ξ£ A
    g x = x , prβ (s x)
    Ξ΅ : (x : X) β prβ (g x) οΌ x
    Ξ΅ x = refl (prβ (g x))
    Ξ· : (Ο : Ξ£ A) β g (prβ Ο) οΌ Ο
    Ξ· (x , a) = to-subtype-οΌ (Ξ» x β singletons-are-subsingletons (A x) (s x)) (Ξ΅ x)
Ξ Ξ£-distr-β = sol
 where
  sol : {X : π€ Μ } {A : X β π₯ Μ } {P : (x : X) β A x β π¦ Μ }
      β (Ξ  x κ X , Ξ£ a κ A x , P x a)
      β (Ξ£ f κ Ξ  A , Ξ  x κ X , P x (f x))
  sol {π€} {π₯} {π¦} {X} {A} {P} = invertibility-gives-β Ο (Ξ³ , Ξ· , Ξ΅)
   where
    Ο : (Ξ  x κ X , Ξ£ a κ A x , P x a)
      β Ξ£ f κ Ξ  A , Ξ  x κ X , P x (f x)
    Ο g = ((Ξ» x β prβ (g x)) , Ξ» x β prβ (g x))
    Ξ³ : (Ξ£ f κ Ξ  A , Ξ  x κ X , P x (f x))
      β Ξ  x κ X , Ξ£ a κ A x , P x a
    Ξ³ (f , Ο) x = f x , Ο x
    Ξ· : Ξ³ β Ο βΌ id
    Ξ· = refl
    Ξ΅ : Ο β Ξ³ βΌ id
    Ξ΅ = refl
Ξ£-assoc = sol
 where
  sol : {X : π€ Μ } {Y : X β π₯ Μ } {Z : Ξ£ Y β π¦ Μ }
      β Ξ£ Z β (Ξ£ x κ X , Ξ£ y κ Y x , Z (x , y))
  sol {π€} {π₯} {π¦} {X} {Y} {Z} = invertibility-gives-β f (g , refl , refl)
   where
    f : Ξ£ Z β Ξ£ x κ X , Ξ£ y κ Y x , Z (x , y)
    f ((x , y) , z) = (x , (y , z))
    g : (Ξ£ x κ X , Ξ£ y κ Y x , Z (x , y)) β Ξ£ Z
    g (x , (y , z)) = ((x , y) , z)
β»ΒΉ-is-equiv : {X : π€ Μ } (x y : X)
            β is-equiv (Ξ» (p : x οΌ y) β p β»ΒΉ)
β»ΒΉ-is-equiv x y = invertibles-are-equivs _β»ΒΉ
                   (_β»ΒΉ , β»ΒΉ-involutive , β»ΒΉ-involutive)
β»ΒΉ-β = sol
 where
  sol : {X : π€ Μ } (x y : X) β (x οΌ y) β (y οΌ x)
  sol x y = (_β»ΒΉ , β»ΒΉ-is-equiv x y)
singleton-types-β = sol
 where
  sol : {X : π€ Μ } (x : X) β singleton-type' x β singleton-type x
  sol x = Ξ£-cong (Ξ» y β β»ΒΉ-β x y)
singletons-β = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ }
      β is-singleton X β is-singleton Y β X β Y
  sol {π€} {π₯} {X} {Y} i j = invertibility-gives-β f (g , Ξ· , Ξ΅)
   where
    f : X β Y
    f x = center Y j
    g : Y β X
    g y = center X i
    Ξ· : (x : X) β g (f x) οΌ x
    Ξ· = centrality X i
    Ξ΅ : (y : Y) β f (g y) οΌ y
    Ξ΅ = centrality Y j
maps-of-singletons-are-equivs = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y)
      β is-singleton X β is-singleton Y β is-equiv f
  sol {π€} {π₯} {X} {Y} f i j = invertibles-are-equivs f (g , Ξ· , Ξ΅)
   where
    g : Y β X
    g y = center X i
    Ξ· : (x : X) β g (f x) οΌ x
    Ξ· = centrality X i
    Ξ΅ : (y : Y) β f (g y) οΌ y
    Ξ΅ y = singletons-are-subsingletons Y j (f (g y)) y
logically-equivalent-subsingletons-are-equivalent = sol
 where
  sol : (X : π€ Μ ) (Y : π₯ Μ )
      β is-subsingleton X β is-subsingleton Y β X β Y β X β Y
  sol  X Y i j (f , g) = invertibility-gives-β f
                          (g ,
                           (Ξ» x β i (g (f x)) x) ,
                           (Ξ» y β j (f (g y)) y))
singletons-are-equivalent = sol
 where
  sol : (X : π€ Μ ) (Y : π₯ Μ )
      β is-singleton X β is-singleton Y β X β Y
  sol  X Y i j = invertibility-gives-β (Ξ» _ β center Y j)
                  ((Ξ» _ β center X i) ,
                   centrality X i ,
                   centrality Y j)
NatΞ£-fiber-equiv = sol
 where
  sol : {X : π€ Μ } (A : X β π₯ Μ ) (B : X β π¦ Μ ) (Ο : Nat A B)
        (x : X) (b : B x)
      β fiber (Ο x) b β fiber (NatΞ£ Ο) (x , b)
  sol A B Ο x b = invertibility-gives-β f (g , Ξ΅ , Ξ·)
   where
    f : fiber (Ο x) b β fiber (NatΞ£ Ο) (x , b)
    f (a , refl _) = ((x , a) , refl (x , Ο x a))
    g : fiber (NatΞ£ Ο) (x , b) β fiber (Ο x) b
    g ((x , a) , refl _) = (a , refl (Ο x a))
    Ξ΅ : (w : fiber (Ο x) b) β g (f w) οΌ w
    Ξ΅ (a , refl _) = refl (a , refl (Ο x a))
    Ξ· : (t : fiber (NatΞ£ Ο) (x , b)) β f (g t) οΌ t
    Ξ· ((x , a) , refl _) = refl ((x , a) , refl (NatΞ£ Ο (x , a)))
NatΞ£-equiv-gives-fiberwise-equiv = sol
 where
  sol : {X : π€ Μ } {A : X β π₯ Μ } {B : X β π¦ Μ } (Ο : Nat A B)
      β is-equiv (NatΞ£ Ο) β ((x : X) β is-equiv (Ο x))
  sol {π€} {π₯} {π¦} {X} {A} {B} Ο e x b = Ξ³
   where
    d : fiber (Ο x) b β fiber (NatΞ£ Ο) (x , b)
    d = NatΞ£-fiber-equiv A B Ο x b
    s : is-singleton (fiber (NatΞ£ Ο) (x , b))
    s = e (x , b)
    Ξ³ : is-singleton (fiber (Ο x) b)
    Ξ³ = equiv-to-singleton d s
Ξ£-is-subsingleton = sol
 where
  sol : {X : π€ Μ } {A : X β π₯ Μ }
      β is-subsingleton X
      β ((x : X) β is-subsingleton (A x))
      β is-subsingleton (Ξ£ A)
  sol i j (x , _) (y , _) = to-subtype-οΌ j (i x y)
Γ-is-singleton = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ }
      β is-singleton X
      β is-singleton Y
      β is-singleton (X Γ Y)
  sol (x , Ο) (y , Ξ³) = (x , y) , Ξ΄
   where
    Ξ΄ : β z β x , y οΌ z
    Ξ΄ (x' , y' ) = to-Γ-οΌ (Ο x' , Ξ³ y')
Γ-is-subsingleton = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ }
      β is-subsingleton X β is-subsingleton Y β is-subsingleton (X Γ Y)
  sol i j = Ξ£-is-subsingleton i (Ξ» _ β j)
Γ-is-subsingleton' = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ }
      β ((Y β is-subsingleton X) Γ (X β is-subsingleton Y))
      β is-subsingleton (X Γ Y)
  sol {π€} {π₯} {X} {Y} (i , j) = k
   where
    k : is-subsingleton (X Γ Y)
    k (x , y) (x' , y') = to-Γ-οΌ (i y x x' , j x y y')
Γ-is-subsingleton'-back = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ }
      β is-subsingleton (X Γ Y)
      β (Y β is-subsingleton X) Γ (X β is-subsingleton Y)
  sol {π€} {π₯} {X} {Y} k = i , j
   where
    i : Y β is-subsingleton X
    i y x x' = ap prβ (k (x , y) (x' , y))
    j : X β is-subsingleton Y
    j x y y' = ap prβ (k (x , y) (x , y'))
apβ = sol
 where
  sol : {X : π€ Μ } {Y : π₯ Μ } {Z : π¦ Μ } (f : X β Y β Z) {x x' : X} {y y' : Y}
      β x οΌ x' β y οΌ y' β f x y οΌ f x' y'
  sol f (refl x) (refl y) = refl (f x y)
\end{code}