Zulip Chat Archive

Stream: maths

Topic: membership in finset.sum


Filippo A. E. Nuccio (Dec 03 2021 at 17:03):

I do not know how to say that a dummy variable in the finset I am summing over belongs to the finset. A MWE is the following:

import data.finset

open_locale big_operators

lemma foo (x : ) (A : finset ) (P :   Prop) : x  A  P x := sorry
def bar (x : ) (P :   Prop) (h : P x) :  := sorry


def bleah (A : finset ) (P :   Prop) :  :=
begin
  refine  a in A, bar a P (foo a A P _),
  sorry,---lean asks for ⊢ a ∈ A
end

What I am doing is definining a natural number in bar under the assumption that P a holds; and foo provides a proof of P a assuming that a ∈ A. When I perform the sum in bleah, I cannot extract the information that a ∈ A from the fact that a in A.

Floris van Doorn (Dec 03 2021 at 17:09):

You cannot do this when using ∑ a in A, ....
One thing you can do is to sum over A.subtype P (or even A.subtype (∈ A)?). See docs#finset.subtype.
Another thing you can try (which is probably more convenient) is to redefine bar to produce some garbage value if P does not hold, e.g.

def bar (x : ) (P :   Prop) :  := if h : P x then sorry else 0

Filippo A. E. Nuccio (Dec 03 2021 at 17:10):

Ok, thanks! I will try to understand how to use A.subtype P(I am not sure the "garbage" strategy would really work in the case I am working on).

Johan Commelin (Dec 03 2021 at 17:11):

Yet another option is to use finsum where you can write ∑ᶠ a ∈ A, f a

Johan Commelin (Dec 03 2021 at 17:12):

But you will then need to work a bit to relate it to finset.sum

Filippo A. E. Nuccio (Dec 03 2021 at 17:13):

I'll try the first option suggested by Floris and if I can't make it work, I will come back here. Thanks :pray:

Floris van Doorn (Dec 03 2021 at 17:18):

Very similar to what I suggested: you can also use ∑ a : (A : set ℤ), ... (see e.g. src#finset.prod_finset_coe)

Filippo A. E. Nuccio (Dec 03 2021 at 17:20):

Yes!

def bleah (A : finset ) (P :   Prop) [decidable_pred P] :  :=
begin
  refine  a : (A : set ), bar a P (foo a A P (finset.coe_mem _)),
end

Filippo A. E. Nuccio (Dec 03 2021 at 17:21):

Thanks (with the first option it was somewhat more cumbersome).

Filippo A. E. Nuccio (Dec 03 2021 at 17:22):

And it also works perfectly in my "true" case.

Yaël Dillies (Dec 03 2021 at 21:51):

The correct thing to do here might be using docs#finset.attach

Eric Wieser (Dec 03 2021 at 22:16):

But that's just finset.univ!


Last updated: Dec 20 2023 at 11:08 UTC