/-
Copyright 2025 The Formal Conjectures Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-/
module
public import Mathlib.Analysis.Complex.ExponentialBounds
public import Mathlib.Analysis.SpecialFunctions.Log.Basic
import Mathlib.Tactic@[expose] public section
The iterated logarithm of x is the number of times the natural logarithm
must be iteratively applied before the result is less than or equal to 1.
Reference: https://en.wikipedia.org/wiki/Iterated_logarithm
noncomputable def Real.iteratedLog (x : ℝ) : ℕ :=
sInf { (n : ℕ) | Real.log^[n] x ≤ 1 }theorem Real.iteratedLog_eq_zero_of_le {x : ℝ} (hx : x ≤ 1) :
Real.iteratedLog x = 0 := x:ℝhx:x ≤ 1⊢ x.iteratedLog = 0
All goals completed! 🐙theorem Real.iteratedLog_eq_zero_of_neg {x : ℝ} (hx : x < 0) :
Real.iteratedLog x = 0 :=
Real.iteratedLog_eq_zero_of_le (x:ℝhx:x < 0⊢ x ≤ 1 All goals completed! 🐙)this:Real.log 2 ≤ 1⊢ Nat.find ⋯ = 1
exact (Nat.find_eq_iff _).2 ⟨this, fun n hn => by this:Real.log 2 ≤ 1n:ℕhn:n < 1⊢ n ∉ {x | Real.log^[x] 2 ≤ 1} simp [Nat.lt_one_iff.1 hn] All goals completed! 🐙⟩
theorem iteratedLog_four : Real.iteratedLog 4 = 2 := by ⊢ Real.iteratedLog 4 = 2
simp [Real.iteratedLog] ⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2
have : Real.log^[2] 4 ≤ 1 := by ⊢ Real.iteratedLog 4 = 2 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2
have h_ne_zero : Real.log √4 ≠ 0 := by ⊢ Real.iteratedLog 4 = 2 h_ne_zero:Real.log √4 ≠ 0⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2 simp ⊢ ¬√4 = -1 h_ne_zero:Real.log √4 ≠ 0⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2; linarith [Real.sqrt_nonneg 4] h_ne_zero:Real.log √4 ≠ 0⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2 h_ne_zero:Real.log √4 ≠ 0⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2
have : Real.log 4 ≤ 2 := by ⊢ Real.iteratedLog 4 = 2 h_ne_zero:Real.log √4 ≠ 0this:Real.log 4 ≤ 2⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2
have := mul_eq_of_eq_mul_inv₀ h_ne_zero <| div_eq_mul_inv _ (2 : ℝ) ▸ (Real.log_sqrt (show 0 ≤ 4 by ⊢ Real.iteratedLog 4 = 2 h_ne_zero:Real.log √4 ≠ 0this:Real.log √4 * 2 = Real.log 4⊢ Real.log 4 ≤ 2 h_ne_zero:Real.log √4 ≠ 0this:Real.log 4 ≤ 2⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2 linarith All goals completed! 🐙 h_ne_zero:Real.log √4 ≠ 0this:Real.log √4 * 2 = Real.log 4⊢ Real.log 4 ≤ 2 h_ne_zero:Real.log √4 ≠ 0this:Real.log 4 ≤ 2⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2)) h_ne_zero:Real.log √4 ≠ 0this:Real.log √4 * 2 = Real.log 4⊢ Real.log 4 ≤ 2 h_ne_zero:Real.log √4 ≠ 0this:Real.log 4 ≤ 2⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2
rw [← this h_ne_zero:Real.log √4 ≠ 0this:Real.log √4 * 2 = Real.log 4⊢ Real.log √4 * 2 ≤ 2 h_ne_zero:Real.log √4 ≠ 0this:Real.log √4 * 2 = Real.log 4⊢ Real.log √4 * 2 ≤ 2 h_ne_zero:Real.log √4 ≠ 0this:Real.log 4 ≤ 2⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2] h_ne_zero:Real.log √4 ≠ 0this:Real.log √4 * 2 = Real.log 4⊢ Real.log √4 * 2 ≤ 2 h_ne_zero:Real.log √4 ≠ 0this:Real.log 4 ≤ 2⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2
norm_num h_ne_zero:Real.log √4 ≠ 0this:Real.log √4 * 2 = Real.log 4⊢ Real.log 2 ≤ 1 h_ne_zero:Real.log √4 ≠ 0this:Real.log 4 ≤ 2⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2
convert! Real.log_le_sub_one_of_pos (show 0 < 2 by ⊢ Real.iteratedLog 4 = 2 h_ne_zero:Real.log √4 ≠ 0this:Real.log 4 ≤ 2⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2 norm_num All goals completed! 🐙 h_ne_zero:Real.log √4 ≠ 0this:Real.log 4 ≤ 2⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2)
norm_num h_ne_zero:Real.log √4 ≠ 0this:Real.log 4 ≤ 2⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2 h_ne_zero:Real.log √4 ≠ 0this:Real.log 4 ≤ 2⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2
have : Real.log 4 - 1 ≤ 1 := by ⊢ Real.iteratedLog 4 = 2 h_ne_zero:Real.log √4 ≠ 0this✝:Real.log 4 ≤ 2this:Real.log 4 - 1 ≤ 1⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2 convert sub_le_sub_right this 1 h_ne_zero:Real.log √4 ≠ 0this:Real.log 4 ≤ 2⊢ 1 = 2 - 1 h_ne_zero:Real.log √4 ≠ 0this✝:Real.log 4 ≤ 2this:Real.log 4 - 1 ≤ 1⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2; norm_num h_ne_zero:Real.log √4 ≠ 0this✝:Real.log 4 ≤ 2this:Real.log 4 - 1 ≤ 1⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2 h_ne_zero:Real.log √4 ≠ 0this✝:Real.log 4 ≤ 2this:Real.log 4 - 1 ≤ 1⊢ Real.log^[2] 4 ≤ 1 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2
exact le_trans (Real.log_le_sub_one_of_pos (Real.log_pos <| by h_ne_zero:Real.log √4 ≠ 0this✝:Real.log 4 ≤ 2this:Real.log 4 - 1 ≤ 1⊢ 1 < 4 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2 norm_num All goals completed! 🐙 this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2)) this this:Real.log^[2] 4 ≤ 1⊢ sInf {x | Real.log^[x] 4 ≤ 1} = 2
rw [Nat.sInf_def ⟨2, by this:Real.log^[2] 4 ≤ 1⊢ 2 ∈ {x | Real.log^[x] 4 ≤ 1} this:Real.log^[2] 4 ≤ 1⊢ Nat.find ⋯ = 2 aesop All goals completed! 🐙 this:Real.log^[2] 4 ≤ 1⊢ Nat.find ⋯ = 2⟩] this:Real.log^[2] 4 ≤ 1⊢ Nat.find ⋯ = 2
refine (Nat.find_eq_iff _).2 ⟨by this:Real.log^[2] 4 ≤ 1⊢ 2 ∈ {x | Real.log^[x] 4 ≤ 1} aesop All goals completed! 🐙, fun n hn => ?_⟩
interval_cases n «0» this:Real.log^[2] 4 ≤ 1n:ℕhn:0 < 2⊢ 0 ∉ {x | Real.log^[x] 4 ≤ 1}«1» this:Real.log^[2] 4 ≤ 1n:ℕhn:1 < 2⊢ 1 ∉ {x | Real.log^[x] 4 ≤ 1}; simp «1» this:Real.log^[2] 4 ≤ 1n:ℕhn:1 < 2⊢ 1 ∉ {x | Real.log^[x] 4 ≤ 1}
simp [Real.lt_log_iff_exp_lt] «1» this:Real.log^[2] 4 ≤ 1n:ℕhn:1 < 2⊢ Real.exp 1 < 4
linarith [Real.exp_one_lt_d9] All goals completed! 🐙