Martin Escardo and Paulo Oliva, April 2024.
The type of discrete graphic monoids.
\begin{code}
{-# OPTIONS --safe --without-K #-}
module DiscreteGraphicMonoids.Type where
open import MLTT.Spartan
open import UF.DiscreteAndSeparated
open import UF.Sets
open import UF.Subsingletons
open import UF.Subsingletons-FunExt
open import UF.FunExt
graphical : {X : ๐ค ฬ } โ (X โ X โ X) โ ๐ค ฬ
graphical _ยท_ = โ x y โ (x ยท y) ยท x ๏ผ x ยท y
monoid-structure : ๐ค ฬ โ ๐ค ฬ
monoid-structure X = X ร (X โ X โ X)
discrete-graphic-monoid-axioms : (X : ๐ค ฬ ) โ monoid-structure X โ ๐ค ฬ
discrete-graphic-monoid-axioms X (e , _ยท_) =
   is-discrete X
 ร left-neutral  e _ยท_
 ร right-neutral e _ยท_
 ร associative'    _ยท_
 ร graphical       _ยท_
discrete-graphic-monoid-axioms-is-prop
 : FunExt
 โ (X : ๐ค ฬ ) (s : monoid-structure X)
 โ is-prop (discrete-graphic-monoid-axioms X s)
discrete-graphic-monoid-axioms-is-prop fe X s =
 prop-criterion (ฮป axioms@(d , _) โ
  รโ
-is-prop
  (being-discrete-is-prop fe)
  (ฮ -is-prop (fe _ _) (ฮป x โ discrete-types-are-sets d))
  (ฮ -is-prop (fe _ _) (ฮป x โ discrete-types-are-sets d))
  (ฮ โ-is-prop (fe _ _) (ฮป x y z โ discrete-types-are-sets d))
  (ฮ โ-is-prop (fe _ _) (ฮป x y โ discrete-types-are-sets d)))
DGM : (๐ค : Universe) โ ๐ค โบ ฬ
DGM ๐ค = ฮฃ M ๊ ๐ค ฬ
      , ฮฃ s ๊ monoid-structure M
      , discrete-graphic-monoid-axioms M s
โจ_โฉ : DGM ๐ค โ ๐ค ฬ
โจ M , (e , _ยท_) , d , ln , rn , a , gl โฉ = M
unit : (๐ : DGM ๐ค)
     โ โจ ๐ โฉ
unit (M , (e , _ยท_) , d , ln , rn , a , gl) = e
syntax unit ๐ = eโจ ๐ โฉ
multiplication : (๐ : DGM ๐ค)
               โ โจ ๐ โฉ โ โจ ๐ โฉ โ โจ ๐ โฉ
multiplication (M , (e , _ยท_) , d , ln , rn , a , gl) = _ยท_
syntax multiplication ๐ x y = x ยทโจ ๐ โฉ y
discreteness : (๐ : DGM ๐ค) โ is-discrete โจ ๐ โฉ
discreteness (M , (e , _ยท_) , d , ln , rn , a , gl) = d
underlying-type-is-set : (๐ : DGM ๐ค) โ is-set โจ ๐ โฉ
underlying-type-is-set ๐ = discrete-types-are-sets (discreteness ๐)
left-neutrality : (๐ : DGM ๐ค)
                โ left-neutral (eโจ ๐ โฉ) (multiplication ๐)
left-neutrality (M , (e , _ยท_) , d , ln , rn , a , gl) = ln
right-neutrality : (๐ : DGM ๐ค)
                 โ right-neutral (eโจ ๐ โฉ) (multiplication ๐)
right-neutrality (M , (e , _ยท_) , d , ln , rn , a , gl) = rn
associativity : (๐ : DGM ๐ค)
              โ associative' (multiplication ๐)
associativity (M , (e , _ยท_) , d , ln , rn , a , gl) = a
graphicality : (๐ : DGM ๐ค)
             โ graphical (multiplication ๐)
graphicality (M , (e , _ยท_) , d , ln , rn , a , gl) = gl
idempotency : (๐ : DGM ๐ค) (x : โจ ๐ โฉ) โ x ยทโจ ๐ โฉ x ๏ผ x
idempotency ๐ x =
 x ยท x       ๏ผโจ ap (_ยท x) ((right-neutrality ๐ x)โปยน) โฉ
 (x ยท e) ยท x ๏ผโจ graphicality ๐ x e โฉ
 x ยท e       ๏ผโจ right-neutrality ๐ x โฉ
 x           โ
 where
  e   = unit ๐
  _ยท_ = multiplication ๐
is-hom : (๐ : DGM ๐ค) (๐ : DGM ๐ฅ) โ (โจ ๐ โฉ โ โจ ๐ โฉ) โ ๐ค โ ๐ฅ ฬ
is-hom ๐ ๐ f = (f eโจ ๐ โฉ ๏ผ eโจ ๐ โฉ)
               ร (โ x y โ f (x ยทโจ ๐ โฉ y) ๏ผ f x ยทโจ ๐ โฉ f y)
homs-preserve-unit : (๐ : DGM ๐ค) (๐ : DGM ๐ฅ)
                   โ (f : โจ ๐ โฉ โ โจ ๐ โฉ)
                   โ is-hom ๐ ๐ f
                   โ f eโจ ๐ โฉ ๏ผ eโจ ๐ โฉ
homs-preserve-unit _ _ _ (u , m) = u
homs-preserve-mul : (๐ : DGM ๐ค) (๐ : DGM ๐ฅ)
                  โ (f : โจ ๐ โฉ โ โจ ๐ โฉ)
                  โ is-hom ๐ ๐ f
                  โ (x y : โจ ๐ โฉ) โ f (x ยทโจ ๐ โฉ y) ๏ผ f x ยทโจ ๐ โฉ f y
homs-preserve-mul _ _ _ (u , m) = m
id-is-hom : (๐ : DGM ๐ค)
          โ is-hom ๐ ๐ id
id-is-hom ๐ = (refl , (ฮป _ _ โ refl))
โ-is-hom : (๐โ : DGM ๐ค) (๐โ : DGM ๐ฅ) (๐โ : DGM ๐ฆ)
           (f : โจ ๐โ โฉ โ โจ ๐โ โฉ) (g : โจ ๐โ โฉ โ โจ ๐โ โฉ)
         โ is-hom ๐โ ๐โ f
         โ is-hom ๐โ ๐โ g
         โ is-hom ๐โ ๐โ (g โ f)
โ-is-hom ๐โ ๐โ ๐โ f g (f-unit , f-mul) (g-unit , g-mul)  =
 ((g โ f) (unit ๐โ) ๏ผโจ ap g f-unit โฉ
  g (unit ๐โ)       ๏ผโจ g-unit โฉ
  unit ๐โ           โ) ,
 (ฮป x y โ g (f (x ยทโจ ๐โ โฉ y))     ๏ผโจ ap g (f-mul x y) โฉ
          g (f x ยทโจ ๐โ โฉ f y)     ๏ผโจ g-mul (f x) (f y) โฉ
          g (f x) ยทโจ ๐โ โฉ g (f y) โ)
\end{code}