module Algebra.Ring.Module.Category {β„“} (R : Ring β„“) where

The category R-ModπŸ”—

Let us investigate the structure of the category for whatever your favourite ring is1. The first thing we’ll show is that it admits an This is the usual β€œpointwise” group structure, but proving that the pointwise sum is a still a linear map is, ahem, very annoying. See for yourself:

  +-is-linear-map
    : βˆ€ {f g : ⌞ M ⌟ β†’ ⌞ N ⌟}
    β†’ is-linear-map f (M .snd) (N .snd)
    β†’ is-linear-map g (M .snd) (N .snd)
    β†’ is-linear-map (Ξ» x β†’ f x + g x) (M .snd) (N .snd)
  +-is-linear-map {f = f} {g} fp gp .linear r s t =
    f (r ⋆ s + t) + g (r ⋆ s + t)      β‰‘βŸ¨ apβ‚‚ _+_ (fp .linear r s t) (gp .linear r s t) βŸ©β‰‘
    (r ⋆ f s + f t) + (r ⋆ g s + g t)  β‰‘βŸ¨ sym +-assoc βˆ™ apβ‚‚ _+_ refl (+-assoc βˆ™ apβ‚‚ _+_ (+-comm _ _) refl βˆ™ sym +-assoc) βˆ™ +-assoc βˆ™ +-assoc βŸ©β‰‘
    ⌜ r ⋆ f s + r ⋆ g s ⌝ + f t + g t  β‰‘Λ˜βŸ¨ apΒ‘ (⋆-distribl r (f s) (g s)) βŸ©β‰‘Λ˜
    r ⋆ (f s + g s) + f t + g t        β‰‘Λ˜βŸ¨ +-assoc βŸ©β‰‘Λ˜
    r ⋆ (f s + g s) + (f t + g t)      ∎

Doing some further algebra will let us prove that linear maps are also closed under pointwise inverse, and contain the zero map. The calculations speak for themselves:

  neg-is-linear-map
    : βˆ€ {f : ⌞ M ⌟ β†’ ⌞ N ⌟}
    β†’ is-linear-map f (M .snd) (N .snd)
    β†’ is-linear-map (Ξ» x β†’ - f x) (M .snd) (N .snd)
  neg-is-linear-map {f = f} fp .linear r s t =
    - f (r ⋆ s + t)        β‰‘βŸ¨ ap -_ (fp .linear r s t) βŸ©β‰‘
    - (r ⋆ f s + f t)      β‰‘βŸ¨ neg-comm βˆ™ +-comm _ _ βŸ©β‰‘
    - (r ⋆ f s) + - (f t)  β‰‘βŸ¨ apβ‚‚ _+_ (sym (Module-on.⋆-invr (N .snd))) refl βŸ©β‰‘
    r ⋆ - f s + - f t      ∎

  0-is-linear-map : is-linear-map (Ξ» x β†’ 0g) (M .snd) (N .snd)
  0-is-linear-map .linear r s t = sym (+-idr βˆ™ Module-on.⋆-idr (N .snd))

Finally, if the base ring is commutative, then linear maps are also closed under pointwise scalar multiplication:

  ⋆-is-linear-map
    : βˆ€ {f : ⌞ M ⌟ β†’ ⌞ N ⌟} {r : ⌞ R ⌟}
    β†’ is-commutative-ring R
    β†’ is-linear-map f (M .snd) (N .snd)
    β†’ is-linear-map (Ξ» x β†’ r ⋆ f x) (M .snd) (N .snd)
  ⋆-is-linear-map {f = f} {r} cring fp .linear s x y =
    r ⋆ f (s ⋆ x + y)      β‰‘βŸ¨ ap (r ⋆_) (fp .linear _ _ _) βŸ©β‰‘
    r ⋆ (s ⋆ f x + f y)    β‰‘βŸ¨ ⋆-distribl r (s ⋆ f x) (f y) βŸ©β‰‘
    r ⋆ s ⋆ f x + r ⋆ f y  β‰‘βŸ¨ ap (_+ r ⋆ f y) (⋆-assoc _ _ _ βˆ™ ap (_⋆ f x) cring βˆ™ sym (⋆-assoc _ _ _)) βŸ©β‰‘
    s ⋆ r ⋆ f x + r ⋆ f y  ∎
  Linear-map-group : Abelian-group (β„“ βŠ” β„“m βŠ” β„“n)
  ∣ Linear-map-group .fst ∣ = Linear-map M N
  Linear-map-group .fst .is-tr = Linear-map-is-set R
  Linear-map-group .snd = to-abelian-group-on grp where
    grp : make-abelian-group (Linear-map M N)
    grp .ab-is-set = Linear-map-is-set R

    grp .mul f g .map x = f .map x + g .map x
    grp .mul f g .lin = +-is-linear-map (f .lin) (g .lin)

    grp .inv f .map x = - f .map x
    grp .inv f .lin = neg-is-linear-map (f .lin)

    grp .1g .map x = 0g
    grp .1g .lin = 0-is-linear-map

    grp .idl f       = ext Ξ» x β†’ +-idl
    grp .assoc f g h = ext Ξ» x β†’ +-assoc
    grp .invl f      = ext Ξ» x β†’ +-invl
    grp .comm f g    = ext Ξ» x β†’ +-comm _ _

module _ (cring : is-commutative-ring R) {β„“m β„“n} (M : Module R β„“m) (N : Module R β„“n) where
  private instance
    _ = module-notation M
    _ = module-notation N

  Action-on-hom : Ring-action R (Linear-map-group M N .snd)
  Action-on-hom .Ring-action._⋆_ r f .map z = r ⋆ f .map z
  Action-on-hom .Ring-action._⋆_ r f .lin = ⋆-is-linear-map M N cring (f .lin)
  Action-on-hom .Ring-action.⋆-distribl f g h = ext Ξ» x β†’ ⋆-distribl _ _ _
  Action-on-hom .Ring-action.⋆-distribr f g h = ext Ξ» x β†’ ⋆-distribr _ _ _
  Action-on-hom .Ring-action.⋆-assoc f g h = ext Ξ» x β†’ ⋆-assoc _ _ _
  Action-on-hom .Ring-action.⋆-id f = ext Ξ» x β†’ ⋆-id _

  Hom-Mod : Module R (level-of ⌞ R ⌟ βŠ” β„“m βŠ” β„“n)
  Hom-Mod .fst = Action→Module R (Linear-map-group M N) Action-on-hom .fst
  Hom-Mod .snd = Action→Module R (Linear-map-group M N) Action-on-hom .snd

Since we’ve essentially equipped the set of linear maps with an structure, which certainly includes an abelian group structure, we can conclude that is not only a category, but an to boot!

R-Mod-ab-category : βˆ€ {β„“'} β†’ Ab-category (R-Mod R β„“')

Finite biproductsπŸ”—

Let’s now prove that is a preadditive category. This is exactly as in The zero object is the zero group, equipped with its unique choice of structure, and direct products are given by direct products of the underlying groups with the canonical choice of structure.

The zero object is simple, because the unit type is so well-behaved2 when it comes to definitional equality: Everything is constantly the unit, including the paths, which are all reflexivity.

R-Mod-is-additive : βˆ€ {β„“} β†’ is-additive (R-Mod R β„“)
R-Mod-is-additive .has-ab = R-Mod-ab-category
R-Mod-is-additive .has-terminal = term where
  act : Ring-action R _
  act .Ring-action._⋆_ r _          = lift tt
  act .Ring-action.⋆-distribl r x y = refl
  act .Ring-action.⋆-distribr r x y = refl
  act .Ring-action.⋆-assoc r s x    = refl
  act .Ring-action.⋆-id x           = refl

  βˆ…α΄Ή : Module R _
  βˆ…α΄Ή = Actionβ†’Module R (Ab-is-additive .has-terminal .Terminal.top) act

  term : Terminal (R-Mod R _)
  term .Terminal.top = βˆ…α΄Ή
  term .Terminal.has⊀ x .centre .hom _ = lift tt
  term .Terminal.has⊀ x .centre .preserves .linear r s t = refl
  term .Terminal.has⊀ x .paths r = trivial!

For the direct products, on the other hand, we have to do a bit more work. Like we mentioned before, the direct product of modules is built on the direct product of abelian groups (which is, in turn, built on the Cartesian product of types). The module action, and its laws, are defined pointwise using the structures of and

R-Mod-is-additive .has-prods M N = prod where
  module P = Product (Ab-is-additive .has-prods
    (M .fst , Module-on→Abelian-group-on (M .snd))
    (N .fst , Module-on→Abelian-group-on (N .snd)))

  instance
    _ = module-notation M
    _ = module-notation N

  act : Ring-action R _
  act .Ring-action._⋆_ r (a , b)    = r ⋆ a , r ⋆ b
  act .Ring-action.⋆-distribl r x y = apβ‚‚ _,_ (⋆-distribl _ _ _) (⋆-distribl _ _ _)
  act .Ring-action.⋆-distribr r x y = apβ‚‚ _,_ (⋆-distribr _ _ _) (⋆-distribr _ _ _)
  act .Ring-action.⋆-assoc r s x    = apβ‚‚ _,_ (⋆-assoc _ _ _) (⋆-assoc _ _ _)
  act .Ring-action.⋆-id x           = apβ‚‚ _,_ (⋆-id _) (⋆-id _)

  MβŠ•α΅£N : Module R _
  MβŠ•α΅£N = Actionβ†’Module R P.apex act

We can readily define the universal cone: The projection maps are the projection maps of the underlying type, which are definitionally linear. Proving that this cone is actually universal involves a bit of path-mangling, but it’s nothing too bad:

  open Product
  open is-product

  prod : Product (R-Mod _ _) M N
  prod .apex = MβŠ•α΅£N
  prod .π₁ .hom = fst
  prod .π₁ .preserves .linear r s t = refl
  prod .Ο€β‚‚ .hom = snd
  prod .Ο€β‚‚ .preserves .linear r s t = refl
  prod .has-is-product .⟨_,_⟩ f g .hom x = f # x , g # x
  prod .has-is-product .⟨_,_⟩ f g .preserves .linear r m s =
    Ξ£-pathp (f .preserves .linear _ _ _) (g .preserves .linear _ _ _)
  prod .has-is-product .Ο€β‚βˆ˜βŸ¨βŸ© = trivial!
  prod .has-is-product .Ο€β‚‚βˆ˜βŸ¨βŸ© = trivial!
  prod .has-is-product .unique p q = ext Ξ» x β†’ p #β‚š x ,β‚š q #β‚š x

  1. if you don’t have a favourite ring, just pick the integers, they’re fine.β†©οΈŽ

  2. and Lift types, tooβ†©οΈŽ