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

Commit 35c070f

Browse files
committed
chore(linear_algebra/dfinsupp): make lsum a linear_equiv (#6185)
[Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Typeclass.20inference.20can't.20fill.20in.20parameters/near/226019081) with a summary of the problem which required the nasty `semimodule_of_linear_map` present here.
1 parent 2411d68 commit 35c070f

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

src/linear_algebra/dfinsupp.lean

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ much more developed, but many lemmas in that file should be eligible to copy ove
3232
function with finite support, semimodule, linear algebra
3333
-/
3434

35-
variables {ι : Type*} {R : Type*} {M : ι → Type*} {N : Type*}
35+
variables {ι : Type*} {R : Type*} {S : Type*} {M : ι → Type*} {N : Type*}
3636

3737
variables [dec_ι : decidable_eq ι]
3838
variables [semiring R] [Π i, add_comm_monoid (M i)] [Π i, semimodule R (M i)]
@@ -83,11 +83,34 @@ omit dec_ι
8383

8484
@[simp] lemma lapply_apply (i : ι) (f : Π₀ i, M i) : (lapply i : _ →ₗ[R] _) f = f i := rfl
8585

86+
section lsum
87+
88+
/-- Typeclass inference can't find `dfinsupp.add_comm_monoid` without help for this case.
89+
This instance allows it to be found where it is needed on the LHS of the colon in
90+
`dfinsupp.semimodule_of_linear_map`. -/
91+
instance add_comm_monoid_of_linear_map : add_comm_monoid (Π₀ (i : ι), M i →ₗ[R] N) :=
92+
@dfinsupp.add_comm_monoid _ (λ i, M i →ₗ[R] N) _
93+
94+
/-- Typeclass inference can't find `dfinsupp.semimodule` without help for this case.
95+
This is needed to define `dfinsupp.lsum` below.
96+
97+
The cause seems to be an inability to unify the `Π i, add_comm_monoid (M i →ₗ[R] N)` instance that
98+
we have with the `Π i, has_zero (M i →ₗ[R] N)` instance which appears as a parameter to the
99+
`dfinsupp` type. -/
100+
instance semimodule_of_linear_map [semiring S] [semimodule S N] [smul_comm_class R S N] :
101+
semimodule S (Π₀ (i : ι), M i →ₗ[R] N) :=
102+
@dfinsupp.semimodule _ (λ i, M i →ₗ[R] N) _ _ _ _
103+
104+
variables (S)
105+
86106
include dec_ι
87107

88-
/-- The `dfinsupp` version of `finsupp.lsum`. -/
108+
/-- The `dfinsupp` version of `finsupp.lsum`.
109+
110+
See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/
89111
@[simps apply symm_apply]
90-
def lsum : (Π i, M i →ₗ[R] N) ≃+ ((Π₀ i, M i) →ₗ[R] N) :=
112+
def lsum [semiring S] [semimodule S N] [smul_comm_class R S N] :
113+
(Π i, M i →ₗ[R] N) ≃ₗ[S] ((Π₀ i, M i) →ₗ[R] N) :=
91114
{ to_fun := λ F, {
92115
to_fun := sum_add_hom (λ i, (F i).to_add_monoid_hom),
93116
map_add' := (lift_add_hom (λ i, (F i).to_add_monoid_hom)).map_add,
@@ -101,6 +124,9 @@ def lsum : (Π i, M i →ₗ[R] N) ≃+ ((Π₀ i, M i) →ₗ[R] N) :=
101124
inv_fun := λ F i, F.comp (lsingle i),
102125
left_inv := λ F, by { ext x y, simp },
103126
right_inv := λ F, by { ext x y, simp },
104-
map_add' := λ F G, by { ext x y, simp } }
127+
map_add' := λ F G, by { ext x y, simp },
128+
map_smul' := λ c F, by { ext, simp } }
129+
130+
end lsum
105131

106132
end dfinsupp

src/linear_algebra/direct_sum_module.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ variables (φ : Π i, M i →ₗ[R] N)
7474
variables (R ι N φ)
7575
/-- The linear map constructed using the universal property of the coproduct. -/
7676
def to_module : (⨁ i, M i) →ₗ[R] N :=
77-
dfinsupp.lsum φ
77+
dfinsupp.lsum φ
7878

7979
variables {ι N φ}
8080

0 commit comments

Comments
 (0)