Sum and difference of multisets #
This file defines the following operations on multisets:
Add (Multiset α)
instance:s + t
adds the multiplicities of the elements ofs
andt
Sub (Multiset α)
instance:s - t
subtracts the multiplicities of the elements ofs
andt
Multiset.erase
:s.erase x
reduces the multiplicity ofx
ins
by one.
Notation (defined later) #
s + t
: The multiset for which the number of occurrences of eacha
is the sum of the occurrences ofa
ins
andt
.s - t
: The multiset for which the number of occurrences of eacha
is the difference of the occurrences ofa
ins
andt
.
Additive monoid #
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
- s₁.add s₂ = Quotient.liftOn₂ s₁ s₂ (fun (l₁ l₂ : List α) => ↑(l₁ ++ l₂)) ⋯
Instances For
Equations
- Multiset.instAdd = { add := Multiset.add }
Alias of the forward direction of Multiset.add_le_add_iff_left
.
Alias of the reverse direction of Multiset.add_le_add_iff_left
.
Alias of the forward direction of Multiset.add_le_add_iff_right
.
Alias of the reverse direction of Multiset.add_le_add_iff_right
.
Erasing one copy of an element #
Subtraction #
s - t
is the multiset such that count a (s - t) = count a s - count a t
for all a
.
(note that it is truncated subtraction, so count a (s - t) = 0
if count a s ≤ count a t
).
Equations
- s.sub t = Quotient.liftOn₂ s t (fun (l₁ l₂ : List α) => ↑(l₁.diff l₂)) ⋯
Instances For
Equations
- Multiset.instSub = { sub := Multiset.sub }
This is a special case of tsub_zero
, which should be used instead of this.
This is needed to prove OrderedSub (Multiset α)
.
This is a special case of tsub_le_iff_right
, which should be used instead of this.
This is needed to prove OrderedSub (Multiset α)
.
This is a special case of tsub_le_iff_left
, which should be used instead of this.