Skip to content

Commit

Permalink
feat: elementary estimate for Real.log (#20766)
Browse files Browse the repository at this point in the history
Generalize the theorem `log_pos_iff'`, weakening the hypothesis `hx : 0 < x` to the (perhaps more natural) hypothesis `hx : 0 ≤ x`. Do the same for `log_nonpos_iff` and depreciate  `log_nonpos_iff'`. Fix one trivial typo in a docstring of `Mathlib/NumberTheory/Bertrand.lean`.
  • Loading branch information
kebekus committed Jan 17, 2025
1 parent e5ab45e commit bad84cb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Mathlib/Analysis/SpecialFunctions/Integrals.lean
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ theorem intervalIntegrable_log' : IntervalIntegrable log volume a b := by
simpa using (hasDerivAt_id s).sub (hasDerivAt_mul_log hs.ne.symm)
· intro s ⟨hs₁, hs₂⟩
norm_num at *
exact (log_nonpos_iff hs₁).mpr hs₂.le
exact (log_nonpos_iff hs₁.le).mpr hs₂.le
· -- Show integrability on [1…t] by continuity
apply ContinuousOn.intervalIntegrable
apply Real.continuousOn_log.mono
Expand Down
17 changes: 10 additions & 7 deletions Mathlib/Analysis/SpecialFunctions/Log/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@ theorem le_log_iff_exp_le (hy : 0 < y) : x ≤ log y ↔ exp x ≤ y := by rw [

theorem lt_log_iff_exp_lt (hy : 0 < y) : x < log y ↔ exp x < y := by rw [← exp_lt_exp, exp_log hy]

theorem log_pos_iff (hx : 0 < x) : 0 < log x ↔ 1 < x := by
theorem log_pos_iff (hx : 0 ≤ x) : 0 < log x ↔ 1 < x := by
rcases hx.eq_or_lt with (rfl | hx)
· simp [le_refl, zero_le_one]
rw [← log_one]
exact log_lt_log_iff zero_lt_one hx

@[bound]
theorem log_pos (hx : 1 < x) : 0 < log x :=
(log_pos_iff (lt_trans zero_lt_one hx)).2 hx
(log_pos_iff (lt_trans zero_lt_one hx).le).2 hx

theorem log_pos_of_lt_neg_one (hx : x < -1) : 0 < log x := by
rw [← neg_neg x, log_neg_eq_log]
Expand All @@ -172,16 +174,17 @@ theorem log_nonneg_iff (hx : 0 < x) : 0 ≤ log x ↔ 1 ≤ x := by rw [← not_
theorem log_nonneg (hx : 1 ≤ x) : 0 ≤ log x :=
(log_nonneg_iff (zero_lt_one.trans_le hx)).2 hx

theorem log_nonpos_iff (hx : 0 < x) : log x ≤ 0 ↔ x ≤ 1 := by rw [← not_lt, log_pos_iff hx, not_lt]

theorem log_nonpos_iff' (hx : 0 ≤ x) : log x ≤ 0 ↔ x ≤ 1 := by
theorem log_nonpos_iff (hx : 0 ≤ x) : log x ≤ 0 ↔ x ≤ 1 := by
rcases hx.eq_or_lt with (rfl | hx)
· simp [le_refl, zero_le_one]
exact log_nonpos_iff hx
rw [← not_lt, log_pos_iff hx.le, not_lt]

@[deprecated (since := "2025-01-16")]
alias log_nonpos_iff' := log_nonpos_iff

@[bound]
theorem log_nonpos (hx : 0 ≤ x) (h'x : x ≤ 1) : log x ≤ 0 :=
(log_nonpos_iff' hx).2 h'x
(log_nonpos_iff hx).2 h'x

theorem log_natCast_nonneg (n : ℕ) : 0 ≤ log n := by
if hn : n = 0 then
Expand Down
6 changes: 3 additions & 3 deletions Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ theorem one_le_rpow_of_pos_of_le_one_of_nonpos (hx1 : 0 < x) (hx2 : x ≤ 1) (hz
exact (rpow_zero x).symm

theorem rpow_lt_one_iff_of_pos (hx : 0 < x) : x ^ y < 11 < x ∧ y < 0 ∨ x < 10 < y := by
rw [rpow_def_of_pos hx, exp_lt_one_iff, mul_neg_iff, log_pos_iff hx, log_neg_iff hx]
rw [rpow_def_of_pos hx, exp_lt_one_iff, mul_neg_iff, log_pos_iff hx.le, log_neg_iff hx]

theorem rpow_lt_one_iff (hx : 0 ≤ x) :
x ^ y < 1 ↔ x = 0 ∧ y ≠ 01 < x ∧ y < 0 ∨ x < 10 < y := by
Expand All @@ -694,7 +694,7 @@ theorem rpow_lt_one_iff' {x y : ℝ} (hx : 0 ≤ x) (hy : 0 < y) :
rw [← Real.rpow_lt_rpow_iff hx zero_le_one hy, Real.one_rpow]

theorem one_lt_rpow_iff_of_pos (hx : 0 < x) : 1 < x ^ y ↔ 1 < x ∧ 0 < y ∨ x < 1 ∧ y < 0 := by
rw [rpow_def_of_pos hx, one_lt_exp_iff, mul_pos_iff, log_pos_iff hx, log_neg_iff hx]
rw [rpow_def_of_pos hx, one_lt_exp_iff, mul_pos_iff, log_pos_iff hx.le, log_neg_iff hx]

theorem one_lt_rpow_iff (hx : 0 ≤ x) : 1 < x ^ y ↔ 1 < x ∧ 0 < y ∨ 0 < x ∧ x < 1 ∧ y < 0 := by
rcases hx.eq_or_lt with (rfl | hx)
Expand Down Expand Up @@ -857,7 +857,7 @@ lemma zpow_lt_of_lt_log {n : ℤ} (hy : 0 < y) (h : log x < n * log y) : x < y ^
rpow_intCast _ _ ▸ rpow_lt_of_lt_log hy h

theorem rpow_le_one_iff_of_pos (hx : 0 < x) : x ^ y ≤ 11 ≤ x ∧ y ≤ 0 ∨ x ≤ 10 ≤ y := by
rw [rpow_def_of_pos hx, exp_le_one_iff, mul_nonpos_iff, log_nonneg_iff hx, log_nonpos_iff hx]
rw [rpow_def_of_pos hx, exp_le_one_iff, mul_nonpos_iff, log_nonneg_iff hx, log_nonpos_iff hx.le]

/-- Bound for `|log x * x ^ t|` in the interval `(0, 1]`, for positive real `t`. -/
theorem abs_log_mul_self_rpow_lt (x t : ℝ) (h1 : 0 < x) (h2 : x ≤ 1) (ht : 0 < t) :
Expand Down
6 changes: 3 additions & 3 deletions Mathlib/NumberTheory/Bertrand.lean
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ open Real

namespace Bertrand

/-- A reified version of the `Bertrand.main_inequality` below.
/-- A refined version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 ≤ x.
-/
theorem real_main_inequality {x : ℝ} (x_large : (512 : ℝ) ≤ x) :
Expand All @@ -61,7 +61,7 @@ theorem real_main_inequality {x : ℝ} (x_large : (512 : ℝ) ≤ x) :
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) x_large
rw [← div_le_one (rpow_pos_of_pos four_pos x), ← div_div_eq_mul_div, ← rpow_sub four_pos, ←
mul_div 2 x, mul_div_left_comm, ← mul_one_sub, (by norm_num1 : (1 : ℝ) - 2 / 3 = 1 / 3),
mul_one_div, ← log_nonpos_iff (hf' x h5), ← hf x h5]
mul_one_div, ← log_nonpos_iff (hf' x h5).le, ← hf x h5]
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11083): the proof was rewritten, because it was too slow
have h : ConcaveOn ℝ (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
Expand All @@ -88,7 +88,7 @@ theorem real_main_inequality {x : ℝ} (x_large : (512 : ℝ) ≤ x) :
norm_num1
· have : √(2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf _ (by norm_num1), log_nonpos_iff (hf' _ (by norm_num1)), this,
rw [hf _ (by norm_num1), log_nonpos_iff (hf' _ (by norm_num1)).le, this,
div_le_one (by positivity)]
conv in 512 => equals 2 ^ 9 => norm_num1
conv in 2 * 512 => equals 2 ^ 10 => norm_num1
Expand Down

0 comments on commit bad84cb

Please sign in to comment.