Zulip Chat Archive

Stream: new members

Topic: Cardinality of s: Set (Fin n)


Ilmārs Cīrulis (Mar 10 2025 at 21:12):

Let's have s: Set (Fin n). If I want to define and prove theorem that it's cardinality is less or equal to n, the only way is to use Set.encard, right?

Ilmārs Cīrulis (Mar 10 2025 at 21:16):

I'm trying to prove

import Mathlib

theorem t {n} (s: Set (Fin n)): s.encard  n := by
  sorry

Ilmārs Cīrulis (Mar 10 2025 at 21:29):

It seems I did it.

import Mathlib

theorem t {n} (s: Set (Fin n)): s.encard  n := by
  have H: Finite (Fin n) := Finite.of_fintype (Fin n)
  have H0: (@Set.univ (Fin n)).encard = n := by
    simp [Set.encard_univ]
  simp [<- H0, Set.encard_le_encard]

Eric Paul (Mar 10 2025 at 21:40):

The following also works

import Mathlib

theorem t {n} (s: Set (Fin n)): s.encard  n := by
  simp [Set.Finite.encard_eq_coe_toFinset_card (s := s) (by toFinite_tac),
    card_finset_fin_le]

You can also use ncard

import Mathlib

theorem t {n} (s: Set (Fin n)): s.ncard  n := by
  simp [Set.ncard_eq_toFinset_card s, card_finset_fin_le]

Ilmārs Cīrulis (Mar 10 2025 at 22:16):

What's the best (computable) way to count the number of fins in the set, if the membership is decidable?

import Mathlib

def count {n} (s: Set (Fin n)) [ x, Decidable (x  s)]:  := sorry

Aaron Liu (Mar 10 2025 at 22:18):

Maybe s.toFinset.card?

Ilmārs Cīrulis (Mar 10 2025 at 22:20):

Yes, that works. Big thank you!


Last updated: May 02 2025 at 03:31 UTC