Download data/lean/OAI/Geometry/PinnedDistances/Variance.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 32.8 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Geometry/PinnedDistances/Variance.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Geometry/PinnedDistances/Variance.lean
-
curl -L -o Variance.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Geometry/PinnedDistances/Variance.lean
32.8 kB
| import OAI.Geometry.PinnedDistances.ArithmeticHierarchy | |
| namespace OAI | |
| universe u1 u2 u3 u4 u5 | |
| 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 | |
| /- Finite off-diagonal variance. All diagonal terms are identically zero, | |
| not O(1/n): singleton cells may persist forever. -/ | |
| noncomputable section | |
| open scoped BigOperators | |
| open MeasureTheory | |
| namespace WeakPinned.Variance | |
| variable {P : Type u1} [Fintype P] [DecidableEq P] | |
| def prob (B : Finset P) (x : P) : β := if x β B then 1 / B.card else 0 | |
| def pairProb (B : Finset P) (x y : P) : β := | |
| if x β B β§ y β B β§ x β y then 1 / ((B.card : β) * (B.card - 1)) else 0 | |
| /-- Mixed cell probability, including B=P without an undefined outside branch. | |
| The outside column formula is never used when B=P. -/ | |
| def mixedProb (B : Finset P) (x y : P) : β := | |
| if x β B β§ x β y then | |
| if y β B then 1 / ((Fintype.card P : β) * (B.card - 1)) | |
| else 1 / ((Fintype.card P : β) * B.card) | |
| else 0 | |
| lemma sum_prob (B : Finset P) (hB : B.Nonempty) : β x, prob B x = 1 := by | |
| classical | |
| rw [show (β x, prob B x) = β x β B, 1 / (B.card : β) by simp [prob]] | |
| simp [hB.card_ne_zero] | |
| lemma sum_pairProb (B : Finset P) (hB : 2 β€ B.card) (x : P) : | |
| β y, pairProb B x y = prob B x := by | |
| classical | |
| by_cases hx : x β B | |
| Β· have hk : (B.card : β) β 0 := by exact_mod_cast (by omega : B.card β 0) | |
| have hk1 : (B.card : β) - 1 β 0 := by | |
| have : (2 : β) β€ B.card := by exact_mod_cast hB | |
| linarith | |
| have he : β y, pairProb B x y = if y β B.erase x then | |
| 1 / ((B.card : β) * (B.card - 1)) else 0 := by | |
| intro y | |
| simp only [pairProb, hx, true_and, Finset.mem_erase, ne_comm (a := y)] | |
| simp only [and_comm] | |
| simp_rw [he] | |
| simp only [Finset.sum_ite_mem, Finset.univ_inter, Finset.sum_const, | |
| nsmul_eq_mul, Finset.card_erase_of_mem hx] | |
| rw [Nat.cast_sub (by omega)] | |
| simp only [Nat.cast_one, prob, hx, reduceIte] | |
| field_simp | |
| Β· simp [pairProb, prob, hx] | |
| omit [Fintype P] in | |
| lemma pairProb_symm (B : Finset P) (x y : P) : pairProb B x y = pairProb B y x := by | |
| simp only [pairProb, and_left_comm, ne_comm] | |
| omit [Fintype P] in | |
| lemma pairProb_diag (B : Finset P) (x : P) : pairProb B x x = 0 := by | |
| simp [pairProb] | |
| omit [DecidableEq P] in | |
| lemma ambient_card_ge_two (B : Finset P) (hB : 2 β€ B.card) : | |
| 2 β€ Fintype.card P := hB.trans (Finset.card_le_univ B) | |
| lemma mixedProb_decompose (B : Finset P) (hB : 2 β€ B.card) (x y : P) : | |
| mixedProb B x y = (B.card : β) / Fintype.card P * pairProb B x y + | |
| prob B x / Fintype.card P * (if y β B then 0 else 1) := by | |
| have hk : (B.card : β) β 0 := by exact_mod_cast (by omega : B.card β 0) | |
| have hn : (Fintype.card P : β) β 0 := by | |
| exact_mod_cast (by have := ambient_card_ge_two B hB; omega : Fintype.card P β 0) | |
| have hk1 : (B.card : β) - 1 β 0 := by | |
| have : (2 : β) β€ B.card := by exact_mod_cast hB | |
| linarith | |
| by_cases hx : x β B <;> by_cases hy : y β B <;> by_cases hxy : x = y | |
| all_goals simp_all [mixedProb, pairProb, prob] | |
| all_goals field_simp | |
| lemma sum_mixedProb (B : Finset P) (hB : 2 β€ B.card) (x : P) : | |
| β y, mixedProb B x y = prob B x := by | |
| have hn : (Fintype.card P : β) β 0 := by | |
| exact_mod_cast (by have := ambient_card_ge_two B hB; omega : Fintype.card P β 0) | |
| have hout : (β y : P, (if y β B then (0 : β) else 1)) = | |
| Fintype.card P - (B.card : β) := by | |
| have he : β y : P, (if y β B then (0 : β) else 1) = | |
| if y β BαΆ then 1 else 0 := by intro y; simp | |
| simp_rw [he] | |
| simp only [Finset.sum_ite_mem, Finset.univ_inter, Finset.sum_const, | |
| nsmul_eq_mul, mul_one, Finset.card_compl, | |
| Nat.cast_sub (Finset.card_le_univ B)] | |
| simp_rw [mixedProb_decompose B hB, Finset.sum_add_distrib, | |
| β Finset.mul_sum, sum_pairProb B hB, hout] | |
| field_simp | |
| ring | |
| lemma sum_mixedProb_left (B : Finset P) (hB : 2 β€ B.card) (y : P) : | |
| β x, mixedProb B x y = 1 / Fintype.card P := by | |
| have hk : (B.card : β) β 0 := by exact_mod_cast (by omega : B.card β 0) | |
| have hne : B.Nonempty := Finset.card_pos.mp (by omega) | |
| simp_rw [mixedProb_decompose B hB, Finset.sum_add_distrib, | |
| β Finset.mul_sum, pairProb_symm B _ y, sum_pairProb B hB, | |
| β Finset.sum_mul, β Finset.sum_div, sum_prob B hne] | |
| by_cases hy : y β B <;> simp [prob, hy] | |
| field_simp | |
| lemma mixedProb_diag (B : Finset P) (x : P) : mixedProb B x x = 0 := by | |
| simp [mixedProb] | |
| def signedPair (B : Finset P) (x y : P) : β := | |
| pairProb B x y - 2 * mixedProb B x y + pairProb Finset.univ x y | |
| lemma signedPair_diag (B : Finset P) (x : P) : signedPair B x x = 0 := by | |
| simp [signedPair, pairProb_diag, mixedProb_diag] | |
| lemma signedPair_row (B : Finset P) (hB : 2 β€ B.card) (x : P) : | |
| (β y, signedPair B x y) = 1 / Fintype.card P - prob B x := by | |
| have hP : 2 β€ (Finset.univ : Finset P).card := ambient_card_ge_two B hB | |
| simp_rw [signedPair, Finset.sum_add_distrib, Finset.sum_sub_distrib, | |
| β Finset.mul_sum, sum_pairProb B hB, sum_mixedProb B hB, | |
| sum_pairProb Finset.univ hP] | |
| simp only [prob, Finset.mem_univ, reduceIte, Finset.card_univ] | |
| ring | |
| lemma signedPair_col (B : Finset P) (hB : 2 β€ B.card) (y : P) : | |
| (β x, signedPair B x y) = prob B y - 1 / Fintype.card P := by | |
| have hP : 2 β€ (Finset.univ : Finset P).card := ambient_card_ge_two B hB | |
| simp_rw [signedPair, Finset.sum_add_distrib, Finset.sum_sub_distrib, | |
| β Finset.mul_sum, sum_mixedProb_left B hB, pairProb_symm B _ y, | |
| pairProb_symm Finset.univ _ y, sum_pairProb B hB, | |
| sum_pairProb Finset.univ hP] | |
| simp only [prob, Finset.mem_univ, reduceIte, Finset.card_univ] | |
| ring | |
| /-- Exact cancellation against every additive off-diagonal overlap kernel. | |
| Only the sum of the two marginals is constrained. -/ | |
| lemma additive_cancel (H L : P β P β β) (b : β) (S : P β β) | |
| (hdiag : β x, H x x = 0) | |
| (hmass : (β x, β y, H x y) = 0) | |
| (hmarg : β x, (β y, H x y) + β y, H y x = 0) | |
| (hL : β x y, x β y β L x y = b + S x + S y) : | |
| (β x, β y, H x y * L x y) = 0 := by | |
| have hterm (x y : P) : H x y * L x y = H x y * (b + S x + S y) := by | |
| by_cases h : x = y | |
| Β· subst y; simp [hdiag] | |
| Β· rw [hL x y h] | |
| simp_rw [hterm, mul_add, Finset.sum_add_distrib] | |
| have hb : (β x, β y, H x y * b) = (β x, β y, H x y) * b := by | |
| simp_rw [Finset.sum_mul] | |
| rw [hb, hmass, zero_mul, zero_add] | |
| have hβ : (β x, β y, H x y * S x) = β x, (β y, H x y) * S x := by | |
| simp_rw [Finset.sum_mul] | |
| have hβ : (β x, β y, H x y * S y) = β x, (β y, H y x) * S x := by | |
| rw [Finset.sum_comm] | |
| simp_rw [Finset.sum_mul] | |
| rw [hβ, hβ, β Finset.sum_add_distrib] | |
| apply Finset.sum_eq_zero | |
| intro x _ | |
| rw [β add_mul, hmarg, zero_mul] | |
| lemma variance_cancel (B : Finset P) (hB : 2 β€ B.card) | |
| (L : P β P β β) (b : β) (S : P β β) | |
| (hL : β x y, x β y β L x y = b + S x + S y) : | |
| (β x, β y, signedPair B x y * L x y) = 0 := by | |
| apply additive_cancel _ _ b S (signedPair_diag B) _ _ hL | |
| Β· simp_rw [signedPair_row B hB, Finset.sum_sub_distrib] | |
| have hn : (Fintype.card P : β) β 0 := by | |
| exact_mod_cast (by have := ambient_card_ge_two B hB; omega : Fintype.card P β 0) | |
| rw [sum_prob B (Finset.card_pos.mp (by omega))] | |
| simp [hn] | |
| Β· intro x | |
| rw [signedPair_row B hB, signedPair_col B hB] | |
| ring | |
| /-- Exact cell probabilities, with the diagonal excluded. -/ | |
| def pairCell (B C : Finset P) : β := β x β C, β y β C, pairProb B x y | |
| def mixedCell (B C : Finset P) : β := β x β C, β y β C, mixedProb B x y | |
| def cellProb (B C : Finset P) : β := ((B β© C).card : β) / B.card | |
| omit [Fintype P] in | |
| lemma sum_prob_cell (B C : Finset P) : β x β C, prob B x = cellProb B C := by | |
| simp only [prob, Finset.sum_ite_mem, Finset.sum_const, nsmul_eq_mul, mul_one_div, | |
| cellProb, Finset.inter_comm] | |
| omit [Fintype P] in | |
| lemma pairCell_formula (B C : Finset P) : | |
| pairCell B C = ((B β© C).card : β) * ((B β© C).card - 1) / | |
| ((B.card : β) * (B.card - 1)) := by | |
| classical | |
| unfold pairCell pairProb | |
| rw [β Finset.sum_product C C (fun xy : P Γ P => | |
| if xy.1 β B β§ xy.2 β B β§ xy.1 β xy.2 then | |
| 1 / ((B.card : β) * (B.card - 1)) else 0), β Finset.sum_filter] | |
| have hf : (C ΓΛ’ C).filter (fun xy => xy.1 β B β§ xy.2 β B β§ xy.1 β xy.2) = | |
| (B β© C).offDiag := by | |
| ext β¨x,yβ© | |
| simp only [Finset.mem_filter, Finset.mem_product, Finset.mem_offDiag, Finset.mem_inter] | |
| tauto | |
| rw [hf, Finset.sum_const, nsmul_eq_mul, Finset.offDiag_card, β Nat.mul_sub_one] | |
| by_cases hb : (B β© C).card = 0 | |
| Β· simp [hb] | |
| Β· rw [Nat.cast_mul, Nat.cast_sub (by omega), Nat.cast_one] | |
| ring | |
| omit [Fintype P] in | |
| lemma sum_outside_cell (B C : Finset P) : | |
| (β y β C, if y β B then (0 : β) else 1) = | |
| (C.card : β) - (B β© C).card := by | |
| have he : β y, (if y β B then (0 : β) else 1) = | |
| if y β B then 1 else 0 := by intro y; split_ifs <;> rfl | |
| simp_rw [he] | |
| rw [β Finset.sum_filter] | |
| rw [show C.filter (fun y => y β B) = C \ B by ext y; simp] | |
| simp only [Finset.sum_const, nsmul_eq_mul, mul_one, Finset.card_sdiff, | |
| Nat.cast_sub (Finset.card_le_card Finset.inter_subset_right)] | |
| lemma mixedCell_formula (B C : Finset P) (hB : 2 β€ B.card) : | |
| mixedCell B C = (B.card : β) / Fintype.card P * pairCell B C + | |
| cellProb B C / Fintype.card P * ((C.card : β) - (B β© C).card) := by | |
| unfold mixedCell | |
| simp_rw [mixedProb_decompose B hB, Finset.sum_add_distrib, β Finset.mul_sum, | |
| sum_outside_cell B C, β Finset.sum_mul, β Finset.sum_div, sum_prob_cell B C] | |
| rfl | |
| omit [Fintype P] in | |
| lemma cellProb_nonneg (B C : Finset P) : 0 β€ cellProb B C := by | |
| unfold cellProb | |
| positivity | |
| omit [Fintype P] in | |
| lemma cellProb_le_one (B C : Finset P) : cellProb B C β€ 1 := by | |
| unfold cellProb | |
| apply div_le_one_of_leβ | |
| Β· exact_mod_cast Finset.card_le_card (Finset.inter_subset_left (sβ := C)) | |
| Β· positivity | |
| omit [Fintype P] in | |
| lemma pairCell_nonneg (B C : Finset P) : 0 β€ pairCell B C := by | |
| unfold pairCell pairProb | |
| apply Finset.sum_nonneg | |
| intro x _ | |
| apply Finset.sum_nonneg | |
| intro y _ | |
| split_ifs with h | |
| Β· have : 2 β€ B.card := Finset.one_lt_card.mpr β¨x,h.1,y,h.2.1,h.2.2β© | |
| have : (2 : β) β€ B.card := by exact_mod_cast this | |
| have : 0 β€ (B.card : β) - 1 := by linarith | |
| positivity | |
| Β· rfl | |
| private lemma pair_fraction (k b : β) (hk : k β 0) (hk1 : k - 1 β 0) : | |
| b * (b-1) / (k*(k-1)) = (b/k)^2 - (b/k)*(1-b/k)/(k-1) := by | |
| field_simp | |
| ring | |
| omit [Fintype P] in | |
| lemma pairCell_centered (B C : Finset P) (hB : 2 β€ B.card) : | |
| pairCell B C = (cellProb B C)^2 - cellProb B C * (1-cellProb B C) / | |
| ((B.card : β) - 1) := by | |
| have hk : (B.card : β) β 0 := by exact_mod_cast (by omega : B.card β 0) | |
| have hk1 : (B.card : β) - 1 β 0 := by | |
| have : (2 : β) β€ B.card := by exact_mod_cast hB | |
| linarith | |
| rw [pairCell_formula, cellProb, pair_fraction _ _ hk hk1] | |
| lemma mixedCell_centered (B C : Finset P) (hB : 2 β€ B.card) : | |
| mixedCell B C = cellProb Finset.univ C * cellProb B C - | |
| (B.card : β) / Fintype.card P * | |
| (cellProb B C * (1-cellProb B C) / ((B.card : β)-1)) := by | |
| have hk : (B.card : β) β 0 := by exact_mod_cast (by omega : B.card β 0) | |
| rw [mixedCell_formula B C hB, pairCell_centered B C hB] | |
| simp only [cellProb, Finset.univ_inter, Finset.card_univ] | |
| field_simp | |
| ring | |
| lemma mixedCell_le_product (B C : Finset P) (hB : 2 β€ B.card) : | |
| mixedCell B C β€ cellProb Finset.univ C * cellProb B C := by | |
| rw [mixedCell_centered B C hB] | |
| have hp := cellProb_nonneg B C | |
| have hp1 := cellProb_le_one B C | |
| have hk : (2 : β) β€ B.card := by exact_mod_cast hB | |
| have hk0 : 0 β€ (B.card : β) - 1 := by linarith | |
| have hp10 : 0 β€ 1-cellProb B C := sub_nonneg.mpr hp1 | |
| have hh : 0 β€ (B.card : β) / Fintype.card P * | |
| (cellProb B C * (1-cellProb B C) / ((B.card : β)-1)) := by positivity | |
| linarith | |
| lemma signedCell_formula (B C : Finset P) (hB : 2 β€ B.card) : | |
| (β x β C, β y β C, signedPair B x y) = | |
| (cellProb B C - cellProb Finset.univ C)^2 + | |
| (2 * (B.card : β) / Fintype.card P - 1) * | |
| (cellProb B C * (1-cellProb B C) / ((B.card : β)-1)) - | |
| cellProb Finset.univ C * (1-cellProb Finset.univ C) / | |
| ((Fintype.card P : β)-1) := by | |
| have hP : 2 β€ (Finset.univ : Finset P).card := ambient_card_ge_two B hB | |
| simp_rw [signedPair, Finset.sum_add_distrib, Finset.sum_sub_distrib, β Finset.mul_sum] | |
| change pairCell B C - 2 * mixedCell B C + pairCell Finset.univ C = _ | |
| rw [pairCell_centered B C hB, mixedCell_centered B C hB, | |
| pairCell_centered Finset.univ C hP] | |
| simp only [Finset.card_univ] | |
| ring | |
| private lemma pair_fraction_bounds (n m : β) (hm : 2 β€ m) (hmn : m β€ n) : | |
| (1/2) * (m/n)^2 β€ m*(m-1)/(n*(n-1)) β§ | |
| m*(m-1)/(n*(n-1)) β€ (m/n)^2 := by | |
| have hn : 0 < n := by linarith | |
| have hn1 : 0 < n-1 := by linarith | |
| have hmn0 : 0 β€ m/n := div_nonneg (by linarith) hn.le | |
| have hlow : m/(2*n) β€ (m-1)/(n-1) := by | |
| apply (div_le_div_iffβ (by positivity) hn1).mpr | |
| nlinarith [mul_nonneg hn.le (show 0 β€ m-2 by linarith)] | |
| have hupp : (m-1)/(n-1) β€ m/n := by | |
| apply (div_le_div_iffβ hn1 hn).mpr | |
| nlinarith | |
| have he : m*(m-1)/(n*(n-1)) = (m/n)*((m-1)/(n-1)) := by | |
| field_simp | |
| rw [he] | |
| constructor | |
| Β· calc | |
| (1/2) * (m/n)^2 = (m/n)*(m/(2*n)) := by ring | |
| _ β€ _ := mul_le_mul_of_nonneg_left hlow hmn0 | |
| Β· simpa only [sq] using mul_le_mul_of_nonneg_left hupp hmn0 | |
| lemma uniform_pair_comparison (C : Finset P) (hC : 2 β€ C.card) : | |
| (1/2) * (cellProb Finset.univ C)^2 β€ pairCell Finset.univ C β§ | |
| pairCell Finset.univ C β€ (cellProb Finset.univ C)^2 := by | |
| rw [pairCell_formula] | |
| simp only [cellProb, Finset.univ_inter, Finset.card_univ] | |
| apply pair_fraction_bounds | |
| Β· exact_mod_cast hC | |
| Β· exact_mod_cast Finset.card_le_univ C | |
| omit [Fintype P] in | |
| lemma fiber_pair_lower (B C : Finset P) (hB : 2 β€ B.card) : | |
| (1/2) * (if 2 / (B.card : β) β€ cellProb B C then (cellProb B C)^2 else 0) β€ | |
| pairCell B C := by | |
| split_ifs with hp | |
| Β· have hk : 0 < (B.card : β) := by exact_mod_cast (by omega : 0 < B.card) | |
| have hb : (2 : β) β€ (B β© C).card := | |
| (div_le_div_iff_of_pos_right hk).mp hp | |
| rw [pairCell_formula, cellProb] | |
| exact (pair_fraction_bounds _ _ hb | |
| (by exact_mod_cast Finset.card_le_card (Finset.inter_subset_left (sβ := C)))).1 | |
| Β· simpa only [mul_zero] using pairCell_nonneg B C | |
| omit [Fintype P] in | |
| lemma singleton_pairCell (B C : Finset P) (hC : C.card β€ 1) : pairCell B C = 0 := by | |
| unfold pairCell | |
| apply Finset.sum_eq_zero | |
| intro x hx | |
| apply Finset.sum_eq_zero | |
| intro y hy | |
| have : x = y := Finset.card_le_one.mp hC x hx y hy | |
| subst y | |
| exact pairProb_diag B x | |
| lemma singleton_mixedCell (B C : Finset P) (hC : C.card β€ 1) : mixedCell B C = 0 := by | |
| unfold mixedCell | |
| apply Finset.sum_eq_zero | |
| intro x hx | |
| apply Finset.sum_eq_zero | |
| intro y hy | |
| have : x = y := Finset.card_le_one.mp hC x hx y hy | |
| subst y | |
| exact mixedProb_diag B x | |
| omit [Fintype P] in | |
| lemma singleton_fiber_term (B C : Finset P) (hB : 2 β€ B.card) (hC : C.card β€ 1) : | |
| (if 2 / (B.card : β) β€ cellProb B C then (cellProb B C)^2 else 0) = 0 := by | |
| have hk : 0 < (B.card : β) := by exact_mod_cast (by omega : 0 < B.card) | |
| have hi : (B β© C).card β€ 1 := (Finset.card_le_card Finset.inter_subset_right).trans hC | |
| have hiR : ((B β© C).card : β) < 2 := by exact_mod_cast (by omega : (B β© C).card < 2) | |
| have hp : cellProb B C < 2 / (B.card : β) := | |
| (div_lt_div_iff_of_pos_right hk).mpr hiR | |
| simp only [not_le.mpr hp, reduceIte] | |
| def signedCell (B C : Finset P) : β := pairCell B C - 2 * mixedCell B C + | |
| pairCell Finset.univ C | |
| lemma signedCell_eq (B C : Finset P) : | |
| signedCell B C = β x β C, β y β C, signedPair B x y := by | |
| simp only [signedCell, pairCell, mixedCell, signedPair, | |
| Finset.sum_add_distrib, Finset.sum_sub_distrib, Finset.mul_sum] | |
| lemma singleton_signedCell (B C : Finset P) (hC : C.card β€ 1) : signedCell B C = 0 := by | |
| simp [signedCell, singleton_pairCell _ _ hC, singleton_mixedCell _ _ hC] | |
| private lemma correction_bound (p k Ξ΅ : β) (hp : 0 β€ p) (hp1 : p β€ 1) | |
| (hk : 0 < k-1) (he : 1/(k-1) β€ Ξ΅) : | |
| 0 β€ p*(1-p)/(k-1) β§ p*(1-p)/(k-1) β€ Ξ΅*p := by | |
| have hΞ΅ : 0 β€ Ξ΅ := (by positivity : 0 β€ 1/(k-1)).trans he | |
| constructor | |
| Β· exact div_nonneg (mul_nonneg hp (sub_nonneg.mpr hp1)) hk.le | |
| Β· calc | |
| p*(1-p)/(k-1) β€ p/(k-1) := by | |
| apply div_le_div_of_nonneg_right _ hk.le | |
| nlinarith [sq_nonneg p] | |
| _ = p * (1/(k-1)) := by ring | |
| _ β€ p*Ξ΅ := mul_le_mul_of_nonneg_left he hp | |
| _ = _ := mul_comm _ _ | |
| /-- The finite large-cell estimate before converting a to pair mass. -/ | |
| lemma signedCell_lower (B C : Finset P) (hB : 2 β€ B.card) (Ξ΅ : β) | |
| (hk : 1 / ((B.card : β)-1) β€ Ξ΅) | |
| (hn : 1 / ((Fintype.card P : β)-1) β€ Ξ΅) : | |
| (cellProb B C - cellProb Finset.univ C)^2 - | |
| Ξ΅ * (cellProb B C + cellProb Finset.univ C) β€ signedCell B C := by | |
| have hkr : (2 : β) β€ B.card := by exact_mod_cast hB | |
| have hnr : (2 : β) β€ Fintype.card P := by exact_mod_cast ambient_card_ge_two B hB | |
| have hp := correction_bound (cellProb B C) (B.card : β) Ξ΅ | |
| (cellProb_nonneg B C) (cellProb_le_one B C) (by linarith) hk | |
| have ha := correction_bound (cellProb Finset.univ C) (Fintype.card P : β) Ξ΅ | |
| (cellProb_nonneg _ C) (cellProb_le_one _ C) (by linarith) hn | |
| rw [signedCell_eq, signedCell_formula B C hB] | |
| have hc : 0 β€ 2 * (B.card : β) / Fintype.card P := by positivity | |
| nlinarith [mul_nonneg hc hp.1] | |
| section Family | |
| variable {I : Type u2} [Fintype I] | |
| variable (w : I β β) (B : I β Finset P) | |
| lemma mean_cell_bound (C : Finset P) (M : β) | |
| (hdom : β x, (β i, w i * prob (B i) x) β€ M * prob Finset.univ x) : | |
| (β i, w i * cellProb (B i) C) β€ M * cellProb Finset.univ C := by | |
| simp_rw [β sum_prob_cell, Finset.mul_sum] | |
| rw [Finset.sum_comm] | |
| exact Finset.sum_le_sum fun x _ => hdom x | |
| lemma family_large_raw (C : Finset P) (M Ξ΅ : β) | |
| (hw : β i, 0 β€ w i) (hW : (β i, w i) β€ 1) (hΞ΅ : 0 β€ Ξ΅) | |
| (hB : β i, 2 β€ (B i).card) | |
| (hk : β i, 1 / (((B i).card : β)-1) β€ Ξ΅) | |
| (hn : 1 / ((Fintype.card P : β)-1) β€ Ξ΅) | |
| (hmean : (β i, w i * cellProb (B i) C) β€ M * cellProb Finset.univ C) : | |
| (β i, w i * (cellProb (B i) C - cellProb Finset.univ C)^2) - | |
| Ξ΅*(M+1)*cellProb Finset.univ C β€ (β i, w i * signedCell (B i) C) := by | |
| let a := cellProb Finset.univ C | |
| have ha : 0 β€ a := cellProb_nonneg _ _ | |
| have hc : (β i, w i * cellProb (B i) C) + (β i, w i)*a β€ (M+1)*a := by | |
| have := mul_le_mul_of_nonneg_right hW ha | |
| dsimp [a] at * | |
| linarith | |
| calc | |
| _ β€ (β i, w i * (cellProb (B i) C - a)^2) - | |
| Ξ΅*((β i, w i * cellProb (B i) C)+(β i, w i)*a) := by | |
| have := mul_le_mul_of_nonneg_left hc hΞ΅ | |
| dsimp [a] at * | |
| nlinarith | |
| _ = β i, w i * ((cellProb (B i) C - a)^2 - Ξ΅*(cellProb (B i) C+a)) := by | |
| simp only [mul_add, Finset.mul_sum, Finset.sum_mul] | |
| rw [sub_add_eq_sub_sub, β Finset.sum_sub_distrib, β Finset.sum_sub_distrib] | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| ring | |
| _ β€ _ := Finset.sum_le_sum fun i _ => mul_le_mul_of_nonneg_left | |
| (signedCell_lower (B i) C (hB i) Ξ΅ (hk i) hn) (hw i) | |
| lemma family_large (C : Finset P) (M Ξ΅ Ο : β) | |
| (hw : β i, 0 β€ w i) (hW : (β i, w i) β€ 1) (hM : 0 β€ M) (hΞ΅ : 0 β€ Ξ΅) | |
| (hΟ : 0 < Ο) (hC : 2 β€ C.card) (ha : Ο β€ cellProb Finset.univ C) | |
| (hB : β i, 2 β€ (B i).card) | |
| (hk : β i, 1 / (((B i).card : β)-1) β€ Ξ΅) | |
| (hn : 1 / ((Fintype.card P : β)-1) β€ Ξ΅) | |
| (hmean : (β i, w i * cellProb (B i) C) β€ M * cellProb Finset.univ C) : | |
| (β i, w i * (cellProb (B i) C - cellProb Finset.univ C)^2) - | |
| (2*Ξ΅*(M+1)/Ο)*pairCell Finset.univ C β€ (β i, w i * signedCell (B i) C) := by | |
| have hcomp := (uniform_pair_comparison C hC).1 | |
| have ha0 := cellProb_nonneg (Finset.univ : Finset P) C | |
| have hmass : cellProb Finset.univ C β€ 2*pairCell Finset.univ C/Ο := by | |
| apply (le_div_iffβ hΟ).mpr | |
| nlinarith [mul_le_mul_of_nonneg_right ha ha0] | |
| have herr := mul_le_mul_of_nonneg_left hmass (show 0 β€ Ξ΅*(M+1) by positivity) | |
| have h := family_large_raw w B C M Ξ΅ hw hW hΞ΅ hB hk hn hmean | |
| have he : Ξ΅*(M+1)*(2*pairCell Finset.univ C/Ο) = | |
| (2*Ξ΅*(M+1)/Ο)*pairCell Finset.univ C := by ring | |
| rw [he] at herr | |
| linarith | |
| lemma family_small (C : Finset P) (M : β) | |
| (hw : β i, 0 β€ w i) (hM : 0 β€ M) (hC : 2 β€ C.card) | |
| (hB : β i, 2 β€ (B i).card) | |
| (hmean : (β i, w i * cellProb (B i) C) β€ M * cellProb Finset.univ C) : | |
| (1/2) * (β i, w i * (if 2 / ((B i).card : β) β€ cellProb (B i) C then | |
| (cellProb (B i) C)^2 else 0)) - 4*M*pairCell Finset.univ C β€ | |
| (β i, w i * signedCell (B i) C) := by | |
| let a := cellProb Finset.univ C | |
| have ha0 : 0 β€ a := cellProb_nonneg _ _ | |
| have hp0 := pairCell_nonneg (Finset.univ : Finset P) C | |
| have hc := (uniform_pair_comparison C hC).1 | |
| have hterm (i : I) : | |
| (1/2)*(if 2 / ((B i).card : β) β€ cellProb (B i) C then | |
| (cellProb (B i) C)^2 else 0) - 2*a*cellProb (B i) C β€ signedCell (B i) C := by | |
| have hβ := fiber_pair_lower (B i) C (hB i) | |
| have hβ := mixedCell_le_product (B i) C (hB i) | |
| dsimp [signedCell, a] at * | |
| linarith | |
| have hs := Finset.sum_le_sum (s := Finset.univ) (fun i _ => | |
| mul_le_mul_of_nonneg_left (hterm i) (hw i)) | |
| have he : (β i, w i * ((1/2)*(if 2 / ((B i).card : β) β€ cellProb (B i) C then | |
| (cellProb (B i) C)^2 else 0) - 2*a*cellProb (B i) C)) = | |
| (1/2)*(β i, w i * (if 2 / ((B i).card : β) β€ cellProb (B i) C then | |
| (cellProb (B i) C)^2 else 0)) - 2*a*(β i, w i * cellProb (B i) C) := by | |
| rw [Finset.mul_sum, Finset.mul_sum, β Finset.sum_sub_distrib] | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| ring | |
| rw [he] at hs | |
| have hmean' := mul_le_mul_of_nonneg_left hmean (show 0 β€ 2*a by positivity) | |
| have hcomp := mul_le_mul_of_nonneg_left hc (show 0 β€ 4*M by positivity) | |
| dsimp [a] at * | |
| nlinarith | |
| end Family | |
| /-- Zero pair overlap is precisely an empty or singleton occurrence. -/ | |
| lemma zero_uniform_pair_iff (C : Finset P) : | |
| pairCell Finset.univ C = 0 β C.card β€ 1 := by | |
| refine β¨?_, singleton_pairCell _ _β© | |
| intro h | |
| by_contra! hc | |
| have hc2 : 2 β€ C.card := hc | |
| have hn : 0 < (Fintype.card P : β) := by | |
| exact_mod_cast (show 0 < Fintype.card P by have := Finset.card_le_univ C; omega) | |
| have hm : 0 < (C.card : β) := by exact_mod_cast (by omega : 0 < C.card) | |
| have ha : 0 < cellProb Finset.univ C := by | |
| simpa only [cellProb, Finset.univ_inter, Finset.card_univ] using div_pos hm hn | |
| have hh := (uniform_pair_comparison C hc2).1 | |
| rw [h] at hh | |
| have : 0 < (1/2 : β)*(cellProb Finset.univ C)^2 := by positivity | |
| linarith | |
| section CellIntegral | |
| variable {Ξ© : Type u3} [MeasurableSpace Ξ©] | |
| -- A finite set of vertex labels is discrete. No condition is imposed on the | |
| -- underlying cell-occurrence measure, which may have infinite singleton tails. | |
| local instance : MeasurableSpace (Finset P) := β€ | |
| local instance : DiscreteMeasurableSpace (Finset P) := β¨fun _ => trivialβ© | |
| private lemma finite_weighted_bound {T : Type u4} [Fintype T] | |
| (f q : T β β) (hq : β t, 0 β€ q t) (hf : β t, q t = 0 β f t = 0) : | |
| β K : β, β t, |f t| β€ K*q t := by | |
| classical | |
| refine β¨β t, |f t / q t|, ?_β© | |
| intro t | |
| by_cases ht : q t = 0 | |
| Β· simp [ht, hf t ht] | |
| Β· calc | |
| |f t| = |f t / q t| * q t := by | |
| rw [abs_div, abs_of_nonneg (hq t), div_mul_cancelβ _ ht] | |
| _ β€ _ := mul_le_mul_of_nonneg_right | |
| (Finset.single_le_sum (s := Finset.univ) (f := fun t => |f t / q t|) | |
| (fun _ _ => abs_nonneg _) (Finset.mem_univ t)) (hq t) | |
| /-- The only integrability input needed for any fixed finite cell function | |
| vanishing on singletons is integrability of the off-diagonal pair mass. -/ | |
| lemma integrable_cell_function (C : Ξ© β Finset P) (ΞΌ : Measure Ξ©) | |
| (hC : Measurable C) (hq : Integrable (fun Ο => pairCell Finset.univ (C Ο)) ΞΌ) | |
| (f : Finset P β β) (hf : β D, D.card β€ 1 β f D = 0) : | |
| Integrable (fun Ο => f (C Ο)) ΞΌ := by | |
| obtain β¨K,hKβ© := finite_weighted_bound f (pairCell Finset.univ) | |
| (pairCell_nonneg _) (fun D hd => hf D ((zero_uniform_pair_iff D).mp hd)) | |
| apply (hq.const_mul K).mono' ((measurable_of_finite f).comp hC).aestronglyMeasurable | |
| exact Filter.Eventually.of_forall fun Ο => by simpa only [Real.norm_eq_abs, Function.comp_apply] using hK (C Ο) | |
| def offDiagonalCell (C : Finset P) (x y : P) : β := | |
| if x β y β§ x β C β§ y β C then 1 else 0 | |
| omit [Fintype P] in | |
| lemma offDiagonalCell_singleton (C : Finset P) (x y : P) (hC : C.card β€ 1) : | |
| offDiagonalCell C x y = 0 := by | |
| unfold offDiagonalCell | |
| split_ifs with h | |
| Β· exact False.elim (h.1 (Finset.card_le_one.mp hC x h.2.1 y h.2.2)) | |
| Β· rfl | |
| def overlap (C : Ξ© β Finset P) (ΞΌ : Measure Ξ©) (x y : P) : β := | |
| β« Ο, offDiagonalCell (C Ο) x y βΞΌ | |
| lemma cell_sum_eq (H : P β P β β) (hdiag : β x, H x x = 0) (C : Finset P) : | |
| (β x β C, β y β C, H x y) = β x, β y, H x y * offDiagonalCell C x y := by | |
| have he (x y : P) : H x y * offDiagonalCell C x y = | |
| if x β C then if y β C then H x y else 0 else 0 := by | |
| by_cases hx : x β C <;> by_cases hy : y β C <;> by_cases hxy : x = y | |
| all_goals simp_all [offDiagonalCell] | |
| simp_rw [he] | |
| simp | |
| lemma integral_signedCell (C : Ξ© β Finset P) (ΞΌ : Measure Ξ©) | |
| (hC : Measurable C) (hq : Integrable (fun Ο => pairCell Finset.univ (C Ο)) ΞΌ) | |
| (B : Finset P) : | |
| (β« Ο, signedCell B (C Ο) βΞΌ) = β x, β y, signedPair B x y * overlap C ΞΌ x y := by | |
| have hi (x y : P) : Integrable (fun Ο => signedPair B x y * offDiagonalCell (C Ο) x y) ΞΌ := | |
| (integrable_cell_function C ΞΌ hC hq (fun D => offDiagonalCell D x y) | |
| (fun D hD => offDiagonalCell_singleton D x y hD)).const_mul _ | |
| calc | |
| _ = β« Ο, β x, β y, signedPair B x y * offDiagonalCell (C Ο) x y βΞΌ := by | |
| apply integral_congr_ae | |
| exact Filter.Eventually.of_forall fun Ο => by | |
| change signedCell B (C Ο) = _ | |
| rw [signedCell_eq, cell_sum_eq _ (signedPair_diag B)] | |
| _ = β x, β y, β« Ο, signedPair B x y * offDiagonalCell (C Ο) x y βΞΌ := by | |
| rw [integral_finsetSum _ (fun x _ => integrable_finsetSum _ (fun y _ => hi x y))] | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| exact integral_finsetSum _ (fun y _ => hi x y) | |
| _ = _ := by simp only [overlap, integral_const_mul] | |
| lemma integrated_cancel (C : Ξ© β Finset P) (ΞΌ : Measure Ξ©) | |
| (hC : Measurable C) (hq : Integrable (fun Ο => pairCell Finset.univ (C Ο)) ΞΌ) | |
| (b : β) (S : P β β) | |
| (hL : β x y, x β y β overlap C ΞΌ x y = b + S x + S y) | |
| (B : Finset P) (hB : 2 β€ B.card) : | |
| (β« Ο, signedCell B (C Ο) βΞΌ) = 0 := by | |
| rw [integral_signedCell C ΞΌ hC hq] | |
| exact variance_cancel B hB _ b S hL | |
| section Quantitative | |
| variable {I : Type u5} [Fintype I] | |
| def varianceCell (w : I β β) (B : I β Finset P) (T : β) (D : Finset P) : β := | |
| if T < D.card then | |
| β i, w i * (cellProb (B i) D - cellProb Finset.univ D)^2 | |
| else (1/2) * β i, w i * | |
| (if 2 / ((B i).card : β) β€ cellProb (B i) D then (cellProb (B i) D)^2 else 0) | |
| lemma varianceCell_singleton (w : I β β) (B : I β Finset P) (T : β) | |
| (hT : 1 β€ T) (hB : β i, 2 β€ (B i).card) (D : Finset P) (hD : D.card β€ 1) : | |
| varianceCell w B T D = 0 := by | |
| have hd : (D.card : β) β€ T := (by exact_mod_cast hD : (D.card : β) β€ 1).trans hT | |
| simp [varianceCell, not_lt.mpr hd, singleton_fiber_term _ _ (hB _) hD] | |
| lemma varianceCell_bound (w : I β β) (B : I β Finset P) (T M Ξ΅ Ο : β) | |
| (hw : β i, 0 β€ w i) (hW : (β i, w i) β€ 1) | |
| (hT : 1 β€ T) (hM : 0 β€ M) (hΞ΅ : 0 β€ Ξ΅) (hΟ : 0 < Ο) | |
| (hscale : Ο * Fintype.card P β€ T) | |
| (hB : β i, 2 β€ (B i).card) | |
| (hk : β i, 1 / (((B i).card : β)-1) β€ Ξ΅) | |
| (hn : 1 / ((Fintype.card P : β)-1) β€ Ξ΅) | |
| (hdom : β x, (β i, w i * prob (B i) x) β€ M * prob Finset.univ x) | |
| (D : Finset P) : | |
| varianceCell w B T D β€ (β i, w i * signedCell (B i) D) + | |
| (2*Ξ΅*(M+1)/Ο)*pairCell Finset.univ D + | |
| 4*M*(if (D.card : β) β€ T then pairCell Finset.univ D else 0) := by | |
| have hmean := mean_cell_bound w B D M hdom | |
| have herr : 0 β€ (2*Ξ΅*(M+1)/Ο)*pairCell Finset.univ D := by | |
| exact mul_nonneg (div_nonneg (mul_nonneg (mul_nonneg (by norm_num) hΞ΅) | |
| (by linarith)) hΟ.le) (pairCell_nonneg _ _) | |
| by_cases hD : T < (D.card : β) | |
| Β· have hd2 : 2 β€ D.card := by | |
| have : (1 : β) < D.card := hT.trans_lt hD | |
| exact_mod_cast (show 1 < D.card by exact_mod_cast this) | |
| have hnp : 0 < (Fintype.card P : β) := by | |
| exact_mod_cast (show 0 < Fintype.card P by have := Finset.card_le_univ D; omega) | |
| have ha : Ο β€ cellProb Finset.univ D := by | |
| simp only [cellProb, Finset.univ_inter, Finset.card_univ] | |
| exact (le_div_iffβ hnp).mpr (hscale.trans hD.le) | |
| have hh := family_large w B D M Ξ΅ Ο hw hW hM hΞ΅ hΟ hd2 ha hB hk hn hmean | |
| simp only [varianceCell, hD, reduceIte, not_le.mpr hD, mul_zero, add_zero] | |
| linarith | |
| Β· simp only [varianceCell, hD, reduceIte, not_lt.mp hD] | |
| by_cases hd2 : 2 β€ D.card | |
| Β· have hh := family_small w B D M hw hM hd2 hB hmean | |
| linarith | |
| Β· have hd1 : D.card β€ 1 := by omega | |
| simp [singleton_fiber_term _ _ (hB _) hd1, singleton_signedCell _ _ hd1, | |
| singleton_pairCell _ _ hd1] | |
| /-- The integrated off-diagonal variance estimate before specializing the | |
| threshold and denominator errors to powers of n. The pair overlap may | |
| have infinite singleton tails; no diagonal integral is used. -/ | |
| theorem integrated_variance (C : Ξ© β Finset P) (ΞΌ : Measure Ξ©) | |
| (hC : Measurable C) (hq : Integrable (fun Ο => pairCell Finset.univ (C Ο)) ΞΌ) | |
| (b : β) (S : P β β) | |
| (hL : β x y, x β y β overlap C ΞΌ x y = b + S x + S y) | |
| (w : I β β) (B : I β Finset P) (T M Ξ΅ Ο : β) | |
| (hw : β i, 0 β€ w i) (hW : (β i, w i) β€ 1) | |
| (hT : 1 β€ T) (hM : 0 β€ M) (hΞ΅ : 0 β€ Ξ΅) (hΟ : 0 < Ο) | |
| (hscale : Ο * Fintype.card P β€ T) | |
| (hB : β i, 2 β€ (B i).card) | |
| (hk : β i, 1 / (((B i).card : β)-1) β€ Ξ΅) | |
| (hn : 1 / ((Fintype.card P : β)-1) β€ Ξ΅) | |
| (hdom : β x, (β i, w i * prob (B i) x) β€ M * prob Finset.univ x) : | |
| (β« Ο, varianceCell w B T (C Ο) βΞΌ) β€ | |
| (2*Ξ΅*(M+1)/Ο)*(β« Ο, pairCell Finset.univ (C Ο) βΞΌ) + | |
| 4*M*(β« Ο, if ((C Ο).card : β) β€ T then pairCell Finset.univ (C Ο) else 0 βΞΌ) := by | |
| have hv : Integrable (fun Ο => varianceCell w B T (C Ο)) ΞΌ := | |
| integrable_cell_function C ΞΌ hC hq _ (varianceCell_singleton w B T hT hB) | |
| have hs (i : I) : Integrable (fun Ο => signedCell (B i) (C Ο)) ΞΌ := | |
| integrable_cell_function C ΞΌ hC hq _ (singleton_signedCell _) | |
| have hsmall : Integrable (fun Ο => | |
| if ((C Ο).card : β) β€ T then pairCell Finset.univ (C Ο) else 0) ΞΌ := by | |
| apply integrable_cell_function C ΞΌ hC hq | |
| (fun D => if (D.card : β) β€ T then pairCell Finset.univ D else 0) | |
| intro D hD | |
| simp [singleton_pairCell _ _ hD] | |
| have hsum : Integrable (fun Ο => β i, w i * signedCell (B i) (C Ο)) ΞΌ := | |
| integrable_finsetSum _ fun i _ => (hs i).const_mul _ | |
| have hzero : (β« Ο, β i, w i * signedCell (B i) (C Ο) βΞΌ) = 0 := by | |
| rw [integral_finsetSum _ fun i _ => (hs i).const_mul _] | |
| simp only [integral_const_mul, | |
| integrated_cancel C ΞΌ hC hq b S hL _ (hB _), mul_zero, Finset.sum_const_zero] | |
| have hh := integral_mono hv | |
| ((hsum.add (hq.const_mul _)).add (hsmall.const_mul _)) | |
| (fun Ο => varianceCell_bound w B T M Ξ΅ Ο hw hW hT hM hΞ΅ hΟ hscale hB hk hn hdom (C Ο)) | |
| simp only [Pi.add_apply] at hh | |
| have hβ := integral_add (hsum.add (hq.const_mul (2*Ξ΅*(M+1)/Ο))) (hsmall.const_mul (4*M)) | |
| have hβ := integral_add hsum (hq.const_mul (2*Ξ΅*(M+1)/Ο)) | |
| simp only [Pi.add_apply] at hβ hβ | |
| rw [hβ, hβ, hzero, zero_add, integral_const_mul, integral_const_mul] at hh | |
| exact hh | |
| end Quantitative | |
| end CellIntegral | |
| end WeakPinned.Variance | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end OAI | |