Zulip Chat Archive

Stream: new members

Topic: to_additive


Paul van Wamelen (May 27 2020 at 02:39):

In big_operators there is a sum_smul' lemma:

lemma sum_smul' [add_comm_monoid β] (s : finset α) (n : ) (f : α  β) :
  ( x in s, add_monoid.smul n (f x)) = add_monoid.smul n (( x in s, f x)) :=
@prod_pow _ (multiplicative β) _ _ _ _
attribute [to_additive sum_smul'] prod_pow

Why can't I seem to use this lemma? I get unknown identifier 'sum_smul'' even later in the big_operators file?
Probably related: Is there somewhere I can read up on to_additive?

Jalex Stark (May 27 2020 at 02:40):

did you open the right namespace?

Mario Carneiro (May 27 2020 at 02:40):

it's probably in the finset namespace

Mario Carneiro (May 27 2020 at 02:43):

https://leanprover-community.github.io/mathlib_docs/algebra/group/to_additive.html

Paul van Wamelen (May 27 2020 at 02:44):

Thanks and thanks! Yeah finset.sum_smul' does the trick.

Kevin Buzzard (May 27 2020 at 08:47):

Typing #where just after a definition will tell you the name of the namespace you're in when you made it.

Unfortunately editing mathlib can cause recompilation issues.

It's a shame that we can't hover over a definition and see exactly what we see when we hover over a use of that definition.

Paul van Wamelen (May 27 2020 at 12:42):

Oh, this is good to know!

Alex Zhang (Jun 28 2021 at 08:33):

@[to_additive]
lemma mul_smul_comm [has_mul α] (s : M) (x y : α) [smul_comm_class M α α] :
  x * (s  y) = s  (x * y) :=
(smul_comm s x y).symm

Alex Zhang (Jun 28 2021 at 08:36):

If my understanding is correct, @[to_additive] allows me to change * to +. But how can I use this feature?

Ruben Van de Velde (Jun 28 2021 at 08:40):

There will be another lemma, docs#add_vadd_comm that you can use instead

Alex Zhang (Jun 28 2021 at 08:46):

Do you mean @[to_additive] automatically produces another lemma add_vadd_comm?

Ruben Van de Velde (Jun 28 2021 at 08:46):

Yep

Alex Zhang (Jun 28 2021 at 08:46):

How the name add_vadd_comm is determined?

Alex Zhang (Jun 28 2021 at 08:48):

Namely, how do I know what the lemmas that @[to_additive] produces are?

Ruben Van de Velde (Jun 28 2021 at 08:49):

The easiest way is to go to docs#mul_smul_comm and scroll up - the last lemma or definition before the multiplicative version is the additive version

Alex Zhang (Jun 28 2021 at 08:49):

I don't quite understand how @[to_additive] works or what it allows us to do.

Alex Zhang (Jun 28 2021 at 08:50):

By the way, what does v stand for in vadd?

Anne Baanen (Jun 28 2021 at 08:58):

Alex Zhang said:

I don't quite understand how @[to_additive] works or what it allows us to do.

When you add a @[to_additive] annotation to a declaration (def or theorem), it calls a tactic that automatically generates a copy of that declaration. In this copy, all references to multiplicative structure (mul, one, inv) are replaced with additive structures (add, zero, neg). You can think of it as copy-pasting the declaration and find-and-replace mul with add, one with zero, inv with neg, except smarter.


Last updated: Dec 20 2023 at 11:08 UTC