Multiset coercion to type #
This module defines a hasCoeToSort 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 #
- A coercion from
m : Multiset αto aType*. Forx : m, then there is a coercion↑x : α, andx.2is a term ofFin (m.count x). The second component is what ensures each term appears with the correct multiplicity. Note that this coercion requiresdecidableEq αdue toMultiset.count. Multiset.toEnumFinsetis aFinsetversion of this.Multiset.coeEmbeddingis the embeddingm ↪ α × ℕ, whose first component is the coercion and whose second component enumerates elements with multiplicity.Multiset.coeEquivis the equivalencem ≃ m.toEnumFinset.
Tags #
multiset enumeration
Auxiliary definition for the hasCoeToSort instance. This prevents the hasCoe m α
instance from inadvertently applying to other sigma types. One should not use this definition
directly.
Equations
- Multiset.ToType m = ((x : α) × Fin (Multiset.count x m))
Instances For
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 with different values of i.
Equations
- instCoeSortMultisetType = { coe := Multiset.ToType }
Constructor for terms of the coercion of m to a type.
This helps Lean pick up the correct instances.
Equations
- Multiset.mkToType m x i = { fst := x, snd := i }
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 }
Equations
- One or more equations did not get rendered due to their size.
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
- Multiset.toEnumFinset m = Set.toFinset {p : α × ℕ | p.2 < Multiset.count p.1 m}
Instances For
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
- One or more equations did not get rendered due to their size.
Instances For
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
Equations
- Multiset.fintypeCoe = Fintype.ofEquiv { x : α × ℕ // x ∈ Multiset.toEnumFinset m } (Multiset.coeEquiv m).symm