Martin Escardo, August 2018.

Large set quotients in univalent mathematics in Agda notation.

This took place during the Dagstuhl meeting "Formalization of
Mathematics in Type Theory", because Dan Grayson wanted to see how
universe levels work in Agda and I thought that this would be a nice
example to illustrate that.

We assume, in addition to Spartan Martin-LΓΆf type theory,

 * function extensionality
   (any two pointwise equal functions are equal),

 * propositional extensionality
   (any two logically equivalent propositions are equal),

 * propositional truncation
   (any type can be universally mapped into a prop in the same
   universe),

and no resizing axioms.

The K axiom is not used (the without-K option below). We also make
sure pattern matching corresponds to Martin-LΓΆf eliminators, using the
option exact-split. With the option safe we make sure that nothing
is postulated - any non-MLTT axiom has to be an explicit assumption
(argument to a function or a module).

\begin{code}

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

open import MLTT.Spartan

open import Quotient.Type
open import UF.Base hiding (_β‰ˆ_)
open import UF.FunExt
open import UF.Powerset
open import UF.PropTrunc
open import UF.Sets
open import UF.Sets-Properties
open import UF.SubtypeClassifier
open import UF.Subsingletons
open import UF.Subsingletons-FunExt

module Quotient.Large
        (pt  : propositional-truncations-exist)
        (fe  : Fun-Ext)
        (pe  : Prop-Ext)
       where

open PropositionalTruncation pt
open import UF.ImageAndSurjection pt

\end{code}

(NB. The Agda library uses the word "Level" for universes, and then
what we write "𝓀 Μ‡" here is written "Set 𝓀". This is not good for
univalent mathematics, because the types in 𝓀 Μ‡ need not be sets, and
also because it places emphasis on levels rather than universes
themselves.)

Now, using an anonymous module UF.with parameters (corresponding to a
section in Coq), we assume propositional truncations that stay in the
same universe, function extensionality for all universes, two
universes 𝓀 and π“₯, propositional truncation for the universe π“₯, a type
X : 𝓀 Μ‡, and an equivalence relation _β‰ˆ_ with values in π“₯ Μ‡.

\begin{code}

module large-quotient
       {𝓀 π“₯ : Universe}
       (X   : 𝓀 Μ‡ )
       (≋@(_β‰ˆ_ , β‰ˆp , β‰ˆr , β‰ˆs , β‰ˆt) : EqRel {𝓀} {π“₯} X)
      where

\end{code}

Now, Ξ© π“₯ is the type of subsingletons, or (univalent) propositions, or
h-propositions, or mere propositions, in the universe π“₯, which lives
in the next universe π“₯ ⁺.

From the relation _β‰ˆ_ : X β†’ (X β†’ π“₯ Μ‡ ) we define a relation
X β†’ (X β†’ Ξ© π“₯), which of course is formally a function. We then take
the quotient X/β‰ˆ to be the image of this function.

Of course, it is for constructing the image that we need propositional
truncations.

\begin{code}

 equiv-rel : X β†’ (X β†’ Ξ© π“₯)
 equiv-rel x y = x β‰ˆ y , β‰ˆp x y

\end{code}

Then the quotient lives in the least upper bound of 𝓀 and π“₯ ⁺, where π“₯ ⁺
is the successor of the universe π“₯:

\begin{code}

 X/β‰ˆ : 𝓀 βŠ” (π“₯ ⁺) Μ‡
 X/β‰ˆ = image equiv-rel

 X/β‰ˆ-is-set : is-set X/β‰ˆ
 X/β‰ˆ-is-set = subsets-of-sets-are-sets (X β†’ Ξ© π“₯) _
               (powersets-are-sets'' fe fe pe)
               βˆ₯βˆ₯-is-prop

 Ξ· : X β†’ X/β‰ˆ
 Ξ· = corestriction equiv-rel

\end{code}

Then Ξ· is the universal solution to the problem of transforming
equivalence _β‰ˆ_ into equality _=_ (identity type).

By construction, Ξ· is a surjection, of course:

\begin{code}

 Ξ·-surjection : is-surjection Ξ·
 Ξ·-surjection = corestrictions-are-surjections equiv-rel

\end{code}

It is convenient to use the following induction principle for
reasoning about the image. Notice that the property we consider has
values in any universe 𝓦 we please:

\begin{code}

 quotient-induction : βˆ€ {𝓦} (P : X/β‰ˆ β†’ 𝓦 Μ‡ )
                    β†’ ((x' : X/β‰ˆ) β†’ is-prop (P x'))
                    β†’ ((x : X) β†’ P (Ξ· x))
                    β†’ (x' : X/β‰ˆ) β†’ P x'
 quotient-induction = surjection-induction Ξ· Ξ·-surjection

\end{code}

The first part of the universal property of Ξ· says that equivalent
points are mapped to equal points:

\begin{code}

 Ξ·-identifies-related-points : {x y : X} β†’ x β‰ˆ y β†’ Ξ· x = Ξ· y
 Ξ·-identifies-related-points {x} {y} e =
   to-Σ-= (dfunext fe
          (Ξ» z β†’ to-Ξ£-= (pe (β‰ˆp x z) (β‰ˆp y z) (β‰ˆt y x z (β‰ˆs x y e)) (β‰ˆt x y z e) ,
                         being-prop-is-prop fe _ _)) ,
       βˆ₯βˆ₯-is-prop _ _)

\end{code}

We also need the fact that Ξ· reflects equality into equivalence:

\begin{code}

 Ξ·-relates-identified-points : {x y : X} β†’ Ξ· x = Ξ· y β†’ x β‰ˆ y
 Ξ·-relates-identified-points {x} {y} p = equiv-rel-reflect (ap pr₁ p)
  where
   equiv-rel-reflect : equiv-rel x = equiv-rel y β†’ x β‰ˆ y
   equiv-rel-reflect q = b (β‰ˆr y)
    where
     a : (y β‰ˆ y) = (x β‰ˆ y)
     a = ap (Ξ» - β†’ pr₁ (- y)) (q ⁻¹)
     b : (y β‰ˆ y) β†’ (x β‰ˆ y)
     b = Idtofun a

\end{code}

We are now ready to formulate and prove the universal property of the
quotient. What is noteworthy here, regarding universes, is that the
universal property says that we can eliminate into any set A of any
universe 𝓦.

                   Ξ·
              X ------> X/β‰ˆ
               \       .
                \     .
               f \   . f'
                  \ .
                   v
                   A

\begin{code}

 universal-property : βˆ€ {𝓦} (A : 𝓦 Μ‡ )
                    β†’ is-set A
                    β†’ (f : X β†’ A)
                    β†’ ({x x' : X} β†’ x β‰ˆ x' β†’ f x = f x')
                    β†’ βˆƒ! f' κž‰ ( X/β‰ˆ β†’ A), f' ∘ Ξ· ∼ f
 universal-property {𝓦} A iss f pr = ic
  where
   Ο† : (x' : X/β‰ˆ) β†’ is-prop (Ξ£ a κž‰ A , βˆƒ x κž‰ X ,  (Ξ· x = x') Γ— (f x = a))
   Ο† = quotient-induction _ Ξ³ induction-step
     where
      induction-step : (y : X) β†’ is-prop (Ξ£ a κž‰ A , βˆƒ x κž‰ X ,  (Ξ· x = Ξ· y) Γ— (f x = a))
      induction-step x (a , d) (b , e) = to-Ξ£-= (p , βˆ₯βˆ₯-is-prop _ _)
       where
        h : (Ξ£ x' κž‰ X , (Ξ· x' = Ξ· x) Γ— (f x' = a))
          β†’ (Ξ£ y' κž‰ X , (Ξ· y' = Ξ· x) Γ— (f y' = b))
          β†’ a = b
        h (x' , r , s) (y' , t , u) = s ⁻¹ βˆ™ pr (Ξ·-relates-identified-points (r βˆ™ t ⁻¹)) βˆ™ u

        p : a = b
        p = βˆ₯βˆ₯-rec iss (Ξ» Οƒ β†’ βˆ₯βˆ₯-rec iss (h Οƒ) e) d

      Ξ³ : (x' : X/β‰ˆ) β†’ is-prop (is-prop (Ξ£ a κž‰ A , βˆƒ x κž‰ X , (Ξ· x = x') Γ— (f x = a)))
      Ξ³ x' = being-prop-is-prop fe

   k : (x' : X/β‰ˆ) β†’ Ξ£ a κž‰ A , βˆƒ x κž‰ X , (Ξ· x = x') Γ— (f x = a)
   k = quotient-induction _ Ο† induction-step
    where
     induction-step : (y : X) β†’ Ξ£ a κž‰ A , βˆƒ x κž‰ X , (Ξ· x = Ξ· y) Γ— (f x = a)
     induction-step x = f x , ∣ x , refl , refl ∣

   f' : X/β‰ˆ β†’ A
   f' x' = pr₁ (k x')

   r : f' ∘ η ∼ f
   r = h
    where
     g : (y : X) β†’ βˆƒ x κž‰ X , (Ξ· x = Ξ· y) Γ— (f x = f' (Ξ· y))
     g y = prβ‚‚ (k (Ξ· y))

     j : (y : X) β†’ (Ξ£ x κž‰ X , (Ξ· x = Ξ· y) Γ— (f x = f' (Ξ· y))) β†’ f' (Ξ· y) = f y
     j y (x , p , q) = q ⁻¹ βˆ™ pr (Ξ·-relates-identified-points p)

     h : (y : X) β†’ f' (Ξ· y) = f y
     h y = βˆ₯βˆ₯-rec iss (j y) (g y)

   c : (Οƒ : Ξ£ f'' κž‰ (X/β‰ˆ β†’ A), f'' ∘ Ξ· ∼ f) β†’ (f' , r) = Οƒ
   c (f'' , s) = to-Σ-= (t , v) -- (t , v)
    where
     w : βˆ€ x β†’ f' (Ξ· x) = f'' (Ξ· x)
     w x = r x βˆ™ (s x)⁻¹

     t : f' = f''
     t = dfunext fe (quotient-induction _ (Ξ» _ β†’ iss) w)

     u : f'' ∘ η ∼ f
     u = transport (Ξ» - β†’ - ∘ Ξ· ∼ f) t r

     v : u = s
     v = dfunext fe (Ξ» x β†’ iss (u x) (s x))

   ic : βˆƒ! f' κž‰ (X/β‰ˆ β†’ A), f' ∘ Ξ· ∼ f
   ic = (f' , r) , c

\end{code}

Added 11 Sep 2023 by Martin Escardo. Package the above into the type
of existence of large effective set quotients.

\begin{code}

large-set-quotients : large-set-quotients-exist
large-set-quotients =
 record
  { _/_ = Ξ» {𝓀 π“₯ : Universe} (X : 𝓀 Μ‡ ) β†’ large-quotient.X/β‰ˆ X
  ; Ξ·/ = Ξ» {𝓀 π“₯ : Universe} {X : 𝓀 Μ‡ } β†’ large-quotient.Ξ· X
  ; Ξ·/-identifies-related-points = Ξ» {𝓀 π“₯ : Universe} {X : 𝓀 Μ‡ }
                                 β†’ large-quotient.Ξ·-identifies-related-points X
  ; /-is-set = Ξ» {𝓀 π“₯ : Universe} {X : 𝓀 Μ‡ } β†’ large-quotient.X/β‰ˆ-is-set X
  ; /-universality = Ξ» {𝓀 π“₯ : Universe} {X : 𝓀 Μ‡ } (≋ : EqRel {𝓀} {π“₯} X)
                       {𝓦 : Universe} {Y : 𝓦 Μ‡ }
                   β†’ large-quotient.universal-property X ≋ Y
  }

large-effective-set-quotients : are-effective large-set-quotients
large-effective-set-quotients {𝓀} {π“₯} {X} ≋ {x} {y} =
 large-quotient.Ξ·-relates-identified-points X ≋

\end{code}