import Mathlib import OAI.Probability.SKRatio.Quantization.BinStability import OAI.Probability.SKRatio.Quantization.TanhEnds import OAI.Probability.SKRatio.Quantization.Quantizer namespace OAI noncomputable section open scoped BigOperators NNReal ENNReal Topology open MeasureTheory ProbabilityTheory Filter Real Set namespace SKRatio.Bins open Planted Scalar SKRatioClock.Regression lemma quantizer_integrable_square {R : ℝ} (hR : 0 x^2) μ) : Integrable (fun x => (x-gridQuant R N x)^2) μ := by apply ((integrable_const ((2*R/N)^2)).add (integrable_squareTail hi R)).mono' ((measurable_id.sub (measurable_gridQuant hR hN)).pow_const 2).aestronglyMeasurable exact ae_of_all _ (fun x => by rw [norm_eq_abs,abs_of_nonneg (sq_nonneg _)] exact gridQuant_square_error hR hN x) theorem quantizer_exists {Ω : ℕ → Type*} [∀ n, MeasurableSpace (Ω n)] {ρ : ∀ n, Measure (Ω n)} {X : ∀ n, Ω n → Fin n → ℝ} (hX : ExponentialSquareTails ρ X) {μ : Measure ℝ} [IsProbabilityMeasure μ] (hi : Integrable (fun x : ℝ => x^2) μ) {δ d : ℝ} (hδ : 0<δ) (hd : 0 {ω | d≤ siteNorm (fun i => X n ω i-gridQuant R N (X n ω i))}) := by obtain ⟨Rt,hRt,ht⟩ := hX (d^2/2) (by positivity) obtain ⟨Rc,hRc,hc⟩ := tanh_tail_uniform hδ have he := (tendsto_integral_squareTail hi).eventually (gt_mem_nhds (by positivity : (0:ℝ) X n ω i-gridQuant R N (X n ω i)) at hω have hnR : (0:ℝ) gridQuant_square_error hR hN0 (X n ω i)) have h3 := Finset.sum_le_sum (s := Finset.univ) (fun i _ => squareTail_antitone hRtR (X n ω i)) rw [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] at h2 have hh := div_le_div_of_nonneg_right h2 hnR.le rw [add_div,mul_div_cancel_left₀ _ (ne_of_gt hnR)] at hh have hh' := div_le_div_of_nonneg_right h3 hnR.le change d^2/2≤(∑ i, squareTail Rt (X n ω i))/(n:ℝ) nlinarith only [h1,hh,hh',hmeshd,sq_nonneg d] end SKRatio.Bins end end OAI