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

Commit efdcab1

Browse files
committed
refactor(algebra/module/basic): Clean up all the nat/int semimodule definitions (#5654)
These were named inconsistently, and lots of proof was duplicated. The name changes are largely making the API for `nsmul` consistent with the one for `gsmul`: * For `ℕ`: * Replaces `nat.smul_def : n • x = n •ℕ x` with `nsmul_def : n •ℕ x = n • x` * Renames `semimodule.nsmul_eq_smul : n •ℕ b = (n : R) • b` to `nsmul_eq_smul_cast` * Removes `semimodule.smul_eq_smul : n • b = (n : R) • b` * Adds `nsmul_eq_smul : n •ℕ b = n • b` (this is different from `nsmul_def` as described in the docstring) * Renames the instances to be named more consistently and all live under `add_comm_monoid.nat_*` * For `ℤ`: * Renames `gsmul_eq_smul : n •ℤ x = n • x` to `gsmul_def` * Renames `module.gsmul_eq_smul : n •ℤ x = n • x` to `gsmul_eq_smul` * Renames `module.gsmul_eq_smul_cast` to `gsmul_eq_smul_cast` * Renames the instances to be named more consistently and all live under `add_comm_group.int_*`
1 parent d89464d commit efdcab1

File tree

4 files changed

+90
-128
lines changed

4 files changed

+90
-128
lines changed

src/algebra/module/basic.lean

Lines changed: 87 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,14 @@ library_note "vector space definition"
263263
abbreviation vector_space (R : Type u) (M : Type v) [field R] [add_comm_group M] :=
264264
semimodule R M
265265

266-
namespace add_comm_monoid
267-
open add_monoid
266+
section add_comm_monoid
268267

269-
variables [add_comm_monoid M]
268+
variables [semiring R] [add_comm_monoid M] [semimodule R M]
270269

271270
/-- The natural ℕ-semimodule structure on any `add_comm_monoid`. -/
272271
-- We don't make this a global instance, as it results in too many instances,
273272
-- and confusing ambiguity in the notation `n • x` when `n : ℕ`.
274-
def nat_semimodule : semimodule ℕ M :=
273+
def add_comm_monoid.nat_semimodule : semimodule ℕ M :=
275274
{ smul := nsmul,
276275
smul_add := λ _ _ _, nsmul_add _ _ _,
277276
add_smul := λ _ _ _, add_nsmul _ _ _,
@@ -280,44 +279,66 @@ def nat_semimodule : semimodule ℕ M :=
280279
zero_smul := zero_nsmul,
281280
smul_zero := nsmul_zero }
282281

283-
instance : subsingleton (semimodule ℕ M) :=
282+
section
283+
local attribute [instance] add_comm_monoid.nat_semimodule
284+
/-- `nsmul` is defined as the `smul` action of `add_comm_monoid.nat_semimodule`. -/
285+
lemma nsmul_def (n : ℕ) (x : M) :
286+
n •ℕ x = n • x :=
287+
rfl
288+
end
289+
290+
section
291+
variables (R)
292+
/-- `nsmul` is equal to any other semimodule structure via a cast. -/
293+
lemma nsmul_eq_smul_cast (n : ℕ) (b : M) :
294+
n •ℕ b = (n : R) • b :=
284295
begin
285-
split,
286-
intros P Q,
287-
ext n,
288-
-- isn't that lovely: `r • m = r • m`
289-
have one_smul : by { haveI := P, exact (1 : ℕ) • m } = by { haveI := Q, exact (1 : ℕ) • m },
290-
begin
291-
rw [@one_smul ℕ _ _ (by { haveI := P, apply_instance, }) m],
292-
rw [@one_smul ℕ _ _ (by { haveI := Q, apply_instance, }) m],
293-
end,
296+
rw nsmul_def,
294297
induction n with n ih,
295-
{ erw [zero_smul, zero_smul], },
296-
{ rw [nat.succ_eq_add_one, add_smul, add_smul],
297-
erw ih,
298-
rw [one_smul], }
298+
{ rw [nat.cast_zero, zero_smul, zero_smul] },
299+
{ rw [nat.succ_eq_add_one, nat.cast_succ, add_smul, add_smul, one_smul, ih, one_smul] }
299300
end
301+
end
302+
303+
/-- `nsmul` is equal to any `ℕ`-semimodule structure. -/
304+
lemma nsmul_eq_smul [semimodule ℕ M] (n : ℕ) (b : M) : n •ℕ b = n • b :=
305+
by rw [nsmul_eq_smul_cast ℕ, n.cast_id]
306+
307+
/-- All `ℕ`-semimodule structures are equal. -/
308+
instance add_comm_monoid.nat_semimodule.subsingleton : subsingleton (semimodule ℕ M) :=
309+
⟨λ P Q, by {
310+
ext n,
311+
rw [←nsmul_eq_smul, ←nsmul_eq_smul], }⟩
300312

301313
/-- Note this does not depend on the `nat_semimodule` definition above, to avoid issues when
302314
diamonds occur in finding `semimodule ℕ M` instances. -/
303-
instance nat_is_scalar_tower [semiring S] [semimodule S M] [semimodule ℕ S] [semimodule ℕ M] :
304-
is_scalar_tower ℕ S M :=
315+
instance add_comm_monoid.nat_is_scalar_tower [semimodule ℕ R] [semimodule ℕ M] :
316+
is_scalar_tower ℕ R M :=
305317
{ smul_assoc := λ n x y, nat.rec_on n
306318
(by simp only [zero_smul])
307319
(λ n ih, by simp only [nat.succ_eq_add_one, add_smul, one_smul, ih]) }
308320

321+
instance add_comm_monoid.nat_smul_comm_class [semimodule ℕ M] : smul_comm_class ℕ R M :=
322+
{ smul_comm := λ n r m, nat.rec_on n
323+
(by simp only [zero_smul, smul_zero])
324+
(λ n ih, by simp only [nat.succ_eq_add_one, add_smul, one_smul, ←ih, smul_add]) }
325+
326+
-- `smul_comm_class.symm` is not registered as an instance, as it would cause a loop
327+
instance add_comm_monoid.nat_smul_comm_class' [semimodule ℕ M] : smul_comm_class R ℕ M :=
328+
smul_comm_class.symm _ _ _
329+
309330
end add_comm_monoid
310331

311-
namespace add_comm_group
332+
section add_comm_group
312333

313-
variables [add_comm_group M]
334+
variables [semiring S] [ring R] [add_comm_group M] [semimodule S M] [semimodule R M]
314335

315336
/-- The natural ℤ-module structure on any `add_comm_group`. -/
316337
-- We don't immediately make this a global instance, as it results in too many instances,
317338
-- and confusing ambiguity in the notation `n • x` when `n : ℤ`.
318339
-- We do turn it into a global instance, but only at the end of this file,
319340
-- and I remain dubious whether this is a good idea.
320-
def int_module : module ℤ M :=
341+
def add_comm_group.int_module : module ℤ M :=
321342
{ smul := gsmul,
322343
smul_add := λ _ _ _, gsmul_add _ _ _,
323344
add_smul := λ _ _ _, add_gsmul _ _ _,
@@ -326,114 +347,53 @@ def int_module : module ℤ M :=
326347
zero_smul := zero_gsmul,
327348
smul_zero := gsmul_zero }
328349

329-
instance : subsingleton (module ℤ M) :=
330-
begin
331-
split,
332-
intros P Q,
333-
ext,
334-
-- isn't that lovely: `r • m = r • m`
335-
have one_smul : by { haveI := P, exact (1 : ℤ) • m } = by { haveI := Q, exact (1 : ℤ) • m },
336-
begin
337-
rw [@one_smul ℤ _ _ (by { haveI := P, apply_instance, }) m],
338-
rw [@one_smul ℤ _ _ (by { haveI := Q, apply_instance, }) m],
339-
end,
340-
have nat_smul : ∀ n : ℕ, by { haveI := P, exact (n : ℤ) • m } = by { haveI := Q, exact (n : ℤ) • m },
341-
begin
342-
intro n,
343-
induction n with n ih,
344-
{ erw [zero_smul, zero_smul], },
345-
{ rw [int.coe_nat_succ, add_smul, add_smul],
346-
erw ih,
347-
rw [one_smul], }
348-
end,
349-
cases r,
350-
{ rw [int.of_nat_eq_coe, nat_smul], },
351-
{ rw [int.neg_succ_of_nat_coe, neg_smul, neg_smul, nat_smul], }
352-
end
353-
354-
instance int_is_scalar_tower [ring S] [module S M] [semimodule ℤ S] [semimodule ℤ M] :
355-
is_scalar_tower ℤ S M :=
356-
{ smul_assoc := λ n x y, int.induction_on n
357-
(by simp only [zero_smul])
358-
(λ n ih, by simp only [one_smul, add_smul, ih])
359-
(λ n ih, by simp only [one_smul, sub_smul, ih]) }
360-
361-
end add_comm_group
362-
363350
section
364-
local attribute [instance] add_comm_monoid.nat_semimodule
365-
366-
lemma semimodule.smul_eq_smul (R : Type*) [semiring R]
367-
{M : Type*} [add_comm_monoid M] [semimodule R M]
368-
(n : ℕ) (b : M) : n • b = (n : R) • b :=
369-
begin
370-
induction n with n ih,
371-
{ rw [nat.cast_zero, zero_smul, zero_smul] },
372-
{ change (n + 1) • b = (n + 1 : R) • b,
373-
rw [add_smul, add_smul, one_smul, ih, one_smul] }
374-
end
375-
376-
lemma semimodule.nsmul_eq_smul (R : Type*) [semiring R]
377-
{M : Type*} [add_comm_monoid M] [semimodule R M] (n : ℕ) (b : M) :
378-
n •ℕ b = (n : R) • b :=
379-
semimodule.smul_eq_smul R n b
380-
381-
lemma nat.smul_def {M : Type*} [add_comm_monoid M] (n : ℕ) (x : M) :
382-
n • x = n •ℕ x :=
383-
rfl
384-
351+
local attribute [instance] add_comm_group.int_module
352+
/-- `gsmul` is defined as the `smul` action of `add_comm_group.int_module`. -/
353+
lemma gsmul_def (n : ℤ) (x : M) : gsmul n x = n • x := rfl
385354
end
386355

387-
namespace nat
388-
389-
variables [semiring R] [add_comm_monoid M] [semimodule R M] [semimodule ℕ M]
390-
391-
instance smul_comm_class : smul_comm_class ℕ R M :=
392-
{ smul_comm := λ n r m, nat.rec_on n
393-
(by simp only [zero_smul, smul_zero])
394-
(λ n ih, by simp only [succ_eq_add_one, add_smul, one_smul, ←ih, smul_add]) }
395-
396-
-- `smul_comm_class.symm` is not registered as an instance, as it would cause a loop
397-
instance smul_comm_class' : smul_comm_class R ℕ M := smul_comm_class.symm _ _ _
398-
399-
end nat
400-
401356
section
402-
local attribute [instance] add_comm_group.int_module
403-
404-
lemma gsmul_eq_smul {M : Type*} [add_comm_group M] (n : ℤ) (x : M) : gsmul n x = n • x := rfl
405-
406-
lemma module.gsmul_eq_smul_cast (R : Type*) [ring R] {M : Type*} [add_comm_group M] [module R M]
407-
(n : ℤ) (b : M) : gsmul n b = (n : R) • b :=
357+
variables (R)
358+
/-- `gsmul` is equal to any other module structure via a cast. -/
359+
lemma gsmul_eq_smul_cast (n : ℤ) (b : M) : gsmul n b = (n : R) • b :=
408360
begin
409-
cases n,
410-
{ apply semimodule.nsmul_eq_smul, },
411-
{ dsimp,
412-
rw semimodule.nsmul_eq_smul R,
413-
push_cast,
414-
rw neg_smul, }
361+
rw gsmul_def,
362+
induction n using int.induction_on with p hp n hn,
363+
{ rw [int.cast_zero, zero_smul, zero_smul] },
364+
{ rw [int.cast_add, int.cast_one, add_smul, add_smul, one_smul, one_smul, hp] },
365+
{ rw [int.cast_sub, int.cast_one, sub_smul, sub_smul, one_smul, one_smul, hn] },
415366
end
416-
417367
end
418368

419-
lemma module.gsmul_eq_smul {M : Type*} [add_comm_group M] [module ℤ M]
420-
(n : ℤ) (b : M) : gsmul n b = n • b :=
421-
by rw [module.gsmul_eq_smul_cast ℤ, int.cast_id]
369+
/-- `gsmul` is equal to any `ℤ`-module structure. -/
370+
lemma gsmul_eq_smul [semimodule ℤ M] (n : ℤ) (b : M) : n •ℤ b = n • b :=
371+
by rw [gsmul_eq_smul_cast ℤ, n.cast_id]
422372

423-
namespace int
373+
/-- All `ℤ`-module structures are equal. -/
374+
instance add_comm_group.int_module.subsingleton : subsingleton (semimodule ℤ M) :=
375+
⟨λ P Q, by {
376+
ext n,
377+
rw [←gsmul_eq_smul, ←gsmul_eq_smul], }⟩
424378

425-
variables [semiring R] [add_comm_group M] [semimodule R M] [semimodule ℤ M]
379+
instance add_comm_group.int_is_scalar_tower [semimodule ℤ R] [semimodule ℤ M] :
380+
is_scalar_tower ℤ R M :=
381+
{ smul_assoc := λ n x y, int.induction_on n
382+
(by simp only [zero_smul])
383+
(λ n ih, by simp only [one_smul, add_smul, ih])
384+
(λ n ih, by simp only [one_smul, sub_smul, ih]) }
426385

427-
instance smul_comm_class : smul_comm_class ℤ R M :=
386+
instance add_comm_group.int_smul_comm_class [semimodule ℤ M] : smul_comm_class ℤ S M :=
428387
{ smul_comm := λ n x y, int.induction_on n
429388
(by simp only [zero_smul, smul_zero])
430389
(λ n ih, by simp only [one_smul, add_smul, smul_add, ih])
431390
(λ n ih, by simp only [one_smul, sub_smul, smul_sub, ih]) }
432391

433392
-- `smul_comm_class.symm` is not registered as an instance, as it would cause a loop
434-
instance smul_comm_class' : smul_comm_class R ℤ M := smul_comm_class.symm _ _ _
393+
instance add_comm_group.int_smul_comm_class' [semimodule ℤ M] : smul_comm_class S ℤ M :=
394+
smul_comm_class.symm _ _ _
435395

436-
end int
396+
end add_comm_group
437397

438398
namespace add_monoid_hom
439399

@@ -442,18 +402,18 @@ namespace add_monoid_hom
442402
lemma map_int_module_smul
443403
[add_comm_group M] [add_comm_group M₂]
444404
[module ℤ M] [module ℤ M₂] (f : M →+ M₂) (x : ℤ) (a : M) : f (x • a) = x • f a :=
445-
by simp only [← module.gsmul_eq_smul, f.map_gsmul]
405+
by simp only [←gsmul_eq_smul, f.map_gsmul]
446406

447407
lemma map_int_cast_smul
448408
[ring R] [add_comm_group M] [add_comm_group M₂] [module R M] [module R M₂]
449409
(f : M →+ M₂) (x : ℤ) (a : M) : f ((x : R) • a) = (x : R) • f a :=
450-
by simp only [← module.gsmul_eq_smul_cast, f.map_gsmul]
410+
by simp only [←gsmul_eq_smul_cast, f.map_gsmul]
451411

452412
lemma map_nat_cast_smul
453413
[semiring R] [add_comm_monoid M] [add_comm_monoid M₂]
454414
[semimodule R M] [semimodule R M₂] (f : M →+ M₂) (x : ℕ) (a : M) :
455415
f ((x : R) • a) = (x : R) • f a :=
456-
by simp only [← semimodule.nsmul_eq_smul, f.map_nsmul]
416+
by simp only [←nsmul_eq_smul_cast, f.map_nsmul]
457417

458418
lemma map_rat_cast_smul {R : Type*} [division_ring R] [char_zero R]
459419
{E : Type*} [add_comm_group E] [module R E] {F : Type*} [add_comm_group F] [module R F]
@@ -500,29 +460,33 @@ end
500460

501461
end add_monoid_hom
502462

503-
-- We finally turn on these instances globally:
504-
attribute [instance] add_comm_monoid.nat_semimodule add_comm_group.int_module
505-
506463
section module_division_ring
507464
/-! Some tests for the vanishing of elements in modules over division rings. -/
508465

509466
variables (R) [division_ring R] [add_comm_group M] [module R M]
510467

511-
lemma smul_nat_eq_zero [char_zero R] {v : M} {n : ℕ} :
468+
lemma smul_nat_eq_zero [semimodule ℕ M] [char_zero R] {v : M} {n : ℕ} :
512469
n • v = 0 ↔ n = 0 ∨ v = 0 :=
513-
by { rw [semimodule.smul_eq_smul R, smul_eq_zero], simp }
470+
by { rw [←nsmul_eq_smul, nsmul_eq_smul_cast R, smul_eq_zero], simp }
514471

515-
lemma eq_zero_of_smul_two_eq_zero [char_zero R] {v : M} (hv : 2 • v = 0) : v = 0 :=
472+
lemma eq_zero_of_smul_two_eq_zero [semimodule ℕ M] [char_zero R] {v : M} (hv : 2 • v = 0) : v = 0 :=
516473
((smul_nat_eq_zero R).mp hv).resolve_left (by norm_num)
517474

518475
lemma eq_zero_of_eq_neg [char_zero R] {v : M} (hv : v = - v) : v = 0 :=
519476
begin
477+
-- any semimodule will do
478+
haveI : semimodule ℕ M := add_comm_monoid.nat_semimodule,
520479
refine eq_zero_of_smul_two_eq_zero R _,
480+
rw ←nsmul_eq_smul,
521481
convert add_eq_zero_iff_eq_neg.mpr hv,
522482
abel
523483
end
524484

525485
lemma ne_neg_of_ne_zero [char_zero R] {v : R} (hv : v ≠ 0) : v ≠ -v :=
526-
λ h, hv (eq_zero_of_eq_neg R h)
486+
λ h, have semimodule ℕ R := add_comm_monoid.nat_semimodule, by exactI hv (eq_zero_of_eq_neg R h)
527487

528488
end module_division_ring
489+
490+
-- We finally turn on these instances globally. By doing this here, we ensure that none of the
491+
-- lemmas about nat semimodules above are specific to these instances.
492+
attribute [instance] add_comm_monoid.nat_semimodule add_comm_group.int_module

src/linear_algebra/alternating.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ lemma coe_alternatization [fintype ι] (a : alternating_map R M N' ι) :
408408
(↑a : multilinear_map R (λ ι, M) N').alternatization = nat.factorial (fintype.card ι) • a :=
409409
begin
410410
ext,
411-
simp only [multilinear_map.alternatization_apply, map_perm, smul_smul, ←nat.smul_def, coe_mk,
411+
simp only [multilinear_map.alternatization_apply, map_perm, smul_smul, nsmul_eq_smul, coe_mk,
412412
smul_apply, add_monoid_hom.coe_mk, finset.sum_const, coe_multilinear_map, one_smul,
413413
multilinear_map.dom_dom_congr_apply, int.units_coe_mul_self,
414414
finset.card_univ, fintype.card_perm],

src/number_theory/arithmetic_function.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ begin
833833
apply forall_congr,
834834
intro a,
835835
apply imp_congr (iff.refl _) (eq.congr_left (sum_congr rfl (λ x hx, _))),
836-
rw [← module.gsmul_eq_smul, gsmul_eq_mul],
836+
rw [←gsmul_eq_smul, gsmul_eq_mul],
837837
end
838838

839839
/-- Möbius inversion for functions to a `comm_group`. -/

src/representation_theory/maschke.lean

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ begin
129129
equivariant_of_linear_of_comm_apply, sum_of_conjugates],
130130
rw [linear_map.sum_apply],
131131
simp only [conjugate_i π i h],
132-
rw [finset.sum_const, finset.card_univ,
133-
@semimodule.nsmul_eq_smul k _
134-
V _ _ (fintype.card G) v,
132+
rw [finset.sum_const, finset.card_univ, nsmul_eq_smul_cast k,
135133
←mul_smul, invertible.inv_of_mul_self, one_smul],
136134
end
137135
end

0 commit comments

Comments
 (0)