Skip to content

Commit 58a8e4f

Browse files
committed
chore(RingTheory): clean up code (leanprover-community#34360)
Utilise opened namespaces where available, spell out projections, style, shorten proofs. No new definitions/theorems. Co-authored-by: LLaurance <laurancelau.2022@berkeley.edu>
1 parent 3fa53c5 commit 58a8e4f

3 files changed

Lines changed: 95 additions & 111 deletions

File tree

Mathlib/RingTheory/Finiteness/Basic.lean

Lines changed: 54 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ theorem fg_span_singleton (x : M) : FG (R ∙ x) :=
4141
fg_span (finite_singleton x)
4242

4343
theorem FG.sup {N₁ N₂ : Submodule R M} (hN₁ : N₁.FG) (hN₂ : N₂.FG) : (N₁ ⊔ N₂).FG :=
44-
let ⟨t₁, ht₁⟩ := fg_def.1 hN₁
45-
let ⟨t₂, ht₂⟩ := fg_def.1 hN₂
46-
fg_def.2 ⟨t₁ ∪ t₂, ht₁.1.union ht₂.1, by rw [span_union, ht₁.2, ht₂.2]⟩
44+
let ⟨t₁, ht₁, span_t₁⟩ := fg_def.mp hN₁
45+
let ⟨t₂, ht₂, span_t₂⟩ := fg_def.mp hN₂
46+
fg_def.mpr ⟨t₁ ∪ t₂, ht₁.union ht₂, by rw [span_union, span_t₁, span_t₂]⟩
4747

4848
theorem fg_finset_sup {ι : Type*} (s : Finset ι) (N : ι → Submodule R M) (h : ∀ i ∈ s, (N i).FG) :
4949
(s.sup N).FG :=
@@ -75,18 +75,18 @@ variable {σ : R →+* S} [RingHomSurjective σ] (f : M →ₛₗ[σ] P)
7575

7676
theorem fg_pi {ι : Type*} {M : ι → Type*} [Finite ι] [∀ i, AddCommMonoid (M i)]
7777
[∀ i, Module R (M i)] {p : ∀ i, Submodule R (M i)} (hsb : ∀ i, (p i).FG) :
78-
(Submodule.pi Set.univ p).FG := by
78+
(pi Set.univ p).FG := by
7979
classical
8080
simp_rw [fg_def] at hsb ⊢
8181
choose t htf hts using hsb
8282
refine
8383
⟨⋃ i, (LinearMap.single R _ i) '' t i, Set.finite_iUnion fun i => (htf i).image _, ?_⟩
8484
-- Note: https://github.com/leanprover-community/mathlib4/pull/8386 changed `span_image` into `span_image _`
85-
simp_rw [span_iUnion, span_image _, hts, Submodule.iSup_map_single]
85+
simp_rw [span_iUnion, span_image _, hts, iSup_map_single]
8686

8787
theorem FG.map {N : Submodule R M} (hs : N.FG) : (N.map f).FG :=
88-
let ⟨t, ht⟩ := fg_def.1 hs
89-
fg_def.2 ⟨f '' t, ht.1.image _, by rw [span_image, ht.2]⟩
88+
let ⟨t, ht, span_t⟩ := fg_def.mp hs
89+
fg_def.mpr ⟨f '' t, ht.image _, by rw [span_image, span_t]⟩
9090

9191
/-- Maps from a finite module have a finite range. -/
9292
@[simp] lemma fg_range [Module.Finite R M] (f : M →ₛₗ[σ] P) : f.range.FG := by
@@ -97,7 +97,7 @@ theorem fg_of_fg_map_injective (hf : Function.Injective f) {N : Submodule R M}
9797
(hfn : (N.map f).FG) : N.FG :=
9898
let ⟨t, ht⟩ := hfn
9999
⟨t.preimage f fun _ _ _ _ h => hf h,
100-
Submodule.map_injective_of_injective hf <| by
100+
map_injective_of_injective hf <| by
101101
rw [map_span, Finset.coe_preimage, Set.image_preimage_eq_inter_range,
102102
Set.inter_eq_self_of_subset_left, ht]
103103
rw [← LinearMap.coe_range, ← span_le, ht, ← map_top]
@@ -113,10 +113,9 @@ variable {P : Type*} [AddCommMonoid P] [Module R P]
113113
variable {f : M →ₗ[R] P}
114114

115115
theorem fg_of_fg_map {R M P : Type*} [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup P]
116-
[Module R P] (f : M →ₗ[R] P)
117-
(hf : LinearMap.ker f = ⊥) {N : Submodule R M}
116+
[Module R P] (f : M →ₗ[R] P) (hf : LinearMap.ker f = ⊥) {N : Submodule R M}
118117
(hfn : (N.map f).FG) : N.FG :=
119-
fg_of_fg_map_injective f (LinearMap.ker_eq_bot.1 hf) hfn
118+
fg_of_fg_map_injective f (LinearMap.ker_eq_bot.mp hf) hfn
120119

121120
/-- The top submodule of another submodule `N` is FG iff `N` is `FG`.
122121
@@ -135,10 +134,10 @@ theorem fg_induction (R M : Type*) [Semiring R] [AddCommMonoid M] [Module R M]
135134
obtain ⟨s, rfl⟩ := hN
136135
induction s using Finset.induction with
137136
| empty =>
138-
rw [Finset.coe_empty, Submodule.span_empty, ← Submodule.span_zero_singleton]
137+
rw [Finset.coe_empty, span_empty, ← span_zero_singleton]
139138
exact h₁ _
140139
| insert _ _ _ ih =>
141-
rw [Finset.coe_insert, Submodule.span_insert]
140+
rw [Finset.coe_insert, span_insert]
142141
exact h₂ _ _ (h₁ _) ih
143142

144143
section RestrictScalars
@@ -159,31 +158,26 @@ theorem FG.of_restrictScalars (R) [Semiring R] [Module R M] [SMul R A] [IsScalar
159158
(hS : (S.restrictScalars R).FG) : S.FG := by
160159
obtain ⟨s, e⟩ := hS
161160
refine ⟨s, restrictScalars_injective R _ _ (le_antisymm ?_ ?_)⟩
162-
· change span A s ≤ S
163-
have := span_le.mp e.le
164-
rwa [span_le]
161+
· have := span_le.mp e.le
162+
rwa [restrictScalars_le, span_le]
165163
· rw [← e]
166-
exact span_le_restrictScalars _ _ _
164+
exact span_le_restrictScalars ..
167165

168166
end RestrictScalars
169167

170168
theorem FG.stabilizes_of_iSup_eq {M' : Submodule R M} (hM' : M'.FG) (N : ℕ →o Submodule R M)
171169
(H : iSup N = M') : ∃ n, M' = N n := by
172170
obtain ⟨S, hS⟩ := hM'
173-
have : ∀ s : S, ∃ n, (s : M) ∈ N n := fun s =>
174-
(Submodule.mem_iSup_of_chain N s).mp
175-
(by
176-
rw [H, ← hS]
177-
exact Submodule.subset_span s.2)
171+
have (s : S) : ∃ n, (s : M) ∈ N n :=
172+
(mem_iSup_of_chain N s).mp (by simpa [H, ← hS] using subset_span s.prop)
178173
choose f hf using this
179174
use S.attach.sup f
180175
apply le_antisymm
181-
· conv_lhs => rw [← hS]
182-
rw [Submodule.span_le]
176+
· rw [← hS, span_le]
183177
intro s hs
184-
exact N.2 (Finset.le_sup <| S.mem_attach ⟨s, hs⟩) (hf _)
178+
exact N.monotone' (Finset.le_sup <| S.mem_attach ⟨s, hs⟩) (hf _)
185179
· rw [← H]
186-
exact le_iSup _ _
180+
exact le_iSup ..
187181

188182
/-- Finitely generated submodules are precisely compact elements in the submodule lattice. -/
189183
theorem fg_iff_compact (s : Submodule R M) : s.FG ↔ IsCompactElement s := by
@@ -194,7 +188,7 @@ theorem fg_iff_compact (s : Submodule R M) : s.FG ↔ IsCompactElement s := by
194188
have supr_rw : ∀ t : Finset M, ⨆ x ∈ t, sp x = ⨆ x ∈ (↑t : Set M), sp x := fun t => by rfl
195189
constructor
196190
· rintro ⟨t, rfl⟩
197-
rw [span_eq_iSup_of_singleton_spans, ← supr_rw, ← Finset.sup_eq_iSup t sp]
191+
rw [span_eq_iSup_of_singleton_spans, ← supr_rw, ← t.sup_eq_iSup sp]
198192
apply CompleteLattice.isCompactElement_finsetSup
199193
exact fun n _ => singleton_span_isCompactElement n
200194
· intro h
@@ -209,8 +203,8 @@ theorem fg_iff_compact (s : Submodule R M) : s.FG ↔ IsCompactElement s := by
209203
rw [sSup', Finset.sup_id_eq_sSup]
210204
exact sSup_le_sSup huspan
211205
obtain ⟨t, -, rfl⟩ := Finset.subset_set_image_iff.mp huspan
212-
rw [Finset.sup_image, Function.id_comp, Finset.sup_eq_iSup, supr_rw,
213-
span_eq_iSup_of_singleton_spans, eq_comm] at ssup
206+
rw [Finset.sup_image, Function.id_comp, Finset.sup_eq_iSup, supr_rw,
207+
span_eq_iSup_of_singleton_spans, eq_comm] at ssup
214208
exact ⟨t, ssup⟩
215209

216210
end Submodule
@@ -235,7 +229,7 @@ instance [Module.Finite R M] : IsCoatomic (Submodule R M) :=
235229
-- See note [lower instance priority]
236230
instance (priority := 100) of_finite [Finite M] : Module.Finite R M := by
237231
cases nonempty_fintype M
238-
exact ⟨⟨Finset.univ, by rw [Finset.coe_univ]; exact Submodule.span_univ⟩⟩
232+
exact ⟨⟨Finset.univ, by rw [Finset.coe_univ, span_univ]⟩⟩
239233

240234
section
241235

@@ -247,19 +241,19 @@ variable {S} {P : Type*} [Semiring S] [AddCommMonoid P] [Module S P]
247241
theorem of_surjective [hM : Module.Finite R M] (f : M →ₛₗ[σ] P) (hf : Surjective f) :
248242
Module.Finite S P :=
249243
by
250-
rw [← LinearMap.range_eq_top.2 hf, ← Submodule.map_top]
251-
exact hM.1.map f⟩
244+
rw [← LinearMap.range_eq_top.mpr hf, ← Submodule.map_top]
245+
exact hM.fg_top.map f⟩
252246

253247
theorem _root_.LinearMap.finite_iff_of_bijective (f : M →ₛₗ[σ] P) (hf : Function.Bijective f) :
254248
Module.Finite R M ↔ Module.Finite S P :=
255249
fun _ ↦ of_surjective f hf.surjective, fun _ ↦ ⟨fg_of_fg_map_injective f hf.injective <| by
256-
rwa [Submodule.map_top, LinearMap.range_eq_top.2 hf.surjective, ← Module.finite_def]⟩⟩
250+
rwa [Submodule.map_top, LinearMap.range_eq_top.mpr hf.surjective, ← Module.finite_def]⟩⟩
257251

258252
end
259253

260254
instance quotient (R) {A M} [Semiring R] [AddCommGroup M] [Ring A] [Module A M] [Module R M]
261-
[SMul R A] [IsScalarTower R A M] [Module.Finite R M]
262-
(N : Submodule A M) : Module.Finite R (M ⧸ N) :=
255+
[SMul R A] [IsScalarTower R A M] [Module.Finite R M] (N : Submodule A M) :
256+
Module.Finite R (M ⧸ N) :=
263257
Module.Finite.of_surjective (N.mkQ.restrictScalars R) N.mkQ_surjective
264258

265259
/-- The range of a linear map from a finite module is finite. -/
@@ -269,18 +263,17 @@ instance range [Module.Finite R M] (f : M →ₗ[R] N) : Module.Finite R f.range
269263

270264
/-- Pushforwards of finite submodules are finite. -/
271265
instance map (p : Submodule R M) [Module.Finite R p] (f : M →ₗ[R] N) : Module.Finite R (p.map f) :=
272-
of_surjective (f.restrict fun _ => Submodule.mem_map_of_mem) fun ⟨_, _, hy, hy'⟩ =>
273-
⟨⟨_, hy⟩, Subtype.ext hy'⟩
266+
of_surjective (f.restrict fun _ ↦ mem_map_of_mem) fun ⟨_, _, hy, hy'⟩ ↦ ⟨⟨_, hy⟩, Subtype.ext hy'⟩
274267

275268
instance pi {ι : Type*} {M : ι → Type*} [_root_.Finite ι] [∀ i, AddCommMonoid (M i)]
276269
[∀ i, Module R (M i)] [h : ∀ i, Module.Finite R (M i)] : Module.Finite R (∀ i, M i) :=
277270
by
278-
rw [← Submodule.pi_top]
279-
exact Submodule.fg_pi fun i => (h i).1
271+
rw [← pi_top]
272+
exact fg_pi fun i => (h i).fg_top
280273

281274
theorem of_pi {ι : Type*} (M : ι → Type*) [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)]
282275
[Module.Finite R (∀ i, M i)] (i : ι) : Module.Finite R (M i) :=
283-
Module.Finite.of_surjective _ <| LinearMap.proj_surjective i
276+
of_surjective _ <| LinearMap.proj_surjective i
284277

285278
theorem pi_iff {ι : Type*} {M : ι → Type*} [_root_.Finite ι] [∀ i, AddCommMonoid (M i)]
286279
[∀ i, Module R (M i)] : Module.Finite R (∀ i, M i) ↔ ∀ i, Module.Finite R (M i) :=
@@ -298,10 +291,10 @@ variable (M)
298291
theorem of_restrictScalars_finite (R A M : Type*) [Semiring R] [Semiring A] [AddCommMonoid M]
299292
[Module R M] [Module A M] [SMul R A] [IsScalarTower R A M] [hM : Module.Finite R M] :
300293
Module.Finite A M := by
301-
rw [finite_def, Submodule.fg_def] at hM ⊢
294+
rw [finite_def, fg_def] at hM ⊢
302295
obtain ⟨S, hSfin, hSgen⟩ := hM
303-
refine ⟨S, hSfin, eq_top_iff.2 ?_⟩
304-
have := Submodule.span_le_restrictScalars R A S
296+
refine ⟨S, hSfin, eq_top_iff.mpr ?_⟩
297+
have := span_le_restrictScalars R A S
305298
rwa [hSgen] at this
306299

307300
variable {R M}
@@ -321,14 +314,14 @@ instance Module.finite_shrink [Module.Finite R M] [Small.{u} M] : Module.Finite
321314
Module.Finite.equiv (Shrink.linearEquiv R M).symm
322315

323316
/-- A submodule is finite as a module iff it is finitely generated. -/
324-
theorem iff_fg {N : Submodule R M} : Module.Finite R N ↔ N.FG := Module.finite_def.trans N.fg_top
317+
theorem iff_fg {N : Submodule R M} : Module.Finite R N ↔ N.FG := finite_def.trans N.fg_top
325318

326319
/-- A finitely-generated submodule is finite as a module. -/
327320
alias ⟨_, of_fg⟩ := iff_fg
328321

329322
/-- A submodule that is finite as a module is finitely generated. -/
330323
theorem _root_.Submodule.FG.of_finite {N : Submodule R M} [Module.Finite R N] : N.FG :=
331-
iff_fg.1 ‹_›
324+
iff_fg.mp ‹_›
332325

333326
variable (R M)
334327

@@ -339,17 +332,16 @@ instance top [Module.Finite R M] : Module.Finite R (⊤ : Submodule R M) := .of_
339332
variable {M}
340333

341334
/-- The submodule generated by a finite set is `R`-finite. -/
342-
theorem span_of_finite {A : Set M} (hA : Set.Finite A) :
343-
Module.Finite R (Submodule.span R A) :=
344-
.of_fg ⟨hA.toFinset, hA.coe_toFinset.symm ▸ rfl⟩
335+
theorem span_of_finite {A : Set M} (hA : Set.Finite A) : Module.Finite R (span R A) :=
336+
of_fg ⟨hA.toFinset, hA.coe_toFinset.symm ▸ rfl⟩
345337

346338
/-- The submodule generated by a single element is `R`-finite. -/
347339
instance span_singleton (x : M) : Module.Finite R (R ∙ x) :=
348-
Module.Finite.span_of_finite R <| Set.finite_singleton _
340+
span_of_finite R <| Set.finite_singleton _
349341

350342
/-- The submodule generated by a finset is `R`-finite. -/
351343
instance span_finset (s : Finset M) : Module.Finite R (span R (s : Set M)) :=
352-
.of_fg ⟨s, rfl⟩
344+
of_fg ⟨s, rfl⟩
353345

354346
variable {R}
355347

@@ -359,11 +351,10 @@ theorem trans {R : Type*} (A M : Type*) [Semiring R] [Semiring A] [Module R A]
359351
[AddCommMonoid M] [Module R M] [Module A M] [IsScalarTower R A M] :
360352
∀ [Module.Finite R A] [Module.Finite A M], Module.Finite R M
361353
| ⟨⟨s, hs⟩⟩, ⟨⟨t, ht⟩⟩ =>
362-
⟨Submodule.fg_def.2
363-
⟨Set.image2 (· • ·) (↑s : Set A) (↑t : Set M),
364-
Set.Finite.image2 _ s.finite_toSet t.finite_toSet, by
365-
rw [Set.image2_smul, Submodule.span_smul_of_span_eq_top hs (↑t : Set M), ht,
366-
Submodule.restrictScalars_top]⟩⟩
354+
⟨fg_def.mpr
355+
⟨image2 (· • ·) (↑s : Set A) (↑t : Set M),
356+
Finite.image2 _ s.finite_toSet t.finite_toSet,
357+
by rw [image2_smul, span_smul_of_span_eq_top hs (↑t : Set M), ht, restrictScalars_top]⟩⟩
367358

368359
lemma of_equiv_equiv {A₁ B₁ A₂ B₂ : Type*} [CommSemiring A₁] [CommSemiring B₁]
369360
[CommSemiring A₂] [Semiring B₂] [Algebra A₁ B₁] [Algebra A₂ B₂] (e₁ : A₁ ≃+* A₂)
@@ -378,8 +369,8 @@ lemma of_equiv_equiv {A₁ B₁ A₂ B₂ : Type*} [CommSemiring A₁] [CommSemi
378369
{ e₂ with
379370
commutes' := fun r ↦ by
380371
simpa [RingHom.algebraMap_toAlgebra] using DFunLike.congr_fun he.symm (e₁.symm r) }
381-
haveI := Module.Finite.of_restrictScalars_finite A₁ A₂ B₁
382-
exact Module.Finite.equiv e.toLinearEquiv
372+
haveI := of_restrictScalars_finite A₁ A₂ B₁
373+
exact equiv e.toLinearEquiv
383374

384375
end Algebra
385376

@@ -408,11 +399,10 @@ Note that strictly this only needs `∀ i ∈ s, FiniteDimensional K (S i)`, but
408399
work well with typeclass search. -/
409400
instance finite_finset_sup {ι : Type*} (s : Finset ι) (S : ι → Submodule R V)
410401
[∀ i, Module.Finite R (S i)] : Module.Finite R (s.sup S : Submodule R V) := by
411-
refine
412-
@Finset.sup_induction _ _ _ _ s S (fun i => Module.Finite R ↑i) (Module.Finite.bot R V)
413-
?_ fun i _ => by infer_instance
402+
refine s.sup_induction (f := S) (p := fun i => Module.Finite R ↑i) (Module.Finite.bot R V) ?_
403+
inferInstance
414404
intro S₁ hS₁ S₂ hS₂
415-
exact Submodule.finite_sup S₁ S₂
405+
exact finite_sup S₁ S₂
416406

417407
section RestrictScalars
418408

@@ -458,11 +448,11 @@ lemma _root_.RingEquiv.finite (e : A ≃+* B) : e.toRingHom.Finite :=
458448

459449
theorem comp {g : B →+* C} {f : A →+* B} (hg : g.Finite) (hf : f.Finite) : (g.comp f).Finite := by
460450
algebraize [f, g, g.comp f]
461-
exact Module.Finite.trans B C
451+
exact .trans B C
462452

463453
theorem of_comp_finite {f : A →+* B} {g : B →+* C} (h : (g.comp f).Finite) : g.Finite := by
464454
algebraize [f, g, g.comp f]
465-
exact Module.Finite.of_restrictScalars_finite A B C
455+
exact .of_restrictScalars_finite A B C
466456

467457
end Finite
468458

@@ -507,7 +497,7 @@ private instance instModuleFiniteAux : Module.Finite R≥0 R := by
507497
obtain hx | hx := le_total 0 x
508498
· simpa using Submodule.smul_mem (M := R) (.span R≥0 {1, -1}) ⟨x, hx⟩ (x := 1)
509499
(Submodule.subset_span <| by simp)
510-
· simpa using Submodule.smul_mem (M := R) (.span R≥0 {1, -1}) ⟨-x, neg_nonneg.2 hx⟩ (x := -1)
500+
· simpa using Submodule.smul_mem (M := R) (.span R≥0 {1, -1}) ⟨-x, neg_nonneg.mpr hx⟩ (x := -1)
511501
(Submodule.subset_span <| by simp)
512502

513503
/-- If a module is finite over a linearly ordered ring, then it is also finite over the non-negative

0 commit comments

Comments
 (0)