import OAI.Geometry.PinnedDistances.GlobalPotentials namespace OAI universe u1 u2 u3 u4 u5 u6 u7 u8 u9 section noncomputable section open NumberField open scoped BigOperators noncomputable section open MeasureTheory open scoped Topology noncomputable section open MeasureTheory open scoped Topology ENNReal noncomputable section open MeasureTheory NumberField open scoped BigOperators noncomputable section open scoped BigOperators open MeasureTheory noncomputable section open Filter open scoped Topology noncomputable section open scoped BigOperators noncomputable section open Filter open scoped Topology noncomputable section open MeasureTheory open scoped BigOperators noncomputable section namespace WeakPinned.Cuts open scoped BigOperators def tent (δ u : ℝ) : ℝ := max 0 (min (u-δ) (1-δ-u)) lemma tent_nonneg (δ u : ℝ) : 0≤tent δ u := le_max_left _ _ lemma tent_symm (δ u : ℝ) : tent δ (1-u)=tent δ u := by unfold tent rw [show 1-u-δ=1-δ-u by ring,show 1-δ-(1-u)=u-δ by ring,min_comm] lemma tent_zero_left {δ u : ℝ} (hu : u≤δ) : tent δ u=0 := by unfold tent exact max_eq_left ((min_le_left _ _).trans (sub_nonpos.mpr hu)) lemma tent_zero_right {δ u : ℝ} (hu : 1-δ≤u) : tent δ u=0 := by rw [← tent_symm] exact tent_zero_left (by linarith) lemma tent_le_one {δ u : ℝ} (hδ : 0≤δ) (hu : u≤1) : tent δ u≤1 := by exact max_le (by norm_num) ((min_le_left _ _).trans (by linarith)) lemma tent_lipschitz (δ u v : ℝ) : |tent δ u-tent δ v|≤|u-v| := by have hm := abs_max_sub_max_le_max (0:ℝ) (min (u-δ) (1-δ-u)) 0 (min (v-δ) (1-δ-v)) have hn := abs_min_sub_min_le_max (u-δ) (1-δ-u) (v-δ) (1-δ-v) have he : 1-δ-u-(1-δ-v)=-(u-v) := by ring have hf : u-δ-(v-δ)=u-v := by ring simp only [he,hf,abs_neg,max_self] at hn exact hm.trans (max_le (by simp [abs_nonneg]) hn) lemma tent_positive {δ u : ℝ} (hu : 0 linarith lemma tent_lower {δ u : ℝ} (hu : 2*δ≤u) (hu' : u≤1-2*δ) : δ≤tent δ u := by exact le_max_iff.mpr (Or.inr (le_min (by linarith) (by linarith))) def cutError (δ p a : ℝ) : ℝ := |tent δ p-tent δ a|+tent δ a*|p-a| lemma cutError_nonneg (δ p a : ℝ) : 0≤cutError δ p a := add_nonneg (abs_nonneg _) (mul_nonneg (tent_nonneg _ _) (abs_nonneg _)) lemma cutError_symm (δ p a : ℝ) : cutError δ (1-p) (1-a)=cutError δ p a := by simp only [cutError,tent_symm,show 1-p-(1-a)=-(p-a) by ring,abs_neg] lemma cutError_le {δ p a : ℝ} (hδ : 0≤δ) (ha : a≤1) : cutError δ p a≤2*|p-a| := by have := tent_lipschitz δ p a have := mul_le_mul_of_nonneg_right (tent_le_one hδ ha) (abs_nonneg (p-a)) unfold cutError linarith lemma cutError_young {δ p a ε : ℝ} (hδ : 0≤δ) (ha : a≤1) (hε : 0<ε) : cutError δ p a≤ε+(p-a)^2/ε := by apply (cutError_le hδ ha).trans apply (mul_le_mul_iff_left₀ hε).mp have he : (ε+(p-a)^2/ε)*ε=ε^2+(p-a)^2 := by field_simp rw [he] nlinarith [sq_nonneg (|p-a|-ε),sq_abs (p-a)] /-- Tiny uniform cells have nonzero balanced-cut weight only if their sampled mass is separated from zero. The variance quadratic then pays the cut error. -/ lemma cutError_tiny {δ p a : ℝ} (hδ : 0<δ) (ha : a<δ/2) (hp : p≤1) : cutError δ p a≤(4/δ^2)*(p-a)^2 ∧ cutError δ p a≤(4/δ^2)*(p^2/2) := by have hz : tent δ a=0 := tent_zero_left (by linarith) rw [cutError,hz,sub_zero,abs_of_nonneg (tent_nonneg _ _),zero_mul,add_zero] by_cases hh : tent δ p=0 · rw [hh]; constructor <;> positivity · have ht : 0 mul_le_mul_of_nonneg_left (cutError_young (p:=cellProb (B i) C) hδ.le (cellProb_le_one (Finset.univ : Finset P) C) hε) (hw i)) change familyCutError w B δ C≤_ at he simp only [mul_add,Finset.sum_add_distrib,← Finset.sum_mul,← mul_div_assoc,← Finset.sum_div] at he have hvf : varianceCell w B T C=∑ i, w i*(cellProb (B i) C-cellProb Finset.univ C)^2 := by simp only [varianceCell,ite_eq_left (hlarge ha)] rw [← hvf] at he have he2 : (∑ i, w i)*ε≤ε := by nlinarith have he3 : ε≤(8*ε/δ^2)*pairCell Finset.univ C := by have hh := mul_le_mul_of_nonneg_left (hpair ha) hε.le calc ε = ε*1 := by ring _ ≤ ε*((8/δ^2)*pairCell Finset.univ C) := hh _ = _ := by ring have hx : 0≤(4/δ^2)*varianceCell w B T C := mul_nonneg (by positivity) hv have hh : varianceCell w B T C/ε=(1/ε)*varianceCell w B T C := by ring rw [hh] at he nlinarith · have hat : cellProb Finset.univ C<δ/2 := lt_of_not_ge ha have hb : familyCutError w B δ C≤(4/δ^2)*varianceCell w B T C := by unfold familyCutError varianceCell split_ifs with hl · rw [Finset.mul_sum] apply Finset.sum_le_sum intro i _ have hh := (cutError_tiny hδ hat (cellProb_le_one (B i) C)).1 have hm := mul_le_mul_of_nonneg_left hh (hw i) convert hm using 1; ring · simp only [Finset.mul_sum] apply Finset.sum_le_sum intro i _ by_cases hpk : 2/((B i).card:ℝ)≤cellProb (B i) C · rw [ite_eq_left hpk] have hh := (cutError_tiny hδ hat (cellProb_le_one (B i) C)).2 have hm := mul_le_mul_of_nonneg_left hh (hw i) convert hm using 1; ring · rw [ite_eq_right hpk] have hp : cellProb (B i) C≤δ := (le_of_lt (lt_of_not_ge hpk)).trans (hk i) simp only [cutError,tent_zero_left hp,tent_zero_left (show cellProb Finset.univ C≤δ by linarith), sub_self,abs_zero,zero_mul,add_zero,mul_zero] norm_num have hx : 0≤(8*ε/δ^2)*pairCell Finset.univ C := mul_nonneg (by positivity) (pairCell_nonneg _ _) have hy : 0≤(1/ε)*varianceCell w B T C := mul_nonneg (by positivity) hv nlinarith end WeakPinned.Variance namespace WeakPinned.Variance open scoped BigOperators variable {P : Type u3} {I : Type u4} [Fintype P] [Fintype I] [DecidableEq P] lemma balanced_cell_size (δ : ℝ) (hδ : 0<δ) (hn : 4≤δ*(Fintype.card P:ℝ)) (C : Finset P) (ha : δ/2≤cellProb Finset.univ C) : 2≤C.card := by have hn0 : (0:ℝ)