@@ -8,10 +8,13 @@ import Mathlib.Algebra.Module.Torsion
88import Mathlib.LinearAlgebra.Dual.Lemmas
99import Mathlib.RingTheory.FiniteType
1010import Mathlib.RingTheory.Flat.EquationalCriterion
11+ import Mathlib.RingTheory.Ideal.Quotient.ChineseRemainder
12+ import Mathlib.RingTheory.LocalProperties.Exactness
1113import Mathlib.RingTheory.LocalRing.ResidueField.Basic
1214import Mathlib.RingTheory.LocalRing.ResidueField.Ideal
1315import Mathlib.RingTheory.Nakayama
1416import Mathlib.RingTheory.Support
17+ import Mathlib.RingTheory.TensorProduct.Free
1518
1619/-!
1720# Finite modules over local rings
@@ -364,3 +367,59 @@ theorem IsLocalRing.split_injective_iff_lTensor_residueField_injective [IsLocalR
364367 exact Module.projective_lifting_property _ _ (Submodule.mkQ_surjective _)
365368
366369end
370+
371+ namespace Module
372+
373+ open Ideal TensorProduct Submodule
374+
375+ variable (R M) [Finite (MaximalSpectrum R)] [AddCommGroup M] [Module R M]
376+
377+ /-- If `M` is a finite flat module over a commutative semilocal ring `R` that has the same rank `n`
378+ at every maximal ideal, then `M` is free of rank `n`. -/
379+ @[stacks 02M9] theorem nonempty_basis_of_flat_of_finrank_eq [Module.Finite R M] [Flat R M]
380+ (n : ℕ) (rk : ∀ P : MaximalSpectrum R, finrank (R ⧸ P.1 ) ((R ⧸ P.1 ) ⊗[R] M) = n) :
381+ Nonempty (Basis (Fin n) R M) := by
382+ let := @Quotient.field
383+ have coprime : Pairwise fun I J : MaximalSpectrum R ↦ IsCoprime I.1 J.1 :=
384+ fun _ _ ne ↦ isCoprime_of_isMaximal (MaximalSpectrum.ext_iff.ne.mp ne)
385+ /- For every maximal ideal `P`, `R⧸P ⊗[R] M` is an `n`-dimensional vector space over the field
386+ `R⧸P` by assumption, so we can choose a basis `b' P` indexed by `Fin n`. -/
387+ have b' (P) := Module.finBasisOfFinrankEq _ _ (rk P)
388+ /- By Chinese remainder theorem for modules, there exist `n` elements `b i : M` that reduces
389+ to `b' P i` modulo each maximal ideal `P`. -/
390+ choose b hb using fun i ↦ pi_tensorProductMk_quotient_surjective M _ coprime (b' · i)
391+ /- It suffices to show `b` spans `M` and is linearly independent when localized at each
392+ maximal ideal. -/
393+ refine ⟨.mk (v := b) (.of_isLocalized_maximal (fun P _ ↦ Localization P.primeCompl) _
394+ (fun P _ ↦ TensorProduct.mk R (Localization P.primeCompl) M 1 ) _ fun P _ ↦ ?_) ?_⟩
395+ · /- Since `M` is finite flat, linear independence in `Rₚ ⊗[R] M` is equivalent to linear
396+ independence in `Rₚ⧸PRₚ ⊗[Rₚ] (Rₚ ⊗[R] M) ≃ Rₚ⧸PRₚ ⊗[R⧸P] (R⧸P ⊗[R] M)`. -/
397+ apply IsLocalRing.linearIndependent_of_flat
398+ rw [← LinearMap.linearIndependent_iff _ (AlgebraTensorModule.cancelBaseChange R _ _ _ M).ker]
399+ convert LinearMap.linearIndependent_iff _ (AlgebraTensorModule.cancelBaseChange R _ _ _ M).ker
400+ |>.mpr (Algebra.TensorProduct.basis P.ResidueField (b' ⟨P, ‹_›⟩)).linearIndependent
401+ ext
402+ simp [← funext_iff.mp (hb _)]
403+ · -- To show `b` spans `M`, it suffices to show `M = Rb + J(R)M` by Nakayama.
404+ refine Submodule.le_of_le_smul_of_le_jacobson_bot (Module.finite_def.mp ‹_›) le_rfl fun m _ ↦ ?_
405+ /- For each `m : M` and maximal ideal `P`, `1 ⊗ₜ m : R⧸P ⊗[R] M` is in the span of `b' P`.
406+ By Chinese remainder theorem for rings, we may lift the coefficients `r i : R`. -/
407+ choose r hr using fun i ↦ pi_quotient_surjective coprime fun P ↦ (b' P).repr (1 ⊗ₜ m) i
408+ rw [← add_sub_cancel (∑ i, r i • b i) m]
409+ /- It suffices to show `m - ∑ i, r i • b i` is `J(R)M`, which equals the kernel of
410+ `M → Πₚ R⧸P ⊗[R] M` by Chinese remainder theorem for modules. -/
411+ refine Submodule.add_mem_sup (sum_mem fun i _ ↦ smul_mem _ _ <| subset_span ⟨i, rfl⟩) <|
412+ ((ker_tensorProductMk_quotient M _ coprime).le.trans <| smul_mono_left <|
413+ le_sInf fun i hi ↦ iInf_le_of_le ⟨i, hi.2 ⟩ le_rfl) ?_
414+ ext P
415+ simp_rw [map_sub, map_sum, map_smul, hb, Pi.sub_apply]
416+ refine sub_eq_zero.mpr (((b' P).sum_repr _).symm.trans ?_)
417+ simp [← hr, ← Quotient.algebraMap_eq]
418+
419+ @[stacks 02M9] theorem free_of_flat_of_finrank_eq [Module.Finite R M] [Flat R M]
420+ (n : ℕ) (rk : ∀ P : MaximalSpectrum R, finrank (R ⧸ P.1 ) ((R ⧸ P.1 ) ⊗[R] M) = n) :
421+ Free R M :=
422+ have ⟨b⟩ := nonempty_basis_of_flat_of_finrank_eq R M n rk
423+ .of_basis b
424+
425+ end Module
0 commit comments