Skip to content

Commit 75368be

Browse files
committed
chore(Data/Finsupp): split off basic scalar multiplication (#19205)
In the comments of #19095 we discussed that `MonoidAlgebra` and `Polynomial` need scalar multiplication by `Nat` or `Int` early on, to define a `Semiring` or `Ring` structure. We can define a generic `SMulWithZero` instance and then specialize it to get `nsmul` and `zsmul`, but only if that instance is available early on for `Finsupp`. So: split this off from `Finsupp/Basic.lean` into a higher-up file. This PR used Damiano's `upstreamableDecls` linter to find out which results could move together with the definitions for free.
1 parent 36ecbb9 commit 75368be

File tree

3 files changed

+105
-54
lines changed

3 files changed

+105
-54
lines changed

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,6 +2498,7 @@ import Mathlib.Data.Finsupp.Notation
24982498
import Mathlib.Data.Finsupp.Order
24992499
import Mathlib.Data.Finsupp.PWO
25002500
import Mathlib.Data.Finsupp.Pointwise
2501+
import Mathlib.Data.Finsupp.SMulWithZero
25012502
import Mathlib.Data.Finsupp.ToDFinsupp
25022503
import Mathlib.Data.Finsupp.Weight
25032504
import Mathlib.Data.Finsupp.WellFounded

Mathlib/Data/Finsupp/Basic.lean

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Mathlib.Algebra.BigOperators.Finsupp
77
import Mathlib.Algebra.Group.Action.Basic
88
import Mathlib.Algebra.Module.Basic
99
import Mathlib.Algebra.Regular.SMul
10+
import Mathlib.Data.Finsupp.SMulWithZero
1011
import Mathlib.Data.Rat.BigOperators
1112

1213
/-!
@@ -1285,25 +1286,11 @@ end
12851286

12861287
section
12871288

1288-
instance smulZeroClass [Zero M] [SMulZeroClass R M] : SMulZeroClass R (α →₀ M) where
1289-
smul a v := v.mapRange (a • ·) (smul_zero _)
1290-
smul_zero a := by
1291-
ext
1292-
apply smul_zero
1293-
12941289
/-!
12951290
Throughout this section, some `Monoid` and `Semiring` arguments are specified with `{}` instead of
12961291
`[]`. See note [implicit instance arguments].
12971292
-/
12981293

1299-
@[simp, norm_cast]
1300-
theorem coe_smul [Zero M] [SMulZeroClass R M] (b : R) (v : α →₀ M) : ⇑(b • v) = b • ⇑v :=
1301-
rfl
1302-
1303-
theorem smul_apply [Zero M] [SMulZeroClass R M] (b : R) (v : α →₀ M) (a : α) :
1304-
(b • v) a = b • v a :=
1305-
rfl
1306-
13071294
theorem _root_.IsSMulRegular.finsupp [Zero M] [SMulZeroClass R M] {k : R}
13081295
(hk : IsSMulRegular M k) : IsSMulRegular (α →₀ M) k :=
13091296
fun _ _ h => ext fun i => hk (DFunLike.congr_fun h i)
@@ -1314,46 +1301,21 @@ instance faithfulSMul [Nonempty α] [Zero M] [SMulZeroClass R M] [FaithfulSMul R
13141301
let ⟨a⟩ := ‹Nonempty α›
13151302
eq_of_smul_eq_smul fun m : M => by simpa using DFunLike.congr_fun (h (single a m)) a
13161303

1317-
instance instSMulWithZero [Zero R] [Zero M] [SMulWithZero R M] : SMulWithZero R (α →₀ M) where
1318-
zero_smul f := by ext i; exact zero_smul _ _
1319-
13201304
variable (α M)
13211305

1322-
instance distribSMul [AddZeroClass M] [DistribSMul R M] : DistribSMul R (α →₀ M) where
1323-
smul := (· • ·)
1324-
smul_add _ _ _ := ext fun _ => smul_add _ _ _
1325-
smul_zero _ := ext fun _ => smul_zero _
1326-
13271306
instance distribMulAction [Monoid R] [AddMonoid M] [DistribMulAction R M] :
13281307
DistribMulAction R (α →₀ M) :=
13291308
{ Finsupp.distribSMul _ _ with
13301309
one_smul := fun x => ext fun y => one_smul R (x y)
13311310
mul_smul := fun r s x => ext fun y => mul_smul r s (x y) }
13321311

1333-
instance isScalarTower [Zero M] [SMulZeroClass R M] [SMulZeroClass S M] [SMul R S]
1334-
[IsScalarTower R S M] : IsScalarTower R S (α →₀ M) where
1335-
smul_assoc _ _ _ := ext fun _ => smul_assoc _ _ _
1336-
1337-
instance smulCommClass [Zero M] [SMulZeroClass R M] [SMulZeroClass S M] [SMulCommClass R S M] :
1338-
SMulCommClass R S (α →₀ M) where
1339-
smul_comm _ _ _ := ext fun _ => smul_comm _ _ _
1340-
1341-
instance isCentralScalar [Zero M] [SMulZeroClass R M] [SMulZeroClass Rᵐᵒᵖ M] [IsCentralScalar R M] :
1342-
IsCentralScalar R (α →₀ M) where
1343-
op_smul_eq_smul _ _ := ext fun _ => op_smul_eq_smul _ _
1344-
13451312
instance module [Semiring R] [AddCommMonoid M] [Module R M] : Module R (α →₀ M) :=
13461313
{ toDistribMulAction := Finsupp.distribMulAction α M
13471314
zero_smul := fun _ => ext fun _ => zero_smul _ _
13481315
add_smul := fun _ _ _ => ext fun _ => add_smul _ _ _ }
13491316

13501317
variable {α M}
13511318

1352-
theorem support_smul [AddMonoid M] [SMulZeroClass R M] {b : R} {g : α →₀ M} :
1353-
(b • g).support ⊆ g.support := fun a => by
1354-
simp only [smul_apply, mem_support_iff, Ne]
1355-
exact mt fun h => h.symm ▸ smul_zero _
1356-
13571319
@[simp]
13581320
theorem support_smul_eq [Semiring R] [AddCommMonoid M] [Module R M] [NoZeroSMulDivisors R M] {b : R}
13591321
(hb : b ≠ 0) {g : α →₀ M} : (b • g).support = g.support :=
@@ -1376,25 +1338,11 @@ theorem mapDomain_smul {_ : Monoid R} [AddCommMonoid M] [DistribMulAction R M] {
13761338
(v : α →₀ M) : mapDomain f (b • v) = b • mapDomain f v :=
13771339
mapDomain_mapRange _ _ _ _ (smul_add b)
13781340

1379-
@[simp]
1380-
theorem smul_single [Zero M] [SMulZeroClass R M] (c : R) (a : α) (b : M) :
1381-
c • Finsupp.single a b = Finsupp.single a (c • b) :=
1382-
mapRange_single
1383-
13841341
-- Porting note: removed `simp` because `simpNF` can prove it.
13851342
theorem smul_single' {_ : Semiring R} (c : R) (a : α) (b : R) :
13861343
c • Finsupp.single a b = Finsupp.single a (c * b) :=
13871344
smul_single _ _ _
13881345

1389-
theorem mapRange_smul {_ : Monoid R} [AddMonoid M] [DistribMulAction R M] [AddMonoid N]
1390-
[DistribMulAction R N] {f : M → N} {hf : f 0 = 0} (c : R) (v : α →₀ M)
1391-
(hsmul : ∀ x, f (c • x) = c • f x) : mapRange f hf (c • v) = c • mapRange f hf v := by
1392-
erw [← mapRange_comp]
1393-
· have : f ∘ (c • ·) = (c • ·) ∘ f := funext hsmul
1394-
simp_rw [this]
1395-
apply mapRange_comp
1396-
simp only [Function.comp_apply, smul_zero, hf]
1397-
13981346
theorem smul_single_one [Semiring R] (a : α) (b : R) : b • single a (1 : R) = single a b := by
13991347
rw [smul_single, smul_eq_mul, mul_one]
14001348

@@ -1701,4 +1649,4 @@ end Sigma
17011649

17021650
end Finsupp
17031651

1704-
set_option linter.style.longFile 1900
1652+
set_option linter.style.longFile 1700
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/-
2+
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Johannes Hölzl, Kim Morrison
5+
-/
6+
import Mathlib.Algebra.Group.Action.Pi
7+
import Mathlib.Algebra.SMulWithZero
8+
import Mathlib.Data.Finsupp.Defs
9+
10+
/-!
11+
# Scalar multiplication on `Finsupp`
12+
13+
This file defines the pointwise scalar multiplication on `Finsupp`, assuming it preserves zero.
14+
15+
## Main declarations
16+
17+
* `Finsupp.smulZeroClass`: if the action of `R` on `M` preserves `0`, then it acts on `α →₀ M`
18+
19+
## Implementation notes
20+
21+
This file is intermediate between `Finsupp.Defs` and `Finsupp.Module` in that it covers scalar
22+
multiplication but does not rely on the definition of `Module`. Scalar multiplication is needed to
23+
supply the `nsmul` (and `zsmul`) fields of (semi)ring structures which are fundamental for e.g.
24+
`Polynomial`, so we want to keep the imports requied for the `Finsupp.smulZeroClass` instance
25+
reasonably light.
26+
27+
This file is a `noncomputable theory` and uses classical logic throughout.
28+
-/
29+
30+
assert_not_exists Module
31+
32+
noncomputable section
33+
34+
open Finset Function
35+
36+
variable {α β γ ι M M' N P G H R S : Type*}
37+
38+
namespace Finsupp
39+
40+
instance smulZeroClass [Zero M] [SMulZeroClass R M] : SMulZeroClass R (α →₀ M) where
41+
smul a v := v.mapRange (a • ·) (smul_zero _)
42+
smul_zero a := by
43+
ext
44+
apply smul_zero
45+
46+
/-!
47+
Throughout this section, some `Monoid` and `Semiring` arguments are specified with `{}` instead of
48+
`[]`. See note [implicit instance arguments].
49+
-/
50+
51+
@[simp, norm_cast]
52+
theorem coe_smul [Zero M] [SMulZeroClass R M] (b : R) (v : α →₀ M) : ⇑(b • v) = b • ⇑v :=
53+
rfl
54+
55+
theorem smul_apply [Zero M] [SMulZeroClass R M] (b : R) (v : α →₀ M) (a : α) :
56+
(b • v) a = b • v a :=
57+
rfl
58+
59+
instance instSMulWithZero [Zero R] [Zero M] [SMulWithZero R M] : SMulWithZero R (α →₀ M) where
60+
zero_smul f := by ext i; exact zero_smul _ _
61+
62+
variable (α M)
63+
64+
instance distribSMul [AddZeroClass M] [DistribSMul R M] : DistribSMul R (α →₀ M) where
65+
smul := (· • ·)
66+
smul_add _ _ _ := ext fun _ => smul_add _ _ _
67+
smul_zero _ := ext fun _ => smul_zero _
68+
69+
instance isScalarTower [Zero M] [SMulZeroClass R M] [SMulZeroClass S M] [SMul R S]
70+
[IsScalarTower R S M] : IsScalarTower R S (α →₀ M) where
71+
smul_assoc _ _ _ := ext fun _ => smul_assoc _ _ _
72+
73+
instance smulCommClass [Zero M] [SMulZeroClass R M] [SMulZeroClass S M] [SMulCommClass R S M] :
74+
SMulCommClass R S (α →₀ M) where
75+
smul_comm _ _ _ := ext fun _ => smul_comm _ _ _
76+
77+
instance isCentralScalar [Zero M] [SMulZeroClass R M] [SMulZeroClass Rᵐᵒᵖ M] [IsCentralScalar R M] :
78+
IsCentralScalar R (α →₀ M) where
79+
op_smul_eq_smul _ _ := ext fun _ => op_smul_eq_smul _ _
80+
81+
variable {α M}
82+
83+
theorem support_smul [AddMonoid M] [SMulZeroClass R M] {b : R} {g : α →₀ M} :
84+
(b • g).support ⊆ g.support := fun a => by
85+
simp only [smul_apply, mem_support_iff, Ne]
86+
exact mt fun h => h.symm ▸ smul_zero _
87+
88+
@[simp]
89+
theorem smul_single [Zero M] [SMulZeroClass R M] (c : R) (a : α) (b : M) :
90+
c • Finsupp.single a b = Finsupp.single a (c • b) :=
91+
mapRange_single
92+
93+
theorem mapRange_smul {_ : Monoid R} [AddMonoid M] [DistribMulAction R M] [AddMonoid N]
94+
[DistribMulAction R N] {f : M → N} {hf : f 0 = 0} (c : R) (v : α →₀ M)
95+
(hsmul : ∀ x, f (c • x) = c • f x) : mapRange f hf (c • v) = c • mapRange f hf v := by
96+
erw [← mapRange_comp]
97+
· have : f ∘ (c • ·) = (c • ·) ∘ f := funext hsmul
98+
simp_rw [this]
99+
apply mapRange_comp
100+
simp only [Function.comp_apply, smul_zero, hf]
101+
102+
end Finsupp

0 commit comments

Comments
 (0)