Mapping and folding multisets #
Main definitions #
Multiset.map:map f sappliesfto each element ofs.Multiset.foldl:foldl f b spicks elements out ofsand appliesf (f ... b x₁) x₂.Multiset.foldr:foldr f b spicks elements out ofsand appliesf x₁ (f ... x₂ b).
TODO #
Many lemmas about Multiset.map are proven in Mathlib/Data/Multiset/Filter.lean:
should we switch the import direction?
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.liftOn s (fun (l : List α) => ↑(List.map f l)) ⋯
Instances For
@[simp]
theorem Multiset.mem_map_of_injective {α : Type u_1} {β : Type v} {f : α → β} (H : Function.Injective f) {a : α} {s : Multiset α} :
theorem Multiset.eq_of_mem_map_const {α : Type u_1} {β : Type v} {b₁ b₂ : β} {l : List α} (h : b₁ ∈ map (Function.const α b₂) ↑l) :
theorem Multiset.map_erase {α : Type u_1} {β : Type v} [DecidableEq α] [DecidableEq β] (f : α → β) (hf : Function.Injective f) (x : α) (s : Multiset α) :
theorem Multiset.map_erase_of_mem {α : Type u_1} {β : Type v} [DecidableEq α] [DecidableEq β] (f : α → β) (s : Multiset α) {x : α} (h : x ∈ s) :
theorem Multiset.map_surjective_of_surjective {α : Type u_1} {β : Type v} {f : α → β} (hf : Function.Surjective f) :
def Multiset.foldl {α : Type u_1} {β : Type v} (f : β → α → β) [RightCommutative f] (b : β) (s : Multiset α) :
β
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 b s = Quot.liftOn s (fun (l : List α) => List.foldl f b l) ⋯
Instances For
@[simp]
theorem Multiset.foldl_zero {α : Type u_1} {β : Type v} (f : β → α → β) [RightCommutative f] (b : β) :
@[simp]
theorem Multiset.foldl_cons {α : Type u_1} {β : Type v} (f : β → α → β) [RightCommutative f] (b : β) (a : α) (s : Multiset α) :
def Multiset.foldr {α : Type u_1} {β : Type v} (f : α → β → β) [LeftCommutative f] (b : β) (s : Multiset α) :
β
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 b s = Quot.liftOn s (fun (l : List α) => List.foldr f b l) ⋯
Instances For
@[simp]
theorem Multiset.foldr_zero {α : Type u_1} {β : Type v} (f : α → β → β) [LeftCommutative f] (b : β) :
@[simp]
theorem Multiset.foldr_cons {α : Type u_1} {β : Type v} (f : α → β → β) [LeftCommutative f] (b : β) (a : α) (s : Multiset α) :
@[simp]
theorem Multiset.foldr_singleton {α : Type u_1} {β : Type v} (f : α → β → β) [LeftCommutative f] (b : β) (a : α) :
@[simp]
theorem Multiset.coe_foldr {α : Type u_1} {β : Type v} (f : α → β → β) [LeftCommutative f] (b : β) (l : List α) :
@[simp]
theorem Multiset.coe_foldl {α : Type u_1} {β : Type v} (f : β → α → β) [RightCommutative f] (b : β) (l : List α) :
theorem Multiset.coe_foldr_swap {α : Type u_1} {β : Type v} (f : α → β → β) [LeftCommutative f] (b : β) (l : List α) :
theorem Multiset.foldr_swap {α : Type u_1} {β : Type v} (f : α → β → β) [LeftCommutative f] (b : β) (s : Multiset α) :
theorem Multiset.foldl_swap {α : Type u_1} {β : Type v} (f : β → α → β) [RightCommutative f] (b : β) (s : Multiset α) :
theorem Multiset.foldr_induction' {α : Type u_1} {β : Type v} (f : α → β → β) [LeftCommutative f] (x : β) (q : α → Prop) (p : β → Prop) (s : Multiset α) (hpqf : ∀ (a : α) (b : β), q a → p b → p (f a b)) (px : p x) (q_s : ∀ (a : α), a ∈ s → q a) :
p (foldr f x s)
theorem Multiset.foldr_induction {α : Type u_1} (f : α → α → α) [LeftCommutative f] (x : α) (p : α → Prop) (s : Multiset α) (p_f : ∀ (a b : α), p a → p b → p (f a b)) (px : p x) (p_s : ∀ (a : α), a ∈ s → p a) :
p (foldr f x s)
theorem Multiset.foldl_induction' {α : Type u_1} {β : Type v} (f : β → α → β) [RightCommutative f] (x : β) (q : α → Prop) (p : β → Prop) (s : Multiset α) (hpqf : ∀ (a : α) (b : β), q a → p b → p (f b a)) (px : p x) (q_s : ∀ (a : α), a ∈ s → q a) :
p (foldl f x s)
theorem Multiset.foldl_induction {α : Type u_1} (f : α → α → α) [RightCommutative f] (x : α) (p : α → Prop) (s : Multiset α) (p_f : ∀ (a b : α), p a → p b → p (f b a)) (px : p x) (p_s : ∀ (a : α), a ∈ s → p a) :
p (foldl f x s)
Map for partial functions #
@[simp]
Subtraction #
theorem Multiset.map_injective {α : Type u_1} {β : Type v} {f : α → β} (hf : Function.Injective f) :
theorem Multiset.Nodup.of_map {α : Type u_1} {β : Type v} {s : Multiset α} (f : α → β) :
(Multiset.map f s).Nodup → s.Nodup
theorem Multiset.Nodup.map {α : Type u_1} {β : Type v} {f : α → β} {s : Multiset α} (hf : Function.Injective f) :
s.Nodup → (Multiset.map f s).Nodup
theorem Multiset.nodup_map_iff_of_injective {α : Type u_1} {β : Type v} {s : Multiset α} {f : α → β} (d : Function.Injective f) :
Alias of the reverse direction of Multiset.nodup_attach.
theorem Multiset.map_eq_map_of_bij_of_nodup {α : Type u_1} {β : Type v} {γ : Type u_2} (f : α → γ) (g : β → γ) {s : Multiset α} {t : Multiset β} (hs : s.Nodup) (ht : t.Nodup) (i : (a : α) → a ∈ s → β) (hi : ∀ (a : α) (ha : a ∈ s), i a ha ∈ t) (i_inj : ∀ (a₁ : α) (ha₁ : a₁ ∈ s) (a₂ : α) (ha₂ : a₂ ∈ s), i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂) (i_surj : ∀ (b : β), b ∈ t → ∃ (a : α), ∃ (ha : a ∈ s), i a ha = b) (h : ∀ (a : α) (ha : a ∈ s), f a = g (i a ha)) :