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

Commit 5eead09

Browse files
paulvanwamelenpaulvanwamelen
andcommitted
feat(algebra/big_operators/basic): add lemmas for a product with two non one factors (#6826)
Add another version of `prod_eq_one` and 3 versions of `prod_eq_double`, a lemma that says a product with only 2 non one factors is equal to the product of the 2 factors. Co-authored-by: paulvanwamelen <30371019+paulvanwamelen@users.noreply.github.com>
1 parent cfd1a4c commit 5eead09

File tree

2 files changed

+63
-7
lines changed

2 files changed

+63
-7
lines changed

src/algebra/big_operators/basic.lean

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,22 +408,70 @@ calc (∏ a in s.filter p, f a) = ∏ a in s.filter p, if p a then f a else 1 :
408408
end
409409

410410
@[to_additive]
411-
lemma prod_eq_single {s : finset α} {f : α → β} (a : α)
412-
(h₀ : ∀b∈s, b ≠ a → f b = 1) (h₁ : a ∉ s → f a = 1) : (∏ x in s, f x) = f a :=
413-
by haveI := classical.dec_eq α;
414-
from classical.by_cases
415-
(assume : a ∈ s,
416-
calc (∏ x in s, f x) = ∏ x in {a}, f x :
411+
lemma prod_eq_single_of_mem {s : finset α} {f : α → β} (a : α) (h : a ∈ s)
412+
(h₀ : ∀ b ∈ s, b ≠ a → f b = 1) : (∏ x in s, f x) = f a :=
413+
begin
414+
haveI := classical.dec_eq α,
415+
calc (∏ x in s, f x) = ∏ x in {a}, f x :
417416
begin
418417
refine (prod_subset _ _).symm,
419418
{ intros _ H, rwa mem_singleton.1 H },
420419
{ simpa only [mem_singleton] }
421420
end
422-
... = f a : prod_singleton)
421+
... = f a : prod_singleton
422+
end
423+
424+
@[to_additive]
425+
lemma prod_eq_single {s : finset α} {f : α → β} (a : α)
426+
(h₀ : ∀b∈s, b ≠ a → f b = 1) (h₁ : a ∉ s → f a = 1) : (∏ x in s, f x) = f a :=
427+
by haveI := classical.dec_eq α;
428+
from classical.by_cases
429+
(assume : a ∈ s, prod_eq_single_of_mem a this h₀)
423430
(assume : a ∉ s,
424431
(prod_congr rfl $ λ b hb, h₀ b hb $ by rintro rfl; cc).trans $
425432
prod_const_one.trans (h₁ this).symm)
426433

434+
@[to_additive]
435+
lemma prod_eq_mul_of_mem {s : finset α} {f : α → β} (a b : α) (ha : a ∈ s) (hb : b ∈ s) (hn : a ≠ b)
436+
(h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) : (∏ x in s, f x) = (f a) * (f b) :=
437+
begin
438+
haveI := classical.dec_eq α;
439+
let s' := ({a, b} : finset α),
440+
have hu : s' ⊆ s,
441+
{ refine insert_subset.mpr _, apply and.intro ha, apply singleton_subset_iff.mpr hb },
442+
have hf : ∀ c ∈ s, c ∉ s' → f c = 1,
443+
{ intros c hc hcs,
444+
apply h₀ c hc,
445+
apply not_or_distrib.mp,
446+
intro hab,
447+
apply hcs,
448+
apply mem_insert.mpr,
449+
rw mem_singleton,
450+
exact hab },
451+
rw ←prod_subset hu hf,
452+
exact finset.prod_pair hn
453+
end
454+
455+
@[to_additive]
456+
lemma prod_eq_mul {s : finset α} {f : α → β} (a b : α) (hn : a ≠ b)
457+
(h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) (ha : a ∉ s → f a = 1) (hb : b ∉ s → f b = 1) :
458+
(∏ x in s, f x) = (f a) * (f b) :=
459+
begin
460+
haveI := classical.dec_eq α;
461+
by_cases h₁ : a ∈ s; by_cases h₂ : b ∈ s,
462+
{ exact prod_eq_mul_of_mem a b h₁ h₂ hn h₀ },
463+
{ rw [hb h₂, mul_one],
464+
apply prod_eq_single_of_mem a h₁,
465+
exact λ c hc hca, h₀ c hc ⟨hca, ne_of_mem_of_not_mem hc h₂⟩ },
466+
{ rw [ha h₁, one_mul],
467+
apply prod_eq_single_of_mem b h₂,
468+
exact λ c hc hcb, h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, hcb⟩ },
469+
{ rw [ha h₁, hb h₂, mul_one],
470+
exact trans
471+
(prod_congr rfl (λ c hc, h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, ne_of_mem_of_not_mem hc h₂⟩))
472+
prod_const_one }
473+
end
474+
427475
@[to_additive]
428476
lemma prod_attach {f : α → β} : (∏ x in s.attach, f x) = (∏ x in s, f x) :=
429477
by haveI := classical.dec_eq α; exact

src/data/fintype/card.lean

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ lemma prod_eq_single {f : α → M} (a : α) (h : ∀ x ≠ a, f x = 1) :
6363
(∏ x, f x) = f a :=
6464
finset.prod_eq_single a (λ x _ hx, h x hx) $ λ ha, (ha (finset.mem_univ a)).elim
6565

66+
@[to_additive]
67+
lemma prod_eq_mul {f : α → M} (a b : α) (h₁ : a ≠ b) (h₂ : ∀ x, x ≠ a ∧ x ≠ b → f x = 1) :
68+
(∏ x, f x) = (f a) * (f b) :=
69+
begin
70+
apply finset.prod_eq_mul a b h₁ (λ x _ hx, h₂ x hx);
71+
exact λ hc, (hc (finset.mem_univ _)).elim
72+
end
73+
6674
@[to_additive]
6775
lemma prod_unique [unique β] (f : β → M) :
6876
(∏ x, f x) = f (default β) :=

0 commit comments

Comments
 (0)