import Mathlib import OAI.Probability.SKBarriers.Coverage.CoverageScale import OAI.Probability.SKBarriers.Dynamics.GreedyNumerics namespace OAI section noncomputable section open scoped BigOperators Topology open Classical MeasureTheory Filter Set namespace SK.Analytic theorem greedyBlockCount_eventual {B : ℕ} (hB : 0 (t/8)*(4*(levelRho n)^2+(levelRho n)^9995)) atTop (𝓝 0) := by convert (((levelRho_tendsto.pow 2).const_mul 4).add (levelRho_tendsto.pow 9995)).const_mul (t/8) using 1 norm_num have HW : Tendsto (fun n => (3*t/2)*(levelRho n)^18+(levelRho n)^10000) atTop (𝓝 0) := by convert ((levelRho_tendsto.pow 18).const_mul (3*t/2)).add (levelRho_tendsto.pow 10000) using 1 norm_num have HE : Tendsto (fun n => 3*Real.exp (-2*levelLogScale n)) atTop (𝓝 0) := by have H := (Real.tendsto_exp_atBot.comp (stretchedLogScale_tendsto.const_mul_atTop_of_neg (by norm_num : (-2:ℝ)<0))).const_mul 3 simpa only [mul_zero,levelLogScale,Function.comp_apply] using H filter_upwards [eventually_gt_atTop (0:ℕ),greedyBlockCount_eventual hB ht, HM.eventually_lt_const (by norm_num : (0:ℝ)<1/2), HW.eventually_le_const (Real.exp_pos (-8/c)),HE.eventually_lt_const (by norm_num : (0:ℝ)<1/2)] with n hn hs hm hw he intro m hmn have hρ := levelRho_pos hn let γ : ℝ := 2*(6*(B*greedyBlockCount B t n:ℕ)*(levelRho n)^20)/(levelRho n)+1/(n:ℝ) have hγ : 0≤γ := by dsimp only [γ]; positivity have hγ' : γ≤Real.exp (-8/c) := (greedy_grid_window_bound hn hB ht).trans hw have hpow : γ^(greedyBlockCount B t n)≤Real.exp (-4*levelLogScale n) := by calc _ ≤ (Real.exp (-8/c))^(greedyBlockCount B t n) := pow_le_pow_left₀ hγ hγ' _ _ = Real.exp ((greedyBlockCount B t n:ℝ)*(-8/c)) := (Real.exp_nat_mul _ _).symm _ ≤ _ := Real.exp_le_exp.mpr (by have hh := mul_le_mul_of_nonpos_right hs.2 (show -8/c≤0 from div_nonpos_of_nonpos_of_nonneg (by norm_num) hc.le) change _≤(c*levelLogScale n/2)*(-8/c) at hh have hz : (c*levelLogScale n/2)*(-8/c)=-4*levelLogScale n := by field_simp; ring rw [hz] at hh exact hh) have hM : (m:ℝ)+1≤3*Real.exp (2*levelLogScale n) := by have hk : (m:ℝ)≤⌈Real.exp (2*levelLogScale n)⌉₊ := by exact_mod_cast hmn exact (add_le_add hk (le_refl (1:ℝ))).trans (horizon_size_bound (L:=levelLogScale n) (by unfold levelLogScale; positivity)) have hprod : ((m:ℝ)+1)*γ^(greedyBlockCount B t n)≤3*Real.exp (-2*levelLogScale n) := by calc _ ≤ (3*Real.exp (2*levelLogScale n))*Real.exp (-4*levelLogScale n) := mul_le_mul hM hpow (by positivity) (by positivity) _ = _ := by rw [mul_assoc,← Real.exp_add]; congr 2; ring have hb := greedy_grid_mass_bound hn hB ht linarith only [hb,hm,hprod,he] end SK.Analytic end end end OAI