Download data/lean/OAI/Probability/Contingency/GridCover.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 31.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Contingency/GridCover.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/Contingency/GridCover.lean
-
curl -L -o GridCover.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Contingency/GridCover.lean
31.7 kB
| import Mathlib | |
| import OAI.Probability.Contingency.DenseAnalytic | |
| namespace OAI | |
| /-! Grid Cover. -/ | |
| noncomputable section | |
| open Set MeasureTheory | |
| open Set MeasureTheory | |
| open scoped Pointwise | |
| namespace Contingency.Grid | |
| noncomputable section | |
| variable {q K : β} | |
| open Contingency.Interpolation | |
| theorem neighbors_symm (v w : Fin q β β) (i : Fin q) (hn : neighbors v w i) : neighbors w v i := | |
| β¨hn.1.symm,fun j hj => (hn.2 j hj).symmβ© | |
| theorem neighbors_unique (v w : Fin q β β) (i j : Fin q) | |
| (hi : neighbors v w i) (hj : neighbors v w j) : i=j := by | |
| by_contra hne | |
| have he := hj.2 i hne | |
| rcases hi.1 with h | h <;> omega | |
| theorem faceBox_swap (v w : Vertex q K) (i : Fin q) (r : β) | |
| (hn : neighbors (corner v) (corner w) i) : faceBox v w i r=faceBox w v i r := by | |
| unfold faceBox | |
| congr 1 <;> funext j <;> split_ifs with hj | |
| Β· rw [max_comm] | |
| Β· have hh := hn.2 j hj | |
| dsimp [corner] at hh | |
| rw [hh] | |
| Β· rw [max_comm] | |
| Β· have hh := hn.2 j hj | |
| dsimp [corner] at hh | |
| rw [hh] | |
| def Cut (V : Finset (Vertex q K)) := | |
| {e : Vertex q KΓVertex q K // e.1βV β§ e.2βV β§ β i,neighbors (corner e.1) (corner e.2) i} | |
| instance cutFintype (V : Finset (Vertex q K)) : Fintype (Cut V) := by unfold Cut; exact Fintype.ofFinite _ | |
| def Cut.coord {V : Finset (Vertex q K)} (e : Cut V) : Fin q := Classical.choose e.property.2.2 | |
| theorem Cut.adjacent {V : Finset (Vertex q K)} (e : Cut V) : | |
| neighbors (corner e.val.1) (corner e.val.2) e.coord := Classical.choose_spec e.property.2.2 | |
| def Cut.neighborhood {V : Finset (Vertex q K)} (e : Cut V) (r : β) : OpenBox q := faceBox e.val.1 e.val.2 e.coord r | |
| theorem cut_cover_endpoints (V : Finset (Vertex q K)) (v w : Vertex q K) (hv : vβV) (hw : wβV) | |
| (x z : Fin q β β) (hx : inside (corner v) x) (hz : inside (corner w) z) | |
| (r : β) (hr : r β€ 1) (hc : β i,|x i-z i|<r) : | |
| β e : Cut V,zβ(e.neighborhood r).carrier := by | |
| obtain β¨u,u',i,hn,hl,hzβ© := bounded_cut_face V v w hv hw x z hx hz r hr hc | |
| rcases hl with β¨hu,hu'β© | β¨hu,hu'β© | |
| Β· let e : Cut V := β¨(u,u'),hu,hu',i,hnβ© | |
| have he : e.coord=i := neighbors_unique _ _ _ _ e.adjacent hn | |
| exact β¨e,by simpa only [Cut.neighborhood,he] using hzβ© | |
| Β· let e : Cut V := β¨(u',u),hu',hu,i,neighbors_symm _ _ _ hnβ© | |
| have he : e.coord=i := neighbors_unique _ _ _ _ e.adjacent (neighbors_symm _ _ _ hn) | |
| refine β¨e,?_β© | |
| change zβ(faceBox u' u e.coord r).carrier | |
| rw [he,β faceBox_swap u u' i r hn] | |
| exact hz | |
| theorem minkowski_cut_cover (V : Finset (Vertex q K)) (t : β) | |
| (ht : 0<t) (ht1 : t<1) (hr : t*(K:β) β€ 1) : | |
| βα΅ z : Fin q β β βvolume, | |
| zβboxUnion (mixBoxes (boxes V) {cube q K} (1-t) t) \ boxUnion (boxes V) β | |
| β e : Cut V,zβ(e.neighborhood (t*K)).carrier := by | |
| filter_upwards [ae_no_grid (q:=q)] with z hgrid | |
| rintro β¨hz,hnzβ© | |
| obtain β¨x,hx,y,hy,heβ© := (mem_mixBoxes (boxes V) {cube q K} (1-t) t (by linarith) ht z).mp hz | |
| have hy' : β i,0<y i β§ y i<(K:β) := (mem_cube y).mp (by simpa [boxUnion] using hy) | |
| have hx' := (mem_cube x).mp (bins_subset_cube V hx) | |
| have he' (i : Fin q) : z i=(1-t)*x i+t*y i := by simpa using (congrFun he i).symm | |
| have hzcube : zβ(cube q K).carrier := by | |
| apply (mem_cube z).mpr | |
| intro i | |
| rw [he'] | |
| constructor | |
| Β· exact add_pos (mul_pos (by linarith) (hx' i).1) (mul_pos ht (hy' i).1) | |
| Β· have h1 := mul_lt_mul_of_pos_left (hx' i).2 (show 0<1-t by linarith) | |
| have h2 := mul_lt_mul_of_pos_left (hy' i).2 ht | |
| nlinarith only [h1,h2] | |
| obtain β¨v,hv,hvxβ© := (mem_boxes V x).mp hx | |
| obtain β¨w,hwzβ© := exists_bin z hzcube hgrid | |
| have hw : wβV := fun hh => hnz ((mem_boxes V z).mpr β¨w,hh,hwzβ©) | |
| apply cut_cover_endpoints V v w hv hw x z hvx hwz (t*K) hr | |
| intro i | |
| have hd : |x i-y i|<(K:β) := by rw [abs_lt]; constructor <;> linarith [(hx' i).1,(hx' i).2,(hy' i).1,(hy' i).2] | |
| rw [he'] | |
| have heq : x i-((1-t)*x i+t*y i)=t*(x i-y i) := by ring | |
| rw [heq,abs_mul,abs_of_pos ht] | |
| exact mul_lt_mul_of_pos_left hd ht | |
| end | |
| end Contingency.Grid | |
| open Set MeasureTheory | |
| open scoped BigOperators | |
| namespace Contingency.Grid | |
| noncomputable section | |
| variable {q K : β} | |
| open Contingency.Interpolation | |
| theorem box_integrable (F : GoodWeight q) (B : OpenBox q) : IntegrableOn F.f B.carrier := by | |
| simpa only [boxUnion,Finset.mem_singleton,iUnion_iUnion_eq_left] using F.integrable {B} | |
| theorem bin_volume (v : Vertex q K) : volume (bin v).carrier=1 := by | |
| simp [bin,OpenBox.carrier,volume_pi_pi] | |
| theorem box_volume_real (B : OpenBox q) (hp : β i,B.lower i β€ B.upper i) : | |
| (volume B.carrier).toReal=β i,(B.upper i-B.lower i) := by | |
| simp only [OpenBox.carrier,volume_pi_pi,Real.volume_Ioo,ENNReal.toReal_prod] | |
| congr 1 | |
| funext i | |
| exact ENNReal.toReal_ofReal (sub_nonneg.mpr (hp i)) | |
| theorem faceBox_volume (v w : Vertex q K) (i : Fin q) (r : β) (hr : 0 β€ r) : | |
| (volume (faceBox v w i r).carrier).toReal=2*r*(1+2*r)^(q-1) := by | |
| have hlen (j : Fin q) : (faceBox v w i r).upper j-(faceBox v w i r).lower j= | |
| if j=i then 2*r else 1+2*r := by | |
| dsimp [faceBox] | |
| split_ifs <;> ring | |
| rw [box_volume_real _ (fun j => sub_nonneg.mp (by rw [hlen]; split_ifs <;> positivity))] | |
| simp_rw [hlen] | |
| classical | |
| rw [β Finset.mul_prod_erase Finset.univ (fun j => if j=i then 2*r else 1+2*r) (Finset.mem_univ i)] | |
| simp only [ite_true] | |
| have he : (β jβFinset.univ.erase i,if j=i then 2*r else 1+2*r)=(1+2*r)^(q-1) := by | |
| calc | |
| _ = β _jβFinset.univ.erase i,(1+2*r) := Finset.prod_congr rfl (fun j hj => ite_eq_right (Finset.ne_of_mem_erase hj)) | |
| _ = _ := by simp | |
| rw [he] | |
| theorem integral_boxes (F : GoodWeight q) (V : Finset (Vertex q K)) : | |
| (β« x in boxUnion (boxes V),F.f x)=β vβV,β« x in (bin v).carrier,F.f x := by | |
| have hs : boxUnion (boxes V)=β vβV,(bin v).carrier := by | |
| ext x | |
| simp only [mem_boxes,Set.mem_iUnion,mem_bin] | |
| constructor <;> rintro β¨v,hv,hxβ© <;> exact β¨v,hv,hxβ© | |
| rw [hs] | |
| apply integral_biUnion_finset V | |
| Β· intro v _; exact (bin v).isOpen.measurableSet | |
| Β· intro v _ w _ hne; exact bins_disjoint hne | |
| Β· intro v _; exact box_integrable F (bin v) | |
| theorem bin_integral_bounds (F : GoodWeight q) (W : Vertex q K β β) | |
| (hp : β v x,xβ(bin v).carrier β W v/4 β€ F.f x β§ F.f x β€ 4*W v) (v : Vertex q K) : | |
| W v/4 β€ β« x in (bin v).carrier,F.f x β§ (β« x in (bin v).carrier,F.f x) β€ 4*W v := by | |
| have hi := box_integrable F (bin v) | |
| have hj (a : β) : IntegrableOn (fun _ : Fin q β β => a) (bin v).carrier := | |
| integrableOn_const (by rw [bin_volume]; exact ENNReal.one_ne_top) | |
| have hc (a : β) : (β« _ in (bin v).carrier,a)=a := by simp [bin_volume,Measure.real] | |
| constructor | |
| Β· rw [β hc (W v/4)] | |
| exact setIntegral_mono_on (hj _) hi (bin v).isOpen.measurableSet (fun x hx => (hp v x hx).1) | |
| Β· rw [β hc (4*W v)] | |
| exact setIntegral_mono_on hi (hj _) (bin v).isOpen.measurableSet (fun x hx => (hp v x hx).2) | |
| theorem boxes_integral_bounds (F : GoodWeight q) (W : Vertex q K β β) | |
| (hp : β v x,xβ(bin v).carrier β W v/4 β€ F.f x β§ F.f x β€ 4*W v) (V : Finset (Vertex q K)) : | |
| (β vβV,W v)/4 β€ β« x in boxUnion (boxes V),F.f x β§ | |
| (β« x in boxUnion (boxes V),F.f x) β€ 4*β vβV,W v := by | |
| rw [integral_boxes] | |
| constructor | |
| Β· rw [Finset.sum_div] | |
| exact Finset.sum_le_sum fun v _ => (bin_integral_bounds F W hp v).1 | |
| Β· rw [Finset.mul_sum] | |
| exact Finset.sum_le_sum fun v _ => (bin_integral_bounds F W hp v).2 | |
| end | |
| end Contingency.Grid | |
| open Set MeasureTheory | |
| open scoped BigOperators Pointwise | |
| namespace Contingency.Grid | |
| noncomputable section | |
| variable {q K : β} | |
| open Contingency.Interpolation | |
| theorem face_volume_bound (d : β) (hd : 1 β€ d) (hq : (q:β) β€ d) | |
| (v w : Vertex q K) (i : Fin q) : | |
| (volume (faceBox v w i (1/(4*d))).carrier).toReal β€ 1 := by | |
| have hd0 : 0<d := by linarith | |
| rw [faceBox_volume _ _ _ _ (by positivity)] | |
| have hexp : (1+2*(1/(4*d)))^(q-1) β€ 2 := by | |
| calc | |
| _ β€ (Real.exp (2*(1/(4*d))))^(q-1) := by | |
| apply pow_le_pow_leftβ (by positivity) | |
| linarith only [Real.add_one_le_exp (2*(1/(4*d)))] | |
| _ = Real.exp ((q-1:β)*(2*(1/(4*d)))) := (Real.exp_nat_mul _ _).symm | |
| _ β€ Real.exp (1/2) := by | |
| apply Real.exp_le_exp.mpr | |
| have hq' : ((q-1:β):β) β€ d := (Nat.cast_le.mpr (Nat.sub_le q 1)).trans hq | |
| have he : ((q-1:β):β)*(2*(1/(4*d)))=((q-1:β):β)/(2*d) := by ring | |
| rw [he] | |
| apply (div_le_iffβ (by positivity : 0<2*d)).mpr | |
| linarith only [hq'] | |
| _ β€ 2 := by have hh := Real.exp_bound_div_one_sub_of_interval (x:=1/2) (by norm_num) (by norm_num); norm_num at hh β’; exact hh | |
| have hmul := mul_le_mul_of_nonneg_left hexp (show 0 β€ 2*(1/(4*d)) by positivity) | |
| calc | |
| _ β€ 2*(1/(4*d))*2 := hmul | |
| _ = 1/d := by ring | |
| _ β€ 1 := (div_le_one hd0).mpr hd | |
| theorem integral_cover (F : GoodWeight q) (V : Finset (Vertex q K)) (t : β) | |
| (ht : 0<t) (ht1 : t<1) (hr : t*(K:β) β€ 1) : | |
| (β« z in boxUnion (mixBoxes (boxes V) {cube q K} (1-t) t) \ boxUnion (boxes V),F.f z) β€ | |
| β e : Cut V,β« z in (e.neighborhood (t*K)).carrier,F.f z := by | |
| classical | |
| let G := boxUnion (mixBoxes (boxes V) {cube q K} (1-t) t) \ boxUnion (boxes V) | |
| have hG : MeasurableSet G := (boxUnion_measurable _).diff (boxUnion_measurable _) | |
| have hiG : Integrable (G.indicator F.f) := | |
| ((F.integrable _).mono_set sdiff_subset).integrable_indicator hG | |
| have hi (e : Cut V) : Integrable ((e.neighborhood (t*K)).carrier.indicator F.f) := | |
| (box_integrable F _).integrable_indicator (e.neighborhood (t*K)).isOpen.measurableSet | |
| have hh : (β« z,G.indicator F.f z) β€ β« z,β e : Cut V,(e.neighborhood (t*K)).carrier.indicator F.f z := by | |
| apply integral_mono_ae hiG (integrable_finsetSum _ (fun e _ => hi e)) | |
| filter_upwards [minkowski_cut_cover V t ht ht1 hr] with z hz | |
| have hnon (e : Cut V) : 0 β€ (e.neighborhood (t*K)).carrier.indicator F.f z := by | |
| by_cases he : zβ(e.neighborhood (t*K)).carrier <;> simp [he,(F.positive z).le] | |
| by_cases hzG : zβG | |
| Β· obtain β¨e,heβ© := hz hzG | |
| rw [Set.indicator_of_mem hzG] | |
| calc | |
| _ = (e.neighborhood (t*K)).carrier.indicator F.f z := (Set.indicator_of_mem he _).symm | |
| _ β€ _ := Finset.single_le_sum (fun e _ => hnon e) (Finset.mem_univ e) | |
| Β· rw [Set.indicator_of_notMem hzG] | |
| exact Finset.sum_nonneg fun e _ => hnon e | |
| rw [integral_indicator hG,integral_finsetSum _ (fun e _ => hi e)] at hh | |
| simp_rw [integral_indicator ((Cut.neighborhood _ _).isOpen.measurableSet)] at hh | |
| exact hh | |
| end | |
| end Contingency.Grid | |
| open Set MeasureTheory | |
| open scoped BigOperators Pointwise | |
| namespace Contingency.Grid | |
| noncomputable section | |
| variable {q K : β} | |
| open Contingency.Interpolation | |
| def border (V : Finset (Vertex q K)) (W : Vertex q K β β) : β := | |
| β e : Cut V,min (W e.val.1) (W e.val.2) | |
| def Cut.reverse (V : Finset (Vertex q K)) : Cut V β Cut VαΆ where | |
| toFun e := β¨(e.val.2,e.val.1),by | |
| refine β¨by simpa using e.property.2.1,by simpa using e.property.1,?_β© | |
| exact β¨e.coord,neighbors_symm _ _ _ e.adjacentβ©β© | |
| invFun e := β¨(e.val.2,e.val.1),by | |
| refine β¨by simpa using e.property.2.1,by simpa using e.property.1,?_β© | |
| exact β¨e.coord,neighbors_symm _ _ _ e.adjacentβ©β© | |
| left_inv _ := rfl | |
| right_inv _ := rfl | |
| theorem border_compl (V : Finset (Vertex q K)) (W : Vertex q K β β) : | |
| border VαΆ W=border V W := by | |
| unfold border | |
| rw [β (Cut.reverse V).sum_comp (fun e => min (W e.val.1) (W e.val.2))] | |
| apply Finset.sum_congr rfl | |
| intro e _ | |
| exact min_comm _ _ | |
| theorem mass_partition (F : GoodWeight q) (V : Finset (Vertex q K)) : | |
| (β« x in boxUnion (boxes V),F.f x)+(β« x in boxUnion (boxes VαΆ),F.f x)= | |
| β« x in (cube q K).carrier,F.f x := by | |
| rw [integral_boxes,integral_boxes,Finset.sum_add_sum_compl] | |
| rw [β integral_boxes F Finset.univ] | |
| exact setIntegral_congr_set cube_ae_union | |
| theorem boxes_nonempty (V : Finset (Vertex q K)) (hV : V.Nonempty) : | |
| (boxUnion (boxes V)).Nonempty := by | |
| obtain β¨v,hvβ© := hV | |
| refine β¨fun i => (v i:β)+1/2,(mem_boxes V _).mpr β¨v,hv,?_β©β© | |
| intro i | |
| dsimp [corner] | |
| constructor <;> linarith | |
| theorem face_integral_bound (F : GoodWeight q) (W : Vertex q K β β) | |
| (hW : β v,0 β€ W v) (d : β) (hd : 1 β€ d) (hq : (q:β) β€ d) | |
| (hp : β (v w : Vertex q K) (i : Fin q),neighbors (corner v) (corner w) i β | |
| β x,xβ(faceBox v w i (1/(4*d))).carrier β F.f x β€ 4*min (W v) (W w)) | |
| (V : Finset (Vertex q K)) (e : Cut V) : | |
| (β« x in (e.neighborhood (1/(4*d))).carrier,F.f x) β€ 4*min (W e.val.1) (W e.val.2) := by | |
| let B := e.neighborhood (1/(4*d)) | |
| calc | |
| _ β€ β« _x in B.carrier,4*min (W e.val.1) (W e.val.2) := | |
| setIntegral_mono_on (box_integrable F B) (integrableOn_const B.isBounded.measure_lt_top.ne) B.isOpen.measurableSet | |
| (hp _ _ _ e.adjacent) | |
| _ = (volume B.carrier).toReal*(4*min (W e.val.1) (W e.val.2)) := by simp [Measure.real] | |
| _ β€ _ := by | |
| exact mul_le_of_le_one_left (mul_nonneg (by norm_num) (le_min (hW _) (hW _))) (face_volume_bound d hd hq _ _ _) | |
| theorem small_side_border (F : GoodWeight q) (W : Vertex q K β β) | |
| (hW : β v,0 β€ W v) (d : β) (hd : 1 β€ d) (hq : (q:β) β€ d) (hK : 1 β€ K) | |
| (hc : β x y (Ξ± Ξ² : β),0 β€ Ξ± β 0 β€ Ξ² β Ξ±+Ξ²=1 β F.f x^Ξ±*F.f y^Ξ² β€ F.f (Ξ± β’ x+Ξ² β’ y)) | |
| (hb : β v x,xβ(bin v).carrier β W v/4 β€ F.f x β§ F.f x β€ 4*W v) | |
| (hp : β (v w : Vertex q K) (i : Fin q),neighbors (corner v) (corner w) i β | |
| β x,xβ(faceBox v w i (1/(4*d))).carrier β F.f x β€ 4*min (W v) (W w)) | |
| (V : Finset (Vertex q K)) (hV : V.Nonempty) | |
| (hsmall : 2*(β« x in boxUnion (boxes V),F.f x) β€ β« x in (cube q K).carrier,F.f x) : | |
| Real.log 2/(64*d*K)*(β vβV,W v) β€ border V W := by | |
| let t : β := 1/(4*d*K) | |
| have hd0 : 0<d := by linarith | |
| have hK' : (1:β) β€ K := by exact_mod_cast hK | |
| have hK0 : (0:β)<K := by linarith | |
| have ht : 0<t := by dsimp [t]; positivity | |
| have ht1 : t<1 := by dsimp [t]; apply (div_lt_one (by positivity)).mpr; nlinarith | |
| have hr : t*(K:β)=1/(4*d) := by dsimp [t]; field_simp | |
| have hr1 : t*(K:β) β€ 1 := by rw [hr]; apply (div_le_one (by positivity)).mpr; linarith | |
| have hsub : boxUnion (boxes V) β boxUnion ({cube q K} : Finset (OpenBox q)) := by | |
| simpa only [boxUnion,Finset.mem_singleton,iUnion_iUnion_eq_left] using bins_subset_cube V | |
| have hgain := mass_gain (boxes V) {cube q K} F hsub (boxes_nonempty V hV) | |
| (by simpa only [boxUnion,Finset.mem_singleton,iUnion_iUnion_eq_left] using hsmall) t ht ht1 | |
| (fun x y => hc x y (1-t) t (by linarith) ht.le (by ring)) | |
| have hcover := integral_cover F V t ht ht1 hr1 | |
| rw [hr] at hcover | |
| have hface : (β e : Cut V,β« x in (e.neighborhood (1/(4*d))).carrier,F.f x) β€ 4*border V W := by | |
| unfold border | |
| rw [Finset.mul_sum] | |
| exact Finset.sum_le_sum fun e _ => face_integral_bound F W hW d hd hq hp V e | |
| have hlower := (boxes_integral_bounds F W hb V).1 | |
| have hlog : 0<Real.log 2 := Real.log_pos (by norm_num) | |
| have hmult := mul_le_mul_of_nonneg_left hlower (mul_nonneg ht.le hlog.le) | |
| have he : t*Real.log 2*((β vβV,W v)/4)/4=Real.log 2/(64*d*K)*(β vβV,W v) := by dsimp [t]; ring | |
| rw [β he] | |
| linarith only [hmult,hgain,hcover,hface] | |
| theorem border_bound (F : GoodWeight q) (W : Vertex q K β β) | |
| (hW : β v,0 β€ W v) (d : β) (hd : 1 β€ d) (hq : (q:β) β€ d) (hK : 1 β€ K) | |
| (hc : β x y (Ξ± Ξ² : β),0 β€ Ξ± β 0 β€ Ξ² β Ξ±+Ξ²=1 β F.f x^Ξ±*F.f y^Ξ² β€ F.f (Ξ± β’ x+Ξ² β’ y)) | |
| (hb : β v x,xβ(bin v).carrier β W v/4 β€ F.f x β§ F.f x β€ 4*W v) | |
| (hp : β (v w : Vertex q K) (i : Fin q),neighbors (corner v) (corner w) i β | |
| β x,xβ(faceBox v w i (1/(4*d))).carrier β F.f x β€ 4*min (W v) (W w)) | |
| (V : Finset (Vertex q K)) (hV : V.Nonempty) (hVc : VαΆ.Nonempty) : | |
| Real.log 2/(64*d*K)*min (β vβV,W v) (β vβVαΆ,W v) β€ border V W := by | |
| have hnon : 0 β€ Real.log 2/(64*d*K) := by positivity | |
| have hm := mass_partition F V | |
| by_cases hs : 2*(β« x in boxUnion (boxes V),F.f x) β€ β« x in (cube q K).carrier,F.f x | |
| Β· exact (mul_le_mul_of_nonneg_left (min_le_left _ _) hnon).trans | |
| (small_side_border F W hW d hd hq hK hc hb hp V hV hs) | |
| Β· have hs' : 2*(β« x in boxUnion (boxes VαΆ),F.f x) β€ β« x in (cube q K).carrier,F.f x := by linarith | |
| have hh := small_side_border F W hW d hd hq hK hc hb hp VαΆ hVc hs' | |
| rw [border_compl] at hh | |
| exact (mul_le_mul_of_nonneg_left (min_le_right _ _) hnon).trans hh | |
| end | |
| end Contingency.Grid | |
| open Set MeasureTheory | |
| open scoped BigOperators Pointwise | |
| namespace Contingency.Grid | |
| noncomputable section | |
| variable {q K : β} | |
| def realCorner (v : Vertex q K) : Fin q β β := fun i => v i | |
| def exponentWeight (g : (Fin q β β) β β) (v : Vertex q K) : β := | |
| (2:β)^(-(βg (realCorner v)β:β)) | |
| theorem exponentWeight_pos (g : (Fin q β β) β β) (v : Vertex q K) : | |
| 0<exponentWeight g v := Real.rpow_pos_of_pos (by norm_num) _ | |
| theorem exponentWeight_upper (g : (Fin q β β) β β) (v : Vertex q K) (x : Fin q β β) | |
| (hh : g (realCorner v)-g x β€ 2) : (2:β)^(-g x) β€ 4*exponentWeight g v := by | |
| have hf := Int.floor_le (g (realCorner v)) | |
| calc | |
| _ β€ (2:β)^(-(βg (realCorner v)β:β)+2) := | |
| Real.rpow_le_rpow_of_exponent_le (by norm_num) (by linarith) | |
| _ = _ := by rw [Real.rpow_add (by norm_num : (0:β)<2)]; norm_num [exponentWeight]; ring | |
| theorem exponentWeight_lower (g : (Fin q β β) β β) (v : Vertex q K) (x : Fin q β β) | |
| (hh : g x-g (realCorner v) β€ 1) : exponentWeight g v/4 β€ (2:β)^(-g x) := by | |
| have hf := Int.lt_floor_add_one (g (realCorner v)) | |
| calc | |
| _ = (2:β)^(-(βg (realCorner v)β:β)-2) := by | |
| rw [Real.rpow_sub (by norm_num : (0:β)<2)]; norm_num [exponentWeight] | |
| _ β€ _ := Real.rpow_le_rpow_of_exponent_le (by norm_num) (by linarith) | |
| theorem bin_distance (v : Vertex q K) (x : Fin q β β) (hx : xβ(bin v).carrier) : | |
| βx-realCorner vβ β€ 1 := by | |
| apply (pi_norm_le_iff_of_nonneg (by norm_num : (0:β) β€ 1)).mpr | |
| intro i | |
| have hh := (mem_bin v x).mp hx i | |
| dsimp [inside,corner] at hh | |
| simp only [Pi.sub_apply,realCorner,Real.norm_eq_abs,abs_le] | |
| constructor <;> linarith [hh.1,hh.2] | |
| theorem face_distance (v w : Vertex q K) (i : Fin q) (r : β) (hr : 0 β€ r) | |
| (hn : neighbors (corner v) (corner w) i) (x : Fin q β β) | |
| (hx : xβ(faceBox v w i r).carrier) : βx-realCorner vβ β€ 1+r := by | |
| apply (pi_norm_le_iff_of_nonneg (by linarith : (0:β) β€ 1+r)).mpr | |
| intro j | |
| have hh := (Set.mem_pi.mp hx) j (Set.mem_univ j) | |
| simp only [Set.mem_Ioo,faceBox] at hh | |
| simp only [Pi.sub_apply,realCorner,Real.norm_eq_abs,abs_le] | |
| by_cases hj : j=i | |
| Β· subst j | |
| simp only [ite_true,Nat.cast_max] at hh | |
| have hn' := hn.1 | |
| dsimp [corner] at hn' | |
| rcases hn' with h | h | |
| Β· have he : (v i:β)+1=(w i:β) := by exact_mod_cast h | |
| have hm : max (v i:β) (w i:β)=(w i:β) := max_eq_right (by linarith) | |
| rw [hm] at hh | |
| constructor <;> linarith [hh.1,hh.2] | |
| Β· have he : (w i:β)+1=(v i:β) := by exact_mod_cast h | |
| have hm : max (v i:β) (w i:β)=(v i:β) := max_eq_left (by linarith) | |
| rw [hm] at hh | |
| constructor <;> linarith [hh.1,hh.2] | |
| Β· simp only [hj,ite_false] at hh | |
| constructor <;> linarith [hh.1,hh.2] | |
| theorem weight_bin_comparison (g : (Fin q β β) β β) (L : β) (hL : 0 β€ L) (hL1 : L β€ 1) | |
| (hg : β x y,|g x-g y| β€ L*βx-yβ) | |
| (v : Vertex q K) (x : Fin q β β) (hx : xβ(bin v).carrier) : | |
| exponentWeight g v/4 β€ (2:β)^(-g x) β§ (2:β)^(-g x) β€ 4*exponentWeight g v := by | |
| have hh : |g x-g (realCorner v)| β€ 1 := | |
| (hg x (realCorner v)).trans ((mul_le_mul_of_nonneg_left (bin_distance v x hx) hL).trans (by simpa using hL1)) | |
| constructor | |
| Β· exact exponentWeight_lower g v x (abs_le.mp hh).2 | |
| Β· apply exponentWeight_upper | |
| linarith only [(abs_le.mp hh).1] | |
| theorem weight_face_comparison (g : (Fin q β β) β β) (L r : β) (hL : 0 β€ L) (hr : 0 β€ r) | |
| (hLr : L*(1+r) β€ 2) (hg : β x y,|g x-g y| β€ L*βx-yβ) | |
| (v w : Vertex q K) (i : Fin q) (hn : neighbors (corner v) (corner w) i) | |
| (x : Fin q β β) (hx : xβ(faceBox v w i r).carrier) : | |
| (2:β)^(-g x) β€ 4*min (exponentWeight g v) (exponentWeight g w) := by | |
| have hv : (2:β)^(-g x) β€ 4*exponentWeight g v := by | |
| apply exponentWeight_upper | |
| have hh := (hg x (realCorner v)).trans ((mul_le_mul_of_nonneg_left (face_distance v w i r hr hn x hx) hL).trans hLr) | |
| linarith only [(abs_le.mp hh).1] | |
| have hw : (2:β)^(-g x) β€ 4*exponentWeight g w := by | |
| apply exponentWeight_upper | |
| have hx' : xβ(faceBox w v i r).carrier := by rw [β faceBox_swap v w i r hn]; exact hx | |
| have hh := (hg x (realCorner w)).trans ((mul_le_mul_of_nonneg_left (face_distance w v i r hr (neighbors_symm _ _ _ hn) x hx') hL).trans hLr) | |
| linarith only [(abs_le.mp hh).1] | |
| rw [mul_min_of_nonneg _ _ (by norm_num : (0:β) β€ 4)] | |
| exact le_min hv hw | |
| end | |
| end Contingency.Grid | |
| open Set MeasureTheory | |
| open scoped BigOperators Pointwise | |
| namespace Contingency.Dense | |
| noncomputable section | |
| variable {a c q K : β} | |
| open Contingency.Grid Contingency.Interpolation | |
| def binExponent (e : Fin q β Fin aΓFin c) (R : Fin (a+1) β β) (P : Fin (c+1) β β) | |
| (w : Fin a β Fin c β β) (d : β) (x : Fin q β β) : β := | |
| d^4*penalty R P w (d^8) d (fun s => x (e.symm s)) | |
| def binWeight (e : Fin q β Fin aΓFin c) (R : Fin (a+1) β β) (P : Fin (c+1) β β) | |
| (w : Fin a β Fin c β β) (d : β) : Vertex q K β β := exponentWeight (binExponent e R P w d) | |
| theorem exponent_lipschitz (e : Fin q β Fin aΓFin c) | |
| (R : Fin (a+1) β β) (P : Fin (c+1) β β) (w : Fin a β Fin c β β) | |
| (d : β) (hd : 1 β€ d) (he : (a*c:β) β€ d) | |
| (hR : β i,0<R i) (hP : β j,0<P j) | |
| (hRmax : β i,R i β€ R (Fin.last a)) (hPmax : β j,P j β€ P (Fin.last c)) | |
| (hw0 : β i j,0 β€ w i j) (hw : β i j,w i j β€ scale R P i.castSucc j.castSucc/d^8) | |
| (x y : Fin q β β) : |binExponent e R P w d x-binExponent e R P w d y| β€ βx-yβ := by | |
| have hd0 : 0<d := by linarith | |
| let u : Fin aΓFin c β β := fun s => x (e.symm s) | |
| let v : Fin aΓFin c β β := fun s => y (e.symm s) | |
| have hn : βu-vβ β€ βx-yβ := by | |
| apply (pi_norm_le_iff_of_nonneg (norm_nonneg _)).mpr | |
| intro s | |
| exact norm_le_pi_norm (x-y) (e.symm s) | |
| have hh := penalty_difference R P w (d^8) d (d/d^8*βu-vβ) (by positivity) u v | |
| (fun i j => normalized_lipschitz R P w (d^8) d (by positivity) he hR hP hRmax hPmax hw0 hw u v i j) | |
| have hcoef : d^4*(d/d^8) β€ 1 := by | |
| have hid : d^4*(d/d^8)=1/d^3 := by field_simp | |
| rw [hid] | |
| exact (div_le_one (by positivity)).mpr (one_le_powβ hd) | |
| unfold binExponent | |
| rw [β mul_sub,abs_mul,abs_of_nonneg (by positivity : 0 β€ d^4)] | |
| calc | |
| _ β€ d^4*(d/d^8*βu-vβ) := mul_le_mul_of_nonneg_left hh (by positivity) | |
| _ β€ βu-vβ := by nlinarith only [mul_le_mul_of_nonneg_right hcoef (norm_nonneg (u-v))] | |
| _ β€ _ := hn | |
| theorem bin_density_eq (e : Fin q β Fin aΓFin c) | |
| (R : Fin (a+1) β β) (P : Fin (c+1) β β) (w : Fin a β Fin c β β) | |
| (d : β) (x : Fin q β β) : | |
| (densityWeight e R P w (d^8) d (d^4) (by positivity)).f x=(2:β)^(-binExponent e R P w d x) := by | |
| simp only [densityWeight,density,binExponent,neg_mul] | |
| theorem bin_border_bound (e : Fin q β Fin aΓFin c) | |
| (R : Fin (a+1) β β) (P : Fin (c+1) β β) (w : Fin a β Fin c β β) | |
| (d : β) (hd : 1 β€ d) (he : (a*c:β) β€ d) (hq : (q:β) β€ d) (hK : 1 β€ K) | |
| (hR : β i,0<R i) (hP : β j,0<P j) | |
| (hRmax : β i,R i β€ R (Fin.last a)) (hPmax : β j,P j β€ P (Fin.last c)) | |
| (hw0 : β i j,0 β€ w i j) (hw : β i j,w i j β€ scale R P i.castSucc j.castSucc/d^8) | |
| (V : Finset (Vertex q K)) (hV : V.Nonempty) (hVc : VαΆ.Nonempty) : | |
| Real.log 2/(64*d*K)*min (β vβV,binWeight e R P w d v) (β vβVαΆ,binWeight e R P w d v) β€ | |
| border V (binWeight e R P w d) := by | |
| let F := densityWeight e R P w (d^8) d (d^4) (by positivity) | |
| have hlip (x y : Fin q β β) : |binExponent e R P w d x-binExponent e R P w d y| β€ 1*βx-yβ := by | |
| simpa only [one_mul] using exponent_lipschitz e R P w d hd he hR hP hRmax hPmax hw0 hw x y | |
| apply border_bound F _ (fun v => (exponentWeight_pos _ v).le) d hd hq hK | |
| Β· intro x y Ξ± Ξ² ha hb hab | |
| exact densityWeight_logconcave e R P w (d^8) d (d^4) (by positivity) x y Ξ± Ξ² ha hb hab | |
| Β· intro v x hx | |
| rw [show F.f x=(2:β)^(-binExponent e R P w d x) from bin_density_eq _ _ _ _ _ _] | |
| exact weight_bin_comparison _ 1 (by norm_num) le_rfl hlip v x hx | |
| Β· intro v w' i hn x hx | |
| rw [show F.f x=(2:β)^(-binExponent e R P w d x) from bin_density_eq _ _ _ _ _ _] | |
| apply weight_face_comparison _ 1 (1/(4*d)) (by norm_num) (by | |
| have hd0 : 0<d := by linarith | |
| positivity) _ hlip v w' i hn x hx | |
| have hd0 : 0<d := by linarith | |
| have hfrac : 1/(4*d) β€ 1 := (div_le_one (by positivity)).mpr (by linarith) | |
| linarith | |
| Β· exact hV | |
| Β· exact hVc | |
| theorem bin_conductance_numerator (e : Fin q β Fin aΓFin c) | |
| (R : Fin (a+1) β β) (P : Fin (c+1) β β) (w : Fin a β Fin c β β) | |
| (d : β) (hd : 1 β€ d) (he : (a*c:β) β€ d) (hq : (q:β) β€ d) (hK : 1 β€ K) | |
| (hR : β i,0<R i) (hP : β j,0<P j) | |
| (hRmax : β i,R i β€ R (Fin.last a)) (hPmax : β j,P j β€ P (Fin.last c)) | |
| (hw0 : β i j,0 β€ w i j) (hw : β i j,w i j β€ scale R P i.castSucc j.castSucc/d^8) | |
| (p : β) (hp : 1/(16*d) β€ p) | |
| (V : Finset (Vertex q K)) (hV : V.Nonempty) (hVc : VαΆ.Nonempty) : | |
| 1/(100000*d^2*K)*min (β vβV,binWeight e R P w d v) (β vβVαΆ,binWeight e R P w d v) β€ | |
| p*border V (binWeight e R P w d) := by | |
| have hd0 : 0<d := by linarith | |
| have hK0 : (0:β)<K := by exact_mod_cast (by omega : 0<K) | |
| have hb := bin_border_bound e R P w d hd he hq hK hR hP hRmax hPmax hw0 hw V hV hVc | |
| have hn : 0 β€ border V (binWeight e R P w d) := by | |
| unfold border | |
| exact Finset.sum_nonneg fun v _ => le_min (exponentWeight_pos _ _).le (exponentWeight_pos _ _).le | |
| have hc : 1/(100000*d^2*K) β€ (1/(16*d))*(Real.log 2/(64*d*K)) := by | |
| apply (div_le_iffβ (by positivity : 0 < 100000*d^2*K)).mpr | |
| have hh : (1/(16*d))*(Real.log 2/(64*d*K))*(100000*d^2*K)=3125/32*Real.log 2 := by field_simp; norm_num | |
| rw [hh] | |
| linarith only [Real.log_two_gt_d9] | |
| have hmin : 0 β€ min (β vβV,binWeight e R P w d v) (β vβVαΆ,binWeight e R P w d v) := | |
| le_min (Finset.sum_nonneg fun v _ => (exponentWeight_pos _ v).le) (Finset.sum_nonneg fun v _ => (exponentWeight_pos _ v).le) | |
| calc | |
| _ β€ (1/(16*d))*(Real.log 2/(64*d*K))*min (β vβV,binWeight e R P w d v) (β vβVαΆ,binWeight e R P w d v) := mul_le_mul_of_nonneg_right hc hmin | |
| _ β€ (1/(16*d))*border V (binWeight e R P w d) := by rw [mul_assoc]; exact mul_le_mul_of_nonneg_left hb (by positivity) | |
| _ β€ _ := mul_le_mul_of_nonneg_right hp hn | |
| end | |
| end Contingency.Dense | |
| open Set MeasureTheory | |
| open scoped BigOperators | |
| namespace Contingency.Dense | |
| noncomputable section | |
| variable {a c q K : β} | |
| open Contingency.Grid Contingency.Interpolation | |
| theorem region_volume_pos (f : (Fin (a+1)ΓFin (c+1)) β (Fin q β β) β β) | |
| (hf : β i,Continuous (f i)) (u : Fin q β β) (hu : β i,0<f i u) : | |
| 0 < volume (region f 0) := by | |
| let S := {x | β i,0<f i x} | |
| have ho : IsOpen S := by | |
| have he : S=β i,{x | 0<f i x} := by ext x; simp [S] | |
| rw [he] | |
| exact isOpen_iInter_of_finite fun i => isOpen_lt continuous_const (hf i) | |
| exact (ho.measure_pos volume β¨u,huβ©).trans_le (measure_mono (fun x hx i => (hx i).le)) | |
| theorem dense_density_volume (e : Fin q β Fin aΓFin c) | |
| (R : Fin (a+1) β β) (P : Fin (c+1) β β) (w : Fin a β Fin c β β) | |
| (d : β) (hd : 4 β€ d) (hq : (q:β) β€ d) (u : Fin q β β) | |
| (hu : β i,1/(2*d) β€ constraints e R P w i u) (S : Set (Fin q β β)) : | |
| (β«β» x in S,ENNReal.ofReal ((densityWeight e R P w (d^8) d (d^4) (by positivity)).f x)) β€ | |
| 4*volume (region (constraints e R P w) 0) := by | |
| let p (x : Fin q β β) := penalty R P w (d^8) d (fun s => x (e.symm s)) | |
| have hd0 : 0<d := by linarith | |
| apply density_layer_bound p ((penalty_continuous R P w (d^8) d).comp | |
| (continuous_pi fun _ => continuous_apply _)).measurable | |
| (fun x => penalty_nonneg _ _ _ _ _ _) (d^4) (by positivity) S | |
| intro j | |
| have hsub : {x | p x < ((j:β)+1)/d^4} β© S β | |
| region (constraints e R P w) (-(d/d^8+((j:β)+1)/d^4)) := by | |
| intro x hx i | |
| have hh := le_penalty R P w (d^8) d (fun s => x (e.symm s)) i.1 i.2 | |
| have hj := hx.1 | |
| change p x < _ at hj | |
| change -constraints e R P w i x-d/d^8 β€ p x at hh | |
| linarith only [hh,hj] | |
| calc | |
| _ β€ volume (region (constraints e R P w) (-(d/d^8+((j:β)+1)/d^4))) := measure_mono hsub | |
| _ β€ ENNReal.ofReal (Real.exp (2*d^2*(d/d^8+((j:β)+1)/d^4)))*volume (region (constraints e R P w) 0) := | |
| relaxed_volume_dense _ (constraints_affine e R P w) d hd0 hq u hu _ (by positivity) | |
| _ β€ ENNReal.ofReal ((4/3:β)^(j+1))*volume (region (constraints e R P w) 0) := by | |
| gcongr | |
| exact dense_exponent_layer d hd j | |
| _ = _ := by | |
| rw [ENNReal.ofReal_pow (by norm_num),ENNReal.ofReal_div_of_pos (by norm_num : (0:β)<3)] | |
| norm_num | |
| theorem dense_bin_normalizer_bound (e : Fin q β Fin aΓFin c) | |
| (R : Fin (a+1) β β) (P : Fin (c+1) β β) (w : Fin a β Fin c β β) | |
| (d : β) (hd : 4 β€ d) (he : (a*c:β) β€ d) (hq : (q:β) β€ d) | |
| (hR : β i,0<R i) (hP : β j,0<P j) | |
| (hRmax : β i,R i β€ R (Fin.last a)) (hPmax : β j,P j β€ P (Fin.last c)) | |
| (hw0 : β i j,0 β€ w i j) (hw : β i j,w i j β€ scale R P i.castSucc j.castSucc/d^8) | |
| (u : Fin q β β) (hu : β i,1/(2*d) β€ constraints e R P w i u) : | |
| ENNReal.ofReal (β v : Vertex q K,binWeight e R P w d v) β€ | |
| 16*volume (region (constraints e R P w) 0) := by | |
| let F := densityWeight e R P w (d^8) d (d^4) (by positivity) | |
| let S := boxUnion (boxes (Finset.univ : Finset (Vertex q K))) | |
| have hlip (x y : Fin q β β) : |binExponent e R P w d x-binExponent e R P w d y| β€ 1*βx-yβ := by | |
| simpa only [one_mul] using exponent_lipschitz e R P w d (by linarith) he hR hP hRmax hPmax hw0 hw x y | |
| have hb : β (v : Vertex q K) x,xβ(bin v).carrier β binWeight e R P w d v/4 β€ F.f x β§ F.f x β€ 4*binWeight e R P w d v := by | |
| intro v x hx | |
| rw [show F.f x=(2:β)^(-binExponent e R P w d x) from bin_density_eq _ _ _ _ _ _] | |
| exact weight_bin_comparison _ 1 (by norm_num) le_rfl hlip v x hx | |
| have hint := (boxes_integral_bounds F (binWeight e R P w d) hb Finset.univ).1 | |
| have hsum : (β v : Vertex q K,binWeight e R P w d v) β€ 4*(β« x in S,F.f x) := by | |
| dsimp [S] | |
| simpa only [mul_comm] using (div_le_iffβ (by norm_num : (0:β)<4)).mp hint | |
| calc | |
| _ β€ ENNReal.ofReal (4*(β« x in S,F.f x)) := ENNReal.ofReal_le_ofReal hsum | |
| _ = 4*(β«β» x in S,ENNReal.ofReal (F.f x)) := by | |
| rw [ENNReal.ofReal_mul (by norm_num),ofReal_integral_eq_lintegral_ofReal (F.integrable _) (Filter.Eventually.of_forall fun x => (F.positive x).le)] | |
| norm_num [S] | |
| _ β€ 4*(4*volume (region (constraints e R P w) 0)) := by | |
| gcongr | |
| exact dense_density_volume e R P w d hd hq u hu S | |
| _ = _ := by rw [β mul_assoc]; norm_num | |
| end | |
| end Contingency.Dense | |
| end | |
| end OAI | |