Zulip Chat Archive

Stream: Is there code for X?

Topic: Finset iUnion


Gareth Ma (Oct 17 2023 at 12:20):

Hi, is there a notion for Finset / Multiset indexed union, at least over a finite set? I want to express that a Finset is the union of a few smaller disjoint Finsets ("classes"), and I want to keep it as Finset so that I can perform cardinality calculations later.

Floris van Doorn (Oct 17 2023 at 12:22):

docs#Finset.biUnion

Gareth Ma (Oct 17 2023 at 12:33):

Thanks! Also, is there a way to state {a : Fin k | P a} as a Finset ? Currently I write it as (univ : Finset (Fin k)).filter P but that's very long...

Gareth Ma (Oct 17 2023 at 12:35):

(deleted)

Gareth Ma (Oct 17 2023 at 12:36):

For example,

#check ({a : Fin 10 | a > 0} : Finset (Fin 10))
/-
▶ 26:8-26:48: error:
type mismatch
  {a | a > 0}
has type
  Set (Fin 10) : Type
but is expected to have type
  Finset (Fin 10) : Type
-/

Floris van Doorn (Oct 17 2023 at 12:37):

I'm afraid not, and you have to write univ.filter P (potentially with more typing information).

Gareth Ma (Oct 17 2023 at 12:39):

I see, that's very annoying for doing anything combinatorial :/ Thanks

Yaël Dillies (Oct 17 2023 at 18:30):

Also see docs#Finset.sigma

Yaël Dillies (Oct 17 2023 at 18:31):

Your suggested syntax is one of the things @Kyle Miller is working on.

Kyle Miller (Oct 18 2023 at 14:51):

@Gareth Ma You should be able to do Set.toFinset {a : Fin k | P a} (maybe even {a : Fin k | P a}.toFinset). The docs#Set.toFinset API is meant to be able to help you construct finsets using set notations, to the extent that typeclass inference can apply.

Gareth Ma (Oct 18 2023 at 14:56):

Thanks a lot!! I will try it out in a second.

Gareth Ma (Oct 18 2023 at 14:57):

I guess everyone in this thread learns something :D


Last updated: Dec 20 2023 at 11:08 UTC