import Mathlib import OAI.Probability.LogConcave.Numerics.TwoendsContinuous import OAI.Probability.LogConcave.Complexity.KernelActionNormalizedBudget namespace OAI section noncomputable section namespace LogConcaveSampling open Set MeasureTheory Quadrature open scoped Classical BigOperators NNReal def kernelAnalyticNormalizedBudget (n d : ℕ) (T h D : ℝ) : ℝ := 32*(1+D^2+(∑i,|zeroHermiteWeight (probabilityNodes (n+1)) 0 i|)^2)* (2*logMeshLength T*(Real.exp (Real.pi^2/4)*(TensorSum.terminalQ (n+1)).val.logCoefficient 0 2)* (1+Real.log ((d:ℝ)+1))^((TensorSum.terminalQ (n+1)).val.logDegree 0)*2^(n+1)*h^n)^2 lemma kernelAnalyticNormalizedBudget_nonneg (n d : ℕ) (T h D : ℝ) : 0≤kernelAnalyticNormalizedBudget n d T h D := by unfold kernelAnalyticNormalizedBudget positivity lemma kernelAnalyticBudget_normalized {d : ℕ} (F : Point d → ℝ) (x : Point d) (lam : ℝ≥0) (r D : ℝ) {T h : ℝ} (hT0 : 0 |terminalQuadratureWeight T h n v|) _ (fun v => abs_nonneg _) hp have ha := kernelAnalyticBudget_normalized F x lam r D hT0 hT1 hh.le n have hb := mul_le_mul_of_nonneg_left (add_le_add (mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hw hq) (by norm_num : (0:ℝ)≤2)) (mul_le_mul_of_nonneg_left ha (by norm_num : (0:ℝ)≤2))) (sq_nonneg ((r*s)⁻¹)) apply hb.trans_eq dsimp [Q,E,B,velocityNormalizedBudget] field_simp end LogConcaveSampling end end section noncomputable section namespace LogConcaveSampling open Set MeasureTheory Quadrature open scoped Classical BigOperators NNReal lemma square_root_two_budget {A B : ℝ} (hA : 0≤A) (hB : 0≤B) (q : ℝ) (N : ℕ) : (2*Real.sqrt A+q^N*Real.sqrt B)^2≤8*A+2*q^(2*N)*B := by have hsA := Real.sq_sqrt hA have hsB := Real.sq_sqrt hB have he : q^(2*N)*B=(q^N*Real.sqrt B)^2 := by rw [show 2*N=N*2 by omega,pow_mul,mul_pow,hsB] nlinarith [sq_nonneg (2*Real.sqrt A-q^N*Real.sqrt B)] def centerStateQuadratureEnvelope (n : ℕ) (α R : ℝ) : ℝ := 8*(singleCellBasisBudget n)^2*(α^2*(R⁻¹)^4)^(n+2)*centeringStateBudget (n+2) def centerInitialEnvelope (α R : ℝ) : ℝ := 2*(α^2*(R⁻¹)^4)*centeringStateBudget 1 def centerStateEnvelope (n N : ℕ) (α R q E : ℝ) : ℝ := 8*(2*(centeringRowBudget n:ℝ)^2*α^2*E+2*centerStateQuadratureEnvelope n α R)+ 2*q^(2*N)*centerInitialEnvelope α R def centerMeanEnvelope (n : ℕ) (α R Z : ℝ) : ℝ := 2*(centeringRowBudget n:ℝ)^2*(Real.pi^2/2)^2*α^2*Z+ 8*(singleCellBasisBudget n)^2*α^2*(α^2*(R⁻¹)^4)^(n+1)*centeringMeanBudget (n+1) lemma centerStateQuadratureEnvelope_nonneg (n : ℕ) (α R : ℝ) : 0≤centerStateQuadratureEnvelope n α R := by unfold centerStateQuadratureEnvelope positivity [centeringStateBudget_nonneg (n+2)] lemma centerInitialEnvelope_nonneg (α R : ℝ) : 0≤centerInitialEnvelope α R := by unfold centerInitialEnvelope positivity [centeringStateBudget_nonneg 1] lemma centerStateEnvelope_nonneg (n N : ℕ) (α R q E : ℝ) (hq : 0≤q) (hE : 0≤E) : 0≤centerStateEnvelope n N α R q E := by unfold centerStateEnvelope positivity [centerStateQuadratureEnvelope_nonneg n α R,centerInitialEnvelope_nonneg α R] lemma centerMeanEnvelope_nonneg (n : ℕ) (α R Z : ℝ) (hZ : 0≤Z) : 0≤centerMeanEnvelope n α R Z := by unfold centerMeanEnvelope positivity [centeringMeanBudget_nonneg (n+1)] lemma centeringStateQuadratureBudget_normalized {d : ℕ} (F : Point d → ℝ) (x : Point d) (n : ℕ) (lam : ℝ≥0) (r R s : ℝ) : centeringStateQuadratureBudget n d lam r R s≤ (circuitD F x)^2*centerStateQuadratureEnvelope n ((lam:ℝ)*r/s) R := by have hd := circuitD_dimension F x have hc := centeringStateBudget_nonneg (n+2) unfold centeringStateQuadratureBudget centerStateQuadratureEnvelope push_cast nlinarith [mul_le_mul_of_nonneg_right hd (show 0≤8*(singleCellBasisBudget n)^2*(((lam:ℝ)*r/s)^2*(R⁻¹)^4)^(n+2)*centeringStateBudget (n+2) by positivity)] lemma centeringInitialBudget_normalized {d : ℕ} (F : Point d → ℝ) (x : Point d) (lam : ℝ≥0) (r R s : ℝ) : centeringInitialBudget d lam r R s≤ (circuitD F x)^2*centerInitialEnvelope ((lam:ℝ)*r/s) R := by have hd := circuitD_dimension F x have hc := centeringStateBudget_nonneg 1 unfold centeringInitialBudget centerInitialEnvelope push_cast nlinarith [mul_le_mul_of_nonneg_right hd (show 0≤2*(((lam:ℝ)*r/s)^2*(R⁻¹)^4)*centeringStateBudget 1 by positivity)] lemma centeringPicardBudget_normalized {d : ℕ} (F : Point d → ℝ) (x : Point d) (n N : ℕ) (lam K : ℝ≥0) (r R s E : ℝ) (hE : 0≤E) : centeringPicardBudget n N d lam K r R s ((((lam:ℝ)*r/s)*circuitD F x)^2*E)≤ (circuitD F x)^2*centerStateEnvelope n N ((lam:ℝ)*r/s) R (centeringRowBudget n*K:ℝ≥0) E := by have hQ := centeringStateQuadratureBudget_normalized F x n lam r R s have hI := centeringInitialBudget_normalized F x lam r R s unfold centeringPicardBudget apply (square_root_two_budget (by positivity [centeringStateQuadratureBudget_nonneg n d lam r R s]) (by unfold centeringInitialBudget; positivity [centeringStateBudget_nonneg 1]) (centeringRowBudget n*K:ℝ≥0) N).trans have hq : 0≤((centeringRowBudget n*K:ℝ≥0):ℝ)^(2*N) := by positivity have hQ' := mul_le_mul_of_nonneg_left hQ (by norm_num : (0:ℝ)≤16) have hI' := mul_le_mul_of_nonneg_left hI (show 0≤2*((centeringRowBudget n*K:ℝ≥0):ℝ)^(2*N) by positivity) unfold centerStateEnvelope nlinarith lemma centeringMeanBudget_normalized {d : ℕ} (F : Point d → ℝ) (x : Point d) (n : ℕ) (lam : ℝ≥0) (r R : ℝ) {s T Z : ℝ} (hs : 0 Real.log (d:ℝ)) := by have ht : Tendsto (fun d : ℕ => (d:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop have hlog : ∀ᶠ d : ℕ in atTop,1≤Real.log (d:ℝ) := (Real.tendsto_log_atTop.comp ht).eventually_ge_atTop 1 apply IsBigO.of_bound 3 filter_upwards [eventually_ge_atTop (2:ℕ),hlog] with d hd hl have hd0 : (0:ℝ) dimensionLog d^k) =o[atTop] (fun d : ℕ => (d:ℝ)^s) := by have hh := (isLittleO_log_rpow_rpow_atTop (k:ℝ) hs).comp_tendsto (tendsto_natCast_atTop_atTop (R:=ℝ)) simp only [Real.rpow_natCast,Function.comp_def] at hh exact (dimensionLog_isBigO_log.pow k).trans_isLittleO hh theorem polylog_power_absorb (C : ℝ) (k : ℕ) {a b : ℝ} (hab : b (d:ℝ)^(-a)) atTop) have he : (fun d : ℕ => (d:ℝ)^(a-b)*(d:ℝ)^(-a)) =ᶠ[atTop] (fun d : ℕ => (d:ℝ)^(-b)) := by filter_upwards [eventually_ge_atTop (1:ℕ)] with d hd have hd0 : (0:ℝ) dimensionLog d^k*(d:ℝ)^(-a)) lemma dimensionLog_one_le (d : ℕ) : 1≤dimensionLog d := by unfold dimensionLog have h := Real.log_nonneg (by linarith [Nat.cast_nonneg (α:=ℝ) d] : 1≤(d:ℝ)+1) linarith namespace LogPowerRate lemma congr {f g : ℕ → ℝ} {a : ℝ} (h : LogPowerRate f a) (he : f=ᶠ[atTop] g) : LogPowerRate g a := by obtain ⟨k,hk⟩ := h exact ⟨k,hk.congr' he Filter.EventuallyEq.rfl⟩ lemma mono {f : ℕ → ℝ} {a b : ℝ} (h : LogPowerRate f a) (hba : b≤a) : LogPowerRate f b := by obtain ⟨k,hk⟩ := h refine ⟨k,hk.trans (IsBigO.of_bound 1 ?_)⟩ filter_upwards [eventually_ge_atTop (1:ℕ)] with d hd have hd1 : (1:ℝ)≤d := by exact_mod_cast hd have hd0 : (0:ℝ) C) 0 := by refine ⟨0,?_⟩ simpa only [pow_zero,neg_zero,Real.rpow_zero,mul_one] using (isBigO_const_const C (by norm_num : (1:ℝ)≠0) atTop : (fun _ : ℕ => C)=O[atTop] (fun _ => (1:ℝ))) lemma power (a : ℝ) : LogPowerRate (fun d => (d:ℝ)^(-a)) a := by refine ⟨0,?_⟩ simpa only [pow_zero,one_mul] using (isBigO_refl (fun d : ℕ => (d:ℝ)^(-a)) atTop) lemma log : LogPowerRate dimensionLog 0 := by refine ⟨1,?_⟩ simpa only [pow_one,neg_zero,Real.rpow_zero,mul_one] using (isBigO_refl dimensionLog atTop) lemma mul {f g : ℕ → ℝ} {a b : ℝ} (hf : LogPowerRate f a) (hg : LogPowerRate g b) : LogPowerRate (fun d => f d*g d) (a+b) := by obtain ⟨k,hk⟩ := hf obtain ⟨l,hl⟩ := hg refine ⟨k+l,(hk.mul hl).congr' Filter.EventuallyEq.rfl ?_⟩ filter_upwards [eventually_ge_atTop (1:ℕ)] with d hd have hd0 : (0:ℝ) f d^n) (n*a) := by induction n with | zero => simpa using const 1 | succ n ih => have h := ih.mul hf simpa only [pow_succ,Nat.cast_add,Nat.cast_one,add_mul,one_mul] using h lemma const_mul {f : ℕ → ℝ} {a : ℝ} (hf : LogPowerRate f a) (C : ℝ) : LogPowerRate (fun d => C*f d) a := by simpa only [zero_add] using (const C).mul hf lemma mul_const {f : ℕ → ℝ} {a : ℝ} (hf : LogPowerRate f a) (C : ℝ) : LogPowerRate (fun d => f d*C) a := by simpa only [add_zero] using hf.mul (const C) lemma add {f g : ℕ → ℝ} {a : ℝ} (hf : LogPowerRate f a) (hg : LogPowerRate g a) : LogPowerRate (fun d => f d+g d) a := by obtain ⟨k,hk⟩ := hf obtain ⟨l,hl⟩ := hg have bound (i j : ℕ) : (fun d : ℕ => dimensionLog d^i*(d:ℝ)^(-a)) =O[atTop] (fun d => dimensionLog d^(i+j)*(d:ℝ)^(-a)) := by apply IsBigO.of_bound 1 filter_upwards [] with d rw [one_mul,Real.norm_of_nonneg (by positivity [dimensionLog_nonneg d]), Real.norm_of_nonneg (by positivity [dimensionLog_nonneg d])] exact mul_le_mul_of_nonneg_right (pow_le_pow_right₀ (dimensionLog_one_le d) (by omega)) (by positivity) exact ⟨k+l,(hk.trans (bound k l)).add (hl.trans (by simpa only [Nat.add_comm] using bound l k))⟩ lemma of_le_abs {f g : ℕ → ℝ} {a : ℝ} (hg : LogPowerRate g a) (hfg : ∀ᶠ d in atTop, |f d|≤|g d|) : LogPowerRate f a := by obtain ⟨k,hk⟩ := hg exact ⟨k,(IsBigO.of_bound 1 (by simpa only [one_mul,Real.norm_eq_abs] using hfg)).trans hk⟩ lemma eventually_small {f : ℕ → ℝ} {a b : ℝ} (hf : LogPowerRate f a) (hba : b |f d|) a := by exact of_le_abs hf (Eventually.of_forall (fun d => by simp)) lemma div_const {f : ℕ → ℝ} {a : ℝ} (hf : LogPowerRate f a) (C : ℝ) : LogPowerRate (fun d => f d/C) a := by simpa only [div_eq_mul_inv] using hf.mul_const C⁻¹ lemma of_le {f g : ℕ → ℝ} {a : ℝ} (hg : LogPowerRate g a) (hf : ∀ᶠ d : ℕ in atTop,0≤f d) (hfg : ∀ᶠ d : ℕ in atTop,f d≤g d) : LogPowerRate f a := by apply of_le_abs hg filter_upwards [hf,hfg] with d hd he rw [abs_of_nonneg hd,abs_of_nonneg (hd.trans he)] exact he lemma inv_power (a : ℝ) : LogPowerRate (fun d => ((d:ℝ)^(-a))⁻¹) (-a) := by apply (power (-a)).congr filter_upwards [eventually_ge_atTop (1:ℕ)] with d hd have hd0 : (0:ℝ)≤d := Nat.cast_nonneg d rw [Real.rpow_neg hd0] lemma log_nat : LogPowerRate (fun d : ℕ => Real.log (d:ℝ)) 0 := by apply of_le log · filter_upwards [eventually_ge_atTop (1:ℕ)] with d hd exact Real.log_nonneg (by exact_mod_cast hd) · filter_upwards [eventually_ge_atTop (1:ℕ)] with d hd have hp : (0:ℝ) Real.log ((d:ℝ)^(-a))) 0 := by apply (log_nat.const_mul (-a)).congr filter_upwards [eventually_ge_atTop (1:ℕ)] with d hd rw [Real.log_rpow (by exact_mod_cast hd : (0:ℝ) logMeshLength (T d)) 0 := by apply LogPowerRate.of_le ((LogPowerRate.const (Real.log 2)).add ((LogPowerRate.log_power a).const_mul (-2))) · filter_upwards [hT0,hT1] with d hd0 hd1 exact (logMeshLength_pos hd0 hd1).le · filter_upwards [hT0,hT1,hRT,eventually_ge_atTop (1:ℕ)] with d hd0 hd1 hRT hd have hp : (0:ℝ) ∑v,|terminalQuadratureWeight (T d) ((d:ℝ)^(-b)) n v|) (-b) := by have hlen := logMeshLength_rate a hT0 hT1 hRT have he := ((LogPowerRate.inv_power b).const_mul 4).mul ((LogPowerRate.const (∑i,|zeroHermiteWeight (probabilityNodes (n+1)) 0 i|)).add (((hlen.add (LogPowerRate.log_power b).abs).add (LogPowerRate.const (Real.log 4))).const_mul ((n+2)*D))) simp only [add_zero] at he apply LogPowerRate.of_le he · exact Eventually.of_forall (fun d => by positivity) · filter_upwards [hT0,hT1,hsmall,hlarge,eventually_ge_atTop (1:ℕ)] with d hd0 hd1 hs hl hd have hp : (0:ℝ)