Zulip Chat Archive

Stream: general

Topic: set to finset


Antoine Labelle (Aug 03 2023 at 14:44):

I'm trying to convert a set inside a fintype to a finset, but set.to_finset does not work:

import data.fintype.basic

def test (ι : Type) [fintype ι] (s : set ι) : finset ι := s.to_finset  --lean does not accept that

What is the right way to do that?

Eric Wieser (Aug 03 2023 at 14:47):

The error message you get is not "Lean does not accept that", right?

Antoine Labelle (Aug 03 2023 at 14:48):

The error message is

failed to synthesize type class instance for
ι : Type,
_inst_1 : fintype ι,
s : set ι
 fintype s

Eric Wieser (Aug 03 2023 at 14:51):

Does [decidable_pred (\mem s)] fix it?

Antoine Labelle (Aug 03 2023 at 14:55):

It does, thanks

Eric Wieser (Aug 03 2023 at 15:07):

The explanation is that the algorithm is to iterate all of ι and keep the ones that are in s; but that means you need a way to test if they're in s!

Kevin Buzzard (Aug 03 2023 at 16:07):

One way to debug this kind of question is to Open Classical, see if that fixes it, and then use #synth to find out what it found and then deduce why it didn't find it before

Anne Baanen (Aug 04 2023 at 09:36):

Or in the old-fashioned, less-uppercase Lean 3 way: open_locale classical :)


Last updated: Dec 20 2023 at 11:08 UTC