Zulip Chat Archive

Stream: Is there code for X?

Topic: Finsupp.linearCombination backwards


Peter Nelson (Feb 20 2025 at 12:56):

docs#Finsupp.linearCombination has the following type signature:

def Finsupp.linearCombination {α M : Type*} (R : Type*) [Semiring R] [AddCommMonoid M]
 [Module R M] (v : α  M) :
(α →₀ R) →ₗ[R] M

Is there an easy way to talk about the natural linear map with the order of arguments reversed? Something like the following:

def Finsupp.linearCombinationReverse {α M : Type*} (R : Type*) [Semiring R] [AddCommMonoid M]
 [Module R M] (v : α →₀ R) :
(α  M) →ₗ[R] M

Kevin Buzzard (Feb 20 2025 at 14:02):

The easiest way to get this would be to make the term of type (α → M) →ₗ[R] (α →₀ R) →ₗ[R] M and then use API which already exists with names like flip or swap.

Kevin Buzzard (Feb 20 2025 at 14:04):

...and when I started trying to do this I ran into the fact that R wasn't commutative so perhaps that approach is off the table (assuming you care about the non-commutative case)

Junyan Xu (Feb 20 2025 at 14:51):

I think you're looking for Finsupp.llift. The SMulCommClass accommodates the non-commutative case (where the map isn't R-linear but you can still take e.g. S=Nat). LinearMap.flip also works under a SMulCommClass assumption.

Kevin Buzzard (Feb 20 2025 at 14:56):

So you don't need CommSemiring R for that but you do need [SMulCommClass R R M] which is basically the same thing? ("R acts on M via a commutative quotient")

Junyan Xu (Feb 20 2025 at 14:58):

I edited the post; I think in the noncommutative case you simply don't have a linear (α → M) → M but it's still an additive map which you can get by setting S=Nat.

Kevin Buzzard (Feb 20 2025 at 16:44):

aah so Peter is trolling us!

import Mathlib

noncomputable
def Finsupp.linearCombinationReverse {α M : Type*} (R : Type*) [Semiring R] [AddCommMonoid M]
    [Module R M] (v : α →₀ R) : (α  M) →ₗ[R] M where
  toFun φ := Finsupp.linearCombination R φ v
  map_add' φ ψ := sorry
  map_smul' r φ := by
    simp
    induction v using Finsupp.induction_linear with
    | h0 => simp
    | hadd => sorry
    | hsingle a s =>
        simp
        -- ⊢ s • r • φ a = r • s • φ a
        sorry

Peter Nelson (Feb 20 2025 at 16:45):

Sorry! I hadn't given thought to commutativity at all - I just copy-pasted the type signature from docs.

Eric Wieser (Feb 20 2025 at 18:41):

Kevin Buzzard said:

So you don't need CommSemiring R for that but you do need [SMulCommClass R R M] which is basically the same thing? ("R acts on M via a commutative quotient")

But you can pick S = MulOpposite R

Kevin Buzzard (Feb 20 2025 at 21:32):

The reason I stopped was that I was waiting for Peter to clarify if they were only interested in the commutative case

Antoine Chambert-Loir (Feb 24 2025 at 12:20):

I wonder whether the stuff we have for weighted degrees of polynomials isn't related to you question.

Antoine Chambert-Loir (Feb 24 2025 at 12:21):

https://leanprover-community.github.io/mathlib4_docs/Mathlib/Data/Finsupp/Weight.html#Finsupp.weight

Antoine Chambert-Loir (Feb 24 2025 at 12:27):

Is there a way to refactor docs#Finsupp.linearCombination to a general bilinear map that would get both cases at once? (Unclear)


Last updated: May 02 2025 at 03:31 UTC