Zulip Chat Archive

Stream: Is there code for X?

Topic: Taking element from non-empty set


sty (Dec 19 2022 at 12:41):

Hi, I'm fairly new to Lean, which could be why I'm failing to find something I'd really expect to exist in mathlib.
Essentially I'd like to have a way to take an element from a set that I know is non-empty. Currently I'm using the following, but there's probably a cleaner alternative:

constant element {γ: Type*} {S: set γ}: S ≠ ∅ -> S

Eric Wieser (Dec 19 2022 at 12:44):

docs#set.nonempty_iff_ne_empty, so you can implement that with (set.nonempty_iff_ne_empty.mpr h).some

Eric Wieser (Dec 19 2022 at 12:45):

The explanation is that S ≠ ∅ is not the preferred spelling of saying that a set is not empty, S.nonempty is

Kevin Buzzard (Dec 19 2022 at 12:45):

As far as lean's concerned, this is the axiom of choice, by the way

Eric Wieser (Dec 19 2022 at 12:48):

Right, as explained in docs#set.nonempty.some

Eric Wieser (Dec 19 2022 at 12:49):

Note that if you're in a proof and your step is "pick an arbitrary element from the nonempty set", often you don't need to use choice, and can just use the cases tactic

sty (Dec 19 2022 at 14:21):

Eric Wieser said:

Note that if you're in a proof and your step is "pick an arbitrary element from the nonempty set", often you don't need to use choice, and can just use the cases tactic

How do I use cases in such a way?

Eric Wieser (Dec 19 2022 at 14:27):

If you have h : S.nonempty then use cases h with x hx

Kevin Buzzard (Dec 19 2022 at 14:38):

You've asked for a function which needs a nonconstructive proof, but if actually your goal is a Prop then you don't need to move from the Prop world to the Type world so you can avoid AC/nonconstructivism. The cases tactic won't eliminate into Type but it will work in tactic mode if your goal is a Prop.


Last updated: Dec 20 2023 at 11:08 UTC