Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 5344da4

Browse files
kim-emmergify[bot]
authored andcommitted
feat(algebra/big_operators): simp lemmas (#1471)
* feat(algebra/big_operators): simp lemmas * remove @[simp]
1 parent 201174d commit 5344da4

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/algebra/big_operators.lean

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ from classical.by_cases
201201
(prod_congr rfl $ λ b hb, h₀ b hb $ by rintro rfl; cc).trans $
202202
prod_const_one.trans (h₁ this).symm)
203203

204+
@[simp, to_additive] lemma prod_ite [decidable_eq α] (s : finset α) (a : α) (b : β) :
205+
s.prod (λ x, (ite (a = x) b 1)) = ite (a ∈ s) b 1 :=
206+
begin
207+
rw ←finset.prod_filter,
208+
split_ifs;
209+
simp only [filter_eq, if_true, if_false, h, prod_empty, prod_singleton, insert_empty_eq_singleton],
210+
end
211+
204212
@[to_additive]
205213
lemma prod_attach {f : α → β} : s.attach.prod (λx, f x.val) = s.prod f :=
206214
by haveI := classical.dec_eq α; exact
@@ -427,6 +435,21 @@ lemma sum_mul : s.sum f * b = s.sum (λx, f x * b) :=
427435
lemma mul_sum : b * s.sum f = s.sum (λx, b * f x) :=
428436
(sum_hom (λx, b * x)).symm
429437

438+
@[simp] lemma sum_mul_boole [decidable_eq α] (s : finset α) (f : α → β) (a : α) :
439+
s.sum (λ x, (f x * ite (a = x) 1 0)) = ite (a ∈ s) (f a) 0 :=
440+
begin
441+
convert sum_ite s a (f a),
442+
funext,
443+
split_ifs with h; simp [h],
444+
end
445+
@[simp] lemma sum_boole_mul [decidable_eq α] (s : finset α) (f : α → β) (a : α) :
446+
s.sum (λ x, (ite (a = x) 1 0) * f x) = ite (a ∈ s) (f a) 0 :=
447+
begin
448+
convert sum_ite s a (f a),
449+
funext,
450+
split_ifs with h; simp [h],
451+
end
452+
430453
end semiring
431454

432455
section comm_semiring

src/data/finset.lean

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,20 @@ begin
659659
{ intro x, simp, intros hx hx₂, refine ⟨or.resolve_left (h hx) hx₂, hx₂⟩ }
660660
end
661661

662+
-- This is not a good simp lemma, as it would prevent `finset.mem_filter` from firing
663+
-- on, e.g. `x ∈ s.filter(eq b)`.
664+
lemma filter_eq [decidable_eq β] (s : finset β) (b : β) :
665+
s.filter(eq b) = ite (b ∈ s) {b} ∅ :=
666+
begin
667+
split_ifs,
668+
{ ext,
669+
simp only [mem_filter, insert_empty_eq_singleton, mem_singleton],
670+
exact ⟨λ h, h.2.symm, by { rintro ⟨h⟩, exact ⟨h, rfl⟩, }⟩ },
671+
{ ext,
672+
simp only [mem_filter, not_and, iff_false, not_mem_empty],
673+
rintros m ⟨e⟩, exact h m, }
674+
end
675+
662676
end filter
663677

664678
/- range -/

0 commit comments

Comments
 (0)