Documentation

Mathlib.Data.Finset.Defs

Finite sets #

Terms of type Finset α are one way of talking about finite subsets of α in Mathlib. Below, Finset α is defined as a structure with 2 fields:

  1. val is a Multiset α of elements;
  2. nodup is a proof that val has no duplicates.

Finsets in Lean are constructive in that they have an underlying List that enumerates their elements. In particular, any function that uses the data of the underlying list cannot depend on its ordering. This is handled on the Multiset level by multiset API, so in most cases one needn't worry about it explicitly.

Finsets give a basic foundation for defining finite sums and products over types:

  1. ∑ i ∈ (s : Finset α), f i;
  2. ∏ i ∈ (s : Finset α), f i.

Lean refers to these operations as big operators. More information can be found in Mathlib/Algebra/BigOperators/Group/Finset/Defs.lean.

Finsets are directly used to define fintypes in Lean. A Fintype α instance for a type α consists of a universal Finset α containing every term of α, called univ. See Mathlib/Data/Fintype/Basic.lean.

Finset.card, the size of a finset is defined in Mathlib/Data/Finset/Card.lean. This is then used to define Fintype.card, the size of a type.

File structure #

This file defines the Finset type and the membership and subset relations between finsets. Most constructions involving Finsets have been split off to their own files.

Main definitions #

Tags #

finite sets, finset

structure Finset (α : Type u_4) :
Type u_4

Finset α is the type of finite sets of elements of α. It is implemented as a multiset (a list up to permutation) which has no duplicate elements.

Instances For
    theorem Finset.eq_of_veq {α : Type u_1} {s t : Finset α} :
    s.val = t.vals = t
    @[simp]
    theorem Finset.val_inj {α : Type u_1} {s t : Finset α} :
    s.val = t.val s = t
    @[implicit_reducible]
    instance Finset.decidableEq {α : Type u_1} [DecidableEq α] :
    Equations

    set coercion #

    @[implicit_reducible]
    instance Finset.instSetLike {α : Type u_1} :
    SetLike (Finset α) α

    Convert a finset to a set in the natural way.

    Equations
    theorem Finset.mem_def {α : Type u_1} {a : α} {s : Finset α} :
    a s a s.val
    @[simp]
    theorem Finset.mem_val {α : Type u_1} {a : α} {s : Finset α} :
    (a s.val) = (a s)
    @[simp]
    theorem Finset.mem_mk {α : Type u_1} {a : α} {s : Multiset α} {nd : s.Nodup} :
    a { val := s, nodup := nd } a s
    @[implicit_reducible]
    instance Finset.decidableMem {α : Type u_1} [_h : DecidableEq α] (a : α) (s : Finset α) :
    Equations
    @[simp]
    theorem Finset.forall_mem_not_eq {α : Type u_1} {s : Finset α} {a : α} :
    (∀ (b : α), b s¬a = b) ¬a s
    @[simp]
    theorem Finset.forall_mem_not_eq' {α : Type u_1} {s : Finset α} {a : α} :
    (∀ (b : α), b s¬b = a) ¬a s
    @[implicit_reducible]
    Equations
    theorem Finset.mem_coe {α : Type u_1} {a : α} {s : Finset α} :
    a s a s
    @[simp]
    theorem Finset.setOf_mem {α : Type u_4} {s : Finset α} :
    {a : α | a s} = s
    theorem Finset.coe_mem {α : Type u_1} {s : Finset α} (x : s) :
    x s
    theorem Finset.mk_coe {α : Type u_1} {s : Finset α} (x : s) {h : x s} :
    x, h = x
    @[implicit_reducible]
    instance Finset.decidableMem' {α : Type u_1} [DecidableEq α] (a : α) (s : Finset α) :
    Decidable (a s)
    Equations

    extensionality #

    theorem Finset.ext {α : Type u_1} {s₁ s₂ : Finset α} (h : ∀ (a : α), a s₁ a s₂) :
    s₁ = s₂
    theorem Finset.ext_iff {α : Type u_1} {s₁ s₂ : Finset α} :
    s₁ = s₂ ∀ (a : α), a s₁ a s₂
    theorem Finset.coe_inj {α : Type u_1} {s₁ s₂ : Finset α} :
    s₁ = s₂ s₁ = s₂

    type coercion #

    theorem Finset.forall_coe {α : Type u_4} (s : Finset α) (p : sProp) :
    (∀ (x : s), p x) ∀ (x : α) (h : x s), p x, h
    theorem Finset.exists_coe {α : Type u_4} (s : Finset α) (p : sProp) :
    ( (x : s), p x) (x : α), (h : x s), p x, h
    instance Finset.PiFinsetCoe.canLift (ι : Type u_4) (α : ιType u_5) [_ne : ∀ (i : ι), Nonempty (α i)] (s : Finset ι) :
    CanLift ((i : s) → α i) ((i : ι) → α i) (fun (f : (i : ι) → α i) (i : s) => f i) fun (x : (i : s) → α i) => True
    instance Finset.PiFinsetCoe.canLift' (ι : Type u_4) (α : Type u_5) [_ne : Nonempty α] (s : Finset ι) :
    CanLift (sα) (ια) (fun (f : ια) (i : s) => f i) fun (x : sα) => True
    instance Finset.FinsetCoe.canLift {α : Type u_1} (s : Finset α) :
    CanLift α (↥s) Subtype.val fun (a : α) => a s
    theorem Finset.coe_sort_coe {α : Type u_1} (s : Finset α) :
    s = s

    Subset and strict subset relations #

    @[deprecated "This is now a syntactic identity" (since := "2026-05-24")]
    theorem Finset.subset_of_le {α : Type u_1} {s t : Finset α} :
    stst
    theorem Finset.subset_def {α : Type u_1} {s t : Finset α} :
    st s.val t.val
    theorem Finset.ssubset_def {α : Type u_1} {s t : Finset α} :
    st st ¬ts
    theorem Finset.Subset.refl {α : Type u_1} (s : Finset α) :
    ss
    theorem Finset.Subset.rfl {α : Type u_1} {s : Finset α} :
    ss
    theorem Finset.subset_of_eq {α : Type u_1} {s t : Finset α} (h : s = t) :
    st
    theorem Finset.Subset.trans {α : Type u_1} {s₁ s₂ s₃ : Finset α} :
    s₁s₂s₂s₃s₁s₃
    theorem Finset.Superset.trans {α : Type u_1} {s₁ s₂ s₃ : Finset α} :
    s₁s₂s₂s₃s₁s₃
    theorem Finset.mem_of_subset {α : Type u_1} {s₁ s₂ : Finset α} {a : α} :
    s₁s₂a s₁a s₂
    theorem Finset.notMem_mono {α : Type u_1} {s t : Finset α} (h : st) {a : α} :
    ¬a t¬a s
    theorem Finset.not_mem_subset {α : Type u_1} {s t : Finset α} (h : st) {a : α} :
    ¬a t¬a s

    Alias of Finset.notMem_mono.

    theorem Finset.Subset.antisymm {α : Type u_1} {s₁ s₂ : Finset α} (H₁ : s₁s₂) (H₂ : s₂s₁) :
    s₁ = s₂
    theorem Finset.subset_iff {α : Type u_1} {s₁ s₂ : Finset α} :
    s₁s₂ ∀ ⦃x : α⦄, x s₁x s₂
    theorem Finset.subset_iff_notMem {α : Type u_1} {s t : Finset α} :
    st ∀ ⦃a : α⦄, ¬a t¬a s
    theorem Finset.coe_subset {α : Type u_1} {s₁ s₂ : Finset α} :
    s₁s₂ s₁s₂
    @[simp]
    theorem Finset.val_le_iff {α : Type u_1} {s₁ s₂ : Finset α} :
    s₁.val s₂.val s₁s₂
    theorem Finset.Subset.antisymm_iff {α : Type u_1} {s₁ s₂ : Finset α} :
    s₁ = s₂ s₁s₂ s₂s₁
    theorem Finset.not_subset {α : Type u_1} {s t : Finset α} :
    ¬st (x : α), x s ¬x t
    @[deprecated "This is now a syntactic equality" (since := "2026-05-24")]
    theorem Finset.le_eq_subset {α : Type u_1} :
    (fun (x1 x2 : Finset α) => x1x2) = fun (x1 x2 : Finset α) => x1x2
    @[deprecated "This is now a syntactic equality" (since := "2026-05-24")]
    theorem Finset.lt_eq_subset {α : Type u_1} :
    (fun (x1 x2 : Finset α) => x1x2) = fun (x1 x2 : Finset α) => x1x2
    @[deprecated "This is now a syntactic equality" (since := "2026-05-24")]
    theorem Finset.le_iff_subset {α : Type u_1} {s₁ s₂ : Finset α} :
    s₁s₂ s₁s₂
    @[deprecated "This is now a syntactic equality" (since := "2026-05-24")]
    theorem Finset.lt_iff_ssubset {α : Type u_1} {s₁ s₂ : Finset α} :
    s₁s₂ s₁s₂
    theorem Finset.coe_ssubset {α : Type u_1} {s₁ s₂ : Finset α} :
    s₁s₂ s₁s₂
    @[simp]
    theorem Finset.val_lt_iff {α : Type u_1} {s₁ s₂ : Finset α} :
    s₁.val < s₂.val s₁s₂
    theorem Finset.ssubset_iff_subset_ne {α : Type u_1} {s t : Finset α} :
    st st s t
    theorem Finset.ssubset_iff_of_subset {α : Type u_1} {s₁ s₂ : Finset α} (h : s₁s₂) :
    s₁s₂ (x : α), x s₂ ¬x s₁
    theorem Finset.ssubset_of_ssubset_of_subset {α : Type u_1} {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁s₂) (hs₂s₃ : s₂s₃) :
    s₁s₃
    theorem Finset.ssubset_of_subset_of_ssubset {α : Type u_1} {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁s₂) (hs₂s₃ : s₂s₃) :
    s₁s₃
    theorem Finset.exists_of_ssubset {α : Type u_1} {s₁ s₂ : Finset α} (h : s₁s₂) :
    (x : α), x s₂ ¬x s₁
    instance Finset.isWellFounded_ssubset {α : Type u_1} :
    IsWellFounded (Finset α) fun (x1 x2 : Finset α) => x1x2

    Order embedding from Finset α to Set α #

    def Finset.coeEmb {α : Type u_1} :

    Coercion to Set α as an OrderEmbedding.

    Equations
    Instances For
      @[simp]
      theorem Finset.coe_coeEmb {α : Type u_1} :

      Assorted results #

      These results can be defined using the current imports, but deserve to be given a nicer home.

      @[implicit_reducible]
      instance Finset.decidableDforallFinset {α : Type u_1} {s : Finset α} {p : (a : α) → a sProp} [_hp : (a : α) → (h : a s) → Decidable (p a h)] :
      Decidable (∀ (a : α) (h : a s), p a h)
      Equations
      @[implicit_reducible]
      instance Finset.instDecidableRelSubset {α : Type u_1} [DecidableEq α] :
      DecidableRel fun (x1 x2 : Finset α) => x1x2
      Equations
      @[implicit_reducible]
      instance Finset.instDecidableRelSSubset {α : Type u_1} [DecidableEq α] :
      DecidableRel fun (x1 x2 : Finset α) => x1x2
      Equations
      @[implicit_reducible]
      instance Finset.decidableDExistsFinset {α : Type u_1} {s : Finset α} {p : (a : α) → a sProp} [_hp : (a : α) → (h : a s) → Decidable (p a h)] :
      Decidable ( (a : α), (h : a s), p a h)
      Equations
      @[implicit_reducible]
      instance Finset.decidableExistsAndFinset {α : Type u_1} {s : Finset α} {p : αProp} [_hp : (a : α) → Decidable (p a)] :
      Decidable ( (a : α), a s p a)
      Equations
      @[implicit_reducible]
      instance Finset.decidableExistsAndFinsetCoe {α : Type u_1} {s : Finset α} {p : αProp} [DecidablePred p] :
      Decidable ( (a : α), a s p a)
      Equations
      @[implicit_reducible]
      instance Finset.decidableEqPiFinset {α : Type u_1} {s : Finset α} {β : αType u_4} [_h : (a : α) → DecidableEq (β a)] :
      DecidableEq ((a : α) → a sβ a)

      decidable equality for functions whose domain is bounded by finsets

      Equations
      theorem Finset.pairwise_subtype_iff_pairwise_finset' {α : Type u_1} {β : Type u_2} {s : Finset α} (r : ββProp) (f : αβ) :
      Pairwise (Function.onFun r fun (x : s) => f x) (↑s).Pairwise (Function.onFun r f)
      theorem Finset.pairwise_subtype_iff_pairwise_finset {α : Type u_1} {s : Finset α} (r : ααProp) :
      Pairwise (Function.onFun r fun (x : s) => x) (↑s).Pairwise r