Multisets
These are implemented as the quotient of a list by permutations.
Equations
- multiset.has_coe = {coe := quot.mk setoid.r}
Equations
- multiset.has_decidable_eq s₁ s₂ = quotient.rec_on_subsingleton₂ s₁ s₂ (λ (l₁ l₂ : list α), decidable_of_iff' (l₁ ≈ l₂) _)
defines a size for a multiset by referring to the size of the underlying list
Equations
- s.sizeof = quot.lift_on s sizeof multiset.sizeof._proof_1
Equations
- multiset.has_sizeof = {sizeof := multiset.sizeof _inst_1}
0 : multiset α is the empty set
Equations
Equations
- multiset.has_zero = {zero := multiset.zero α}
Equations
- multiset.has_emptyc = {emptyc := 0}
Equations
- multiset.inhabited = {default := 0}
cons a s is the multiset which contains s plus one more
instance of a.
Equations
Dependent recursor on multisets.
TODO: should be @[recursor 6], but then the definition of multiset.pi fails with a stack
overflow in whnf.
Equations
- multiset.rec C_0 C_cons C_cons_heq m = quotient.hrec_on m (list.rec C_0 (λ (a : α) (l : list α) (b : (λ (l : list α), C ⟦l⟧) l), C_cons a ⟦l⟧ b)) _
Equations
- m.rec_on C_0 C_cons C_cons_heq = multiset.rec C_0 C_cons C_cons_heq m
a ∈ s means that a has nonzero multiplicity in s.
Equations
- multiset.mem a s = quot.lift_on s (λ (l : list α), a ∈ l) _
Equations
- multiset.has_mem = {mem := multiset.mem α}
Equations
s ⊆ t is the lift of the list subset relation. It means that any
element with nonzero multiplicity in s has nonzero multiplicity in t,
but it does not imply that the multiplicity of a in s is less or equal than in t;
see s ≤ t for this relation.
Equations
s ≤ t means that s is a sublist of t (up to permutation).
Equivalently, s ≤ t means that count a s ≤ count a t for all a.
Equations
- s.le t = quotient.lift_on₂ s t list.subperm multiset.le._proof_1
Equations
- multiset.partial_order = {le := multiset.le α, lt := preorder.lt._default multiset.le, le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _}
The cardinality of a multiset is the sum of the multiplicities of all its elements, or simply the length of the underlying list.
Equations
- s.card = quot.lift_on s list.length multiset.card._proof_1
Equations
- s.strong_induction_on = λ (ih : Π (s : multiset α), (Π (t : multiset α), t < s → p t) → p s), ih s (λ (t : multiset α) (h : t < s), t.strong_induction_on ih)
Equations
- multiset.has_singleton = {singleton := λ (a : α), a :: 0}
Equations
The sum of two multisets is the lift of the list append operation.
This adds the multiplicities of each element,
i.e. count a (s + t) = count a s + count a t.
Equations
- multiset.has_add = {add := multiset.add α}
Equations
- multiset.ordered_cancel_add_comm_monoid = {add := has_add.add multiset.has_add, add_assoc := _, zero := 0, zero_add := _, add_zero := _, add_comm := _, add_left_cancel := _, add_right_cancel := _, le := partial_order.le multiset.partial_order, lt := partial_order.lt multiset.partial_order, le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _, add_le_add_left := _, le_of_add_le_add_left := _}
Equations
- multiset.canonically_ordered_add_monoid = {add := ordered_cancel_add_comm_monoid.add multiset.ordered_cancel_add_comm_monoid, add_assoc := _, zero := ordered_cancel_add_comm_monoid.zero multiset.ordered_cancel_add_comm_monoid, zero_add := _, add_zero := _, add_comm := _, le := ordered_cancel_add_comm_monoid.le multiset.ordered_cancel_add_comm_monoid, lt := ordered_cancel_add_comm_monoid.lt multiset.ordered_cancel_add_comm_monoid, le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _, add_le_add_left := _, lt_of_add_lt_add_left := _, bot := 0, bot_le := _, le_iff_exists_add := _}
repeat a n is the multiset containing only a with multiplicity n.
Equations
- multiset.repeat a n = ↑(list.repeat a n)
erase s a is the multiset that subtracts 1 from the
multiplicity of a.
map f s is the lift of the list map operation. The multiplicity
of b in map f s is the number of a ∈ s (counting multiplicity)
such that f a = b.
Equations
- multiset.map f s = quot.lift_on s (λ (l : list α), ↑(list.map f l)) _
Equations
- _ = _
foldl f H b s is the lift of the list operation foldl f b l,
which folds f over the multiset. It is well defined when f is right-commutative,
that is, f (f b a₁) a₂ = f (f b a₂) a₁.
Equations
- multiset.foldl f H b s = quot.lift_on s (λ (l : list α), list.foldl f b l) _
foldr f H b s is the lift of the list operation foldr f b l,
which folds f over the multiset. It is well defined when f is left-commutative,
that is, f a₁ (f a₂ b) = f a₂ (f a₁ b).
Equations
- multiset.foldr f H b s = quot.lift_on s (λ (l : list α), list.foldr f b l) _
Product of a multiset given a commutative monoid structure on α.
prod {a, b, c} = a * b * c
Equations
- multiset.prod = multiset.foldr has_mul.mul multiset.prod._proof_1 1
join S, where S is a multiset of multisets, is the lift of the list join
operation, that is, the union of all the sets.
join {{1, 2}, {1, 2}, {0, 1}} = {0, 1, 1, 1, 2, 2}
Equations
bind s f is the monad bind operation, defined as join (map f s).
It is the union of f a as a ranges over s.
Equations
- s.bind f = (multiset.map f s).join
sigma s t is the dependent version of product. It is the sum of
(a, b) as a ranges over s and b ranges over t a.
Equations
- s.sigma t = s.bind (λ (a : α), multiset.map (sigma.mk a) (t a))
Lift of the list pmap operation. Map a partial function f over a multiset
s whose elements are all in the domain of f.
Equations
- multiset.pmap f s = quot.rec_on s (λ (l : list α) (H : ∀ (a : α), a ∈ quot.mk setoid.r l → p a), ↑(list.pmap f l H)) _
"Attach" a proof that a ∈ s to each element a in s to produce
a multiset on {x // x ∈ s}.
Equations
- s.attach = multiset.pmap subtype.mk s _
Equations
- multiset.decidable_forall_multiset = quotient.rec_on_subsingleton m (λ (l : list α), decidable_of_iff (∀ (a : α), a ∈ l → p a) _)
Equations
- multiset.decidable_dforall_multiset = decidable_of_decidable_of_iff multiset.decidable_forall_multiset multiset.decidable_dforall_multiset._proof_3
decidable equality for functions whose domain is bounded by multisets
Equations
- multiset.decidable_eq_pi_multiset = λ (f g : Π (a : α), a ∈ m → β a), decidable_of_iff (∀ (a : α) (h : a ∈ m), f a h = g a h) _
Equations
- multiset.decidable_dexists_multiset = decidable_of_decidable_of_iff multiset.decidable_exists_multiset multiset.decidable_dexists_multiset._proof_3
s - t is the multiset such that
count a (s - t) = count a s - count a t for all a.
Equations
- multiset.has_sub = {sub := multiset.sub (λ (a b : α), _inst_1 a b)}
s ∪ t is the lattice join operation with respect to the
multiset ≤. The multiplicity of a in s ∪ t is the maximum
of the multiplicities in s and t.
Equations
- multiset.has_union = {union := multiset.union (λ (a b : α), _inst_1 a b)}
s ∩ t is the lattice meet operation with respect to the
multiset ≤. The multiplicity of a in s ∩ t is the minimum
of the multiplicities in s and t.
Equations
- multiset.has_inter = {inter := multiset.inter (λ (a b : α), _inst_1 a b)}
Equations
- multiset.lattice = {sup := has_union.union multiset.has_union, le := partial_order.le multiset.partial_order, lt := partial_order.lt multiset.partial_order, le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _, le_sup_left := _, le_sup_right := _, sup_le := _, inf := has_inter.inter multiset.has_inter, inf_le_left := _, inf_le_right := _, le_inf := _}
Equations
- multiset.semilattice_inf_bot = {bot := 0, le := lattice.le multiset.lattice, lt := lattice.lt multiset.lattice, le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _, bot_le := _, inf := lattice.inf multiset.lattice, inf_le_left := _, inf_le_right := _, le_inf := _}
filter p s returns the elements in s (with the same multiplicities)
which satisfy p, and removes the rest.
Equations
- multiset.filter p s = quot.lift_on s (λ (l : list α), ↑(list.filter p l)) _
filter_map f s is a combination filter/map operation on s.
The function f : α → option β is applied to each element of s;
if f a is some b then b is added to the result, otherwise
a is removed from the resulting multiset.
Equations
- multiset.filter_map f s = quot.lift_on s (λ (l : list α), ↑(list.filter_map f l)) _
countp
countp p s counts the number of elements of s (with multiplicity) that
satisfy p.
Equations
- multiset.countp p s = quot.lift_on s (list.countp p) _
Equations
count a s is the multiplicity of a in s.
Equations
- multiset.count a = multiset.countp (eq a)
Equations
Equations
- multiset.distrib_lattice = {sup := lattice.sup multiset.lattice, le := lattice.le multiset.lattice, lt := lattice.lt multiset.lattice, le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _, le_sup_left := _, le_sup_right := _, sup_le := _, inf := lattice.inf multiset.lattice, inf_le_left := _, inf_le_right := _, le_inf := _, le_sup_inf := _}
Equations
- multiset.semilattice_sup_bot = {bot := 0, le := lattice.le multiset.lattice, lt := lattice.lt multiset.lattice, le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _, bot_le := _, sup := lattice.sup multiset.lattice, le_sup_left := _, le_sup_right := _, sup_le := _}
- zero : ∀ {α : Type u_1} {β : Type u_2} (r : α → β → Prop), multiset.rel r 0 0
- cons : ∀ {α : Type u_1} {β : Type u_2} (r : α → β → Prop) {a : α} {b : β} {as : multiset α} {bs : multiset β}, r a b → multiset.rel r as bs → multiset.rel r (a :: as) (b :: bs)
rel r s t -- lift the relation r between two elements to a relation between s and t,
s.t. there is a one-to-one mapping betweem elements in s and t following r.
pairwise r m states that there exists a list of the elements s.t. r holds pairwise on this list.
Equations
- multiset.pairwise r m = ∃ (l : list α), m = ↑l ∧ list.pairwise r l
Given a proof hp that there exists a unique a ∈ l such that p a, choose p l hp returns
that a.
Equations
- multiset.choose_x p l = quotient.rec_on l (λ (l' : list α) (ex_unique : ∃! (a : α), a ∈ ⟦l'⟧ ∧ p a), list.choose_x p l' _) _
Equations
- multiset.choose p l hp = ↑(multiset.choose_x p l hp)
The equivalence between lists and multisets of a subsingleton type.
Equations
- multiset.subsingleton_equiv α = {to_fun := coe coe_to_lift, inv_fun := quot.lift id _, left_inv := _, right_inv := _}