Download lean/OAI/Probability/CriticalPercolation/ProductMeasure/Density.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 7.07 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Probability/CriticalPercolation/ProductMeasure/Density.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Probability/CriticalPercolation/ProductMeasure/Density.lean
-
curl -L -o Density.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Probability/CriticalPercolation/ProductMeasure/Density.lean
7.07 kB
| import Mathlib | |
| namespace OAI | |
| section | |
| section | |
| open Set MeasureTheory ProbabilityTheory | |
| open scoped BigOperators | |
| open Set | |
| namespace CriticalPercolation.FiniteProduct | |
| variable {E A : Type*} [Fintype E] [Fintype A] | |
| noncomputable def density (w : E → A → ℝ) (ω : E → A) : ℝ := ∏ e, w e (ω e) | |
| noncomputable def expect (w : E → A → ℝ) (f : (E → A) → ℝ) : ℝ := by | |
| classical | |
| exact ∑ ω, density w ω * f ω | |
| omit [Fintype A] in | |
| lemma density_nonneg {w : E → A → ℝ} (h : ∀ e a, 0 ≤ w e a) (ω : E → A) : | |
| 0 ≤ density w ω := Finset.prod_nonneg fun e _ => h e (ω e) | |
| lemma sum_density [DecidableEq E] (w : E → A → ℝ) (h : ∀ e, ∑ a, w e a = 1) : | |
| ∑ ω, density w ω = 1 := by | |
| classical | |
| unfold density | |
| rw [← Fintype.prod_sum] | |
| simp [h] | |
| lemma expect_const (w : E → A → ℝ) (h : ∀ e, ∑ a, w e a = 1) (c : ℝ) : | |
| expect w (fun _ => c) = c := by | |
| classical | |
| rw [expect, ← Finset.sum_mul, sum_density w h, one_mul] | |
| lemma expect_add (w : E → A → ℝ) (f g : (E → A) → ℝ) : | |
| expect w (fun ω => f ω + g ω) = expect w f + expect w g := by | |
| classical | |
| simp [expect, mul_add, Finset.sum_add_distrib] | |
| lemma expect_sub (w : E → A → ℝ) (f g : (E → A) → ℝ) : | |
| expect w (fun ω => f ω - g ω) = expect w f - expect w g := by | |
| classical | |
| simp [expect, mul_sub, Finset.sum_sub_distrib] | |
| lemma expect_mono {w : E → A → ℝ} (hw : ∀ e a, 0 ≤ w e a) | |
| {f g : (E → A) → ℝ} (hfg : ∀ ω, f ω ≤ g ω) : expect w f ≤ expect w g := by | |
| classical | |
| exact Finset.sum_le_sum fun ω _ => mul_le_mul_of_nonneg_left (hfg ω) (density_nonneg hw ω) | |
| omit [Fintype A] in | |
| lemma density_split (w : E → A → ℝ) (P : E → Prop) [DecidablePred P] (ω : E → A) : | |
| density w ω = | |
| density (fun e : {e // P e} => w e) (fun e => ω e) * | |
| density (fun e : {e // ¬ P e} => w e) (fun e => ω e) := by | |
| exact (Fintype.prod_subtype_mul_prod_subtype P (fun e => w e (ω e))).symm | |
| lemma expect_split (w : E → A → ℝ) (P : E → Prop) [DecidablePred P] | |
| (f : (E → A) → ℝ) : | |
| expect w f = | |
| expect (fun e : {e // P e} => w e) (fun a => | |
| expect (fun e : {e // ¬ P e} => w e) (fun b => | |
| f ((Equiv.piEquivPiSubtypeProd P (fun _ => A)).symm (a, b)))) := by | |
| classical | |
| let e := Equiv.piEquivPiSubtypeProd P (fun _ => A) | |
| unfold expect | |
| rw [← e.symm.sum_comp] | |
| rw [Fintype.sum_prod_type] | |
| apply Finset.sum_congr (by ext; simp) | |
| intro a _ | |
| rw [Finset.mul_sum] | |
| apply Finset.sum_congr (by ext; simp) | |
| intro b _ | |
| have h₁ : (fun i : {e // P e} => e.symm (a, b) i) = a := | |
| congrArg Prod.fst (e.apply_symm_apply (a, b)) | |
| have h₂ : (fun i : {e // ¬ P e} => e.symm (a, b) i) = b := | |
| congrArg Prod.snd (e.apply_symm_apply (a, b)) | |
| rw [density_split w P, h₁, h₂, mul_assoc] | |
| lemma expect_factor (w : E → A → ℝ) (P : E → Prop) [DecidablePred P] | |
| (f : ({e // P e} → A) → ℝ) (g : ({e // ¬ P e} → A) → ℝ) : | |
| expect w (fun ω => f (fun e => ω e) * g (fun e => ω e)) = | |
| expect (fun e : {e // P e} => w e) f * | |
| expect (fun e : {e // ¬ P e} => w e) g := by | |
| classical | |
| rw [expect_split w P] | |
| have h₁ : ∀ (a : {e // P e} → A) (b : {e // ¬ P e} → A), | |
| (fun i : {e // P e} => | |
| (Equiv.piEquivPiSubtypeProd P (fun _ => A)).symm (a, b) i) = a := by | |
| intro a b | |
| exact congrArg Prod.fst ((Equiv.piEquivPiSubtypeProd P (fun _ => A)).apply_symm_apply (a, b)) | |
| have h₂ : ∀ (a : {e // P e} → A) (b : {e // ¬ P e} → A), | |
| (fun i : {e // ¬ P e} => | |
| (Equiv.piEquivPiSubtypeProd P (fun _ => A)).symm (a, b) i) = b := by | |
| intro a b | |
| exact congrArg Prod.snd ((Equiv.piEquivPiSubtypeProd P (fun _ => A)).apply_symm_apply (a, b)) | |
| simp_rw [h₁, h₂] | |
| unfold expect | |
| rw [Finset.sum_mul] | |
| apply Finset.sum_congr (by ext; simp) | |
| intro a _ | |
| rw [Finset.mul_sum, Finset.mul_sum] | |
| apply Finset.sum_congr (by ext; simp) | |
| intro b _ | |
| ring | |
| lemma expect_indep (w : E → A → ℝ) (hw : ∀ e, ∑ a, w e a = 1) | |
| (S : Set E) {f g : (E → A) → ℝ} | |
| (hf : DependsOn f S) (hg : DependsOn g Sᶜ) : | |
| expect w (fun ω => f ω * g ω) = expect w f * expect w g := by | |
| classical | |
| obtain ⟨f', rfl⟩ := dependsOn_iff_exists_comp.mp hf | |
| obtain ⟨g', rfl⟩ := dependsOn_iff_exists_comp.mp hg | |
| have hw₁ : ∀ e : S, ∑ a, w e a = 1 := fun e => hw e | |
| have hw₂ : ∀ e : {e // e ∉ S}, ∑ a, w e a = 1 := fun e => hw e | |
| have hf' : expect w (fun ω => f' (fun e => ω e)) = | |
| expect (fun e : S => w e) f' := by | |
| have h := expect_factor w (fun e => e ∈ S) f' (fun _ => 1) | |
| simpa only [mul_one, expect_const _ hw₂] using h | |
| have hg' : expect w (fun ω => g' (fun e => ω e)) = | |
| expect (fun e : {e // e ∉ S} => w e) g' := by | |
| have h := expect_factor w (fun e => e ∈ S) (fun _ => 1) g' | |
| simp only [one_mul, expect_const _ hw₁] at h | |
| convert h using 1 | |
| rfl | |
| change expect w (fun ω => f' (fun e => ω e) * g' (fun e => ω e)) = | |
| expect w (fun ω => f' (fun e => ω e)) * expect w (fun ω => g' (fun e => ω e)) | |
| rw [hf', hg'] | |
| convert expect_factor w (fun e => e ∈ S) f' g' using 1 | |
| rfl | |
| lemma expect_mul_const (w : E → A → ℝ) (f : (E → A) → ℝ) (c : ℝ) : | |
| expect w (fun ω => f ω * c) = expect w f * c := by | |
| classical | |
| unfold expect | |
| rw [Finset.sum_mul] | |
| apply Finset.sum_congr (by ext; simp) | |
| intro ω _ | |
| ring | |
| lemma expect_partition {B : Type*} [Fintype B] [DecidableEq B] (w : E → A → ℝ) | |
| (r : (E → A) → B) (f : B → (E → A) → ℝ) : | |
| expect w (fun ω => f (r ω) ω) = | |
| ∑ b, expect w (fun ω => if r ω = b then f b ω else 0) := by | |
| classical | |
| simp only [expect] | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_congr (by ext; simp) | |
| intro ω _ | |
| rw [← Finset.mul_sum] | |
| simp | |
| lemma expect_exposure {B : Type*} [Fintype B] (w : E → A → ℝ) | |
| (hw : ∀ e, ∑ a, w e a = 1) (r : (E → A) → B) (D : B → Set E) | |
| (hr : ∀ b, DependsOn (fun ω => r ω = b) (D b)) | |
| (f : B → (E → A) → ℝ) (hf : ∀ b, DependsOn (f b) (D b)ᶜ) : | |
| expect w (fun ω => f (r ω) ω) = | |
| expect w (fun ω => expect w (f (r ω))) := by | |
| classical | |
| rw [expect_partition w r f, | |
| expect_partition w r (fun b _ => expect w (f b))] | |
| apply Finset.sum_congr (by ext; simp) | |
| intro b _ | |
| have hi : DependsOn (fun ω => if r ω = b then (1 : ℝ) else 0) (D b) := by | |
| intro ω ω' hω | |
| change (if r ω = b then (1 : ℝ) else 0) = (if r ω' = b then 1 else 0) | |
| have hh : (r ω = b) = (r ω' = b) := hr b hω | |
| rw [hh] | |
| have hleft : (fun ω => if r ω = b then f b ω else 0) = | |
| (fun ω => (if r ω = b then (1 : ℝ) else 0) * f b ω) := by | |
| funext ω | |
| split_ifs <;> simp | |
| have hright : (fun ω => if r ω = b then expect w (f b) else 0) = | |
| (fun ω => (if r ω = b then (1 : ℝ) else 0) * expect w (f b)) := by | |
| funext ω | |
| split_ifs <;> simp | |
| rw [hleft, hright, expect_indep w hw (D b) hi (hf b), expect_mul_const] | |
| end CriticalPercolation.FiniteProduct | |
| end | |
| end | |
| end OAI | |