Skip to content

Commit a2d097b

Browse files
committed
chore: more uses of calc and gcongr (#19173)
Motivated by the deprecation in #19081
1 parent 0002a67 commit a2d097b

File tree

16 files changed

+83
-96
lines changed

16 files changed

+83
-96
lines changed

Mathlib/Algebra/Order/GroupWithZero/Unbundled.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,9 @@ theorem pow_le_pow_left₀ (ha : 0 ≤ a) (hab : a ≤ b) : ∀ n, a ^ n ≤ b ^
10331033
| n + 1 => by simpa only [pow_succ']
10341034
using mul_le_mul hab (pow_le_pow_left₀ ha hab _) (pow_nonneg ha _) (ha.trans hab)
10351035

1036+
lemma pow_left_monotoneOn : MonotoneOn (fun a : M₀ ↦ a ^ n) {x | 0 ≤ x} :=
1037+
fun _a ha _b _ hab ↦ pow_le_pow_left₀ ha hab _
1038+
10361039
end
10371040

10381041
variable [Preorder α] {f g : α → M₀}

Mathlib/Analysis/Fourier/FourierTransformDeriv.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,8 @@ lemma norm_iteratedFDeriv_fourierPowSMulRight
412412
gcongr with i hi
413413
· rw [← Nat.cast_pow, Nat.cast_le]
414414
calc n.descFactorial i ≤ n ^ i := Nat.descFactorial_le_pow _ _
415-
_ ≤ (n + 1) ^ i := pow_le_pow_left (by omega) (by omega) i
416-
_ ≤ (n + 1) ^ k := pow_right_mono₀ (by omega) (Finset.mem_range_succ_iff.mp hi)
415+
_ ≤ (n + 1) ^ i := by gcongr; omega
416+
_ ≤ (n + 1) ^ k := by gcongr; exacts [le_add_self, Finset.mem_range_succ_iff.mp hi]
417417
· exact hv _ (by omega) _ (by omega)
418418
_ = (2 * n + 2) ^ k * (‖L‖^n * C) := by
419419
simp only [← Finset.sum_mul, ← Nat.cast_sum, Nat.sum_range_choose, mul_one, ← mul_assoc,

Mathlib/Analysis/InnerProductSpace/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ instance (priority := 100) InnerProductSpace.toUniformConvexSpace : UniformConve
12121212
refine le_sqrt_of_sq_le ?_
12131213
rw [sq, eq_sub_iff_add_eq.2 (parallelogram_law_with_norm ℝ x y), ← sq ‖x - y‖, hx, hy]
12141214
ring_nf
1215-
exact sub_le_sub_left (pow_le_pow_left hε.le hxy _) 4
1215+
gcongr
12161216

12171217
section Complex_Seminormed
12181218

Mathlib/Analysis/Normed/Field/Ultra.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ lemma isUltrametricDist_of_forall_pow_norm_le_nsmul_pow_max_one_norm
8989
-- `‖x + 1‖ ^ m ≤ (m + 1) • max 1 ‖x‖ ^ m`, so we're done
9090
-- we can distribute powers into the right term of `max`
9191
have hp : max 1 ‖x‖ ^ m = max 1 (‖x‖ ^ m) := by
92-
have : MonotoneOn (fun a : ℝ ↦ a ^ m) (Set.Ici _) := fun a h b _ h' ↦ pow_le_pow_left h h' _
93-
rw [this.map_max (by simp [zero_le_one]) (norm_nonneg x), one_pow]
92+
rw [pow_left_monotoneOn.map_max (by simp [zero_le_one]) (norm_nonneg x), one_pow]
9493
rw [hp] at hm
9594
refine le_of_pow_le_pow_left₀ (fun h ↦ ?_) (zero_lt_one.trans ha').le ((h _ _).trans hm.le)
9695
simp only [h, zero_add, pow_zero, max_self, one_smul, lt_self_iff_false] at hm

Mathlib/Analysis/SpecialFunctions/Exp.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ theorem tendsto_exp_div_pow_atTop (n : ℕ) : Tendsto (fun x => exp x / x ^ n) a
264264
have hx₀ : 0 < x := (Nat.cast_nonneg N).trans_lt hx
265265
rw [Set.mem_Ici, le_div_iff₀ (pow_pos hx₀ _), ← le_div_iff₀' hC₀]
266266
calc
267-
x ^ n ≤ ⌈x⌉₊ ^ n := mod_cast pow_le_pow_left hx₀.le (Nat.le_ceil _) _
267+
x ^ n ≤ ⌈x⌉₊ ^ n := by gcongr; exact Nat.le_ceil _
268268
_ ≤ exp ⌈x⌉₊ / (exp 1 * C) := mod_cast (hN _ (Nat.lt_ceil.2 hx).le).le
269269
_ ≤ exp (x + 1) / (exp 1 * C) := by gcongr; exact (Nat.ceil_lt_add_one hx₀.le).le
270270
_ = exp x / C := by rw [add_comm, exp_add, mul_div_mul_left _ _ (exp_pos _).ne']

Mathlib/Analysis/SpecialFunctions/JapaneseBracket.lean

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,14 @@ variable {E}
7272
theorem finite_integral_rpow_sub_one_pow_aux {r : ℝ} (n : ℕ) (hnr : (n : ℝ) < r) :
7373
(∫⁻ x : ℝ in Ioc 0 1, ENNReal.ofReal ((x ^ (-r⁻¹) - 1) ^ n)) < ∞ := by
7474
have hr : 0 < r := lt_of_le_of_lt n.cast_nonneg hnr
75-
have h_int : ∀ x : ℝ, x ∈ Ioc (0 : ℝ) 1
76-
ENNReal.ofReal ((x ^ (-r⁻¹) - 1) ^ n) ≤ ENNReal.ofReal (x ^ (-(r⁻¹ * n))) := fun x hx ↦ by
77-
apply ENNReal.ofReal_le_ofReal
78-
rw [← neg_mul, rpow_mul hx.1.le, rpow_natCast]
79-
refine pow_le_pow_left ?_ (by simp only [sub_le_self_iff, zero_le_one]) n
80-
rw [le_sub_iff_add_le', add_zero]
81-
refine Real.one_le_rpow_of_pos_of_le_one_of_nonpos hx.1 hx.2 ?_
82-
rw [Right.neg_nonpos_iff, inv_nonneg]
83-
exact hr.le
75+
have h_int x (hx : x ∈ Ioc (0 : ℝ) 1) := by
76+
calc
77+
ENNReal.ofReal ((x ^ (-r⁻¹) - 1) ^ n) ≤ .ofReal ((x ^ (-r⁻¹) - 0) ^ n) := by
78+
gcongr
79+
· rw [sub_nonneg]
80+
exact Real.one_le_rpow_of_pos_of_le_one_of_nonpos hx.1 hx.2 (by simpa using hr.le)
81+
· norm_num
82+
_ = .ofReal (x ^ (-(r⁻¹ * n))) := by simp [rpow_mul hx.1.le, ← neg_mul]
8483
refine lt_of_le_of_lt (setLIntegral_mono' measurableSet_Ioc h_int) ?_
8584
refine IntegrableOn.setLIntegral_lt_top ?_
8685
rw [← intervalIntegrable_iff_integrableOn_Ioc_of_le zero_le_one]

Mathlib/Combinatorics/SimpleGraph/Regularity/Bound.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private theorem eps_pos {ε : ℝ} {n : ℕ} (h : 100 ≤ (4 : ℝ) ^ n * ε ^ 5
6969
(pos_of_mul_pos_right ((show 0 < (100 : ℝ) by norm_num).trans_le h) (by positivity))
7070

7171
private theorem m_pos [Nonempty α] (hPα : #P.parts * 16 ^ #P.parts ≤ card α) : 0 < m :=
72-
Nat.div_pos ((Nat.mul_le_mul_left _ <| Nat.pow_le_pow_left (by norm_num) _).trans hPα) <|
72+
Nat.div_pos (hPα.trans' <| by unfold stepBound; gcongr; norm_num) <|
7373
stepBound_pos (P.parts_nonempty <| univ_nonempty.ne_empty).card_pos
7474

7575
/-- Local extension for the `positivity` tactic: A few facts that are needed many times for the

Mathlib/Combinatorics/SimpleGraph/Regularity/Chunk.lean

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,19 @@ private theorem one_sub_le_m_div_m_add_one_sq [Nonempty α]
226226
sz_positivity
227227

228228
private theorem m_add_one_div_m_le_one_add [Nonempty α]
229-
(hPα : #P.parts * 16 ^ #P.parts ≤ card α) (hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5)
230-
(hε₁ : ε ≤ 1) : ((m + 1 : ℝ) / m) ^ 2 ≤ ↑1 + ε ^ 5 / 49 := by
231-
rw [same_add_div]
232-
swap; · sz_positivity
233-
have : ↑1 + ↑1 / (m : ℝ) ≤ ↑1 + ε ^ 5 / 100 := by
234-
rw [add_le_add_iff_left, ← one_div_div (100 : ℝ)]
235-
exact one_div_le_one_div_of_le (by sz_positivity) (hundred_div_ε_pow_five_le_m hPα hPε)
236-
refine (pow_le_pow_left ?_ this 2).trans ?_
237-
· positivity
238-
rw [add_sq, one_pow, add_assoc, add_le_add_iff_left, mul_one, ← le_sub_iff_add_le',
239-
div_eq_mul_one_div _ (49 : ℝ), mul_div_left_comm (2 : ℝ), ← mul_sub_left_distrib, div_pow,
240-
div_le_iff₀ (show (0 : ℝ) < ↑100 ^ 2 by norm_num), mul_assoc, sq]
241-
refine mul_le_mul_of_nonneg_left ?_ (by sz_positivity)
242-
exact (pow_le_one₀ (by sz_positivity) hε₁).trans (by norm_num)
229+
(hPα : #P.parts * 16 ^ #P.parts ≤ card α) (hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5) (hε₁ : ε ≤ 1) :
230+
((m + 1 : ℝ) / m) ^ 2 ≤ ↑1 + ε ^ 5 / 49 := by
231+
have : 0 ≤ ε := by sz_positivity
232+
rw [same_add_div (by sz_positivity)]
233+
calc
234+
_ ≤ (1 + ε ^ 5 / 100) ^ 2 := by
235+
gcongr (1 + ?_) ^ 2
236+
rw [← one_div_div (100 : ℝ)]
237+
exact one_div_le_one_div_of_le (by sz_positivity) (hundred_div_ε_pow_five_le_m hPα hPε)
238+
_ = 1 + ε ^ 5 * (50⁻¹ + ε ^ 5 / 10000) := by ring
239+
_ ≤ 1 + ε ^ 5 * (50⁻¹ + 1 ^ 5 / 10000) := by gcongr
240+
_ ≤ 1 + ε ^ 5 * 49⁻¹ := by gcongr; norm_num
241+
_ = 1 + ε ^ 5 / 49 := by rw [div_eq_mul_inv]
243242

244243
private theorem density_sub_eps_le_sum_density_div_card [Nonempty α]
245244
(hPα : #P.parts * 16 ^ #P.parts ≤ card α) (hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5)
@@ -346,21 +345,20 @@ private theorem edgeDensity_chunk_aux [Nonempty α]
346345
· exact mod_cast G.edgeDensity_le_one _ _
347346
· exact div_le_div_of_nonneg_left (by sz_positivity) (by norm_num) (by norm_num)
348347
rw [← sub_nonneg] at hGε
349-
have : ↑(G.edgeDensity U V) - ε ^ 5 / ↑50
350-
(∑ ab ∈ (chunk hP G ε hU).parts.product (chunk hP G ε hV).parts,
351-
(G.edgeDensity ab.1 ab.2 : ℝ)) / ↑16 ^ #P.parts := by
352-
have rflU := Set.Subset.refl (chunk hP G ε hU).parts.toSet
353-
have rflV := Set.Subset.refl (chunk hP G ε hV).parts.toSet
354-
refine (le_trans ?_ <| density_sub_eps_le_sum_density_div_card hPα hPε rflU rflV).trans ?_
355-
· rw [biUnion_parts, biUnion_parts]
356-
· rw [card_chunk (m_pos hPα).ne', card_chunk (m_pos hPα).ne', ← cast_mul, ← mul_pow, cast_pow]
357-
norm_cast
358-
refine le_trans ?_ (pow_le_pow_left hGε this 2)
359-
rw [sub_sq, sub_add, sub_le_sub_iff_left]
360-
refine (sub_le_self _ <| sq_nonneg <| ε ^ 5 / 50).trans ?_
361-
rw [mul_right_comm, mul_div_left_comm, div_eq_mul_inv (ε ^ 5),
362-
show (2 : ℝ) / 50 = 25⁻¹ by norm_num]
363-
exact mul_le_of_le_one_right (by sz_positivity) (mod_cast G.edgeDensity_le_one _ _)
348+
have : 0 ≤ ε := by sz_positivity
349+
calc
350+
_ = G.edgeDensity U V ^ 2 - 1 * ε ^ 5 / 25 + 0 ^ 10 / 2500 := by ring
351+
_ ≤ G.edgeDensity U V ^ 2 - G.edgeDensity U V * ε ^ 5 / 25 + ε ^ 10 / 2500 := by
352+
gcongr; exact mod_cast G.edgeDensity_le_one ..
353+
_ = (G.edgeDensity U V - ε ^ 5 / 50) ^ 2 := by ring
354+
_ ≤ _ := by
355+
gcongr
356+
have rflU := Set.Subset.refl (chunk hP G ε hU).parts.toSet
357+
have rflV := Set.Subset.refl (chunk hP G ε hV).parts.toSet
358+
refine (le_trans ?_ <| density_sub_eps_le_sum_density_div_card hPα hPε rflU rflV).trans ?_
359+
· rw [biUnion_parts, biUnion_parts]
360+
· rw [card_chunk (m_pos hPα).ne', card_chunk (m_pos hPα).ne', ← cast_mul, ← mul_pow, cast_pow]
361+
norm_cast
364362

365363
private theorem abs_density_star_sub_density_le_eps (hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5)
366364
(hε₁ : ε ≤ 1) {hU : U ∈ P.parts} {hV : V ∈ P.parts} (hUV' : U ≠ V) (hUV : ¬G.IsUniform ε U V) :

Mathlib/Combinatorics/SimpleGraph/Regularity/Lemma.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ theorem szemeredi_regularity (hε : 0 < ε) (hl : l ≤ card α) :
100100
obtain ⟨P, hP₁, hP₂, hP₃, hP₄⟩ := h (⌊4 / ε ^ 5⌋₊ + 1)
101101
refine ⟨P, hP₁, (le_initialBound _ _).trans hP₂, hP₃.trans ?_,
102102
hP₄.resolve_right fun hPenergy => lt_irrefl (1 : ℝ) ?_⟩
103-
· rw [iterate_succ_apply']
104-
exact mul_le_mul_left' (pow_le_pow_left (by norm_num) (by norm_num) _) _
103+
· rw [iterate_succ_apply', stepBound, bound]
104+
gcongr
105+
norm_num
105106
calc
106107
(1 : ℝ) = ε ^ 5 / ↑4 * (↑4 / ε ^ 5) := by
107108
rw [mul_comm, div_mul_div_cancel₀ (pow_pos hε 5).ne']; norm_num

Mathlib/Data/Complex/Exponential.lean

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,13 +1441,12 @@ theorem one_sub_div_pow_le_exp_neg {n : ℕ} {t : ℝ} (ht' : t ≤ n) : (1 - t
14411441
rcases eq_or_ne n 0 with (rfl | hn)
14421442
· simp
14431443
rwa [Nat.cast_zero] at ht'
1444-
convert pow_le_pow_left ?_ (one_sub_le_exp_neg (t / n)) n using 2
1445-
· rw [← Real.exp_nat_mul]
1446-
congr 1
1447-
field_simp
1448-
ring_nf
1449-
· rwa [sub_nonneg, div_le_one]
1450-
positivity
1444+
calc
1445+
(1 - t / n) ^ n ≤ rexp (-(t / n)) ^ n := by
1446+
gcongr
1447+
· exact sub_nonneg.2 <| div_le_one_of_le₀ ht' n.cast_nonneg
1448+
· exact one_sub_le_exp_neg _
1449+
_ = rexp (-t) := by rw [← Real.exp_nat_mul, mul_neg, mul_comm, div_mul_cancel₀]; positivity
14511450

14521451
end Real
14531452

0 commit comments

Comments
 (0)