Skip to content

MGS.More-Exercise-Solutions

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-Exercise-Solutions where

open import MGS.Classifiers             public
open import MGS.Subsingleton-Truncation public


module โ„•-order-exercise-solution where

  _โ‰ค'_ : โ„• โ†’ โ„• โ†’ ๐“คโ‚€ ฬ‡
  _โ‰ค'_ = โ„•-iteration (โ„• โ†’ ๐“คโ‚€ ฬ‡ ) (ฮป y โ†’ ๐Ÿ™)
          (ฮป f โ†’ โ„•-recursion (๐“คโ‚€ ฬ‡ ) ๐Ÿ˜ (ฮป y P โ†’ f y))

  open โ„•-order

  โ‰ค-and-โ‰ค'-coincide : (x y : โ„•) โ†’ (x โ‰ค y) ๏ผ (x โ‰ค' y)
  โ‰ค-and-โ‰ค'-coincide 0 y = refl _
  โ‰ค-and-โ‰ค'-coincide (succ x) 0 = refl _
  โ‰ค-and-โ‰ค'-coincide (succ x) (succ y) = โ‰ค-and-โ‰ค'-coincide x y

module โ„•-more where

  open Arithmetic renaming (_+_ to _โˆ”_)
  open basic-arithmetic-and-order

  โ‰ค-prop-valued : (x y : โ„•) โ†’ is-subsingleton (x โ‰ค y)
  โ‰ค-prop-valued 0 y               = ๐Ÿ™-is-subsingleton
  โ‰ค-prop-valued (succ x) zero     = ๐Ÿ˜-is-subsingleton
  โ‰ค-prop-valued (succ x) (succ y) = โ‰ค-prop-valued x y

  โ‰ผ-prop-valued : (x y : โ„•) โ†’ is-subsingleton (x โ‰ผ y)
  โ‰ผ-prop-valued x y (z , p) (z' , p') = ฮณ
   where
    q : z ๏ผ z'
    q = +-lc x z z' (x โˆ” z  ๏ผโŸจ p โŸฉ
                     y      ๏ผโŸจ p' โปยน โŸฉ
                     x โˆ” z' โˆŽ)

    ฮณ : z , p ๏ผ z' , p'
    ฮณ = to-subtype-๏ผ (ฮป z โ†’ โ„•-is-set (x โˆ” z) y) q

  โ‰ค-charac : propext ๐“คโ‚€ โ†’ (x y : โ„•) โ†’ (x โ‰ค y) ๏ผ (x โ‰ผ y)
  โ‰ค-charac pe x y = pe (โ‰ค-prop-valued x y) (โ‰ผ-prop-valued x y)
                       (โ‰ค-gives-โ‰ผ x y) (โ‰ผ-gives-โ‰ค x y)

the-subsingletons-are-the-subtypes-of-a-singleton : (X : ๐“ค ฬ‡ )
                                                  โ†’ is-subsingleton X โ†” (X โ†ช ๐Ÿ™)
the-subsingletons-are-the-subtypes-of-a-singleton X = ฯ† , ฯˆ
 where
  i : is-subsingleton X โ†’ is-embedding (!๐Ÿ™' X)
  i s โ‹† (x , refl โ‹†) (y , refl โ‹†) = ap (ฮป - โ†’ - , refl โ‹†) (s x y)

  ฯ† : is-subsingleton X โ†’ X โ†ช ๐Ÿ™
  ฯ† s = !๐Ÿ™ , i s

  ฯˆ : X โ†ช ๐Ÿ™ โ†’ is-subsingleton X
  ฯˆ (f , e) x y = d
   where
    a : x ๏ผ y โ†’ f x ๏ผ f y
    a = ap f {x} {y}

    b : is-equiv a
    b = embedding-gives-ap-is-equiv f e x y

    c : f x ๏ผ f y
    c = ๐Ÿ™-is-subsingleton (f x) (f y)

    d : x ๏ผ y
    d = inverse a b c

the-subsingletons-are-the-subtypes-of-a-singleton' : propext ๐“ค โ†’ global-dfunext
                                                   โ†’ (X : ๐“ค ฬ‡ )
                                                   โ†’ is-subsingleton X ๏ผ (X โ†ช ๐Ÿ™)
the-subsingletons-are-the-subtypes-of-a-singleton' pe fe X = ฮณ
 where
  a : is-subsingleton X โ†” (X โ†ช ๐Ÿ™)
  a = the-subsingletons-are-the-subtypes-of-a-singleton X

  b : is-subsingleton (X โ†ช ๐Ÿ™)
  b (f , e) (f' , e') = to-subtype-๏ผ
                           (being-embedding-is-subsingleton fe)
                           (fe (ฮป x โ†’ ๐Ÿ™-is-subsingleton (f x) (f' x)))

  ฮณ : is-subsingleton X ๏ผ (X โ†ช ๐Ÿ™)
  ฮณ = pe (being-subsingleton-is-subsingleton fe) b (prโ‚ a) (prโ‚‚ a)

Gโ†‘-โ‰ƒ-equation : (ua : is-univalent (๐“ค โŠ” ๐“ฅ))
              โ†’ (X : ๐“ค ฬ‡ )
              โ†’ (A : (ฮฃ Y ๊ž‰ ๐“ค โŠ” ๐“ฅ ฬ‡ , X โ‰ƒ Y) โ†’ ๐“ฆ ฬ‡ )
              โ†’ (a : A (Lift ๐“ฅ X , โ‰ƒ-Lift X))
              โ†’ Gโ†‘-โ‰ƒ ua X A a (Lift ๐“ฅ X) (โ‰ƒ-Lift X) ๏ผ a
Gโ†‘-โ‰ƒ-equation {๐“ค} {๐“ฅ} {๐“ฆ} ua X A a =
  Gโ†‘-โ‰ƒ ua X A a (Lift ๐“ฅ X) (โ‰ƒ-Lift X) ๏ผโŸจ refl (transport A p a) โŸฉ
  transport A p a                     ๏ผโŸจ ap (ฮป - โ†’ transport A - a) q โŸฉ
  transport A (refl t) a              ๏ผโŸจ refl a โŸฉ
  a                                   โˆŽ
 where
  t : (ฮฃ Y ๊ž‰ ๐“ค โŠ” ๐“ฅ ฬ‡ , X โ‰ƒ Y)
  t = (Lift ๐“ฅ X , โ‰ƒ-Lift 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)

Hโ†‘-โ‰ƒ-equation : (ua : is-univalent (๐“ค โŠ” ๐“ฅ))
              โ†’ (X : ๐“ค ฬ‡ )
              โ†’ (A : (Y : ๐“ค โŠ” ๐“ฅ ฬ‡ ) โ†’ X โ‰ƒ Y โ†’ ๐“ฆ ฬ‡ )
              โ†’ (a : A (Lift ๐“ฅ X) (โ‰ƒ-Lift X))
              โ†’ Hโ†‘-โ‰ƒ ua X A a (Lift ๐“ฅ X) (โ‰ƒ-Lift X) ๏ผ a
Hโ†‘-โ‰ƒ-equation ua X A = Gโ†‘-โ‰ƒ-equation ua X (ฮฃ-induction A)

has-section-charac : {X : ๐“ค ฬ‡ } {Y : ๐“ฅ ฬ‡ } (f : X โ†’ Y)
                   โ†’ ((y : Y) โ†’ ฮฃ x ๊ž‰ X , f x ๏ผ y) โ‰ƒ has-section f
has-section-charac f = ฮ ฮฃ-distr-โ‰ƒ

retractions-into : ๐“ค ฬ‡ โ†’ ๐“ค โบ ฬ‡
retractions-into {๐“ค} Y = ฮฃ X ๊ž‰ ๐“ค ฬ‡ , Y โ— X

pointed-types : (๐“ค : Universe) โ†’ ๐“ค โบ ฬ‡
pointed-types ๐“ค = ฮฃ X ๊ž‰ ๐“ค ฬ‡ , X

retraction-classifier : Univalence
                      โ†’ (Y : ๐“ค ฬ‡ ) โ†’ retractions-into Y โ‰ƒ (Y โ†’ pointed-types ๐“ค)
retraction-classifier {๐“ค} ua Y =
 retractions-into Y                                              โ‰ƒโŸจ i โŸฉ
 (ฮฃ X ๊ž‰ ๐“ค ฬ‡ , ฮฃ f ๊ž‰ (X โ†’ Y) , ((y : Y) โ†’ ฮฃ x ๊ž‰ X , f x ๏ผ y))     โ‰ƒโŸจ id-โ‰ƒ _ โŸฉ
 ((๐“ค /[ id ] Y))                                                 โ‰ƒโŸจ ii โŸฉ
 (Y โ†’ pointed-types ๐“ค)                                           โ– 
 where
  i  = โ‰ƒ-sym (ฮฃ-cong (ฮป X โ†’ ฮฃ-cong (ฮป f โ†’ ฮ ฮฃ-distr-โ‰ƒ)))
  ii = special-map-classifier (ua ๐“ค)
        (univalence-gives-dfunext' (ua ๐“ค) (ua (๐“ค โบ)))
        id Y

module surjection-classifier
         (pt : subsingleton-truncations-exist)
         (ua : Univalence)
       where

  hfe : global-hfunext
  hfe = univalence-gives-global-hfunext ua

  open basic-truncation-development pt hfe public

  _โ† _ : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡
  X โ†  Y = ฮฃ f ๊ž‰ (X โ†’ Y), is-surjection f

  surjections-into : ๐“ค ฬ‡ โ†’ ๐“ค โบ ฬ‡
  surjections-into {๐“ค} Y = ฮฃ X ๊ž‰ ๐“ค ฬ‡ , X โ†  Y

  inhabited-types : (๐“ค : Universe) โ†’ ๐“ค โบ ฬ‡
  inhabited-types ๐“ค = ฮฃ X ๊ž‰ ๐“ค ฬ‡ , โˆฅ X โˆฅ

  surjection-classifier : Univalence
                        โ†’ (Y : ๐“ค ฬ‡ )
                        โ†’ surjections-into Y โ‰ƒ (Y โ†’ inhabited-types ๐“ค)
  surjection-classifier {๐“ค} ua = special-map-classifier (ua ๐“ค)
                                  (univalence-gives-dfunext' (ua ๐“ค) (ua (๐“ค โบ)))
                                  โˆฅ_โˆฅ

positive-cantors-diagonal : (e : โ„• โ†’ (โ„• โ†’ โ„•)) โ†’ ฮฃ ฮฑ ๊ž‰ (โ„• โ†’ โ„•), ((n : โ„•) โ†’ ฮฑ โ‰  e n)

cantors-diagonal : ยฌ (ฮฃ e ๊ž‰ (โ„• โ†’ (โ„• โ†’ โ„•)) , ((ฮฑ : โ„• โ†’ โ„•) โ†’ ฮฃ n ๊ž‰ โ„• , ฮฑ ๏ผ e n))

๐Ÿš-has-๐Ÿš-automorphisms : dfunext ๐“คโ‚€ ๐“คโ‚€ โ†’ (๐Ÿš โ‰ƒ ๐Ÿš) โ‰ƒ ๐Ÿš

lifttwo : is-univalent ๐“คโ‚€ โ†’ is-univalent ๐“คโ‚ โ†’ (๐Ÿš ๏ผ ๐Ÿš) ๏ผ Lift ๐“คโ‚ ๐Ÿš

DNE : โˆ€ ๐“ค โ†’ ๐“ค โบ ฬ‡
DNE ๐“ค = (P : ๐“ค ฬ‡ ) โ†’ is-subsingleton P โ†’ ยฌยฌ P โ†’ P

ne : (X : ๐“ค ฬ‡ ) โ†’ ยฌยฌ (X + ยฌ X)

DNE-gives-EM : dfunext ๐“ค ๐“คโ‚€ โ†’ DNE ๐“ค โ†’ EM ๐“ค

EM-gives-DNE : EM ๐“ค โ†’ DNE ๐“ค

SN : โˆ€ ๐“ค โ†’ ๐“ค โบ ฬ‡
SN ๐“ค = (P : ๐“ค ฬ‡ ) โ†’ is-subsingleton P โ†’ ฮฃ X ๊ž‰ ๐“ค ฬ‡ , P โ†” ยฌ X

SN-gives-DNE : SN ๐“ค โ†’ DNE ๐“ค

DNE-gives-SN : DNE ๐“ค โ†’ SN ๐“ค

succ-no-fixed-point : (n : โ„•) โ†’ succ n โ‰  n
succ-no-fixed-point 0        = positive-not-zero 0
succ-no-fixed-point (succ n) = ฮณ
 where
  IH : succ n โ‰  n
  IH = succ-no-fixed-point n

  ฮณ : succ (succ n) โ‰  succ n
  ฮณ p = IH (succ-lc p)

positive-cantors-diagonal = sol
 where
  sol : (e : โ„• โ†’ (โ„• โ†’ โ„•)) โ†’ ฮฃ ฮฑ ๊ž‰ (โ„• โ†’ โ„•), ((n : โ„•) โ†’ ฮฑ โ‰  e n)
  sol e = (ฮฑ , ฯ†)
   where
    ฮฑ : โ„• โ†’ โ„•
    ฮฑ n = succ (e n n)

    ฯ† : (n : โ„•) โ†’ ฮฑ โ‰  e n
    ฯ† n p = succ-no-fixed-point (e n n) q
     where
      q = succ (e n n)  ๏ผโŸจ refl (ฮฑ n) โŸฉ
          ฮฑ n           ๏ผโŸจ ap (ฮป - โ†’ - n) p โŸฉ
          e n n         โˆŽ

cantors-diagonal = sol
 where
  sol : ยฌ (ฮฃ e ๊ž‰ (โ„• โ†’ (โ„• โ†’ โ„•)) , ((ฮฑ : โ„• โ†’ โ„•) โ†’ ฮฃ n ๊ž‰ โ„• , ฮฑ ๏ผ e n))
  sol (e , ฮณ) = c
   where
    ฮฑ : โ„• โ†’ โ„•
    ฮฑ = prโ‚ (positive-cantors-diagonal e)

    ฯ† : (n : โ„•) โ†’ ฮฑ โ‰  e n
    ฯ† = prโ‚‚ (positive-cantors-diagonal e)

    b : ฮฃ n ๊ž‰ โ„• , ฮฑ ๏ผ e n
    b = ฮณ ฮฑ

    c : ๐Ÿ˜
    c = ฯ† (prโ‚ b) (prโ‚‚ b)

๐Ÿš-has-๐Ÿš-automorphisms = sol
 where
  sol : dfunext ๐“คโ‚€ ๐“คโ‚€ โ†’ (๐Ÿš โ‰ƒ ๐Ÿš) โ‰ƒ ๐Ÿš
  sol fe = invertibility-gives-โ‰ƒ f (g , ฮท , ฮต)
   where
    f : (๐Ÿš โ‰ƒ ๐Ÿš) โ†’ ๐Ÿš
    f (h , e) = h โ‚€

    g : ๐Ÿš โ†’ (๐Ÿš โ‰ƒ ๐Ÿš)
    g โ‚€ = id , id-is-equiv ๐Ÿš
    g โ‚ = swapโ‚‚ , swapโ‚‚-is-equiv

    ฮท : (e : ๐Ÿš โ‰ƒ ๐Ÿš) โ†’ g (f e) ๏ผ e
    ฮท (h , e) = ฮณ (h โ‚€) (h โ‚) (refl (h โ‚€)) (refl (h โ‚))
     where
      ฮณ : (m n : ๐Ÿš) โ†’ h โ‚€ ๏ผ m โ†’ h โ‚ ๏ผ n โ†’ g (h โ‚€) ๏ผ (h , e)

      ฮณ โ‚€ โ‚€ p q = !๐Ÿ˜ (g (h โ‚€) ๏ผ (h , e))
                     (โ‚-is-not-โ‚€ (equivs-are-lc h e (h โ‚ ๏ผโŸจ q โŸฉ
                                                     โ‚€   ๏ผโŸจ p โปยน โŸฉ
                                                     h โ‚€ โˆŽ)))

      ฮณ โ‚€ โ‚ p q = to-subtype-๏ผ
                     (being-equiv-is-subsingleton fe fe)
                     (fe (๐Ÿš-induction (ฮป n โ†’ prโ‚ (g (h โ‚€)) n ๏ผ h n)
                               (prโ‚ (g (h โ‚€)) โ‚€ ๏ผโŸจ ap (ฮป - โ†’ prโ‚ (g -) โ‚€) p โŸฉ
                                prโ‚ (g โ‚€) โ‚€     ๏ผโŸจ refl โ‚€ โŸฉ
                                โ‚€               ๏ผโŸจ p โปยน โŸฉ
                                h โ‚€             โˆŽ)
                               (prโ‚ (g (h โ‚€)) โ‚ ๏ผโŸจ ap (ฮป - โ†’ prโ‚ (g -) โ‚) p โŸฉ
                                prโ‚ (g โ‚€) โ‚     ๏ผโŸจ refl โ‚ โŸฉ
                                โ‚               ๏ผโŸจ q โปยน โŸฉ
                                h โ‚             โˆŽ)))

      ฮณ โ‚ โ‚€ p q = to-subtype-๏ผ
                     (being-equiv-is-subsingleton fe fe)
                     (fe (๐Ÿš-induction (ฮป n โ†’ prโ‚ (g (h โ‚€)) n ๏ผ h n)
                               (prโ‚ (g (h โ‚€)) โ‚€ ๏ผโŸจ ap (ฮป - โ†’ prโ‚ (g -) โ‚€) p โŸฉ
                                prโ‚ (g โ‚) โ‚€     ๏ผโŸจ refl โ‚ โŸฉ
                                โ‚               ๏ผโŸจ p โปยน โŸฉ
                                h โ‚€             โˆŽ)
                               (prโ‚ (g (h โ‚€)) โ‚ ๏ผโŸจ ap (ฮป - โ†’ prโ‚ (g -) โ‚) p โŸฉ
                                prโ‚ (g โ‚) โ‚     ๏ผโŸจ refl โ‚€ โŸฉ
                                โ‚€               ๏ผโŸจ q โปยน โŸฉ
                                h โ‚             โˆŽ)))

      ฮณ โ‚ โ‚ p q = !๐Ÿ˜ (g (h โ‚€) ๏ผ (h , e))
                     (โ‚-is-not-โ‚€ (equivs-are-lc h e (h โ‚ ๏ผโŸจ q โŸฉ
                                                     โ‚   ๏ผโŸจ p โปยน โŸฉ
                                                     h โ‚€ โˆŽ)))

    ฮต : (n : ๐Ÿš) โ†’ f (g n) ๏ผ n
    ฮต โ‚€ = refl โ‚€
    ฮต โ‚ = refl โ‚

lifttwo = sol
 where
  sol : is-univalent ๐“คโ‚€ โ†’ is-univalent ๐“คโ‚ โ†’ (๐Ÿš ๏ผ ๐Ÿš) ๏ผ Lift ๐“คโ‚ ๐Ÿš
  sol uaโ‚€ uaโ‚ = Eqโ†’Id uaโ‚ (๐Ÿš ๏ผ ๐Ÿš) (Lift ๐“คโ‚ ๐Ÿš) e
   where
    e = (๐Ÿš ๏ผ ๐Ÿš)   โ‰ƒโŸจ Idโ†’Eq ๐Ÿš ๐Ÿš , uaโ‚€ ๐Ÿš ๐Ÿš โŸฉ
        (๐Ÿš โ‰ƒ ๐Ÿš)   โ‰ƒโŸจ ๐Ÿš-has-๐Ÿš-automorphisms (univalence-gives-dfunext uaโ‚€) โŸฉ
        ๐Ÿš         โ‰ƒโŸจ โ‰ƒ-sym (Lift-โ‰ƒ ๐Ÿš) โŸฉ
        Lift ๐“คโ‚ ๐Ÿš โ– 

hde-is-subsingleton : dfunext ๐“ค ๐“คโ‚€
                    โ†’ dfunext ๐“ค ๐“ค
                    โ†’ (X : ๐“ค ฬ‡ )
                    โ†’ is-subsingleton (has-decidable-equality X)
hde-is-subsingleton feโ‚€ fe X h h' = c h h'
 where
  a : (x y : X) โ†’ is-subsingleton (decidable (x ๏ผ y))
  a x y = +-is-subsingleton' feโ‚€ b
   where
    b : is-subsingleton (x ๏ผ y)
    b = hedberg h x y

  c : is-subsingleton (has-decidable-equality X)
  c = ฮ -is-subsingleton fe (ฮป x โ†’ ฮ -is-subsingleton fe (a x))

ne = sol
 where
  sol : (X : ๐“ค ฬ‡ ) โ†’ ยฌยฌ (X + ยฌ X)
  sol X = ฮป (f : ยฌ (X + ยฌ X)) โ†’ f (inr (ฮป (x : X) โ†’ f (inl x)))

DNE-gives-EM = sol
 where
  sol : dfunext ๐“ค ๐“คโ‚€ โ†’ DNE ๐“ค โ†’ EM ๐“ค
  sol fe dne P i = dne (P + ยฌ P) (+-is-subsingleton' fe i) (ne P)

EM-gives-DNE = sol
 where
  sol : EM ๐“ค โ†’ DNE ๐“ค
  sol em P i = ฮณ (em P i)
   where
    ฮณ : P + ยฌ P โ†’ ยฌยฌ P โ†’ P
    ฮณ (inl p) ฯ† = p
    ฮณ (inr n) ฯ† = !๐Ÿ˜ P (ฯ† n)

SN-gives-DNE = sol
 where
  sol : SN ๐“ค โ†’ DNE ๐“ค
  sol {๐“ค} sn P i = h
   where
    X : ๐“ค ฬ‡
    X = prโ‚ (sn P i)

    f : P โ†’ ยฌ X
    f = prโ‚ (prโ‚‚ (sn P i))

    g : ยฌ X โ†’ P
    g = prโ‚‚ (prโ‚‚ (sn P i))

    f' : ยฌยฌ P โ†’ ยฌ (ยฌยฌ X)
    f' = contrapositive (contrapositive f)

    h : ยฌยฌ P โ†’ P
    h = g โˆ˜ tno X โˆ˜ f'

    h' : ยฌยฌ P โ†’ P
    h' ฯ† = g (ฮป (x : X) โ†’ ฯ† (ฮป (p : P) โ†’ f p x))

DNE-gives-SN = sol
 where
  sol : DNE ๐“ค โ†’ SN ๐“ค
  sol dne P i = ยฌ P , dni P , dne P i