Zulip Chat Archive

Stream: Is there code for X?

Topic: Converse to `Multiset.toFinset_card_of_nodup`?


Jz Pan (Nov 11 2023 at 23:07):

I think we only have this in mathlib:

theorem Multiset.toFinset_card_of_nodup {α : Type*} [DecidableEq α] {m : Multiset α} (h : Multiset.Nodup m) :
    Finset.card (Multiset.toFinset m) = Multiset.card m

But in fact its converse is also true.

Jz Pan (Nov 11 2023 at 23:30):

theorem Multiset.toFinset_card_eq_card_iff_nodup {α : Type*} [DecidableEq α] {m : Multiset α} :
    m.toFinset.card = card m  m.Nodup := by
  intro h
  rw [ dedup_eq_self]
  by_contra h1
  have : m.toFinset.card < card m := card_lt_of_lt (Ne.lt_of_le h1 (dedup_le m))
  linarith only [h, this],
  toFinset_card_of_nodup

Junyan Xu (Nov 12 2023 at 01:04):

(deleted)

Junyan Xu (Nov 12 2023 at 01:05):

@loogle Finset.card, Multiset.Nodup

loogle (Nov 12 2023 at 01:05):

:search: Finset.card_mk, Multiset.toFinset_card_of_nodup

Yaël Dillies (Nov 12 2023 at 08:50):

In fact you should first prove card m.dedup = card m ↔ m.Nodup.

Eric Wieser (Nov 12 2023 at 09:32):

@loogle Multiset.card, Multiset.dedup

Eric Wieser (Nov 12 2023 at 09:32):

@loogle Multiset.card, Multiset.dedup

loogle (Nov 12 2023 at 09:32):

:search: Multiset.card_toFinset

Ruben Van de Velde (Nov 12 2023 at 10:09):

open Multiset in
example (α : Type*) [DecidableEq α] (m : Multiset α) : card m.dedup = card m  m.Nodup :=
  .trans fun h => eq_of_le_of_card_le (dedup_le m) h.ge, congr_arg _ dedup_eq_self

Jz Pan (Nov 12 2023 at 21:46):

Ruben Van de Velde said:

open Multiset in
example (α : Type*) [DecidableEq α] (m : Multiset α) : card m.dedup = card m  m.Nodup :=
  .trans fun h => eq_of_le_of_card_le (dedup_le m) h.ge, congr_arg _ dedup_eq_self

Cool! This is much shorter than my proof. Should this be added in mathlib?

Ruben Van de Velde (Nov 12 2023 at 21:49):

What do you think, @Yaël Dillies ? :)

Jz Pan (Nov 19 2023 at 20:58):

I opened the PR #8515. Comments are welcomed.


Last updated: Dec 20 2023 at 11:08 UTC