import Mathlib import OAI.Probability.LogConcave.OraclePrograms.StandaloneCorrect namespace OAI section noncomputable section namespace LogConcaveSampling open Filter MeasureTheory ProbabilityTheory open scoped Classical NNReal Topology lemma LogPowerRate.envelope {q : ℕ → ℝ} {a : ℝ} (hq : LogPowerRate q a) : ∃S : ℝ,0≤S ∧ ∃k : ℕ,∀ᶠ d : ℕ in atTop,|q d|≤S*dimensionLog d^k*(d:ℝ)^(-a) := by obtain ⟨k,hk⟩ := hq obtain ⟨C,hC⟩ := hk.bound refine ⟨|C|,abs_nonneg _,k,?_⟩ filter_upwards [hC] with d hd have hn : 0≤dimensionLog d^k*(d:ℝ)^(-a) := by positivity [dimensionLog_nonneg d] rw [Real.norm_eq_abs,Real.norm_of_nonneg hn] at hd exact (hd.trans (mul_le_mul_of_nonneg_right (le_abs_self C) hn)).trans_eq (by ring) lemma source_error_square (κ J : ℝ) {d : ℕ} (_ : 0 ‖sampleMeanCircuit F x r T ((d:ℝ)^(-(κ*w))) (n+1) (numericalLayerCount J) e z- T⁻¹ • fullProbabilityFlow hF x hz.1.le hl' (probabilityNodeTime T ((d:ℝ)^(-(κ*w))) (n+1) e) z‖^2) (stdGaussian (Point d)) ∧ (∫z,‖sampleMeanCircuit F x r T ((d:ℝ)^(-(κ*w))) (n+1) (numericalLayerCount J) e z- T⁻¹ • fullProbabilityFlow hF x hz.1.le hl' (probabilityNodeTime T ((d:ℝ)^(-(κ*w))) (n+1) e) z‖^2 ∂stdGaussian (Point d))≤circuitD F x^2*(d:ℝ)^(-(2*κ*J)) at hp rw [←hC.h_eq,←hC.n_eq,←hC.N_eq] at hp have he := hp hη.1 hη.2.1 (C.sampleEndpoint η hz.2.2.1 hz.2.2.2.1) simpa only [CircuitParameters.sampleEndpoint, probabilityEndpoint_time _ _ _ _ (Nat.succ_pos C.n),hsquare] using he end OracleCompiler end LogConcaveSampling end end end OAI