The areas / V03. Sets, finite structures and big operators
Mathlib.Data.Multiset.MapFold
80 declarations. Mathlib docs · Source
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?
Multiset.map
Multiset.fold
Map for partial functions
Subtraction
Lift a relation to Multisets
theorem Multiset.foldr.congr_simp E1 #
∀ {α : Type u_1} {β : Type v} (f f_1 : α → β → β) (e_f : f = f_1) [inst : LeftCommutative f] (b b_1 : β),
b = b_1 → ∀ (s s_1 : Multiset α), s = s_1 → Multiset.foldr f b s = Multiset.foldr f_1 b_1 s_1
def Multiset.map E3 #
{α : Type u_1} → {β : Type v} → (α → β) → Multiset α → Multiset β
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.
theorem Multiset.map_congr E0 #
∀ {α : Type u_1} {β : Type v} {f g : α → β} {s t : Multiset α},
s = t → (∀ x ∈ t, f x = g x) → Multiset.map f s = Multiset.map g t
theorem Multiset.map_hcongr E0 #
∀ {α : Type u_1} {β β' : Type v} {m : Multiset α} {f : α → β} {f' : α → β'},
β = β' → (∀ a ∈ m, f a ≍ f' a) → Multiset.map f m ≍ Multiset.map f' m
theorem Multiset.forall_mem_map_iff E0 #
∀ {α : Type u_1} {β : Type v} {f : α → β} {p : β → Prop} {s : Multiset α},
(∀ y ∈ Multiset.map f s, p y) ↔ ∀ x ∈ s, p (f x)
theorem Multiset.map_coe E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β) (l : List α), Multiset.map f ↑l = ↑(List.map f l)
theorem Multiset.map_zero E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β), Multiset.map f 0 = 0
theorem Multiset.map_cons E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β) (a : α) (s : Multiset α), Multiset.map f (a ::ₘ s) = f a ::ₘ Multiset.map f s
theorem Multiset.map_comp_cons E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β) (t : α),
Multiset.map f ∘ Multiset.cons t = Multiset.cons (f t) ∘ Multiset.map f
theorem Multiset.map_singleton E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β) (a : α), Multiset.map f {a} = {f a}
theorem Multiset.map_replicate E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β) (k : ℕ) (a : α),
Multiset.map f (Multiset.replicate k a) = Multiset.replicate k (f a)
theorem Multiset.map_add E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β) (s t : Multiset α),
Multiset.map f (s + t) = Multiset.map f s + Multiset.map f t
instance Multiset.canLift E0 #
∀ {α : Type u_1} {β : Type v} (c : β → α) (p : α → Prop) [CanLift α β c p],
CanLift (Multiset α) (Multiset β) (Multiset.map c) fun s ↦ ∀ x ∈ s, p x
If each element of s : Multiset α can be lifted to β, then s can be lifted to
Multiset β.
theorem Multiset.mem_map E0 #
∀ {α : Type u_1} {β : Type v} {f : α → β} {b : β} {s : Multiset α}, b ∈ Multiset.map f s ↔ ∃ a ∈ s, f a = b
theorem Multiset.card_map E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β) (s : Multiset α), (Multiset.map f s).card = s.card
theorem Multiset.map_eq_zero E0 #
∀ {α : Type u_1} {β : Type v} {s : Multiset α} {f : α → β}, Multiset.map f s = 0 ↔ s = 0
theorem Multiset.zero_eq_map E0 #
∀ {α : Type u_1} {β : Type v} {s : Multiset α} {f : α → β}, 0 = Multiset.map f s ↔ s = 0
theorem Multiset.mem_map_of_mem E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β) {a : α} {s : Multiset α}, a ∈ s → f a ∈ Multiset.map f s
theorem Multiset.map_eq_singleton E0 #
∀ {α : Type u_1} {β : Type v} {f : α → β} {s : Multiset α} {b : β}, Multiset.map f s = {b} ↔ ∃ a, s = {a} ∧ f a = b
theorem Multiset.map_eq_cons E0 #
∀ {α : Type u_1} {β : Type v} [inst : DecidableEq α] (f : α → β) (s : Multiset α) (t : Multiset β) (b : β),
(∃ a ∈ s, f a = b ∧ Multiset.map f (s.erase a) = t) ↔ Multiset.map f s = b ::ₘ t
theorem Multiset.mem_map_of_injective E0 #
∀ {α : Type u_1} {β : Type v} {f : α → β},
Function.Injective f → ∀ {a : α} {s : Multiset α}, f a ∈ Multiset.map f s ↔ a ∈ s
theorem Multiset.map_map E0 #
∀ {α : Type u_1} {β : Type v} {γ : Type u_2} (g : β → γ) (f : α → β) (s : Multiset α),
Multiset.map g (Multiset.map f s) = Multiset.map (g ∘ f) s
theorem Multiset.map_id E0 #
∀ {α : Type u_1} (s : Multiset α), Multiset.map id s = s
theorem Multiset.map_id' E0 #
∀ {α : Type u_1} (s : Multiset α), Multiset.map (fun x ↦ x) s = s
theorem Multiset.map_const E0 #
∀ {α : Type u_1} {β : Type v} (s : Multiset α) (b : β),
Multiset.map (Function.const α b) s = Multiset.replicate s.card b
theorem Multiset.map_const' E0 #
∀ {α : Type u_1} {β : Type v} (s : Multiset α) (b : β), Multiset.map (fun x ↦ b) s = Multiset.replicate s.card b
theorem Multiset.map_le_map E0 #
∀ {α : Type u_1} {β : Type v} {f : α → β} {s t : Multiset α}, s ≤ t → Multiset.map f s ≤ Multiset.map f t
theorem Multiset.map_lt_map E0 #
∀ {α : Type u_1} {β : Type v} {f : α → β} {s t : Multiset α}, s < t → Multiset.map f s < Multiset.map f t
theorem Multiset.map_mono E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β), Monotone (Multiset.map f)
theorem Multiset.map_strictMono E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β), StrictMono (Multiset.map f)
theorem Multiset.map_subset_map E0 #
∀ {α : Type u_1} {β : Type v} {f : α → β} {s t : Multiset α}, s ⊆ t → Multiset.map f s ⊆ Multiset.map f t
theorem Multiset.map_erase E0 #
∀ {α : Type u_1} {β : Type v} [inst : DecidableEq α] [inst_1 : DecidableEq β] (f : α → β),
Function.Injective f → ∀ (x : α) (s : Multiset α), Multiset.map f (s.erase x) = (Multiset.map f s).erase (f x)
theorem Multiset.map_erase_of_mem E0 #
∀ {α : Type u_1} {β : Type v} [inst : DecidableEq α] [inst_1 : DecidableEq β] (f : α → β) (s : Multiset α) {x : α},
x ∈ s → Multiset.map f (s.erase x) = (Multiset.map f s).erase (f x)
theorem Multiset.map_surjective_of_surjective E0 #
∀ {α : Type u_1} {β : Type v} {f : α → β}, Function.Surjective f → Function.Surjective (Multiset.map f)
def Multiset.foldl E3 #
{α : Type u_1} → {β : Type v} → (f : β → α → β) → [RightCommutative f] → β → 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₁.
theorem Multiset.foldl_zero E0 #
∀ {α : Type u_1} {β : Type v} (f : β → α → β) [inst : RightCommutative f] (b : β), Multiset.foldl f b 0 = b
theorem Multiset.foldl_cons E0 #
∀ {α : Type u_1} {β : Type v} (f : β → α → β) [inst : RightCommutative f] (b : β) (a : α) (s : Multiset α),
Multiset.foldl f b (a ::ₘ s) = Multiset.foldl f (f b a) s
theorem Multiset.foldl_add E0 #
∀ {α : Type u_1} {β : Type v} (f : β → α → β) [inst : RightCommutative f] (b : β) (s t : Multiset α),
Multiset.foldl f b (s + t) = Multiset.foldl f (Multiset.foldl f b s) t
def Multiset.foldr E3 #
{α : Type u_1} → {β : Type v} → (f : α → β → β) → [LeftCommutative f] → β → 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).
theorem Multiset.foldr_zero E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β → β) [inst : LeftCommutative f] (b : β), Multiset.foldr f b 0 = b
theorem Multiset.foldr_cons E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β → β) [inst : LeftCommutative f] (b : β) (a : α) (s : Multiset α),
Multiset.foldr f b (a ::ₘ s) = f a (Multiset.foldr f b s)
theorem Multiset.foldr_singleton E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β → β) [inst : LeftCommutative f] (b : β) (a : α), Multiset.foldr f b {a} = f a b
theorem Multiset.foldr_add E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β → β) [inst : LeftCommutative f] (b : β) (s t : Multiset α),
Multiset.foldr f b (s + t) = Multiset.foldr f (Multiset.foldr f b t) s
theorem Multiset.coe_foldr E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β → β) [inst : LeftCommutative f] (b : β) (l : List α),
Multiset.foldr f b ↑l = List.foldr f b l
theorem Multiset.coe_foldl E0 #
∀ {α : Type u_1} {β : Type v} (f : β → α → β) [inst : RightCommutative f] (b : β) (l : List α),
Multiset.foldl f b ↑l = List.foldl f b l
theorem Multiset.coe_foldr_swap E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β → β) [inst : LeftCommutative f] (b : β) (l : List α),
Multiset.foldr f b ↑l = List.foldl (fun x y ↦ f y x) b l
theorem Multiset.foldr_swap E1 #
∀ {α : Type u_1} {β : Type v} (f : α → β → β) [inst : LeftCommutative f] (b : β) (s : Multiset α),
Multiset.foldr f b s = Multiset.foldl (fun x y ↦ f y x) b s
theorem Multiset.foldl_swap E1 #
∀ {α : Type u_1} {β : Type v} (f : β → α → β) [inst : RightCommutative f] (b : β) (s : Multiset α),
Multiset.foldl f b s = Multiset.foldr (fun x y ↦ f y x) b s
theorem Multiset.foldr_induction' E1 #
∀ {α : Type u_1} {β : Type v} (f : α → β → β) [inst : LeftCommutative f] (x : β) (q : α → Prop) (p : β → Prop)
(s : Multiset α), (∀ (a : α) (b : β), q a → p b → p (f a b)) → p x → (∀ a ∈ s, q a) → p (Multiset.foldr f x s)
theorem Multiset.foldr_induction E1 #
∀ {α : Type u_1} (f : α → α → α) [inst : LeftCommutative f] (x : α) (p : α → Prop) (s : Multiset α),
(∀ (a b : α), p a → p b → p (f a b)) → p x → (∀ a ∈ s, p a) → p (Multiset.foldr f x s)
theorem Multiset.foldl_induction' E1 #
∀ {α : Type u_1} {β : Type v} (f : β → α → β) [inst : RightCommutative f] (x : β) (q : α → Prop) (p : β → Prop)
(s : Multiset α), (∀ (a : α) (b : β), q a → p b → p (f b a)) → p x → (∀ a ∈ s, q a) → p (Multiset.foldl f x s)
theorem Multiset.foldl_induction E1 #
∀ {α : Type u_1} (f : α → α → α) [inst : RightCommutative f] (x : α) (p : α → Prop) (s : Multiset α),
(∀ (a b : α), p a → p b → p (f b a)) → p x → (∀ a ∈ s, p a) → p (Multiset.foldl f x s)
theorem Multiset.pmap_eq_map E1 #
∀ {α : Type u_1} {β : Type v} (p : α → Prop) (f : α → β) (s : Multiset α) (H : ∀ a ∈ s, p a),
Multiset.pmap (fun a x ↦ f a) s H = Multiset.map f s
theorem Multiset.map_pmap E0 #
∀ {α : Type u_1} {β : Type v} {γ : Type u_2} {p : α → Prop} (g : β → γ) (f : (a : α) → p a → β) (s : Multiset α)
(H : ∀ a ∈ s, p a), Multiset.map g (Multiset.pmap f s H) = Multiset.pmap (fun a h ↦ g (f a h)) s H
theorem Multiset.pmap_eq_map_attach E1 #
∀ {α : Type u_1} {β : Type v} {p : α → Prop} (f : (a : α) → p a → β) (s : Multiset α) (H : ∀ a ∈ s, p a),
Multiset.pmap f s H = Multiset.map (fun x ↦ f ↑x ⋯) s.attach
theorem Multiset.attach_map_val' E0 #
∀ {α : Type u_1} {β : Type v} (s : Multiset α) (f : α → β), Multiset.map (fun i ↦ f ↑i) s.attach = Multiset.map f s
theorem Multiset.attach_map_val E0 #
∀ {α : Type u_1} (s : Multiset α), Multiset.map Subtype.val s.attach = s
theorem Multiset.attach_cons E1 #
∀ {α : Type u_1} (a : α) (m : Multiset α), (a ::ₘ m).attach = ⟨a, ⋯⟩ ::ₘ Multiset.map (fun p ↦ ⟨↑p, ⋯⟩) m.attach
theorem Multiset.erase_attach_map_val E0 #
∀ {α : Type u_1} [inst : DecidableEq α] (s : Multiset α) (x : { x // x ∈ s }),
Multiset.map Subtype.val (s.attach.erase x) = s.erase ↑x
theorem Multiset.erase_attach_map E1 #
∀ {α : Type u_1} {β : Type v} [inst : DecidableEq α] (s : Multiset α) (f : α → β) (x : { x // x ∈ s }),
Multiset.map (fun j ↦ f ↑j) (s.attach.erase x) = Multiset.map f (s.erase ↑x)
theorem Multiset.sub_eq_fold_erase E1 #
∀ {α : Type u_1} [inst : DecidableEq α] (s t : Multiset α), s - t = Multiset.foldl Multiset.erase s t
theorem Multiset.rel_map_left E1 #
∀ {α : Type u_1} {β : Type v} {γ : Type u_2} {r : α → β → Prop} {s : Multiset γ} {f : γ → α} {t : Multiset β},
Multiset.Rel r (Multiset.map f s) t ↔ Multiset.Rel (fun a b ↦ r (f a) b) s t
theorem Multiset.rel_map_right E1 #
∀ {α : Type u_1} {β : Type v} {γ : Type u_2} {r : α → β → Prop} {s : Multiset α} {t : Multiset γ} {f : γ → β},
Multiset.Rel r s (Multiset.map f t) ↔ Multiset.Rel (fun a b ↦ r a (f b)) s t
theorem Multiset.rel_map E1 #
∀ {α : Type u_1} {β : Type v} {γ : Type u_2} {δ : Type u_3} {p : γ → δ → Prop} {s : Multiset α} {t : Multiset β}
{f : α → γ} {g : β → δ},
Multiset.Rel p (Multiset.map f s) (Multiset.map g t) ↔ Multiset.Rel (fun a b ↦ p (f a) (g b)) s t
theorem Multiset.map_eq_map E0 #
∀ {α : Type u_1} {β : Type v} {f : α → β},
Function.Injective f → ∀ {s t : Multiset α}, Multiset.map f s = Multiset.map f t ↔ s = t
theorem Multiset.map_injective E0 #
∀ {α : Type u_1} {β : Type v} {f : α → β}, Function.Injective f → Function.Injective (Multiset.map f)
theorem Multiset.map_mk_eq_map_mk_of_rel E0 #
∀ {α : Type u_1} {r : α → α → Prop} {s t : Multiset α},
Multiset.Rel r s t → Multiset.map (Quot.mk r) s = Multiset.map (Quot.mk r) t
theorem Multiset.exists_multiset_eq_map_quot_mk E0 #
∀ {α : Type u_1} {r : α → α → Prop} (s : Multiset (Quot r)), ∃ t, s = Multiset.map (Quot.mk r) t
theorem Multiset.induction_on_multiset_quot E1 #
∀ {α : Type u_1} {r : α → α → Prop} {p : Multiset (Quot r) → Prop} (s : Multiset (Quot r)),
(∀ (s : Multiset α), p (Multiset.map (Quot.mk r) s)) → p s
theorem Multiset.Nodup.of_map E1 #
∀ {α : Type u_1} {β : Type v} {s : Multiset α} (f : α → β), (Multiset.map f s).Nodup → s.Nodup
theorem Multiset.Nodup.map_on E0 #
∀ {α : Type u_1} {β : Type v} {s : Multiset α} {f : α → β},
(∀ x ∈ s, ∀ y ∈ s, f x = f y → x = y) → s.Nodup → (Multiset.map f s).Nodup
theorem Multiset.Nodup.map E1 #
∀ {α : Type u_1} {β : Type v} {f : α → β} {s : Multiset α}, Function.Injective f → s.Nodup → (Multiset.map f s).Nodup
theorem Multiset.nodup_map_iff_of_inj_on E1 #
∀ {α : Type u_1} {β : Type v} {s : Multiset α} {f : α → β},
(∀ x ∈ s, ∀ y ∈ s, f x = f y → x = y) → ((Multiset.map f s).Nodup ↔ s.Nodup)
theorem Multiset.nodup_map_iff_of_injective E1 #
∀ {α : Type u_1} {β : Type v} {s : Multiset α} {f : α → β}, Function.Injective f → ((Multiset.map f s).Nodup ↔ s.Nodup)
theorem Multiset.inj_on_of_nodup_map E1 #
∀ {α : Type u_1} {β : Type v} {f : α → β} {s : Multiset α},
(Multiset.map f s).Nodup → ∀ x ∈ s, ∀ y ∈ s, f x = f y → x = y
theorem Multiset.nodup_map_iff_inj_on E1 #
∀ {α : Type u_1} {β : Type v} {f : α → β} {s : Multiset α},
s.Nodup → ((Multiset.map f s).Nodup ↔ ∀ x ∈ s, ∀ y ∈ s, f x = f y → x = y)
theorem Multiset.Nodup.pmap E1 #
∀ {α : Type u_1} {β : Type v} {p : α → Prop} {f : (a : α) → p a → β} {s : Multiset α} {H : ∀ a ∈ s, p a},
(∀ (a : α) (ha : p a) (b : α) (hb : p b), f a ha = f b hb → a = b) → s.Nodup → (Multiset.pmap f s H).Nodup
theorem Multiset.nodup_attach E0 #
∀ {α : Type u_1} {s : Multiset α}, s.attach.Nodup ↔ s.Nodup
theorem Multiset.Nodup.attach E1 #
∀ {α : Type u_1} {s : Multiset α}, s.Nodup → s.attach.Nodup
Alias of the reverse direction of Multiset.nodup_attach.
theorem Multiset.map_eq_map_of_bij_of_nodup E0 #
∀ {α : Type u_1} {β : Type v} {γ : Type u_2} (f : α → γ) (g : β → γ) {s : Multiset α} {t : Multiset β},
s.Nodup →
t.Nodup →
∀ (i : (a : α) → a ∈ s → β),
(∀ (a : α) (ha : a ∈ s), i a ha ∈ t) →
(∀ (a₁ : α) (ha₁ : a₁ ∈ s) (a₂ : α) (ha₂ : a₂ ∈ s), i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂) →
(∀ b ∈ t, ∃ a, ∃ (ha : a ∈ s), i a ha = b) →
(∀ (a : α) (ha : a ∈ s), f a = g (i a ha)) → Multiset.map f s = Multiset.map g t