math / data /lean /OAI /NumberTheory /PiExponent /Approximation /ApproximationCenters.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
3.14 kB
import Mathlib
namespace OAI
namespace PiExponent
noncomputable def approximatePeriod (p : β„€) (q : β„•) : β„‚ :=
2 * Complex.I * (p : β„‚) / (q : β„‚)
theorem approximatePeriod_ne_zero {p : β„€} {q : β„•} (hp : p β‰  0) (hq : q β‰  0) :
approximatePeriod p q β‰  0 := by
unfold approximatePeriod
exact div_ne_zero
(mul_ne_zero (mul_ne_zero (by norm_num) Complex.I_ne_zero) (by exact_mod_cast hp))
(by exact_mod_cast hq)
theorem approximation_centers_injective {p : β„€} {q : β„•}
(hp : p β‰  0) (hq : q β‰  0) :
Function.Injective (fun j : β„• => (j : β„‚) * approximatePeriod p q) := by
intro j k h
have heq : (j : β„‚) = (k : β„‚) := mul_right_cancelβ‚€ (approximatePeriod_ne_zero hp hq) h
exact_mod_cast heq
noncomputable def logarithmicPeriod : β„‚ := 2 * (Real.pi : β„‚) * Complex.I
theorem norm_period_error (p : β„€) (q : β„•) :
β€–approximatePeriod p q - logarithmicPeriodβ€– =
2 * |Real.pi - (p : ℝ) / q| := by
have heq : approximatePeriod p q - logarithmicPeriod =
(2 * Complex.I) * (((p : ℝ) / q - Real.pi : ℝ) : β„‚) := by
unfold approximatePeriod logarithmicPeriod
push_cast
ring
rw [heq, norm_mul, Complex.norm_real, Real.norm_eq_abs]
norm_num [norm_mul, abs_sub_comm]
theorem norm_center_error_le (nu : ℝ) {p : β„€} {q j K : β„•}
(hj : j ≀ K)
(happrox : |Real.pi - (p : ℝ) / q| ≀ (q : ℝ) ^ (-nu)) :
β€–(j : β„‚) * (approximatePeriod p q - logarithmicPeriod)β€– ≀
2 * K * (q : ℝ) ^ (-nu) := by
rw [norm_mul, norm_period_error]
have hjR : (j : ℝ) ≀ (K : ℝ) := by exact_mod_cast hj
have hqpow : 0 ≀ (q : ℝ) ^ (-nu) := Real.rpow_nonneg (by positivity) _
simp only [Complex.norm_natCast]
nlinarith [abs_nonneg (Real.pi - (p : ℝ) / q)]
theorem ceil_log_bounds {q : β„•} (hq : 1 ≀ q) :
0 ≀ (⌈Real.log qβŒ‰β‚Š : ℝ) - Real.log q ∧
(⌈Real.log qβŒ‰β‚Š : ℝ) - Real.log q < 1 := by
have hlog : 0 ≀ Real.log (q : ℝ) := Real.log_nonneg (by exact_mod_cast hq)
constructor
Β· exact sub_nonneg.mpr (Nat.le_ceil _)
Β· have := Nat.ceil_lt_add_one hlog
linarith
theorem rpow_neg_le_exp_ceil_log (nu : ℝ) {q : β„•} (hnu : 0 ≀ nu) (hq : 1 ≀ q) :
(q : ℝ) ^ (-nu) ≀
Real.exp nu * Real.exp (-nu * (⌈Real.log qβŒ‰β‚Š : ℝ)) := by
have hqpos : (0 : ℝ) < q := by exact_mod_cast (by omega : 0 < q)
rw [Real.rpow_def_of_pos hqpos, ← Real.exp_add]
apply Real.exp_le_exp.mpr
have hw := (ceil_log_bounds hq).2
nlinarith
theorem norm_center_error_exp (nu : ℝ) {p : β„€} {q j K : β„•}
(hnu : 0 ≀ nu) (hq : 1 ≀ q) (hj : j ≀ K)
(happrox : |Real.pi - (p : ℝ) / q| ≀ (q : ℝ) ^ (-nu)) :
β€–(j : β„‚) * (approximatePeriod p q - logarithmicPeriod)β€– ≀
(2 * K * Real.exp nu) * Real.exp (-nu * (⌈Real.log qβŒ‰β‚Š : ℝ)) := by
calc
_ ≀ 2 * K * (q : ℝ) ^ (-nu) := norm_center_error_le nu hj happrox
_ ≀ 2 * K * (Real.exp nu * Real.exp (-nu * (⌈Real.log qβŒ‰β‚Š : ℝ))) :=
mul_le_mul_of_nonneg_left (rpow_neg_le_exp_ceil_log nu hnu hq) (by positivity)
_ = _ := by ring
end PiExponent
end OAI