Zulip Chat Archive

Stream: new members

Topic: Prove Finset has cardinality 1


Nathan (Oct 02 2025 at 06:01):

example (s : Finset ) (a : ) (h : a  s) : {x  s | x = a}.card = 1 := sorry

How do you prove this? I tried proving {x ∈ s | x = a} = {a}, but no luck

Yongxi Lin (Aaron) (Oct 02 2025 at 06:37):

If you can prove {x ∈ s | x = a} = {a}, then I believe simp should give you result. To prove {x ∈ s | x = a} = {a}, you can use the ext tactic.

Kyle Miller (Oct 02 2025 at 07:48):

I guessed that there would be a Finset.card_filter lemma, then simp turned out to basically prove it.

import Mathlib

example (s : Finset ) (a : ) (h : a  s) : {x  s | x = a}.card = 1 := by
  rw [Finset.card_filter]
  simp
  assumption

The proof can be compressed to simp [Finset.card_filter, h].

Nathan (Oct 02 2025 at 13:55):

thanks!

Nathan (Oct 02 2025 at 20:47):

Why does this work though? Finset.card_filter changes it to a sum, why is that better?

Ruben Van de Velde (Oct 02 2025 at 21:00):

If you replace simp by simp?, it shows what lemmas were used:

simp only [Finset.sum_ite_eq', ite_eq_left_iff, zero_ne_one, imp_false, Decidable.not_not]

Ruben Van de Velde (Oct 02 2025 at 21:01):

So notably docs#Finset.sum_ite_eq' shows there's at most one term that contributes to the sum

Nathan (Oct 02 2025 at 21:03):

oh yeah that would do it

Nathan (Oct 02 2025 at 21:04):

it should be possible with ext too, right? i was struggling to show a ∈ {a}. maybe i'll take another look

Matt Diamond (Oct 02 2025 at 21:28):

i was struggling to show a ∈ {a}

you can use docs#Finset.mem_singleton_self if you're talking about Finset singletons (there's a separate lemma for sets)

Nathan (Oct 02 2025 at 21:43):

thanks!

Nathan (Oct 02 2025 at 22:04):

can simp and rw be used on the constants in the context, or only on the goal?

Robin Arnez (Oct 02 2025 at 22:06):

simp ... at <hypothesis>, rw ... at <hypothesis> for hypothesis in the context.

Nathan (Oct 02 2025 at 22:08):

oh awesome

Nathan (Oct 02 2025 at 22:16):

example (s : Finset ) (a : ) (h : a  s) : {x  s | x = a}.card = 1 :=
  have : {x  s | x = a} = {a} := by
    ext t
    apply Iff.intro
    · intro ts
      simp at ts
      rw [ts.right]
      exact Finset.mem_singleton_self a
    · intro ta
      simp at ta
      simp
      sorry
  sorry

getting there... am i on the right track?

Aaron Liu (Oct 02 2025 at 22:19):

you can just simp it

import Mathlib

example (s : Finset ) (a : ) (h : a  s) : {x  s | x = a}.card = 1 := by
  have : {x  s | x = a} = {a} := by
    simp [Finset.ext_iff, h]
  rw [this]
  rfl

Nathan (Oct 02 2025 at 22:37):

:astonished:

Ruben Van de Velde (Oct 02 2025 at 22:38):

rfl there is not great, especially given that docs#Finset.card_singleton is right there

Nathan (Oct 02 2025 at 23:17):

the thing i've been thinking about regarding tactics is, when changes are made it could break people's code

Nathan (Oct 03 2025 at 02:35):

why do you have to open classical to use excluded middle, but not for Nat.lt_trichotomy?

Nathan (Oct 03 2025 at 02:36):

i'm working on a proof that's currently 241 lines, which i fully expect to be reduced to like 20 lines if someone takes a look at it :joy:

Nathan (Oct 03 2025 at 02:38):

thanks for the tip earlier, Aaron

Matt Diamond (Oct 03 2025 at 05:22):

I don't think you have to open classical to use excluded middle

Matt Diamond (Oct 03 2025 at 05:24):

you can just use docs#em ... it uses choice under the hood, but you don't have to open classical to take advantage of that

Kenny Lau (Oct 03 2025 at 09:56):

Nathan said:

why do you have to open classical to use excluded middle, but not for Nat.lt_trichotomy?

the first part is not true, but the second part is because you can prove that particular instance of excluded middle without using the axiom

Kenny Lau (Oct 03 2025 at 09:57):

when we say choiceless lean rejects excluded middle, it doesn't mean every instance of excluded middle is literally false; some instances can still be proved

Kenny Lau (Oct 03 2025 at 09:59):

what open Classical does is enable if then else for any condition


Last updated: Dec 20 2025 at 21:32 UTC