doc-next-gen

Mathlib.LinearAlgebra.FreeModule.Basic

Module docstring

{"# Free modules

We introduce a class Module.Free R M, for R a Semiring and M an R-module and we provide several basic instances for this class.

Use Finsupp.linearCombination_id_surjective to prove that any module is the quotient of a free module.

Main definition

  • Module.Free R M : the class of free R-modules. "}
Module.Free structure
(R : Type u) (M : Type v) [Semiring R] [AddCommMonoid M] [Module R M]
Full source
/-- `Module.Free R M` is the statement that the `R`-module `M` is free. -/
class Free (R : Type u) (M : Type v) [Semiring R] [AddCommMonoid M] [Module R M] : Prop where
  exists_basis (R M) : Nonempty <| (I : Type v) × Basis I R M
Free Module
Informal description
The structure `Module.Free R M` represents the property that the module `M` over the semiring `R` is free, meaning there exists a basis for `M` as an `R`-module.
Module.free_def theorem
[Small.{w, v} M] : Free R M ↔ ∃ I : Type w, Nonempty (Basis I R M)
Full source
/-- If `M` fits in universe `w`, then freeness is equivalent to existence of a basis in that
universe.

Note that if `M` does not fit in `w`, the reverse direction of this implication is still true as
`Module.Free.of_basis`. -/
theorem free_def [Small.{w, v} M] : FreeFree R M ↔ ∃ I : Type w, Nonempty (Basis I R M) where
  mp h :=
    ⟨Shrink (Set.range h.exists_basis.some.2),
      ⟨(Basis.reindexRange h.exists_basis.some.2).reindex (equivShrink _)⟩⟩
  mpr h := ⟨(nonempty_sigma.2 h).map fun ⟨_, b⟩ => ⟨Set.range b, b.reindexRange⟩⟩
Characterization of Free Modules via Existence of Basis in Small Universe
Informal description
Let $R$ be a semiring and $M$ an $R$-module that is $w$-small (i.e., there exists a bijection between $M$ and some type in universe $w$). Then $M$ is a free $R$-module if and only if there exists a type $I$ in universe $w$ and a basis for $M$ indexed by $I$.
Module.Free.of_basis theorem
{ι : Type w} (b : Basis ι R M) : Free R M
Full source
theorem Free.of_basis {ι : Type w} (b : Basis ι R M) : Free R M :=
  (free_def R M).2 ⟨Set.range b, ⟨b.reindexRange⟩⟩
Existence of Basis Implies Module is Free
Informal description
Given a module $M$ over a semiring $R$ and a basis $b$ indexed by a type $\iota$, the module $M$ is free over $R$.
Module.Free.ChooseBasisIndex definition
: Type _
Full source
/-- If `Module.Free R M` then `ChooseBasisIndex R M` is the `ι` which indexes the basis
  `ι → M`. Note that this is defined such that this type is finite if `R` is trivial. -/
def ChooseBasisIndex : Type _ :=
  ((Module.free_iff_set R M).mp ‹_›).choose
Indexing type for basis of a free module
Informal description
Given a free module $M$ over a semiring $R$, the type `ChooseBasisIndex R M` is the indexing type $\iota$ for which there exists a basis $\iota \to M$ of $M$ as an $R$-module. This type is constructed such that it is finite when $R$ is the trivial ring.
Module.Free.instDecidableEqChooseBasisIndex instance
: DecidableEq (ChooseBasisIndex R M)
Full source
/-- There is no hope of computing this, but we add the instance anyway to avoid fumbling with
`open scoped Classical`. -/
noncomputable instance : DecidableEq (ChooseBasisIndex R M) := Classical.decEq _
Decidability of Equality on Basis Indices for Free Modules
Informal description
For any free module $M$ over a semiring $R$, the equality relation on the basis indexing type $\text{ChooseBasisIndex}\, R\, M$ is decidable.
Module.Free.chooseBasis definition
: Basis (ChooseBasisIndex R M) R M
Full source
/-- If `Module.Free R M` then `chooseBasis : ι → M` is the basis.
Here `ι = ChooseBasisIndex R M`. -/
noncomputable def chooseBasis : Basis (ChooseBasisIndex R M) R M :=
  ((Module.free_iff_set R M).mp ‹_›).choose_spec.some
Basis of a free module
Informal description
Given a free module \( M \) over a semiring \( R \), the function `chooseBasis` returns a basis for \( M \) indexed by the type `ChooseBasisIndex R M`. This basis provides a linear equivalence between \( M \) and the space of finitely supported functions from the indexing type to \( R \).
Module.Free.repr definition
: M ≃ₗ[R] ChooseBasisIndex R M →₀ R
Full source
/-- The isomorphism `M ≃ₗ[R] (ChooseBasisIndex R M →₀ R)`. -/
noncomputable def repr : M ≃ₗ[R] ChooseBasisIndex R M →₀ R :=
  (chooseBasis R M).repr
Linear equivalence between a free module and its finitely supported function space
Informal description
The linear equivalence between a free module \( M \) over a semiring \( R \) and the space of finitely supported functions from the basis indexing type \( \text{ChooseBasisIndex}\, R\, M \) to \( R \). This isomorphism is induced by the chosen basis of \( M \).
Module.Free.constr definition
{S : Type z} [Semiring S] [Module S N] [SMulCommClass R S N] : (ChooseBasisIndex R M → N) ≃ₗ[S] M →ₗ[R] N
Full source
/-- The universal property of free modules: giving a function `(ChooseBasisIndex R M) → N`, for `N`
an `R`-module, is the same as giving an `R`-linear map `M →ₗ[R] N`.

This definition is parameterized over an extra `Semiring S`,
such that `SMulCommClass R S M'` holds.
If `R` is commutative, you can set `S := R`; if `R` is not commutative,
you can recover an `AddEquiv` by setting `S := ℕ`.
See library note [bundled maps over different rings]. -/
noncomputable def constr {S : Type z} [Semiring S] [Module S N] [SMulCommClass R S N] :
    (ChooseBasisIndex R M → N) ≃ₗ[S] M →ₗ[R] N :=
  Basis.constr (chooseBasis R M) S
Universal property of free modules: linear map construction from basis vectors
Informal description
Given a free module \( M \) over a semiring \( R \), an extra semiring \( S \), and an \( S \)-module \( N \) with commuting scalar actions of \( R \) and \( S \) on \( N \), the function `Module.Free.constr` provides a linear equivalence between the space of functions from the basis indexing set \( \text{ChooseBasisIndex}\, R\, M \) to \( N \) and the space of \( R \)-linear maps from \( M \) to \( N \). Specifically, for any function \( f : \text{ChooseBasisIndex}\, R\, M \to N \), the linear map `Module.Free.constr f` sends each basis vector \( b(i) \) to \( f(i) \), and extends linearly to all of \( M \).
Module.Free.noZeroSMulDivisors instance
[NoZeroDivisors R] : NoZeroSMulDivisors R M
Full source
instance (priority := 100) noZeroSMulDivisors [NoZeroDivisors R] : NoZeroSMulDivisors R M :=
  let ⟨⟨_, b⟩⟩ := exists_basis (R := R) (M := M)
  b.noZeroSMulDivisors
Free Modules over Rings without Zero Divisors have No Zero Scalar Divisors
Informal description
For any semiring $R$ with no zero divisors and any free $R$-module $M$, the module $M$ has no zero scalar divisors. That is, for any $c \in R$ and $x \in M$, if $c \cdot x = 0$, then $c = 0$ or $x = 0$.
Module.Free.instFaithfulSMulOfNontrivial instance
[Module.Free R M] [Nontrivial M] : FaithfulSMul R M
Full source
instance [Module.Free R M] [Nontrivial M] : FaithfulSMul R M :=
  .of_injective _ (Module.Free.repr R M).symm.injective
Faithful Scalar Multiplication on Nontrivial Free Modules
Informal description
For any nontrivial free module $M$ over a semiring $R$, the scalar multiplication action of $R$ on $M$ is faithful. That is, distinct elements of $R$ act differently on $M$.
Module.Free.of_equiv theorem
(e : M ≃ₗ[R] N) : Module.Free R N
Full source
theorem of_equiv (e : M ≃ₗ[R] N) : Module.Free R N :=
  of_basis <| (chooseBasis R M).map e
Linear Equivalence Preserves Free Module Property
Informal description
If $M$ is a free module over a semiring $R$ and there exists a linear equivalence $e : M \simeq_{R} N$ between $M$ and another $R$-module $N$, then $N$ is also a free $R$-module.
Module.Free.of_equiv' theorem
{P : Type v} [AddCommMonoid P] [Module R P] (_ : Module.Free R P) (e : P ≃ₗ[R] N) : Module.Free R N
Full source
/-- A variation of `of_equiv`: the assumption `Module.Free R P` here is explicit rather than an
instance. -/
theorem of_equiv' {P : Type v} [AddCommMonoid P] [Module R P] (_ : Module.Free R P)
    (e : P ≃ₗ[R] N) : Module.Free R N :=
  of_equiv e
Free Module Property via Explicit Linear Equivalence
Informal description
Let $P$ and $N$ be modules over a semiring $R$, with $P$ being a free $R$-module. If there exists a linear equivalence $e : P \simeq_R N$ between $P$ and $N$, then $N$ is also a free $R$-module.
Module.Free.of_ringEquiv theorem
{R R' M M'} [Semiring R] [AddCommMonoid M] [Module R M] [Semiring R'] [AddCommMonoid M'] [Module R' M'] (e₁ : R ≃+* R') (e₂ : M ≃ₛₗ[RingHomClass.toRingHom e₁] M') [Module.Free R M] : Module.Free R' M'
Full source
lemma of_ringEquiv {R R' M M'} [Semiring R] [AddCommMonoid M] [Module R M]
    [Semiring R'] [AddCommMonoid M'] [Module R' M']
    (e₁ : R ≃+* R') (e₂ : M ≃ₛₗ[RingHomClass.toRingHom e₁] M') [Module.Free R M] :
    Module.Free R' M' := by
  let I := Module.Free.ChooseBasisIndex R M
  obtain ⟨e₃ : M ≃ₗ[R] I →₀ R⟩ := Module.Free.chooseBasis R M
  let e : M' ≃+ (I →₀ R') :=
    (e₂.symm.trans e₃).toAddEquiv.trans (Finsupp.mapRange.addEquiv (α := I) e₁.toAddEquiv)
  have he (x) : e x = Finsupp.mapRange.addEquiv (α := I) e₁.toAddEquiv (e₃ (e₂.symm x)) := rfl
  let e' : M' ≃ₗ[R'] (I →₀ R') :=
    { __ := e, map_smul' := fun m x ↦ Finsupp.ext fun i ↦ by simp [he, map_smulₛₗ] }
  exact of_basis (.ofRepr e')
Preservation of Free Modules under Ring Equivalence and Semilinear Equivalence
Informal description
Let $R$ and $R'$ be semirings, and let $M$ and $M'$ be modules over $R$ and $R'$ respectively. Given a ring equivalence $e₁: R ≃+* R'$ and a semilinear equivalence $e₂: M ≃ₛₗ[e₁] M'$, if $M$ is a free $R$-module, then $M'$ is a free $R'$-module. Here, $e₂$ being semilinear means it satisfies $e₂(r • x) = e₁(r) • e₂(x)$ for all $r ∈ R$ and $x ∈ M$.
Module.Free.iff_of_ringEquiv theorem
{R R' M M'} [Semiring R] [AddCommMonoid M] [Module R M] [Semiring R'] [AddCommMonoid M'] [Module R' M'] (e₁ : R ≃+* R') (e₂ : M ≃ₛₗ[RingHomClass.toRingHom e₁] M') : Module.Free R M ↔ Module.Free R' M'
Full source
lemma iff_of_ringEquiv {R R' M M'} [Semiring R] [AddCommMonoid M] [Module R M]
    [Semiring R'] [AddCommMonoid M'] [Module R' M']
    (e₁ : R ≃+* R') (e₂ : M ≃ₛₗ[RingHomClass.toRingHom e₁] M') :
    Module.FreeModule.Free R M ↔ Module.Free R' M' :=
  ⟨fun _ ↦ of_ringEquiv e₁ e₂, fun _ ↦ of_ringEquiv e₁.symm e₂.symm⟩
Free Module Property is Preserved under Ring and Semilinear Equivalence
Informal description
Let $R$ and $R'$ be semirings, and let $M$ and $M'$ be modules over $R$ and $R'$ respectively. Given a ring equivalence $e₁: R \simeq R'$ and a semilinear equivalence $e₂: M \simeq M'$ (where $e₂$ satisfies $e₂(r \cdot x) = e₁(r) \cdot e₂(x)$ for all $r \in R$ and $x \in M$), then $M$ is a free $R$-module if and only if $M'$ is a free $R'$-module.
Module.Free.self instance
: Module.Free R R
Full source
/-- The module structure provided by `Semiring.toModule` is free. -/
instance self : Module.Free R R :=
  of_basis (Basis.singleton Unit R)
The Free Module Structure on a Semiring
Informal description
For any semiring $R$, the module structure on $R$ itself (where the action is given by multiplication in $R$) is free. This means there exists a basis for $R$ as an $R$-module, which can be taken to be the singleton set $\{1\}$.
Module.Free.ulift instance
[Free R M] : Free R (ULift M)
Full source
instance ulift [Free R M] : Free R (ULift M) := of_equiv ULift.moduleEquiv.symm
Free Module Property Preserved Under Lifting
Informal description
For any free module $M$ over a semiring $R$, the lifted module $\mathrm{ULift}\, M$ is also free.
Module.Free.of_subsingleton instance
[Subsingleton N] : Module.Free R N
Full source
instance (priority := 100) of_subsingleton [Subsingleton N] : Module.Free R N :=
  of_basis.{u,z,z} (Basis.empty N : Basis PEmpty R N)
Subsingleton Modules are Free
Informal description
For any semiring $R$ and any $R$-module $N$ that is a subsingleton (i.e., has at most one element), $N$ is a free $R$-module.
Module.Free.of_subsingleton' instance
[Subsingleton R] : Module.Free R N
Full source
instance (priority := 100) of_subsingleton' [Subsingleton R] : Module.Free R N :=
  letI := Module.subsingleton R N
  Module.Free.of_subsingleton R N
Free Module Structure on Modules over Subsingleton Semirings
Informal description
For any semiring $R$ that is a subsingleton (i.e., has at most one element) and any $R$-module $N$, $N$ is a free $R$-module.
Basis.repr_algebraMap theorem
{ι : Type*} [DecidableEq ι] {B : Basis ι R S} {i : ι} (hBi : B i = 1) (r : R) : B.repr ((algebraMap R S) r) = fun j : ι ↦ if i = j then r else 0
Full source
/-- If `B` is a basis of the `R`-algebra `S` such that `B i = 1` for some index `i`, then
each `r : R` gets represented as `s • B i` as an element of `S`. -/
theorem repr_algebraMap {ι : Type*} [DecidableEq ι] {B : Basis ι R S} {i : ι} (hBi : B i = 1)
    (r : R) : B.repr ((algebraMap R S) r) = fun j : ι ↦ if i = j then r else 0 := by
  ext j
  rw [Algebra.algebraMap_eq_smul_one, map_smul, ← hBi, Finsupp.smul_apply, B.repr_self_apply]
  simp
Coordinate Representation of Algebra Map in Basis with Unit Vector
Informal description
Let $S$ be an $R$-algebra with a basis $B$ indexed by a type $\iota$, and suppose there exists an index $i \in \iota$ such that $B(i) = 1$. Then for any element $r \in R$, the coordinate representation of the algebra map $\text{algebraMap}\, R\, S\, r$ with respect to the basis $B$ is given by: \[ B.\text{repr}(\text{algebraMap}\, R\, S\, r)(j) = \begin{cases} r & \text{if } i = j, \\ 0 & \text{otherwise}, \end{cases} \] for all $j \in \iota$.