import Mathlib import OAI.Probability.LogConcave.OraclePrograms.Fresh import OAI.Probability.LogConcave.OraclePrograms.IndependentSeq import OAI.Probability.LogConcave.Sampling.AverageLipschitz namespace OAI section noncomputable section namespace LogConcaveSampling.OracleCompiler open MeasureTheory ProbabilityTheory Function open scoped Classical NNReal variable {d : ℕ} def topProgram (S : ReservedProgram d) (h : ℝ) (N J : ℕ) := (Program.fresh (fun _ => proximalProgram S h) N).independentSeq (Program.fresh (fun j => halvingProgram S (descentScale h j)) J) def topSeedLaw (S : ReservedProgram d) (N J : ℕ) := ((Measure.dirac (0:Point d)).prod (Measure.pi (fun _ : Fin N => gaussianTape d S.full.slots))).prod (Measure.pi (fun _ : Fin J => gaussianTape d S.full.slots)) instance topSeedLaw_probability (S : ReservedProgram d) (N J : ℕ) : IsProbabilityMeasure (topSeedLaw S N J) := by unfold topSeedLaw; infer_instance lemma topProgram_law (S : ReservedProgram d) (h : ℝ) (N J : ℕ) {V : Point d → ℝ} (hV : Admissible V) : (topSeedLaw S N J).map ((topProgram S h N J).run V)= changingChain (fun j => approximateHalvingKernel S (descentScale h j) V hV) (markovChain (approximateProximalKernel S h V hV) (Measure.dirac 0) N) J := by let (j : ℕ) : IsMarkovKernel (approximateHalvingKernel S (descentScale h j) V hV) := approximateHalvingKernel_markov _ _ _ let := approximateProximalKernel_markov S h hV have hVm := hV.continuous_firstOrderReply.measurable rw [topProgram,topSeedLaw,Program.independentSeq_law _ _ hVm, Program.fresh_law (fun _ => proximalProgram S h) hVm] rw [stateLaw_eq_changingChain _ _ _ (fun _ => (proximalProgram S h).measurable_run V hVm) (fun _ => approximateProximalKernel S h V hV) (fun _ => approximateProximalKernel_apply S h hV), changingChain_constant] rw [Program.fresh_law _ hVm] exact stateLaw_eq_changingChain _ _ _ (fun j => (halvingProgram S (descentScale h j)).measurable_run V hVm) _ (fun j => approximateHalvingKernel_program S (descentScale h j) hV) J lemma affine_correct_from_uniform (S : ℝ → ℝ → ReservedProgram d) {q K e ηmin : ℝ} (hc : ∀{F : Point d → ℝ} {lam : ℝ≥0},Primitive F lam → 0 by convert! hloc x using 1; ring) (n+1) have hp' : TVAtMost (markovChain (approximateProximalKernel T h V hV) (Measure.dirac 0) (n+1)) (markovChain (proximalKernel V hV h) (Measure.dirac 0) (n+1)) ((n+1)*(18*e*Real.sqrt d)) := by apply hp.mono push_cast apply mul_le_mul_of_nonneg_left _ (by positivity) have hss : Real.sqrt h*(1+Real.sqrt h)≤2 := by nlinarith [Real.sqrt_nonneg h] nlinarith [mul_le_mul_of_nonneg_right hss (by positivity : 0≤e*Real.sqrt d)] have hm := hp'.trans (proximal_chain_mixing hV hh n) have hd := halving_chain_error hV hh hh1 he (fun j => approximateHalvingKernel T (descentScale h j) V hV) (fun j x => approximateHalvingKernel_tv S hV (descentScale_pos hh j) (by linarith [descentScale_le hh.le j]) hq1 he hη hres (affine_correct_from_uniform S hc hV (descentScale_pos hh j) (by linarith [descentScale_le hh.le j])) x) J have ht := ((changingChain_tv _ hm J).trans hd).trans (noisedLaw_tv hV (descentScale_pos hh J)) rw [topProgram_law _ _ _ _ hV] apply ht.mono ring_nf rfl end LogConcaveSampling.OracleCompiler end end end OAI