Documentation

Mathlib.Data.Finset.Card

Cardinality of a finite set #

This defines the cardinality of a Finset and provides induction principles for finsets.

Main declarations #

Induction principles #

TODO #

Should we add a noncomputable version?

def Finset.card {α : Type u_1} (s : Finset α) :

s.card is the number of elements of s, aka its cardinality.

Equations
Instances For
    theorem Finset.card_def {α : Type u_1} (s : Finset α) :
    Finset.card s = Multiset.card s.val
    @[simp]
    theorem Finset.card_mk {α : Type u_1} {m : Multiset α} {nodup : Multiset.Nodup m} :
    Finset.card { val := m, nodup := nodup } = Multiset.card m
    @[simp]
    theorem Finset.card_empty {α : Type u_1} :
    theorem Finset.card_le_of_subset {α : Type u_1} {s : Finset α} {t : Finset α} :
    theorem Finset.card_mono {α : Type u_1} :
    Monotone Finset.card
    @[simp]
    theorem Finset.card_eq_zero {α : Type u_1} {s : Finset α} :
    theorem Finset.card_pos {α : Type u_1} {s : Finset α} :
    theorem Finset.Nonempty.card_pos {α : Type u_1} {s : Finset α} :

    Alias of the reverse direction of Finset.card_pos.

    theorem Finset.card_ne_zero_of_mem {α : Type u_1} {s : Finset α} {a : α} (h : a s) :
    @[simp]
    theorem Finset.card_singleton {α : Type u_1} (a : α) :
    theorem Finset.card_singleton_inter {α : Type u_1} {s : Finset α} {a : α} [DecidableEq α] :
    Finset.card ({a} s) 1
    @[simp]
    theorem Finset.card_cons {α : Type u_1} {s : Finset α} {a : α} (h : ¬a s) :
    @[simp]
    theorem Finset.card_insert_of_not_mem {α : Type u_1} {s : Finset α} {a : α} [DecidableEq α] (h : ¬a s) :
    theorem Finset.card_insert_of_mem {α : Type u_1} {s : Finset α} {a : α} [DecidableEq α] (h : a s) :
    theorem Finset.card_insert_le {α : Type u_1} [DecidableEq α] (a : α) (s : Finset α) :
    theorem Finset.card_insert_eq_ite {α : Type u_1} {s : Finset α} {a : α} [DecidableEq α] :
    Finset.card (insert a s) = if a s then Finset.card s else Finset.card s + 1

    If a ∈ s is known, see also Finset.card_insert_of_mem and Finset.card_insert_of_not_mem.

    @[simp]
    theorem Finset.card_doubleton {α : Type u_1} {a : α} {b : α} [DecidableEq α] (h : a b) :
    Finset.card {a, b} = 2
    @[simp]
    theorem Finset.card_erase_of_mem {α : Type u_1} {s : Finset α} {a : α} [DecidableEq α] :

    $#(s \setminus {a}) = #s - 1$ if $a \in s$.

    @[simp]
    theorem Finset.cast_card_erase_of_mem {α : Type u_1} {a : α} [DecidableEq α] {R : Type u_3} [AddGroupWithOne R] {s : Finset α} (hs : a s) :
    ↑(Finset.card (Finset.erase s a)) = ↑(Finset.card s) - 1

    $#(s \setminus {a}) = #s - 1$ if $a \in s$. This result is casted to any additive group with 1, so that we don't have to work with -subtraction.

    @[simp]
    theorem Finset.card_erase_add_one {α : Type u_1} {s : Finset α} {a : α} [DecidableEq α] :
    theorem Finset.card_erase_lt_of_mem {α : Type u_1} {s : Finset α} {a : α} [DecidableEq α] :
    theorem Finset.card_erase_le {α : Type u_1} {s : Finset α} {a : α} [DecidableEq α] :
    theorem Finset.card_erase_eq_ite {α : Type u_1} {s : Finset α} {a : α} [DecidableEq α] :
    Finset.card (Finset.erase s a) = if a s then Finset.card s - 1 else Finset.card s

    If a ∈ s is known, see also Finset.card_erase_of_mem and Finset.erase_eq_of_not_mem.

    @[simp]
    theorem Multiset.card_toFinset {α : Type u_1} [DecidableEq α] (m : Multiset α) :
    theorem Multiset.toFinset_card_le {α : Type u_1} [DecidableEq α] (m : Multiset α) :
    Finset.card (Multiset.toFinset m) Multiset.card m
    theorem Multiset.toFinset_card_of_nodup {α : Type u_1} [DecidableEq α] {m : Multiset α} (h : Multiset.Nodup m) :
    Finset.card (Multiset.toFinset m) = Multiset.card m
    @[simp]
    theorem Finset.card_image_le {α : Type u_1} {β : Type u_2} {s : Finset α} {f : αβ} [DecidableEq β] :
    theorem Finset.card_image_of_injOn {α : Type u_1} {β : Type u_2} {s : Finset α} {f : αβ} [DecidableEq β] (H : Set.InjOn f s) :
    theorem Finset.injOn_of_card_image_eq {α : Type u_1} {β : Type u_2} {s : Finset α} {f : αβ} [DecidableEq β] (H : Finset.card (Finset.image f s) = Finset.card s) :
    Set.InjOn f s
    theorem Finset.card_image_iff {α : Type u_1} {β : Type u_2} {s : Finset α} {f : αβ} [DecidableEq β] :
    theorem Finset.card_image_of_injective {α : Type u_1} {β : Type u_2} {f : αβ} [DecidableEq β] (s : Finset α) (H : Function.Injective f) :
    theorem Finset.fiber_card_ne_zero_iff_mem_image {α : Type u_1} {β : Type u_2} (s : Finset α) (f : αβ) [DecidableEq β] (y : β) :
    Finset.card (Finset.filter (fun x => f x = y) s) 0 y Finset.image f s
    @[simp]
    theorem Finset.card_map {α : Type u_1} {β : Type u_2} {s : Finset α} (f : α β) :
    @[simp]
    theorem Finset.card_subtype {α : Type u_1} (p : αProp) [DecidablePred p] (s : Finset α) :
    theorem Finset.card_filter_le {α : Type u_1} (s : Finset α) (p : αProp) [DecidablePred p] :
    theorem Finset.eq_of_subset_of_card_le {α : Type u_1} {s : Finset α} {t : Finset α} (h : s t) (h₂ : Finset.card t Finset.card s) :
    s = t
    theorem Finset.eq_of_superset_of_card_ge {α : Type u_1} {s : Finset α} {t : Finset α} (hst : s t) (hts : Finset.card t Finset.card s) :
    t = s
    theorem Finset.subset_iff_eq_of_card_le {α : Type u_1} {s : Finset α} {t : Finset α} (h : Finset.card t Finset.card s) :
    s t s = t
    theorem Finset.map_eq_of_subset {α : Type u_1} {s : Finset α} {f : α α} (hs : Finset.map f s s) :
    theorem Finset.filter_card_eq {α : Type u_1} {s : Finset α} {p : αProp} [DecidablePred p] (h : Finset.card (Finset.filter p s) = Finset.card s) (x : α) (hx : x s) :
    p x
    theorem Finset.card_lt_card {α : Type u_1} {s : Finset α} {t : Finset α} (h : s t) :
    theorem Finset.card_eq_of_bijective {α : Type u_1} {s : Finset α} {n : } (f : (i : ) → i < nα) (hf : ∀ (a : α), a si h, f i h = a) (hf' : ∀ (i : ) (h : i < n), f i h s) (f_inj : ∀ (i j : ) (hi : i < n) (hj : j < n), f i hi = f j hji = j) :
    theorem Finset.card_congr {α : Type u_1} {β : Type u_2} {s : Finset α} {t : Finset β} (f : (a : α) → a sβ) (h₁ : ∀ (a : α) (ha : a s), f a ha t) (h₂ : ∀ (a b : α) (ha : a s) (hb : b s), f a ha = f b hba = b) (h₃ : ∀ (b : β), b ta ha, f a ha = b) :
    theorem Finset.card_le_card_of_inj_on {α : Type u_1} {β : Type u_2} {s : Finset α} {t : Finset β} (f : αβ) (hf : ∀ (a : α), a sf a t) (f_inj : ∀ (a₁ : α), a₁ s∀ (a₂ : α), a₂ sf a₁ = f a₂a₁ = a₂) :
    theorem Finset.exists_ne_map_eq_of_card_lt_of_maps_to {α : Type u_1} {β : Type u_2} {s : Finset α} {t : Finset β} (hc : Finset.card t < Finset.card s) {f : αβ} (hf : ∀ (a : α), a sf a t) :
    x, x s y, y s x y f x = f y

    If there are more pigeons than pigeonholes, then there are two pigeons in the same pigeonhole.

    theorem Finset.le_card_of_inj_on_range {α : Type u_1} {s : Finset α} {n : } (f : α) (hf : ∀ (i : ), i < nf i s) (f_inj : ∀ (i : ), i < n∀ (j : ), j < nf i = f ji = j) :
    theorem Finset.surj_on_of_inj_on_of_card_le {α : Type u_1} {β : Type u_2} {s : Finset α} {t : Finset β} (f : (a : α) → a sβ) (hf : ∀ (a : α) (ha : a s), f a ha t) (hinj : ∀ (a₁ a₂ : α) (ha₁ : a₁ s) (ha₂ : a₂ s), f a₁ ha₁ = f a₂ ha₂a₁ = a₂) (hst : Finset.card t Finset.card s) (b : β) :
    b ta ha, b = f a ha
    theorem Finset.inj_on_of_surj_on_of_card_le {α : Type u_1} {β : Type u_2} {s : Finset α} {t : Finset β} (f : (a : α) → a sβ) (hf : ∀ (a : α) (ha : a s), f a ha t) (hsurj : ∀ (b : β), b ta ha, b = f a ha) (hst : Finset.card s Finset.card t) ⦃a₁ : α ⦃a₂ : α (ha₁ : a₁ s) (ha₂ : a₂ s) (ha₁a₂ : f a₁ ha₁ = f a₂ ha₂) :
    a₁ = a₂
    @[simp]
    theorem Finset.card_disjUnion {α : Type u_1} (s : Finset α) (t : Finset α) (h : Disjoint s t) :

    Lattice structure #

    theorem Finset.card_union_le {α : Type u_1} [DecidableEq α] (s : Finset α) (t : Finset α) :
    theorem Finset.card_union_eq {α : Type u_1} {s : Finset α} {t : Finset α} [DecidableEq α] (h : Disjoint s t) :
    @[simp]
    theorem Finset.card_disjoint_union {α : Type u_1} {s : Finset α} {t : Finset α} [DecidableEq α] (h : Disjoint s t) :
    theorem Finset.card_sdiff {α : Type u_1} {s : Finset α} {t : Finset α} [DecidableEq α] (h : s t) :
    theorem Finset.card_sdiff_add_card_eq_card {α : Type u_1} [DecidableEq α] {s : Finset α} {t : Finset α} (h : s t) :
    theorem Finset.le_card_sdiff {α : Type u_1} [DecidableEq α] (s : Finset α) (t : Finset α) :
    theorem Finset.card_sdiff_add_card {α : Type u_1} {s : Finset α} {t : Finset α} [DecidableEq α] :
    theorem Finset.card_sdiff_comm {α : Type u_1} {s : Finset α} {t : Finset α} [DecidableEq α] (h : Finset.card s = Finset.card t) :
    theorem Finset.filter_card_add_filter_neg_card_eq_card {α : Type u_1} {s : Finset α} (p : αProp) [DecidablePred p] [(x : α) → Decidable ¬p x] :
    theorem Finset.exists_intermediate_set {α : Type u_1} {A : Finset α} {B : Finset α} (i : ) (h₁ : i + Finset.card B Finset.card A) (h₂ : B A) :
    C, B C C A Finset.card C = i + Finset.card B

    Given a set A and a set B inside it, we can shrink A to any appropriate size, and keep B inside it.

    theorem Finset.exists_smaller_set {α : Type u_1} (A : Finset α) (i : ) (h₁ : i Finset.card A) :
    B, B A Finset.card B = i

    We can shrink A to any smaller size.

    theorem Finset.exists_subset_or_subset_of_two_mul_lt_card {α : Type u_1} [DecidableEq α] {X : Finset α} {Y : Finset α} {n : } (hXY : 2 * n < Finset.card (X Y)) :
    C, n < Finset.card C (C X C Y)

    Explicit description of a finset from its card #

    theorem Finset.card_eq_one {α : Type u_1} {s : Finset α} :
    Finset.card s = 1 a, s = {a}
    theorem Finset.exists_eq_insert_iff {α : Type u_1} [DecidableEq α] {s : Finset α} {t : Finset α} :
    (a x, insert a s = t) s t Finset.card s + 1 = Finset.card t
    theorem Finset.card_le_one {α : Type u_1} {s : Finset α} :
    Finset.card s 1 ∀ (a : α), a s∀ (b : α), b sa = b
    theorem Finset.card_le_one_iff {α : Type u_1} {s : Finset α} :
    Finset.card s 1 ∀ {a b : α}, a sb sa = b
    theorem Finset.card_le_one_iff_subset_singleton {α : Type u_1} {s : Finset α} [Nonempty α] :
    Finset.card s 1 x, s {x}

    A Finset of a subsingleton type has cardinality at most one.

    theorem Finset.one_lt_card {α : Type u_1} {s : Finset α} :
    1 < Finset.card s a, a s b, b s a b
    theorem Finset.one_lt_card_iff {α : Type u_1} {s : Finset α} :
    1 < Finset.card s a b, a s b s a b
    theorem Finset.two_lt_card_iff {α : Type u_1} {s : Finset α} :
    2 < Finset.card s a b c, a s b s c s a b a c b c
    theorem Finset.two_lt_card {α : Type u_1} {s : Finset α} :
    2 < Finset.card s a, a s b, b s c, c s a b a c b c
    theorem Finset.exists_ne_of_one_lt_card {α : Type u_1} {s : Finset α} (hs : 1 < Finset.card s) (a : α) :
    b, b s b a
    theorem Finset.exists_of_one_lt_card_pi {ι : Type u_3} {α : ιType u_4} [(i : ι) → DecidableEq (α i)] {s : Finset ((i : ι) → α i)} (h : 1 < Finset.card s) :
    i, 1 < Finset.card (Finset.image (fun x => x i) s) ∀ (ai : α i), Finset.filter (fun x => x i = ai) s s

    If a Finset in a Pi type is nontrivial (has at least two elements), then its projection to some factor is nontrivial, and the fibers of the projection are proper subsets.

    theorem Finset.card_eq_succ {α : Type u_1} {s : Finset α} {n : } [DecidableEq α] :
    Finset.card s = n + 1 a t, ¬a t insert a t = s Finset.card t = n
    theorem Finset.card_eq_two {α : Type u_1} {s : Finset α} [DecidableEq α] :
    Finset.card s = 2 x y, x y s = {x, y}
    theorem Finset.card_eq_three {α : Type u_1} {s : Finset α} [DecidableEq α] :
    Finset.card s = 3 x y z, x y x z y z s = {x, y, z}

    Inductions #

    def Finset.strongInduction {α : Type u_1} {p : Finset αSort u_3} (H : (s : Finset α) → ((t : Finset α) → t sp t) → p s) (s : Finset α) :
    p s

    Suppose that, given objects defined on all strict subsets of any finset s, one knows how to define an object on s. Then one can inductively define an object on all finsets, starting from the empty set and iterating. This can be used either to define data, or to prove properties.

    Equations
    Instances For
      theorem Finset.strongInduction_eq {α : Type u_1} {p : Finset αSort u_3} (H : (s : Finset α) → ((t : Finset α) → t sp t) → p s) (s : Finset α) :
      def Finset.strongInductionOn {α : Type u_1} {p : Finset αSort u_3} (s : Finset α) :
      ((s : Finset α) → ((t : Finset α) → t sp t) → p s) → p s

      Analogue of strongInduction with order of arguments swapped.

      Equations
      Instances For
        theorem Finset.strongInductionOn_eq {α : Type u_1} {p : Finset αSort u_3} (s : Finset α) (H : (s : Finset α) → ((t : Finset α) → t sp t) → p s) :
        theorem Finset.case_strong_induction_on {α : Type u_1} [DecidableEq α] {p : Finset αProp} (s : Finset α) (h₀ : p ) (h₁ : (a : α) → (s : Finset α) → ¬a s((t : Finset α) → t sp t) → p (insert a s)) :
        p s
        def Finset.strongDownwardInduction {α : Type u_1} {p : Finset αSort u_3} {n : } (H : (t₁ : Finset α) → ({t₂ : Finset α} → Finset.card t₂ nt₁ t₂p t₂) → Finset.card t₁ np t₁) (s : Finset α) :
        Finset.card s np s

        Suppose that, given that p t can be defined on all supersets of s of cardinality less than n, one knows how to define p s. Then one can inductively define p s for all finsets s of cardinality less than n, starting from finsets of card n and iterating. This can be used either to define data, or to prove properties.

        Equations
        Instances For
          theorem Finset.strongDownwardInduction_eq {α : Type u_1} {n : } {p : Finset αSort u_3} (H : (t₁ : Finset α) → ({t₂ : Finset α} → Finset.card t₂ nt₁ t₂p t₂) → Finset.card t₁ np t₁) (s : Finset α) :
          def Finset.strongDownwardInductionOn {α : Type u_1} {n : } {p : Finset αSort u_3} (s : Finset α) (H : (t₁ : Finset α) → ({t₂ : Finset α} → Finset.card t₂ nt₁ t₂p t₂) → Finset.card t₁ np t₁) :
          Finset.card s np s

          Analogue of strongDownwardInduction with order of arguments swapped.

          Equations
          Instances For
            theorem Finset.strongDownwardInductionOn_eq {α : Type u_1} {n : } {p : Finset αSort u_3} (s : Finset α) (H : (t₁ : Finset α) → ({t₂ : Finset α} → Finset.card t₂ nt₁ t₂p t₂) → Finset.card t₁ np t₁) :
            (fun a => Finset.strongDownwardInductionOn s H a) = H s fun {t} ht x => Finset.strongDownwardInductionOn t H ht
            theorem Finset.lt_wf {α : Type u_3} :