Zulip Chat Archive

Stream: Is there code for X?

Topic: finset.drop_none


Yury G. Kudryashov (Oct 08 2021 at 04:17):

Do we have a definition equivalent to

def finset.drop_none (s : finset (option α)) : finset α :=
s.bUnion (λ o, o.to_finset)

but without the need for [decidable_eq α]? If not, what is the best way to define it? Go all the way from list? Use some existing defs?

Yakov Pechersky (Oct 08 2021 at 10:14):

docs#finset.filter

Yakov Pechersky (Oct 08 2021 at 10:15):

Filter for ne none? That might be decidable regardless of decidability of base type

Eric Wieser (Oct 08 2021 at 10:22):

Perhaps something like this?

lemma option.eq_of_mem :  {a₁ a₂ : option α} {b} (ha₁ : b  a₁) (ha₂ : b  a₂), a₁ = a₂
| (some _) (some _) _ rfl rfl := rfl

def finset.drop_none (s : finset (option α)) : finset α :=
s.1.filter_map id, multiset.nodup_filter_map _ (λ a₁ a₂ b, option.eq_of_mem) s.nodup

Eric Wieser (Oct 08 2021 at 10:33):

removed the sorry above.

Floris van Doorn (Oct 08 2021 at 12:01):

@Yakov Pechersky you then still need to map from option α to α, which is annoying (docs#finset.map wouldn't work).

Yury G. Kudryashov (Oct 08 2021 at 12:15):

I came up with

def unoption (s : finset (option α)) : finset α :=
(s.subtype $ λ o : option α, o.is_some).map (equiv.option_is_some_equiv α).to_embedding

It uses existing operations, so I can prove API lemmas by simp [unoption].

Eric Wieser (Oct 08 2021 at 13:05):

I would have though you could prove lemmas about my version by coercing to multiset with ext or similar

Eric Wieser (Oct 08 2021 at 13:06):

Are they defeq?

Yakov Pechersky (Oct 08 2021 at 14:28):

(deleted)

Yakov Pechersky (Oct 08 2021 at 14:53):

docs#finset.pmap

Yakov Pechersky (Oct 08 2021 at 14:54):

That's too bad that that doesn't exist

Yury G. Kudryashov (Oct 10 2021 at 16:23):

#9630


Last updated: Dec 20 2023 at 11:08 UTC