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 #
- A coercion from m : Multiset αto aType*. Eachx : mhas two components. The first,x.1, can be obtained via the coercion↑x : α, and it yields the underlying element of the multiset. The second,x.2, is a term ofFin (m.count x), and its function is to ensure each term appears with the correct multiplicity. Note that this coercion requiresDecidableEq αdue to the definition usingMultiset.count.
- Multiset.toEnumFinsetis a- Finsetversion of this.
- Multiset.coeEmbeddingis the embedding- m ↪ α × ℕ, whose first component is the coercion and whose second component enumerates elements with multiplicity.
- Multiset.coeEquivis the equivalence- m ≃ m.toEnumFinset.
Tags #
multiset enumeration
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
- Multiset.instCoeSortType = { coe := Multiset.ToType }
As a convenience, there is a coercion from m : Type* to α by projecting onto the first
component.
Equations
- Multiset.instFintypeElemProdNatSetOfLtSndCountFst = Fintype.ofFinset (m.toFinset.biUnion fun (x : α) => Finset.map { toFun := Prod.mk x, inj' := ⋯ } (Finset.range (Multiset.count x m))) ⋯
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.
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 (↑).
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
Instances For
Equations
If s = t then there's an equivalence between the appropriate types.
Equations
Instances For
There is some equivalence between m and m.map f which respects f.
Equations
- One or more equations did not get rendered due to their size.
Instances For
One of the possible equivalences from Multiset.mapEquiv_aux, selected using choice.
Equations
- s.mapEquiv f = ↑(Quot.out (s.mapEquiv_aux f))