Skip to content

Commit 2fb27be

Browse files
committed
chore(Algebra/Module): further split Defs.lean (#18995)
The goal is that we can define `Module` without depending on `Units`. The following moves out of `Defs.lean` are included in this PR: * Module structure over Nat and Int go to `Module/NatInt.lean` * Composition with `RingHom`s goes to `Module/RingHom.lean` * Results about units go to `Module/Basic.lean`
1 parent ef950f1 commit 2fb27be

File tree

26 files changed

+281
-166
lines changed

26 files changed

+281
-166
lines changed

Mathlib.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ import Mathlib.Algebra.Module.LocalizedModule.Int
520520
import Mathlib.Algebra.Module.LocalizedModule.IsLocalization
521521
import Mathlib.Algebra.Module.LocalizedModule.Submodule
522522
import Mathlib.Algebra.Module.MinimalAxioms
523+
import Mathlib.Algebra.Module.NatInt
523524
import Mathlib.Algebra.Module.Opposite
524525
import Mathlib.Algebra.Module.PID
525526
import Mathlib.Algebra.Module.Pi
@@ -533,6 +534,7 @@ import Mathlib.Algebra.Module.Presentation.Tautological
533534
import Mathlib.Algebra.Module.Prod
534535
import Mathlib.Algebra.Module.Projective
535536
import Mathlib.Algebra.Module.Rat
537+
import Mathlib.Algebra.Module.RingHom
536538
import Mathlib.Algebra.Module.SnakeLemma
537539
import Mathlib.Algebra.Module.Submodule.Basic
538540
import Mathlib.Algebra.Module.Submodule.Bilinear

Mathlib/Algebra/AddConstMap/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Authors: Yury Kudryashov
55
-/
66
import Mathlib.Algebra.Group.Action.Pi
77
import Mathlib.Algebra.GroupPower.IterateHom
8-
import Mathlib.Algebra.Module.Defs
8+
import Mathlib.Algebra.Module.NatInt
99
import Mathlib.Algebra.Order.Archimedean.Basic
1010
import Mathlib.Algebra.Order.Group.Instances
1111
import Mathlib.Logic.Function.Iterate

Mathlib/Algebra/CharZero/Quotient.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Authors: Eric Wieser
55
-/
66
import Mathlib.Algebra.Field.Basic
77
import Mathlib.Algebra.Order.Group.Unbundled.Int
8-
import Mathlib.Algebra.Module.Defs
8+
import Mathlib.Algebra.Module.NatInt
99
import Mathlib.GroupTheory.QuotientGroup.Defs
1010
import Mathlib.Algebra.Group.Subgroup.ZPowers.Basic
1111

Mathlib/Algebra/Group/Submonoid/Pointwise.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Authors: Eric Wieser
55
-/
66
import Mathlib.Algebra.Group.Hom.End
77
import Mathlib.Algebra.Group.Submonoid.Membership
8+
import Mathlib.Algebra.GroupWithZero.Action.End
89
import Mathlib.Algebra.Order.BigOperators.Group.List
910
import Mathlib.Data.Set.Pointwise.SMul
1011
import Mathlib.Order.WellFoundedSet

Mathlib/Algebra/Homology/TotalComplex.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Authors: Joël Riou
66
import Mathlib.CategoryTheory.Linear.Basic
77
import Mathlib.Algebra.Homology.ComplexShapeSigns
88
import Mathlib.Algebra.Homology.HomologicalBicomplex
9+
import Mathlib.Algebra.Module.Basic
910

1011
/-!
1112
# The total complex of a bicomplex

Mathlib/Algebra/Module/Basic.lean

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro
66
import Mathlib.Algebra.Field.Basic
77
import Mathlib.Algebra.Group.Action.Pi
88
import Mathlib.Algebra.Group.Indicator
9-
import Mathlib.Algebra.Module.Defs
9+
import Mathlib.Algebra.GroupWithZero.Action.Units
10+
import Mathlib.Algebra.Module.NatInt
1011
import Mathlib.Algebra.NoZeroSMulDivisors.Defs
1112

1213
/-!
@@ -23,6 +24,11 @@ universe u v
2324

2425
variable {α R M M₂ : Type*}
2526

27+
@[simp]
28+
theorem Units.neg_smul [Ring R] [AddCommGroup M] [Module R M] (u : Rˣ) (x : M) :
29+
-u • x = -(u • x) := by
30+
rw [Units.smul_def, Units.val_neg, _root_.neg_smul, Units.smul_def]
31+
2632
@[simp]
2733
theorem invOf_two_smul_add_invOf_two_smul (R) [Semiring R] [AddCommMonoid M] [Module R M]
2834
[Invertible (2 : R)] (x : M) :

Mathlib/Algebra/Module/Defs.lean

Lines changed: 8 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ Copyright (c) 2015 Nathaniel Thomas. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro
55
-/
6-
import Mathlib.Algebra.GroupWithZero.Action.End
7-
import Mathlib.Algebra.GroupWithZero.Action.Units
6+
import Mathlib.Algebra.Group.Action.End
7+
import Mathlib.Algebra.Group.Equiv.Basic
8+
import Mathlib.Algebra.GroupWithZero.Action.Defs
9+
import Mathlib.Algebra.Ring.Defs
810
import Mathlib.Algebra.SMulWithZero
9-
import Mathlib.Data.Int.Cast.Lemmas
1011

1112
/-!
1213
# Modules over a ring
@@ -39,7 +40,9 @@ assert_not_exists Field
3940
assert_not_exists Invertible
4041
assert_not_exists Multiset
4142
assert_not_exists Pi.single_smul₀
43+
assert_not_exists RingHom
4244
assert_not_exists Set.indicator
45+
assert_not_exists Units
4346

4447
open Function Set
4548

@@ -72,14 +75,6 @@ instance (priority := 100) Module.toMulActionWithZero
7275
smul_zero := smul_zero
7376
zero_smul := Module.zero_smul }
7477

75-
instance AddCommGroup.toNatModule : Module ℕ M where
76-
one_smul := one_nsmul
77-
mul_smul m n a := mul_nsmul' a m n
78-
smul_add n a b := nsmul_add a b n
79-
smul_zero := nsmul_zero
80-
zero_smul := zero_nsmul
81-
add_smul r s x := add_nsmul x r s
82-
8378
theorem add_smul : (r + s) • x = r • x + s • x :=
8479
Module.add_smul r s x
8580

@@ -111,31 +106,7 @@ protected abbrev Function.Surjective.module [AddCommMonoid M₂] [SMul R M₂] (
111106
rcases hf x with ⟨x, rfl⟩
112107
rw [← f.map_zero, ← smul, zero_smul] }
113108

114-
/-- Push forward the action of `R` on `M` along a compatible surjective map `f : R →+* S`.
115-
116-
See also `Function.Surjective.mulActionLeft` and `Function.Surjective.distribMulActionLeft`.
117-
-/
118-
abbrev Function.Surjective.moduleLeft {R S M : Type*} [Semiring R] [AddCommMonoid M] [Module R M]
119-
[Semiring S] [SMul S M] (f : R →+* S) (hf : Function.Surjective f)
120-
(hsmul : ∀ (c) (x : M), f c • x = c • x) : Module S M :=
121-
{ hf.distribMulActionLeft f.toMonoidHom hsmul with
122-
zero_smul := fun x => by rw [← f.map_zero, hsmul, zero_smul]
123-
add_smul := hf.forall₂.mpr fun a b x => by simp only [← f.map_add, hsmul, add_smul] }
124-
125-
variable {R} (M)
126-
127-
/-- Compose a `Module` with a `RingHom`, with action `f s • m`.
128-
129-
See note [reducible non-instances]. -/
130-
abbrev Module.compHom [Semiring S] (f : S →+* R) : Module S M :=
131-
{ MulActionWithZero.compHom M f.toMonoidWithZeroHom, DistribMulAction.compHom M (f : S →* R) with
132-
-- Porting note: the `show f (r + s) • x = f r • x + f s • x` wasn't needed in mathlib3.
133-
-- Somehow, now that `SMul` is heterogeneous, it can't unfold earlier fields of a definition for
134-
-- use in later fields. See
135-
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Heterogeneous.20scalar.20multiplication
136-
add_smul := fun r s x => show f (r + s) • x = f r • x + f s • x by simp [add_smul] }
137-
138-
variable {M}
109+
variable {R}
139110

140111
theorem Module.eq_zero_of_zero_eq_one (zero_eq_one : (0 : R) = 1) : x = 0 := by
141112
rw [← one_smul R x, ← zero_eq_one, zero_smul]
@@ -146,20 +117,9 @@ theorem smul_add_one_sub_smul {R : Type*} [Ring R] [Module R M] {r : R} {m : M}
146117

147118
end AddCommMonoid
148119

149-
150120
section AddCommGroup
151121

152-
variable (R M) [Semiring R] [AddCommGroup M]
153-
154-
instance AddCommGroup.toIntModule : Module ℤ M where
155-
one_smul := one_zsmul
156-
mul_smul m n a := mul_zsmul a m n
157-
smul_add n a b := zsmul_add a b n
158-
smul_zero := zsmul_zero
159-
zero_smul := zero_zsmul
160-
add_smul r s x := add_zsmul x r s
161-
162-
variable {R M}
122+
variable [Semiring R] [AddCommGroup M]
163123

164124
theorem Convex.combo_eq_smul_sub_add [Module R M] {x y : M} {a b : R} (h : a + b = 1) :
165125
a • x + b • y = b • (y - x) + x :=
@@ -187,10 +147,6 @@ theorem neg_smul : -r • x = -(r • x) :=
187147

188148
theorem neg_smul_neg : -r • -x = r • x := by rw [neg_smul, smul_neg, neg_neg]
189149

190-
@[simp]
191-
theorem Units.neg_smul (u : Rˣ) (x : M) : -u • x = -(u • x) := by
192-
rw [Units.smul_def, Units.val_neg, _root_.neg_smul, Units.smul_def]
193-
194150
variable (R)
195151

196152
theorem neg_one_smul (x : M) : (-1 : R) • x = -x := by simp
@@ -202,26 +158,6 @@ theorem sub_smul (r s : R) (y : M) : (r - s) • y = r • y - s • y := by
202158

203159
end Module
204160

205-
variable (R)
206-
207-
/-- An `AddCommMonoid` that is a `Module` over a `Ring` carries a natural `AddCommGroup`
208-
structure.
209-
See note [reducible non-instances]. -/
210-
abbrev Module.addCommMonoidToAddCommGroup
211-
[Ring R] [AddCommMonoid M] [Module R M] : AddCommGroup M :=
212-
{ (inferInstance : AddCommMonoid M) with
213-
neg := fun a => (-1 : R) • a
214-
neg_add_cancel := fun a =>
215-
show (-1 : R) • a + a = 0 by
216-
nth_rw 2 [← one_smul R a]
217-
rw [← add_smul, neg_add_cancel, zero_smul]
218-
zsmul := fun z a => (z : R) • a
219-
zsmul_zero' := fun a => by simpa only [Int.cast_zero] using zero_smul R a
220-
zsmul_succ' := fun z a => by simp [add_comm, add_smul]
221-
zsmul_neg' := fun z a => by simp [← smul_assoc, neg_one_smul] }
222-
223-
variable {R}
224-
225161
/-- A module over a `Subsingleton` semiring is a `Subsingleton`. We cannot register this
226162
as an instance because Lean has no way to guess `R`. -/
227163
protected theorem Module.subsingleton (R M : Type*) [Semiring R] [Subsingleton R] [AddCommMonoid M]
@@ -242,87 +178,3 @@ instance (priority := 910) Semiring.toModule [Semiring R] : Module R R where
242178

243179
instance [NonUnitalNonAssocSemiring R] : DistribSMul R R where
244180
smul_add := left_distrib
245-
246-
/-- A ring homomorphism `f : R →+* M` defines a module structure by `r • x = f r * x`. -/
247-
def RingHom.toModule [Semiring R] [Semiring S] (f : R →+* S) : Module R S :=
248-
Module.compHom S f
249-
250-
/-- If the module action of `R` on `S` is compatible with multiplication on `S`, then
251-
`fun x ↦ x • 1` is a ring homomorphism from `R` to `S`.
252-
253-
This is the `RingHom` version of `MonoidHom.smulOneHom`.
254-
255-
When `R` is commutative, usually `algebraMap` should be preferred. -/
256-
@[simps!] def RingHom.smulOneHom
257-
[Semiring R] [NonAssocSemiring S] [Module R S] [IsScalarTower R S S] : R →+* S where
258-
__ := MonoidHom.smulOneHom
259-
map_zero' := zero_smul R 1
260-
map_add' := (add_smul · · 1)
261-
262-
/-- A homomorphism between semirings R and S can be equivalently specified by a R-module
263-
structure on S such that S/S/R is a scalar tower. -/
264-
def ringHomEquivModuleIsScalarTower [Semiring R] [Semiring S] :
265-
(R →+* S) ≃ {_inst : Module R S // IsScalarTower R S S} where
266-
toFun f := ⟨Module.compHom S f, SMul.comp.isScalarTower _⟩
267-
invFun := fun ⟨_, _⟩ ↦ RingHom.smulOneHom
268-
left_inv f := RingHom.ext fun r ↦ mul_one (f r)
269-
right_inv := fun ⟨_, _⟩ ↦ Subtype.ext <| Module.ext <| funext₂ <| smul_one_smul S
270-
271-
section AddCommMonoid
272-
273-
variable [Semiring R] [AddCommMonoid M] [Module R M]
274-
275-
section
276-
277-
variable (R)
278-
279-
/-- `nsmul` is equal to any other module structure via a cast. -/
280-
lemma Nat.cast_smul_eq_nsmul (n : ℕ) (b : M) : (n : R) • b = n • b := by
281-
induction n with
282-
| zero => rw [Nat.cast_zero, zero_smul, zero_smul]
283-
| succ n ih => rw [Nat.cast_succ, add_smul, add_smul, one_smul, ih, one_smul]
284-
285-
/-- `nsmul` is equal to any other module structure via a cast. -/
286-
-- See note [no_index around OfNat.ofNat]
287-
lemma ofNat_smul_eq_nsmul (n : ℕ) [n.AtLeastTwo] (b : M) :
288-
(no_index (OfNat.ofNat n) : R) • b = OfNat.ofNat n • b := Nat.cast_smul_eq_nsmul ..
289-
290-
/-- `nsmul` is equal to any other module structure via a cast. -/
291-
@[deprecated Nat.cast_smul_eq_nsmul (since := "2024-07-23")]
292-
lemma nsmul_eq_smul_cast (n : ℕ) (b : M) : n • b = (n : R) • b := (Nat.cast_smul_eq_nsmul ..).symm
293-
294-
end
295-
296-
/-- Convert back any exotic `ℕ`-smul to the canonical instance. This should not be needed since in
297-
mathlib all `AddCommMonoid`s should normally have exactly one `ℕ`-module structure by design.
298-
-/
299-
theorem nat_smul_eq_nsmul (h : Module ℕ M) (n : ℕ) (x : M) : @SMul.smul ℕ M h.toSMul n x = n • x :=
300-
Nat.cast_smul_eq_nsmul ..
301-
302-
/-- All `ℕ`-module structures are equal. Not an instance since in mathlib all `AddCommMonoid`
303-
should normally have exactly one `ℕ`-module structure by design. -/
304-
def AddCommMonoid.uniqueNatModule : Unique (Module ℕ M) where
305-
default := by infer_instance
306-
uniq P := (Module.ext' P _) fun n => by convert nat_smul_eq_nsmul P n
307-
308-
instance AddCommMonoid.nat_isScalarTower : IsScalarTower ℕ R M where
309-
smul_assoc n x y := by
310-
induction n with
311-
| zero => simp only [zero_smul]
312-
| succ n ih => simp only [add_smul, one_smul, ih]
313-
314-
end AddCommMonoid
315-
316-
theorem map_natCast_smul [AddCommMonoid M] [AddCommMonoid M₂] {F : Type*} [FunLike F M M₂]
317-
[AddMonoidHomClass F M M₂] (f : F) (R S : Type*) [Semiring R] [Semiring S] [Module R M]
318-
[Module S M₂] (x : ℕ) (a : M) : f ((x : R) • a) = (x : S) • f a := by
319-
simp only [Nat.cast_smul_eq_nsmul, AddMonoidHom.map_nsmul, map_nsmul]
320-
321-
theorem Nat.smul_one_eq_cast {R : Type*} [NonAssocSemiring R] (m : ℕ) : m • (1 : R) = ↑m := by
322-
rw [nsmul_eq_mul, mul_one]
323-
324-
theorem Int.smul_one_eq_cast {R : Type*} [NonAssocRing R] (m : ℤ) : m • (1 : R) = ↑m := by
325-
rw [zsmul_eq_mul, mul_one]
326-
327-
@[deprecated (since := "2024-05-03")] alias Nat.smul_one_eq_coe := Nat.smul_one_eq_cast
328-
@[deprecated (since := "2024-05-03")] alias Int.smul_one_eq_coe := Int.smul_one_eq_cast

Mathlib/Algebra/Module/End.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro
55
-/
66
import Mathlib.Algebra.Group.Hom.End
77
import Mathlib.Algebra.Module.Defs
8+
import Mathlib.Algebra.Module.NatInt
89

910
/-!
1011
# Module structure and endomorphisms

Mathlib/Algebra/Module/Hom.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Eric Wieser
55
-/
66
import Mathlib.Algebra.Group.Hom.Instances
7+
import Mathlib.Algebra.GroupWithZero.Action.End
78
import Mathlib.Algebra.Module.End
89
import Mathlib.Algebra.Ring.Opposite
910
import Mathlib.GroupTheory.GroupAction.DomAct.Basic

Mathlib/Algebra/Module/LinearMap/Defs.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro, Anne
55
Frédéric Dupuis, Heather Macbeth
66
-/
77
import Mathlib.Algebra.Group.Hom.Instances
8+
import Mathlib.Algebra.Module.NatInt
9+
import Mathlib.Algebra.Module.RingHom
810
import Mathlib.Algebra.Ring.CompTypeclasses
911
import Mathlib.GroupTheory.GroupAction.Hom
1012

0 commit comments

Comments
 (0)