Download data/lean/OAI/Probability/SKBarriers/Dynamics/GridThreshold.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 5.8 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/SKBarriers/Dynamics/GridThreshold.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/SKBarriers/Dynamics/GridThreshold.lean
-
curl -L -o GridThreshold.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/SKBarriers/Dynamics/GridThreshold.lean
5.8 kB
| import Mathlib | |
| import OAI.Probability.SKBarriers.SpinGlass.FiniteLaw | |
| namespace OAI | |
| section | |
| noncomputable section | |
| open scoped BigOperators | |
| open Classical MeasureTheory Set | |
| namespace SK.Analytic | |
| namespace FiniteLaw | |
| def uniformFin (n : β) (hn : 0 < n) : FiniteLaw (Fin n) where | |
| weight _ := 1/(n:β) | |
| nonneg _ := by positivity | |
| sum_one := by | |
| simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] | |
| field_simp | |
| theorem uniformFin_prob (n : β) (hn : 0 < n) (E : Fin n β Prop) : | |
| (uniformFin n hn).prob E=(Finset.univ.filter E).card/(n:β) := by | |
| simp only [prob,expect,uniformFin,β Finset.mul_sum] | |
| rw [Finset.sum_boole] | |
| ring | |
| theorem markov {n : β} (P : FiniteLaw (Fin n)) (f : Fin n β β) (hf : β x, 0 β€ f x) | |
| (c : β) (_hc : 0 < c) : c*P.prob (fun x => c < f x) β€ P.expect f := by | |
| rw [prob,β expect_const_mul] | |
| apply expect_mono | |
| intro x | |
| split_ifs with h | |
| Β· simpa only [mul_one] using h.le | |
| Β· simpa only [mul_zero] using hf x | |
| end FiniteLaw | |
| def thresholdGrid (n : β) (a Ο : β) (i : Fin n) : β := a+Ο*(i:β)/(n:β) | |
| theorem thresholdGrid_mem {n : β} (hn : 0 < n) {Ο : β} (hΟ : 0 < Ο) | |
| (a : β) (i : Fin n) : thresholdGrid n a Ο i β Icc a (a+Ο) := by | |
| have hnR : (0:β)<n := by exact_mod_cast hn | |
| have hi : (i:β)<n := by exact_mod_cast i.isLt | |
| unfold thresholdGrid | |
| constructor | |
| Β· have : 0 β€ Ο*(i:β)/(n:β) := by positivity | |
| linarith only [this] | |
| Β· have : Ο*(i:β)/(n:β) β€ Ο := (div_le_iffβ hnR).mpr (by gcongr) | |
| linarith only [this] | |
| theorem thresholdGrid_count {n : β} (hn : 0 < n) {Ο w : β} (hΟ : 0 < Ο) (hw : 0 β€ w) | |
| (a x : β) : | |
| ((Finset.univ.filter (fun i : Fin n => |thresholdGrid n a Ο i-x| β€ w)).card:β) β€ | |
| 2*w*(n:β)/Ο+1 := by | |
| let S := Finset.univ.filter (fun i : Fin n => |thresholdGrid n a Ο i-x| β€ w) | |
| have hnR : (0:β)<n := by exact_mod_cast hn | |
| by_cases hs : S.Nonempty | |
| Β· let i := S.min' hs | |
| let j := S.max' hs | |
| have hi : iβS := Finset.min'_mem S hs | |
| have hj : jβS := Finset.max'_mem S hs | |
| have hij : iβ€j := Finset.min'_le S j hj | |
| have hcard : S.card β€ (j:β)+1-(i:β) := by | |
| rw [β Fin.card_Icc] | |
| apply Finset.card_le_card | |
| intro z hz | |
| exact Finset.mem_Icc.mpr β¨Finset.min'_le S z hz,Finset.le_max' S z hzβ© | |
| have hcard' : (S.card:β) β€ (j:β)-(i:β)+1 := by | |
| have hnat : (i:β)β€(j:β)+1 := by omega | |
| have hc : (S.card:β) β€ (((j:β)+1-(i:β):β):β) := by exact_mod_cast hcard | |
| rw [Nat.cast_sub hnat,Nat.cast_add,Nat.cast_one] at hc | |
| linarith only [hc] | |
| have hdi := abs_le.mp ((Finset.mem_filter.mp hi).2) | |
| have hdj := abs_le.mp ((Finset.mem_filter.mp hj).2) | |
| have hgap : Ο*((j:β)-(i:β)) β€ 2*w*(n:β) := by | |
| have H : thresholdGrid n a Ο j-thresholdGrid n a Ο i β€ 2*w := by linarith only [hdi.1,hdj.2] | |
| have HH : thresholdGrid n a Ο j-thresholdGrid n a Ο i=Ο*((j:β)-(i:β))/(n:β) := by | |
| unfold thresholdGrid | |
| ring | |
| rw [HH,div_le_iffβ hnR] at H | |
| exact H | |
| have hgap' : (j:β)-(i:β) β€ 2*w*(n:β)/Ο := (le_div_iffβ hΟ).mpr (by nlinarith only [hgap]) | |
| exact hcard'.trans (by linarith only [hgap']) | |
| Β· have he : S=β := Finset.not_nonempty_iff_eq_empty.mp hs | |
| change (S.card:β)β€_ | |
| rw [he,Finset.card_empty,Nat.cast_zero] | |
| positivity | |
| theorem thresholdGrid_window {n : β} (hn : 0 < n) {Ο w : β} (hΟ : 0 < Ο) (hw : 0 β€ w) | |
| (a x : β) : | |
| (FiniteLaw.uniformFin n hn).prob (fun i => |thresholdGrid n a Ο i-x| β€ w) β€ 2*w/Ο+1/(n:β) := by | |
| rw [FiniteLaw.uniformFin_prob] | |
| have h := div_le_div_of_nonneg_right (thresholdGrid_count hn hΟ hw a x) (by positivity : (0:β)β€n) | |
| refine h.trans_eq ?_ | |
| have hnR : (n:β)β 0 := by exact_mod_cast hn.ne' | |
| field_simp | |
| theorem thresholdGrid_mass_expect {n : β} (hn : 0 < n) (ΞΌ : ProbabilityMeasure β) | |
| {Ο h : β} (hΟ : 0 < Ο) (hh : 0 β€ h) (a : β) : | |
| (FiniteLaw.uniformFin n hn).expect (fun i => (ΞΌ:Measure β).real | |
| (Icc (thresholdGrid n a Ο i-h) (thresholdGrid n a Ο i+h))) β€ 2*h/Ο+1/(n:β) := by | |
| let f (i : Fin n) := (Icc (thresholdGrid n a Ο i-h) (thresholdGrid n a Ο i+h)).indicator (fun _ : β => (1:β)) | |
| have hi (i : Fin n) : Integrable (f i) (ΞΌ:Measure β) := | |
| (integrable_const 1).indicator measurableSet_Icc | |
| have he : (FiniteLaw.uniformFin n hn).expect (fun i => (ΞΌ:Measure β).real | |
| (Icc (thresholdGrid n a Ο i-h) (thresholdGrid n a Ο i+h))) = | |
| β« x, (1/(n:β))*β i, f i x β(ΞΌ:Measure β) := by | |
| unfold FiniteLaw.expect FiniteLaw.uniformFin | |
| rw [integral_const_mul,integral_finsetSum _ (fun i _ => hi i),Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| dsimp only [f] | |
| rw [integral_indicator_const (1:β) measurableSet_Icc] | |
| simp only [smul_eq_mul,mul_one] | |
| rw [he] | |
| have hb (x : β) : (1/(n:β))*β i, f i x β€ 2*h/Ο+1/(n:β) := by | |
| have H := thresholdGrid_window hn hΟ hh a x | |
| change (1/(n:β))*(β i, f i x)β€_ | |
| convert H using 1 | |
| unfold FiniteLaw.prob FiniteLaw.expect FiniteLaw.uniformFin | |
| rw [β Finset.mul_sum] | |
| congr 1 | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| have he : xβIcc (thresholdGrid n a Ο i-h) (thresholdGrid n a Ο i+h) β |thresholdGrid n a Ο i-x|β€h := by | |
| rw [Set.mem_Icc,abs_le] | |
| constructor <;> intro H <;> constructor <;> linarith only [H.1,H.2] | |
| simp only [f,Set.indicator_apply,he] | |
| exact (integral_mono_of_nonneg (ae_of_all _ (fun x => by | |
| apply mul_nonneg (by positivity) | |
| exact Finset.sum_nonneg (fun i _ => Set.indicator_nonneg (fun _ _ => zero_le_one) x))) | |
| (integrable_const _) (ae_of_all _ hb)).trans_eq (by simp) | |
| end SK.Analytic | |
| end | |
| end | |
| end OAI | |