import OAI.Computability.FourierTransform.UniformBounds namespace OAI /- asymptotic analysis, one n for both length functions -/ namespace PowerSaving open RAM Bench Selection Slant Filter Asymptotics Real noncomputable section namespace Skies abbrev Tm (n : ℕ) : ℝ := log (n:ℝ) abbrev Qm (n : ℕ) : ℝ := log (Tm n) lemma Ttop : Tendsto Tm atTop atTop := Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTop lemma Qtop : Tendsto Qm atTop atTop := Real.tendsto_log_atTop.comp Ttop lemma log2_min : 2/3 ≤ log (2:ℝ) := by have hh := le_log_one_add_of_nonneg (show (0:ℝ)≤1 by norm_num) norm_num at * exact hh -- n is problem size, N allowed between n and 2n lemma stack_lim (n N : ℕ) (hn : 0 first | exact alpha_lt.le | norm_num _ ≤ _ := by rw [rpow_one] have hTT : 0 < Tm n^alpha := by positivity linarith def flight (n : ℕ) := (n:ℝ)*(Tm n)^alpha*Qm n^2 lemma leg_lim (n N : ℕ) (hn : 0 (n:ℝ)) tendsto_natCast_atTop_atTop 2 (c:=1/10^6) (p:=1) (by norm_num) (by norm_num) filter_upwards [H,eventually_gt_atTop 0,Ttop.eventually_ge_atTop 1] with n hh hn ht rw [rpow_one] at hh have hh' : (Tm n)^2 ≤ 1/10^6*n := hh have hh1 := order_pow_lim n (N n) hn (h n).1 (h n).2 ht have hh2 : (2:ℝ)^(orderE (N n)) ≤ n := by linarith exact (show 2^orderE (N n) ≤ n by exact_mod_cast hh2).trans (h n).1 lemma polylog_ev (h : ∀ n:ℕ,n ≤ N n ∧ N n ≤ 2*n) (d : ℕ) : ∀ᶠ n in atTop, ((stackN (N n):ℝ)+2)^d ≤ n := by have h0 : 0< (12:ℝ)^d := by positivity have H := dwarf (v:=fun n => (n:ℝ)) tendsto_natCast_atTop_atTop d (c:=((12:ℝ)^d)⁻¹) (p:=1) (by norm_num) (by positivity) filter_upwards [H,eventually_gt_atTop 0,Ttop.eventually_ge_atTop 1] with n hh hn ht rw [rpow_one] at hh have hh' : (Tm n)^d ≤ ((12:ℝ)^d)⁻¹*n := hh have hh1 := stack_lim n (N n) hn (h n).1 (h n).2 ht calc _ ≤ (12*Tm n)^d := by gcongr; linarith _ ≤ _ := by rw [mul_pow] calc _ ≤ _ := mul_le_mul_of_nonneg_left hh' h0.le _ = _ := by rw [← mul_assoc,mul_inv_cancel₀ h0.ne',one_mul] lemma wind_ev (h : ∀ n:ℕ,n ≤ N n ∧ N n ≤ 2*n) (d : ℕ) : ∀ᶠ n in atTop,(fairwind d (N n):ℝ)+1 ≤ 10^41*flight n := by filter_upwards [docks_ev h,polylog_ev h d,eventually_gt_atTop 0,Ttop.eventually_ge_atTop 1, Qtop.eventually_ge_atTop 1] with n hh hk hn ht hu unfold fairwind Bench.surf rw [ite_eq_left hh,Nat.add_zero] push_cast have hp := leg_lim n (N n) hn (h n).1 (h n).2 ht hu have he := flight_big n ht hu have he' : 1≤(n:ℝ) := by exact_mod_cast hn have hx : (N n:ℝ) ≤ 2*n := by exact_mod_cast (h n).2 linarith lemma lunch_big (a b : Ration) (h : ∀ n:ℕ,n ≤ N n ∧ N n ≤ 2*n) : (fun n : ℕ => (lunch a b N n:ℝ)) =O[atTop] flight := by let W := lunch a b N refine isBigO_iff.mpr ⟨(a.c:ℝ)*10^41+1+(b.c:ℝ)*10^41,?_⟩ filter_upwards [wind_ev h a.d,wind_ev h b.d,eventually_gt_atTop 0,Ttop.eventually_ge_atTop 1, Qtop.eventually_ge_atTop 1] with n hh hk hn ht hu have he := flight_big n ht hu have h1 : 1≤(n:ℝ) := by exact_mod_cast hn rw [Real.norm_of_nonneg (by positivity),Real.norm_of_nonneg (by linarith)] unfold lunch calorie push_cast; simp only [add_mul,one_mul,mul_assoc] gcongr exact h1.trans he end Skies end end PowerSaving end OAI