Documentation

Mathlib.Data.Multiset.Fintype

Multiset coercion to type #

This module defines a CoeSort instance for multisets and gives it a Fintype instance. It also defines Multiset.toEnumFinset, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing Finset theory.

Main definitions #

Tags #

multiset enumeration

def Multiset.ToType {α : Type u_1} [DecidableEq α] (m : Multiset α) :
Type u_1

Auxiliary definition for the CoeSort instance. This prevents the CoeOut m α instance from inadvertently applying to other sigma types.

Equations
Instances For
    instance instCoeSortMultisetType {α : Type u_1} [DecidableEq α] :

    Create a type that has the same number of elements as the multiset. Terms of this type are triples ⟨x, ⟨i, h⟩⟩ where x : α, i : ℕ, and h : i < m.count x. This way repeated elements of a multiset appear multiple times from different values of i.

    Equations
    • instCoeSortMultisetType = { coe := Multiset.ToType }
    @[match_pattern, reducible]
    def Multiset.mkToType {α : Type u_1} [DecidableEq α] (m : Multiset α) (x : α) (i : Fin (Multiset.count x m)) :

    Constructor for terms of the coercion of m to a type. This helps Lean pick up the correct instances.

    Equations
    Instances For

      As a convenience, there is a coercion from m : Type* to α by projecting onto the first component.

      Equations
      • instCoeSortMultisetType.instCoeOutToType = { coe := fun (x : Multiset.ToType m) => x.fst }
      theorem Multiset.coe_mk {α : Type u_1} [DecidableEq α] {m : Multiset α} {x : α} {i : Fin (Multiset.count x m)} :
      (Multiset.mkToType m x i).fst = x
      @[simp]
      theorem Multiset.coe_mem {α : Type u_1} [DecidableEq α] {m : Multiset α} {x : Multiset.ToType m} :
      x.fst m
      @[simp]
      theorem Multiset.forall_coe {α : Type u_1} [DecidableEq α] {m : Multiset α} (p : Multiset.ToType mProp) :
      (∀ (x : Multiset.ToType m), p x) ∀ (x : α) (i : Fin (Multiset.count x m)), p { fst := x, snd := i }
      @[simp]
      theorem Multiset.exists_coe {α : Type u_1} [DecidableEq α] {m : Multiset α} (p : Multiset.ToType mProp) :
      (∃ (x : Multiset.ToType m), p x) ∃ (x : α) (i : Fin (Multiset.count x m)), p { fst := x, snd := i }
      instance instFintypeElemProdNatSetOfLtInstLTNatSndCountFst {α : Type u_1} [DecidableEq α] {m : Multiset α} :
      Fintype {p : α × | p.2 < Multiset.count p.1 m}
      Equations
      • One or more equations did not get rendered due to their size.
      def Multiset.toEnumFinset {α : Type u_1} [DecidableEq α] (m : Multiset α) :

      Construct a finset whose elements enumerate the elements of the multiset m. The component is used to differentiate between equal elements: if x appears n times then (x, 0), ..., and (x, n-1) appear in the Finset.

      Equations
      Instances For
        @[simp]
        theorem Multiset.mem_toEnumFinset {α : Type u_1} [DecidableEq α] (m : Multiset α) (p : α × ) :
        theorem Multiset.mem_of_mem_toEnumFinset {α : Type u_1} [DecidableEq α] {m : Multiset α} {p : α × } (h : p Multiset.toEnumFinset m) :
        p.1 m
        theorem Multiset.toEnumFinset_mono {α : Type u_1} [DecidableEq α] {m₁ : Multiset α} {m₂ : Multiset α} (h : m₁ m₂) :
        @[simp]
        theorem Multiset.toEnumFinset_subset_iff {α : Type u_1} [DecidableEq α] {m₁ : Multiset α} {m₂ : Multiset α} :
        @[simp]
        theorem Multiset.coeEmbedding_apply {α : Type u_1} [DecidableEq α] (m : Multiset α) (x : Multiset.ToType m) :
        (Multiset.coeEmbedding m) x = (x.fst, x.snd)

        The embedding from a multiset into α × ℕ where the second coordinate enumerates repeats. If you are looking for the function m → α, that would be plain (↑).

        Equations
        Instances For
          @[simp]
          theorem Multiset.coeEquiv_symm_apply_fst {α : Type u_1} [DecidableEq α] (m : Multiset α) (x : { x : α × // x Multiset.toEnumFinset m }) :
          ((Multiset.coeEquiv m).symm x).fst = (x).1
          @[simp]
          @[simp]
          theorem Multiset.coeEquiv_symm_apply_snd_val {α : Type u_1} [DecidableEq α] (m : Multiset α) (x : { x : α × // x Multiset.toEnumFinset m }) :
          ((Multiset.coeEquiv m).symm x).snd = (x).2
          def Multiset.coeEquiv {α : Type u_1} [DecidableEq α] (m : Multiset α) :

          Another way to coerce a Multiset to a type is to go through m.toEnumFinset and coerce that Finset to a type.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            @[irreducible]
            instance Multiset.fintypeCoe {α : Type u_1} [DecidableEq α] {m : Multiset α} :
            Equations
            theorem Multiset.toEnumFinset_filter_eq {α : Type u_1} [DecidableEq α] (m : Multiset α) (x : α) :
            Finset.filter (fun (p : α × ) => x = p.1) (Multiset.toEnumFinset m) = Finset.map { toFun := Prod.mk x, inj' := } (Finset.range (Multiset.count x m))
            @[simp]
            theorem Multiset.map_toEnumFinset_fst {α : Type u_1} [DecidableEq α] (m : Multiset α) :
            @[simp]
            theorem Multiset.map_univ_coe {α : Type u_1} [DecidableEq α] (m : Multiset α) :
            Multiset.map (fun (x : Multiset.ToType m) => x.fst) Finset.univ.val = m
            @[simp]
            theorem Multiset.map_univ {α : Type u_1} [DecidableEq α] {β : Type u_2} (m : Multiset α) (f : αβ) :
            Multiset.map (fun (x : Multiset.ToType m) => f x.fst) Finset.univ.val = Multiset.map f m
            @[simp]
            theorem Multiset.card_toEnumFinset {α : Type u_1} [DecidableEq α] (m : Multiset α) :
            (Multiset.toEnumFinset m).card = Multiset.card m
            @[simp]
            theorem Multiset.card_coe {α : Type u_1} [DecidableEq α] (m : Multiset α) :
            Fintype.card (Multiset.ToType m) = Multiset.card m
            theorem Multiset.sum_eq_sum_coe {α : Type u_1} [DecidableEq α] [AddCommMonoid α] (m : Multiset α) :
            Multiset.sum m = Finset.sum Finset.univ fun (x : Multiset.ToType m) => x.fst
            theorem Multiset.prod_eq_prod_coe {α : Type u_1} [DecidableEq α] [CommMonoid α] (m : Multiset α) :
            Multiset.prod m = Finset.prod Finset.univ fun (x : Multiset.ToType m) => x.fst
            theorem Multiset.sum_toEnumFinset {α : Type u_1} [DecidableEq α] {β : Type u_2} [AddCommMonoid β] (m : Multiset α) (f : αβ) :
            (Finset.sum (Multiset.toEnumFinset m) fun (x : α × ) => f x.1 x.2) = Finset.sum Finset.univ fun (x : Multiset.ToType m) => f x.fst x.snd
            theorem Multiset.prod_toEnumFinset {α : Type u_1} [DecidableEq α] {β : Type u_2} [CommMonoid β] (m : Multiset α) (f : αβ) :
            (Finset.prod (Multiset.toEnumFinset m) fun (x : α × ) => f x.1 x.2) = Finset.prod Finset.univ fun (x : Multiset.ToType m) => f x.fst x.snd