Zulip Chat Archive

Stream: Is there code for X?

Topic: set.any


Patrick Thomas (Apr 17 2022 at 19:32):

Is there a function that takes a finite set and returns a boolean indicating whether any of the elements in that set satisfy a predicate function?

Ruben Van de Velde (Apr 17 2022 at 19:39):

Maybe you could start with finset.filter and go from there, of there's nothing better

Patrick Thomas (Apr 17 2022 at 19:44):

Thank you.

Yaël Dillies (Apr 17 2022 at 19:44):

(finset.filter s p).nonempty is what you want. You will need decidable equality and decidability of p.

Patrick Thomas (Apr 17 2022 at 19:45):

Thank you.

Eric Wieser (Apr 17 2022 at 19:56):

Can you just directly use ∃ x ∈ s, p x?

Patrick Thomas (Apr 17 2022 at 19:58):

I think it needs to be a computable function that can be used with if then else.

Yaël Dillies (Apr 17 2022 at 19:58):

∃ x ∈ s, p x is decidable if s is a finset. No need to reinvent the wheel.

Patrick Thomas (Apr 17 2022 at 20:04):

I can use that in ite?

Patrick Thomas (Apr 17 2022 at 20:05):

I'll give it a try. Thank you.


Last updated: Dec 20 2023 at 11:08 UTC