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

Commit ff5fa52

Browse files
committed
chore(data/finsupp/basic): add coe_{neg,sub,smul} lemmas to match coe_{zero,add,fn_sum} (#6350)
This also: * merges together `smul_apply'` and `smul_apply`, since the latter is just a special case of the former. * changes the implicitness of arguments to all of the `finsupp.*_apply` lemmas so that all the variables and none of the types are explicit The whitespace style here matches how `coe_add` is spaced.
1 parent dd5363b commit ff5fa52

File tree

7 files changed

+27
-37
lines changed

7 files changed

+27
-37
lines changed

src/algebra/monoid_algebra.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ In particular this provides the instance `algebra k (monoid_algebra k G)`.
350350
-/
351351
instance {A : Type*} [comm_semiring k] [semiring A] [algebra k A] [monoid G] :
352352
algebra k (monoid_algebra A G) :=
353-
{ smul_def' := λ r a, by { ext, simp [single_one_mul_apply, algebra.smul_def''], },
353+
{ smul_def' := λ r a, by { ext, simp [single_one_mul_apply, algebra.smul_def'', pi.smul_apply], },
354354
commutes' := λ r f, by { ext, simp [single_one_mul_apply, mul_single_one_apply,
355355
algebra.commutes], },
356356
..single_one_ring_hom.comp (algebra_map k A) }
@@ -827,7 +827,7 @@ In particular this provides the instance `algebra k (add_monoid_algebra k G)`.
827827
-/
828828
instance [comm_semiring R] [semiring k] [algebra R k] [add_monoid G] :
829829
algebra R (add_monoid_algebra k G) :=
830-
{ smul_def' := λ r a, by { ext, simp [single_zero_mul_apply, algebra.smul_def''], },
830+
{ smul_def' := λ r a, by { ext, simp [single_zero_mul_apply, algebra.smul_def'', pi.smul_apply], },
831831
commutes' := λ r f, by { ext, simp [single_zero_mul_apply, mul_single_zero_apply,
832832
algebra.commutes], },
833833
..single_zero_ring_hom.comp (algebra_map R k) }

src/data/finsupp/basic.lean

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Authors: Johannes Hölzl, Scott Morrison
66
import algebra.group.pi
77
import algebra.big_operators.order
88
import algebra.module.basic
9+
import algebra.module.pi
910
import group_theory.submonoid.basic
1011
import data.fintype.card
1112
import data.finset.preimage
@@ -639,7 +640,7 @@ variables [add_monoid M]
639640
instance : has_add (α →₀ M) := ⟨zip_with (+) (add_zero 0)⟩
640641

641642
@[simp] lemma coe_add (f g : α →₀ M) : ⇑(f + g) = f + g := rfl
642-
lemma add_apply {g₁ g₂ : α →₀ M} {a : α} : (g₁ + g₂) a = g₁ a + g₂ a := rfl
643+
lemma add_apply (g₁ g₂ : α →₀ M) (a : α) : (g₁ + g₂) a = g₁ a + g₂ a := rfl
643644

644645
lemma support_add {g₁ g₂ : α →₀ M} : (g₁ + g₂).support ⊆ g₁.support ∪ g₂.support :=
645646
support_zip_with
@@ -682,7 +683,7 @@ See `finsupp.lsingle` for the stronger version as a linear map.
682683
683684
See `finsupp.lapply` for the stronger version as a linear map. -/
684685
@[simps apply]
685-
def apply_add_hom (a : α) : (α →₀ M) →+ M := ⟨λ g, g a, zero_apply, λ _ _, add_apply⟩
686+
def apply_add_hom (a : α) : (α →₀ M) →+ M := ⟨λ g, g a, zero_apply, λ _ _, add_apply _ _ _
686687

687688
lemma single_add_erase (a : α) (f : α →₀ M) : single a (f a) + f.erase a = f :=
688689
ext $ λ a',
@@ -822,9 +823,8 @@ namespace finsupp
822823
section nat_sub
823824
instance nat_sub : has_sub (α →₀ ℕ) := ⟨zip_with (λ m n, m - n) (nat.sub_zero 0)⟩
824825

825-
@[simp] lemma nat_sub_apply {g₁ g₂ : α →₀ ℕ} {a : α} :
826-
(g₁ - g₂) a = g₁ a - g₂ a :=
827-
rfl
826+
@[simp] lemma coe_nat_sub (g₁ g₂ : α →₀ ℕ) : ⇑(g₁ - g₂) = g₁ - g₂ := rfl
827+
lemma nat_sub_apply (g₁ g₂ : α →₀ ℕ) (a : α) : (g₁ - g₂) a = g₁ a - g₂ a := rfl
828828

829829
@[simp] lemma single_sub {a : α} {n₁ n₂ : ℕ} : single a (n₁ - n₂) = single a n₁ - single a n₂ :=
830830
begin
@@ -901,11 +901,11 @@ lemma prod_neg_index [add_group G] [comm_monoid M] {g : α →₀ G} {h : α →
901901
(-g).prod h = g.prod (λa b, h a (- b)) :=
902902
prod_map_range_index h0
903903

904-
@[simp] lemma neg_apply [add_group G] {g : α →₀ G} {a : α} : (- g) a = - g a :=
905-
rfl
904+
@[simp] lemma coe_neg [add_group G] (g : α →₀ G) : ⇑(-g) = -g := rfl
905+
lemma neg_apply [add_group G] (g : α →₀ G) (a : α) : (- g) a = - g a := rfl
906906

907-
@[simp] lemma sub_apply [add_group G] {g₁ g₂ : α →₀ G} {a : α} : (g₁ - g₂) a = g₁ a - g₂ a :=
908-
rfl
907+
@[simp] lemma coe_sub [add_group G] (g₁ g₂ : α →₀ G) : ⇑(g₁ - g₂) = g₁ - g₂ := rfl
908+
lemma sub_apply [add_group G] (g₁ g₂ : α →₀ G) (a : α) : (g₁ - g₂) a = g₁ a - g₂ a := rfl
909909

910910
@[simp] lemma support_neg [add_group G] {f : α →₀ G} : support (-f) = support f :=
911911
finset.subset.antisymm
@@ -1664,16 +1664,17 @@ section
16641664
instance [semiring R] [add_comm_monoid M] [semimodule R M] : has_scalar R (α →₀ M) :=
16651665
⟨λa v, v.map_range ((•) a) (smul_zero _)⟩
16661666

1667-
variables (α M)
1668-
16691667
/-!
16701668
Throughout this section, some `semiring` arguments are specified with `{}` instead of `[]`.
16711669
See note [implicit instance arguments].
16721670
-/
16731671

1674-
@[simp] lemma smul_apply' {_:semiring R} [add_comm_monoid M] [semimodule R M]
1675-
{a : α} {b : R} {v : α →₀ M} : (b • v) a = b • (v a) :=
1676-
rfl
1672+
@[simp] lemma coe_smul {_ : semiring R} [add_comm_monoid M] [semimodule R M]
1673+
(b : R) (v : α →₀ M) : ⇑(b • v) = b • v := rfl
1674+
lemma smul_apply {_ : semiring R} [add_comm_monoid M] [semimodule R M]
1675+
(b : R) (v : α →₀ M) (a : α) : (b • v) a = b • (v a) := rfl
1676+
1677+
variables (α M)
16771678

16781679
instance [semiring R] [add_comm_monoid M] [semimodule R M] : semimodule R (α →₀ M) :=
16791680
{ smul := (•),
@@ -1688,7 +1689,7 @@ variables {α M} {R}
16881689

16891690
lemma support_smul {_ : semiring R} [add_comm_monoid M] [semimodule R M] {b : R} {g : α →₀ M} :
16901691
(b • g).support ⊆ g.support :=
1691-
λ a, by simp only [smul_apply', mem_support_iff, ne.def]; exact mt (λ h, h.symm ▸ smul_zero _)
1692+
λ a, by simp only [smul_apply, mem_support_iff, ne.def]; exact mt (λ h, h.symm ▸ smul_zero _)
16921693

16931694
section
16941695

@@ -1724,10 +1725,6 @@ by rw [smul_single, smul_eq_mul, mul_one]
17241725

17251726
end
17261727

1727-
@[simp] lemma smul_apply [semiring R] {a : α} {b : R} {v : α →₀ R} :
1728-
(b • v) a = b • (v a) :=
1729-
rfl
1730-
17311728
lemma sum_smul_index [semiring R] [add_comm_monoid M] {g : α →₀ R} {b : R} {h : α → R → M}
17321729
(h0 : ∀i, h i 0 = 0) : (b • g).sum h = g.sum (λi a, h i (b * a)) :=
17331730
finsupp.sum_map_range_index h0

src/data/mv_polynomial/basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ lemma ext_iff (p q : mv_polynomial σ R) :
317317
⟨ λ h m, by rw h, ext p q⟩
318318

319319
@[simp] lemma coeff_add (m : σ →₀ ℕ) (p q : mv_polynomial σ R) :
320-
coeff m (p + q) = coeff m p + coeff m q := add_apply
320+
coeff m (p + q) = coeff m p + coeff m q := add_apply p q m
321321

322322
@[simp] lemma coeff_zero (m : σ →₀ ℕ) :
323323
coeff m (0 : mv_polynomial σ R) = 0 := rfl

src/data/mv_polynomial/comm_ring.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ variables (σ a a')
6161
@[simp] lemma C_neg : (C (-a) : mv_polynomial σ R) = -C a := is_ring_hom.map_neg _
6262

6363
@[simp] lemma coeff_neg (m : σ →₀ ℕ) (p : mv_polynomial σ R) :
64-
coeff m (-p) = -coeff m p := finsupp.neg_apply
64+
coeff m (-p) = -coeff m p := finsupp.neg_apply _ _
6565

6666
@[simp] lemma coeff_sub (m : σ →₀ ℕ) (p q : mv_polynomial σ R) :
67-
coeff m (p - q) = coeff m p - coeff m q := finsupp.sub_apply
67+
coeff m (p - q) = coeff m p - coeff m q := finsupp.sub_apply _ _ _
6868

6969
instance coeff.is_add_group_hom (m : σ →₀ ℕ) :
7070
is_add_group_hom (coeff m : mv_polynomial σ R → R) :=

src/data/polynomial/coeff.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ lemma coeff_sum [semiring S] (n : ℕ) (f : ℕ → R → polynomial S) :
3737
coeff (p.sum f) n = p.sum (λ a b, coeff (f a b) n) := finsupp.sum_apply
3838

3939
@[simp] lemma coeff_smul (p : polynomial R) (r : R) (n : ℕ) :
40-
coeff (r • p) n = r * coeff p n := finsupp.smul_apply
40+
coeff (r • p) n = r * coeff p n := finsupp.smul_apply _ _ _
4141

4242
lemma mem_support_iff_coeff_ne_zero : n ∈ p.support ↔ p.coeff n ≠ 0 :=
4343
by { rw mem_support_to_fun, refl }

src/linear_algebra/basis.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ variables [fintype ι] (h : is_basis R v)
367367
-/
368368
def is_basis.equiv_fun : M ≃ₗ[R] (ι → R) :=
369369
linear_equiv.trans (module_equiv_finsupp h)
370-
{ to_fun := finsupp.to_fun,
371-
map_add' := λ x y, by ext; exact finsupp.add_apply,
372-
map_smul' := λ x y, by ext; exact finsupp.smul_apply,
370+
{ to_fun := coe_fn,
371+
map_add' := finsupp.coe_add,
372+
map_smul' := finsupp.coe_smul,
373373
..finsupp.equiv_fun_on_fintype }
374374

375375
/-- A module over a finite ring that admits a finite basis is finite. -/

src/linear_algebra/dual.lean

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,10 @@ def to_dual_flip (v : V) : (V →ₗ[K] K) := (h.to_dual B).flip v
135135

136136
variable {B}
137137

138-
omit de h
139-
-- TODO: unify this with `finsupp.lapply`.
140-
/-- Evaluation of finitely supported functions at a fixed point `i`, as a `K`-linear map. -/
141-
def eval_finsupp_at (i : ι) : (ι →₀ K) →ₗ[K] K :=
142-
{ to_fun := λ f, f i,
143-
map_add' := by intros; rw finsupp.add_apply,
144-
map_smul' := by intros; rw finsupp.smul_apply }
145-
include h
138+
omit de
146139

147140
/-- `h.coord_fun i` sends vectors to their `i`'th coordinate with respect to the basis `h`. -/
148-
def coord_fun (i : ι) : (V →ₗ[K] K) := linear_map.comp (eval_finsupp_at i) h.repr
141+
def coord_fun (i : ι) : (V →ₗ[K] K) := (finsupp.lapply i).comp h.repr
149142

150143
lemma coord_fun_eq_repr (v : V) (i : ι) : h.coord_fun i v = h.repr v i := rfl
151144

0 commit comments

Comments
 (0)