module Algebra.Ring.Module where

ModulesπŸ”—

A module over a ring is an abelian group equipped with an action by . 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, functors into the category

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

The structure of an on a type consists of an addition and a scalar multiplication In prose, we generally omit the star, writing rather than the wordlier These must satisfy the following properties:

  • makes 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 onto endomorphism ring. In other words, we have:

    • and
  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 is the linear map; in case we need to make the base ring clear, we shall call them maps. Since the structure of 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

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

  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 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
  R-Mod : βˆ€ β„“m β†’ Precategory (lsuc β„“m βŠ” β„“) (β„“m βŠ” β„“)
  R-Mod β„“m = Structured-objects (R-Mod-structure {β„“m})

  R-Modβ†ͺSets : βˆ€ β„“m β†’ Functor (R-Mod β„“m) (Sets β„“m)
  R-Modβ†ͺSets _ = Forget-structure R-Mod-structure

  record make-module {β„“m} (M : Type β„“m) : Type (β„“m βŠ” β„“) where
    field
      has-is-set : is-set M
      _+_ : M β†’ M β†’ M
      inv : M β†’ M
      0g  : M

      +-assoc : βˆ€ x y z β†’ x + (y + z) ≑ (x + y) + z
      +-invl  : βˆ€ x β†’ inv x + x ≑ 0g
      +-idl   : βˆ€ x β†’ 0g + x ≑ x
      +-comm  : βˆ€ x y β†’ x + y ≑ y + x

      _⋆_ : ⌞ R ⌟ β†’ M β†’ M

      ⋆-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

  to-module-on : βˆ€ {β„“m} {M : Type β„“m} β†’ make-module M β†’ Module-on M
  to-module-on m .Module-on._+_ = make-module._+_ m
  to-module-on m .Module-on._⋆_ = make-module._⋆_ m
  to-module-on m .Module-on.has-is-mod = mod where
    gr : Group-on _
    gr = to-group-on Ξ» where
      .make-group.group-is-set β†’ make-module.has-is-set m
      .make-group.unit β†’ make-module.0g m
      .make-group.mul β†’ make-module._+_ m
      .make-group.inv β†’ make-module.inv m
      .make-group.assoc β†’ make-module.+-assoc m
      .make-group.invl β†’ make-module.+-invl m
      .make-group.idl β†’ make-module.+-idl m

    mod : is-module _ _
    mod .is-module.has-is-ab .is-abelian-group.has-is-group = gr .Group-on.has-is-group
    mod .is-module.has-is-ab .is-abelian-group.commutes = make-module.+-comm m _ _
    mod .is-module.⋆-distribl = make-module.⋆-distribl m
    mod .is-module.⋆-distribr = make-module.⋆-distribr m
    mod .is-module.⋆-assoc = make-module.⋆-assoc m
    mod .is-module.⋆-id = make-module.⋆-id m

  to-module : βˆ€ {β„“m} {M : Type β„“m} β†’ make-module M β†’ Module β„“m
  ∣ to-module m .fst ∣ = _
  to-module m .fst .is-tr = make-module.has-is-set m
  to-module m .snd = to-module-on m

β€œRepresentable” modulesπŸ”—

A prototypical example of is.. 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 as an with a single object, this construction corresponds to the functor β€” the β€œYoneda embedding” of unique object. Stretching the analogy, we refer to as the β€œrepresentable”

  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 as the space of β€œ1-dimensional vectors” over itself. Following this line of reasoning one can define the module of vectors over

-- Hide the constructions that take the base ring as an explicit
-- argument:
open Mod
  hiding
    ( Linear-map
    ; Linear-map-path
    ; is-linear-map
    ; to-module
    ; to-module-on
    ; Module-on→Group-on
    ; Module-on→Abelian-group-on
    ; H-Level-is-linear-map
    ; H-Level-is-module
    ; H-Level-Linear-map
    )
  public

-- And open them here where R is implicit instead:
module _ {β„“} {R : Ring β„“} where
  open Mod R
    using
      ( Linear-map
      ; Linear-map-path
      ; is-linear-map
      ; to-module
      ; to-module-on
      ; Module-on→Group-on
      ; Module-on→Abelian-group-on
      ; H-Level-is-linear-map
      ; H-Level-is-module
      ; H-Level-Linear-map
      )
    public

  instance
    Extensional-linear-map
      : βˆ€ {β„“r} {M : Module R β„“m} {N : Module R β„“n}
      β†’ ⦃ ext : Extensional (⌞ M ⌟ β†’ ⌞ N ⌟) β„“r ⦄
      β†’ Extensional (Linear-map M N) β„“r
    Extensional-linear-map ⦃ ext ⦄ = injectionβ†’extensional! (Ξ» p β†’ Linear-map-path (happly p)) ext

module R-Mod {β„“ β„“m} {R : Ring β„“} = Cat.Reasoning (R-Mod R β„“m)

hom→linear-map
  : βˆ€ {β„“ β„“m} {R : Ring β„“} {M N : Module R β„“m}
  β†’ R-Mod.Hom M N
  β†’ Linear-map M N
hom→linear-map h .map = h .hom
hom→linear-map h .lin = h .preserves

linear-map→hom
  : βˆ€ {β„“ β„“m} {R : Ring β„“} {M N : Module R β„“m}
  β†’ Linear-map M N
  β†’ R-Mod.Hom M N
linear-map→hom h .hom       = h .map
linear-map→hom h .preserves = h .lin

extensional-mod-hom
  : βˆ€ {β„“ β„“rel} {R : Ring β„“} {M : Module R β„“m} {N : Module R β„“m}
  β†’ ⦃ ext : Extensional (Linear-map M N) β„“rel ⦄
  β†’ Extensional (R-Mod R _ .Precategory.Hom M N) β„“rel
extensional-mod-hom ⦃ ei ⦄ = injectionβ†’extensional! {f = homβ†’linear-map} (Ξ» p β†’ ext Ξ» e β†’ ap map p $β‚š e) ei

instance Extensional-mod-hom = extensional-mod-hom
{-# OVERLAPS Extensional-mod-hom #-}