module Algebra.Ring.Module where

ModulesπŸ”—

A module over a ring RR is an abelian group GG equipped with an action by RR. Modules generalise the idea of vector spaces, which may be familiar from linear algebra, by replacing the field of scalars by a ring of scalars. More pertinently, though, modules specialise functors: specifically, Ab\mathbf{Ab}-enriched functors into the category Ab\mathbf{Ab}.

For silly formalisation reasons, when defining modules, we do not take β€œan Ab\mathbf{Ab}-functor into Ab\mathbf{Ab}” as the definition: this correspondence is a theorem we prove later. Instead, we set up RR-modules as typical algebraic structures, as data (and property) attached to a type.

The structure of an RR-module on a type TT consists of an addition +:TΓ—Tβ†’T+ : T \times T \to T and a scalar multiplication ⋆:RΓ—Tβ†’T\star : R \times T \to T. In prose, we generally omit the star, writing rxrx rather than the wordlier r⋆xr \star x. These must satisfy the following properties:

  • ++ makes TT into an abelian group. Since we’ve already defined abelian groups, we can take this entire property as β€œindivisible”, saving some effort.

  • β‹…Β· is a ring homomorphism of RR onto (T,+)(T, +)’s endomorphism ring. In other words, we have:

    • 1x=x1x = x;
    • (rs)β‹…x=rβ‹…(sβ‹…x)(rs) \cdot x = r \cdot (s \cdot x);
    • (r+s)x=rx+sx(r + s)x = rx + sx; and
    • r(x+y)=rx+ryr(x + y) = rx + ry.
  record is-module {β„“'} {T : Type β„“'} (_+_ : T β†’ T β†’ T) (_⋆_ : ⌞ R ⌟ β†’ T β†’ T) : Type (β„“ βŠ” β„“') where
    no-eta-equality
    field
      has-is-ab  : is-abelian-group _+_
      ⋆-distribl : βˆ€ r x y β†’ r ⋆ (x + y)   ≑ (r ⋆ x) + (r ⋆ y)
      ⋆-distribr : βˆ€ r s x β†’ (r R.+ s) ⋆ x ≑ (r ⋆ x) + (s ⋆ x)
      ⋆-assoc    : βˆ€ r s x β†’ r ⋆ (s ⋆ x)   ≑ (r R.* s) ⋆ x
      ⋆-id       : βˆ€ x     β†’ R.1r ⋆ x      ≑ x

Correspondingly, a module structure on a type packages the addition, the scalar multiplication, and the proofs that these behave as we set above. A module is a type equipped with a module structure.

  record Module-on {β„“'} (T : Type β„“') : Type (β„“ βŠ” β„“') where
    no-eta-equality
    field
      _+_        : T β†’ T β†’ T
      _⋆_        : ⌞ R ⌟ β†’ T β†’ T
      has-is-mod : is-module _+_ _⋆_

    infixl 25 _+_
    infixr 27 _⋆_

    open is-module has-is-mod public
  Module : βˆ€ β„“m β†’ Type (lsuc β„“m βŠ” β„“)
  Module β„“m = Ξ£ (Set β„“m) Ξ» X β†’ Module-on ∣ X ∣

  record is-linear-map (f : S β†’ T) (M : Module-on S) (N : Module-on T)
    : Type (β„“ βŠ” level-of S βŠ” level-of T) where

Linear mapsπŸ”—

The correct notion of morphism between RR-modules is the linear map; in case we need to make the base ring RR clear, we shall call them RR-linear maps. Since the structure of RR-modules are their additions and their scalar multiplications, it stands to reason that these are what homomorphisms should preserve. Rather than separately asking for preservation of addition and of multiplication, the following single assumption suffices:

    field linear : βˆ€ r s t β†’ f (r ⋆ s + t) ≑ r ⋆ f s + f t

Any map which satisfies this equation must preserve addition, since we have

f(a+b)=f(1a+b)=1f(a)+f(b)=f(a)+f(b), f(a+b) = f(1a+b) = 1f(a)+f(b) = f(a)+f(b)\text{,}

and standard lemmas about group homomorphisms ensure that ff will also preserve negation, and, more importantly, zero. We can then derive that ff preserves the scalar multiplication, by calculating

f(ra)=f(ra+0)=rf(a)+f(0)=rf(a)+0=rf(a). f(ra) = f(ra + 0) = rf(a) + f(0) = rf(a) + 0 = rf(a)\text{.}

  record Linear-map (M : Module β„“m) (N : Module β„“n) : Type (β„“ βŠ” β„“m βŠ” β„“n) where
    no-eta-equality
    field
      map : ⌞ M ⌟ β†’ ⌞ N ⌟
      lin : is-linear-map map (M .snd) (N .snd)
    open is-linear-map lin public

The collection of linear maps forms a set, whose identity type is given by pointwise identity of the underlying maps. Therefore, we may take these to be the morphisms of a category R-Mod{R}\text{-}\mathbf{Mod}. R-Mod{R}\text{-}\mathbf{Mod} is a very standard category, so very standard constructions can set up the category, the functor witnessing its concreteness, and a proof that it is univalent.

  R-Mod-structure : βˆ€ {β„“} β†’ Thin-structure _ Module-on
  R-Mod-structure {β„“} = rms where
    rms : Thin-structure _ Module-on
    ∣ rms .is-hom f M N ∣    = is-linear-map {β„“} {_} {β„“} f M N
    rms .is-hom f M N .is-tr = is-linear-map-is-prop

    rms .id-is-hom        .linear r s t = refl
    rms .∘-is-hom f g α β .linear r s t =
      ap f (Ξ² .linear r s t) βˆ™ Ξ± .linear _ _ _

    rms .id-hom-unique {s = s} {t = t} Ξ± _ = r where
      module s = Module-on s
      module t = Module-on t

      r : s ≑ t
      r i .Module-on._+_ x y = is-linear-map.pres-+ Ξ± x y i
      r i .Module-on._⋆_ x y = is-linear-map.pres-⋆ Ξ± x y i
      r i .Module-on.has-is-mod =
        is-prop→pathp (λ i → hlevel {T = is-module
          (Ξ» x y β†’ is-linear-map.pres-+ Ξ± x y i)
          (Ξ» x y β†’ is-linear-map.pres-⋆ Ξ± x y i)} 1)
          (Module-on.has-is-mod s) (Module-on.has-is-mod t) i

β€œRepresentable” modulesπŸ”—

A prototypical example of RR-module is.. RR itself! A ring has an underlying abelian group, and the multiplication operation can certainly be considered a special kind of β€œscalar multiplication”. If we treat RR as an Ab\mathbf{Ab}-category with a single object, this construction corresponds to the functor HomR(βˆ’,βˆ™)\mathbf{Hom}_R(-,\bull) β€” the β€œYoneda embedding” of RR’s unique object. Stretching the analogy, we refer to RR-as-an-RR-module as the β€œrepresentable” RR-module.

  representable-module : Module β„“
  representable-module .fst = R .fst
  representable-module .snd = to-module-on record
    { has-is-set = R.has-is-set
    ; _+_ = R._+_
    ; inv = R.-_
    ; 0g = R.0r
    ; +-assoc = Ξ» x y z β†’ R.+-associative
    ; +-invl = Ξ» x β†’ R.+-invl
    ; +-idl = Ξ» x β†’ R.+-idl
    ; +-comm = Ξ» x y β†’ R.+-commutes
    ; _⋆_ = R._*_
    ; ⋆-distribl = Ξ» x y z β†’ R.*-distribl
    ; ⋆-distribr = Ξ» x y z β†’ R.*-distribr
    ; ⋆-assoc    = Ξ» x y z β†’ R.*-associative
    ; ⋆-id       = Ξ» x β†’ R.*-idl
    }

Another perspective on this construction is that we are regarding RR as the space of β€œ1-dimensional vectors” over itself. Following this line of reasoning one can define the module of nn-dimensional vectors over RR.