import Mathlib namespace OAI section noncomputable section open scoped Classical namespace CriticalPercolation.HarmonicAnalysis lemma sparse_real_doubling (f : ℕ → ℝ) (hf : Monotone f) (R₀ : ℕ) (hpos : ∀ n≥R₀, 0 simp | succ k ih => have hr : max R R₀≤b^k*a := haR.trans (by have hh : 1≤b^k := Nat.one_le_pow k b (by omega) nlinarith) have hh := (hbad (b^k*a) hr).le calc _ = (b:ℝ)^(d+1)*(((b:ℝ)^(d+1))^k*f a) := by rw [pow_succ]; ring _ ≤ (b:ℝ)^(d+1)*f (b^k*a) := mul_le_mul_of_nonneg_left ih (by positivity) _ ≤ f (b*(b^k*a)) := hh _ = _ := by congr 1; rw [pow_succ]; ring obtain ⟨N,hN⟩ := exists_nat_gt (C*((b*a:ℕ):ℝ)^d/f a) have hNF : C*((b*a:ℕ):ℝ)^d<(N:ℝ)*f a := (div_lt_iff₀ hfapos).mp hN obtain ⟨n,hn,hnpoly⟩ := hpoly (b*a*(N+1)) have hnA : b*(N+1)≤n/a := (Nat.le_div_iff_mul_le ha).mpr (by nlinarith) have hnAp : n/a≠0 := by nlinarith let k := Nat.log b (n/a) let P := b^k have hP : P≤n/a := Nat.pow_log_le_self b hnAp have hP' : n/a simp | succ i ih => have hh := ih (by omega) calc _ = C*(C^i*f 0) := by rw [pow_succ]; ring _ ≤ C*f i := mul_le_mul_of_nonneg_left hh hC.le _ ≤ _ := (hbad i (by omega)).le have hlast := hbad (L-1) (by omega) rw [Nat.sub_add_cancel (by omega : 1≤L)] at hlast have hg := mul_le_mul_of_nonneg_left (hgrow (L-1) (by omega)) hC.le have he : C*(C^(L-1)*f 0)=C^L*f 0 := by rw [←mul_assoc,←pow_succ',Nat.sub_add_cancel (by omega : 1≤L)] rw [he] at hg exact (not_lt_of_ge hbound) (hg.trans_lt hlast) end CriticalPercolation.HarmonicAnalysis end end end OAI