Zulip Chat Archive

Stream: lean4

Topic: decidable existence of mem of finset


Kayla Thomas (Sep 15 2023 at 20:32):

Is the existence of a member of a finite set undecidable? This gives me failed to synthesize instance Decidable (∃ n, n ∈ S):

import Mathlib.Data.Finset.Basic

set_option autoImplicit false

def blah (S : Finset Nat) := if  (n : Nat), n  S then true else false

but this works:

import Mathlib.Data.Finset.Basic

set_option autoImplicit false

def blah (S : Finset Nat) (m : Nat) := if  (n : Nat), n  S  m = n then true else false

Mario Carneiro (Sep 15 2023 at 20:33):

You could put True in there

Mario Carneiro (Sep 15 2023 at 20:33):

I guess there is no instance for this

Kayla Thomas (Sep 15 2023 at 20:34):

True gives the same error.

Kayla Thomas (Sep 15 2023 at 20:35):

What is the simplest way to make an instance of it?

Mario Carneiro (Sep 15 2023 at 20:35):

this works for me:

def blah (S : Finset Nat) (m : Nat) := if  (n : Nat), n  S  True then true else false

Kayla Thomas (Sep 15 2023 at 20:35):

oh, I thought you meant change true to True.

Eric Wieser (Sep 15 2023 at 20:36):

I think the meta-answer is that you're supposed to be using docs#Finset.Nonempty

Eric Wieser (Sep 15 2023 at 20:37):

Channeling the docs:

It should be used in theorem assumptions instead of ∃ x, x ∈ s

Mario Carneiro (Sep 15 2023 at 20:37):

instance {α} (S : Finset α) : Decidable ( a, a  S) := inferInstanceAs (Decidable S.Nonempty)

Kayla Thomas (Sep 15 2023 at 20:37):

Shouldn't it be decidable if it is empty too?

Eric Wieser (Sep 15 2023 at 20:38):

def blah (S : Finset Nat) (m : Nat) := if S.Nonempty then true else false

Kayla Thomas (Sep 15 2023 at 20:40):

To the question mark, I don't understand why we need the additional hypothesis that the set is not empty for membership to be decidable.

Kayla Thomas (Sep 15 2023 at 20:41):

In the non mwe, it could be empty.

Eric Wieser (Sep 15 2023 at 20:41):

Where do you think you are seeing that hypothesis?

Eric Wieser (Sep 15 2023 at 20:42):

Neither Mario nor I are suggesting you add h : S.Nonempty

Kayla Thomas (Sep 15 2023 at 20:42):

Oh, oops, misread instance {α} (S : Finset α) : Decidable (∃ a, a ∈ S) := inferInstanceAs (Decidable S.Nonempty).

Kayla Thomas (Sep 15 2023 at 20:43):

Sorry, thank you.


Last updated: Dec 20 2023 at 11:08 UTC