Skip to content

Commit

Permalink
feat(data/finsupp): generalize finsupp.has_scalar to require only dis…
Browse files Browse the repository at this point in the history
…trib_mul_action instead of semimodule (#7819)

This propagates the generalization to (add_)monoid_algebra and mv_polynomial.
  • Loading branch information
eric-wieser committed Jun 9, 2021
1 parent 393f638 commit 34c433d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 33 deletions.
23 changes: 16 additions & 7 deletions src/algebra/monoid_algebra.lean
Expand Up @@ -222,25 +222,30 @@ instance [comm_ring k] [comm_monoid G] : comm_ring (monoid_algebra k G) :=

variables {R S : Type*}

instance [semiring R] [semiring k] [module R k] :
instance [monoid R] [semiring k] [distrib_mul_action R k] :
has_scalar R (monoid_algebra k G) :=
finsupp.has_scalar

instance [monoid R] [semiring k] [distrib_mul_action R k] :
distrib_mul_action R (monoid_algebra k G) :=
finsupp.distrib_mul_action G k

instance [semiring R] [semiring k] [module R k] :
module R (monoid_algebra k G) :=
finsupp.module G k

instance [semiring R] [semiring S] [semiring k] [module R k] [module S k]
instance [monoid R] [monoid S] [semiring k] [distrib_mul_action R k] [distrib_mul_action S k]
[has_scalar R S] [is_scalar_tower R S k] :
is_scalar_tower R S (monoid_algebra k G) :=
finsupp.is_scalar_tower G k

instance [semiring R] [semiring S] [semiring k] [module R k] [module S k]
instance [monoid R] [monoid S] [semiring k] [distrib_mul_action R k] [distrib_mul_action S k]
[smul_comm_class R S k] :
smul_comm_class R S (monoid_algebra k G) :=
finsupp.smul_comm_class G k

instance [group G] [semiring k] : distrib_mul_action G (monoid_algebra k G) :=
instance comap_distrib_mul_action_self [group G] [semiring k] :
distrib_mul_action G (monoid_algebra k G) :=
finsupp.comap_distrib_mul_action_self

end derived_instances
Expand Down Expand Up @@ -748,7 +753,7 @@ end mul_one_class
/-! #### Semiring structure -/
section semiring

instance {R : Type*} [semiring R] [semiring k] [module R k] :
instance {R : Type*} [monoid R] [semiring k] [distrib_mul_action R k] :
has_scalar R (add_monoid_algebra k G) :=
finsupp.has_scalar

Expand Down Expand Up @@ -803,15 +808,19 @@ instance [comm_ring k] [add_comm_monoid G] : comm_ring (add_monoid_algebra k G)

variables {R S : Type*}

instance [monoid R] [semiring k] [distrib_mul_action R k] :
distrib_mul_action R (add_monoid_algebra k G) :=
finsupp.distrib_mul_action G k

instance [semiring R] [semiring k] [module R k] : module R (add_monoid_algebra k G) :=
finsupp.module G k

instance [semiring R] [semiring S] [semiring k] [module R k] [module S k]
instance [monoid R] [monoid S] [semiring k] [distrib_mul_action R k] [distrib_mul_action S k]
[has_scalar R S] [is_scalar_tower R S k] :
is_scalar_tower R S (add_monoid_algebra k G) :=
finsupp.is_scalar_tower G k

instance [semiring R] [semiring S] [semiring k] [module R k] [module S k]
instance [monoid R] [monoid S] [semiring k] [distrib_mul_action R k] [distrib_mul_action S k]
[smul_comm_class R S k] :
smul_comm_class R S (add_monoid_algebra k G) :=
finsupp.smul_comm_class G k
Expand Down
42 changes: 23 additions & 19 deletions src/data/finsupp/basic.lean
Expand Up @@ -2003,57 +2003,61 @@ lemma comap_smul_apply (g : G) (f : α →₀ M) (a : α) :
end

section
instance [semiring R] [add_comm_monoid M] [module R M] : has_scalar R (α →₀ M) :=
instance [monoid R] [add_monoid M] [distrib_mul_action R M] : has_scalar R (α →₀ M) :=
⟨λa v, v.map_range ((•) a) (smul_zero _)⟩

/-!
Throughout this section, some `semiring` arguments are specified with `{}` instead of `[]`.
See note [implicit instance arguments].
Throughout this section, some `monoid` and `semiring` arguments are specified with `{}` instead of
`[]`. See note [implicit instance arguments].
-/

@[simp] lemma coe_smul {_ : semiring R} [add_comm_monoid M] [module R M]
@[simp] lemma coe_smul {_ : monoid R} [add_monoid M] [distrib_mul_action R M]
(b : R) (v : α →₀ M) : ⇑(b • v) = b • v := rfl
lemma smul_apply {_ : semiring R} [add_comm_monoid M] [module R M]
lemma smul_apply {_ : monoid R} [add_monoid M] [distrib_mul_action R M]
(b : R) (v : α →₀ M) (a : α) : (b • v) a = b • (v a) := rfl

variables (α M)

instance [semiring R] [add_comm_monoid M] [module R M] : module R (α →₀ M) :=
instance [monoid R] [add_monoid M] [distrib_mul_action R M] : distrib_mul_action R (α →₀ M) :=
{ smul := (•),
smul_add := λ a x y, ext $ λ _, smul_add _ _ _,
add_smul := λ a x y, ext $ λ _, add_smul _ _ _,
one_smul := λ x, ext $ λ _, one_smul _ _,
mul_smul := λ r s x, ext $ λ _, mul_smul _ _ _,
zero_smul := λ x, ext $ λ _, zero_smul _ _,
smul_zero := λ x, ext $ λ _, smul_zero _ }

instance [semiring R] [semiring S] [add_comm_monoid M] [module R M] [module S M]
instance [monoid R] [monoid S] [add_monoid M] [distrib_mul_action R M] [distrib_mul_action S M]
[has_scalar R S] [is_scalar_tower R S M] :
is_scalar_tower R S (α →₀ M) :=
{ smul_assoc := λ r s a, ext $ λ _, smul_assoc _ _ _ }

instance [semiring R] [semiring S] [add_comm_monoid M] [module R M] [module S M]
instance [monoid R] [monoid S] [add_monoid M] [distrib_mul_action R M] [distrib_mul_action S M]
[smul_comm_class R S M] :
smul_comm_class R S (α →₀ M) :=
{ smul_comm := λ r s a, ext $ λ _, smul_comm _ _ _ }

instance [semiring R] [add_comm_monoid M] [module R M] : module R (α →₀ M) :=
{ smul := (•),
zero_smul := λ x, ext $ λ _, zero_smul _ _,
add_smul := λ a x y, ext $ λ _, add_smul _ _ _,
.. finsupp.distrib_mul_action α M }

variables {α M} {R}

lemma support_smul {_ : semiring R} [add_comm_monoid M] [module R M] {b : R} {g : α →₀ M} :
lemma support_smul {_ : monoid R} [add_monoid M] [distrib_mul_action R M] {b : R} {g : α →₀ M} :
(b • g).support ⊆ g.support :=
λ a, by simp only [smul_apply, mem_support_iff, ne.def]; exact mt (λ h, h.symm ▸ smul_zero _)
λ a, by { simp only [smul_apply, mem_support_iff, ne.def], exact mt (λ h, h.symm ▸ smul_zero _) }

section

variables {p : α → Prop}

@[simp] lemma filter_smul {_ : semiring R} [add_comm_monoid M] [module R M]
@[simp] lemma filter_smul {_ : monoid R} [add_monoid M] [distrib_mul_action R M]
{b : R} {v : α →₀ M} : (b • v).filter p = b • v.filter p :=
coe_fn_injective $ set.indicator_smul {x | p x} b v

end

lemma map_domain_smul {_ : semiring R} [add_comm_monoid M] [module R M]
lemma map_domain_smul {_ : monoid R} [add_comm_monoid M] [distrib_mul_action R M]
{f : α → β} (b : R) (v : α →₀ M) : map_domain f (b • v) = b • map_domain f v :=
begin
change map_domain f (map_range _ _ _) = map_range _ _ _,
Expand All @@ -2064,16 +2068,16 @@ begin
apply smul_add
end

@[simp] lemma smul_single {_ : semiring R} [add_comm_monoid M] [module R M]
@[simp] lemma smul_single {_ : monoid R} [add_monoid M] [distrib_mul_action R M]
(c : R) (a : α) (b : M) : c • finsupp.single a b = finsupp.single a (c • b) :=
map_range_single

@[simp] lemma smul_single' {_ : semiring R}
(c : R) (a : α) (b : R) : c • finsupp.single a b = finsupp.single a (c * b) :=
smul_single _ _ _

lemma map_range_smul {_ : semiring R} [add_comm_monoid M] [module R M]
[add_comm_monoid N] [module R N]
lemma map_range_smul {_ : monoid R} [add_monoid M] [distrib_mul_action R M]
[add_monoid N] [distrib_mul_action R N]
{f : M → N} {hf : f 0 = 0} (c : R) (v : α →₀ M) (hsmul : ∀ x, f (c • x) = c • f x) :
map_range f hf (c • v) = c • map_range f hf v :=
begin
Expand All @@ -2093,14 +2097,14 @@ lemma sum_smul_index [semiring R] [add_comm_monoid M] {g : α →₀ R} {b : R}
(h0 : ∀i, h i 0 = 0) : (b • g).sum h = g.sum (λi a, h i (b * a)) :=
finsupp.sum_map_range_index h0

lemma sum_smul_index' [semiring R] [add_comm_monoid M] [module R M] [add_comm_monoid N]
lemma sum_smul_index' [monoid R] [add_monoid M] [distrib_mul_action R M] [add_comm_monoid N]
{g : α →₀ M} {b : R} {h : α → M → N} (h0 : ∀i, h i 0 = 0) :
(b • g).sum h = g.sum (λi c, h i (b • c)) :=
finsupp.sum_map_range_index h0

/-- A version of `finsupp.sum_smul_index'` for bundled additive maps. -/
lemma sum_smul_index_add_monoid_hom
[semiring R] [add_comm_monoid M] [add_comm_monoid N] [module R M]
[monoid R] [add_monoid M] [add_comm_monoid N] [distrib_mul_action R M]
{g : α →₀ M} {b : R} {h : α → M →+ N} :
(b • g).sum (λ a, h a) = g.sum (λ i c, h i (b • c)) :=
sum_map_range_index (λ i, (h i).map_zero)
Expand Down
4 changes: 2 additions & 2 deletions src/data/finsupp/to_dfinsupp.lean
Expand Up @@ -120,7 +120,7 @@ namespace finsupp
(f - g).to_dfinsupp = f.to_dfinsupp - g.to_dfinsupp :=
dfinsupp.coe_fn_injective (sub_eq_add_neg _ _)

@[simp] lemma to_dfinsupp_smul [semiring R] [add_comm_monoid M] [module R M]
@[simp] lemma to_dfinsupp_smul [monoid R] [add_monoid M] [distrib_mul_action R M]
(r : R) (f : ι →₀ M) : (r • f).to_dfinsupp = r • f.to_dfinsupp :=
dfinsupp.coe_fn_injective rfl

Expand All @@ -144,7 +144,7 @@ finsupp.coe_fn_injective $ dfinsupp.coe_neg _
(to_finsupp (f - g) : ι →₀ M) = to_finsupp f - to_finsupp g :=
finsupp.coe_fn_injective $ dfinsupp.coe_sub _ _

@[simp] lemma to_finsupp_smul [semiring R] [add_comm_monoid M] [module R M]
@[simp] lemma to_finsupp_smul [monoid R] [add_monoid M] [distrib_mul_action R M]
[Π m : M, decidable (m ≠ 0)]
(r : R) (f : Π₀ i : ι, M) : (to_finsupp (r • f) : ι →₀ M) = r • to_finsupp f :=
finsupp.coe_fn_injective $ dfinsupp.coe_smul _ _
Expand Down
13 changes: 8 additions & 5 deletions src/data/mv_polynomial/basic.lean
Expand Up @@ -101,14 +101,17 @@ instance decidable_eq_mv_polynomial [comm_semiring R] [decidable_eq σ] [decidab
decidable_eq (mv_polynomial σ R) := finsupp.decidable_eq
instance [comm_semiring R] : comm_semiring (mv_polynomial σ R) := add_monoid_algebra.comm_semiring
instance [comm_semiring R] : inhabited (mv_polynomial σ R) := ⟨0
instance [monoid R] [comm_semiring S₁] [distrib_mul_action R S₁] :
distrib_mul_action R (mv_polynomial σ S₁) :=
add_monoid_algebra.distrib_mul_action
instance [semiring R] [comm_semiring S₁] [module R S₁] : module R (mv_polynomial σ S₁) :=
add_monoid_algebra.module
instance [semiring R] [semiring S₁] [comm_semiring S₂]
[has_scalar R S₁] [module R S₂] [module S₁ S₂] [is_scalar_tower R S₁ S₂] :
instance [monoid R] [monoid S₁] [comm_semiring S₂]
[has_scalar R S₁] [distrib_mul_action R S₂] [distrib_mul_action S₁ S₂] [is_scalar_tower R S₁ S₂] :
is_scalar_tower R S₁ (mv_polynomial σ S₂) :=
add_monoid_algebra.is_scalar_tower
instance [semiring R] [semiring S₁][comm_semiring S₂]
[module R S₂] [module S₁ S₂] [smul_comm_class R S₁ S₂] :
instance [monoid R] [monoid S₁][comm_semiring S₂]
[distrib_mul_action R S₂] [distrib_mul_action S₁ S₂] [smul_comm_class R S₁ S₂] :
smul_comm_class R S₁ (mv_polynomial σ S₂) :=
add_monoid_algebra.smul_comm_class
instance [comm_semiring R] [comm_semiring S₁] [algebra R S₁] : algebra R (mv_polynomial σ S₁) :=
Expand Down Expand Up @@ -349,7 +352,7 @@ lemma ext_iff (p q : mv_polynomial σ R) :
@[simp] lemma coeff_add (m : σ →₀ ℕ) (p q : mv_polynomial σ R) :
coeff m (p + q) = coeff m p + coeff m q := add_apply p q m

@[simp] lemma coeff_smul {S₁ : Type*} [semiring S₁] [module S₁ R]
@[simp] lemma coeff_smul {S₁ : Type*} [monoid S₁] [distrib_mul_action S₁ R]
(m : σ →₀ ℕ) (c : S₁) (p : mv_polynomial σ R) :
coeff m (c • p) = c • coeff m p := smul_apply c p m

Expand Down

0 comments on commit 34c433d

Please sign in to comment.