Skip to content

Commit 90290fc

Browse files
committed
chore: golf using positivity (#37554)
1 parent 6ef8cc2 commit 90290fc

File tree

13 files changed

+37
-42
lines changed

13 files changed

+37
-42
lines changed

Mathlib/Analysis/MeanInequalities.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ theorem harm_mean_le_geom_mean_weighted (w z : ι → ℝ) (hs : s.Nonempty) (hw
357357
inv_pos.2 (prod_pos fun i hi => rpow_pos_of_pos ((hz i hi)) _)
358358
rw [← inv_inv (∏ i ∈ s, z i ^ w i), inv_le_inv₀ p_pos p_pos₂, ← Finset.prod_inv_distrib]
359359
gcongr
360-
· exact fun i hi ↦ inv_nonneg.mpr (Real.rpow_nonneg (le_of_lt (hz i hi)) _)
360+
· exact fun i hi ↦ by positivity [hz i hi]
361361
· rw [Real.inv_rpow]; apply fun i hi ↦ le_of_lt (hz i hi); assumption
362362

363363

@@ -371,7 +371,7 @@ theorem harm_mean_le_geom_mean {ι : Type*} (s : Finset ι) (hs : s.Nonempty) (w
371371
nth_rw 1 [div_eq_mul_inv, (show n = (n⁻¹)⁻¹ by simp), ← mul_inv, Finset.mul_sum _ _ n⁻¹]
372372
simp_rw [inv_mul_eq_div n ((w _) / (z _)), div_right_comm _ _ n]
373373
convert this
374-
rw [← Real.finset_prod_rpow s _ (fun i hi ↦ Real.rpow_nonneg (le_of_lt <| hz i hi) _)]
374+
rw [← Real.finset_prod_rpow s _ (fun i hi ↦ by positivity [hz i hi])]
375375
refine Finset.prod_congr rfl (fun i hi => ?_)
376376
rw [← Real.rpow_mul (le_of_lt <| hz i hi) (w _) n⁻¹, div_eq_mul_inv (w _) n]
377377
· exact fun i hi ↦ div_pos (hw i hi) hw'

Mathlib/Analysis/MellinTransform.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ theorem mellin_convergent_zero_of_isBigO {b : ℝ} {f : ℝ → ℝ}
250250
· refine (ae_restrict_iff' measurableSet_Ioo).mpr (Eventually.of_forall fun t ht => ?_)
251251
rw [mul_comm, norm_mul]
252252
specialize hε' _ ht.1
253-
· rw [dist_eq_norm, sub_zero, norm_of_nonneg (le_of_lt ht.1)]
253+
· rw [dist_eq_norm, sub_zero, norm_of_nonneg ht.1.le]
254254
exact ht.2
255255
· calc _ ≤ d * ‖t ^ (-b)‖ * ‖t ^ (s - 1)‖ := by gcongr
256256
_ = d * t ^ (s - b - 1) := ?_
257-
simp_rw [norm_of_nonneg (rpow_nonneg (le_of_lt ht.1) _), mul_assoc]
257+
simp_rw [norm_of_nonneg (rpow_nonneg ht.1.le _), mul_assoc]
258258
rw [← rpow_add ht.1]
259259
congr 2
260260
abel

Mathlib/Analysis/Normed/Lp/lpSpace.lean

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ theorem memℓp_gen' {C : ℝ} {f : ∀ i, E i} (hf : ∀ s : Finset α, ∑ i
115115
use ⨆ s : Finset α, ∑ i ∈ s, ‖f i‖ ^ p.toReal
116116
apply hasSum_of_isLUB_of_nonneg
117117
· intro b
118-
exact Real.rpow_nonneg (norm_nonneg _) _
118+
positivity
119119
apply isLUB_ciSup
120120
use C
121121
rintro - ⟨s, rfl⟩
@@ -239,7 +239,7 @@ theorem of_exponent_ge {p q : ℝ≥0∞} {f : ∀ i, E i} (hfq : Memℓp f q) (
239239
exact H.subset fun i hi => Real.one_le_rpow hi hq.le
240240
· change ∀ i, ¬|‖f i‖ ^ p.toReal| ≤ ‖f i‖ ^ q.toReal → 1 ≤ ‖f i‖
241241
intro i hi
242-
have : 0 ≤ ‖f i‖ ^ p.toReal := Real.rpow_nonneg (norm_nonneg _) p.toReal
242+
have : 0 ≤ ‖f i‖ ^ p.toReal := by positivity
243243
simp only [abs_of_nonneg, this] at hi
244244
contrapose! hi
245245
exact Real.rpow_le_rpow_of_exponent_ge' (norm_nonneg _) hi.le hq.le hpq'
@@ -472,8 +472,7 @@ theorem norm_nonneg' (f : lp E p) : 0 ≤ ‖f‖ := by
472472
inhabit α
473473
exact (norm_nonneg (f default)).trans ((lp.isLUB_norm f).1 ⟨default, rfl⟩)
474474
· rw [lp.norm_eq_tsum_rpow hp f]
475-
refine Real.rpow_nonneg (tsum_nonneg ?_) _
476-
exact fun i => Real.rpow_nonneg (norm_nonneg _) _
475+
exact Real.rpow_nonneg (tsum_nonneg fun i ↦ by positivity) _
477476

478477
set_option backward.isDefEq.respectTransparency false in
479478
@[simp]
@@ -501,7 +500,7 @@ theorem norm_eq_zero_iff {f : lp E p} : ‖f‖ = 0 ↔ f = 0 := by
501500
· have hf : HasSum (fun i : α => ‖f i‖ ^ p.toReal) 0 := by
502501
have := lp.hasSum_norm hp f
503502
rwa [h, Real.zero_rpow hp.ne'] at this
504-
have : ∀ i, 0 ≤ ‖f i‖ ^ p.toReal := fun i => Real.rpow_nonneg (norm_nonneg _) _
503+
have : ∀ i, 0 ≤ ‖f i‖ ^ p.toReal := fun i by positivity
505504
rw [hasSum_zero_iff_of_nonneg this] at hf
506505
ext i
507506
have : f i = 0 ∧ p.toReal ≠ 0 := by
@@ -584,7 +583,7 @@ theorem norm_apply_le_norm (hp : p ≠ 0) (f : lp E p) (i : α) : ‖f i‖ ≤
584583
· haveI : Nonempty α := ⟨i⟩
585584
exact (isLUB_norm f).1 ⟨i, rfl⟩
586585
have hp'' : 0 < p.toReal := ENNReal.toReal_pos hp hp'
587-
have : ∀ i, 0 ≤ ‖f i‖ ^ p.toReal := fun i => Real.rpow_nonneg (norm_nonneg _) _
586+
have : ∀ i, 0 ≤ ‖f i‖ ^ p.toReal := fun i by positivity
588587
rw [← Real.rpow_le_rpow_iff (norm_nonneg _) (norm_nonneg' _) hp'']
589588
convert le_hasSum (hasSum_norm hp'' f) i fun i _ => this i
590589

@@ -597,7 +596,7 @@ lemma lipschitzWith_one_eval (p : ℝ≥0∞) [Fact (1 ≤ p)] (i : α) :
597596
theorem sum_rpow_le_norm_rpow (hp : 0 < p.toReal) (f : lp E p) (s : Finset α) :
598597
∑ i ∈ s, ‖f i‖ ^ p.toReal ≤ ‖f‖ ^ p.toReal := by
599598
rw [lp.norm_rpow_eq_tsum hp f]
600-
have : ∀ i, 0 ≤ ‖f i‖ ^ p.toReal := fun i => Real.rpow_nonneg (norm_nonneg _) _
599+
have : ∀ i, 0 ≤ ‖f i‖ ^ p.toReal := fun i by positivity
601600
refine Summable.sum_le_tsum _ (fun i _ => this i) ?_
602601
exact (lp.memℓp f).summable hp
603602

Mathlib/Analysis/Normed/Unbundled/IsPowMulFaithful.lean

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ theorem contraction_of_isPowMul_of_boundedWrt {F : Type*} {α : outParam (Type*)
4747
intro n hn
4848
have h : (C ^ (1 / n : ℝ)) ^ n = C := by
4949
have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (ne_of_gt hn)
50-
rw [← rpow_natCast, ← rpow_mul (le_of_lt hC0), one_div, inv_mul_cancel₀ hn0, rpow_one]
51-
apply le_of_pow_le_pow_left₀ (ne_of_gt hn)
52-
(mul_nonneg (rpow_nonneg (le_of_lt hC0) _) (apply_nonneg _ _))
50+
rw [← rpow_natCast, ← rpow_mul hC0.le, one_div, inv_mul_cancel₀ hn0, rpow_one]
51+
apply le_of_pow_le_pow_left₀ (ne_of_gt hn) (by positivity)
5352
· rw [mul_pow, h, ← hβ _ hn, ← map_pow]
5453
apply le_trans (hC (x ^ n))
5554
rw [mul_le_mul_iff_right₀ hC0]

Mathlib/Analysis/Normed/Unbundled/SmoothingSeminorm.lean

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private theorem smoothingSeminormSeq_tendsto_aux {L : ℝ} (hL : 0 ≤ L) {ε :
8888
theorem zero_mem_lowerBounds_smoothingSeminormSeq_range (x : R) :
8989
0 ∈ lowerBounds (Set.range fun n : ℕ+ => μ (x ^ (n : ℕ)) ^ (1 / (n : ℝ))) := by
9090
rintro y ⟨n, rfl⟩
91-
exact rpow_nonneg (apply_nonneg μ _) _
91+
positivity
9292

9393
/-- `smoothingSeminormSeq` is bounded below (by zero). -/
9494
theorem smoothingSeminormSeq_bddBelow (x : R) :
@@ -111,15 +111,15 @@ theorem tendsto_smoothingFun_of_eq_zero {x : R} (hx : μ x = 0) :
111111
have hL0 : (iInf fun n : PNat => μ (x ^ (n : ℕ)) ^ (1 / (n : ℝ))) = 0 :=
112112
le_antisymm
113113
(ciInf_le_of_le (smoothingSeminormSeq_bddBelow μ x) (1 : PNat) (le_of_eq (h0 1 (le_refl _))))
114-
(le_ciInf fun n => rpow_nonneg (apply_nonneg μ _) _)
114+
(le_ciInf fun n by positivity)
115115
simpa only [hL0] using tendsto_atTop_of_eventually_const h0
116116

117117
/-- If `μ 1 ≤ 1` and `μ x ≠ 0`, then `smoothingFun μ x` is the limit of
118118
`smoothingSeminormSeq μ x`. -/
119119
theorem tendsto_smoothingFun_of_ne_zero (hμ1 : μ 11) {x : R} (hx : μ x ≠ 0) :
120120
Tendsto (smoothingSeminormSeq μ x) atTop (𝓝 (smoothingFun μ x)) := by
121121
let L := iInf fun n : PNat => μ (x ^ (n : ℕ)) ^ (1 / (n : ℝ))
122-
have hL0 : 0 ≤ L := le_ciInf fun x => rpow_nonneg (apply_nonneg _ _) _
122+
have hL0 : 0 ≤ L := le_ciInf fun x by positivity
123123
rw [Metric.tendsto_atTop]
124124
intro ε hε
125125
/- For each `ε > 0`, we can find a positive natural number `m1` such that
@@ -247,7 +247,7 @@ theorem tendsto_smoothingFun_of_map_one_le_one (hμ1 : μ 1 ≤ 1) (x : R) :
247247
/-- If `μ 1 ≤ 1`, then `smoothingFun μ x` is nonnegative. -/
248248
theorem smoothingFun_nonneg (hμ1 : μ 11) (x : R) : 0 ≤ smoothingFun μ x := by
249249
apply ge_of_tendsto (tendsto_smoothingFun_of_map_one_le_one μ hμ1 x)
250-
simpa [eventually_atTop, ge_iff_le] using1, fun _ _ ↦ rpow_nonneg (apply_nonneg μ _) _
250+
simpa [eventually_atTop, ge_iff_le] using1, fun _ _ ↦ by positivity
251251

252252
/-- If `μ 1 ≤ 1`, then `smoothingFun μ 1 ≤ 1`. -/
253253
theorem smoothingFun_one_le (hμ1 : μ 11) : smoothingFun μ 11 := by
@@ -398,7 +398,7 @@ private theorem limsup_mu_le (hμ1 : μ 1 ≤ 1) {s : ℕ → ℕ} (hs_le : ∀
398398
· use 0
399399
simp only [mem_lowerBounds, eventually_map, eventually_atTop, ge_iff_le,
400400
Set.mem_setOf_eq, forall_exists_index]
401-
exact fun _ m hm ↦ le_trans (rpow_nonneg (apply_nonneg μ _) _) (hm m (le_refl _))
401+
exact fun _ m hm ↦ le_trans (by positivity) (hm m (le_refl _))
402402
_ ≤ 1 := (μ_limsup_le_one μ hs_le hψ_lim)
403403
_ = smoothingFun μ x ^ a := by rw [ha, rpow_zero]
404404
· have ha_pos : 0 < a := lt_of_le_of_ne a_in.1 (Ne.symm ha)
@@ -465,15 +465,14 @@ theorem isNonarchimedean_smoothingFun (hμ1 : μ 1 ≤ 1) (hna : IsNonarchimedea
465465
limsup (fun n : ℕ => μ (x ^ mu (ψ n)) ^ (1 / (ψ n : ℝ)) * μ (y ^ nu (ψ n)) ^ (1 / (ψ n : ℝ)))
466466
atTop ≤ limsup (fun n : ℕ => μ (x ^ mu (ψ n)) ^ (1 / (ψ n : ℝ))) atTop *
467467
limsup (fun n : ℕ => μ (y ^ nu (ψ n)) ^ (1 / (ψ n : ℝ))) atTop :=
468-
limsup_mul_le (Frequently.of_forall (fun n => rpow_nonneg (apply_nonneg _ _) _))
468+
limsup_mul_le (Frequently.of_forall (fun n by positivity))
469469
(μ_bddAbove μ hμ1 hmu_le x ψ).isBoundedUnder_of_range
470-
(Eventually.of_forall (fun n => rpow_nonneg (apply_nonneg _ _) _))
470+
(Eventually.of_forall (fun n by positivity))
471471
(μ_bddAbove μ hμ1 hnu_le y ψ).isBoundedUnder_of_range
472472
have h_bdd : IsBoundedUnder LE.le atTop fun n : ℕ => μ (y ^ nu (ψ n)) ^ (1 / (ψ n : ℝ)) :=
473473
RingSeminorm.isBoundedUnder μ hμ1 hnu_le ψ
474474
apply le_trans hxy' (mul_le_mul hx hy (le_limsup_of_frequently_le (Frequently.of_forall
475-
(fun n ↦ rpow_nonneg (apply_nonneg μ _) _)) h_bdd)
476-
(rpow_nonneg (smoothingFun_nonneg μ hμ1 x) _))
475+
(fun n ↦ by positivity)) h_bdd) (rpow_nonneg (smoothingFun_nonneg μ hμ1 x) _))
477476
apply le_of_forall_sub_le
478477
/- Fix `ε > 0`. We first show that `smoothingFun μ x ^ a * smoothingFun μ y ^ b + ε ≤
479478
max (smoothingFun μ x) (smoothingFun μ y) + ε`. -/
@@ -502,8 +501,8 @@ theorem isNonarchimedean_smoothingFun (hμ1 : μ 1 ≤ 1) (hna : IsNonarchimedea
502501
have hex : ∃ n : PNat, μ (x ^ mu (ψ n)) ^ (1 / (ψ n : ℝ)) * μ (y ^ nu (ψ n)) ^ (1 / (ψ n : ℝ)) <
503502
smoothingFun μ x ^ a * smoothingFun μ y ^ b + ε :=
504503
Filter.exists_lt_of_limsup_le (bddAbove_range_mul (μ_bddAbove μ hμ1 hmu_le _ _)
505-
(fun n => rpow_nonneg (apply_nonneg _ _) _) (μ_bddAbove μ hμ1 hnu_le _ _)
506-
fun n => rpow_nonneg (apply_nonneg _ _) _).isBoundedUnder_of_range hxy hε
504+
(fun n by positivity) (μ_bddAbove μ hμ1 hnu_le _ _)
505+
(fun n by positivity)).isBoundedUnder_of_range hxy hε
507506
obtain ⟨N, hN⟩ := hex
508507
/- By definition of `smoothingFun`, and applying the inequality `hN`, it suffices to show that
509508
`μ ((x + y) ^ ψ N) ^ (1 / ψ N) ≤ μ (x ^ mu (ψ N)) ^ (1 / ψ N) * μ (y ^ nu ψ N) ^ (1 / ψ N)`. -/

Mathlib/Analysis/Normed/Unbundled/SpectralNorm.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ theorem spectralValueTerms_bddAbove (p : R[X]) : BddAbove (Set.range (spectralVa
129129
theorem spectralValueTerms_nonneg (p : R[X]) (n : ℕ) : 0 ≤ spectralValueTerms p n := by
130130
simp only [spectralValueTerms]
131131
split_ifs with h
132-
· exact rpow_nonneg (norm_nonneg _) _
132+
· positivity
133133
· exact le_refl _
134134

135135
/-- The spectral value of a polynomial is nonnegative. -/
@@ -262,7 +262,8 @@ theorem norm_root_le_spectralValue {f : AlgebraNorm K L} (hf_pm : IsPowMul f)
262262
Set.range (spectralValueTerms p) := by use n; simp only [spectralValueTerms, if_pos hn]
263263
exact h_ge (‖p.coeff n‖₊ ^ (1 / (p.natDegree - n : ℝ))) h_rg
264264
rw [← hexp, ← rpow_natCast, ← rpow_natCast]
265-
exact rpow_lt_rpow (rpow_nonneg (norm_nonneg _) _) h_base (cast_pos.mpr (tsub_pos_of_lt hn))
265+
gcongr
266+
exact cast_pos.mpr (tsub_pos_of_lt hn)
266267
have h_deg : 0 < p.natDegree := natDegree_pos_of_monic_of_aeval_eq_zero hp hx
267268
have h_lt : f ((Finset.range p.natDegree).sum fun i : ℕ ↦ p.coeff i • x ^ i) <
268269
f (x ^ p.natDegree) := by

Mathlib/Analysis/SpecialFunctions/Gamma/Beta.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ theorem approx_Gamma_integral_tendsto_Gamma_integral {s : ℂ} (hs : 0 < re s) :
327327
rcases lt_or_ge (n : ℝ) x with (hxn | hxn)
328328
· rw [indicator_of_notMem (notMem_Ioc_of_gt hxn), norm_zero,
329329
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
330-
exact rpow_nonneg (le_of_lt hx) _
330+
positivity
331331
· rw [indicator_of_mem (mem_Ioc.mpr ⟨mem_Ioi.mp hx, hxn⟩), norm_mul, Complex.norm_of_nonneg
332332
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le₀ hxn <| by positivity) _),
333333
norm_cpow_eq_rpow_re_of_pos hx, sub_re, one_re]

Mathlib/Combinatorics/Additive/AP/Three/Behrend.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ theorem le_N (hN : 2 ≤ N) : (2 * dValue N - 1) ^ nValue N ≤ N := by
388388
rw [cast_ne_zero]
389389
apply (nValue_pos hN).ne'
390390
rw [← le_div_iff₀']
391-
· exact floor_le (div_nonneg (rpow_nonneg (cast_nonneg _) _) zero_le_two)
391+
· exact floor_le (by positivity)
392392
apply zero_lt_two
393393

394394
theorem bound (hN : 4096 ≤ N) : (N : ℝ) ^ (nValue N : ℝ)⁻¹ / exp 1 < dValue N := by

Mathlib/MeasureTheory/Function/UniformIntegrable.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ theorem MemLp.eLpNorm_indicator_norm_ge_le (hf : MemLp f p μ) (hmeas : Strongly
290290
rw [enorm_indicator_eq_indicator_enorm, enorm_indicator_eq_indicator_enorm]
291291
have hiff : M ^ (1 / p.toReal) ≤ ‖f x‖₊ ↔ M ≤ ‖‖f x‖ ^ p.toReal‖₊ := by
292292
rw [coe_nnnorm, coe_nnnorm, Real.norm_rpow_of_nonneg (norm_nonneg _), norm_norm,
293-
← Real.rpow_le_rpow_iff hM' (Real.rpow_nonneg (norm_nonneg _) _)
293+
← Real.rpow_le_rpow_iff hM' (by positivity)
294294
(one_div_pos.2 <| ENNReal.toReal_pos hp_ne_zero hp_ne_top), ← Real.rpow_mul (norm_nonneg _),
295295
mul_one_div_cancel (ENNReal.toReal_pos hp_ne_zero hp_ne_top).ne.symm, Real.rpow_one]
296296
by_cases hx : x ∈ { x : α | M ^ (1 / p.toReal) ≤ ‖f x‖₊ }

Mathlib/MeasureTheory/Integral/Bochner/Basic.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,11 +1183,11 @@ theorem integral_mul_norm_le_Lp_mul_Lq {E} [NormedAddCommGroup E] {f g : α →
11831183
rw [integral_eq_lintegral_of_nonneg_ae, integral_eq_lintegral_of_nonneg_ae,
11841184
integral_eq_lintegral_of_nonneg_ae]
11851185
rotate_left
1186-
· exact Eventually.of_forall fun x => Real.rpow_nonneg (norm_nonneg _) _
1186+
· exact Eventually.of_forall fun x by positivity
11871187
· exact (hg.1.norm.aemeasurable.pow aemeasurable_const).aestronglyMeasurable
1188-
· exact Eventually.of_forall fun x => Real.rpow_nonneg (norm_nonneg _) _
1188+
· exact Eventually.of_forall fun x by positivity
11891189
· exact (hf.1.norm.aemeasurable.pow aemeasurable_const).aestronglyMeasurable
1190-
· exact Eventually.of_forall fun x => mul_nonneg (norm_nonneg _) (norm_nonneg _)
1190+
· exact Eventually.of_forall fun x by positivity
11911191
· exact hf.1.norm.mul hg.1.norm
11921192
rw [ENNReal.toReal_rpow, ENNReal.toReal_rpow, ← ENNReal.toReal_mul]
11931193
-- replace norms by nnnorm

0 commit comments

Comments
 (0)