math / data /lean /OAI /Probability /Contingency /DenseAnalytic.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
29.2 kB
import Mathlib
import OAI.Probability.Contingency.PieceQuantiles
namespace OAI
/-! Dense Analytic. -/
noncomputable section
open Set MeasureTheory
open scoped Pointwise
open Set MeasureTheory
open scoped Pointwise
namespace Contingency.Dense
noncomputable section
variable {a c q : β„•}
theorem normalized_continuous (R : Fin (a+1) β†’ ℝ) (P : Fin (c+1) β†’ ℝ)
(w : Fin a β†’ Fin c β†’ ℝ) (i : Fin (a+1)) (j : Fin (c+1)) :
Continuous (fun u => normalized R P w u i j) := by
refine Fin.lastCases ?_ (fun i => ?_) i <;> refine Fin.lastCases ?_ (fun j => ?_) j
all_goals simp only [normalized,scaled,complete_corner,complete_bottom,complete_right,complete_free]
all_goals fun_prop
theorem penalty_continuous (R : Fin (a+1) β†’ ℝ) (P : Fin (c+1) β†’ ℝ)
(w : Fin a β†’ Fin c β†’ ℝ) (B d : ℝ) : Continuous (penalty R P w B d) := by
apply continuous_const.max
exact Continuous.finset_sup'_apply Finset.univ_nonempty fun s _ =>
(normalized_continuous R P w s.1 s.2).neg.sub continuous_const
theorem density_continuous (R : Fin (a+1) β†’ ℝ) (P : Fin (c+1) β†’ ℝ)
(w : Fin a β†’ Fin c β†’ ℝ) (B d A : ℝ) : Continuous (density R P w B d A) := by
unfold density
exact continuous_const.rpow (continuous_const.mul (penalty_continuous _ _ _ _ _)) (fun _ => Or.inl (by norm_num))
theorem density_le_one (R : Fin (a+1) β†’ ℝ) (P : Fin (c+1) β†’ ℝ)
(w : Fin a β†’ Fin c β†’ ℝ) (B d A : ℝ) (hA : 0 ≀ A) (u) : density R P w B d A u ≀ 1 := by
unfold density
exact Real.rpow_le_one_of_one_le_of_nonpos (by norm_num) (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hA) (penalty_nonneg _ _ _ _ _ _))
def densityWeight (e : Fin q ≃ Fin aΓ—Fin c)
(R : Fin (a+1) β†’ ℝ) (P : Fin (c+1) β†’ ℝ)
(w : Fin a β†’ Fin c β†’ ℝ) (B d A : ℝ) (hA : 0 ≀ A) : Interpolation.GoodWeight q where
f u := density R P w B d A (fun s => u (e.symm s))
continuous := (density_continuous _ _ _ _ _ _).comp (continuous_pi fun s => continuous_apply _)
positive u := density_pos _ _ _ _ _ _ _
bound := 1
bounded u := by rw [Real.norm_eq_abs,abs_of_pos (density_pos _ _ _ _ _ _ _)]; exact density_le_one _ _ _ _ _ _ hA _
theorem densityWeight_logconcave (e : Fin q ≃ Fin aΓ—Fin c)
(R : Fin (a+1) β†’ ℝ) (P : Fin (c+1) β†’ ℝ)
(w : Fin a β†’ Fin c β†’ ℝ) (B d A : ℝ) (hA : 0 ≀ A)
(u v : Fin q β†’ ℝ) (Ξ± Ξ² : ℝ) (ha : 0 ≀ Ξ±) (hb : 0 ≀ Ξ²) (hab : Ξ±+Ξ²=1) :
(densityWeight e R P w B d A hA).f u^Ξ±*(densityWeight e R P w B d A hA).f v^Ξ² ≀
(densityWeight e R P w B d A hA).f (Ξ± β€’ u+Ξ² β€’ v) :=
density_logconcave R P w B d A hA (fun s => u (e.symm s)) (fun s => v (e.symm s)) Ξ± Ξ² ha hb hab
end
end Contingency.Dense
namespace Contingency.Interpolation
noncomputable section
variable {q : β„•}
theorem mix_contains (S T : Finset (OpenBox q)) (hsub : boxUnion S βŠ† boxUnion T)
(t : ℝ) (ht : 0<t) (ht1 : t<1) : boxUnion S βŠ† boxUnion (mixBoxes S T (1-t) t) := by
intro x hx
apply (mem_mixBoxes S T (1-t) t (by linarith) ht x).mpr
refine ⟨x,hx,x,hsub hx,?_⟩
ext i
simp only [Pi.add_apply,Pi.smul_apply,smul_eq_mul]
ring
theorem mass_gain (S T : Finset (OpenBox q)) (F : GoodWeight q)
(hsub : boxUnion S βŠ† boxUnion T) (hS : (boxUnion S).Nonempty)
(hsmall : 2*(∫ x in boxUnion S,F.f x) ≀ ∫ x in boxUnion T,F.f x)
(t : ℝ) (ht : 0<t) (ht1 : t<1)
(hc : βˆ€ x y,F.f x^(1-t)*F.f y^t ≀ F.f ((1-t) β€’ x+t β€’ y)) :
t*Real.log 2*(∫ x in boxUnion S,F.f x) ≀
∫ x in boxUnion (mixBoxes S T (1-t) t) \ boxUnion S,F.f x := by
let m := ∫ x in boxUnion S,F.f x
have hm : 0 < m := F.integral_pos S hS
have hinter := logconcave_interpolation S T F (1-t) t (by linarith) ht (by ring) hc
have hlower : (2:ℝ)^t*m ≀ ∫ x in boxUnion (mixBoxes S T (1-t) t),F.f x := by
calc
_ = m^(1-t)*(2*m)^t := by
rw [Real.mul_rpow (by norm_num : (0:ℝ) ≀ 2) hm.le]
rw [mul_left_comm,← Real.rpow_add hm]
simp
_ ≀ m^(1-t)*(∫ x in boxUnion T,F.f x)^t :=
mul_le_mul_of_nonneg_left (Real.rpow_le_rpow (by positivity) hsmall ht.le) (Real.rpow_nonneg hm.le _)
_ ≀ _ := hinter
have hexp : 1+t*Real.log 2 ≀ (2:ℝ)^t := by
rw [Real.rpow_def_of_pos (by norm_num : (0:ℝ)<2)]
nlinarith only [Real.add_one_le_exp (Real.log 2*t)]
rw [setIntegral_sdiff (boxUnion_measurable S) (F.integrable _) (mix_contains S T hsub t ht ht1)]
have hh := mul_le_mul_of_nonneg_right hexp hm.le
dsimp [m] at hh hlower
nlinarith only [hh,hlower]
end
end Contingency.Interpolation
open Set MeasureTheory
open scoped Pointwise BigOperators
namespace Contingency.Dense
noncomputable section
variable {q : β„•} {I : Type*} [Fintype I]
def region (f : I β†’ (Fin q β†’ ℝ) β†’ ℝ) (Ο„ : ℝ) : Set (Fin q β†’ ℝ) :=
{x | βˆ€ i,Ο„ ≀ f i x}
theorem region_measurable (f : I β†’ (Fin q β†’ ℝ) β†’ ℝ) (hf : βˆ€ i,Continuous (f i)) (Ο„ : ℝ) :
MeasurableSet (region f Ο„) := by
have he : region f Ο„=β‹‚ i,{x | Ο„ ≀ f i x} := by ext x; simp [region]
rw [he]
exact MeasurableSet.iInter fun i => isClosed_le continuous_const (hf i) |>.measurableSet
omit [Fintype I] in
theorem homothety_affine (f : I β†’ (Fin q β†’ ℝ) β†’ ℝ)
(hf : βˆ€ i x y (Ξ± Ξ² : ℝ),Ξ±+Ξ²=1 β†’ f i (Ξ± β€’ x+Ξ² β€’ y)=Ξ±*f i x+Ξ²*f i y)
(i : I) (u x : Fin q β†’ ℝ) (r : ℝ) :
f i (AffineMap.homothety u r x)=r*f i x+(1-r)*f i u := by
have he : AffineMap.homothety u r x=r β€’ x+(1-r) β€’ u := by
ext j
simp only [AffineMap.homothety_apply, vadd_eq_add,vsub_eq_sub,Pi.add_apply,Pi.sub_apply,Pi.smul_apply,smul_eq_mul]
ring
rw [he,hf i x u r (1-r) (by ring)]
omit [Fintype I] in
theorem inner_image_subset (f : I β†’ (Fin q β†’ ℝ) β†’ ℝ)
(hf : βˆ€ i x y (Ξ± Ξ² : ℝ),Ξ±+Ξ²=1 β†’ f i (Ξ± β€’ x+Ξ² β€’ y)=Ξ±*f i x+Ξ²*f i y)
(u : Fin q β†’ ℝ) (s Ξ± : ℝ) (hu : βˆ€ i,s ≀ f i u)
(ha : 0 ≀ Ξ±) (ha1 : Ξ± ≀ 1) :
AffineMap.homothety u (1-Ξ±) '' region f 0 βŠ† region f (Ξ±*s) := by
rintro z ⟨x,hx,rfl⟩ i
rw [homothety_affine f hf,sub_sub_cancel]
exact add_le_add (mul_nonneg (by linarith) (hx i)) (mul_le_mul_of_nonneg_left (hu i) ha) |>.trans' (by ring_nf; rfl)
omit [Fintype I] in
theorem relaxed_subset_image (f : I β†’ (Fin q β†’ ℝ) β†’ ℝ)
(hf : βˆ€ i x y (Ξ± Ξ² : ℝ),Ξ±+Ξ²=1 β†’ f i (Ξ± β€’ x+Ξ² β€’ y)=Ξ±*f i x+Ξ²*f i y)
(u : Fin q β†’ ℝ) (s Ξ³ : ℝ) (hs : 0<s) (hu : βˆ€ i,s ≀ f i u) (hg : 0 ≀ Ξ³) :
region f (-Ξ³) βŠ† AffineMap.homothety u (1+Ξ³/s) '' region f 0 := by
intro x hx
let r := 1+Ξ³/s
have hr : 0<r := by dsimp [r]; positivity
let z := AffineMap.homothety u (1/r) x
refine ⟨z,?_,?_⟩
Β· intro i
dsimp [z]
rw [homothety_affine f hf]
have hr1 : 1 ≀ r := by
dsimp [r]
have hh : 0 ≀ Ξ³/s := by positivity
linarith
have hcoef : 0 ≀ 1-1/r := by have := (div_le_one hr).mpr hr1; linarith
have h1 := mul_le_mul_of_nonneg_left (hx i) (show 0 ≀ 1/r by positivity)
have h2 := mul_le_mul_of_nonneg_left (hu i) hcoef
have he : (1/r)*(-Ξ³)+(1-1/r)*s=0 := by dsimp [r]; field_simp; ring
linarith only [h1,h2,he]
Β· ext j
simp only [z,AffineMap.homothety_apply,vadd_eq_add,vsub_eq_sub,Pi.add_apply,Pi.sub_apply,Pi.smul_apply,smul_eq_mul]
change r*((1/r*(x j-u j)+u j)-u j)+u j=x j
field_simp
ring
theorem homothety_volume (u : Fin q β†’ ℝ) (r : ℝ) (hr : 0 ≀ r) (S : Set (Fin q β†’ ℝ)) :
volume (AffineMap.homothety u r '' S)=ENNReal.ofReal (r^q)*volume S := by
rw [Measure.addHaar_image_homothety]
simp [abs_of_nonneg (pow_nonneg hr _)]
omit [Fintype I] in
theorem inner_volume (f : I β†’ (Fin q β†’ ℝ) β†’ ℝ)
(hf : βˆ€ i x y (Ξ± Ξ² : ℝ),Ξ±+Ξ²=1 β†’ f i (Ξ± β€’ x+Ξ² β€’ y)=Ξ±*f i x+Ξ²*f i y)
(u : Fin q β†’ ℝ) (s Ξ± : ℝ) (hu : βˆ€ i,s ≀ f i u)
(ha : 0 ≀ Ξ±) (ha1 : Ξ± ≀ 1) :
ENNReal.ofReal ((1-Ξ±)^q)*volume (region f 0) ≀ volume (region f (Ξ±*s)) := by
rw [← homothety_volume u (1-Ξ±) (by linarith)]
exact measure_mono (inner_image_subset f hf u s Ξ± hu ha ha1)
omit [Fintype I] in
theorem relaxed_volume (f : I β†’ (Fin q β†’ ℝ) β†’ ℝ)
(hf : βˆ€ i x y (Ξ± Ξ² : ℝ),Ξ±+Ξ²=1 β†’ f i (Ξ± β€’ x+Ξ² β€’ y)=Ξ±*f i x+Ξ²*f i y)
(u : Fin q β†’ ℝ) (s Ξ³ : ℝ) (hs : 0<s) (hu : βˆ€ i,s ≀ f i u) (hg : 0 ≀ Ξ³) :
volume (region f (-Ξ³)) ≀ ENNReal.ofReal (Real.exp ((q:ℝ)*Ξ³/s))*volume (region f 0) := by
have hh := measure_mono (ΞΌ:=volume) (relaxed_subset_image f hf u s Ξ³ hs hu hg)
rw [homothety_volume u (1+Ξ³/s) (by positivity)] at hh
apply hh.trans
gcongr
calc
(1+Ξ³/s)^q ≀ (Real.exp (Ξ³/s))^q := pow_le_pow_leftβ‚€ (by positivity) (by linarith only [Real.add_one_le_exp (Ξ³/s)]) q
_ = _ := by rw [← Real.exp_nat_mul]; congr 1; ring
end
end Contingency.Dense
open Set MeasureTheory
open scoped Pointwise BigOperators
namespace Contingency.Dense
noncomputable section
variable {a c q : β„•}
def constraints (e : Fin q ≃ Fin aΓ—Fin c) (R : Fin (a+1) β†’ ℝ) (P : Fin (c+1) β†’ ℝ)
(w : Fin a β†’ Fin c β†’ ℝ) (s : Fin (a+1)Γ—Fin (c+1)) (x : Fin q β†’ ℝ) : ℝ :=
normalized R P w (fun s => x (e.symm s)) s.1 s.2
theorem constraints_affine (e : Fin q ≃ Fin aΓ—Fin c) (R : Fin (a+1) β†’ ℝ) (P : Fin (c+1) β†’ ℝ)
(w : Fin a β†’ Fin c β†’ ℝ) (i) (x y : Fin q β†’ ℝ) (Ξ± Ξ² : ℝ) (hab : Ξ±+Ξ²=1) :
constraints e R P w i (Ξ± β€’ x+Ξ² β€’ y)=Ξ±*constraints e R P w i x+Ξ²*constraints e R P w i y :=
normalized_affine R P w _ _ Ξ± Ξ² hab _ _
theorem constraints_continuous (e : Fin q ≃ Fin aΓ—Fin c) (R : Fin (a+1) β†’ ℝ) (P : Fin (c+1) β†’ ℝ)
(w : Fin a β†’ Fin c β†’ ℝ) (i) : Continuous (constraints e R P w i) :=
(normalized_continuous R P w _ _).comp (continuous_pi fun coordinate => continuous_apply (e.symm coordinate))
theorem constraints_lipschitz (e : Fin q ≃ Fin aΓ—Fin c) (R : Fin (a+1) β†’ ℝ) (P : Fin (c+1) β†’ ℝ)
(w : Fin a β†’ Fin c β†’ ℝ) (B d : ℝ) (hB : 0<B) (hd : 0 ≀ d) (hdim : (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/B)
(x y : Fin q β†’ ℝ) (i) :
|constraints e R P w i x-constraints e R P w i y| ≀ d/B*β€–x-yβ€– := by
apply (normalized_lipschitz R P w B d hB hdim hR hP hRmax hPmax hw0 hw _ _ _ _).trans
apply mul_le_mul_of_nonneg_left _ (div_nonneg hd hB.le)
apply (pi_norm_le_iff_of_nonneg (norm_nonneg _)).mpr
intro s
exact norm_le_pi_norm (x-y) (e.symm s)
theorem region_bounded (e : Fin q ≃ Fin aΓ—Fin c) (R : Fin (a+1) β†’ ℝ) (P : Fin (c+1) β†’ ℝ)
(w : Fin a β†’ Fin c β†’ ℝ) (B : ℝ) (hB : 0<B)
(hR : βˆ€ i,0<R i) (hP : βˆ€ j,0<P j) (heq : (βˆ‘ i,R i)=βˆ‘ j,P j)
(hw : βˆ€ i j,scale R P i.castSucc j.castSucc/(2*B) ≀ w i j) :
region (constraints e R P w) 0 βŠ† Set.pi Set.univ (fun _ => Set.Icc 0 (2*B)) := by
intro x hx
have hh := polytope_bounded R P w B hB hR hP heq hw (fun s => x (e.symm s)) (fun i j => hx (i,j))
intro i _
simpa only [e.symm_apply_apply,Set.mem_Icc] using hh (e i)
theorem region_volume_finite (e : Fin q ≃ Fin aΓ—Fin c) (R : Fin (a+1) β†’ ℝ) (P : Fin (c+1) β†’ ℝ)
(w : Fin a β†’ Fin c β†’ ℝ) (B : ℝ) (hB : 0<B)
(hR : βˆ€ i,0<R i) (hP : βˆ€ j,0<P j) (heq : (βˆ‘ i,R i)=βˆ‘ j,P j)
(hw : βˆ€ i j,scale R P i.castSucc j.castSucc/(2*B) ≀ w i j) :
volume (region (constraints e R P w) 0)<⊀ := by
apply (measure_mono (region_bounded e R P w B hB hR hP heq hw)).trans_lt
exact (isCompact_univ_pi fun _ => isCompact_Icc).measure_lt_top
theorem region_interior (e : Fin q ≃ Fin aΓ—Fin c) (d : ℝ) (hd : 0<d)
(R : Fin (a+1) β†’ ℝ) (P : Fin (c+1) β†’ ℝ) (w : Fin a β†’ Fin c β†’ ℝ)
(hR : βˆ€ i,0<R i) (hP : βˆ€ j,0<P j) (heq : (βˆ‘ i,R i)=βˆ‘ j,P j)
(ha : (a+1:β„•) ≀ d) (hc : (c+1:β„•) ≀ d) (hw : βˆ€ i j,0<w i j) :
βˆƒ u : Fin q β†’ ℝ,βˆ€ i,1/(2*d) ≀ constraints e R P w i u := by
obtain ⟨u,hu⟩ := interior_point d hd R P w hR hP heq ha hc hw
refine ⟨fun i => u (e i),fun i => ?_⟩
simpa only [constraints,e.apply_symm_apply] using hu i.1 i.2
theorem inner_half_volume (f : (Fin (a+1)Γ—Fin (c+1)) β†’ (Fin q β†’ ℝ) β†’ ℝ)
(hf : βˆ€ i x y (Ξ± Ξ² : ℝ),Ξ±+Ξ²=1 β†’ f i (Ξ± β€’ x+Ξ² β€’ y)=Ξ±*f i x+Ξ²*f i y)
(d : ℝ) (hd : 2 ≀ d) (hq : (q:ℝ) ≀ d) (u : Fin q β†’ ℝ)
(hu : βˆ€ i,1/(2*d) ≀ f i u) :
(1/2:ENNReal)*volume (region f 0) ≀ volume (region f (2*d/d^8)) := by
have hd0 : 0<d := by linarith
let Ξ± := 4*d^2/d^8
have ha : 0 ≀ Ξ± := by dsimp [Ξ±]; positivity
have had : Ξ±*d ≀ 1/2 := by
have he : Ξ±*d=4/d^5 := by dsimp [Ξ±]; field_simp
rw [he]
apply (div_le_iffβ‚€ (by positivity)).mpr
have hp : (2:ℝ)^5 ≀ d^5 := pow_le_pow_leftβ‚€ (by norm_num) hd 5
norm_num at hp
linarith
have ha1 : Ξ± ≀ 1 := by nlinarith
have hpow : 1/2 ≀ (1-Ξ±)^q := by
have hh := one_add_mul_le_pow (a := -Ξ±) (by linarith) q
have hq' := mul_le_mul_of_nonneg_right hq ha
have he : 1+-Ξ±=1-Ξ± := by ring
rw [he] at hh
nlinarith only [hh,hq',had]
have hh := inner_volume f hf u (1/(2*d)) Ξ± hu ha ha1
have he : Ξ±*(1/(2*d))=2*d/d^8 := by dsimp [Ξ±]; field_simp; ring
rw [he] at hh
have hlo : (1/2:ENNReal) ≀ ENNReal.ofReal ((1-Ξ±)^q) := by
have ht := ENNReal.ofReal_le_ofReal hpow
simpa only [ENNReal.ofReal_div_of_pos (by norm_num : (0:ℝ)<2),ENNReal.ofReal_one,ENNReal.ofReal_ofNat] using ht
calc
_ ≀ ENNReal.ofReal ((1-Ξ±)^q)*volume (region f 0) := by gcongr
_ ≀ _ := hh
theorem relaxed_volume_dense (f : (Fin (a+1)Γ—Fin (c+1)) β†’ (Fin q β†’ ℝ) β†’ ℝ)
(hf : βˆ€ i x y (Ξ± Ξ² : ℝ),Ξ±+Ξ²=1 β†’ f i (Ξ± β€’ x+Ξ² β€’ y)=Ξ±*f i x+Ξ²*f i y)
(d : ℝ) (hd : 0<d) (hq : (q:ℝ) ≀ d) (u : Fin q β†’ ℝ)
(hu : βˆ€ i,1/(2*d) ≀ f i u) (Ξ³ : ℝ) (hg : 0 ≀ Ξ³) :
volume (region f (-Ξ³)) ≀ ENNReal.ofReal (Real.exp (2*d^2*Ξ³))*volume (region f 0) := by
apply (relaxed_volume f hf u (1/(2*d)) Ξ³ (by positivity) hu hg).trans
gcongr
have he : (q:ℝ)*Ξ³/(1/(2*d))=(q:ℝ)*(2*d*Ξ³) := by field_simp
rw [he]
have hh := mul_le_mul_of_nonneg_right hq (show 0 ≀ 2*d*Ξ³ by positivity)
nlinarith only [hh]
end
end Contingency.Dense
open Set MeasureTheory
open scoped BigOperators
namespace Contingency.Dense
noncomputable section
variable {q : β„•}
theorem half_times_four_thirds : (1/2:ENNReal)*(4/3)=2/3 := by
have h : (1/2:NNReal)*(4/3)=2/3 := by norm_num
have hh := congrArg (fun x : NNReal => (x : ENNReal)) h
simpa only [ENNReal.coe_mul,ENNReal.coe_div (by norm_num : (2:NNReal)β‰ 0),ENNReal.coe_div (by norm_num : (3:NNReal)β‰ 0),ENNReal.coe_one,ENNReal.coe_ofNat] using hh
theorem geometric_constant : (1-(2/3:ENNReal))⁻¹*(4/3)=4 := by
have hs : (1-(2/3:NNReal))=1/3 := by
apply NNReal.eq
rw [NNReal.coe_sub (by norm_num [div_le_one (by norm_num : (0:NNReal)<3)] : (2/3:NNReal) ≀ 1)]
norm_num
have h : (1-(2/3:NNReal))⁻¹*(4/3)=4 := by rw [hs]; norm_num
have hh := congrArg (fun x : NNReal => (x : ENNReal)) h
simpa only [ENNReal.coe_mul,ENNReal.coe_inv (show (1-(2/3:NNReal))β‰ 0 by rw [hs]; norm_num),ENNReal.coe_sub,ENNReal.coe_div (by norm_num : (3:NNReal)β‰ 0),ENNReal.coe_one,ENNReal.coe_ofNat] using hh
theorem decay_nat (j : β„•) : ENNReal.ofReal ((2:ℝ)^(-(j:ℝ)))=(1/2:ENNReal)^j := by
rw [Real.rpow_neg (by norm_num),Real.rpow_natCast,← inv_pow,ENNReal.ofReal_pow (by positivity)]
rw [ENNReal.ofReal_inv_of_pos (by norm_num : (0:ℝ)<2)]
norm_num
theorem density_layer_bound (p : (Fin q β†’ ℝ) β†’ ℝ) (hp : Measurable p)
(hp0 : βˆ€ x,0 ≀ p x) (A : ℝ) (hA : 0<A) (S : Set (Fin q β†’ ℝ))
(V : ENNReal) (hvol : βˆ€ j : β„•,
volume ({x | p x < ((j:ℝ)+1)/A} ∩ S) ≀ (4/3:ENNReal)^(j+1)*V) :
(∫⁻ x in S,ENNReal.ofReal ((2:ℝ)^(-A*p x))) ≀ 4*V := by
let T (j : β„•) := {x | p x < ((j:ℝ)+1)/A}
have hm (j : β„•) : MeasurableSet (T j) := measurableSet_lt hp measurable_const
let f (j : β„•) := (T j).indicator (fun _ => (1/2:ENNReal)^j)
have hf (j : β„•) : Measurable (f j) := measurable_const.indicator (hm j)
have hpoint (x : Fin q β†’ ℝ) : ENNReal.ofReal ((2:ℝ)^(-A*p x)) ≀ βˆ‘' j,f j x := by
let j := ⌊A*p xβŒ‹β‚Š
have hj : x∈T j := by
apply (lt_div_iffβ‚€ hA).mpr
simpa only [mul_comm] using Nat.lt_floor_add_one (A*p x)
apply le_trans _ (ENNReal.le_tsum j)
rw [show f j x=(1/2:ENNReal)^j from Set.indicator_of_mem hj _]
rw [← decay_nat]
apply ENNReal.ofReal_le_ofReal
apply Real.rpow_le_rpow_of_exponent_le (by norm_num)
have hh := Nat.floor_le (mul_nonneg hA.le (hp0 x))
dsimp [j]
linarith only [hh]
calc
_ ≀ ∫⁻ x in S,βˆ‘' j,f j x := lintegral_mono hpoint
_ = βˆ‘' j, (1/2:ENNReal)^j*volume (T j∩S) := by
rw [lintegral_tsum fun j => (hf j).aemeasurable]
congr 1
funext j
rw [lintegral_indicator (hm j),lintegral_const,Measure.restrict_apply MeasurableSet.univ]
rw [Set.univ_inter,Measure.restrict_apply (hm j)]
_ ≀ βˆ‘' j,(1/2:ENNReal)^j*((4/3:ENNReal)^(j+1)*V) :=
ENNReal.tsum_le_tsum fun j => by gcongr; exact hvol j
_ = 4*V := by
have hterm (j : β„•) : (1/2:ENNReal)^j*((4/3:ENNReal)^(j+1)*V)=
(2/3:ENNReal)^j*((4/3)*V) := by
rw [pow_succ]
calc
_ = ((1/2:ENNReal)*(4/3))^j*((4/3)*V) := by rw [mul_pow]; ring
_ = _ := by rw [half_times_four_thirds]
simp_rw [hterm]
rw [ENNReal.tsum_mul_right,ENNReal.tsum_geometric]
rw [← mul_assoc,geometric_constant]
theorem exp_quarter_bound (x : ℝ) (hx : x ≀ 1/4) : Real.exp x ≀ 4/3 := by
apply (Real.exp_le_exp.mpr hx).trans
have hh := Real.exp_bound_div_one_sub_of_interval (x := 1/4) (by norm_num) (by norm_num)
norm_num at hh ⊒
exact hh
theorem dense_exponent_layer (d : ℝ) (hd : 4 ≀ d) (j : β„•) :
Real.exp (2*d^2*(d/d^8+((j:ℝ)+1)/d^4)) ≀ (4/3:ℝ)^(j+1) := by
have hd0 : 0<d := by linarith
let Ξ± := 2/d^2
let Ξ² := 2/d^5
have hΞ± : Ξ± ≀ 1/8 := by
dsimp [Ξ±]
apply (div_le_iffβ‚€ (by positivity)).mpr
nlinarith [sq_nonneg (d-4)]
have hΞ² : Ξ² ≀ 1/8 := by
dsimp [Ξ²]
apply (div_le_iffβ‚€ (by positivity)).mpr
have hh := pow_le_pow_leftβ‚€ (by norm_num : (0:ℝ) ≀ 4) hd 5
norm_num at hh
linarith
have he : 2*d^2*(d/d^8+((j:ℝ)+1)/d^4)=Ξ²+((j:ℝ)+1)*Ξ± := by
dsimp [Ξ±,Ξ²]
field_simp
have hΞ²0 : 0 ≀ Ξ² := by dsimp [Ξ²]; positivity
calc
_ = Real.exp (Ξ²+((j:ℝ)+1)*Ξ±) := by rw [he]
_ ≀ Real.exp (((j:ℝ)+1)*(Ξ±+Ξ²)) := by
apply Real.exp_le_exp.mpr
nlinarith only [mul_nonneg (show 0 ≀ (j:ℝ) by positivity) hΞ²0]
_ = Real.exp (Ξ±+Ξ²)^(j+1) := by rw [← Real.exp_nat_mul]; congr 1; push_cast; ring
_ ≀ _ := pow_le_pow_leftβ‚€ (Real.exp_pos _).le (exp_quarter_bound _ (by linarith)) _
end
end Contingency.Dense
open Set
namespace Contingency.Grid
noncomputable section
variable {q : β„•}
def inside (v : Fin q β†’ β„•) (x : Fin q β†’ ℝ) : Prop :=
βˆ€ i,(v i:ℝ)<x i ∧ x i<(v i:ℝ)+1
def path (v w : Fin q β†’ β„•) (n : β„•) : Fin q β†’ β„• :=
fun i => if i.val<n then w i else v i
@[simp] theorem path_zero (v w : Fin q β†’ β„•) : path v w 0=v := by ext i; simp [path]
@[simp] theorem path_end (v w : Fin q β†’ β„•) : path v w q=w := by ext i; simp [path,i.isLt]
theorem exists_label_step {Ξ± : Type*} (f : β„• β†’ Ξ±) (n : β„•) (h : f 0 β‰  f n) :
βˆƒ k,k<n ∧ f k β‰  f (k+1) := by
induction n with
| zero => exact (h rfl).elim
| succ n ih =>
by_cases hh : f 0=f n
· exact ⟨n,Nat.lt_succ_self n,fun he => h (hh.trans he)⟩
· obtain ⟨k,hk,he⟩ := ih hh
exact ⟨k,hk.trans (Nat.lt_succ_self n),he⟩
theorem path_step (v w : Fin q β†’ β„•) (k : Fin q) :
path v w (k.val+1)=Function.update (path v w k.val) k (w k) := by
ext i
by_cases hi : i=k
Β· subst i; simp [path]
Β· have hh : i.val β‰  k.val := fun h => hi (Fin.ext h)
simp only [path,Function.update_of_ne hi]
split_ifs <;> omega
def neighbors (v w : Fin q β†’ β„•) (i : Fin q) : Prop :=
(v i+1=w i ∨ w i+1=v i) ∧ βˆ€ j,j β‰  i β†’ v j=w j
def face (v w : Fin q β†’ β„•) (i : Fin q) : Set (Fin q β†’ ℝ) :=
{z | z i=(max (v i) (w i):β„•) ∧ βˆ€ j,j β‰  i β†’ (v j:ℝ) ≀ z j ∧ z j ≀ (v j:ℝ)+1}
theorem adjacent_of_close (v w : β„•) (x z r : ℝ)
(hx : (v:ℝ)<x ∧ x<(v:ℝ)+1) (hz : (w:ℝ)<z ∧ z<(w:ℝ)+1)
(hclose : |x-z|<r) (hr : r ≀ 1) (hne : v β‰  w) :
v+1=w ∨ w+1=v := by
have hc := abs_lt.mp hclose
have hvw : (v:ℝ)<(w:ℝ)+2 := by linarith
have hwv : (w:ℝ)<(v:ℝ)+2 := by linarith
have hvw' : v<w+2 := by exact_mod_cast hvw
have hwv' : w<v+2 := by exact_mod_cast hwv
omega
theorem cut_face_close (v w : Fin q β†’ β„•) (label : (Fin q β†’ β„•) β†’ Bool)
(hl : label v β‰  label w) (x z : Fin q β†’ ℝ) (hx : inside v x) (hz : inside w z)
(r : ℝ) (hr : r ≀ 1) (hc : βˆ€ i,|x i-z i|<r) :
βˆƒ u u' : Fin q β†’ β„•,βˆƒ i : Fin q,
neighbors u u' i ∧ label u β‰  label u' ∧
(βˆ€ j,u j=v j ∨ u j=w j) ∧ (βˆ€ j,u' j=v j ∨ u' j=w j) ∧
βˆƒ p∈face u u' i,βˆ€ j,|p j-z j|<r := by
have hp : label (path v w 0) β‰  label (path v w q) := by simpa using hl
obtain ⟨k,hk,hstep⟩ := exists_label_step (fun n => label (path v w n)) q hp
let i : Fin q := ⟨k,hk⟩
have hiv : path v w k i=v i := by simp [path,i]
have hiw : path v w (k+1) i=w i := by simp [path,i]
have hj (j : Fin q) (hji : j β‰  i) : path v w k j=path v w (k+1) j := by
have hh := congrFun (path_step v w i) j
simpa only [i,Function.update_of_ne hji] using hh.symm
have hne : v i β‰  w i := by
intro hh
apply hstep
congr 1
ext j
by_cases hji : j=i
Β· subst j; rw [hiv,hiw,hh]
Β· exact hj j hji
have hn := adjacent_of_close (v i) (w i) (x i) (z i) r (hx i) (hz i) (hc i) hr hne
let p : Fin q β†’ ℝ := fun j => if j=i then (max (v i) (w i):β„•) else if j.val<k then z j else x j
refine ⟨path v w k,path v w (k+1),i,?_,hstep,?_,?_,p,?_,?_⟩
· exact ⟨by simpa only [hiv,hiw] using hn,hj⟩
Β· intro j; simp only [path]; split_ifs <;> simp
Β· intro j; simp only [path]; split_ifs <;> simp
Β· constructor
Β· simp [p,hiv,hiw]
Β· intro j hji
simp only [p,ite_eq_right hji,path]
split_ifs with h
· exact ⟨(hz j).1.le,(hz j).2.le⟩
· exact ⟨(hx j).1.le,(hx j).2.le⟩
Β· intro j
by_cases hji : j=i
Β· subst j
simp only [p,ite_eq_left rfl]
rcases hn with hh | hh
Β· have hle : v i ≀ w i := by omega
rw [max_eq_right hle,abs_of_nonpos (by linarith [(hz i).1] : (w i:ℝ)-z i ≀ 0)]
have hc' := (abs_lt.mp (hc i)).1
have he : (v i:ℝ)+1=(w i:ℝ) := by exact_mod_cast hh
linarith [(hx i).2]
Β· have hle : w i ≀ v i := by omega
have he : (w i:ℝ)+1=(v i:ℝ) := by exact_mod_cast hh
have hnz : 0 ≀ (v i:ℝ)-z i := by linarith [(hz i).2]
rw [max_eq_left hle,abs_of_nonneg hnz]
have hc' := (abs_lt.mp (hc i)).2
linarith [(hx i).1]
Β· simp only [p,ite_eq_right hji]
split_ifs
Β· simpa only [sub_self,abs_zero] using (lt_of_le_of_lt (abs_nonneg (x j-z j)) (hc j))
Β· exact hc j
end
end Contingency.Grid
open Set MeasureTheory
namespace Contingency.Grid
noncomputable section
variable {q K : β„•}
abbrev Vertex (q K : β„•) := Fin q β†’ Fin K
def corner (v : Vertex q K) : Fin q β†’ β„• := fun i => v i
def bin (v : Vertex q K) : Interpolation.OpenBox q :=
⟨fun i => v i,fun i => (v i:ℝ)+1⟩
@[simp] theorem mem_bin (v : Vertex q K) (x : Fin q β†’ ℝ) : x∈(bin v).carrier ↔ inside (corner v) x := by
simp [bin,Interpolation.OpenBox.carrier,inside,corner]
def cube (q K : β„•) : Interpolation.OpenBox q := ⟨fun _ => 0,fun _ => K⟩
@[simp] theorem mem_cube (x : Fin q β†’ ℝ) : x∈(cube q K).carrier ↔ βˆ€ i,0<x i ∧ x i<(K:ℝ) := by
simp [cube,Interpolation.OpenBox.carrier]
def boxes (V : Finset (Vertex q K)) : Finset (Interpolation.OpenBox q) := by classical exact V.image bin
@[simp] theorem mem_boxes (V : Finset (Vertex q K)) (x : Fin q β†’ ℝ) :
x∈Interpolation.boxUnion (boxes V) ↔ βˆƒ v∈V,inside (corner v) x := by
classical
simp [Interpolation.boxUnion,boxes,mem_bin]
theorem bins_subset_cube (V : Finset (Vertex q K)) : Interpolation.boxUnion (boxes V) βŠ† (cube q K).carrier := by
intro x hx
obtain ⟨v,_,hv⟩ := (mem_boxes V x).mp hx
apply (mem_cube x).mpr
intro i
have hh : (v i:ℝ)+1 ≀ (K:ℝ) := by exact_mod_cast (v i).isLt
exact ⟨lt_of_le_of_lt (Nat.cast_nonneg _) (hv i).1,lt_of_lt_of_le (hv i).2 hh⟩
theorem bin_unique (v w : Vertex q K) (x : Fin q β†’ ℝ)
(hv : inside (corner v) x) (hw : inside (corner w) x) : v=w := by
ext i
apply le_antisymm
Β· by_contra hn
have hn' : (w i:β„•)+1 ≀ (v i:β„•) := by omega
have hh : (w i:ℝ)+1 ≀ (v i:ℝ) := by exact_mod_cast hn'
have h1 := (hv i).1; have h2 := (hw i).2
dsimp [corner] at h1 h2
linarith
Β· by_contra hn
have hn' : (v i:β„•)+1 ≀ (w i:β„•) := by omega
have hh : (v i:ℝ)+1 ≀ (w i:ℝ) := by exact_mod_cast hn'
have h1 := (hw i).1; have h2 := (hv i).2
dsimp [corner] at h1 h2
linarith
theorem bins_disjoint : Pairwise (fun v w : Vertex q K => Disjoint (bin v).carrier (bin w).carrier) := by
intro v w hne
apply Set.disjoint_left.mpr
intro x hx hy
exact hne (bin_unique v w x ((mem_bin v x).mp hx) ((mem_bin w x).mp hy))
theorem ae_no_grid : βˆ€α΅ x : Fin q β†’ ℝ βˆ‚volume,βˆ€ i : Fin q,βˆ€ n : β„•,x i β‰  (n:ℝ) := by
apply ae_all_iff.mpr
intro i
apply ae_all_iff.mpr
intro n
exact Measure.ae_eval_ne (fun _ : Fin q => (volume : Measure ℝ)) i (n:ℝ)
theorem exists_bin (x : Fin q β†’ ℝ) (hx : x∈(cube q K).carrier)
(hgrid : βˆ€ i : Fin q,βˆ€ n : β„•,x i β‰  (n:ℝ)) :
βˆƒ v : Vertex q K,inside (corner v) x := by
have hc := (mem_cube x).mp hx
have hf (i : Fin q) : ⌊x iβŒ‹β‚Š<K := by
have hh := (Nat.floor_le (hc i).1.le).trans_lt (hc i).2
exact_mod_cast hh
let v : Vertex q K := fun i => ⟨⌊x iβŒ‹β‚Š,hf i⟩
refine ⟨v,fun i => ⟨?_,?_⟩⟩
Β· exact lt_of_le_of_ne (Nat.floor_le (hc i).1.le) (Ne.symm (hgrid i _))
Β· exact Nat.lt_floor_add_one (x i)
theorem cube_ae_union : Interpolation.boxUnion (boxes (Finset.univ : Finset (Vertex q K))) =ᡐ[volume]
(cube q K).carrier := by
filter_upwards [ae_no_grid (q:=q)] with x hx
apply propext
constructor
Β· intro hx
exact bins_subset_cube (Finset.univ : Finset (Vertex q K)) hx
Β· intro hc
obtain ⟨v,hv⟩ := exists_bin x hc hx
exact (mem_boxes _ x).mpr ⟨v,Finset.mem_univ _,hv⟩
def faceBox (v w : Vertex q K) (i : Fin q) (r : ℝ) : Interpolation.OpenBox q :=
⟨fun j => if j=i then (max (v i:β„•) (w i:β„•):β„•)-r else (v j:ℝ)-r,
fun j => if j=i then (max (v i:β„•) (w i:β„•):β„•)+r else (v j:ℝ)+1+r⟩
theorem mem_faceBox (v w : Vertex q K) (i : Fin q) (r : ℝ) (p z : Fin q β†’ ℝ)
(hp : p∈face (corner v) (corner w) i) (hc : βˆ€ j,|p j-z j|<r) :
z∈(faceBox v w i r).carrier := by
intro j _
have hh := abs_lt.mp (hc j)
by_cases hj : j=i
Β· subst j
simp only [faceBox,Set.mem_Ioo,ite_true]
have he := hp.1
dsimp [corner] at he
constructor <;> linarith
Β· simp only [faceBox,ite_eq_right hj]
have he := hp.2 j hj
dsimp [corner] at he
constructor <;> linarith
theorem bounded_cut_face (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) :
βˆƒ u u' : Vertex q K,βˆƒ i : Fin q,neighbors (corner u) (corner u') i ∧
(u∈V ∧ u'βˆ‰V ∨ uβˆ‰V ∧ u'∈V) ∧ z∈(faceBox u u' i r).carrier := by
classical
let lift (a : Fin q β†’ β„•) (ha : βˆ€ i,a i<K) : Vertex q K := fun i => ⟨a i,ha i⟩
let label (a : Fin q β†’ β„•) : Bool := if ha : βˆ€ i,a i<K then decide (lift a ha∈V) else false
have hvb : βˆ€ i,corner v i<K := fun i => (v i).isLt
have hwb : βˆ€ i,corner w i<K := fun i => (w i).isLt
have hl : label (corner v) β‰  label (corner w) := by simp [label,lift,corner,hv,hw]
obtain ⟨u,u',i,hn,hl',hu,hu',p,hp,hclose⟩ := cut_face_close (corner v) (corner w) label hl x z hx hz r hr hc
have hub : βˆ€ j,u j<K := fun j => by rcases hu j with h | h <;> rw [h]; exact hvb j; exact hwb j
have hu'b : βˆ€ j,u' j<K := fun j => by rcases hu' j with h | h <;> rw [h]; exact hvb j; exact hwb j
refine ⟨lift u hub,lift u' hu'b,i,hn,?_,?_⟩
Β· simp only [label,dite_eq_left hub,dite_eq_left hu'b] at hl'
by_cases h : lift u hub∈V
· exact Or.inl ⟨h,fun h' => hl' (by simp [h,h'])⟩
· exact Or.inr ⟨h,by by_contra h'; exact hl' (by simp [h,h'])⟩
Β· exact mem_faceBox _ _ _ _ p z hp hclose
end
end Contingency.Grid
end
end OAI