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

Commit 824f9ae

Browse files
committed
feat(algebra/order/ring/canonical): add canonically_ordered_comm_semiring.to_ordered_comm_monoid (#18504)
Also merge `finset.prod_le_prod'` with `finset.prod_le_prod''`. Mathlib 4 version is leanprover-community/mathlib4#2510
1 parent c3fc15b commit 824f9ae

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

src/algebra/big_operators/order.lean

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ variables {f g : ι → N} {s t : finset ι}
110110
equal to the corresponding factor `g i` of another finite product, then
111111
`∏ i in s, f i ≤ ∏ i in s, g i`. -/
112112
@[to_additive sum_le_sum]
113-
lemma prod_le_prod'' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=
113+
lemma prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i in s, f i ≤ ∏ i in s, g i :=
114114
multiset.prod_map_le_prod_map f g h
115115

116116
/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than
@@ -119,14 +119,14 @@ or equal to the corresponding summand `g i` of another finite sum, then
119119
add_decl_doc sum_le_sum
120120

121121
@[to_additive sum_nonneg] lemma one_le_prod' (h : ∀i ∈ s, 1 ≤ f i) : 1 ≤ (∏ i in s, f i) :=
122-
le_trans (by rw prod_const_one) (prod_le_prod'' h)
122+
le_trans (by rw prod_const_one) (prod_le_prod' h)
123123

124124
@[to_additive finset.sum_nonneg']
125125
lemma one_le_prod'' (h : ∀ (i : ι), 1 ≤ f i) : 1 ≤ ∏ (i : ι) in s, f i :=
126126
finset.one_le_prod' (λ i hi, h i)
127127

128128
@[to_additive sum_nonpos] lemma prod_le_one' (h : ∀i ∈ s, f i ≤ 1) : (∏ i in s, f i) ≤ 1 :=
129-
(prod_le_prod'' h).trans_eq (by rw prod_const_one)
129+
(prod_le_prod' h).trans_eq (by rw prod_const_one)
130130

131131
@[to_additive sum_le_sum_of_subset_of_nonneg]
132132
lemma prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :
@@ -367,7 +367,7 @@ begin
367367
classical,
368368
rcases Hlt with ⟨i, hi, hlt⟩,
369369
rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)],
370-
exact mul_lt_mul_of_lt_of_le hlt (prod_le_prod'' $ λ j hj, Hle j $ mem_of_mem_erase hj)
370+
exact mul_lt_mul_of_lt_of_le hlt (prod_le_prod' $ λ j hj, Hle j $ mem_of_mem_erase hj)
371371
end
372372

373373
@[to_additive sum_lt_sum_of_nonempty]
@@ -432,7 +432,7 @@ begin
432432
refine finset.induction_on s (λ _, ⟨λ _ _, false.elim, λ _, rfl⟩) (λ a s ha ih H, _),
433433
specialize ih (λ i, H i ∘ finset.mem_insert_of_mem),
434434
rw [finset.prod_insert ha, finset.prod_insert ha, finset.forall_mem_insert, ←ih],
435-
exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (finset.prod_le_prod''
435+
exact mul_eq_mul_iff_eq_and_eq (H a (s.mem_insert_self a)) (finset.prod_le_prod'
436436
(λ i, H i ∘ finset.mem_insert_of_mem)),
437437
end
438438

@@ -447,7 +447,7 @@ theorem exists_lt_of_prod_lt' (Hlt : ∏ i in s, f i < ∏ i in s, g i) :
447447
∃ i ∈ s, f i < g i :=
448448
begin
449449
contrapose! Hlt with Hle,
450-
exact prod_le_prod'' Hle
450+
exact prod_le_prod' Hle
451451
end
452452

453453
@[to_additive exists_le_of_sum_le]
@@ -482,7 +482,7 @@ lemma prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i in s, f i :=
482482
prod_induction f (λ i, 0 ≤ i) (λ _ _ ha hb, mul_nonneg ha hb) zero_le_one h0
483483

484484
/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the
485-
product of `f i` is less than or equal to the product of `g i`. See also `finset.prod_le_prod''` for
485+
product of `f i` is less than or equal to the product of `g i`. See also `finset.prod_le_prod'` for
486486
the case of an ordered commutative multiplicative monoid. -/
487487
lemma prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :
488488
∏ i in s, f i ≤ ∏ i in s, g i :=
@@ -551,18 +551,6 @@ lemma _root_.canonically_ordered_comm_semiring.prod_pos [nontrivial R] :
551551
0 < ∏ i in s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=
552552
canonically_ordered_comm_semiring.multiset_prod_pos.trans $ by simp
553553

554-
lemma prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) :
555-
∏ i in s, f i ≤ ∏ i in s, g i :=
556-
begin
557-
classical,
558-
induction s using finset.induction with a s has ih h,
559-
{ simp },
560-
{ rw [finset.prod_insert has, finset.prod_insert has],
561-
apply mul_le_mul',
562-
{ exact h _ (finset.mem_insert_self a s) },
563-
{ exact ih (λ i hi, h _ (finset.mem_insert_of_mem hi)) } }
564-
end
565-
566554
/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the
567555
sum of the products of `g` and `h`. This is the version for `canonically_ordered_comm_semiring`.
568556
-/
@@ -587,7 +575,7 @@ variables [fintype ι]
587575

588576
@[to_additive sum_mono, mono]
589577
lemma prod_mono' [ordered_comm_monoid M] : monotone (λ f : ι → M, ∏ i, f i) :=
590-
λ f g hfg, finset.prod_le_prod'' $ λ x _, hfg x
578+
λ f g hfg, finset.prod_le_prod' $ λ x _, hfg x
591579

592580
attribute [mono] sum_mono
593581

src/algebra/order/ring/canonical.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ begin
9292
apply self_le_add_right
9393
end
9494

95+
@[priority 100] -- see Note [lower instance priority]
96+
instance to_ordered_comm_monoid : ordered_comm_monoid α :=
97+
{ mul_le_mul_left := λ _ _, mul_le_mul_left',
98+
.. ‹canonically_ordered_comm_semiring α› }
99+
95100
@[priority 100] -- see Note [lower instance priority]
96101
instance to_ordered_comm_semiring : ordered_comm_semiring α :=
97102
{ zero_le_one := zero_le _,

src/number_theory/bertrand.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ begin
156156
rw [central_binom_factorization_small n n_big no_prime, ← this,
157157
← finset.prod_filter_mul_prod_filter_not S (≤ sqrt (2 * n))],
158158
apply mul_le_mul',
159-
{ refine (finset.prod_le_prod'' (λ p hp, (_ : f p ≤ 2 * n))).trans _,
159+
{ refine (finset.prod_le_prod' (λ p hp, (_ : f p ≤ 2 * n))).trans _,
160160
{ exact pow_factorization_choose_le (mul_pos two_pos n_pos) },
161161
have : (finset.Icc 1 (sqrt (2 * n))).card = sqrt (2 * n),
162162
{ rw [card_Icc, nat.add_sub_cancel] },

0 commit comments

Comments
 (0)