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

Commit 54cc126

Browse files
committed
feat(data/finset,data/fintype,algebra/big_operators): some more lemmas (#3124)
Add some `finset`, `fintype` and `algebra.big_operators` lemmas that were found useful in proving things related to affine independent families. (In all cases where results are proved for products, and then derived for sums where possible using `to_additive`, it was the result for sums that I actually had a use for. In the case of `eq_one_of_card_le_one_of_prod_eq_one` and `eq_zero_of_card_le_one_of_sum_eq_zero`, `to_additive` couldn't be used because it also tries to convert the `1` in `s.card ≤ 1` to `0`.)
1 parent 86dcd5c commit 54cc126

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

src/algebra/big_operators.lean

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,77 @@ lemma prod_update_of_mem [decidable_eq α] {s : finset α} {i : α} (h : i ∈ s
752752
(∏ x in s, function.update f i b x) = b * (∏ x in s \ (singleton i), f x) :=
753753
by { rw [update_eq_piecewise, prod_piecewise], simp [h] }
754754

755+
/-- If a product of a `finset` of size at most 1 has a given value, so
756+
do the terms in that product. -/
757+
lemma eq_of_card_le_one_of_prod_eq {s : finset α} (hc : s.card ≤ 1) {f : α → β} {b : β}
758+
(h : ∏ x in s, f x = b) : ∀ x ∈ s, f x = b :=
759+
begin
760+
intros x hx,
761+
by_cases hc0 : s.card = 0,
762+
{ exact false.elim (card_ne_zero_of_mem hx hc0) },
763+
{ have h1 : s.card = 1 := le_antisymm hc (nat.one_le_of_lt (nat.pos_of_ne_zero hc0)),
764+
rw card_eq_one at h1,
765+
cases h1 with x2 hx2,
766+
rw [hx2, mem_singleton] at hx,
767+
simp_rw hx2 at h,
768+
rw hx,
769+
rw prod_singleton at h,
770+
exact h }
771+
end
772+
773+
/-- If a sum of a `finset` of size at most 1 has a given value, so do
774+
the terms in that sum. -/
775+
lemma eq_of_card_le_one_of_sum_eq [add_comm_monoid γ] {s : finset α} (hc : s.card ≤ 1)
776+
{f : α → γ} {b : γ} (h : ∑ x in s, f x = b) : ∀ x ∈ s, f x = b :=
777+
begin
778+
intros x hx,
779+
by_cases hc0 : s.card = 0,
780+
{ exact false.elim (card_ne_zero_of_mem hx hc0) },
781+
{ have h1 : s.card = 1 := le_antisymm hc (nat.one_le_of_lt (nat.pos_of_ne_zero hc0)),
782+
rw card_eq_one at h1,
783+
cases h1 with x2 hx2,
784+
rw [hx2, mem_singleton] at hx,
785+
simp_rw hx2 at h,
786+
rw hx,
787+
rw sum_singleton at h,
788+
exact h }
789+
end
790+
791+
attribute [to_additive eq_of_card_le_one_of_sum_eq] eq_of_card_le_one_of_prod_eq
792+
793+
/-- If a function applied at a point is 1, a product is unchanged by
794+
removing that point, if present, from a `finset`. -/
795+
@[to_additive "If a function applied at a point is 0, a sum is unchanged by
796+
removing that point, if present, from a `finset`."]
797+
lemma prod_erase [decidable_eq α] (s : finset α) {f : α → β} {a : α} (h : f a = 1) :
798+
∏ x in s.erase a, f x = ∏ x in s, f x :=
799+
begin
800+
rw ←sdiff_singleton_eq_erase,
801+
apply prod_subset sdiff_subset_self,
802+
intros x hx hnx,
803+
rw sdiff_singleton_eq_erase at hnx,
804+
rwa eq_of_mem_of_not_mem_erase hx hnx
805+
end
806+
807+
/-- If a product is 1 and the function is 1 except possibly at one
808+
point, it is 1 everywhere on the `finset`. -/
809+
@[to_additive "If a sum is 0 and the function is 0 except possibly at one
810+
point, it is 0 everywhere on the `finset`."]
811+
lemma eq_one_of_prod_eq_one {s : finset α} {f : α → β} {a : α} (hp : ∏ x in s, f x = 1)
812+
(h1 : ∀ x ∈ s, x ≠ a → f x = 1) : ∀ x ∈ s, f x = 1 :=
813+
begin
814+
intros x hx,
815+
classical,
816+
by_cases h : x = a,
817+
{ rw h,
818+
rw h at hx,
819+
rw [←prod_subset (singleton_subset_iff.2 hx)
820+
(λ t ht ha, h1 t ht (not_mem_singleton.1 ha)),
821+
prod_singleton] at hp,
822+
exact hp },
823+
{ exact h1 x hx h }
824+
end
825+
755826
end comm_monoid
756827

757828
lemma sum_update_of_mem [add_comm_monoid β] [decidable_eq α] {s : finset α} {i : α}

src/data/finset.lean

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,15 @@ theorem mem_of_mem_erase {a b : α} {s : finset α} : b ∈ erase s a → b ∈
580580
theorem mem_erase_of_ne_of_mem {a b : α} {s : finset α} : a ≠ b → a ∈ s → a ∈ erase s b :=
581581
by simp only [mem_erase]; exact and.intro
582582

583+
/-- An element of `s` that is not an element of `erase s a` must be
584+
`a`. -/
585+
lemma eq_of_mem_of_not_mem_erase {a b : α} {s : finset α} (hs : b ∈ s)
586+
(hsa : b ∉ s.erase a) : b = a :=
587+
begin
588+
rw [mem_erase, not_and] at hsa,
589+
exact not_imp_not.mp hsa hs
590+
end
591+
583592
theorem erase_insert {a : α} {s : finset α} (h : a ∉ s) : erase (insert a s) a = s :=
584593
ext $ assume x, by simp only [mem_erase, mem_insert, and_or_distrib_left, not_and_self, false_or];
585594
apply and_iff_right_of_imp; rintro H rfl; exact h H

src/data/fintype/basic.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,10 @@ begin
521521
exact subtype.eq (H x.2 y.2) }
522522
end
523523

524+
/-- A `finset` of a subsingleton type has cardinality at most one. -/
525+
lemma finset.card_le_one_of_subsingleton [subsingleton α] (s : finset α) : s.card ≤ 1 :=
526+
finset.card_le_one_iff.2 $ λ _ _ _ _, subsingleton.elim _ _
527+
524528
lemma finset.one_lt_card_iff {s : finset α} :
525529
1 < s.card ↔ ∃ x y, (x ∈ s) ∧ (y ∈ s) ∧ x ≠ y :=
526530
begin

src/data/fintype/card.lean

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ lemma prod_unique [unique β] (f : β → M) :
5858
(∏ x, f x) = f (default β) :=
5959
by simp only [finset.prod_singleton, univ_unique]
6060

61+
/-- If a product of a `finset` of a subsingleton type has a given
62+
value, so do the terms in that product. -/
63+
@[to_additive "If a sum of a `finset` of a subsingleton type has a given
64+
value, so do the terms in that sum."]
65+
lemma eq_of_subsingleton_of_prod_eq {ι : Type*} [subsingleton ι] {s : finset ι}
66+
{f : ι → M} {b : M} (h : ∏ i in s, f i = b) : ∀ i ∈ s, f i = b :=
67+
finset.eq_of_card_le_one_of_prod_eq (finset.card_le_one_of_subsingleton s) h
68+
6169
end
6270

6371
end fintype

0 commit comments

Comments
 (0)