import Mathlib import OAI.Probability.LogConcave.Sampling.LogMeshCountRate namespace OAI section noncomputable section namespace LogConcaveSampling open Filter Quadrature MeanTree open scoped Topology Classical def sourceOccurrenceBudget (a b : ℝ) (n m N nc Nc d : ℕ) : ℕ := meanWork (Fintype.card (ProbabilityNode (sourceCorrelation a d) ((d:ℝ)^(-b)) (n+1))) (n+2) m N nc Nc 0 0 0+ (Fintype.card (ProbabilityNode (sampleCorrelation ((d:ℝ)^(-a))) ((d:ℝ)^(-b)) (n+1))+1)^N def occurrenceDegree (N Nc : ℕ) : ℕ := max (Nc*(2*N+2)) N lemma sourceOccurrenceBudget_rate {a b : ℝ} (ha : 0 (sourceOccurrenceBudget a b n m N nc Nc d:ℝ)) (-((occurrenceDegree N Nc:ℕ):ℝ)*b) := by have he := sourceCorrelation_eventually ha have hp := probabilityNode_card_rate hb.le (n+1) (he.mono (fun _ h => h.1)) (he.mono (fun _ h => h.2.1)) (logMeshLength_rate a (he.mono (fun _ h => h.1)) (he.mono (fun _ h => h.2.1)) (he.mono (fun _ h => h.2.2.le))) have hR : ∀ᶠ d : ℕ in atTop,0<(d:ℝ)^(-a) ∧ (d:ℝ)^(-a)≤1 := by filter_upwards [eventually_ge_atTop (1:ℕ)] with d hd have hd1 : (1:ℝ)≤d := by exact_mod_cast hd exact ⟨Real.rpow_pos_of_pos (by linarith) _,Real.rpow_le_one_of_one_le_of_nonpos hd1 (by linarith)⟩ have hs := hR.mono (fun d hd => sampleCorrelation_properties hd.1 hd.2) have hsp := probabilityNode_card_rate hb.le (n+1) (hs.mono (fun _ h => by linarith [h.1])) (hs.mono (fun _ h => h.2.1)) (logMeshLength_sample_rate (hR.mono (fun _ h => ⟨le_rfl,h.2⟩))) have hsample := (hsp.add ((LogPowerRate.const 1).mono (by linarith))).pow N have hmean := meanWork_rate hb.le hp (n+2) m N nc Nc have hB₁ : ((Nc*(2*N+2):ℕ):ℝ)≤(occurrenceDegree N Nc:ℝ) := by exact_mod_cast le_max_left (Nc*(2*N+2)) N have hB₂ : (N:ℝ)≤(occurrenceDegree N Nc:ℝ) := by exact_mod_cast le_max_right (Nc*(2*N+2)) N have hm := hmean.mono (show -(occurrenceDegree N Nc:ℝ)*b≤-((Nc*(2*N+2):ℕ):ℝ)*b by nlinarith) have hp' := hsample.mono (show -(occurrenceDegree N Nc:ℝ)*b≤(N:ℝ)*(-b) by nlinarith) simpa only [sourceOccurrenceBudget,Nat.cast_add,Nat.cast_pow,Nat.cast_one] using hm.add hp' namespace OracleCompiler lemma literalSample_cost_le_source {a b : ℝ} {d : ℕ} (hd : 0