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

Free modulesπŸ”—

For a finite set of generators, we can define free modules very directly: for example, using vectors. For infinite sets, this definition does not work as well: rings do not admit infinite sums, so we would need a way to β€œtame” the vectors so only a finite amount of information needs to be summed at a time. The usual definition, of being zero in all but finitely many indices, is problematic since we can not (unless the indexing set admits decidable equality) define the map

Note: even if is not, strictly speaking, built on an underlying (sub)set of functions into we will stick to the exponential notation for definiteness.

Fortunately, free objects have a very straightforward definition in type theory: they are initial objects in certain categories of algebras, so they can be presented as1 inductive types.

data Free-mod {β„“'} (A : Type β„“') : Type (β„“ βŠ” β„“') where
  inc  : A β†’ Free-mod A

  _+_ : Free-mod A β†’ Free-mod A β†’ Free-mod A
  neg : Free-mod A β†’ Free-mod A
  0m  : Free-mod A

  _Β·_  : ⌞ R ⌟ β†’ Free-mod A β†’ Free-mod A

The free module on is generated by elements of (the inc) constructor, the operations of an Abelian group (which we write with _+_), together with a scalar multiplication operation The equations imposed are precisely those necessary to make _+_ into an abelian group, and the scalar multiplication into an action by We also add a squash constructor, since modules must have an underlying set.

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


  Β·-id       : βˆ€ x     β†’ R.1r Β· x      ≑ x
  Β·-distribl : βˆ€ x y z β†’ x Β· (y + z)   ≑ x Β· y + x Β· z
  Β·-distribr : βˆ€ x y z β†’ (x R.+ y) Β· z ≑ x Β· z + y Β· z
  Β·-assoc    : βˆ€ x y z β†’ x Β· y Β· z     ≑ (x R.* y) Β· z

  squash : is-set (Free-mod A)

In passing, we define a record to package together the data of a predicate on free modules: as long as it is prop-valued, we can prove something for all of by treating the group operations, the ring action, and the generators.

record Free-elim-prop {β„“' β„“''} {A : Type β„“'} (P : Free-mod A β†’ Type β„“'')
          : Type (β„“ βŠ” β„“' βŠ” β„“'') where
  no-eta-equality
  field
    has-is-prop : βˆ€ x β†’ is-prop (P x)
    P-0m  : P 0m
    P-neg : βˆ€ x β†’ P x β†’ P (neg x)
    P-inc : βˆ€ x β†’ P (inc x)
    P-Β·   : βˆ€ x y β†’ P y β†’ P (x Β· y)
    P-+   : βˆ€ x y β†’ P x β†’ P y β†’ P (x + y)

  elim : βˆ€ x β†’ P x
  elim (inc x) = P-inc x
  elim (x Β· y) = P-Β· x y (elim y)
  elim (x + y) = P-+ x y (elim x) (elim y)
  elim (neg x) = P-neg x (elim x)
  elim 0m = P-0m
  elim (+-comm x y i) =
    is-prop→pathp (λ j → has-is-prop (+-comm x y j))
      (P-+ x y (elim x) (elim y)) (P-+ y x (elim y) (elim x)) i
  elim (+-assoc x y z i) =
    is-prop→pathp (λ j → has-is-prop (+-assoc x y z j))
      (P-+ _ _ (elim x) (P-+ _ _ (elim y) (elim z)))
      (P-+ _ _ (P-+ _ _ (elim x) (elim y)) (elim z)) i
  elim (+-invl x i) =
    is-prop→pathp (λ j → has-is-prop (+-invl x j))
      (P-+ _ _ (P-neg _ (elim x)) (elim x)) P-0m i
  elim (+-idl x i) =
    is-prop→pathp (λ j → has-is-prop (+-idl x j))
      (P-+ _ _ P-0m (elim x)) (elim x) i
  elim (Β·-id x i)  =
    is-prop→pathp (λ j → has-is-prop (·-id x j))
      (P-Β· R.1r _ (elim x)) (elim x) i
  elim (Β·-distribl x y z i) =
    is-prop→pathp (λ j → has-is-prop (·-distribl x y z j))
      (P-Β· x _ (P-+ _ _ (elim y) (elim z)))
      (P-+ _ _ (P-Β· x _ (elim y)) (P-Β· x _ (elim z))) i
  elim (Β·-distribr x y z i) =
    is-prop→pathp (λ j → has-is-prop (·-distribr x y z j ))
      (P-Β· (x R.+ y) _ (elim z))
      (P-+ _ _ (P-Β· x _ (elim z)) (P-Β· y _ (elim z))) i
  elim (Β·-assoc x y z i) =
    is-prop→pathp (λ j → has-is-prop (·-assoc x y z j))
      (P-Β· x (y Β· z) (P-Β· y _ (elim z)))
      (P-Β· (x R.* y) z (elim z)) i
  elim (squash x y p q i j) =
    is-prop→squarep (λ i j → has-is-prop (squash x y p q i j))
      (Ξ» _ β†’ elim x) (Ξ» j β†’ elim (p j)) (Ξ» j β†’ elim (q j)) (Ξ» _ β†’ elim y) i j
I’ll leave the definition of the group, Abelian group, and structures on in this <details> tag, since they’re not particularly interesting. For every operation and law, we simply use the corresponding constructors.
open Module-on hiding (_+_)
open make-module hiding (_+_)

Module-on-free-mod
  : βˆ€ {β„“'} (A : Type β„“')
  β†’ Module-on R (Free-mod A)
Module-on-free-mod A = to-module-on mk module Module-on-free-mod where
  mk : make-module R (Free-mod A)
  mk .has-is-set = squash
  mk .make-module._+_ = _+_
  mk .inv = neg
  mk .0g = 0m
  mk .make-module.+-assoc = Free-mod.+-assoc
  mk .make-module.+-invl = Free-mod.+-invl
  mk .make-module.+-idl = Free-mod.+-idl
  mk .make-module.+-comm = Free-mod.+-comm
  mk ._⋆_ = _Β·_
  mk .⋆-distribl = Free-mod.Β·-distribl
  mk .⋆-distribr = Free-mod.Β·-distribr
  mk .⋆-assoc x y z = Free-mod.Β·-assoc x y z
  mk .⋆-id = Free-mod.Β·-id

Free-Mod : βˆ€ {β„“'} β†’ Type β„“' β†’ Module R (β„“ βŠ” β„“')
Free-Mod T = to-module (Module-on-free-mod.mk T)

open Functor
fold-free-mod
  : βˆ€ {β„“ β„“'} {A : Type β„“} (N : Module R β„“')
  β†’ (A β†’ ⌞ N ⌟)
  β†’ Linear-map (Free-Mod A) N
fold-free-mod {A = A} N f = go-linear module fold-free-mod where
  private module N = Module-on (N .snd)

The endless constructors of Free-mod are powerless in the face of a function from the generators into the underlying type of an actual Each operation is mapped to the corresponding operation on so the path constructors are also handled by the witnesses that is an actual module. This function, annoying though it may be to write, is definitionally a linear map β€” saving us a bit of effort.

  -- Rough:
  go : Free-mod A β†’ ⌞ N ⌟
  go (inc x) = f x
  go (x Β· y) = x N.⋆ go y
  go (x + y) = go x N.+ go y
  go (neg x) = N.- (go x)
  go 0m      = N.0g
  go (+-comm x y i)       = N.+-comm {go x} {go y} i
  go (+-assoc x y z i)    = N.+-assoc {go x} {go y} {go z} i
  go (+-invl x i)         = N.+-invl {go x} i
  go (+-idl x i)          = N.+-idl {go x} i
  go (Β·-id x i)           = N.⋆-id (go x) i
  go (Β·-distribl x y z i) = N.⋆-distribl x (go y) (go z) i
  go (Β·-distribr x y z i) = N.⋆-distribr x y (go z) i
  go (Β·-assoc x y z i)    = N.⋆-assoc x y (go z) i
  go (squash a b p q i j) =
    N.has-is-set (go a) (go b) (Ξ» i β†’ go (p i)) (Ξ» i β†’ go (q i)) i j

  go-linear : Linear-map (Free-Mod A) N
  go-linear .map = go
  go-linear .lin .linear r s t = refl

{-# DISPLAY fold-free-mod.go = fold-free-mod #-}
{-# DISPLAY fold-free-mod.go-linear = fold-free-mod #-}

To prove that free modules have the expected universal property, it remains to show that if then Since we’re eliminating into a proposition, all we have to handle are the operation constructors, which is.. inductive, but manageable. I’ll leave the computation here if you’re interested:

make-free-module : βˆ€ {β„“'} (S : Set (β„“ βŠ” β„“')) β†’ Free-object (R-Modβ†ͺSets R (β„“ βŠ” β„“')) S
make-free-module {β„“' = β„“'} S = go where
  open Free-object

  go : Free-object (R-Modβ†ͺSets R (β„“ βŠ” β„“')) S
  go .free = Free-Mod ⌞ S ⌟
  go .unit = inc
  go .fold {b} f = linear-map→hom (fold-free-mod b f)
  go .commute = refl
  go .unique {M} {f} g p = reext! p

After that calculation, we can ✨ just ✨ conclude that Free-module has the right universal property: that is, we can rearrange the proof above into the form of a functor and an adjunction.

Free-module : βˆ€ {β„“'} β†’ Functor (Sets (β„“ βŠ” β„“')) (R-Mod R (β„“ βŠ” β„“'))
Free-module {ℓ' = ℓ'} = free-objects→functor (make-free-module {ℓ' = ℓ'})

Free⊣Forget : βˆ€ {β„“'} β†’ Free-module {β„“'} ⊣ R-Modβ†ͺSets R (β„“ βŠ” β„“')
Free⊣Forget {β„“'} = free-objectsβ†’left-adjoint (make-free-module {β„“' = β„“'})
equal-on-basis'
  : βˆ€ {β„“b β„“g} {T : Type β„“b} {G : Type β„“g} (M : Module-on R G)
  β†’ (let module M = Module-on M)
  β†’ {f : Free-mod T β†’ G}
  β†’ (βˆ€ r x y β†’ f (r Β· x + y) ≑ r M.⋆ f x M.+ f y)
  β†’ {g : Free-mod T β†’ G}
  β†’ (βˆ€ r x y β†’ g (r Β· x + y) ≑ r M.⋆ g x M.+ g y)
  β†’ ((x : T) β†’ f (inc x) ≑ g (inc x))
  β†’ f ≑ g
equal-on-basis' M l1 l2 p = ap map $
  equal-on-basis (el _ (Module-on.has-is-set M) , M)
    {f = record { lin = record { linear = l1 } }}
    {g = record { lin = record { linear = l2 } }}
    p

module _ (cring : is-commutative-ring R) where
  open Algebra.Ring.Module.Multilinear R cring

  multilinear-extension
    : βˆ€ {n} {β„“β‚™}
      {β„“β‚˜ : Fin (suc n) β†’ Level} {Ms : (i : Fin (suc n)) β†’ Type (β„“β‚˜ i)} {N : Module R β„“β‚™}
    β†’ (f : ArrαΆ  Ms ⌞ N ⌟)
    β†’ Multilinear-map (suc n) (Ξ» i β†’ Free-Mod (Ms i)) N
  multilinear-extension {zero} {N = N} f = 1-linear-map (fold-free-mod N f)
  multilinear-extension {suc n} f = Uncurry.from $
    fold-free-mod _ Ξ» x β†’ multilinear-extension (f x)

  multi-equal-on-bases
    : βˆ€ {n} {β„“β‚™} {β„“β‚˜ : Fin n β†’ Level} {Ms : (i : Fin n) β†’ Type (β„“β‚˜ i)} {N : Module R β„“β‚™}
    β†’ {f g : Multilinear-map n (Ξ» i β†’ Free-Mod (Ms i)) N}
    β†’ (βˆ€ (as : Ξ αΆ  Ms) β†’ applyαΆ  (f .map) (mapβ‚š (Ξ» _ β†’ inc) as) ≑ applyαΆ  (g .map) (mapβ‚š (Ξ» _ β†’ inc) as))
    β†’ f ≑ g
  multi-equal-on-bases {n = zero} p = Multilinear-map-path (p tt)
  multi-equal-on-bases {n = suc n} {f = f} {g} p =
    Uncurry.injective $ equal-on-basis _ Ξ» x β†’
      multi-equal-on-bases Ξ» as β†’
        p (x , as)

  1. truncated, higherβ†©οΈŽ