Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit bf1b813

Browse files
committed
chore(algebra/module/basic): generalize to add_monoid_hom_class (#13346)
I need some of these lemmas for `ring_hom`. Additionally, this: * removes `map_nat_module_smul` (duplicate of `map_nsmul`) and `map_int_module_smul` (duplicate of `map_zsmul`) * renames `map_rat_module_smul` to `map_rat_smul` for brevity. * adds the lemmas `inv_nat_cast_smul_comm` and `inv_int_cast_smul_comm`. * Swaps the order of the arguments to `map_zsmul` and `map_nsmul` to align with the usual rules (`to_additive` emitted them in the wrong order)
1 parent 955cb8e commit bf1b813

7 files changed

Lines changed: 75 additions & 50 deletions

File tree

src/algebra/category/Group/Z_Module_equivalence.lean

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ namespace Module
2424
/-- The forgetful functor from `ℤ` modules to `AddCommGroup` is full. -/
2525
instance forget₂_AddCommGroup_full : full (forget₂ (Module ℤ) AddCommGroup.{u}) :=
2626
{ preimage := λ A B f,
27-
-- TODO: why `add_monoid_hom.to_int_linear_map` doesn't work here?
27+
-- `add_monoid_hom.to_int_linear_map` doesn't work here because `A` and `B` are not definitionally
28+
-- equal to the canonical `add_comm_group.int_module` module instances it expects.
2829
{ to_fun := f,
2930
map_add' := add_monoid_hom.map_add f,
30-
map_smul' := λ n x, by simp [int_smul_eq_zsmul] } }
31+
map_smul' := λ n x, by rw [int_smul_eq_zsmul, int_smul_eq_zsmul, map_zsmul,
32+
ring_hom.id_apply] } }
3133

3234
/-- The forgetful functor from `ℤ` modules to `AddCommGroup` is essentially surjective. -/
3335
instance forget₂_AddCommGroup_ess_surj : ess_surj (forget₂ (Module ℤ) AddCommGroup.{u}) :=

src/algebra/hom/group.lean

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,25 +307,42 @@ lemma map_div [group G] [group H] [monoid_hom_class F G H]
307307
(f : F) (x y : G) : f (x / y) = f x / f y :=
308308
by rw [div_eq_mul_inv, div_eq_mul_inv, map_mul_inv]
309309

310-
@[simp, to_additive] theorem map_pow [monoid G] [monoid H] [monoid_hom_class F G H]
310+
-- to_additive puts the arguments in the wrong order, so generate an auxiliary lemma, then
311+
-- swap its arguments.
312+
@[to_additive map_nsmul.aux, simp] theorem map_pow [monoid G] [monoid H] [monoid_hom_class F G H]
311313
(f : F) (a : G) :
312314
∀ (n : ℕ), f (a ^ n) = (f a) ^ n
313315
| 0 := by rw [pow_zero, pow_zero, map_one]
314316
| (n+1) := by rw [pow_succ, pow_succ, map_mul, map_pow]
315317

318+
@[simp] theorem map_nsmul [add_monoid G] [add_monoid H] [add_monoid_hom_class F G H]
319+
(f : F) (n : ℕ) (a : G) : f (n • a) = n • (f a) :=
320+
map_nsmul.aux f a n
321+
322+
attribute [to_additive_reorder 8, to_additive] map_pow
323+
316324
@[to_additive]
317325
theorem map_zpow' [div_inv_monoid G] [div_inv_monoid H] [monoid_hom_class F G H]
318326
(f : F) (hf : ∀ (x : G), f (x⁻¹) = (f x)⁻¹) (a : G) :
319327
∀ n : ℤ, f (a ^ n) = (f a) ^ n
320328
| (n : ℕ) := by rw [zpow_coe_nat, map_pow, zpow_coe_nat]
321329
| -[1+n] := by rw [zpow_neg_succ_of_nat, hf, map_pow, ← zpow_neg_succ_of_nat]
322330

331+
-- to_additive puts the arguments in the wrong order, so generate an auxiliary lemma, then
332+
-- swap its arguments.
323333
/-- Group homomorphisms preserve integer power. -/
324-
@[simp, to_additive "Additive group homomorphisms preserve integer scaling."]
334+
@[to_additive map_zsmul.aux, simp]
325335
theorem map_zpow [group G] [group H] [monoid_hom_class F G H] (f : F) (g : G) (n : ℤ) :
326336
f (g ^ n) = (f g) ^ n :=
327337
map_zpow' f (map_inv f) g n
328338

339+
/-- Additive group homomorphisms preserve integer scaling. -/
340+
theorem map_zsmul [add_group G] [add_group H] [add_monoid_hom_class F G H] (f : F) (n : ℤ) (g : G) :
341+
f (n • g) = n • f g :=
342+
map_zsmul.aux f g n
343+
344+
attribute [to_additive_reorder 8, to_additive] map_zpow
345+
329346
end mul_one
330347

331348
section mul_zero_one

src/algebra/module/basic.lean

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -360,29 +360,21 @@ def add_comm_group.int_module.unique : unique (module ℤ M) :=
360360

361361
end add_comm_group
362362

363-
namespace add_monoid_hom
364-
365-
lemma map_nat_module_smul [add_monoid M] [add_monoid M₂]
366-
(f : M →+ M₂) (x : ℕ) (a : M) : f (x • a) = x • f a :=
367-
f.map_nsmul a x
368-
369-
lemma map_int_module_smul [add_group M] [add_group M₂]
370-
(f : M →+ M₂) (x : ℤ) (a : M) : f (x • a) = x • f a :=
371-
f.map_zsmul a x
372-
373-
lemma map_int_cast_smul [add_comm_group M] [add_comm_group M₂]
374-
(f : M →+ M₂) (R S : Type*) [ring R] [ring S] [module R M] [module S M₂]
363+
lemma map_int_cast_smul [add_comm_group M] [add_comm_group M₂] {F : Type*}
364+
[add_monoid_hom_class F M M₂] (f : F) (R S : Type*) [ring R] [ring S] [module R M] [module S M₂]
375365
(x : ℤ) (a : M) : f ((x : R) • a) = (x : S) • f a :=
376-
by simp only [←zsmul_eq_smul_cast, f.map_zsmul]
366+
by simp only [←zsmul_eq_smul_cast, map_zsmul]
377367

378-
lemma map_nat_cast_smul [add_comm_monoid M] [add_comm_monoid M₂] (f : M →+ M₂)
368+
lemma map_nat_cast_smul [add_comm_monoid M] [add_comm_monoid M₂] {F : Type*}
369+
[add_monoid_hom_class F M M₂] (f : F)
379370
(R S : Type*) [semiring R] [semiring S] [module R M] [module S M₂] (x : ℕ) (a : M) :
380371
f ((x : R) • a) = (x : S) • f a :=
381-
by simp only [←nsmul_eq_smul_cast, f.map_nsmul]
372+
by simp only [←nsmul_eq_smul_cast, map_nsmul]
382373

383-
lemma map_inv_int_cast_smul {E F : Type*} [add_comm_group E] [add_comm_group F] (f : E →+ F)
384-
(R S : Type*) [division_ring R] [division_ring S] [module R E] [module S F]
385-
(n : ℤ) (x : E) :
374+
lemma map_inv_int_cast_smul [add_comm_group M] [add_comm_group M₂] {F : Type*}
375+
[add_monoid_hom_class F M M₂] (f : F)
376+
(R S : Type*) [division_ring R] [division_ring S] [module R M] [module S M₂]
377+
(n : ℤ) (x : M) :
386378
f ((n⁻¹ : R) • x) = (n⁻¹ : S) • f x :=
387379
begin
388380
by_cases hR : (n : R) = 0; by_cases hS : (n : S) = 0,
@@ -394,65 +386,79 @@ begin
394386
{ rw [← inv_smul_smul₀ hS (f _), ← map_int_cast_smul f R S, smul_inv_smul₀ hR] }
395387
end
396388

397-
lemma map_inv_nat_cast_smul {E F : Type*} [add_comm_group E] [add_comm_group F] (f : E →+ F)
398-
(R S : Type*) [division_ring R] [division_ring S] [module R E] [module S F]
399-
(n : ℕ) (x : E) :
389+
lemma map_inv_nat_cast_smul [add_comm_group M] [add_comm_group M₂] {F : Type*}
390+
[add_monoid_hom_class F M M₂] (f : F)
391+
(R S : Type*) [division_ring R] [division_ring S] [module R M] [module S M₂]
392+
(n : ℕ) (x : M) :
400393
f ((n⁻¹ : R) • x) = (n⁻¹ : S) • f x :=
401-
f.map_inv_int_cast_smul R S n x
394+
map_inv_int_cast_smul f R S n x
402395

403-
lemma map_rat_cast_smul {E F : Type*} [add_comm_group E] [add_comm_group F] (f : E →+ F)
404-
(R S : Type*) [division_ring R] [division_ring S] [module R E] [module S F]
405-
(c : ℚ) (x : E) :
396+
lemma map_rat_cast_smul [add_comm_group M] [add_comm_group M₂] {F : Type*}
397+
[add_monoid_hom_class F M M₂] (f : F)
398+
(R S : Type*) [division_ring R] [division_ring S] [module R M] [module S M₂]
399+
(c : ℚ) (x : M) :
406400
f ((c : R) • x) = (c : S) • f x :=
407401
by rw [rat.cast_def, rat.cast_def, div_eq_mul_inv, div_eq_mul_inv, mul_smul, mul_smul,
408402
map_int_cast_smul f R S, map_inv_nat_cast_smul f R S]
409403

410-
lemma map_rat_module_smul {E : Type*} [add_comm_group E] [module ℚ E]
411-
{F : Type*} [add_comm_group F] [module ℚ F] (f : E →+ F) (c : ℚ) (x : E) :
404+
lemma map_rat_smul [add_comm_group M] [add_comm_group M₂] [module ℚ M] [module ℚ M₂] {F : Type*}
405+
[add_monoid_hom_class F M M₂] (f : F) (c : ℚ) (x : M) :
412406
f (c • x) = c • f x :=
413-
rat.cast_id c ▸ f.map_rat_cast_smul ℚ ℚ c x
414-
415-
end add_monoid_hom
407+
rat.cast_id c ▸ map_rat_cast_smul f ℚ ℚ c x
416408

417409
/-- There can be at most one `module ℚ E` structure on an additive commutative group. This is not
418410
an instance because `simp` becomes very slow if we have many `subsingleton` instances,
419411
see [gh-6025]. -/
420412
lemma subsingleton_rat_module (E : Type*) [add_comm_group E] : subsingleton (module ℚ E) :=
421413
⟨λ P Q, module.ext' P Q $ λ r x,
422-
@add_monoid_hom.map_rat_module_smul E ‹_› P E ‹_› Q (add_monoid_hom.id _) r x⟩
414+
@map_rat_smul _ _ _ _ P Q _ _ (add_monoid_hom.id E) r x⟩
423415

424416
/-- If `E` is a vector space over two division rings `R` and `S`, then scalar multiplications
425417
agree on inverses of integer numbers in `R` and `S`. -/
426418
lemma inv_int_cast_smul_eq {E : Type*} (R S : Type*) [add_comm_group E] [division_ring R]
427419
[division_ring S] [module R E] [module S E] (n : ℤ) (x : E) :
428420
(n⁻¹ : R) • x = (n⁻¹ : S) • x :=
429-
(add_monoid_hom.id E).map_inv_int_cast_smul R S n x
421+
map_inv_int_cast_smul (add_monoid_hom.id E) R S n x
430422

431423
/-- If `E` is a vector space over two division rings `R` and `S`, then scalar multiplications
432424
agree on inverses of natural numbers in `R` and `S`. -/
433425
lemma inv_nat_cast_smul_eq {E : Type*} (R S : Type*) [add_comm_group E] [division_ring R]
434426
[division_ring S] [module R E] [module S E] (n : ℕ) (x : E) :
435427
(n⁻¹ : R) • x = (n⁻¹ : S) • x :=
436-
(add_monoid_hom.id E).map_inv_nat_cast_smul R S n x
428+
map_inv_nat_cast_smul (add_monoid_hom.id E) R S n x
429+
430+
/-- If `E` is a vector space over a division rings `R` and has a monoid action by `α`, then that
431+
action commutes by scalar multiplication of inverses of integers in `R` -/
432+
lemma inv_int_cast_smul_comm {α E : Type*} (R : Type*) [add_comm_group E] [division_ring R]
433+
[monoid α] [module R E] [distrib_mul_action α E] (n : ℤ) (s : α) (x : E) :
434+
(n⁻¹ : R) • s • x = s • (n⁻¹ : R) • x :=
435+
(map_inv_int_cast_smul (distrib_mul_action.to_add_monoid_hom E s) R R n x).symm
436+
437+
/-- If `E` is a vector space over a division rings `R` and has a monoid action by `α`, then that
438+
action commutes by scalar multiplication of inverses of natural numbers in `R`. -/
439+
lemma inv_nat_cast_smul_comm {α E : Type*} (R : Type*) [add_comm_group E] [division_ring R]
440+
[monoid α] [module R E] [distrib_mul_action α E] (n : ℕ) (s : α) (x : E) :
441+
(n⁻¹ : R) • s • x = s • (n⁻¹ : R) • x :=
442+
(map_inv_nat_cast_smul (distrib_mul_action.to_add_monoid_hom E s) R R n x).symm
437443

438444
/-- If `E` is a vector space over two division rings `R` and `S`, then scalar multiplications
439445
agree on rational numbers in `R` and `S`. -/
440446
lemma rat_cast_smul_eq {E : Type*} (R S : Type*) [add_comm_group E] [division_ring R]
441447
[division_ring S] [module R E] [module S E] (r : ℚ) (x : E) :
442448
(r : R) • x = (r : S) • x :=
443-
(add_monoid_hom.id E).map_rat_cast_smul R S r x
449+
map_rat_cast_smul (add_monoid_hom.id E) R S r x
444450

445451
instance add_comm_group.int_is_scalar_tower {R : Type u} {M : Type v} [ring R] [add_comm_group M]
446452
[module R M]: is_scalar_tower ℤ R M :=
447-
{ smul_assoc := λ n x y, ((smul_add_hom R M).flip y).map_int_module_smul n x }
453+
{ smul_assoc := λ n x y, ((smul_add_hom R M).flip y).map_zsmul x n }
448454

449455
instance is_scalar_tower.rat {R : Type u} {M : Type v} [ring R] [add_comm_group M]
450456
[module R M] [module ℚ R] [module ℚ M] : is_scalar_tower ℚ R M :=
451-
{ smul_assoc := λ r x y, ((smul_add_hom R M).flip y).map_rat_module_smul r x }
457+
{ smul_assoc := λ r x y, map_rat_smul ((smul_add_hom R M).flip y) r x }
452458

453459
instance smul_comm_class.rat {R : Type u} {M : Type v} [semiring R] [add_comm_group M]
454460
[module R M] [module ℚ M] : smul_comm_class ℚ R M :=
455-
{ smul_comm := λ r x y, ((smul_add_hom R M x).map_rat_module_smul r y).symm }
461+
{ smul_comm := λ r x y, (map_rat_smul (smul_add_hom R M x) r y).symm }
456462

457463
instance smul_comm_class.rat' {R : Type u} {M : Type v} [semiring R] [add_comm_group M]
458464
[module R M] [module ℚ M] : smul_comm_class R ℚ M :=

src/algebra/module/linear_map.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ abbreviation module.End (R : Type u) (M : Type v)
500500
/-- Reinterpret an additive homomorphism as a `ℕ`-linear map. -/
501501
def add_monoid_hom.to_nat_linear_map [add_comm_monoid M] [add_comm_monoid M₂] (f : M →+ M₂) :
502502
M →ₗ[ℕ] M₂ :=
503-
{ to_fun := f, map_add' := f.map_add, map_smul' := f.map_nat_module_smul }
503+
{ to_fun := f, map_add' := f.map_add, map_smul' := map_nsmul f }
504504

505505
lemma add_monoid_hom.to_nat_linear_map_injective [add_comm_monoid M] [add_comm_monoid M₂] :
506506
function.injective (@add_monoid_hom.to_nat_linear_map M M₂ _ _) :=
@@ -509,7 +509,7 @@ by { intros f g h, ext, exact linear_map.congr_fun h x }
509509
/-- Reinterpret an additive homomorphism as a `ℤ`-linear map. -/
510510
def add_monoid_hom.to_int_linear_map [add_comm_group M] [add_comm_group M₂] (f : M →+ M₂) :
511511
M →ₗ[ℤ] M₂ :=
512-
{ to_fun := f, map_add' := f.map_add, map_smul' := f.map_int_module_smul }
512+
{ to_fun := f, map_add' := f.map_add, map_smul' := map_zsmul f }
513513

514514
lemma add_monoid_hom.to_int_linear_map_injective [add_comm_group M] [add_comm_group M₂] :
515515
function.injective (@add_monoid_hom.to_int_linear_map M M₂ _ _) :=
@@ -523,7 +523,7 @@ by { intros f g h, ext, exact linear_map.congr_fun h x }
523523
def add_monoid_hom.to_rat_linear_map [add_comm_group M] [module ℚ M]
524524
[add_comm_group M₂] [module ℚ M₂] (f : M →+ M₂) :
525525
M →ₗ[ℚ] M₂ :=
526-
{ map_smul' := f.map_rat_module_smul, ..f }
526+
{ map_smul' := map_rat_smul f, ..f }
527527

528528
lemma add_monoid_hom.to_rat_linear_map_injective
529529
[add_comm_group M] [module ℚ M] [add_comm_group M₂] [module ℚ M₂] :

src/category_theory/preadditive/default.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,16 @@ map_neg (left_comp R f) g
133133
by simp
134134

135135
lemma nsmul_comp (n : ℕ) : (n • f) ≫ g = n • (f ≫ g) :=
136-
map_nsmul (right_comp P g) f n
136+
map_nsmul (right_comp P g) n f
137137

138138
lemma comp_nsmul (n : ℕ) : f ≫ (n • g) = n • (f ≫ g) :=
139-
map_nsmul (left_comp R f) g n
139+
map_nsmul (left_comp R f) n g
140140

141141
lemma zsmul_comp (n : ℤ) : (n • f) ≫ g = n • (f ≫ g) :=
142-
map_zsmul (right_comp P g) f n
142+
map_zsmul (right_comp P g) n f
143143

144144
lemma comp_zsmul (n : ℤ) : f ≫ (n • g) = n • (f ≫ g) :=
145-
map_zsmul (left_comp R f) g n
145+
map_zsmul (left_comp R f) n g
146146

147147
@[reassoc] lemma comp_sum {P Q R : C} {J : Type*} (s : finset J) (f : P ⟶ Q) (g : J → (Q ⟶ R)) :
148148
f ≫ ∑ j in s, g j = ∑ j in s, f ≫ g j :=

src/group_theory/free_abelian_group.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def punit_equiv (T : Type*) [unique T] : free_abelian_group T ≃+ ℤ :=
481481
(λ x y hx hy, by { simp only [add_monoid_hom.map_add, add_smul] at *, rw [hx, hy]}),
482482
right_inv := λ n,
483483
begin
484-
rw [add_monoid_hom.map_int_module_smul, lift.of],
484+
rw [add_monoid_hom.map_zsmul, lift.of],
485485
exact zsmul_int_one n
486486
end,
487487
map_add' := add_monoid_hom.map_add _ }

src/topology/instances/real_vector_space.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ suffices (λ c : ℝ, f (c • x)) = λ c : ℝ, c • f x, from _root_.congr_fu
2727
rat.dense_embedding_coe_real.dense.equalizer
2828
(hf.comp $ continuous_id.smul continuous_const)
2929
(continuous_id.smul continuous_const)
30-
(funext $ λ r, f.map_rat_cast_smul ℝ ℝ r x)
30+
(funext $ λ r, map_rat_cast_smul f ℝ ℝ r x)
3131

3232
/-- Reinterpret a continuous additive homomorphism between two real vector spaces
3333
as a continuous real-linear map. -/

0 commit comments

Comments
 (0)