import Mathlib import OAI.Probability.LogConcave.OraclePrograms.RoutineBudget import OAI.Probability.LogConcave.OraclePrograms.FullTape import OAI.Probability.LogConcave.Complexity.OccurrenceBudget namespace OAI section noncomputable section namespace LogConcaveSampling.OracleCompiler open Filter Quadrature MeanTree open scoped Topology Classical lemma source_anchor_radius {a : ℝ} (ha : 0 ∑j : Fin (m+1),|derivativeWeight (angleNodes m) j/((d:ℝ)^(-a))|) (-a) := by apply ((LogPowerRate.inv_power a).const_mul (∑j : Fin (m+1),|derivativeWeight (angleNodes m) j|)).congr filter_upwards [eventually_ge_atTop (1:ℕ)] with d hd have hp : (0:ℝ) 1+2*fixedCenteringBudget nc*((∑j,|terminalQuadratureWeight (sourceCorrelation a d) ((d:ℝ)^(-b)) n j|)* (∑j : Fin (m+1),|derivativeWeight (angleNodes m) j/((d:ℝ)^(-(4*a)))|)* (2*fixedProbabilityBudget n)+2)+4*fixedProbabilityBudget n+fixedHarmonicBudget n) (-(b+4*a)) := by obtain ⟨D,hD,hDu⟩ := exists_basisDerivative_budget (probabilityNodes (n+1)) have he := sourceCorrelation_eventually ha have hm := sourceMesh_eventually ha hb have hq := terminalQuadratureWeight_rate n D (by linarith) hDu a b (he.mono (fun _ h => h.1)) (he.mono (fun _ h => h.2.1)) (he.mono (fun _ h => h.2.2.le)) (hm.mono (fun _ h => h.1)) (hm.mono (fun _ h => h.2)) have hs := derivativeBudget_rate m (4*a) have hr : LogPowerRate (fun d : ℕ => (∑j,|terminalQuadratureWeight (sourceCorrelation a d) ((d:ℝ)^(-b)) n j|)* (∑j : Fin (m+1),|derivativeWeight (angleNodes m) j/((d:ℝ)^(-(4*a)))|)) (-(b+4*a)) := by simpa only [neg_add] using hq.mul hs have hc (c : ℝ) : LogPowerRate (fun _ : ℕ => c) (-(b+4*a)) := (LogPowerRate.const c).mono (by linarith) exact (((hc 1).add ((hr.mul_const (2*fixedProbabilityBudget n)).add (hc 2) |>.const_mul (2*fixedCenteringBudget nc))).add (hc (4*fixedProbabilityBudget n))).add (hc (fixedHarmonicBudget n)) end LogConcaveSampling.OracleCompiler end end section noncomputable section namespace LogConcaveSampling.OracleCompiler open Filter Quadrature MeanTree open scoped Classical Topology lemma source_angle_square {a : ℝ} (ha : 0 (le_abs_self _).trans hd) theorem exists_source_configuration {a b : ℝ} (ha : 0 16*(d:ℝ)^(κ*t)*sourceA κ t w n d/((d:ℝ)^(-(κ*t)))) (-(κ*(w+6*t))) := by convert he using 1 · funext d; simp only [neg_neg,div_eq_mul_inv] · ring have hc := (LogPowerRate.const 1).mono (show -(κ*(w+6*t))≤0 by nlinarith) have hi := hq.mul (hc.add he') have him := hi.mono (show κ*(b-10*t)≤κ*b+ -(κ*(w+6*t)) by nlinarith) exact him lemma anchorSize_rate {κ t b : ℝ} (hκ : 0≤κ) (ht : 0≤t) {q : ℕ → ℝ} (hq : LogPowerRate q (κ*b)) : LogPowerRate (anchorSize κ t q) (κ*(b-10*t)) := by have h := hq.mul (LogPowerRate.inv_power (κ*t)) have hm := h.mono (show κ*(b-10*t)≤κ*b+ -(κ*t) by nlinarith) change LogPowerRate (fun d => q d/((d:ℝ)^(-(κ*t)))) _ simpa only [div_eq_mul_inv] using hm lemma small_coefficient_rate {κ t w b : ℝ} (hκ : 0<κ) (ht : 0 sourceA κ t w n d*q d) (κ/3) := by exact ((sourceA_rate hκ ht hw n).mul hq).mono (by nlinarith) lemma parent_intrinsic_rate {κ b p : ℝ} (hκ : 0≤κ) (hb : 1/2≤b) {q e : ℕ → ℝ} (hq : LogPowerRate q (κ*b)) (he : LogPowerRate e (κ*(p-1/4))) : LogPowerRate (fun d => q d*e d) (κ*p) := (hq.mul he).mono (by nlinarith) lemma meanError_rate {κ J b p : ℝ} (hκ : 0≤κ) (hb : 1/2≤b) (hp : p≤J) (Af H Kf : ℝ) {q es ei ef : ℕ → ℝ} (hq : LogPowerRate q (κ*b)) (hes : LogPowerRate es (κ*(p-1/4))) (hei : LogPowerRate ei (κ*(p-1/4))) (hef : LogPowerRate ef (κ*p)) : LogPowerRate (fun d => 2*Af*Kf*H*q d*es d+ 10*(20+16*circuitGrowthConstant^2)*(2*(1+2*H)*(Af*Kf*q d*ei d+ef d))+ 2*(d:ℝ)^(-(κ*J))) (κ*p) := by have he := (parent_intrinsic_rate hκ hb hq hei).const_mul (Af*Kf) have hc := (he.add hef).const_mul (2*(1+2*H)) |>.const_mul (10*(20+16*circuitGrowthConstant^2)) have ha := (parent_intrinsic_rate hκ hb hq hes).const_mul (2*Af*Kf*H) have hn := ((LogPowerRate.power (κ*J)).mono (show κ*p≤κ*J by nlinarith)).const_mul 2 apply ((ha.add hc).add hn).congr filter_upwards [] with d ring lemma sampleError_rate {κ J b p : ℝ} (hκ : 0≤κ) (hb : 1/2≤b) (hp : p≤J) (Af H Kf : ℝ) {q ei ef : ℕ → ℝ} (hq : LogPowerRate q (κ*b)) (hei : LogPowerRate ei (κ*(p-1/4))) (hef : LogPowerRate ef (κ*p)) : LogPowerRate (fun d => 20*(2*(1+2*H)*(Af*Kf*q d*ei d+ef d))+ 2*(d:ℝ)^(-(κ*J))) (κ*p) := by have he := (parent_intrinsic_rate hκ hb hq hei).const_mul (Af*Kf) have hc := (he.add hef).const_mul (2*(1+2*H)) |>.const_mul 20 have hn := ((LogPowerRate.power (κ*J)).mono (show κ*p≤κ*J by nlinarith)).const_mul 2 apply (hc.add hn).congr filter_upwards [] with d ring end LogConcaveSampling.OracleCompiler end end section noncomputable section namespace LogConcaveSampling.OracleCompiler open scoped Classical def RoutineLabel.Admissible (t K : ℝ) (L : RoutineLabel) : Prop := 0≤L.p ∧ L.p≤K ∧ 1/2+40*t*L.p≤L.b lemma RoutineLabel.Admissible.b_lower {t K : ℝ} {L : RoutineLabel} (h : L.Admissible t K) (ht : 0≤t) : 1/2≤L.b := by have he : 0≤40*t*L.p := by positivity [h.1] linarith [h.2.2] lemma RoutineLabel.Admissible.child {t K : ℝ} {P C : RoutineLabel} (h : P.Admissible t K) (ht : 0≤t) (hnt : ¬P.terminal) (hc : RoutineStep t P C) : C.Admissible t K := by have hb := h.b_lower ht have hp : P.b rcases h with ⟨hp0,hpK,hbp⟩ dsimp only [RoutineLabel.Admissible] at * exact ⟨hp0,hpK,by linarith⟩ | sampleFinal b p => exact h | internal k k' b p => rcases h with ⟨hp0,hpK,hbp⟩ dsimp only [RoutineLabel.Admissible] at * exact ⟨by linarith,by linarith,by nlinarith⟩ lemma RoutineLabel.Admissible.rank_bound {t K : ℝ} {L : RoutineLabel} (h : L.Admissible t K) (ht : 0 dsimp only <;> omega lemma topLabel_admissible {t K : ℝ} (hK : 0≤K) (ht : 0≤t) (hsmall : 40*(K+2)*t<1/4) : (⟨.sample,1,K⟩:RoutineLabel).Admissible t K := by refine ⟨hK,le_rfl,?_⟩ dsimp nlinarith end LogConcaveSampling.OracleCompiler end end section noncomputable section namespace LogConcaveSampling.OracleCompiler open Filter Quadrature MeanTree open scoped Classical Topology theorem exists_uniform_routine_mesh {κ t K : ℝ} (hκ : 0<κ) (ht : 0