The fold operation for a commutative associative operation over a finset. #
fold #
def Finset.fold {α : Type u_1} {β : Type u_2} (op : β → β → β) [hc : Std.Commutative op] [ha : Std.Associative op] (b : β) (f : α → β) (s : Finset α) :
β
fold op b f s folds the commutative associative operation op over the
f-image of s, i.e. fold (+) b f {1,2,3} = f 1 + f 2 + f 3 + b.
Equations
- Finset.fold op b f s = Multiset.fold op b (Multiset.map f s.val)
Instances For
@[simp]
theorem Finset.fold_empty {α : Type u_1} {β : Type u_2} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {f : α → β} {b : β} :
@[simp]
theorem Finset.fold_cons {α : Type u_1} {β : Type u_2} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {f : α → β} {b : β} {s : Finset α} {a : α} (h : a ∉ s) :
@[simp]
theorem Finset.fold_insert {α : Type u_1} {β : Type u_2} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {f : α → β} {b : β} {s : Finset α} {a : α} [DecidableEq α] (h : a ∉ s) :
@[simp]
theorem Finset.fold_singleton {α : Type u_1} {β : Type u_2} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {f : α → β} {b : β} {a : α} :
@[simp]
theorem Finset.fold_map {α : Type u_1} {β : Type u_2} {γ : Type u_3} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {f : α → β} {b : β} {g : γ ↪ α} {s : Finset γ} :
@[simp]
theorem Finset.fold_image {α : Type u_1} {β : Type u_2} {γ : Type u_3} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {f : α → β} {b : β} [DecidableEq α] {g : γ → α} {s : Finset γ} (H : Set.InjOn g ↑s) :
theorem Finset.fold_congr {α : Type u_1} {β : Type u_2} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {f : α → β} {b : β} {s : Finset α} {g : α → β} (H : ∀ x ∈ s, f x = g x) :
theorem Finset.fold_op_distrib {α : Type u_1} {β : Type u_2} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {s : Finset α} {f g : α → β} {b₁ b₂ : β} :
theorem Finset.fold_hom {α : Type u_1} {β : Type u_2} {γ : Type u_3} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {f : α → β} {b : β} {s : Finset α} {op' : γ → γ → γ} [Std.Commutative op'] [Std.Associative op'] {m : β → γ} (hm : ∀ (x y : β), m (op x y) = op' (m x) (m y)) :
theorem Finset.fold_disjUnion {α : Type u_1} {β : Type u_2} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {f : α → β} {s₁ s₂ : Finset α} {b₁ b₂ : β} (h : Disjoint s₁ s₂) :
theorem Finset.fold_union_inter {α : Type u_1} {β : Type u_2} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {f : α → β} [DecidableEq α] {s₁ s₂ : Finset α} {b₁ b₂ : β} :
@[simp]
theorem Finset.fold_insert_idem {α : Type u_1} {β : Type u_2} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {f : α → β} {b : β} {s : Finset α} {a : α} [DecidableEq α] [hi : Std.IdempotentOp op] :
theorem Finset.fold_image_idem {α : Type u_1} {β : Type u_2} {γ : Type u_3} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {f : α → β} {b : β} [DecidableEq α] {g : γ → α} {s : Finset γ} [hi : Std.IdempotentOp op] :
theorem Finset.fold_ite' {α : Type u_1} {β : Type u_2} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {f : α → β} {b : β} {s : Finset α} {g : α → β} (hb : op b b = b) (p : α → Prop) [DecidablePred p] :
A stronger version of Finset.fold_ite, but relies on
an explicit proof of idempotency on the seed element, rather
than relying on typeclass idempotency over the whole type.
theorem Finset.fold_ite {α : Type u_1} {β : Type u_2} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {f : α → β} {b : β} {s : Finset α} [Std.IdempotentOp op] {g : α → β} (p : α → Prop) [DecidablePred p] :
A weaker version of Finset.fold_ite',
relying on typeclass idempotency over the whole type,
instead of solely on the seed element.
However, this is easier to use because it does not generate side goals.
theorem Finset.fold_op_rel_iff_and {α : Type u_1} {β : Type u_2} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {f : α → β} {b : β} {s : Finset α} {r : β → β → Prop} (hr : ∀ {x y z : β}, r x (op y z) ↔ r x y ∧ r x z) {c : β} :
theorem Finset.fold_op_rel_iff_or {α : Type u_1} {β : Type u_2} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op] {f : α → β} {b : β} {s : Finset α} {r : β → β → Prop} (hr : ∀ {x y z : β}, r x (op y z) ↔ r x y ∨ r x z) {c : β} :