open import Algebra.Semigroup
open import Algebra.Group.Ab
open import Algebra.Prelude
open import Algebra.Monoid
open import Algebra.Group

module Algebra.Ring where


The ring is one of the basic objects of study in algebra, which abstracts the best bits of the common algebraic structures: The integers Z\bb{Z}, the rationals Q\bb{Q}, the reals R\bb{R}, and the complex numbers C\bb{C} are all rings, as are the collections of polynomials with coefficients in any of those. Less familiar examples of rings include square matrices (with values in a ring) and the integral cohomology ring of a topological space: that these are so far from being β€œnumber-like” indicates the incredible generality of rings.

A ring is an abelian group RR (which we call the additive group of RR), together with the data of a monoid on RR (the multiplicative monoid), where the multiplication of the monoid distributes over the addition. We’ll see why this compatibility condition is required afterwards. Check out what it means for a triple (1,βˆ—,+)(1, *, +) to be a ring structure on a type:

record is-ring {β„“} {R : Type β„“} (1R : R) (_*_ _+_ : R β†’ R β†’ R) : Type β„“ where
    *-monoid : is-monoid 1R _*_
    +-group  : is-group _+_
    +-commutes : βˆ€ {x y} β†’ x + y ≑ y + x
    *-distribl : βˆ€ {x y z} β†’ x * (y + z) ≑ (x * y) + (x * z)
    *-distribr : βˆ€ {x y z} β†’ (y + z) * x ≑ (y * x) + (z * x)

There is a natural notion of ring homomorphism, which we get by smashing together that of a monoid homomorphism (for the multiplicative part) and of group homomorphism; Every map of rings has an underlying map of groups which preserves the addition operation, and it must also preserve the multiplication. This encodes the view of a ring as an β€œabelian group with a monoid structure”.

record is-ring-hom {β„“} (A B : Ring β„“) (f : A .fst β†’ B .fst) : Type β„“ where
    module A = Ring-on (A .snd)
    module B = Ring-on (B .snd)

    pres-id : f A.1R ≑ B.1R
    pres-+  : βˆ€ x y β†’ f (x A.+ y) ≑ f x B.+ f y
    pres-*  : βˆ€ x y β†’ f (x A.* y) ≑ f x B.* f y

It follows, by standard equational nonsense, that rings and ring homomorphisms form a precategory β€” for instance, we have f(g(1R))=f(1S)=1Tf(g(1_R)) = f(1_S) = 1_T.

Rings : βˆ€ β„“ β†’ Precategory (lsuc β„“) β„“

In componentsπŸ”—

We give a more elementary description of rings, which is suitable for constructing values of the record type Ring above. This re-expresses the data included in the definition of a ring with the least amount of redundancy possible, in the most direct terms possible: A ring is a set, equipped with two binary operations βˆ—* and ++, such that βˆ—* distributes over ++ on either side; ++ is an abelian group; and βˆ—* is a monoid.

record make-ring {β„“} (R : Type β„“) : Type β„“ where
    ring-is-set : is-set R

    -- R is an abelian group:
    0R      : R
    _+_     : R β†’ R β†’ R
    -_      : R β†’ R
    +-idl   : βˆ€ {x} β†’ 0R + x ≑ x
    +-invr  : βˆ€ {x} β†’ x + (- x) ≑ 0R
    +-assoc : βˆ€ {x y z} β†’ (x + y) + z ≑ x + (y + z)
    +-comm  : βˆ€ {x y} β†’ x + y ≑ y + x

    -- R is a monoid:
    1R      : R
    _*_     : R β†’ R β†’ R
    *-idl   : βˆ€ {x} β†’ 1R * x ≑ x
    *-idr   : βˆ€ {x} β†’ x * 1R ≑ x
    *-assoc : βˆ€ {x y z} β†’ (x * y) * z ≑ x * (y * z)

    -- Multiplication is bilinear:
    *-distribl : βˆ€ {x y z} β†’ x * (y + z) ≑ (x * y) + (x * z)
    *-distribr : βˆ€ {x y z} β†’ (y + z) * x ≑ (y * x) + (z * x)

This data is missing (by design, actually!) one condition which we would expect: 0β‰ 10 \ne 1. We exploit this to give our first example of a ring, the zero ring, which has carrier set the unit β€” the type with one object.

Despite the name, the zero ring is not the zero object in the category of rings: it is the terminal object. In the category of rings, the initial object is the ring Z\bb{Z}, which is very far (infinitely far!) from having a single element. It’s called the β€œzero ring” because it has one element xx, which must be the additive identity, hence we call it 00. But it’s also the multiplicative identity, so we might also call the ring {βˆ—}\{*\} the One Ring, which would be objectively cooler.

Zero-ring : Ring lzero
Zero-ring = from-make-ring {R = ⊀} $ record
  { ring-is-set = Ξ» _ _ _ _ _ _ β†’ tt
  ; 0R         = tt
  ; _+_        = Ξ» _ _ β†’ tt
  ; -_         = Ξ» _ β†’ tt
  ; +-idl      = Ξ» _ β†’ tt
  ; +-invr     = Ξ» _ β†’ tt
  ; +-assoc    = Ξ» _ β†’ tt
  ; +-comm     = Ξ» _ β†’ tt
  ; 1R         = tt
  ; _*_        = Ξ» _ _ β†’ tt
  ; *-idl      = Ξ» _ β†’ tt
  ; *-idr      = Ξ» _ β†’ tt
  ; *-assoc    = Ξ» _ β†’ tt
  ; *-distribl = Ξ» _ β†’ tt
  ; *-distribr = Ξ» _ β†’ tt