module Algebra.Ring.Cat.Initial {} where

The initial ring🔗

We have, in the introduction to rings, mentioned offhand that the ring is an initial object. This turns out to be a fairly nontrivial theorem to formalise, so we have decided to do so in this module. For starters, note that the ring is an object of the category of “rings in the zeroth universe”, whereas we would like any category of rings to have its own initial object. So, the first thing we must do is define a lifting of to larger universes:

Liftℤ : Ring 
Liftℤ = to-ring mr where
  open make-ring
  mr : make-ring (Lift  Int)
  mr .ring-is-set = hlevel 2
  mr .1R = lift 1
  mr .0R = lift 0
  mr .-_  (lift x)          = lift (negℤ x)
  mr ._+_ (lift x) (lift y) = lift (x +ℤ y)
  mr ._*_ (lift x) (lift y) = lift (x *ℤ y)

With that set up out of the way, we can now proceed to the actual theorem we’re interested in: For a ring there is a contractible space of homomorphisms The definition of this construction is fairly involved, as algebra tends to be, so let’s see it in parts: The first thing we must do is write a procedure to turn natural numbers into elements of There’s really only one choice1, so here it is:

Int-is-initial : is-initial (Rings ) Liftℤ
Int-is-initial R = contr z→r λ x  ext (lemma x) where
  module R = Kit R

Note that we treat 1 with care: we could have this map 1 to 1r + 0r, but this results in worse definitional behaviour when actually using the embedding. This will result in a bit more work right now, but is work worth doing.

  e : Nat   R 
  e zero          = R.0r
  e (suc zero)    = R.1r
  e (suc (suc x)) = R.1r R.+ e (suc x)

Zero gets sent to zero, and “adding one” gets sent to adding one. Is anyone surprised? I know I’m not. Anyway, this operation is a semiring homomorphism from the natural numbers to i.e., it sends sums of naturals to sums in and products of naturals to products in We’ll need this later.

  e-suc :  n  e (suc n)  R.1r R.+ e n
  e-add :  m n  e (m Nat.+ n)  e m R.+ e n
  e-mul :  m n  e (m Nat.* n)  e m R.* e n

The last thing we need is a little lemma that will be used in showing that our embedding extends to a function We want to define by sending to meaning that must respect the path constructor used in the definition of integers, i.e. we need This is annoying to show, but not too annoying:

  e-tr :  m n  e m R.- e n  e (suc m) R.- e (suc n)
  e-tr m n = sym $
    (e (suc m) R.- e (suc n))                   ≡⟨ ap₂ R._-_ (e-suc m) (e-suc n) 
    (R.1r R.+ e m) R.- (R.1r R.+ e n)           ≡⟨ ap₂ R._+_ refl (R.a.inv-comm  R.+-commutes)  R.+-associative 
    R.1r R.+ e m R.+ (R.- R.1r) R.+ (R.- e n)   ≡⟨ ap₂ R._+_ (R.pullr R.+-commutes  R.pulll refl) refl 
    R.1r R.+ (R.- R.1r) R.+ e m R.+ (R.- e n)   ≡⟨ ap₂ R._+_ (R.eliml R.+-invr) refl 
    e m R.- e n                                 

We can now build the embedding It remains to show that this is a ring homomorphism… which involves a mountain of annoying algebra, so I won’t comment on it too much: it can be worked out on paper, following the ring laws.

  ℤ↪R : Int   R 
  ℤ↪R (pos x) = e x
  ℤ↪R (negsuc x) = R.- (e (suc x))

  open is-ring-hom

  z-natdiff :  x y  ℤ↪R (x ℕ- y)  e x R.- e y
  z-natdiff x zero = R.intror R.inv-unit
  z-natdiff zero (suc y) = R.introl refl
  z-natdiff (suc x) (suc y) = z-natdiff x y  e-tr x y

  z-add :  x y  ℤ↪R (x +ℤ y)  ℤ↪R x R.+ ℤ↪R y
  z-add (pos x) (pos y) = e-add x y
  z-add (pos x) (negsuc y) = z-natdiff x (suc y)
  z-add (negsuc x) (pos y) = z-natdiff y (suc x)  R.+-commutes
  z-add (negsuc x) (negsuc y) =
    R.- (e 1 R.+ e (suc x Nat.+ y))         ≡⟨ ap R.-_ (ap₂ R._+_ refl (e-add (suc x) y)  R.extendl R.+-commutes) 
    R.- (e (suc x) R.+ (e 1 R.+ e y))       ≡⟨ R.a.inv-comm 
    (R.- (e 1 R.+ e y)) R.+ (R.- e (suc x)) ≡⟨ R.+-commutes 
    (R.- e (suc x)) R.+ (R.- (e 1 R.+ e y)) ≡⟨ ap₂ R._+_ refl (ap R.-_ (sym (e-add 1 y))) 
    (R.- e (suc x)) R.+ (R.- e (1 Nat.+ y)) 

  z-mul :  x y  ℤ↪R (x *ℤ y)  ℤ↪R x R.* ℤ↪R y
  z-mul (pos x) (pos y) =
    ℤ↪R (assign pos (x Nat.* y)) ≡⟨ ap ℤ↪R (assign-pos (x Nat.* y)) 
    e (x Nat.* y)                ≡⟨ e-mul x y 
    (e x R.* e y)                
  z-mul (posz) (negsuc y) = sym R.*-zerol
  z-mul (possuc x) (negsuc y) =
    R.- e (suc x Nat.* suc y)     ≡⟨ ap R.-_ (e-mul (suc x) (suc y)) 
    R.- (e (suc x) R.* e (suc y)) ≡˘⟨ R.*-negater ≡˘
    e (suc x) R.* (R.- e (suc y)) 
  z-mul (negsuc x) (posz) =
    ℤ↪R (assign neg (x Nat.* 0)) ≡⟨ ap ℤ↪R (ap (assign neg) (Nat.*-zeror x)) 
    ℤ↪R 0                        ≡⟨ sym R.*-zeror 
    ℤ↪R (negsuc x) R.* R.0r      
  z-mul (negsuc x) (possuc y) =
    R.- e (suc x Nat.* suc y)     ≡⟨ ap R.-_ (e-mul (suc x) (suc y)) 
    R.- (e (suc x) R.* e (suc y)) ≡⟨ sym R.*-negatel 
    (R.- e (suc x)) R.* e (suc y) 
  z-mul (negsuc x) (negsuc y) =
    e (suc x Nat.* suc y)               ≡⟨ e-mul (suc x) (suc y) 
    e (suc x) R.* e (suc y)             ≡˘⟨ R.inv-inv ≡˘
    R.- (R.- (e (suc x) R.* e (suc y))) ≡˘⟨ ap R.-_ R.*-negater ≡˘
    R.- (e (suc x) R.* ℤ↪R (negsuc y))  ≡˘⟨ R.*-negatel ≡˘
    ℤ↪R (negsuc x) R.* ℤ↪R (negsuc y)   

  z→r : Rings.Hom Liftℤ R
  z→r .hom (lift x) = ℤ↪R x
  z→r .preserves .pres-id = refl
  z→r .preserves .pres-+ (lift x) (lift y) = z-add x y
  z→r .preserves .pres-* (lift x) (lift y) = z-mul x y

The last thing we must show is that this is the unique ring homomorphism from the integers to This, again, is slightly indirect: We know for a fact that, if we have some other homomorphism then it must enjoy just as our chosen embedding does. Now, no matter how trivial this coming observation may seem, do not brush it aside: The integer is the sum of copies of the number 1. This is actually precisely what we need to establish the result! That’s because we have

and that last expression is pretty exactly what our canonical map evaluates to on So we’re done!

  module _ (f : Rings.Hom Liftℤ R) where
    private module f = is-ring-hom (f .preserves)

    f-pos :  x  e x  f .hom (lift (pos x))
    f-pos zero = sym f.pres-0
    f-pos (suc x) = e-suc x  sym (f.pres-+ (lift 1) (lift (pos x))  ap₂ R._+_ f.pres-id (sym (f-pos x)))

    lemma : (i : Int)  z→r # lift i  f # lift i
    lemma (pos x) = f-pos x
    lemma (negsuc x) = sym (f.pres-neg {lift (possuc x)}  ap R.-_ (sym (f-pos (suc x))))

  1. though the fact that there’s only one choice is sorta the theorem we are trying to prove…↩︎