Skip to content

MGS.SIP

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.SIP where

open import MGS.More-FunExt-Consequences public
open import MGS.Yoneda                   public
open import MGS.Powerset                 public
open import MGS.Classifiers              public
open import MGS.Subsingleton-Truncation  public

module sip where

 โŸจ_โŸฉ : {S : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ } โ†’ ฮฃ S โ†’ ๐“ค ฬ‡
 โŸจ X , s โŸฉ = X

 structure : {S : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ } (A : ฮฃ S) โ†’ S โŸจ A โŸฉ
 structure (X , s) = s

 canonical-map : {S : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ }
                 (ฮน : (A B : ฮฃ S) โ†’ โŸจ A โŸฉ โ‰ƒ โŸจ B โŸฉ โ†’ ๐“ฆ ฬ‡ )
                 (ฯ : (A : ฮฃ S) โ†’ ฮน A A (id-โ‰ƒ โŸจ A โŸฉ))
                 {X : ๐“ค ฬ‡ }
                 (s t : S X)

               โ†’ s ๏ผ t โ†’ ฮน (X , s) (X , t) (id-โ‰ƒ X)

 canonical-map ฮน ฯ {X} s s (refl s) = ฯ (X , s)

 SNS : (๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ ) โ†’ (๐“ฆ : Universe) โ†’ ๐“ค โบ โŠ” ๐“ฅ โŠ” (๐“ฆ โบ) ฬ‡

 SNS {๐“ค} {๐“ฅ} S ๐“ฆ = ฮฃ ฮน ๊ž‰ ((A B : ฮฃ S) โ†’ (โŸจ A โŸฉ โ‰ƒ โŸจ B โŸฉ โ†’ ๐“ฆ ฬ‡ ))
                  , ฮฃ ฯ ๊ž‰ ((A : ฮฃ S) โ†’ ฮน A A (id-โ‰ƒ โŸจ A โŸฉ))
                  , ({X : ๐“ค ฬ‡ } (s t : S X) โ†’ is-equiv (canonical-map ฮน ฯ s t))

 homomorphic : {S : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ } โ†’ SNS S ๐“ฆ
             โ†’ (A B : ฮฃ S) โ†’ โŸจ A โŸฉ โ‰ƒ โŸจ B โŸฉ โ†’ ๐“ฆ ฬ‡

 homomorphic (ฮน , ฯ , ฮธ) = ฮน

 _โ‰ƒ[_]_ : {S : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ } โ†’ ฮฃ S โ†’ SNS S ๐“ฆ โ†’ ฮฃ S โ†’ ๐“ค โŠ” ๐“ฆ ฬ‡

 A โ‰ƒ[ ฯƒ ] B = ฮฃ f ๊ž‰ (โŸจ A โŸฉ โ†’ โŸจ B โŸฉ)
            , ฮฃ i ๊ž‰ is-equiv f
            , homomorphic ฯƒ A B (f , i)

 Idโ†’homEq : {S : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ } (ฯƒ : SNS S ๐“ฆ)
          โ†’ (A B : ฮฃ S) โ†’ (A ๏ผ B) โ†’ (A โ‰ƒ[ ฯƒ ] B)

 Idโ†’homEq (_ , ฯ , _) A A (refl A) = id , id-is-equiv โŸจ A โŸฉ , ฯ A

 homomorphism-lemma : {S : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ } (ฯƒ : SNS S ๐“ฆ)
                      (A B : ฮฃ S) (p : โŸจ A โŸฉ ๏ผ โŸจ B โŸฉ)
                    โ†’
                      (transport S p (structure A) ๏ผ structure B)
                    โ‰ƒ  homomorphic ฯƒ A B (Idโ†’Eq โŸจ A โŸฉ โŸจ B โŸฉ p)

 homomorphism-lemma (ฮน , ฯ , ฮธ) (X , s) (X , t) (refl X) = ฮณ
  where
   ฮณ : (s ๏ผ t) โ‰ƒ ฮน (X , s) (X , t) (id-โ‰ƒ X)
   ฮณ = (canonical-map ฮน ฯ s t , ฮธ s t)

 characterization-of-๏ผ : is-univalent ๐“ค
                       โ†’ {S : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ } (ฯƒ : SNS S ๐“ฆ)
                       โ†’ (A B : ฮฃ S)

                       โ†’ (A ๏ผ B) โ‰ƒ (A โ‰ƒ[ ฯƒ ] B)

 characterization-of-๏ผ ua {S} ฯƒ A B =

    (A ๏ผ B)                                                           โ‰ƒโŸจ i โŸฉ
    (ฮฃ p ๊ž‰ โŸจ A โŸฉ ๏ผ โŸจ B โŸฉ , transport S p (structure A) ๏ผ structure B) โ‰ƒโŸจ ii โŸฉ
    (ฮฃ p ๊ž‰ โŸจ A โŸฉ ๏ผ โŸจ B โŸฉ , ฮน A B (Idโ†’Eq โŸจ A โŸฉ โŸจ B โŸฉ p))               โ‰ƒโŸจ iii โŸฉ
    (ฮฃ e ๊ž‰ โŸจ A โŸฉ โ‰ƒ โŸจ B โŸฉ , ฮน A B e)                                   โ‰ƒโŸจ iv โŸฉ
    (A โ‰ƒ[ ฯƒ ] B)                                                      โ– 

  where
   ฮน   = homomorphic ฯƒ

   i   = ฮฃ-๏ผ-โ‰ƒ A B
   ii  = ฮฃ-cong (homomorphism-lemma ฯƒ A B)
   iii = โ‰ƒ-sym (ฮฃ-change-of-variable (ฮน A B) (Idโ†’Eq โŸจ A โŸฉ โŸจ B โŸฉ) (ua โŸจ A โŸฉ โŸจ B โŸฉ))
   iv  = ฮฃ-assoc

 Idโ†’homEq-is-equiv : (ua : is-univalent ๐“ค) {S : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ } (ฯƒ : SNS S ๐“ฆ)
                   โ†’ (A B : ฮฃ S) โ†’ is-equiv (Idโ†’homEq ฯƒ A B)

 Idโ†’homEq-is-equiv ua {S} ฯƒ A B = ฮณ
  where
   h : (A B : ฮฃ S) โ†’ Idโ†’homEq ฯƒ A B โˆผ โŒœ characterization-of-๏ผ ua ฯƒ A B โŒ
   h A A (refl A) = refl _

   ฮณ : is-equiv (Idโ†’homEq ฯƒ A B)
   ฮณ = equivs-closed-under-โˆผ
       (โŒœโŒ-is-equiv (characterization-of-๏ผ ua ฯƒ A B))
       (h A B)

 module _ {S : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ }
          (ฮน : (A B : ฮฃ S) โ†’ โŸจ A โŸฉ โ‰ƒ โŸจ B โŸฉ โ†’ ๐“ฆ ฬ‡ )
          (ฯ : (A : ฮฃ S) โ†’ ฮน A A (id-โ‰ƒ โŸจ A โŸฉ))
          {X : ๐“ค ฬ‡ }

        where

  canonical-map-charac : (s t : S X) (p : s ๏ผ t)

                       โ†’ canonical-map ฮน ฯ s t p
                       ๏ผ transport (ฮป - โ†’ ฮน (X , s) (X , -) (id-โ‰ƒ X)) p (ฯ (X , s))

  canonical-map-charac s = transport-lemma (ฮป t โ†’ ฮน (X , s) (X , t) (id-โ‰ƒ X)) s
                            (canonical-map ฮน ฯ s)

  when-canonical-map-is-equiv : ((s t : S X) โ†’ is-equiv (canonical-map ฮน ฯ s t))
                              โ†” ((s : S X) โ†’ โˆƒ! t ๊ž‰ S X , ฮน (X , s) (X , t) (id-โ‰ƒ X))

  when-canonical-map-is-equiv = (ฮป e s โ†’ fiberwise-equiv-universal (A s) s (ฯ„ s) (e s)) ,
                                (ฮป ฯ† s โ†’ universal-fiberwise-equiv (A s) (ฯ† s) s (ฯ„ s))
   where
    A = ฮป s t โ†’ ฮน (X , s) (X , t) (id-โ‰ƒ X)
    ฯ„ = canonical-map ฮน ฯ

  canonical-map-equiv-criterion : ((s t : S X) โ†’ (s ๏ผ t) โ‰ƒ ฮน (X , s) (X , t) (id-โ‰ƒ X))
                                โ†’ (s t : S X) โ†’ is-equiv (canonical-map ฮน ฯ s t)

  canonical-map-equiv-criterion ฯ† s = fiberwise-equiv-criterion'
                                       (ฮป t โ†’ ฮน (X , s) (X , t) (id-โ‰ƒ X))
                                       s (ฯ† s) (canonical-map ฮน ฯ s)

  canonical-map-equiv-criterion' : ((s t : S X) โ†’ ฮน (X , s) (X , t) (id-โ‰ƒ X) โ— (s ๏ผ t))
                                 โ†’ (s t : S X) โ†’ is-equiv (canonical-map ฮน ฯ s t)

  canonical-map-equiv-criterion' ฯ† s = fiberwise-equiv-criterion
                                        (ฮป t โ†’ ฮน (X , s) (X , t) (id-โ‰ƒ X))
                                        s (ฯ† s) (canonical-map ฮน ฯ s)

module โˆž-magma {๐“ค : Universe} where

 open sip

 โˆž-magma-structure : ๐“ค ฬ‡ โ†’ ๐“ค ฬ‡
 โˆž-magma-structure X = X โ†’ X โ†’ X

 โˆž-Magma : ๐“ค โบ ฬ‡
 โˆž-Magma = ฮฃ X ๊ž‰ ๐“ค ฬ‡ , โˆž-magma-structure X

 sns-data : SNS โˆž-magma-structure ๐“ค
 sns-data = (ฮน , ฯ , ฮธ)
  where
   ฮน : (A B : โˆž-Magma) โ†’ โŸจ A โŸฉ โ‰ƒ โŸจ B โŸฉ โ†’ ๐“ค ฬ‡
   ฮน (X , _ยท_) (Y , _*_) (f , _) = (ฮป x x' โ†’ f (x ยท x')) ๏ผ (ฮป x x' โ†’ f x * f x')

   ฯ : (A : โˆž-Magma) โ†’ ฮน A A (id-โ‰ƒ โŸจ A โŸฉ)
   ฯ (X , _ยท_) = refl _ยท_

   h : {X : ๐“ค ฬ‡ } {_ยท_ _*_ : โˆž-magma-structure X}
     โ†’ canonical-map ฮน ฯ _ยท_ _*_ โˆผ ๐‘–๐‘‘ (_ยท_ ๏ผ _*_)

   h (refl _ยท_) = refl (refl _ยท_)

   ฮธ : {X : ๐“ค ฬ‡ } (_ยท_ _*_ : โˆž-magma-structure X)
     โ†’ is-equiv (canonical-map ฮน ฯ _ยท_ _*_)

   ฮธ _ยท_ _*_ = equivs-closed-under-โˆผ (id-is-equiv (_ยท_ ๏ผ _*_)) h

 _โ‰…_ : โˆž-Magma โ†’ โˆž-Magma โ†’ ๐“ค ฬ‡

 (X , _ยท_) โ‰… (Y , _*_) =

           ฮฃ f ๊ž‰ (X โ†’ Y), is-equiv f
                        ร— ((ฮป x x' โ†’ f (x ยท x')) ๏ผ (ฮป x x' โ†’ f x * f x'))

 characterization-of-โˆž-Magma-๏ผ : is-univalent ๐“ค โ†’ (A B : โˆž-Magma) โ†’ (A ๏ผ B) โ‰ƒ (A โ‰… B)
 characterization-of-โˆž-Magma-๏ผ ua = characterization-of-๏ผ ua sns-data

 characterization-of-characterization-of-โˆž-Magma-๏ผ :

    (ua : is-univalent ๐“ค) (A : โˆž-Magma)
  โ†’
    โŒœ characterization-of-โˆž-Magma-๏ผ ua A A โŒ (refl A)
  ๏ผ
    (๐‘–๐‘‘ โŸจ A โŸฉ , id-is-equiv โŸจ A โŸฉ , refl _)

 characterization-of-characterization-of-โˆž-Magma-๏ผ ua A = refl _

module sip-with-axioms where

 open sip

 [_] : {S : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ } {axioms : (X : ๐“ค ฬ‡ ) โ†’ S X โ†’ ๐“ฆ ฬ‡ }
     โ†’ (ฮฃ X ๊ž‰ ๐“ค ฬ‡ , ฮฃ s ๊ž‰ S X , axioms X s) โ†’ ฮฃ S

 [ X , s , _ ] = (X , s)

 โŸช_โŸซ : {S : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ } {axioms : (X : ๐“ค ฬ‡ ) โ†’ S X โ†’ ๐“ฆ ฬ‡ }
     โ†’ (ฮฃ X ๊ž‰ ๐“ค ฬ‡ , ฮฃ s ๊ž‰ S X , axioms X s) โ†’ ๐“ค ฬ‡

 โŸช X , _ , _ โŸซ = X

 add-axioms : {S : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ }
              (axioms : (X : ๐“ค ฬ‡ ) โ†’ S X โ†’ ๐“ฆ ฬ‡ )
            โ†’ ((X : ๐“ค ฬ‡ ) (s : S X) โ†’ is-subsingleton (axioms X s))

            โ†’ SNS S ๐“ฃ
            โ†’ SNS (ฮป X โ†’ ฮฃ s ๊ž‰ S X , axioms X s) ๐“ฃ

 add-axioms {๐“ค} {๐“ฅ} {๐“ฆ} {๐“ฃ} {S} axioms i (ฮน , ฯ , ฮธ) = ฮน' , ฯ' , ฮธ'
  where
   S' : ๐“ค ฬ‡ โ†’ ๐“ฅ โŠ” ๐“ฆ ฬ‡
   S' X = ฮฃ s ๊ž‰ S X , axioms X s

   ฮน' : (A B : ฮฃ S') โ†’ โŸจ A โŸฉ โ‰ƒ โŸจ B โŸฉ โ†’ ๐“ฃ ฬ‡
   ฮน' A B = ฮน [ A ] [ B ]

   ฯ' : (A : ฮฃ S') โ†’ ฮน' A A (id-โ‰ƒ โŸจ A โŸฉ)
   ฯ' A = ฯ [ A ]

   ฮธ' : {X : ๐“ค ฬ‡ } (s' t' : S' X) โ†’ is-equiv (canonical-map ฮน' ฯ' s' t')
   ฮธ' {X} (s , a) (t , b) = ฮณ
    where
     ฯ€ : S' X โ†’ S X
     ฯ€ (s , _) = s

     j : is-embedding ฯ€
     j = prโ‚-embedding (i X)

     k : {s' t' : S' X} โ†’ is-equiv (ap ฯ€ {s'} {t'})
     k {s'} {t'} = embedding-gives-ap-is-equiv ฯ€ j s' t'

     l : canonical-map ฮน' ฯ' (s , a) (t , b)
       โˆผ canonical-map ฮน ฯ s t โˆ˜ ap ฯ€ {s , a} {t , b}

     l (refl (s , a)) = refl (ฯ (X , s))

     e : is-equiv (canonical-map ฮน ฯ s t โˆ˜ ap ฯ€ {s , a} {t , b})
     e = โˆ˜-is-equiv (ฮธ s t) k

     ฮณ : is-equiv (canonical-map ฮน' ฯ' (s , a) (t , b))
     ฮณ = equivs-closed-under-โˆผ e l

 characterization-of-๏ผ-with-axioms :

     is-univalent ๐“ค
   โ†’ {S : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ }
     (ฯƒ : SNS S ๐“ฃ)
     (axioms : (X : ๐“ค ฬ‡ ) โ†’ S X โ†’ ๐“ฆ ฬ‡ )
   โ†’ ((X : ๐“ค ฬ‡ ) (s : S X) โ†’ is-subsingleton (axioms X s))
   โ†’ (A B : ฮฃ X ๊ž‰ ๐“ค ฬ‡ , ฮฃ s ๊ž‰ S X , axioms X s)

   โ†’ (A ๏ผ B) โ‰ƒ ([ A ] โ‰ƒ[ ฯƒ ] [ B ])

 characterization-of-๏ผ-with-axioms ua ฯƒ axioms i =
   characterization-of-๏ผ ua (add-axioms axioms i ฯƒ)

module magma {๐“ค : Universe} where

 open sip-with-axioms

 Magma : ๐“ค โบ ฬ‡
 Magma = ฮฃ X ๊ž‰ ๐“ค ฬ‡ , (X โ†’ X โ†’ X) ร— is-set X

 _โ‰…_ : Magma โ†’ Magma โ†’ ๐“ค ฬ‡

 (X , _ยท_ , _) โ‰… (Y , _*_ , _) =

               ฮฃ f ๊ž‰ (X โ†’ Y), is-equiv f
                            ร— ((ฮป x x' โ†’ f (x ยท x')) ๏ผ (ฮป x x' โ†’ f x * f x'))

 characterization-of-Magma-๏ผ : is-univalent ๐“ค โ†’ (A B : Magma ) โ†’ (A ๏ผ B) โ‰ƒ (A โ‰… B)
 characterization-of-Magma-๏ผ ua =
   characterization-of-๏ผ-with-axioms ua
     โˆž-magma.sns-data
     (ฮป X s โ†’ is-set X)
     (ฮป X s โ†’ being-set-is-subsingleton (univalence-gives-dfunext ua))

module pointed-type {๐“ค : Universe} where

 open sip

 Pointed : ๐“ค ฬ‡ โ†’ ๐“ค ฬ‡
 Pointed X = X

 sns-data : SNS Pointed ๐“ค
 sns-data = (ฮน , ฯ , ฮธ)
  where
   ฮน : (A B : ฮฃ Pointed) โ†’ โŸจ A โŸฉ โ‰ƒ โŸจ B โŸฉ โ†’ ๐“ค ฬ‡
   ฮน (X , xโ‚€) (Y , yโ‚€) (f , _) = (f xโ‚€ ๏ผ yโ‚€)

   ฯ : (A : ฮฃ Pointed) โ†’ ฮน A A (id-โ‰ƒ โŸจ A โŸฉ)
   ฯ (X , xโ‚€) = refl xโ‚€

   ฮธ : {X : ๐“ค ฬ‡ } (xโ‚€ xโ‚ : Pointed X) โ†’ is-equiv (canonical-map ฮน ฯ xโ‚€ xโ‚)
   ฮธ xโ‚€ xโ‚ = equivs-closed-under-โˆผ (id-is-equiv (xโ‚€ ๏ผ xโ‚)) h
    where
     h : canonical-map ฮน ฯ xโ‚€ xโ‚ โˆผ ๐‘–๐‘‘ (xโ‚€ ๏ผ xโ‚)
     h (refl xโ‚€) = refl (refl xโ‚€)

 _โ‰…_ : ฮฃ Pointed โ†’ ฮฃ Pointed โ†’ ๐“ค ฬ‡
 (X , xโ‚€) โ‰… (Y , yโ‚€) = ฮฃ f ๊ž‰ (X โ†’ Y), is-equiv f ร— (f xโ‚€ ๏ผ yโ‚€)

 characterization-of-pointed-type-๏ผ : is-univalent ๐“ค
                                    โ†’ (A B : ฮฃ Pointed)

                                    โ†’ (A ๏ผ B) โ‰ƒ (A โ‰… B)

 characterization-of-pointed-type-๏ผ ua = characterization-of-๏ผ ua sns-data

module sip-join where

 technical-lemma :
     {X : ๐“ค ฬ‡ } {A : X โ†’ X โ†’ ๐“ฅ ฬ‡ }
     {Y : ๐“ฆ ฬ‡ } {B : Y โ†’ Y โ†’ ๐“ฃ ฬ‡ }
     (f : (xโ‚€ xโ‚ : X) โ†’ xโ‚€ ๏ผ xโ‚ โ†’ A xโ‚€ xโ‚)
     (g : (yโ‚€ yโ‚ : Y) โ†’ yโ‚€ ๏ผ yโ‚ โ†’ B yโ‚€ yโ‚)
   โ†’ ((xโ‚€ xโ‚ : X) โ†’ is-equiv (f xโ‚€ xโ‚))
   โ†’ ((yโ‚€ yโ‚ : Y) โ†’ is-equiv (g yโ‚€ yโ‚))

   โ†’ ((xโ‚€ , yโ‚€) (xโ‚ , yโ‚) : X ร— Y) โ†’ is-equiv (ฮป (p : (xโ‚€ , yโ‚€) ๏ผ (xโ‚ , yโ‚)) โ†’ f xโ‚€ xโ‚ (ap prโ‚ p) ,
                                                                               g yโ‚€ yโ‚ (ap prโ‚‚ p))
 technical-lemma {๐“ค} {๐“ฅ} {๐“ฆ} {๐“ฃ} {X} {A} {Y} {B} f g i j (xโ‚€ , yโ‚€) = ฮณ
  where
   u : โˆƒ! xโ‚ ๊ž‰ X , A xโ‚€ xโ‚
   u = fiberwise-equiv-universal (A xโ‚€) xโ‚€ (f xโ‚€) (i xโ‚€)

   v : โˆƒ! yโ‚ ๊ž‰ Y , B yโ‚€ yโ‚
   v = fiberwise-equiv-universal (B yโ‚€) yโ‚€ (g yโ‚€) (j yโ‚€)

   C : X ร— Y โ†’ ๐“ฅ โŠ” ๐“ฃ ฬ‡
   C (xโ‚ , yโ‚) = A xโ‚€ xโ‚ ร— B yโ‚€ yโ‚

   w : (โˆƒ! xโ‚ ๊ž‰ X , A xโ‚€ xโ‚)
     โ†’ (โˆƒ! yโ‚ ๊ž‰ Y , B yโ‚€ yโ‚)
     โ†’  โˆƒ! (xโ‚ , yโ‚) ๊ž‰ X ร— Y , C (xโ‚ , yโ‚)
   w ((xโ‚ , aโ‚) , ฯ†) ((yโ‚ , bโ‚) , ฯˆ) = ((xโ‚ , yโ‚) , (aโ‚ , bโ‚)) , ฮด
    where
     p : โˆ€ x y a b
       โ†’ (xโ‚ , aโ‚) ๏ผ (x , a)
       โ†’ (yโ‚ , bโ‚) ๏ผ (y , b)
       โ†’ (xโ‚ , yโ‚) , (aโ‚ , bโ‚) ๏ผ (x , y) , (a , b)
     p .xโ‚ .yโ‚ .aโ‚ .bโ‚ (refl .(xโ‚ , aโ‚)) (refl .(yโ‚ , bโ‚)) = refl ((xโ‚ , yโ‚) , (aโ‚ , bโ‚))

     ฮด : (((x , y) , (a , b)) : ฮฃ C) โ†’ (xโ‚ , yโ‚) , (aโ‚ , bโ‚) ๏ผ ((x , y) , (a , b))
     ฮด ((x , y) , (a , b)) = p x y a b (ฯ† (x , a)) (ฯˆ (y , b))

   ฯ„ : Nat (๐“จ (xโ‚€ , yโ‚€)) C
   ฯ„ (xโ‚ , yโ‚) p = f xโ‚€ xโ‚ (ap prโ‚ p) , g yโ‚€ yโ‚ (ap prโ‚‚ p)

   ฮณ : is-fiberwise-equiv ฯ„
   ฮณ = universal-fiberwise-equiv C (w u v) (xโ‚€ , yโ‚€) ฯ„


 open sip

 โŸช_โŸซ : {Sโ‚€ : ๐“ค ฬ‡ โ†’ ๐“ฅโ‚€ ฬ‡ } {Sโ‚ : ๐“ค ฬ‡ โ†’ ๐“ฅโ‚ ฬ‡ }
     โ†’ (ฮฃ X ๊ž‰ ๐“ค ฬ‡ , Sโ‚€ X ร— Sโ‚ X) โ†’ ๐“ค ฬ‡

 โŸช X , sโ‚€ , sโ‚ โŸซ = X

 [_]โ‚€ : {Sโ‚€ : ๐“ค ฬ‡ โ†’ ๐“ฅโ‚€ ฬ‡ } {Sโ‚ : ๐“ค ฬ‡ โ†’ ๐“ฅโ‚ ฬ‡ }
      โ†’ (ฮฃ X ๊ž‰ ๐“ค ฬ‡ , Sโ‚€ X ร— Sโ‚ X) โ†’ ฮฃ Sโ‚€

 [ X , sโ‚€ , sโ‚ ]โ‚€ = (X , sโ‚€)

 [_]โ‚ : {Sโ‚€ : ๐“ค ฬ‡ โ†’ ๐“ฅโ‚€ ฬ‡ } {Sโ‚ : ๐“ค ฬ‡ โ†’ ๐“ฅโ‚ ฬ‡ }
      โ†’ (ฮฃ X ๊ž‰ ๐“ค ฬ‡ , Sโ‚€ X ร— Sโ‚ X) โ†’ ฮฃ Sโ‚

 [ X , sโ‚€ , sโ‚ ]โ‚ = (X , sโ‚)

 join : {Sโ‚€ : ๐“ค ฬ‡ โ†’ ๐“ฅโ‚€ ฬ‡ } {Sโ‚ : ๐“ค ฬ‡ โ†’ ๐“ฅโ‚ ฬ‡ }
      โ†’ SNS Sโ‚€ ๐“ฆโ‚€
      โ†’ SNS Sโ‚ ๐“ฆโ‚
      โ†’ SNS (ฮป X โ†’ Sโ‚€ X ร— Sโ‚ X) (๐“ฆโ‚€ โŠ” ๐“ฆโ‚)

 join {๐“ค} {๐“ฅโ‚€} {๐“ฅโ‚} {๐“ฆโ‚€} {๐“ฆโ‚} {Sโ‚€} {Sโ‚} (ฮนโ‚€ , ฯโ‚€ , ฮธโ‚€) (ฮนโ‚ , ฯโ‚ , ฮธโ‚) = ฮน , ฯ , ฮธ
  where
   S : ๐“ค ฬ‡ โ†’ ๐“ฅโ‚€ โŠ” ๐“ฅโ‚ ฬ‡
   S X = Sโ‚€ X ร— Sโ‚ X

   ฮน : (A B : ฮฃ S) โ†’ โŸจ A โŸฉ โ‰ƒ โŸจ B โŸฉ โ†’ ๐“ฆโ‚€ โŠ” ๐“ฆโ‚ ฬ‡
   ฮน A B e = ฮนโ‚€ [ A ]โ‚€ [ B ]โ‚€ e  ร—  ฮนโ‚ [ A ]โ‚ [ B ]โ‚ e

   ฯ : (A : ฮฃ S) โ†’ ฮน A A (id-โ‰ƒ โŸจ A โŸฉ)
   ฯ A = (ฯโ‚€ [ A ]โ‚€ , ฯโ‚ [ A ]โ‚)

   ฮธ : {X : ๐“ค ฬ‡ } (s t : S X) โ†’ is-equiv (canonical-map ฮน ฯ s t)
   ฮธ {X} (sโ‚€ , sโ‚) (tโ‚€ , tโ‚) = ฮณ
    where
     c : (p : sโ‚€ , sโ‚ ๏ผ tโ‚€ , tโ‚) โ†’ ฮนโ‚€ (X , sโ‚€) (X , tโ‚€) (id-โ‰ƒ X)
                                 ร— ฮนโ‚ (X , sโ‚) (X , tโ‚) (id-โ‰ƒ X)

     c p = (canonical-map ฮนโ‚€ ฯโ‚€ sโ‚€ tโ‚€ (ap prโ‚ p) ,
            canonical-map ฮนโ‚ ฯโ‚ sโ‚ tโ‚ (ap prโ‚‚ p))

     i : is-equiv c
     i = technical-lemma
          (canonical-map ฮนโ‚€ ฯโ‚€)
          (canonical-map ฮนโ‚ ฯโ‚)
          ฮธโ‚€ ฮธโ‚ (sโ‚€ , sโ‚) (tโ‚€ , tโ‚)

     e : canonical-map ฮน ฯ (sโ‚€ , sโ‚) (tโ‚€ , tโ‚) โˆผ c
     e (refl (sโ‚€ , sโ‚)) = refl (ฯโ‚€ (X , sโ‚€) , ฯโ‚ (X , sโ‚))

     ฮณ : is-equiv (canonical-map ฮน ฯ (sโ‚€ , sโ‚) (tโ‚€ , tโ‚))
     ฮณ = equivs-closed-under-โˆผ i e

 _โ‰ƒโŸฆ_,_โŸง_ : {Sโ‚€ : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ } {Sโ‚ : ๐“ค ฬ‡ โ†’ ๐“ฅโ‚ ฬ‡ }

          โ†’ (ฮฃ X ๊ž‰ ๐“ค ฬ‡ , Sโ‚€ X ร— Sโ‚ X)
          โ†’ SNS Sโ‚€ ๐“ฆโ‚€
          โ†’ SNS Sโ‚ ๐“ฆโ‚
          โ†’ (ฮฃ X ๊ž‰ ๐“ค ฬ‡ , Sโ‚€ X ร— Sโ‚ X)

          โ†’ ๐“ค โŠ” ๐“ฆโ‚€ โŠ” ๐“ฆโ‚ ฬ‡

 A โ‰ƒโŸฆ ฯƒโ‚€ , ฯƒโ‚ โŸง B = ฮฃ f ๊ž‰ (โŸช A โŸซ โ†’ โŸช B โŸซ)
                  , ฮฃ i ๊ž‰ is-equiv f , homomorphic ฯƒโ‚€ [ A ]โ‚€ [ B ]โ‚€ (f , i)
                                     ร— homomorphic ฯƒโ‚ [ A ]โ‚ [ B ]โ‚ (f , i)

 characterization-of-join-๏ผ : is-univalent ๐“ค
                            โ†’ {Sโ‚€ : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ } {Sโ‚ : ๐“ค ฬ‡ โ†’ ๐“ฅโ‚ ฬ‡ }
                              (ฯƒโ‚€ : SNS Sโ‚€ ๐“ฆโ‚€)  (ฯƒโ‚ : SNS Sโ‚ ๐“ฆโ‚)
                              (A B : ฮฃ X ๊ž‰ ๐“ค ฬ‡ , Sโ‚€ X ร— Sโ‚ X)

                            โ†’ (A ๏ผ B) โ‰ƒ (A โ‰ƒโŸฆ ฯƒโ‚€ , ฯƒโ‚ โŸง B)

 characterization-of-join-๏ผ ua ฯƒโ‚€ ฯƒโ‚ = characterization-of-๏ผ ua (join ฯƒโ‚€ ฯƒโ‚)

module pointed-โˆž-magma {๐“ค : Universe} where

 open sip-join

 โˆž-Magmaยท : ๐“ค โบ ฬ‡
 โˆž-Magmaยท = ฮฃ X ๊ž‰ ๐“ค ฬ‡ , (X โ†’ X โ†’ X) ร— X

 _โ‰…_ : โˆž-Magmaยท โ†’ โˆž-Magmaยท โ†’ ๐“ค ฬ‡

 (X ,  _ยท_ , xโ‚€) โ‰… (Y ,  _*_ , yโ‚€) =

                 ฮฃ f ๊ž‰ (X โ†’ Y), is-equiv f
                              ร— ((ฮป x x' โ†’ f (x ยท x')) ๏ผ (ฮป x x' โ†’ f x * f x'))
                              ร— (f xโ‚€ ๏ผ yโ‚€)

 characterization-of-pointed-magma-๏ผ : is-univalent ๐“ค
                                     โ†’ (A B : โˆž-Magmaยท)

                                     โ†’ (A ๏ผ B) โ‰ƒ (A โ‰… B)

 characterization-of-pointed-magma-๏ผ ua = characterization-of-join-๏ผ ua
                                            โˆž-magma.sns-data
                                            pointed-type.sns-data

module monoid {๐“ค : Universe} (ua : is-univalent ๐“ค) where

 dfe : dfunext ๐“ค ๐“ค
 dfe = univalence-gives-dfunext ua

 open sip
 open sip-join
 open sip-with-axioms

 monoid-structure : ๐“ค ฬ‡ โ†’ ๐“ค ฬ‡
 monoid-structure X = (X โ†’ X โ†’ X) ร— X

 monoid-axioms : (X : ๐“ค ฬ‡ ) โ†’ monoid-structure X โ†’ ๐“ค ฬ‡
 monoid-axioms X (_ยท_ , e) = is-set X
                           ร— monoids.left-neutral  e _ยท_
                           ร— monoids.right-neutral e _ยท_
                           ร— monoids.associative     _ยท_

 Monoid : ๐“ค โบ ฬ‡
 Monoid = ฮฃ X ๊ž‰ ๐“ค ฬ‡ , ฮฃ s ๊ž‰ monoid-structure X , monoid-axioms X s

 monoid-axioms-subsingleton : (X : ๐“ค ฬ‡ ) (s : monoid-structure X)
                            โ†’ is-subsingleton (monoid-axioms X s)

 monoid-axioms-subsingleton X (_ยท_ , e) s = ฮณ s
  where
   i : is-set X
   i = prโ‚ s

   ฮณ : is-subsingleton (monoid-axioms X (_ยท_ , e))
   ฮณ = ร—-is-subsingleton
         (being-set-is-subsingleton dfe)
      (ร—-is-subsingleton
         (ฮ -is-subsingleton dfe
           (ฮป x โ†’ i (e ยท x) x))
      (ร—-is-subsingleton
         (ฮ -is-subsingleton dfe
           (ฮป x โ†’ i (x ยท e) x))
         (ฮ -is-subsingleton dfe
           (ฮป x โ†’ ฮ -is-subsingleton dfe
           (ฮป y โ†’ ฮ -is-subsingleton dfe
           (ฮป z โ†’ i ((x ยท y) ยท z) (x ยท (y ยท z))))))))

 sns-data : SNS (ฮป X โ†’ ฮฃ s ๊ž‰ monoid-structure X , monoid-axioms X s) ๐“ค
 sns-data = add-axioms
              monoid-axioms monoid-axioms-subsingleton
              (join
                 โˆž-magma.sns-data
                 pointed-type.sns-data)

 _โ‰…_ : Monoid โ†’ Monoid โ†’ ๐“ค ฬ‡

 (X , (_ยท_ , d) , _) โ‰… (Y , (_*_ , e) , _) =

                     ฮฃ f ๊ž‰ (X โ†’ Y), is-equiv f
                                  ร— ((ฮป x x' โ†’ f (x ยท x')) ๏ผ (ฮป x x' โ†’ f x * f x'))
                                  ร— (f d ๏ผ e)

 characterization-of-monoid-๏ผ : is-univalent ๐“ค
                              โ†’ (A B : Monoid)

                              โ†’ (A ๏ผ B) โ‰ƒ (A โ‰… B)

 characterization-of-monoid-๏ผ ua = characterization-of-๏ผ ua sns-data

module associative-โˆž-magma
        {๐“ค : Universe}
        (ua : is-univalent ๐“ค)
       where

 fe : dfunext ๐“ค ๐“ค
 fe = univalence-gives-dfunext ua

 associative : {X : ๐“ค ฬ‡ } โ†’ (X โ†’ X โ†’ X) โ†’ ๐“ค ฬ‡
 associative _ยท_ = โˆ€ x y z โ†’ (x ยท y) ยท z ๏ผ x ยท (y ยท z)

 โˆž-amagma-structure : ๐“ค ฬ‡ โ†’ ๐“ค ฬ‡
 โˆž-amagma-structure X = ฮฃ _ยท_ ๊ž‰ (X โ†’ X โ†’ X), (associative _ยท_)

 โˆž-aMagma : ๐“ค โบ ฬ‡
 โˆž-aMagma = ฮฃ X ๊ž‰ ๐“ค ฬ‡ , โˆž-amagma-structure X

 homomorphic : {X Y : ๐“ค ฬ‡ } โ†’ (X โ†’ X โ†’ X) โ†’ (Y โ†’ Y โ†’ Y) โ†’ (X โ†’ Y) โ†’ ๐“ค ฬ‡
 homomorphic _ยท_ _*_ f = (ฮป x y โ†’ f (x ยท y)) ๏ผ (ฮป x y โ†’ f x * f y)

 respect-assoc : {X A : ๐“ค ฬ‡ } (_ยท_ : X โ†’ X โ†’ X) (_*_ : A โ†’ A โ†’ A)
               โ†’ associative _ยท_ โ†’ associative _*_
               โ†’ (f : X โ†’ A) โ†’ homomorphic _ยท_ _*_ f โ†’ ๐“ค ฬ‡

 respect-assoc _ยท_ _*_ ฮฑ ฮฒ f h  =  fฮฑ ๏ผ ฮฒf
  where
   l = ฮป x y z โ†’ f ((x ยท y) ยท z)   ๏ผโŸจ ap (ฮป - โ†’ - (x ยท y) z) h โŸฉ
                 f (x ยท y) * f z   ๏ผโŸจ ap (ฮป - โ†’ - x y * f z) h โŸฉ
                 (f x * f y) * f z โˆŽ

   r = ฮป x y z โ†’ f (x ยท (y ยท z))   ๏ผโŸจ ap (ฮป - โ†’ - x (y ยท z)) h โŸฉ
                 f x * f (y ยท z)   ๏ผโŸจ ap (ฮป - โ†’ f x * - y z) h โŸฉ
                 f x * (f y * f z) โˆŽ

   fฮฑ ฮฒf : โˆ€ x y z โ†’ (f x * f y) * f z ๏ผ f x * (f y * f z)
   fฮฑ x y z = (l x y z)โปยน โˆ™ ap f (ฮฑ x y z) โˆ™ r x y z
   ฮฒf x y z = ฮฒ (f x) (f y) (f z)

 remark : {X : ๐“ค ฬ‡ } (_ยท_ : X โ†’ X โ†’ X) (ฮฑ ฮฒ : associative _ยท_ )
        โ†’ respect-assoc _ยท_ _ยท_ ฮฑ ฮฒ id (refl _ยท_)
        ๏ผ ((ฮป x y z โ†’ refl ((x ยท y) ยท z) โˆ™ ap id (ฮฑ x y z)) ๏ผ ฮฒ)

 remark _ยท_ ฮฑ ฮฒ = refl _

 open sip hiding (homomorphic)

 sns-data : SNS โˆž-amagma-structure ๐“ค
 sns-data = (ฮน , ฯ , ฮธ)
  where
   ฮน : (๐“ง ๐“ : โˆž-aMagma) โ†’ โŸจ ๐“ง โŸฉ โ‰ƒ โŸจ ๐“ โŸฉ โ†’ ๐“ค ฬ‡
   ฮน (X , _ยท_ , ฮฑ) (A , _*_ , ฮฒ) (f , i) = ฮฃ h ๊ž‰ homomorphic _ยท_ _*_ f
                                               , respect-assoc _ยท_ _*_ ฮฑ ฮฒ f h

   ฯ : (๐“ง : โˆž-aMagma) โ†’ ฮน ๐“ง ๐“ง (id-โ‰ƒ โŸจ ๐“ง โŸฉ)
   ฯ (X , _ยท_ , ฮฑ) = h , p
    where
     h : homomorphic _ยท_ _ยท_ id
     h = refl _ยท_

     p : (ฮป x y z โ†’ refl ((x ยท y) ยท z) โˆ™ ap id (ฮฑ x y z)) ๏ผ ฮฑ
     p = fe (ฮป x โ†’ fe (ฮป y โ†’ fe (ฮป z โ†’ refl-left โˆ™ ap-id (ฮฑ x y z))))

   u : (X : ๐“ค ฬ‡ ) โ†’ โˆ€ s โ†’ โˆƒ! t ๊ž‰ โˆž-amagma-structure X , ฮน (X , s) (X , t) (id-โ‰ƒ X)
   u X (_ยท_ , ฮฑ) = c , ฯ†
    where
     c : ฮฃ t ๊ž‰ โˆž-amagma-structure X , ฮน (X , _ยท_ , ฮฑ) (X , t) (id-โ‰ƒ X)
     c = (_ยท_ , ฮฑ) , ฯ (X , _ยท_ , ฮฑ)

     ฯ† : (ฯƒ : ฮฃ t ๊ž‰ โˆž-amagma-structure X , ฮน (X , _ยท_ , ฮฑ) (X , t) (id-โ‰ƒ X)) โ†’ c ๏ผ ฯƒ
     ฯ† ((_ยท_ , ฮฒ) , refl _ยท_ , k) = ฮณ
      where
       a : associative _ยท_
       a x y z = refl ((x ยท y) ยท z) โˆ™ ap id (ฮฑ x y z)

       g : singleton-type' a โ†’ ฮฃ t ๊ž‰ โˆž-amagma-structure X , ฮน (X , _ยท_ , ฮฑ) (X , t) (id-โ‰ƒ X)
       g (ฮฒ , k) = (_ยท_ , ฮฒ) , refl _ยท_ , k

       i : is-subsingleton (singleton-type' a)
       i = singletons-are-subsingletons _ (singleton-types'-are-singletons _ a)

       q : ฮฑ , prโ‚‚ (ฯ (X , _ยท_ , ฮฑ)) ๏ผ ฮฒ , k
       q = i _ _

       ฮณ : c ๏ผ (_ยท_ , ฮฒ) , refl _ยท_ , k
       ฮณ = ap g q

   ฮธ : {X : ๐“ค ฬ‡ } (s t : โˆž-amagma-structure X) โ†’ is-equiv (canonical-map ฮน ฯ s t)
   ฮธ {X} s = universal-fiberwise-equiv (ฮป t โ†’ ฮน (X , s) (X , t) (id-โ‰ƒ X))
              (u X s) s (canonical-map ฮน ฯ s)

 _โ‰…_ : โˆž-aMagma โ†’ โˆž-aMagma โ†’ ๐“ค ฬ‡
 (X , _ยท_ , ฮฑ) โ‰… (Y , _*_ , ฮฒ) = ฮฃ f ๊ž‰ (X โ†’ Y)
                                     , is-equiv f
                                     ร— (ฮฃ h ๊ž‰ homomorphic _ยท_ _*_ f
                                            , respect-assoc _ยท_ _*_ ฮฑ ฮฒ f h)

 characterization-of-โˆž-aMagma-๏ผ : (A B : โˆž-aMagma) โ†’ (A ๏ผ B) โ‰ƒ (A โ‰… B)
 characterization-of-โˆž-aMagma-๏ผ = characterization-of-๏ผ ua sns-data

module group {๐“ค : Universe} (ua : is-univalent ๐“ค) where

 hfe : hfunext ๐“ค ๐“ค
 hfe = univalence-gives-hfunext ua

 open sip
 open sip-with-axioms
 open monoid {๐“ค} ua hiding (sns-data ; _โ‰…_)

 group-structure : ๐“ค ฬ‡ โ†’ ๐“ค ฬ‡
 group-structure X = ฮฃ s ๊ž‰ monoid-structure X , monoid-axioms X s

 group-axiom : (X : ๐“ค ฬ‡ ) โ†’ monoid-structure X โ†’ ๐“ค ฬ‡
 group-axiom X (_ยท_ , e) = (x : X) โ†’ ฮฃ x' ๊ž‰ X , (x ยท x' ๏ผ e) ร— (x' ยท x ๏ผ e)

 Group : ๐“ค โบ ฬ‡
 Group = ฮฃ X ๊ž‰ ๐“ค ฬ‡ , ฮฃ ((_ยท_ , e) , a) ๊ž‰ group-structure X , group-axiom X (_ยท_ , e)

 inv-lemma : (X : ๐“ค ฬ‡ ) (_ยท_ : X โ†’ X โ†’ X) (e : X)
           โ†’ monoid-axioms X (_ยท_ , e)
           โ†’ (x y z : X)
           โ†’ (y ยท x) ๏ผ e
           โ†’ (x ยท z) ๏ผ e
           โ†’ y ๏ผ z

 inv-lemma X _ยท_  e (s , l , r , a) x y z q p =

    y             ๏ผโŸจ (r y)โปยน โŸฉ
    (y ยท e)       ๏ผโŸจ ap (y ยท_) (p โปยน) โŸฉ
    (y ยท (x ยท z)) ๏ผโŸจ (a y x z)โปยน โŸฉ
    ((y ยท x) ยท z) ๏ผโŸจ ap (_ยท z) q โŸฉ
    (e ยท z)       ๏ผโŸจ l z โŸฉ
    z             โˆŽ

 group-axiom-is-subsingleton : (X : ๐“ค ฬ‡ )
                             โ†’ (s : group-structure X)
                             โ†’ is-subsingleton (group-axiom X (prโ‚ s))

 group-axiom-is-subsingleton X ((_ยท_ , e) , (s , l , r , a)) = ฮณ
  where
   i : (x : X) โ†’ is-subsingleton (ฮฃ x' ๊ž‰ X , (x ยท x' ๏ผ e) ร— (x' ยท x ๏ผ e))
   i x (y , _ , q) (z , p , _) = u
    where
     t : y ๏ผ z
     t = inv-lemma X _ยท_ e (s , l , r , a) x y z q p

     u : (y , _ , q) ๏ผ (z , p , _)
     u = to-subtype-๏ผ (ฮป x' โ†’ ร—-is-subsingleton (s (x ยท x') e) (s (x' ยท x) e)) t

   ฮณ : is-subsingleton (group-axiom X (_ยท_ , e))
   ฮณ = ฮ -is-subsingleton dfe i

 sns-data : SNS (ฮป X โ†’ ฮฃ s ๊ž‰ group-structure X , group-axiom X (prโ‚ s)) ๐“ค
 sns-data = add-axioms
             (ฮป X s โ†’ group-axiom X (prโ‚ s)) group-axiom-is-subsingleton
             (monoid.sns-data ua)

 _โ‰…_ : Group โ†’ Group โ†’ ๐“ค ฬ‡

 (X , ((_ยท_ , d) , _) , _) โ‰… (Y , ((_*_ , e) , _) , _) =

            ฮฃ f ๊ž‰ (X โ†’ Y), is-equiv f
                         ร— ((ฮป x x' โ†’ f (x ยท x')) ๏ผ (ฮป x x' โ†’ f x * f x'))
                         ร— (f d ๏ผ e)

 characterization-of-group-๏ผ : (A B : Group) โ†’ (A ๏ผ B) โ‰ƒ (A โ‰… B)
 characterization-of-group-๏ผ = characterization-of-๏ผ ua sns-data

 _โ‰…'_ : Group โ†’ Group โ†’ ๐“ค ฬ‡

 (X , ((_ยท_ , d) , _) , _) โ‰…' (Y , ((_*_ , e) , _) , _) =

            ฮฃ f ๊ž‰ (X โ†’ Y), is-equiv f
                         ร— ((ฮป x x' โ†’ f (x ยท x')) ๏ผ (ฮป x x' โ†’ f x * f x'))

 group-structure-of : (G : Group) โ†’ group-structure โŸจ G โŸฉ
 group-structure-of (X , ((_ยท_ , e) , i , l , r , a) , ฮณ) = (_ยท_ , e) , i , l , r , a

 monoid-structure-of : (G : Group) โ†’ monoid-structure โŸจ G โŸฉ
 monoid-structure-of (X , ((_ยท_ , e) , i , l , r , a) , ฮณ) = (_ยท_ , e)

 monoid-axioms-of : (G : Group) โ†’ monoid-axioms โŸจ G โŸฉ (monoid-structure-of G)
 monoid-axioms-of (X , ((_ยท_ , e) , i , l , r , a) , ฮณ) = i , l , r , a

 multiplication : (G : Group) โ†’ โŸจ G โŸฉ โ†’ โŸจ G โŸฉ โ†’ โŸจ G โŸฉ
 multiplication (X , ((_ยท_ , e) , i , l , r , a) , ฮณ) = _ยท_

 syntax multiplication G x y = x ยทโŸจ G โŸฉ y

 unit : (G : Group) โ†’ โŸจ G โŸฉ
 unit (X , ((_ยท_ , e) , i , l , r , a) , ฮณ) = e

 group-is-set : (G : Group)
              โ†’ is-set โŸจ G โŸฉ

 group-is-set (X , ((_ยท_ , e) , i , l , r , a) , ฮณ) = i

 unit-left : (G : Group) (x : โŸจ G โŸฉ)
           โ†’ unit G ยทโŸจ G โŸฉ x ๏ผ x

 unit-left (X , ((_ยท_ , e) , i , l , r , a) , ฮณ) x = l x

 unit-right : (G : Group) (x : โŸจ G โŸฉ)
            โ†’ x ยทโŸจ G โŸฉ unit G ๏ผ x

 unit-right (X , ((_ยท_ , e) , i , l , r , a) , ฮณ) x = r x

 assoc : (G : Group) (x y z : โŸจ G โŸฉ)
       โ†’ (x ยทโŸจ G โŸฉ y) ยทโŸจ G โŸฉ z ๏ผ x ยทโŸจ G โŸฉ (y ยทโŸจ G โŸฉ z)

 assoc (X , ((_ยท_ , e) , i , l , r , a) , ฮณ) = a

 inv : (G : Group) โ†’ โŸจ G โŸฉ โ†’ โŸจ G โŸฉ
 inv (X , ((_ยท_ , e) , i , l , r , a) , ฮณ) x = prโ‚ (ฮณ x)

 inv-left : (G : Group) (x : โŸจ G โŸฉ)
          โ†’ inv G x ยทโŸจ G โŸฉ x ๏ผ unit G

 inv-left (X , ((_ยท_ , e) , i , l , r , a) , ฮณ) x = prโ‚‚ (prโ‚‚ (ฮณ x))

 inv-right : (G : Group) (x : โŸจ G โŸฉ)
           โ†’ x ยทโŸจ G โŸฉ inv G x ๏ผ unit G

 inv-right (X , ((_ยท_ , e) , i , l , r , a) , ฮณ) x = prโ‚ (prโ‚‚ (ฮณ x))

 preserves-multiplication : (G H : Group) โ†’ (โŸจ G โŸฉ โ†’ โŸจ H โŸฉ) โ†’ ๐“ค ฬ‡
 preserves-multiplication G H f = (ฮป (x y : โŸจ G โŸฉ) โ†’ f (x ยทโŸจ G โŸฉ y))
                                ๏ผ (ฮป (x y : โŸจ G โŸฉ) โ†’ f x ยทโŸจ H โŸฉ f y)

 preserves-unit : (G H : Group) โ†’ (โŸจ G โŸฉ โ†’ โŸจ H โŸฉ) โ†’ ๐“ค ฬ‡
 preserves-unit G H f = f (unit G) ๏ผ unit H

 idempotent-is-unit : (G : Group) (x : โŸจ G โŸฉ)
                    โ†’ x ยทโŸจ G โŸฉ x ๏ผ x
                    โ†’ x ๏ผ unit G

 idempotent-is-unit G x p = ฮณ
  where
   x' = inv G x
   ฮณ = x                        ๏ผโŸจ (unit-left G x)โปยน โŸฉ
       unit G ยทโŸจ G โŸฉ x          ๏ผโŸจ (ap (ฮป - โ†’ - ยทโŸจ G โŸฉ x) (inv-left G x))โปยน โŸฉ
       (x' ยทโŸจ G โŸฉ x) ยทโŸจ G โŸฉ x   ๏ผโŸจ assoc G x' x x โŸฉ
       x' ยทโŸจ G โŸฉ (x ยทโŸจ G โŸฉ x)   ๏ผโŸจ ap (ฮป - โ†’ x' ยทโŸจ G โŸฉ -) p โŸฉ
       x' ยทโŸจ G โŸฉ x              ๏ผโŸจ inv-left G x โŸฉ
       unit G                   โˆŽ

 unit-preservation-lemma : (G H : Group) (f : โŸจ G โŸฉ โ†’ โŸจ H โŸฉ)
                         โ†’ preserves-multiplication G H f
                         โ†’ preserves-unit G H f

 unit-preservation-lemma G H f m = idempotent-is-unit H e p
  where
   e  = f (unit G)

   p = e ยทโŸจ H โŸฉ e               ๏ผโŸจ ap (ฮป - โ†’ - (unit G) (unit G)) (m โปยน) โŸฉ
       f (unit G ยทโŸจ G โŸฉ unit G) ๏ผโŸจ ap f (unit-left G (unit G)) โŸฉ
       e                        โˆŽ

 inv-Lemma : (G : Group) (x y z : โŸจ G โŸฉ)
           โ†’ (y ยทโŸจ G โŸฉ x) ๏ผ unit G
           โ†’ (x ยทโŸจ G โŸฉ z) ๏ผ unit G
           โ†’ y ๏ผ z

 inv-Lemma G = inv-lemma โŸจ G โŸฉ (multiplication G) (unit G) (monoid-axioms-of G)

 one-left-inv : (G : Group) (x x' : โŸจ G โŸฉ)
              โ†’ (x' ยทโŸจ G โŸฉ x) ๏ผ unit G
              โ†’ x' ๏ผ inv G x

 one-left-inv G x x' p = inv-Lemma G x x' (inv G x) p (inv-right G x)

 one-right-inv : (G : Group) (x x' : โŸจ G โŸฉ)
               โ†’ (x ยทโŸจ G โŸฉ x') ๏ผ unit G
               โ†’ x' ๏ผ inv G x

 one-right-inv G x x' p = (inv-Lemma G x (inv G x) x' (inv-left G x) p)โปยน

 preserves-inv : (G H : Group) โ†’ (โŸจ G โŸฉ โ†’ โŸจ H โŸฉ) โ†’ ๐“ค ฬ‡
 preserves-inv G H f = (x : โŸจ G โŸฉ) โ†’ f (inv G x) ๏ผ inv H (f x)

 inv-preservation-lemma : (G H : Group) (f : โŸจ G โŸฉ โ†’ โŸจ H โŸฉ)
                        โ†’ preserves-multiplication G H f
                        โ†’ preserves-inv G H f

 inv-preservation-lemma G H f m x = ฮณ
  where
   p = f (inv G x) ยทโŸจ H โŸฉ f x ๏ผโŸจ (ap (ฮป - โ†’ - (inv G x) x) m)โปยน โŸฉ
       f (inv G x ยทโŸจ G โŸฉ x)   ๏ผโŸจ ap f (inv-left G x) โŸฉ
       f (unit G)             ๏ผโŸจ unit-preservation-lemma G H f m โŸฉ
       unit H                 โˆŽ

   ฮณ : f (inv G x) ๏ผ inv H (f x)
   ฮณ = one-left-inv H (f x) (f (inv G x)) p

 is-homomorphism : (G H : Group) โ†’ (โŸจ G โŸฉ โ†’ โŸจ H โŸฉ) โ†’ ๐“ค ฬ‡
 is-homomorphism G H f = preserves-multiplication G H f
                       ร— preserves-unit G H f

 preservation-of-mult-is-subsingleton : (G H : Group) (f : โŸจ G โŸฉ โ†’ โŸจ H โŸฉ)
                                      โ†’ is-subsingleton (preserves-multiplication G H f)
 preservation-of-mult-is-subsingleton G H f = j
  where
   j : is-subsingleton (preserves-multiplication G H f)
   j = ฮ -is-set hfe
        (ฮป _ โ†’ ฮ -is-set hfe
        (ฮป _ โ†’ group-is-set H))
        (ฮป (x y : โŸจ G โŸฉ) โ†’ f (x ยทโŸจ G โŸฉ y))
        (ฮป (x y : โŸจ G โŸฉ) โ†’ f x ยทโŸจ H โŸฉ f y)

 being-homomorphism-is-subsingleton : (G H : Group) (f : โŸจ G โŸฉ โ†’ โŸจ H โŸฉ)
                                    โ†’ is-subsingleton (is-homomorphism G H f)
 being-homomorphism-is-subsingleton G H f = i
  where

   i : is-subsingleton (is-homomorphism G H f)
   i = ร—-is-subsingleton
        (preservation-of-mult-is-subsingleton G H f)
        (group-is-set H (f (unit G)) (unit H))

 notions-of-homomorphism-agree : (G H : Group) (f : โŸจ G โŸฉ โ†’ โŸจ H โŸฉ)
                               โ†’ is-homomorphism G H f
                               โ‰ƒ preserves-multiplication G H f

 notions-of-homomorphism-agree G H f = ฮณ
  where
   ฮฑ : is-homomorphism G H f โ†’ preserves-multiplication G H f
   ฮฑ = prโ‚

   ฮฒ : preserves-multiplication G H f โ†’ is-homomorphism G H f
   ฮฒ m = m , unit-preservation-lemma G H f m

   ฮณ : is-homomorphism G H f โ‰ƒ preserves-multiplication G H f
   ฮณ = logically-equivalent-subsingletons-are-equivalent _ _
        (being-homomorphism-is-subsingleton G H f)
        (preservation-of-mult-is-subsingleton G H f)
        (ฮฑ , ฮฒ)

 โ‰…-agreement : (G H : Group) โ†’ (G โ‰… H) โ‰ƒ (G โ‰…' H)
 โ‰…-agreement G H = ฮฃ-cong (ฮป f โ†’ ฮฃ-cong (ฮป _ โ†’ notions-of-homomorphism-agree G H f))

 forget-unit-preservation : (G H : Group) โ†’ (G โ‰… H) โ†’ (G โ‰…' H)
 forget-unit-preservation G H (f , e , m , _) = f , e , m

 NB : (G H : Group) โ†’ โŒœ โ‰…-agreement G H โŒ ๏ผ forget-unit-preservation G H
 NB G H = refl _

 forget-unit-preservation-is-equiv : (G H : Group)
                                   โ†’ is-equiv (forget-unit-preservation G H)

 forget-unit-preservation-is-equiv G H = โŒœโŒ-is-equiv (โ‰…-agreement G H)

module subgroup
        (๐“ค  : Universe)
        (ua : Univalence)
       where

 gfe : global-dfunext
 gfe = univalence-gives-global-dfunext ua

 open sip
 open monoid {๐“ค} (ua ๐“ค) hiding (sns-data ; _โ‰…_)
 open group {๐“ค} (ua ๐“ค)

 module ambient (G : Group) where

  _ยท_ : โŸจ G โŸฉ โ†’ โŸจ G โŸฉ โ†’ โŸจ G โŸฉ
  x ยท y = x ยทโŸจ G โŸฉ y

  infixl 42 _ยท_

  group-closed : (โŸจ G โŸฉ โ†’ ๐“ฅ ฬ‡ ) โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡
  group-closed ๐“ = ๐“ (unit G)
                 ร— ((x y : โŸจ G โŸฉ) โ†’ ๐“ x โ†’ ๐“ y โ†’ ๐“ (x ยท y))
                 ร— ((x : โŸจ G โŸฉ) โ†’ ๐“ x โ†’ ๐“ (inv G x))

  Subgroups : ๐“ค โบ ฬ‡
  Subgroups = ฮฃ A ๊ž‰ ๐“Ÿ โŸจ G โŸฉ , group-closed (_โˆˆ A)

  โŸช_โŸซ : Subgroups โ†’ ๐“Ÿ โŸจ G โŸฉ
  โŸช A , u , c , ฮน โŸซ = A

  being-group-closed-subset-is-subsingleton : (A : ๐“Ÿ โŸจ G โŸฉ) โ†’ is-subsingleton (group-closed (_โˆˆ A))
  being-group-closed-subset-is-subsingleton A = ร—-is-subsingleton
                                                  (โˆˆ-is-subsingleton A (unit G))
                                               (ร—-is-subsingleton
                                                  (ฮ -is-subsingleton dfe
                                                     (ฮป x โ†’ ฮ -is-subsingleton dfe
                                                     (ฮป y โ†’ ฮ -is-subsingleton dfe
                                                     (ฮป _ โ†’ ฮ -is-subsingleton dfe
                                                     (ฮป _ โ†’ โˆˆ-is-subsingleton A (x ยท y))))))
                                                  (ฮ -is-subsingleton dfe
                                                     (ฮป x โ†’ ฮ -is-subsingleton dfe
                                                     (ฮป _ โ†’ โˆˆ-is-subsingleton A (inv G x)))))

  โŸชโŸซ-is-embedding : is-embedding โŸช_โŸซ
  โŸชโŸซ-is-embedding = prโ‚-embedding being-group-closed-subset-is-subsingleton

  ap-โŸชโŸซ : (S T : Subgroups) โ†’ S ๏ผ T โ†’ โŸช S โŸซ ๏ผ โŸช T โŸซ
  ap-โŸชโŸซ S T = ap โŸช_โŸซ

  ap-โŸชโŸซ-is-equiv : (S T : Subgroups) โ†’ is-equiv (ap-โŸชโŸซ S T)
  ap-โŸชโŸซ-is-equiv = embedding-gives-ap-is-equiv โŸช_โŸซ โŸชโŸซ-is-embedding

  subgroups-form-a-set : is-set Subgroups
  subgroups-form-a-set S T = equiv-to-subsingleton
                              (ap-โŸชโŸซ S T , ap-โŸชโŸซ-is-equiv S T)
                              (powersets-are-sets' ua โŸช S โŸซ โŸช T โŸซ)

  subgroup-equality : (S T : Subgroups)
                    โ†’ (S ๏ผ T)
                    โ‰ƒ ((x : โŸจ G โŸฉ) โ†’ (x โˆˆ โŸช S โŸซ) โ†” (x โˆˆ โŸช T โŸซ))

  subgroup-equality S T = ฮณ
   where
    f : S ๏ผ T โ†’ (x : โŸจ G โŸฉ) โ†’ x โˆˆ โŸช S โŸซ โ†” x โˆˆ โŸช T โŸซ
    f p x = transport (ฮป - โ†’ x โˆˆ โŸช - โŸซ) p , transport (ฮป - โ†’ x โˆˆ โŸช - โŸซ) (p โปยน)

    h : ((x : โŸจ G โŸฉ) โ†’ x โˆˆ โŸช S โŸซ โ†” x โˆˆ โŸช T โŸซ) โ†’ โŸช S โŸซ ๏ผ โŸช T โŸซ
    h ฯ† = subset-extensionality' ua ฮฑ ฮฒ
     where
      ฮฑ : โŸช S โŸซ โІ โŸช T โŸซ
      ฮฑ x = lr-implication (ฯ† x)

      ฮฒ : โŸช T โŸซ โІ โŸช S โŸซ
      ฮฒ x = rl-implication (ฯ† x)

    g : ((x : โŸจ G โŸฉ) โ†’ x โˆˆ โŸช S โŸซ โ†” x โˆˆ โŸช T โŸซ) โ†’ S ๏ผ T
    g = inverse (ap-โŸชโŸซ S T) (ap-โŸชโŸซ-is-equiv S T) โˆ˜ h

    ฮณ : (S ๏ผ T) โ‰ƒ ((x : โŸจ G โŸฉ) โ†’ x โˆˆ โŸช S โŸซ โ†” x โˆˆ โŸช T โŸซ)
    ฮณ = logically-equivalent-subsingletons-are-equivalent _ _
          (subgroups-form-a-set S T)
          (ฮ -is-subsingleton dfe
             (ฮป x โ†’ ร—-is-subsingleton
                      (ฮ -is-subsingleton dfe (ฮป _ โ†’ โˆˆ-is-subsingleton โŸช T โŸซ x))
                      (ฮ -is-subsingleton dfe (ฮป _ โ†’ โˆˆ-is-subsingleton โŸช S โŸซ x))))
          (f , g)

  T : ๐“ค ฬ‡ โ†’ ๐“ค ฬ‡
  T X = ฮฃ ((_ยท_ , e) , a) ๊ž‰ group-structure X , group-axiom X (_ยท_ , e)

  module _ {X : ๐“ค ฬ‡ } (h : X โ†’ โŸจ G โŸฉ) (e : is-embedding h) where

   private
    h-lc : left-cancellable h
    h-lc = embeddings-are-lc h e

   having-group-closed-fiber-is-subsingleton : is-subsingleton (group-closed (fiber h))
   having-group-closed-fiber-is-subsingleton = being-group-closed-subset-is-subsingleton
                                                (ฮป x โ†’ (fiber h x , e x))

   at-most-one-homomorphic-structure : is-subsingleton (ฮฃ ฯ„ ๊ž‰ T X , is-homomorphism (X , ฯ„) G h)
   at-most-one-homomorphic-structure
      ((((_*_ ,  unitH) ,  maxioms) ,  gaxiom) ,  (pmult ,  punit))
      ((((_*'_ , unitH') , maxioms') , gaxiom') , (pmult' , punit'))
    = ฮณ
    where
     ฯ„ ฯ„' : T X
     ฯ„  = ((_*_ ,  unitH) ,  maxioms) ,  gaxiom
     ฯ„' = ((_*'_ , unitH') , maxioms') , gaxiom'

     i :  is-homomorphism (X , ฯ„)  G h
     i  = (pmult ,  punit)

     i' : is-homomorphism (X , ฯ„') G h
     i' = (pmult' , punit')

     p : _*_ ๏ผ _*'_
     p = gfe (ฮป x โ†’ gfe (ฮป y โ†’ h-lc (h (x * y)  ๏ผโŸจ  ap (ฮป - โ†’ - x y) pmult โŸฉ
                                     h x ยท h y  ๏ผโŸจ (ap (ฮป - โ†’ - x y) pmult')โปยน โŸฉ
                                     h (x *' y) โˆŽ)))
     q : unitH ๏ผ unitH'
     q = h-lc (h unitH  ๏ผโŸจ  punit โŸฉ
               unit G   ๏ผโŸจ  punit' โปยน โŸฉ
               h unitH' โˆŽ)

     r : (_*_ , unitH) ๏ผ (_*'_ , unitH')
     r = to-ร—-๏ผ (p , q)

     ฮด : ฯ„ ๏ผ ฯ„'
     ฮด = to-subtype-๏ผ
           (group-axiom-is-subsingleton X)
           (to-subtype-๏ผ
              (monoid-axioms-subsingleton X)
              r)

     ฮณ : (ฯ„  , i) ๏ผ (ฯ„' , i')
     ฮณ = to-subtype-๏ผ (ฮป ฯ„ โ†’ being-homomorphism-is-subsingleton (X , ฯ„) G h) ฮด

   group-closed-fiber-gives-homomorphic-structure : group-closed (fiber h)
                                                  โ†’ (ฮฃ ฯ„ ๊ž‰ T X , is-homomorphism (X , ฯ„) G h)

   group-closed-fiber-gives-homomorphic-structure (unitc , mulc , invc) = ฯ„ , i
    where
     ฯ† : (x : X) โ†’ fiber h (h x)
     ฯ† x = (x , refl (h x))

     unitH : X
     unitH = fiber-point unitc

     _*_ : X โ†’ X โ†’ X
     x * y = fiber-point (mulc (h x) (h y) (ฯ† x) (ฯ† y))

     invH : X โ†’ X
     invH x = fiber-point (invc (h x) (ฯ† x))

     pmul : (x y : X) โ†’ h (x * y) ๏ผ h x ยท h y
     pmul x y = fiber-identification (mulc (h x) (h y) (ฯ† x) (ฯ† y))

     punit : h unitH ๏ผ unit G
     punit = fiber-identification unitc

     pinv : (x : X) โ†’ h (invH x) ๏ผ inv G (h x)
     pinv x = fiber-identification (invc (h x) (ฯ† x))

     unitH-left : (x : X) โ†’ unitH * x ๏ผ x
     unitH-left x = h-lc (h (unitH * x) ๏ผโŸจ pmul unitH x โŸฉ
                          h unitH ยท h x ๏ผโŸจ ap (_ยท h x) punit โŸฉ
                          unit G ยท h x  ๏ผโŸจ unit-left G (h x) โŸฉ
                          h x           โˆŽ)

     unitH-right : (x : X) โ†’ x * unitH ๏ผ x
     unitH-right x = h-lc (h (x * unitH) ๏ผโŸจ pmul x unitH โŸฉ
                           h x ยท h unitH ๏ผโŸจ ap (h x ยท_) punit โŸฉ
                           h x ยท unit G  ๏ผโŸจ unit-right G (h x) โŸฉ
                           h x           โˆŽ)

     assocH : (x y z : X) โ†’ ((x * y) * z) ๏ผ (x * (y * z))
     assocH x y z = h-lc (h ((x * y) * z)   ๏ผโŸจ pmul (x * y) z โŸฉ
                          h (x * y) ยท h z   ๏ผโŸจ ap (_ยท h z) (pmul x y) โŸฉ
                          (h x ยท h y) ยท h z ๏ผโŸจ assoc G (h x) (h y) (h z) โŸฉ
                          h x ยท (h y ยท h z) ๏ผโŸจ (ap (h x ยท_) (pmul y z))โปยน โŸฉ
                          h x ยท h (y * z)   ๏ผโŸจ (pmul x (y * z))โปยน โŸฉ
                          h (x * (y * z))   โˆŽ)

     group-axiomH : (x : X) โ†’ ฮฃ x' ๊ž‰ X , (x * x' ๏ผ unitH) ร— (x' * x ๏ผ unitH)
     group-axiomH x = invH x ,

                      h-lc (h (x * invH x)     ๏ผโŸจ pmul x (invH x) โŸฉ
                            h x ยท h (invH x)   ๏ผโŸจ ap (h x ยท_) (pinv x) โŸฉ
                            h x ยท inv G (h x)  ๏ผโŸจ inv-right G (h x) โŸฉ
                            unit G             ๏ผโŸจ punit โปยน โŸฉ
                            h unitH            โˆŽ),

                      h-lc ((h (invH x * x)    ๏ผโŸจ pmul (invH x) x โŸฉ
                             h (invH x) ยท h x  ๏ผโŸจ ap (_ยท h x) (pinv x) โŸฉ
                             inv G (h x) ยท h x ๏ผโŸจ inv-left G (h x) โŸฉ
                             unit G            ๏ผโŸจ punit โปยน โŸฉ
                             h unitH           โˆŽ))

     j : is-set X
     j = subtypes-of-sets-are-sets' h h-lc (group-is-set G)

     ฯ„ : T X
     ฯ„ = ((_*_ , unitH) , (j , unitH-left , unitH-right , assocH)) , group-axiomH

     i : is-homomorphism (X , ฯ„) G h
     i = gfe (ฮป x โ†’ gfe (pmul x)) , punit

   homomorphic-structure-gives-group-closed-fiber : (ฮฃ ฯ„ ๊ž‰ T X , is-homomorphism (X , ฯ„) G h)
                                                  โ†’ group-closed (fiber h)

   homomorphic-structure-gives-group-closed-fiber
       ((((_*_ , unitH) , maxioms) , gaxiom) , (pmult , punit))
     = (unitc , mulc , invc)
    where
     H : Group
     H = X , ((_*_ , unitH) , maxioms) , gaxiom

     unitc : fiber h (unit G)
     unitc = unitH , punit

     mulc : ((x y : โŸจ G โŸฉ) โ†’ fiber h x โ†’ fiber h y โ†’ fiber h (x ยท y))
     mulc x y (a , p) (b , q) = (a * b) ,
                                (h (a * b) ๏ผโŸจ ap (ฮป - โ†’ - a b) pmult โŸฉ
                                 h a ยท h b ๏ผโŸจ apโ‚‚ (ฮป - -' โ†’ - ยท -') p q โŸฉ
                                 x ยท y     โˆŽ)

     invc : ((x : โŸจ G โŸฉ) โ†’ fiber h x โ†’ fiber h (inv G x))
     invc x (a , p) = inv H a ,
                      (h (inv H a) ๏ผโŸจ inv-preservation-lemma H G h pmult a โŸฉ
                       inv G (h a) ๏ผโŸจ ap (inv G) p โŸฉ
                       inv G x     โˆŽ)

   fiber-structure-lemma : group-closed (fiber h)
                         โ‰ƒ (ฮฃ ฯ„ ๊ž‰ T X , is-homomorphism (X , ฯ„) G h)

   fiber-structure-lemma = logically-equivalent-subsingletons-are-equivalent _ _
                             having-group-closed-fiber-is-subsingleton
                             at-most-one-homomorphic-structure
                             (group-closed-fiber-gives-homomorphic-structure ,
                              homomorphic-structure-gives-group-closed-fiber)

  characterization-of-the-type-of-subgroups :  Subgroups โ‰ƒ  (ฮฃ H ๊ž‰ Group
                                                           , ฮฃ h ๊ž‰ (โŸจ H โŸฉ โ†’ โŸจ G โŸฉ)
                                                           , is-embedding h
                                                           ร— is-homomorphism H G h)
  characterization-of-the-type-of-subgroups =

   Subgroups                                                                                       โ‰ƒโŸจ i โŸฉ
   (ฮฃ A ๊ž‰ ๐“Ÿ โŸจ G โŸฉ , group-closed (_โˆˆ A))                                                           โ‰ƒโŸจ ii โŸฉ
   (ฮฃ (X , h , e) ๊ž‰ Subtypes โŸจ G โŸฉ , group-closed (fiber h))                                       โ‰ƒโŸจ iii โŸฉ
   (ฮฃ X ๊ž‰ ๐“ค ฬ‡ , ฮฃ (h , e) ๊ž‰ X โ†ช โŸจ G โŸฉ , group-closed (fiber h))                                     โ‰ƒโŸจ iv โŸฉ
   (ฮฃ X ๊ž‰ ๐“ค ฬ‡ , ฮฃ (h , e) ๊ž‰ X โ†ช โŸจ G โŸฉ , ฮฃ ฯ„ ๊ž‰ T X , is-homomorphism (X , ฯ„) G h)                    โ‰ƒโŸจ v โŸฉ
   (ฮฃ X ๊ž‰ ๐“ค ฬ‡ , ฮฃ h ๊ž‰ (X โ†’ โŸจ G โŸฉ) , ฮฃ e ๊ž‰ is-embedding h , ฮฃ ฯ„ ๊ž‰ T X , is-homomorphism (X , ฯ„) G h) โ‰ƒโŸจ vi โŸฉ
   (ฮฃ X ๊ž‰ ๐“ค ฬ‡ , ฮฃ h ๊ž‰ (X โ†’ โŸจ G โŸฉ) , ฮฃ ฯ„ ๊ž‰ T X , ฮฃ e ๊ž‰ is-embedding h , is-homomorphism (X , ฯ„) G h) โ‰ƒโŸจ vii โŸฉ
   (ฮฃ X ๊ž‰ ๐“ค ฬ‡ , ฮฃ ฯ„ ๊ž‰ T X , ฮฃ h ๊ž‰ (X โ†’ โŸจ G โŸฉ) , is-embedding h ร— is-homomorphism (X , ฯ„) G h)       โ‰ƒโŸจ viii โŸฉ
   (ฮฃ H ๊ž‰ Group , ฮฃ h ๊ž‰ (โŸจ H โŸฉ โ†’ โŸจ G โŸฉ) , is-embedding h ร— is-homomorphism H G h)                  โ– 

      where
       ฯ† : Subtypes โŸจ G โŸฉ โ†’ ๐“Ÿ โŸจ G โŸฉ
       ฯ† = ฯ‡-special is-subsingleton โŸจ G โŸฉ

       j : is-equiv ฯ†
       j = ฯ‡-special-is-equiv (ua ๐“ค) gfe is-subsingleton โŸจ G โŸฉ

       i    = id-โ‰ƒ Subgroups
       ii   = ฮฃ-change-of-variable (ฮป (A : ๐“Ÿ โŸจ G โŸฉ) โ†’ group-closed (_โˆˆ A)) ฯ† j
       iii  = ฮฃ-assoc
       iv   = ฮฃ-cong (ฮป X โ†’ ฮฃ-cong (ฮป (h , e) โ†’ fiber-structure-lemma h e))
       v    = ฮฃ-cong (ฮป X โ†’ ฮฃ-assoc)
       vi   = ฮฃ-cong (ฮป X โ†’ ฮฃ-cong (ฮป h โ†’ ฮฃ-flip))
       vii  = ฮฃ-cong (ฮป X โ†’ ฮฃ-flip)
       viii = โ‰ƒ-sym ฮฃ-assoc

  induced-group : Subgroups โ†’ Group
  induced-group S = prโ‚ (โŒœ characterization-of-the-type-of-subgroups โŒ S)

module slice
        {๐“ค ๐“ฅ : Universe}
        (R : ๐“ฅ ฬ‡ )
       where

 open sip

 S : ๐“ค ฬ‡ โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡
 S X = X โ†’ R

 sns-data : SNS S (๐“ค โŠ” ๐“ฅ)
 sns-data = (ฮน , ฯ , ฮธ)
  where
   ฮน : (A B : ฮฃ S) โ†’ โŸจ A โŸฉ โ‰ƒ โŸจ B โŸฉ โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡
   ฮน (X , g) (Y , h) (f , _) = (g ๏ผ h โˆ˜ f)

   ฯ : (A : ฮฃ S) โ†’ ฮน A A (id-โ‰ƒ โŸจ A โŸฉ)
   ฯ (X , g) = refl g

   k : {X : ๐“ค ฬ‡ } {g h : S X} โ†’ canonical-map ฮน ฯ g h โˆผ ๐‘–๐‘‘ (g ๏ผ h)
   k (refl g) = refl (refl g)

   ฮธ : {X : ๐“ค ฬ‡ } (g h : S X) โ†’ is-equiv (canonical-map ฮน ฯ g h)
   ฮธ g h = equivs-closed-under-โˆผ (id-is-equiv (g ๏ผ h)) k

 _โ‰…_  : ๐“ค / R โ†’ ๐“ค / R โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡
 (X , g) โ‰… (Y , h) = ฮฃ f ๊ž‰ (X โ†’ Y), is-equiv f ร— (g ๏ผ h โˆ˜ f )

 characterization-of-/-๏ผ : is-univalent ๐“ค โ†’ (A B : ๐“ค / R) โ†’ (A ๏ผ B) โ‰ƒ (A โ‰… B)
 characterization-of-/-๏ผ ua = characterization-of-๏ผ ua sns-data

module generalized-metric-space
        {๐“ค ๐“ฅ : Universe}
        (R : ๐“ฅ ฬ‡ )
        (axioms  : (X : ๐“ค ฬ‡ ) โ†’ (X โ†’ X โ†’ R) โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡ )
        (axiomss : (X : ๐“ค ฬ‡ ) (d : X โ†’ X โ†’ R) โ†’ is-subsingleton (axioms X d))
       where

 open sip
 open sip-with-axioms

 S : ๐“ค ฬ‡ โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡
 S X = X โ†’ X โ†’ R

 sns-data : SNS S (๐“ค โŠ” ๐“ฅ)
 sns-data = (ฮน , ฯ , ฮธ)
  where
   ฮน : (A B : ฮฃ S) โ†’ โŸจ A โŸฉ โ‰ƒ โŸจ B โŸฉ โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡
   ฮน (X , d) (Y , e) (f , _) = (d ๏ผ ฮป x x' โ†’ e (f x) (f x'))

   ฯ : (A : ฮฃ S) โ†’ ฮน A A (id-โ‰ƒ โŸจ A โŸฉ)
   ฯ (X , d) = refl d

   h : {X : ๐“ค ฬ‡ } {d e : S X} โ†’ canonical-map ฮน ฯ d e โˆผ ๐‘–๐‘‘ (d ๏ผ e)
   h (refl d) = refl (refl d)

   ฮธ : {X : ๐“ค ฬ‡ } (d e : S X) โ†’ is-equiv (canonical-map ฮน ฯ d e)
   ฮธ d e = equivs-closed-under-โˆผ (id-is-equiv (d ๏ผ e)) h

 M : ๐“ค โบ โŠ” ๐“ฅ ฬ‡
 M = ฮฃ X ๊ž‰ ๐“ค ฬ‡ , ฮฃ d ๊ž‰ (X โ†’ X โ†’ R) , axioms X d

 _โ‰…_  : M โ†’ M โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡
 (X , d , _) โ‰… (Y , e , _) = ฮฃ f ๊ž‰ (X โ†’ Y), is-equiv f
                                          ร— (d ๏ผ ฮป x x' โ†’ e (f x) (f x'))

 characterization-of-M-๏ผ : is-univalent ๐“ค
                         โ†’ (A B : M)

                         โ†’ (A ๏ผ B) โ‰ƒ (A โ‰… B)

 characterization-of-M-๏ผ ua = characterization-of-๏ผ-with-axioms ua
                                sns-data
                                axioms axiomss

module generalized-topological-space
        (๐“ค ๐“ฅ : Universe)
        (R : ๐“ฅ ฬ‡ )
        (axioms  : (X : ๐“ค ฬ‡ ) โ†’ ((X โ†’ R) โ†’ R) โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡ )
        (axiomss : (X : ๐“ค ฬ‡ ) (๐“ž : (X โ†’ R) โ†’ R) โ†’ is-subsingleton (axioms X ๐“ž))
       where

 open sip
 open sip-with-axioms

 โ„™ : ๐“ฆ ฬ‡ โ†’ ๐“ฅ โŠ” ๐“ฆ ฬ‡
 โ„™ X = X โ†’ R

 _โˆŠ_ : {X : ๐“ฆ ฬ‡ } โ†’ X โ†’ โ„™ X โ†’ R
 x โˆŠ A = A x

 inverse-image : {X Y : ๐“ค ฬ‡ } โ†’ (X โ†’ Y) โ†’ โ„™ Y โ†’ โ„™ X
 inverse-image f B = ฮป x โ†’ f x โˆŠ B

 โ„™โ„™ : ๐“ค ฬ‡ โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡
 โ„™โ„™ X = โ„™ (โ„™ X)

 Space : ๐“ค โบ โŠ” ๐“ฅ ฬ‡
 Space = ฮฃ X ๊ž‰ ๐“ค ฬ‡ , ฮฃ ๐“ž ๊ž‰ โ„™โ„™ X , axioms X ๐“ž

 sns-data : SNS โ„™โ„™ (๐“ค โŠ” ๐“ฅ)
 sns-data = (ฮน , ฯ , ฮธ)
  where
   ฮน : (A B : ฮฃ โ„™โ„™) โ†’ โŸจ A โŸฉ โ‰ƒ โŸจ B โŸฉ โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡
   ฮน (X , ๐“žX) (Y , ๐“žY) (f , _) = (ฮป (V : โ„™ Y) โ†’ inverse-image f V โˆŠ ๐“žX) ๏ผ ๐“žY

   ฯ : (A : ฮฃ โ„™โ„™) โ†’ ฮน A A (id-โ‰ƒ โŸจ A โŸฉ)
   ฯ (X , ๐“ž) = refl ๐“ž

   h : {X : ๐“ค ฬ‡ } {๐“ž ๐“ž' : โ„™โ„™ X} โ†’ canonical-map ฮน ฯ ๐“ž ๐“ž' โˆผ ๐‘–๐‘‘ (๐“ž ๏ผ ๐“ž')
   h (refl ๐“ž) = refl (refl ๐“ž)

   ฮธ : {X : ๐“ค ฬ‡ } (๐“ž ๐“ž' : โ„™โ„™ X) โ†’ is-equiv (canonical-map ฮน ฯ ๐“ž ๐“ž')
   ฮธ {X} ๐“ž ๐“ž' = equivs-closed-under-โˆผ (id-is-equiv (๐“ž ๏ผ ๐“ž')) h

 _โ‰…_  : Space โ†’ Space โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡

 (X , ๐“žX , _) โ‰… (Y , ๐“žY , _) =

              ฮฃ f ๊ž‰ (X โ†’ Y), is-equiv f
                           ร— ((ฮป V โ†’ inverse-image f V โˆŠ ๐“žX) ๏ผ ๐“žY)

 characterization-of-Space-๏ผ : is-univalent ๐“ค
                             โ†’ (A B : Space)

                             โ†’ (A ๏ผ B) โ‰ƒ (A โ‰… B)

 characterization-of-Space-๏ผ ua = characterization-of-๏ผ-with-axioms ua
                                   sns-data axioms axiomss

 _โ‰…'_  : Space โ†’ Space โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡

 (X , F , _) โ‰…' (Y , G , _) =

             ฮฃ f ๊ž‰ (X โ†’ Y), is-equiv f
                          ร— ((ฮป (v : Y โ†’ R) โ†’ F (v โˆ˜ f)) ๏ผ G)

 characterization-of-Space-๏ผ' : is-univalent ๐“ค
                              โ†’ (A B : Space)

                              โ†’ (A ๏ผ B) โ‰ƒ (A โ‰…' B)

 characterization-of-Space-๏ผ' = characterization-of-Space-๏ผ

module selection-space
        (๐“ค ๐“ฅ : Universe)
        (R : ๐“ฅ ฬ‡ )
        (axioms  : (X : ๐“ค ฬ‡ ) โ†’ ((X โ†’ R) โ†’ X) โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡ )
        (axiomss : (X : ๐“ค ฬ‡ ) (ฮต : (X โ†’ R) โ†’ X) โ†’ is-subsingleton (axioms X ฮต))
       where

 open sip
 open sip-with-axioms

 S : ๐“ค ฬ‡ โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡
 S X = (X โ†’ R) โ†’ X

 SelectionSpace : ๐“ค โบ โŠ” ๐“ฅ ฬ‡
 SelectionSpace = ฮฃ X ๊ž‰ ๐“ค ฬ‡ , ฮฃ ฮต ๊ž‰ S X , axioms X ฮต

 sns-data : SNS S (๐“ค โŠ” ๐“ฅ)
 sns-data = (ฮน , ฯ , ฮธ)
  where
   ฮน : (A B : ฮฃ S) โ†’ โŸจ A โŸฉ โ‰ƒ โŸจ B โŸฉ โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡
   ฮน (X , ฮต) (Y , ฮด) (f , _) = (ฮป (q : Y โ†’ R) โ†’ f (ฮต (q โˆ˜ f))) ๏ผ ฮด

   ฯ : (A : ฮฃ S) โ†’ ฮน A A (id-โ‰ƒ โŸจ A โŸฉ)
   ฯ (X , ฮต) = refl ฮต

   ฮธ : {X : ๐“ค ฬ‡ } (ฮต ฮด : S X) โ†’ is-equiv (canonical-map ฮน ฯ ฮต ฮด)
   ฮธ {X} ฮต ฮด = ฮณ
    where
     h : canonical-map ฮน ฯ ฮต ฮด โˆผ ๐‘–๐‘‘ (ฮต ๏ผ ฮด)
     h (refl ฮต) = refl (refl ฮต)

     ฮณ : is-equiv (canonical-map ฮน ฯ ฮต ฮด)
     ฮณ = equivs-closed-under-โˆผ (id-is-equiv (ฮต ๏ผ ฮด)) h

 _โ‰…_  :  SelectionSpace โ†’ SelectionSpace โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡

 (X , ฮต , _) โ‰… (Y , ฮด , _) =

             ฮฃ f ๊ž‰ (X โ†’ Y), is-equiv f
                          ร— ((ฮป (q : Y โ†’ R) โ†’ f (ฮต (q โˆ˜ f))) ๏ผ ฮด)

 characterization-of-selection-space-๏ผ : is-univalent ๐“ค
                                       โ†’ (A B : SelectionSpace)

                                       โ†’ (A ๏ผ B) โ‰ƒ (A โ‰… B)

 characterization-of-selection-space-๏ผ ua = characterization-of-๏ผ-with-axioms ua
                                             sns-data
                                             axioms axiomss

module contrived-example (๐“ค : Universe) where

 open sip

 contrived-๏ผ : is-univalent ๐“ค โ†’

    (X Y : ๐“ค ฬ‡ ) (ฯ† : (X โ†’ X) โ†’ X) (ฮณ : (Y โ†’ Y) โ†’ Y)
  โ†’
    ((X , ฯ†) ๏ผ (Y , ฮณ)) โ‰ƒ (ฮฃ f ๊ž‰ (X โ†’ Y)
                         , ฮฃ i ๊ž‰ is-equiv f
                         , (ฮป (g : Y โ†’ Y) โ†’ f (ฯ† (inverse f i โˆ˜ g โˆ˜ f))) ๏ผ ฮณ)

 contrived-๏ผ ua X Y ฯ† ฮณ =
   characterization-of-๏ผ ua
    ((ฮป (X , ฯ†) (Y , ฮณ) (f , i) โ†’ (ฮป (g : Y โ†’ Y) โ†’ f (ฯ† (inverse f i โˆ˜ g โˆ˜ f))) ๏ผ ฮณ) ,
     (ฮป (X , ฯ†) โ†’ refl ฯ†) ,
     (ฮป ฯ† ฮณ โ†’ equivs-closed-under-โˆผ (id-is-equiv (ฯ† ๏ผ ฮณ)) (ฮป {(refl ฯ†) โ†’ refl (refl ฯ†)})))
    (X , ฯ†) (Y , ฮณ)

module generalized-functor-algebra
         {๐“ค ๐“ฅ : Universe}
         (F : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ )
         (๐“• : {X Y : ๐“ค ฬ‡ } โ†’ (X โ†’ Y) โ†’ F X โ†’ F Y)
         (๐“•-id : {X : ๐“ค ฬ‡ } โ†’ ๐“• (๐‘–๐‘‘ X) ๏ผ ๐‘–๐‘‘ (F X))
       where

 open sip

 S : ๐“ค ฬ‡ โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡
 S X = F X โ†’ X

 sns-data : SNS S (๐“ค โŠ” ๐“ฅ)
 sns-data = (ฮน , ฯ , ฮธ)
  where
   ฮน : (A B : ฮฃ S) โ†’ โŸจ A โŸฉ โ‰ƒ โŸจ B โŸฉ โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡
   ฮน (X , ฮฑ) (Y , ฮฒ) (f , _) = f โˆ˜ ฮฑ ๏ผ ฮฒ โˆ˜ ๐“• f

   ฯ : (A : ฮฃ S) โ†’ ฮน A A (id-โ‰ƒ โŸจ A โŸฉ)
   ฯ (X , ฮฑ) = ฮฑ        ๏ผโŸจ ap (ฮฑ โˆ˜_) (๐“•-id โปยน) โŸฉ
               ฮฑ โˆ˜ ๐“• id โˆŽ

   ฮธ : {X : ๐“ค ฬ‡ } (ฮฑ ฮฒ : S X) โ†’ is-equiv (canonical-map ฮน ฯ ฮฑ ฮฒ)
   ฮธ {X} ฮฑ ฮฒ = ฮณ
    where
     c : ฮฑ ๏ผ ฮฒ โ†’ ฮฑ ๏ผ ฮฒ โˆ˜ ๐“• id
     c = transport (ฮฑ ๏ผ_) (ฯ (X , ฮฒ))

     i : is-equiv c
     i = transport-is-equiv (ฮฑ ๏ผ_) (ฯ (X , ฮฒ))

     h : canonical-map ฮน ฯ ฮฑ ฮฒ โˆผ c
     h (refl _) = ฯ (X , ฮฑ)          ๏ผโŸจ refl-left โปยน โŸฉ
                  refl ฮฑ โˆ™ ฯ (X , ฮฑ) โˆŽ

     ฮณ : is-equiv (canonical-map ฮน ฯ ฮฑ ฮฒ)
     ฮณ = equivs-closed-under-โˆผ i h

 characterization-of-functor-algebra-๏ผ : is-univalent ๐“ค
   โ†’ (X Y : ๐“ค ฬ‡ ) (ฮฑ : F X โ†’ X) (ฮฒ : F Y โ†’ Y)

   โ†’ ((X , ฮฑ) ๏ผ (Y , ฮฒ))  โ‰ƒ  (ฮฃ f ๊ž‰ (X โ†’ Y), is-equiv f ร— (f โˆ˜ ฮฑ ๏ผ ฮฒ โˆ˜ ๐“• f))

 characterization-of-functor-algebra-๏ผ ua X Y ฮฑ ฮฒ =
   characterization-of-๏ผ ua sns-data (X , ฮฑ) (Y , ฮฒ)

type-valued-preorder-S : ๐“ค ฬ‡ โ†’ ๐“ค โŠ” (๐“ฅ โบ) ฬ‡
type-valued-preorder-S {๐“ค} {๐“ฅ} X = ฮฃ _โ‰ค_ ๊ž‰ (X โ†’ X โ†’ ๐“ฅ ฬ‡ )
                                         , ((x : X) โ†’ x โ‰ค x)
                                         ร— ((x y z : X) โ†’ x โ‰ค y โ†’ y โ‰ค z โ†’ x โ‰ค z)

module type-valued-preorder
        (๐“ค ๐“ฅ : Universe)
        (ua : Univalence)
       where

 open sip

 fe : global-dfunext
 fe = univalence-gives-global-dfunext ua

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

 S : ๐“ค ฬ‡ โ†’ ๐“ค โŠ” (๐“ฅ โบ) ฬ‡
 S = type-valued-preorder-S {๐“ค} {๐“ฅ}

 Type-valued-preorder : (๐“ค โŠ” ๐“ฅ) โบ ฬ‡
 Type-valued-preorder = ฮฃ S

 Ob : ฮฃ S โ†’ ๐“ค ฬ‡
 Ob (X , homX , idX , compX ) = X

 hom : (๐“ง : ฮฃ S) โ†’ Ob ๐“ง โ†’ Ob ๐“ง โ†’ ๐“ฅ ฬ‡
 hom (X , homX , idX , compX) = homX

 ๐’พ๐’น : (๐“ง : ฮฃ S) (x : Ob ๐“ง) โ†’ hom ๐“ง x x
 ๐’พ๐’น (X , homX , idX , compX) = idX

 comp : (๐“ง : ฮฃ S) (x y z : Ob ๐“ง) โ†’ hom ๐“ง x y โ†’ hom ๐“ง y z โ†’ hom ๐“ง x z
 comp (X , homX , idX , compX) = compX

 functorial : (๐“ง ๐“ : ฮฃ S)
            โ†’ (F : Ob ๐“ง โ†’ Ob ๐“)
            โ†’ ((x y : Ob ๐“ง) โ†’ hom ๐“ง x y โ†’ hom ๐“ (F x) (F y))
            โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡

 functorial ๐“ง ๐“ F ๐“•' = pidentity ร— pcomposition
  where

   _o_ : {x y z : Ob ๐“ง} โ†’ hom ๐“ง y z โ†’ hom ๐“ง x y โ†’ hom ๐“ง x z
   g o f = comp ๐“ง _ _ _ f g

   _โ–ก_ : {a b c : Ob ๐“} โ†’ hom ๐“ b c โ†’ hom ๐“ a b โ†’ hom ๐“ a c
   g โ–ก f = comp ๐“ _ _ _ f g

   ๐“• : {x y : Ob ๐“ง} โ†’ hom ๐“ง x y โ†’ hom ๐“ (F x) (F y)
   ๐“• f = ๐“•' _ _ f

   pidentity = (ฮป x โ†’ ๐“• (๐’พ๐’น ๐“ง x)) ๏ผ (ฮป x โ†’ ๐’พ๐’น ๐“ (F x))

   pcomposition = (ฮป x y z (f : hom ๐“ง x y) (g : hom ๐“ง y z) โ†’ ๐“• (g o f))
                ๏ผ (ฮป x y z (f : hom ๐“ง x y) (g : hom ๐“ง y z) โ†’ ๐“• g โ–ก ๐“• f)

 sns-data : SNS S (๐“ค โŠ” (๐“ฅ โบ))
 sns-data = (ฮน , ฯ , ฮธ)
  where
   ฮน : (๐“ง ๐“ : ฮฃ S) โ†’ โŸจ ๐“ง โŸฉ โ‰ƒ โŸจ ๐“ โŸฉ โ†’ ๐“ค โŠ” (๐“ฅ โบ) ฬ‡
   ฮน ๐“ง ๐“ (F , _) = ฮฃ p ๊ž‰ hom ๐“ง ๏ผ (ฮป x y โ†’ hom ๐“ (F x) (F y))
                       , functorial ๐“ง ๐“ F (ฮป x y โ†’ transport (ฮป - โ†’ - x y) p)

   ฯ : (๐“ง : ฮฃ S) โ†’ ฮน ๐“ง ๐“ง (id-โ‰ƒ โŸจ ๐“ง โŸฉ)
   ฯ ๐“ง = refl (hom ๐“ง) , refl (๐’พ๐’น ๐“ง) , refl (comp ๐“ง)

   ฮธ : {X : ๐“ค ฬ‡ } (s t : S X) โ†’ is-equiv (canonical-map ฮน ฯ s t)
   ฮธ {X} (homX , idX , compX) (homA , idA , compA) = g
    where
     ฯ† = canonical-map ฮน ฯ (homX , idX , compX) (homA , idA , compA)

     ฮณ : codomain ฯ† โ†’ domain ฯ†
     ฮณ (refl _ , refl _ , refl _) = refl _

     ฮท : ฮณ โˆ˜ ฯ† โˆผ id
     ฮท (refl _) = refl _

     ฮต : ฯ† โˆ˜ ฮณ โˆผ id
     ฮต (refl _ , refl _ , refl _) = refl _

     g : is-equiv ฯ†
     g = invertibles-are-equivs ฯ† (ฮณ , ฮท , ฮต)

 lemma : (๐“ง ๐“ : ฮฃ S) (F : Ob ๐“ง โ†’ Ob ๐“)
       โ†’
         (ฮฃ p ๊ž‰ hom ๐“ง ๏ผ (ฮป x y โ†’ hom ๐“ (F x) (F y))
              , functorial ๐“ง ๐“ F (ฮป x y โ†’ transport (ฮป - โ†’ - x y) p))
       โ‰ƒ
         (ฮฃ ๐“• ๊ž‰ ((x y : Ob ๐“ง) โ†’ hom ๐“ง x y โ†’ hom ๐“ (F x) (F y))
              , (โˆ€ x y โ†’ is-equiv (๐“• x y))
              ร— functorial ๐“ง ๐“ F ๐“•)

 lemma ๐“ง ๐“ F = ฮณ
  where
   e = (hom ๐“ง ๏ผ ฮป x y โ†’ hom ๐“ (F x) (F y))                            โ‰ƒโŸจ i โŸฉ
       (โˆ€ x y โ†’ hom ๐“ง x y ๏ผ hom ๐“ (F x) (F y))                        โ‰ƒโŸจ ii โŸฉ
       (โˆ€ x y โ†’ hom ๐“ง x y โ‰ƒ hom ๐“ (F x) (F y))                        โ‰ƒโŸจ iii โŸฉ
       (โˆ€ x โ†’ ฮฃ ฯ† ๊ž‰ (โˆ€ y โ†’ hom ๐“ง x y โ†’ hom ๐“ (F x) (F y))
                  , โˆ€ y โ†’ is-equiv (ฯ† y))                             โ‰ƒโŸจ iv โŸฉ
       (ฮฃ ๐“• ๊ž‰ ((x y : Ob ๐“ง) โ†’ hom ๐“ง x y โ†’ hom ๐“ (F x) (F y))
            , (โˆ€ x y โ†’ is-equiv (๐“• x y)))                             โ– 
    where
     i   = hfunextโ‚‚-โ‰ƒ hfe hfe (hom ๐“ง )  ฮป x y โ†’ hom ๐“ (F x) (F y)
     ii  = ฮ -cong fe fe
            (ฮป x โ†’ ฮ -cong fe fe
            (ฮป y โ†’ univalence-โ‰ƒ (ua ๐“ฅ) (hom ๐“ง x y) (hom ๐“ (F x) (F y))))
     iii = ฮ -cong fe fe (ฮป y โ†’ ฮ ฮฃ-distr-โ‰ƒ)
     iv  = ฮ ฮฃ-distr-โ‰ƒ

   v : (p : hom ๐“ง ๏ผ ฮป x y โ†’ hom ๐“ (F x) (F y))
     โ†’ functorial ๐“ง ๐“ F (ฮป x y โ†’ transport (ฮป - โ†’ - x y) p)
     โ‰ƒ functorial ๐“ง ๐“ F (prโ‚ (โŒœ e โŒ p))

   v (refl _) = id-โ‰ƒ _

   ฮณ =

    (ฮฃ p ๊ž‰ hom ๐“ง ๏ผ (ฮป x y โ†’ hom ๐“ (F x) (F y))
         , functorial ๐“ง ๐“ F (ฮป x y โ†’ transport (ฮป - โ†’ - x y) p)) โ‰ƒโŸจ vi โŸฉ

    (ฮฃ p ๊ž‰ hom ๐“ง ๏ผ (ฮป x y โ†’ hom ๐“ (F x) (F y))
         , functorial ๐“ง ๐“ F (prโ‚ (โŒœ e โŒ p)))                     โ‰ƒโŸจ vii โŸฉ

    (ฮฃ ฯƒ ๊ž‰ (ฮฃ ๐“• ๊ž‰ ((x y : Ob ๐“ง) โ†’ hom ๐“ง x y โ†’ hom ๐“ (F x) (F y))
                , (โˆ€ x y โ†’ is-equiv (๐“• x y)))
         , functorial ๐“ง ๐“ F (prโ‚ ฯƒ))                             โ‰ƒโŸจ viii โŸฉ

    (ฮฃ ๐“• ๊ž‰ ((x y : Ob ๐“ง) โ†’ hom ๐“ง x y โ†’ hom ๐“ (F x) (F y))
                  , (โˆ€ x y โ†’ is-equiv (๐“• x y))
                  ร— functorial ๐“ง ๐“ F ๐“•)                          โ– 
    where
     vi   = ฮฃ-cong v
     vii  = โ‰ƒ-sym (ฮฃ-change-of-variable _ โŒœ e โŒ (โŒœโŒ-is-equiv e))
     viii = ฮฃ-assoc

 characterization-of-type-valued-preorder-๏ผ :

      (๐“ง ๐“ : ฮฃ S)
    โ†’
      (๐“ง ๏ผ ๐“)
    โ‰ƒ
      (ฮฃ F ๊ž‰ (Ob ๐“ง โ†’ Ob ๐“)
           , is-equiv F
           ร— (ฮฃ ๐“• ๊ž‰ ((x y : Ob ๐“ง) โ†’ hom ๐“ง x y โ†’ hom ๐“ (F x) (F y))
                  , (โˆ€ x y โ†’ is-equiv (๐“• x y))
                  ร— functorial ๐“ง ๐“ F ๐“•))

 characterization-of-type-valued-preorder-๏ผ ๐“ง ๐“ =

   (๐“ง ๏ผ ๐“)                                                              โ‰ƒโŸจ i โŸฉ
   (ฮฃ F ๊ž‰ (Ob ๐“ง โ†’ Ob ๐“)
        , is-equiv F
        ร— (ฮฃ p ๊ž‰ hom ๐“ง ๏ผ (ฮป x y โ†’ hom ๐“ (F x) (F y))
               , functorial ๐“ง ๐“ F (ฮป x y โ†’ transport (ฮป - โ†’ - x y) p))) โ‰ƒโŸจ ii โŸฉ
   (ฮฃ F ๊ž‰ (Ob ๐“ง โ†’ Ob ๐“)
     , is-equiv F
     ร— (ฮฃ ๐“• ๊ž‰ ((x y : Ob ๐“ง) โ†’ hom ๐“ง x y โ†’ hom ๐“ (F x) (F y))
            , (โˆ€ x y โ†’ is-equiv (๐“• x y))
            ร— functorial ๐“ง ๐“ F ๐“•))                                      โ– 

  where
   i  = characterization-of-๏ผ (ua ๐“ค) sns-data ๐“ง ๐“
   ii = ฮฃ-cong (ฮป F โ†’ ฮฃ-cong (ฮป _ โ†’ lemma ๐“ง ๐“ F))

module type-valued-preorder-with-axioms
        (๐“ค ๐“ฅ ๐“ฆ : Universe)
        (ua : Univalence)
        (axioms  : (X : ๐“ค ฬ‡ ) โ†’ type-valued-preorder-S {๐“ค} {๐“ฅ} X โ†’ ๐“ฆ ฬ‡ )
        (axiomss : (X : ๐“ค ฬ‡ ) (s : type-valued-preorder-S X) โ†’ is-subsingleton (axioms X s))
       where

 open sip
 open sip-with-axioms
 open type-valued-preorder ๐“ค ๐“ฅ ua

 S' : ๐“ค ฬ‡ โ†’ ๐“ค โŠ” (๐“ฅ โบ) โŠ” ๐“ฆ ฬ‡
 S' X = ฮฃ s ๊ž‰ S X , axioms X s

 sns-data' : SNS S' (๐“ค โŠ” (๐“ฅ โบ))
 sns-data' = add-axioms axioms axiomss sns-data

 characterization-of-type-valued-preorder-๏ผ-with-axioms :

      (๐“ง' ๐“' : ฮฃ S')
    โ†’
      (๐“ง' ๏ผ ๐“')
    โ‰ƒ
      (ฮฃ F ๊ž‰ (Ob [ ๐“ง' ] โ†’ Ob [ ๐“' ])
           , is-equiv F
           ร— (ฮฃ ๐“• ๊ž‰ ((x y : Ob [ ๐“ง' ]) โ†’ hom [ ๐“ง' ] x y โ†’ hom [ ๐“' ] (F x) (F y))
                    , (โˆ€ x y โ†’ is-equiv (๐“• x y))
                    ร— functorial [ ๐“ง' ] [ ๐“' ] F ๐“•))

 characterization-of-type-valued-preorder-๏ผ-with-axioms ๐“ง' ๐“' =

  (๐“ง' ๏ผ ๐“')                     โ‰ƒโŸจ i โŸฉ
  ([ ๐“ง' ] โ‰ƒ[ sns-data ] [ ๐“' ]) โ‰ƒโŸจ ii โŸฉ
  _                              โ– 

  where
   i  = characterization-of-๏ผ-with-axioms (ua ๐“ค) sns-data axioms axiomss ๐“ง' ๐“'
   ii = ฮฃ-cong (ฮป F โ†’ ฮฃ-cong (ฮป _ โ†’ lemma [ ๐“ง' ] [ ๐“' ] F))

module category
        (๐“ค ๐“ฅ : Universe)
        (ua : Univalence)
       where

 open type-valued-preorder-with-axioms ๐“ค ๐“ฅ (๐“ค โŠ” ๐“ฅ) ua

 fe : global-dfunext
 fe = univalence-gives-global-dfunext ua

 S : ๐“ค ฬ‡ โ†’ ๐“ค โŠ” (๐“ฅ โบ) ฬ‡
 S = type-valued-preorder-S {๐“ค} {๐“ฅ}

 category-axioms : (X : ๐“ค ฬ‡ ) โ†’ S X โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡
 category-axioms X (homX , idX , compX) = hom-sets ร— identityl ร— identityr ร— associativity
  where
   _o_ : {x y z : X} โ†’ homX y z โ†’ homX x y โ†’ homX x z
   g o f = compX _ _ _ f g

   hom-sets      = โˆ€ x y โ†’ is-set (homX x y)

   identityl     = โˆ€ x y (f : homX x y) โ†’ f o (idX x) ๏ผ f

   identityr     = โˆ€ x y (f : homX x y) โ†’ (idX y) o f ๏ผ f

   associativity = โˆ€ x y z t (f : homX x y) (g : homX y z) (h : homX z t)
                 โ†’ (h o g) o f ๏ผ h o (g o f)

 category-axioms-subsingleton : (X : ๐“ค ฬ‡ ) (s : S X) โ†’ is-subsingleton (category-axioms X s)
 category-axioms-subsingleton X (homX , idX , compX) ca = ฮณ ca
  where
   i : โˆ€ x y โ†’ is-set (homX x y)
   i = prโ‚ ca

   ฮณ : is-subsingleton (category-axioms X (homX , idX , compX))
   ฮณ = ร—-is-subsingleton ss (ร—-is-subsingleton ls (ร—-is-subsingleton rs as))
    where
     ss = ฮ -is-subsingleton fe
           (ฮป x โ†’ ฮ -is-subsingleton fe
           (ฮป y โ†’ being-set-is-subsingleton fe))

     ls = ฮ -is-subsingleton fe
           (ฮป x โ†’ ฮ -is-subsingleton fe
           (ฮป y โ†’ ฮ -is-subsingleton fe
           (ฮป f โ†’ i x y (compX x x y (idX x) f) f)))

     rs = ฮ -is-subsingleton fe
           (ฮป x โ†’ ฮ -is-subsingleton fe
           (ฮป y โ†’ ฮ -is-subsingleton fe
           (ฮป f โ†’ i x y (compX x y y f (idX y)) f)))

     as = ฮ -is-subsingleton fe
           (ฮป x โ†’ ฮ -is-subsingleton fe
           (ฮป y โ†’ ฮ -is-subsingleton fe
           (ฮป z โ†’ ฮ -is-subsingleton fe
           (ฮป t โ†’ ฮ -is-subsingleton fe
           (ฮป f โ†’ ฮ -is-subsingleton fe
           (ฮป g โ†’ ฮ -is-subsingleton fe
           (ฮป h โ†’ i x t (compX x y t f (compX y z t g h))
                        (compX x z t (compX x y z f g) h))))))))

 Cat : (๐“ค โŠ” ๐“ฅ)โบ ฬ‡
 Cat = ฮฃ X ๊ž‰ ๐“ค ฬ‡ , ฮฃ s ๊ž‰ S X , category-axioms X s

 Ob : Cat โ†’ ๐“ค ฬ‡
 Ob (X , (homX , idX , compX) , _) = X

 hom : (๐“ง : Cat) โ†’ Ob ๐“ง โ†’ Ob ๐“ง โ†’ ๐“ฅ ฬ‡
 hom (X , (homX , idX , compX) , _) = homX

 ๐’พ๐’น : (๐“ง : Cat) (x : Ob ๐“ง) โ†’ hom ๐“ง x x
 ๐’พ๐’น (X , (homX , idX , compX) , _) = idX

 comp : (๐“ง : Cat) (x y z : Ob ๐“ง) (f : hom ๐“ง x y) (g : hom ๐“ง y z) โ†’ hom ๐“ง x z
 comp (X , (homX , idX , compX) , _) = compX

 is-functorial : (๐“ง ๐“ : Cat)
               โ†’ (F : Ob ๐“ง โ†’ Ob ๐“)
               โ†’ ((x y : Ob ๐“ง) โ†’ hom ๐“ง x y โ†’ hom ๐“ (F x) (F y))
               โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡

 is-functorial ๐“ง ๐“ F ๐“•' = pidentity ร— pcomposition
  where
   _o_ : {x y z : Ob ๐“ง} โ†’ hom ๐“ง y z โ†’ hom ๐“ง x y โ†’ hom ๐“ง x z
   g o f = comp ๐“ง _ _ _ f g

   _โ–ก_ : {a b c : Ob ๐“} โ†’ hom ๐“ b c โ†’ hom ๐“ a b โ†’ hom ๐“ a c
   g โ–ก f = comp ๐“ _ _ _ f g

   ๐“• : {x y : Ob ๐“ง} โ†’ hom ๐“ง x y โ†’ hom ๐“ (F x) (F y)
   ๐“• f = ๐“•' _ _ f

   pidentity    = (ฮป x โ†’ ๐“• (๐’พ๐’น ๐“ง x)) ๏ผ (ฮป x โ†’ ๐’พ๐’น ๐“ (F x))

   pcomposition = (ฮป x y z (f : hom ๐“ง x y) (g : hom ๐“ง y z) โ†’ ๐“• (g o f))
                ๏ผ (ฮป x y z (f : hom ๐“ง x y) (g : hom ๐“ง y z) โ†’ ๐“• g โ–ก ๐“• f)

 _โ‹_ : Cat โ†’ Cat โ†’ ๐“ค โŠ” ๐“ฅ ฬ‡

 ๐“ง โ‹ ๐“ = ฮฃ F ๊ž‰ (Ob ๐“ง โ†’ Ob ๐“)
              , is-equiv F
              ร— (ฮฃ ๐“• ๊ž‰ ((x y : Ob ๐“ง) โ†’ hom ๐“ง x y โ†’ hom ๐“ (F x) (F y))
                     , (โˆ€ x y โ†’ is-equiv (๐“• x y))
                     ร— is-functorial ๐“ง ๐“ F ๐“•)

 Idโ†’EqCat : (๐“ง ๐“ : Cat) โ†’ ๐“ง ๏ผ ๐“ โ†’ ๐“ง โ‹ ๐“
 Idโ†’EqCat ๐“ง ๐“ง (refl ๐“ง) = ๐‘–๐‘‘ (Ob ๐“ง ) ,
                         id-is-equiv (Ob ๐“ง ) ,
                         (ฮป x y โ†’ ๐‘–๐‘‘ (hom ๐“ง x y)) ,
                         (ฮป x y โ†’ id-is-equiv (hom ๐“ง x y)) ,
                         refl (๐’พ๐’น ๐“ง) ,
                         refl (comp ๐“ง)

 characterization-of-category-๏ผ : (๐“ง ๐“ : Cat) โ†’ (๐“ง ๏ผ ๐“) โ‰ƒ (๐“ง โ‹ ๐“)
 characterization-of-category-๏ผ = characterization-of-type-valued-preorder-๏ผ-with-axioms
                                   category-axioms category-axioms-subsingleton

 Idโ†’EqCat-is-equiv : (๐“ง ๐“ : Cat) โ†’ is-equiv (Idโ†’EqCat ๐“ง ๐“)
 Idโ†’EqCat-is-equiv ๐“ง ๐“ = equivs-closed-under-โˆผ
                           (โŒœโŒ-is-equiv (characterization-of-category-๏ผ ๐“ง ๐“))
                           (ฮณ ๐“ง ๐“)
  where
   ฮณ : (๐“ง ๐“ : Cat) โ†’ Idโ†’EqCat ๐“ง ๐“ โˆผ โŒœ characterization-of-category-๏ผ ๐“ง ๐“ โŒ
   ฮณ ๐“ง ๐“ง (refl ๐“ง) = refl _

module ring {๐“ค : Universe} (ua : Univalence) where
 open sip hiding (โŸจ_โŸฉ)
 open sip-with-axioms
 open sip-join

 fe : global-dfunext
 fe = univalence-gives-global-dfunext ua

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

 rng-structure : ๐“ค ฬ‡ โ†’ ๐“ค ฬ‡
 rng-structure X = (X โ†’ X โ†’ X) ร— (X โ†’ X โ†’ X)

 rng-axioms : (R : ๐“ค ฬ‡ ) โ†’ rng-structure R โ†’ ๐“ค ฬ‡
 rng-axioms R (_+_ , _ยท_) = I ร— II ร— III ร— IV ร— V ร— VI ร— VII
  where
    I   = is-set R
    II  = (x y z : R) โ†’ (x + y) + z ๏ผ x + (y + z)
    III = (x y : R) โ†’ x + y ๏ผ y + x
    IV  = ฮฃ O ๊ž‰ R , ((x : R) โ†’ x + O ๏ผ x) ร— ((x : R) โ†’ ฮฃ x' ๊ž‰ R , x + x' ๏ผ O)
    V   = (x y z : R) โ†’ (x ยท y) ยท z ๏ผ x ยท (y ยท z)
    VI  = (x y z : R) โ†’ x ยท (y + z) ๏ผ (x ยท y) + (x ยท z)
    VII = (x y z : R) โ†’ (y + z) ยท x ๏ผ (y ยท x) + (z ยท x)

 Rng : ๐“ค โบ ฬ‡
 Rng = ฮฃ R ๊ž‰ ๐“ค ฬ‡ , ฮฃ s ๊ž‰ rng-structure R , rng-axioms R s

 rng-axioms-is-subsingleton : (R : ๐“ค ฬ‡ ) (s : rng-structure R)
                            โ†’ is-subsingleton (rng-axioms R s)

 rng-axioms-is-subsingleton R (_+_ , _ยท_) (i , ii , iii , iv-vii) = ฮด
  where
    A   = ฮป (O : R) โ†’ ((x : R) โ†’ x + O ๏ผ x)
                    ร— ((x : R) โ†’ ฮฃ x' ๊ž‰ R , x + x' ๏ผ O)

    IV  = ฮฃ A

    a : (O O' : R) โ†’ ((x : R) โ†’ x + O ๏ผ x) โ†’ ((x : R) โ†’ x + O' ๏ผ x) โ†’ O ๏ผ O'
    a O O' f f' = O       ๏ผโŸจ (f' O)โปยน โŸฉ
                 (O + O') ๏ผโŸจ iii O O' โŸฉ
                 (O' + O) ๏ผโŸจ f O' โŸฉ
                  O'      โˆŽ

    b : (O : R) โ†’ is-subsingleton ((x : R) โ†’ x + O ๏ผ x)
    b O = ฮ -is-subsingleton fe (ฮป x โ†’ i (x + O) x)

    c : (O : R)
      โ†’ ((x : R) โ†’ x + O ๏ผ x)
      โ†’ (x : R) โ†’ is-subsingleton (ฮฃ x' ๊ž‰ R , x + x' ๏ผ O)
    c O f x (x' , p') (x'' , p'') = to-subtype-๏ผ (ฮป x' โ†’ i (x + x') O) r
     where
      r : x' ๏ผ x''
      r = x'               ๏ผโŸจ (f x')โปยน โŸฉ
          (x' + O)         ๏ผโŸจ ap (x' +_) (p'' โปยน) โŸฉ
          (x' + (x + x'')) ๏ผโŸจ (ii x' x x'')โปยน โŸฉ
          ((x' + x) + x'') ๏ผโŸจ ap (_+ x'') (iii x' x) โŸฉ
          ((x + x') + x'') ๏ผโŸจ ap (_+ x'') p' โŸฉ
          (O + x'')        ๏ผโŸจ iii O x'' โŸฉ
          (x'' + O)        ๏ผโŸจ f x'' โŸฉ
          x''              โˆŽ

    d : (O : R) โ†’ is-subsingleton (A O)
    d O (f , g) = ฯ† (f , g)
     where
      ฯ† : is-subsingleton (A O)
      ฯ† = ร—-is-subsingleton (b O) (ฮ -is-subsingleton fe (ฮป x โ†’ c O f x))

    IV-is-subsingleton : is-subsingleton IV
    IV-is-subsingleton (O , f , g) (O' , f' , g') = e
     where
      e : (O , f , g) ๏ผ (O' , f' , g')
      e = to-subtype-๏ผ d (a O O' f f')

    ฮณ : is-subsingleton (rng-axioms R (_+_ , _ยท_))
    ฮณ = ร—-is-subsingleton
          (being-set-is-subsingleton fe)
       (ร—-is-subsingleton
          (ฮ -is-subsingleton fe
          (ฮป x โ†’ ฮ -is-subsingleton fe
          (ฮป y โ†’ ฮ -is-subsingleton fe
          (ฮป z โ†’ i ((x + y) + z) (x + (y + z))))))
       (ร—-is-subsingleton
          (ฮ -is-subsingleton fe
          (ฮป x โ†’ ฮ -is-subsingleton fe
          (ฮป y โ†’ i (x + y) (y + x))))
       (ร—-is-subsingleton
          IV-is-subsingleton
       (ร—-is-subsingleton
          (ฮ -is-subsingleton fe
          (ฮป x โ†’ ฮ -is-subsingleton fe
          (ฮป y โ†’ ฮ -is-subsingleton fe
          (ฮป z โ†’ i ((x ยท y) ยท z) (x ยท (y ยท z))))))
       (ร—-is-subsingleton
          (ฮ -is-subsingleton fe
          (ฮป x โ†’ ฮ -is-subsingleton fe
          (ฮป y โ†’ ฮ -is-subsingleton fe
          (ฮป z โ†’ i (x ยท (y + z)) ((x ยท y) + (x ยท z))))))

          (ฮ -is-subsingleton fe
          (ฮป x โ†’ ฮ -is-subsingleton fe
          (ฮป y โ†’ ฮ -is-subsingleton fe
          (ฮป z โ†’ i ((y + z) ยท x) ((y ยท x) + (z ยท x)))))))))))

    ฮด : (ฮฑ : rng-axioms R (_+_ , _ยท_)) โ†’ (i , ii , iii , iv-vii) ๏ผ ฮฑ
    ฮด = ฮณ (i , ii , iii , iv-vii)

 _โ‰…[Rng]_ : Rng โ†’ Rng โ†’ ๐“ค ฬ‡

 (R , (_+_ , _ยท_) , _) โ‰…[Rng] (R' , (_+'_ , _ยท'_) , _) =

                       ฮฃ f ๊ž‰ (R โ†’ R')
                           , is-equiv f
                           ร— ((ฮป x y โ†’ f (x + y)) ๏ผ (ฮป x y โ†’ f x +' f y))
                           ร— ((ฮป x y โ†’ f (x ยท y)) ๏ผ (ฮป x y โ†’ f x ยท' f y))

 characterization-of-rng-๏ผ : (๐“ก ๐“ก' : Rng) โ†’ (๐“ก ๏ผ ๐“ก') โ‰ƒ (๐“ก โ‰…[Rng] ๐“ก')
 characterization-of-rng-๏ผ = characterization-of-๏ผ (ua ๐“ค)
                              (add-axioms
                                rng-axioms
                                rng-axioms-is-subsingleton
                                (join
                                  โˆž-magma.sns-data
                                  โˆž-magma.sns-data))

 โŸจ_โŸฉ : (๐“ก : Rng) โ†’ ๐“ค ฬ‡
 โŸจ R , _ โŸฉ = R

 ring-structure : ๐“ค ฬ‡ โ†’ ๐“ค ฬ‡
 ring-structure X = X ร— rng-structure X

 ring-axioms : (R : ๐“ค ฬ‡ ) โ†’ ring-structure R โ†’ ๐“ค ฬ‡
 ring-axioms R (๐Ÿ , _+_ , _ยท_) = rng-axioms R (_+_ , _ยท_) ร— VIII
  where
   VIII = (x : R) โ†’ (x ยท ๐Ÿ ๏ผ x) ร— (๐Ÿ ยท x ๏ผ x)

 ring-axioms-is-subsingleton : (R : ๐“ค ฬ‡ ) (s : ring-structure R)
                             โ†’ is-subsingleton (ring-axioms R s)

 ring-axioms-is-subsingleton R (๐Ÿ , _+_ , _ยท_) ((i , ii-vii) , viii) = ฮณ ((i , ii-vii) , viii)
  where
   ฮณ : is-subsingleton (ring-axioms R (๐Ÿ , _+_ , _ยท_))
   ฮณ = ร—-is-subsingleton
         (rng-axioms-is-subsingleton R (_+_ , _ยท_))
         (ฮ -is-subsingleton fe (ฮป x โ†’ ร—-is-subsingleton (i (x ยท ๐Ÿ) x) (i (๐Ÿ ยท x) x)))

 Ring : ๐“ค โบ ฬ‡
 Ring = ฮฃ R ๊ž‰ ๐“ค ฬ‡ , ฮฃ s ๊ž‰ ring-structure R , ring-axioms R s

 _โ‰…[Ring]_ : Ring โ†’ Ring โ†’ ๐“ค ฬ‡

 (R , (๐Ÿ , _+_ , _ยท_) , _) โ‰…[Ring] (R' , (๐Ÿ' , _+'_ , _ยท'_) , _) =

                           ฮฃ f ๊ž‰ (R โ†’ R')
                               , is-equiv f
                               ร— (f ๐Ÿ ๏ผ ๐Ÿ')
                               ร— ((ฮป x y โ†’ f (x + y)) ๏ผ (ฮป x y โ†’ f x +' f y))
                               ร— ((ฮป x y โ†’ f (x ยท y)) ๏ผ (ฮป x y โ†’ f x ยท' f y))

 characterization-of-ring-๏ผ : (๐“ก ๐“ก' : Ring) โ†’ (๐“ก ๏ผ ๐“ก') โ‰ƒ (๐“ก โ‰…[Ring] ๐“ก')
 characterization-of-ring-๏ผ = sip.characterization-of-๏ผ (ua ๐“ค)
                                (sip-with-axioms.add-axioms
                                  ring-axioms
                                  ring-axioms-is-subsingleton
                                  (sip-join.join
                                    pointed-type.sns-data
                                      (join
                                        โˆž-magma.sns-data
                                        โˆž-magma.sns-data)))

 is-commutative : Rng โ†’ ๐“ค ฬ‡
 is-commutative (R , (_+_ , _ยท_) , _) = (x y : R) โ†’ x ยท y ๏ผ y ยท x

 being-commutative-is-subsingleton : (๐“ก : Rng) โ†’ is-subsingleton (is-commutative ๐“ก)
 being-commutative-is-subsingleton (R , (_+_ , _ยท_) , i , ii-vii) =

   ฮ -is-subsingleton fe
   (ฮป x โ†’ ฮ -is-subsingleton fe
   (ฮป y โ†’ i (x ยท y) (y ยท x)))

 is-ideal : (๐“ก : Rng) โ†’ ๐“Ÿ โŸจ ๐“ก โŸฉ โ†’ ๐“ค ฬ‡
 is-ideal (R , (_+_ , _ยท_) , _) I = (x y : R) โ†’ (x โˆˆ I โ†’ y โˆˆ I โ†’ (x + y) โˆˆ I)
                                              ร— (x โˆˆ I โ†’ (x ยท y) โˆˆ I)
                                              ร— (y โˆˆ I โ†’ (x ยท y) โˆˆ I)

 is-local : Rng โ†’ ๐“ค โบ ฬ‡
 is-local ๐“ก = โˆƒ! I ๊ž‰ ๐“Ÿ โŸจ ๐“ก โŸฉ , (is-ideal ๐“ก I โ†’ (J : ๐“Ÿ โŸจ ๐“ก โŸฉ) โ†’ is-ideal ๐“ก J โ†’ J โІ I)

 being-local-is-subsingleton : (๐“ก : Rng) โ†’ is-subsingleton (is-local ๐“ก)
 being-local-is-subsingleton ๐“ก = โˆƒ!-is-subsingleton _ fe

 module _ (pt : subsingleton-truncations-exist) where

  open basic-truncation-development pt hfe
  open โ„•-order

  is-noetherian : (๐“ก : Rng) โ†’ ๐“ค โบ ฬ‡
  is-noetherian ๐“ก = (I : โ„• โ†’ ๐“Ÿ โŸจ ๐“ก โŸฉ)
                  โ†’ ((n : โ„•) โ†’ is-ideal ๐“ก (I n))
                  โ†’ ((n : โ„•) โ†’ I n โІ I (succ n))
                  โ†’ โˆƒ m ๊ž‰ โ„• , ((n : โ„•) โ†’ m โ‰ค n โ†’ I m ๏ผ I n)

  NoetherianRng : ๐“ค โบ ฬ‡
  NoetherianRng = ฮฃ ๐“ก ๊ž‰ Rng , is-noetherian ๐“ก

  being-noetherian-is-subsingleton : (๐“ก : Rng) โ†’ is-subsingleton (is-noetherian ๐“ก)

  being-noetherian-is-subsingleton ๐“ก = ฮ -is-subsingleton fe
                                       (ฮป I โ†’ ฮ -is-subsingleton fe
                                       (ฮป _ โ†’ ฮ -is-subsingleton fe
                                       (ฮป _ โ†’ โˆƒ-is-subsingleton)))

  forget-Noether : NoetherianRng โ†’ Rng
  forget-Noether (๐“ก , _) = ๐“ก

  forget-Noether-is-embedding : is-embedding forget-Noether
  forget-Noether-is-embedding = prโ‚-embedding being-noetherian-is-subsingleton

  _โ‰…[NoetherianRng]_ : NoetherianRng โ†’ NoetherianRng โ†’ ๐“ค ฬ‡

  ((R , (_+_ , _ยท_) , _) , _) โ‰…[NoetherianRng] ((R' , (_+'_ , _ยท'_) , _) , _) =

                              ฮฃ f ๊ž‰ (R โ†’ R')
                                  , is-equiv f
                                  ร— ((ฮป x y โ†’ f (x + y)) ๏ผ (ฮป x y โ†’ f x +' f y))
                                  ร— ((ฮป x y โ†’ f (x ยท y)) ๏ผ (ฮป x y โ†’ f x ยท' f y))

  NB : (๐“ก ๐“ก' : NoetherianRng)
     โ†’ (๐“ก โ‰…[NoetherianRng] ๐“ก') ๏ผ (forget-Noether ๐“ก โ‰…[Rng] forget-Noether ๐“ก')

  NB ๐“ก ๐“ก' = refl _

  characterization-of-nrng-๏ผ : (๐“ก ๐“ก' : NoetherianRng)
                             โ†’ (๐“ก ๏ผ ๐“ก') โ‰ƒ (๐“ก โ‰…[NoetherianRng] ๐“ก')

  characterization-of-nrng-๏ผ ๐“ก ๐“ก' =

    (๐“ก ๏ผ ๐“ก')                               โ‰ƒโŸจ i โŸฉ
    (forget-Noether ๐“ก ๏ผ forget-Noether ๐“ก') โ‰ƒโŸจ ii โŸฉ
    (๐“ก โ‰…[NoetherianRng] ๐“ก')                โ– 

    where
     i = โ‰ƒ-sym (embedding-criterion-converse forget-Noether
                  forget-Noether-is-embedding ๐“ก ๐“ก')
     ii = characterization-of-rng-๏ผ (forget-Noether ๐“ก) (forget-Noether ๐“ก')

  isomorphic-NoetherianRng-transport :

      (A : NoetherianRng โ†’ ๐“ฅ ฬ‡ )
    โ†’ (๐“ก ๐“ก' : NoetherianRng) โ†’ ๐“ก โ‰…[NoetherianRng] ๐“ก' โ†’ A ๐“ก โ†’ A ๐“ก'

  isomorphic-NoetherianRng-transport A ๐“ก ๐“ก' i a = a'
   where
    p : ๐“ก ๏ผ ๐“ก'
    p = โŒœ โ‰ƒ-sym (characterization-of-nrng-๏ผ ๐“ก ๐“ก') โŒ i

    a' : A ๐“ก'
    a' = transport A p a

  is-CNL : Ring โ†’ ๐“ค โบ ฬ‡
  is-CNL (R , (๐Ÿ , _+_ , _ยท_) , i-vii , viii) = is-commutative ๐“ก
                                              ร— is-noetherian ๐“ก
                                              ร— is-local ๐“ก
   where
    ๐“ก : Rng
    ๐“ก = (R , (_+_ , _ยท_) , i-vii)

  being-CNL-is-subsingleton : (๐“ก : Ring) โ†’ is-subsingleton (is-CNL ๐“ก)
  being-CNL-is-subsingleton (R , (๐Ÿ , _+_ , _ยท_) , i-vii , viii) =

     ร—-is-subsingleton (being-commutative-is-subsingleton ๐“ก)
    (ร—-is-subsingleton (being-noetherian-is-subsingleton ๐“ก)
                       (being-local-is-subsingleton ๐“ก))
   where
    ๐“ก : Rng
    ๐“ก = (R , (_+_ , _ยท_) , i-vii)

  CNL-Ring : ๐“ค โบ ฬ‡
  CNL-Ring = ฮฃ ๐“ก ๊ž‰ Ring , is-CNL ๐“ก

  _โ‰…[CNL]_ : CNL-Ring โ†’ CNL-Ring โ†’ ๐“ค ฬ‡

  ((R , (๐Ÿ , _+_ , _ยท_) , _) , _) โ‰…[CNL] ((R' , (๐Ÿ' , _+'_ , _ยท'_) , _) , _) =

                                  ฮฃ f ๊ž‰ (R โ†’ R')
                                      , is-equiv f
                                      ร— (f ๐Ÿ ๏ผ ๐Ÿ')
                                      ร— ((ฮป x y โ†’ f (x + y)) ๏ผ (ฮป x y โ†’ f x +' f y))
                                      ร— ((ฮป x y โ†’ f (x ยท y)) ๏ผ (ฮป x y โ†’ f x ยท' f y))

  forget-CNL : CNL-Ring โ†’ Ring
  forget-CNL (๐“ก , _) = ๐“ก

  forget-CNL-is-embedding : is-embedding forget-CNL
  forget-CNL-is-embedding = prโ‚-embedding being-CNL-is-subsingleton

  NB' : (๐“ก ๐“ก' : CNL-Ring)
      โ†’ (๐“ก โ‰…[CNL] ๐“ก') ๏ผ (forget-CNL ๐“ก โ‰…[Ring] forget-CNL ๐“ก')

  NB' ๐“ก ๐“ก' = refl _

  characterization-of-CNL-ring-๏ผ : (๐“ก ๐“ก' : CNL-Ring)
                                 โ†’ (๐“ก ๏ผ ๐“ก') โ‰ƒ (๐“ก โ‰…[CNL] ๐“ก')

  characterization-of-CNL-ring-๏ผ ๐“ก ๐“ก' =

     (๐“ก ๏ผ ๐“ก')                               โ‰ƒโŸจ i โŸฉ
     (forget-CNL ๐“ก ๏ผ forget-CNL ๐“ก')         โ‰ƒโŸจ ii โŸฉ
     (๐“ก โ‰…[CNL] ๐“ก')                          โ– 

     where
      i = โ‰ƒ-sym (embedding-criterion-converse forget-CNL
                   forget-CNL-is-embedding ๐“ก ๐“ก')
      ii = characterization-of-ring-๏ผ (forget-CNL ๐“ก) (forget-CNL ๐“ก')

  isomorphic-CNL-Ring-transport :

      (A : CNL-Ring โ†’ ๐“ฅ ฬ‡ )
    โ†’ (๐“ก ๐“ก' : CNL-Ring) โ†’ ๐“ก โ‰…[CNL] ๐“ก' โ†’ A ๐“ก โ†’ A ๐“ก'

  isomorphic-CNL-Ring-transport A ๐“ก ๐“ก' i a = a'
   where
    p : ๐“ก ๏ผ ๐“ก'
    p = โŒœ โ‰ƒ-sym (characterization-of-CNL-ring-๏ผ ๐“ก ๐“ก') โŒ i

    a' : A ๐“ก'
    a' = transport A p a