Skip to content

Commit c8320ac

Browse files
committed
feat: When the sum of a nonneg function is zero (#7372)
Also fix implicitness of arguments to `Finset.sum_singleton`.
1 parent fad287b commit c8320ac

File tree

6 files changed

+62
-20
lines changed

6 files changed

+62
-20
lines changed

Mathlib/Algebra/BigOperators/Basic.lean

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import Mathlib.Algebra.Group.Pi
88
import Mathlib.Algebra.GroupPower.Lemmas
99
import Mathlib.Algebra.Hom.Equiv.Basic
1010
import Mathlib.Algebra.Ring.Opposite
11+
import Mathlib.Data.Finset.Powerset
12+
import Mathlib.Data.Finset.Sigma
1113
import Mathlib.Data.Finset.Sum
1214
import Mathlib.Data.Fintype.Basic
13-
import Mathlib.Data.Finset.Sigma
1415
import Mathlib.Data.Multiset.Powerset
1516
import Mathlib.Data.Set.Pairwise.Basic
1617

@@ -340,7 +341,7 @@ theorem prod_insert_one [DecidableEq α] (h : f a = 1) : ∏ x in insert a s, f
340341
#align finset.sum_insert_zero Finset.sum_insert_zero
341342

342343
@[to_additive (attr := simp)]
343-
theorem prod_singleton : ∏ x in singleton a, f x = f a :=
344+
theorem prod_singleton (f : α → β) (a : α) : ∏ x in singleton a, f x = f a :=
344345
Eq.trans fold_singleton <| mul_one _
345346
#align finset.prod_singleton Finset.prod_singleton
346347
#align finset.sum_singleton Finset.sum_singleton
@@ -790,7 +791,7 @@ theorem prod_eq_single_of_mem {s : Finset α} {f : α → β} (a : α) (h : a
790791
· intro _ H
791792
rwa [mem_singleton.1 H]
792793
· simpa only [mem_singleton] }
793-
_ = f a := prod_singleton
794+
_ = f a := prod_singleton _ _
794795
#align finset.prod_eq_single_of_mem Finset.prod_eq_single_of_mem
795796
#align finset.sum_eq_single_of_mem Finset.sum_eq_single_of_mem
796797

@@ -1265,8 +1266,7 @@ theorem prod_range_zero (f : ℕ → β) : ∏ k in range 0, f k = 1 := by rw [r
12651266

12661267
@[to_additive sum_range_one]
12671268
theorem prod_range_one (f : ℕ → β) : ∏ k in range 1, f k = f 0 := by
1268-
rw [range_one]
1269-
apply @prod_singleton β ℕ 0 f
1269+
rw [range_one, prod_singleton]
12701270
#align finset.prod_range_one Finset.prod_range_one
12711271
#align finset.sum_range_one Finset.sum_range_one
12721272

@@ -1460,6 +1460,13 @@ theorem prod_pow (s : Finset α) (n : ℕ) (f : α → β) : ∏ x in s, f x ^ n
14601460
#align finset.prod_pow Finset.prod_pow
14611461
#align finset.sum_nsmul Finset.sum_nsmul
14621462

1463+
/-- A product over `Finset.powersetLen` which only depends on the size of the sets is constant. -/
1464+
@[to_additive
1465+
"A sum over `Finset.powersetLen` which only depends on the size of the sets is constant."]
1466+
lemma prod_powersetLen (n : ℕ) (s : Finset α) (f : ℕ → β) :
1467+
∏ t in powersetLen n s, f t.card = f n ^ s.card.choose n := by
1468+
rw [prod_eq_pow_card, card_powersetLen]; rintro a ha; rw [(mem_powersetLen.1 ha).2]
1469+
14631470
@[to_additive]
14641471
theorem prod_flip {n : ℕ} (f : ℕ → β) :
14651472
(∏ r in range (n + 1), f (n - r)) = ∏ k in range (n + 1), f k := by

Mathlib/Algebra/BigOperators/Order.lean

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ theorem prod_eq_one_iff_of_le_one' :
202202
@[to_additive single_le_sum]
203203
theorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x in s, f x :=
204204
calc
205-
f a = ∏ i in {a}, f i := prod_singleton.symm
205+
f a = ∏ i in {a}, f i := (prod_singleton _ _).symm
206206
_ ≤ ∏ i in s, f i :=
207207
prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi
208208
#align finset.single_le_prod' Finset.single_le_prod'
@@ -494,7 +494,7 @@ theorem prod_lt_prod_of_subset' (h : s ⊆ t) {i : ι} (ht : i ∈ t) (hs : i
494494
theorem single_lt_prod' {i j : ι} (hij : j ≠ i) (hi : i ∈ s) (hj : j ∈ s) (hlt : 1 < f j)
495495
(hle : ∀ k ∈ s, k ≠ i → 1 ≤ f k) : f i < ∏ k in s, f k :=
496496
calc
497-
f i = ∏ k in {i}, f k := prod_singleton.symm
497+
f i = ∏ k in {i}, f k := by rw [prod_singleton]
498498
_ < ∏ k in s, f k :=
499499
prod_lt_prod_of_subset' (singleton_subset_iff.2 hi) hj (mt mem_singleton.1 hij) hlt
500500
fun k hks hki ↦ hle k hks (mt mem_singleton.2 hki)
@@ -682,23 +682,60 @@ end CanonicallyOrderedCommSemiring
682682
end Finset
683683

684684
namespace Fintype
685-
686-
variable [Fintype ι]
685+
section OrderedCommMonoid
686+
variable [Fintype ι] [OrderedCommMonoid M] {f : ι → M}
687687

688688
@[to_additive (attr := mono) sum_mono]
689-
theorem prod_mono' [OrderedCommMonoid M] : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦
689+
theorem prod_mono' : Monotone fun f : ι → M ↦ ∏ i, f i := fun _ _ hfg ↦
690690
Finset.prod_le_prod' fun x _ ↦ hfg x
691691
#align fintype.prod_mono' Fintype.prod_mono'
692692
#align fintype.sum_mono Fintype.sum_mono
693693

694+
@[to_additive sum_nonneg]
695+
lemma one_le_prod (hf : 1 ≤ f) : 1 ≤ ∏ i, f i := Finset.one_le_prod' λ _ _ ↦ hf _
696+
697+
@[to_additive] lemma prod_le_one (hf : f ≤ 1) : ∏ i, f i ≤ 1 := Finset.prod_le_one' λ _ _ ↦ hf _
698+
699+
end OrderedCommMonoid
700+
701+
section OrderedCancelCommMonoid
702+
variable [Fintype ι] [OrderedCancelCommMonoid M] {f : ι → M}
703+
694704
@[to_additive sum_strictMono]
695-
theorem prod_strictMono' [OrderedCancelCommMonoid M] : StrictMono fun f : ι → M ↦ ∏ x, f x :=
705+
theorem prod_strictMono' : StrictMono fun f : ι → M ↦ ∏ x, f x :=
696706
fun _ _ hfg ↦
697707
let ⟨hle, i, hlt⟩ := Pi.lt_def.mp hfg
698708
Finset.prod_lt_prod' (fun i _ ↦ hle i) ⟨i, Finset.mem_univ i, hlt⟩
699709
#align fintype.prod_strict_mono' Fintype.prod_strictMono'
700710
#align fintype.sum_strict_mono Fintype.sum_strictMono
701711

712+
@[to_additive sum_pos]
713+
lemma one_lt_prod (hf : 1 < f) : 1 < ∏ i, f i :=
714+
Finset.one_lt_prod' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2
715+
716+
@[to_additive]
717+
lemma prod_lt_one (hf : f < 1) : ∏ i, f i < 1 :=
718+
Finset.prod_lt_one' (λ _ _ ↦ hf.le _) $ by simpa using (Pi.lt_def.1 hf).2
719+
720+
@[to_additive sum_pos_iff_of_nonneg]
721+
lemma one_lt_prod_iff_of_one_le (hf : 1 ≤ f) : 1 < ∏ i, f i ↔ 1 < f := by
722+
obtain rfl | hf := hf.eq_or_lt <;> simp [*, one_lt_prod]
723+
724+
@[to_additive]
725+
lemma prod_lt_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i < 1 ↔ f < 1 := by
726+
obtain rfl | hf := hf.eq_or_lt <;> simp [*, prod_lt_one]
727+
728+
@[to_additive]
729+
lemma prod_eq_one_iff_of_one_le (hf : 1 ≤ f) : ∏ i, f i = 1 ↔ f = 1 := by
730+
simpa only [(one_le_prod hf).not_gt_iff_eq, hf.not_gt_iff_eq]
731+
using (one_lt_prod_iff_of_one_le hf).not
732+
733+
@[to_additive]
734+
lemma prod_eq_one_iff_of_le_one (hf : f ≤ 1) : ∏ i, f i = 1 ↔ f = 1 := by
735+
simpa only [(prod_le_one hf).not_gt_iff_eq, hf.not_gt_iff_eq, eq_comm]
736+
using (prod_lt_one_iff_of_le_one hf).not
737+
738+
end OrderedCancelCommMonoid
702739
end Fintype
703740

704741
namespace WithTop

Mathlib/Analysis/Convex/Combination.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ theorem convexHull_eq (s : Set E) : convexHull R s =
330330
(_ : ∑ i in t, w i = 1) (_ : ∀ i ∈ t, z i ∈ s), t.centerMass w z = x } := by
331331
refine' Subset.antisymm (convexHull_min _ _) _
332332
· intro x hx
333-
use PUnit, {PUnit.unit}, fun _ => 1, fun _ => x, fun _ _ => zero_le_one, Finset.sum_singleton,
333+
use PUnit, {PUnit.unit}, fun _ => 1, fun _ => x, fun _ _ => zero_le_one, sum_singleton _ _,
334334
fun _ _ => hx
335335
simp only [Finset.centerMass, Finset.sum_singleton, inv_one, one_smul]
336336
· rintro x ⟨ι, sx, wx, zx, hwx₀, hwx₁, hzx, rfl⟩ y ⟨ι', sy, wy, zy, hwy₀, hwy₁, hzy, rfl⟩ a b ha

Mathlib/Data/Nat/Digits.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ theorem sub_one_mul_sum_div_pow_eq_sub_sum_digits
552552
have ih := ih (w₂' h') w₁'
553553
simp only [self_div_pow_eq_ofDigits_drop _ _ h, digits_ofDigits p h tl w₁' w₂',
554554
succ_eq_one_add] at ih
555-
have := @sum_singleton _ _ tl.length (fun x => ofDigits p <| tl.drop x) _
555+
have := sum_singleton (fun x ofDigits p <| tl.drop x) tl.length
556556
rw [← Ico_succ_singleton, List.drop_length, ofDigits] at this
557557
have h₁ : 1 ≤ tl.length := List.length_pos.mpr h'
558558
rw [← sum_range_add_sum_Ico _ <| h₁, ← add_zero (∑ x in Ico _ _, ofDigits p (tl.drop x)),

Mathlib/NumberTheory/Divisors.lean

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,8 @@ theorem sum_properDivisors_dvd (h : (∑ x in n.properDivisors, x) ∣ n) :
373373
have hlt : ∑ x in n.succ.succ.properDivisors, x < n.succ.succ :=
374374
lt_of_le_of_ne (Nat.le_of_dvd (Nat.succ_pos _) h) ne_n
375375
symm
376-
rw [← mem_singleton,
377-
eq_properDivisors_of_subset_of_sum_eq_sum
378-
(singleton_subset_iff.2 (mem_properDivisors.2 ⟨h, hlt⟩)) sum_singleton,
379-
mem_properDivisors]
376+
rw [← mem_singleton, eq_properDivisors_of_subset_of_sum_eq_sum (singleton_subset_iff.2
377+
(mem_properDivisors.2 ⟨h, hlt⟩)) (sum_singleton _ _), mem_properDivisors]
380378
refine' ⟨one_dvd _, Nat.succ_lt_succ (Nat.succ_pos _)⟩
381379
#align nat.sum_proper_divisors_dvd Nat.sum_properDivisors_dvd
382380

@@ -416,13 +414,13 @@ theorem sum_properDivisors_eq_one_iff_prime : ∑ x in n.properDivisors, x = 1
416414
· cases n
417415
· simp [Nat.not_prime_one]
418416
· rw [← properDivisors_eq_singleton_one_iff_prime]
419-
refine' ⟨fun h => _, fun h => h.symm ▸ sum_singleton⟩
417+
refine' ⟨fun h => _, fun h => h.symm ▸ sum_singleton _ _
420418
rw [@eq_comm (Finset ℕ) _ _]
421419
apply
422420
eq_properDivisors_of_subset_of_sum_eq_sum
423421
(singleton_subset_iff.2
424422
(one_mem_properDivisors_iff_one_lt.2 (succ_lt_succ (Nat.succ_pos _))))
425-
(Eq.trans sum_singleton h.symm)
423+
((sum_singleton _ _).trans h.symm)
426424
#align nat.sum_proper_divisors_eq_one_iff_prime Nat.sum_properDivisors_eq_one_iff_prime
427425

428426
theorem mem_properDivisors_prime_pow {p : ℕ} (pp : p.Prime) (k : ℕ) {x : ℕ} :

Mathlib/Topology/Algebra/InfiniteSum/Order.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ theorem isLUB_hasSum (h : ∀ i, 0 ≤ f i) (hf : HasSum f a) :
8888

8989
theorem le_hasSum (hf : HasSum f a) (i : ι) (hb : ∀ j, j ≠ i → 0 ≤ f j) : f i ≤ a :=
9090
calc
91-
f i = ∑ i in {i}, f i := Finset.sum_singleton.symm
91+
f i = ∑ i in {i}, f i := by rw [sum_singleton]
9292
_ ≤ a := sum_le_hasSum _ (by simpa) hf
9393
#align le_has_sum le_hasSum
9494

0 commit comments

Comments
 (0)