Download data/lean/OAI/Probability/Contingency/ConcreteKernel.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 25 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Contingency/ConcreteKernel.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/Contingency/ConcreteKernel.lean
-
curl -L -o ConcreteKernel.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Contingency/ConcreteKernel.lean
25 kB
| import Mathlib | |
| import OAI.Probability.Contingency.Completions | |
| namespace OAI | |
| /-! Concrete Kernel. -/ | |
| noncomputable section | |
| open scoped BigOperators | |
| open scoped BigOperators | |
| namespace Contingency.PaddedGraph | |
| variable {m n : β} | |
| abbrev SmallSlot (U : β) (r : Fin m β β) (c : Fin n β β) := | |
| {w : Cell m n // IsSmall U r c w} | |
| abbrev LargeSlot (U : β) (r : Fin m β β) (c : Fin n β β) := | |
| {w : Cell m n // IsLarge U r c w} | |
| abbrev SmallCoord (U : β) (r : Fin m β β) (c : Fin n β β) := | |
| SmallSlot U r c Γ Bool | |
| noncomputable def largeIndex (U : β) (r : Fin m β β) (c : Fin n β β) := | |
| Fintype.equivFin (LargeSlot U r c) | |
| noncomputable def wholeCoordinates (U : β) (r : Fin m β β) (c : Fin n β β) : | |
| Coordinate m n β (SmallCoord U r c β (Fin (Fintype.card (LargeSlot U r c)) Γ Bool)) where | |
| toFun w := if h : IsSmall U r c w.2 then .inl (β¨w.2,hβ©,w.1) | |
| else .inr (largeIndex U r c β¨w.2,Classical.not_not.mp hβ©,w.1) | |
| invFun w := match w with | |
| | .inl (s,b) => (b,s.val) | |
| | .inr (s,b) => (b,((largeIndex U r c).symm s).val) | |
| left_inv w := by | |
| rcases w with β¨b,wβ© | |
| by_cases hw : IsSmall U r c w | |
| Β· simp only [dite_eq_left hw] | |
| Β· simp only [dite_eq_right hw,Equiv.symm_apply_apply] | |
| right_inv w := by | |
| rcases w with β¨s,bβ© | β¨s,bβ© | |
| Β· dsimp; rw [dite_eq_left s.property] | |
| Β· dsimp | |
| rw [dite_eq_right (show Β¬IsSmall U r c ((largeIndex U r c).symm s).val from | |
| fun h => h ((largeIndex U r c).symm s).property)] | |
| simp | |
| @[simp] theorem wholeCoordinates_small (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (s : SmallSlot U r c) (b : Bool) : | |
| wholeCoordinates U r c (b,s.val) = Sum.inl (s,b) := by | |
| simp only [wholeCoordinates,Equiv.coe_fn_mk,dite_eq_left s.property] | |
| @[simp] theorem wholeCoordinates_large (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (s : LargeSlot U r c) (b : Bool) : | |
| wholeCoordinates U r c (b,s.val) = Sum.inr (largeIndex U r c s,b) := by | |
| simp only [wholeCoordinates,Equiv.coe_fn_mk,dite_eq_right (show Β¬IsSmall U r c s.val from | |
| fun h => h s.property)] | |
| theorem capacity_box (U C : β) (r : Fin m β β) (c : Fin n β β) : | |
| (fun w : Coordinate m n => capacity U C r c w.2) β (wholeCoordinates U r c).symm = | |
| balanceBox (fun _ : SmallCoord U r c => (U:β€)) (fun _ => C) := by | |
| funext w | |
| rcases w with β¨s,bβ© | β¨s,bβ© | |
| Β· simp [wholeCoordinates,capacity,balanceBox,(show Β¬IsLarge U r c s.val from s.property)] | |
| Β· simp [wholeCoordinates,capacity,balanceBox,((largeIndex U r c).symm s).property] | |
| theorem capacity_total (U C : β) (r : Fin m β β) (c : Fin n β β) : | |
| (β w, capacity U C r c w) = | |
| (Fintype.card (SmallSlot U r c):β€)*U+(Fintype.card (LargeSlot U r c):β€)*C := by | |
| have h := Fintype.sum_subtype_add_sum_subtype (IsLarge U r c) (capacity U C r c) | |
| have hl (w : LargeSlot U r c) : capacity U C r c w.val = (C:β€) := by | |
| simp [capacity,w.property] | |
| have hs (w : SmallSlot U r c) : capacity U C r c w.val = (U:β€) := by | |
| simp [capacity,(show Β¬IsLarge U r c w.val from w.property)] | |
| change (β w : LargeSlot U r c, capacity U C r c w.val) + | |
| (β w : SmallSlot U r c, capacity U C r c w.val) = _ at h | |
| simp only [hl,hs,Finset.sum_const,Finset.card_univ, nsmul_eq_mul] at h | |
| linarith | |
| noncomputable def smallKernel (Ξ· : β) (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (p : SmallCoord U r c β β€) : β := | |
| balancedSlots (fun q => softWeight Ξ· (fun i => r i) (paddedRow U L r c) | |
| (fun j => c j) (paddedCol U L r c) (capacity U C r c) (smallSet U r c) | |
| (q β wholeCoordinates U r c)) (fun _ => C) p | |
| theorem smallKernel_signature (Ξ· : β) (hΞ· : 0 < Ξ·) (hΞ·1 : Ξ· < 1) | |
| (U L C : β) (hC : 2 β€ C) (r : Fin m β β) (c : Fin n β β) : | |
| PositiveSlice (smallKernel Ξ· U L C r c) (fun _ => (U:β€)) | |
| ((Fintype.card (SmallSlot U r c):β€)*U) β§ | |
| HasSignature (smallKernel Ξ· U L C r c) (fun _ => (U:β€)) | |
| ((Fintype.card (SmallSlot U r c):β€)*U) := by | |
| have hp := (softWeight_positive Ξ· hΞ· (fun i => r i) (paddedRow U L r c) | |
| (fun j => c j) (paddedCol U L r c) (capacity U C r c) (smallSet U r c)).reindex | |
| (wholeCoordinates U r c) | |
| have hs := (softWeight_signature Ξ· hΞ· hΞ·1 (fun i => r i) (paddedRow U L r c) | |
| (fun j => c j) (paddedCol U L r c) (capacity U C r c) (smallSet U r c)).reindex | |
| (wholeCoordinates U r c) | |
| rw [capacity_box] at hp hs | |
| have h := balancedSlots_closure _ _ _ (fun _ => C) (fun _ => hC) _ hp hs | |
| rw [capacity_total] at h | |
| simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,Fintype.card_fin,add_sub_cancel_right] at h | |
| exact h | |
| noncomputable def stateCoordinates (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (X : State m n) (w : SmallCoord U r c) : β€ := | |
| if w.2 then X.x w.1.val else (U:β€)-X.q w.1.val | |
| noncomputable def coordinatesState (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (p : SmallCoord U r c β β€) : State m n where | |
| x w := if h : IsSmall U r c w then p (β¨w,hβ©,true) else 0 | |
| q w := if h : IsSmall U r c w then (U:β€)-p (β¨w,hβ©,false) else 0 | |
| @[simp] theorem coordinatesState_x (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (p : SmallCoord U r c β β€) (w : SmallSlot U r c) : | |
| (coordinatesState U r c p).x w.val = p (w,true) := by simp [coordinatesState,w.property] | |
| @[simp] theorem coordinatesState_q (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (p : SmallCoord U r c β β€) (w : SmallSlot U r c) : | |
| (coordinatesState U r c p).q w.val = (U:β€)-p (w,false) := by simp [coordinatesState,w.property] | |
| @[simp] theorem stateCoordinates_coordinatesState (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (p : SmallCoord U r c β β€) : | |
| stateCoordinates U r c (coordinatesState U r c p) = p := by | |
| funext β¨w,bβ© | |
| cases b <;> simp [stateCoordinates] | |
| def largeChoicesEquiv (U C : β) (r : Fin m β β) (c : Fin n β β) : | |
| LargeChoices U C r c β (LargeSlot U r c β Fin (C+1)) where | |
| toFun A w := β¨(A.val w.val).toNat,by have h := A.property w.val; omegaβ© | |
| invFun a := β¨(fun w => if h : IsLarge U r c w then (a β¨w,hβ©:β) else 0),by | |
| intro w | |
| dsimp | |
| by_cases hw : IsLarge U r c w | |
| Β· rw [dite_eq_left hw] | |
| have h := (a β¨w,hwβ©).isLt | |
| exact β¨by omega,by omega,fun hh => (hh hw).elimβ© | |
| Β· rw [dite_eq_right hw] | |
| exact β¨by omega,by omega,fun _ => rflβ©β© | |
| left_inv A := by | |
| apply Subtype.ext | |
| funext w | |
| dsimp | |
| by_cases hw : IsLarge U r c w | |
| Β· rw [ite_eq_left hw,Int.toNat_of_nonneg (A.property w).1] | |
| Β· rw [ite_eq_right hw,(A.property w).2.2 hw] | |
| right_inv a := by | |
| funext w | |
| apply Fin.ext | |
| simp only [dite_eq_left w.property,Int.toNat_natCast] | |
| noncomputable def largeProfileEquiv (U C : β) (r : Fin m β β) (c : Fin n β β) : | |
| LargeChoices U C r c β (Fin (Fintype.card (LargeSlot U r c)) β Fin (C+1)) := | |
| (largeChoicesEquiv U C r c).trans ((largeIndex U r c).arrowCongr (Equiv.refl _)) | |
| theorem balanced_fullCoordinates (U C : β) (r : Fin m β β) (c : Fin n β β) | |
| (X : State m n) (hX : β w, IsLarge U r c w β X.x w=0 β§ X.q w=0) | |
| (A : LargeChoices U C r c) : | |
| (Sum.elim (stateCoordinates U r c X) (balanceProfile (fun _ => C) (largeProfileEquiv U C r c A))) β | |
| wholeCoordinates U r c = fullCoordinates U C r c X A.val := by | |
| funext β¨b,wβ© | |
| by_cases hw : IsSmall U r c w | |
| Β· have hA := (A.property w).2.2 hw | |
| have he := wholeCoordinates_small U r c β¨w,hwβ© b | |
| simp only [Function.comp_apply,he,Sum.elim_inl,stateCoordinates] | |
| cases b <;> simp [fullCoordinates,capacity,(show Β¬IsLarge U r c w from hw),hA] | |
| Β· have hl := Classical.not_not.mp hw | |
| have hx := hX w hl | |
| have he := wholeCoordinates_large U r c β¨w,hlβ© b | |
| simp only [Function.comp_apply,he,Sum.elim_inr,balanceProfile] | |
| have ha : (largeProfileEquiv U C r c A (largeIndex U r c β¨w,hlβ©):β) = (A.val w).toNat := by | |
| simp [largeProfileEquiv,largeChoicesEquiv] | |
| rfl | |
| rw [ha,Int.toNat_of_nonneg (A.property w).1] | |
| cases b <;> simp [fullCoordinates,capacity,hl,hx] | |
| theorem smallKernel_zero_count (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (hrc : (β i, r i) = β j, c j) (X : State m n) (hf : Feasible U r c X) | |
| (hC : β i, paddedRow U L r c i β€ C) : | |
| smallKernel 0 U L C r c (stateCoordinates U r c X) = | |
| (Nat.card (Completion U L r c X):β) := by | |
| unfold smallKernel balancedSlots | |
| rw [β Equiv.sum_comp (largeProfileEquiv U C r c)] | |
| simp_rw [balanced_fullCoordinates U C r c X hf.2.1] | |
| exact sum_choice_softWeight U L C r c hrc X hf hC | |
| theorem full_zero_feasible (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (X : State m n) (hX : β w, IsLarge U r c w β X.x w=0 β§ X.q w=0) | |
| (A : LargeChoices U C r c) | |
| (hb : InBox (fun w => capacity U C r c w.2) (fullCoordinates U C r c X A.val)) | |
| (hp : softPenalty (fun i => r i) (paddedRow U L r c) | |
| (fun j => c j) (paddedCol U L r c) (capacity U C r c) (smallSet U r c) | |
| (fullCoordinates U C r c X A.val)=0) : Feasible U r c X := by | |
| rw [softPenalty_zero_iff] at hp | |
| have hsx (w : Cell m n) : | |
| (if w β smallSet U r c then fullCoordinates U C r c X A.val (true,w) else 0) = X.x w := by | |
| by_cases hw : IsSmall U r c w | |
| Β· simp [smallSet,hw,fullCoordinates,(A.property w).2.2 hw] | |
| Β· simp [smallSet,hw,(hX w (Classical.not_not.mp hw)).1] | |
| have hsq (w : Cell m n) : | |
| (if w β smallSet U r c then capacity U C r c w - | |
| fullCoordinates U C r c X A.val (false,w) else 0) = X.q w := by | |
| rw [fullCoordinates_q] | |
| by_cases hw : IsSmall U r c w | |
| Β· simp [smallSet,hw,(A.property w).2.2 hw] | |
| Β· simp [smallSet,hw,(hX w (Classical.not_not.mp hw)).2] | |
| refine β¨?_,hX,?_,?_β© | |
| Β· intro w | |
| by_cases hw : IsLarge U r c w | |
| Β· rw [(hX w hw).1,(hX w hw).2]; exact β¨by omega,by omega,by omega,by omegaβ© | |
| Β· have hx := hb (true,w) | |
| have hq := hb (false,w) | |
| simp only [fullCoordinates,capacity,ite_eq_right hw,(A.property w).2.2 hw, | |
| Bool.false_eq_true,ite_false,ite_true,add_zero] at hx hq | |
| omega | |
| Β· intro i | |
| have hi := hp.2.2.1 i | |
| simp only [hsx] at hi | |
| refine β¨hi,?_β© | |
| intro hno | |
| have ha (j : Fin n) : A.val (i,j)=0 := (A.property (i,j)).2.2 (hno j) | |
| have he := hp.1 i | |
| simp only [fullCoordinates_x,ha,add_zero] at he | |
| simpa [rowSum,paddedRow,rowPadding,hno] using he | |
| Β· intro j | |
| have hj := hp.2.2.2 j | |
| simp only [hsq] at hj | |
| refine β¨hj,?_β© | |
| intro hno | |
| have ha (i : Fin m) : A.val (i,j)=0 := (A.property (i,j)).2.2 (hno i) | |
| have he := hp.2.1 j | |
| simp only [fullCoordinates_q,ha,add_zero] at he | |
| simpa [colSum,paddedCol,colPadding,hno] using he | |
| theorem coordinatesState_supported (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (p : SmallCoord U r c β β€) : | |
| β w, IsLarge U r c w β (coordinatesState U r c p).x w=0 β§ | |
| (coordinatesState U r c p).q w=0 := by | |
| intro w hw | |
| have hs : Β¬IsSmall U r c w := fun h => h hw | |
| simp [coordinatesState,hs] | |
| theorem smallKernel_zero_infeasible (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (p : SmallCoord U r c β β€) (hf : Β¬Feasible U r c (coordinatesState U r c p)) : | |
| smallKernel 0 U L C r c p = 0 := by | |
| let X := coordinatesState U r c p | |
| have hX := coordinatesState_supported U r c p | |
| have he : p = stateCoordinates U r c X := (stateCoordinates_coordinatesState U r c p).symm | |
| rw [he] | |
| unfold smallKernel balancedSlots | |
| rw [β Equiv.sum_comp (largeProfileEquiv U C r c)] | |
| simp_rw [balanced_fullCoordinates U C r c X hX] | |
| apply Finset.sum_eq_zero | |
| intro A hA | |
| rw [softWeight_zero,ite_eq_right] | |
| rintro β¨hb,ht,hpβ© | |
| exact hf (full_zero_feasible U L C r c X hX A hb hp) | |
| theorem smallKernel_continuous (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (p : SmallCoord U r c β β€) : Continuous (fun Ξ· : β => smallKernel Ξ· U L C r c p) := by | |
| unfold smallKernel balancedSlots | |
| apply continuous_finsetSum | |
| intro a _ | |
| exact softWeight_continuous _ _ _ _ _ _ _ | |
| theorem smallKernel_nonneg (Ξ· : β) (hΞ· : 0 β€ Ξ·) (U L C : β) | |
| (r : Fin m β β) (c : Fin n β β) (p : SmallCoord U r c β β€) : | |
| 0 β€ smallKernel Ξ· U L C r c p := by | |
| unfold smallKernel balancedSlots | |
| apply Finset.sum_nonneg | |
| intro a _ | |
| unfold softWeight | |
| dsimp only | |
| split_ifs | |
| Β· exact pow_nonneg hΞ· _ | |
| Β· rfl | |
| end Contingency.PaddedGraph | |
| open scoped BigOperators | |
| namespace Contingency | |
| section Nonnegative | |
| variable {Ξ± : Type*} [Fintype Ξ±] | |
| theorem weight_zero_of_total_zero (w : Ξ± β β) (hw : β x, 0 β€ w x) | |
| (hz : totalWeight w = 0) : β x, w x=0 := by | |
| have h := (Finset.sum_eq_zero_iff_of_nonneg fun x _ => hw x).mp hz | |
| exact fun x => h x (Finset.mem_univ x) | |
| theorem mass_mul_mean (w H : Ξ± β β) (hw : β x, 0 β€ w x) : | |
| totalWeight w*weightedMean w H = β x, w x*H x := by | |
| by_cases hz : totalWeight w = 0 | |
| Β· have h := weight_zero_of_total_zero w hw hz | |
| simp [hz,h] | |
| Β· unfold weightedMean | |
| exact mul_div_cancelβ _ hz | |
| theorem centered_sum_nonneg (w H : Ξ± β β) (hw : β x, 0 β€ w x) : | |
| (β x, w x*(H x-weightedMean w H))=0 := by | |
| simp only [mul_sub,Finset.sum_sub_distrib,β Finset.sum_mul] | |
| change (β x, w x*H x)-totalWeight w*weightedMean w H = 0 | |
| rw [mass_mul_mean w H hw,sub_self] | |
| theorem variance_translate_nonneg (w H : Ξ± β β) (hw : β x, 0 β€ w x) (a : β) : | |
| (β x, w x*(H x-a)^2) = | |
| weightedVariance w H + totalWeight w*(weightedMean w H-a)^2 := by | |
| have h (x : Ξ±) : w x*(H x-a)^2 = | |
| w x*(H x-weightedMean w H)^2 + | |
| 2*(weightedMean w H-a)*(w x*(H x-weightedMean w H)) + | |
| w x*(weightedMean w H-a)^2 := by ring | |
| simp only [h,Finset.sum_add_distrib,β Finset.mul_sum,β Finset.sum_mul] | |
| rw [centered_sum_nonneg w H hw] | |
| simp [weightedVariance,totalWeight] | |
| theorem variance_le_deviation (w H : Ξ± β β) (hw : β x, 0 β€ w x) (a : β) : | |
| weightedVariance w H β€ β x, w x*(H x-a)^2 := by | |
| rw [variance_translate_nonneg w H hw a] | |
| have hZ : 0 β€ totalWeight w := Finset.sum_nonneg fun x _ => hw x | |
| exact le_add_of_nonneg_right (mul_nonneg hZ (sq_nonneg _)) | |
| end Nonnegative | |
| section Decomposition | |
| variable {Ξ± Ξ² : Type*} [Fintype Ξ±] [Fintype Ξ²] | |
| theorem variance_decompose (w H : Ξ± Γ Ξ² β β) (hw : β x, 0 β€ w x) : | |
| weightedVariance w H = | |
| (β a, weightedVariance (fun b => w (a,b)) (fun b => H (a,b))) + | |
| weightedVariance (fun a => totalWeight (fun b => w (a,b))) | |
| (fun a => weightedMean (fun b => w (a,b)) (fun b => H (a,b))) := by | |
| have hmean : weightedMean w H = | |
| weightedMean (fun a => totalWeight (fun b => w (a,b))) | |
| (fun a => weightedMean (fun b => w (a,b)) (fun b => H (a,b))) := by | |
| unfold weightedMean | |
| congr 1 | |
| Β· simp_rw [show β a, totalWeight (fun b => w (a,b)) * | |
| ((β b, w (a,b)*H (a,b))/totalWeight (fun b => w (a,b))) = | |
| β b, w (a,b)*H (a,b) from fun a => mass_mul_mean _ _ (fun b => hw (a,b))] | |
| exact Fintype.sum_prod_type _ | |
| Β· simp [totalWeight,Fintype.sum_prod_type] | |
| unfold weightedVariance | |
| rw [Fintype.sum_prod_type] | |
| simp_rw [variance_translate_nonneg _ _ (fun b => hw (_,b)) (weightedMean w H)] | |
| rw [Finset.sum_add_distrib] | |
| rw [hmean] | |
| rfl | |
| end Decomposition | |
| def Profiles (C : β) : β β Type | |
| | 0 => PUnit | |
| | n+1 => Fin (C+1) Γ Profiles C n | |
| instance profilesFintype (C : β) : (n : β) β Fintype (Profiles C n) | |
| | 0 => inferInstanceAs (Fintype PUnit) | |
| | n+1 => letI := profilesFintype C n | |
| inferInstanceAs (Fintype (Fin (C+1) Γ Profiles C n)) | |
| def ExposureEnergies (C : β) : β β Type | |
| | 0 => PUnit | |
| | n+1 => β Γ (Fin (C+1) β ExposureEnergies C n) | |
| noncomputable def exposureEnergy (C : β) : (n : β) β ExposureEnergies C n β β | |
| | 0, _ => 0 | |
| | n+1, E => E.1 + β j, exposureEnergy C n (E.2 j) | |
| def ChildVarianceBounds (C : β) (A : β) : (n : β) β | |
| (Profiles C n β β) β (Profiles C n β β) β ExposureEnergies C n β Prop | |
| | 0, _, _, _ => True | |
| | n+1, w, H, E => | |
| weightedVariance (fun j => totalWeight (fun b => w (j,b))) | |
| (fun j => weightedMean (fun b => w (j,b)) (fun b => H (j,b))) β€ A*E.1 β§ | |
| β j, ChildVarianceBounds C A n (fun b => w (j,b)) (fun b => H (j,b)) (E.2 j) | |
| theorem exposure_variance_bound (C : β) (A : β) (n : β) | |
| (w H : Profiles C n β β) (hw : β x, 0 β€ w x) (E : ExposureEnergies C n) | |
| (h : ChildVarianceBounds C A n w H E) : | |
| weightedVariance w H β€ A*exposureEnergy C n E := by | |
| induction n with | |
| | zero => | |
| simp only [exposureEnergy,mul_zero] | |
| let : Unique (Profiles C 0) := inferInstanceAs (Unique PUnit) | |
| by_cases hz : w (default : Profiles C 0)=0 | |
| Β· simp [weightedVariance,hz] | |
| Β· simp [weightedVariance,weightedMean,totalWeight, | |
| mul_div_cancel_leftβ _ hz] | |
| | succ n ih => | |
| have hd := variance_decompose (Ξ±:=Fin (C+1)) (Ξ²:=Profiles C n) w H hw | |
| change weightedVariance w H = _ at hd | |
| rw [hd] | |
| change _ β€ A*(E.1 + β j, exposureEnergy C n (E.2 j)) | |
| have hb : (β j, weightedVariance (fun b => w (j,b)) (fun b => H (j,b))) β€ | |
| β j, A*exposureEnergy C n (E.2 j) := by | |
| apply Finset.sum_le_sum | |
| intro j hj | |
| exact ih _ _ (fun b => hw (j,b)) (E.2 j) (h.2 j) | |
| rw [β Finset.mul_sum] at hb | |
| dsimp only [ChildVarianceBounds] at h | |
| nlinarith [h.1] | |
| noncomputable def exposureLevel (C : β) : (n : β) β ExposureEnergies C n β β β β | |
| | 0, _, _ => 0 | |
| | _+1, E, 0 => E.1 | |
| | n+1, E, k+1 => β j, exposureLevel C n (E.2 j) k | |
| theorem exposureEnergy_levels (C n : β) (E : ExposureEnergies C n) : | |
| exposureEnergy C n E = β k β Finset.range n, exposureLevel C n E k := by | |
| induction n with | |
| | zero => simp [exposureEnergy] | |
| | succ n ih => | |
| rw [Finset.sum_range_succ'] | |
| simp only [exposureEnergy,exposureLevel] | |
| simp_rw [ih] | |
| rw [Finset.sum_comm] | |
| ring | |
| theorem exposure_variance_level_bound (C : β) (A : β) (hA : 0 β€ A) (n : β) | |
| (w H : Profiles C n β β) (hw : β x, 0 β€ w x) (E : ExposureEnergies C n) | |
| (h : ChildVarianceBounds C A n w H E) (G : β) | |
| (hlevel : β k < n, exposureLevel C n E k β€ G) : | |
| weightedVariance w H β€ (n:β)*A*G := by | |
| have he : exposureEnergy C n E β€ (n:β)*G := by | |
| rw [exposureEnergy_levels] | |
| calc | |
| _ β€ β k β Finset.range n, G := Finset.sum_le_sum fun k hk => hlevel k (Finset.mem_range.mp hk) | |
| _ = _ := by simp | |
| calc | |
| _ β€ A*exposureEnergy C n E := exposure_variance_bound C A n w H hw E h | |
| _ β€ A*((n:β)*G) := mul_le_mul_of_nonneg_left he hA | |
| _ = _ := by ring | |
| end Contingency | |
| open scoped BigOperators | |
| namespace Contingency | |
| noncomputable def nodeMass (C n : β) (f : (PairCoords Bool n β β€) β β) (j : β) : β := | |
| allBalance C n f (childProfile C j) | |
| noncomputable def nodeMean (C n : β) (f H : (PairCoords Bool n β β€) β β) (j : β) : β := | |
| nodeMass C n (fun x => f x*H x) j / nodeMass C n f j | |
| def adjacentDisplay (C j : β) : Bool β β€ := fun b => if b then (j:β€)+1 else (C:β€)-j | |
| @[simp] theorem adjacent_minus (C j : β) : | |
| removeOne (adjacentDisplay C j) true = childProfile C j := by | |
| funext b; cases b <;> simp [removeOne,adjacentDisplay,childProfile] | |
| @[simp] theorem adjacent_plus (C j : β) : | |
| removeOne (adjacentDisplay C j) false = childProfile C (j+1:β) := by | |
| funext b; cases b <;> simp [removeOne,adjacentDisplay,childProfile] | |
| ring | |
| theorem nodeMass_min (C : β) (hC : 2 β€ C) (n : β) | |
| (f : β β (PairCoords Bool n β β€) β β) | |
| (hc : β x, Continuous (fun Ξ· => f Ξ· x)) | |
| (hf : β Ξ·, 0 < Ξ· β Ξ· < 1 β PositiveSlice (f Ξ·) (fun _ => (C:β€)) (((n+1:β):β€)*C)) | |
| (hs : β Ξ·, 0 < Ξ· β Ξ· < 1 β HasSignature (f Ξ·) (fun _ => (C:β€)) (((n+1:β):β€)*C)) | |
| (a b j : β) (haj : a β€ j) (hjb : j β€ b) (hb : b β€ C) : | |
| min (nodeMass C n (f 0) a) (nodeMass C n (f 0) b) β€ nodeMass C n (f 0) j := by | |
| have hcl (Ξ· : β) (hΞ· : 0 < Ξ·) (hΞ·' : Ξ· < 1) := | |
| allBalance_closure C hC n (f Ξ·) (fun _ => (C:β€)) (((n+1:β):β€)*C) | |
| (by simpa only [pairBox_const] using hf Ξ· hΞ· hΞ·') | |
| (by simpa only [pairBox_const] using hs Ξ· hΞ· hΞ·') | |
| have ht : ((n+1:β):β€)*C-(n:β€)*C = C := by push_cast; ring | |
| simp only [ht] at hcl | |
| exact zero_child_min C (fun Ξ· => allBalance C n (f Ξ·)) | |
| (allBalance_continuous C n f hc) (fun Ξ· hΞ· hΞ·' => (hcl Ξ· hΞ· hΞ·').1) | |
| (fun Ξ· hΞ· hΞ·' => (hcl Ξ· hΞ· hΞ·').2) a b j (by positivity) | |
| (by exact_mod_cast haj) (by exact_mod_cast hjb) (by exact_mod_cast hb) | |
| theorem node_adjacent_bound (C : β) (hC : 2 β€ C) (n : β) | |
| (f : β β (PairCoords Bool n β β€) β β) | |
| (hc : β x, Continuous (fun Ξ· => f Ξ· x)) | |
| (hf : β Ξ·, 0 < Ξ· β Ξ· < 1 β PositiveSlice (f Ξ·) (fun _ => (C:β€)) (((n+1:β):β€)*C)) | |
| (hs : β Ξ·, 0 < Ξ· β Ξ· < 1 β HasSignature (f Ξ·) (fun _ => (C:β€)) (((n+1:β):β€)*C)) | |
| (hz : β x, 0 β€ f 0 x) (H : (PairCoords Bool n β β€) β β) | |
| (d : β) (hd : 0 β€ d) (j : β) (hj : j < C) | |
| (ha : auxiliaryMass n C (f 0) (adjacentDisplay C j) β€ | |
| d*max (nodeMass C n (f 0) j) (nodeMass C n (f 0) (j+1))) : | |
| min (nodeMass C n (f 0) j) (nodeMass C n (f 0) (j+1)) * | |
| (nodeMean C n (f 0) H j-nodeMean C n (f 0) H (j+1))^2 β€ | |
| (2+2*d*((C:β)+1)^2) * β e β smallUnitEdges C n, edgeEnergy (f 0) H e := by | |
| have hzm (i : β) : 0 β€ nodeMass C n (f 0) i := allBalance_nonneg C n (f 0) hz _ | |
| have hE : 0 β€ β e β smallUnitEdges C n, edgeEnergy (f 0) H e := | |
| Finset.sum_nonneg fun e _ => edgeEnergy_nonneg (f 0) H hz e | |
| have hA : 0 β€ 2+2*d*((C:β)+1)^2 := by positivity | |
| by_cases hm : nodeMass C n (f 0) j = 0 | |
| Β· rw [hm,min_eq_left (hzm (j+1)),zero_mul] | |
| exact mul_nonneg hA hE | |
| by_cases hp : nodeMass C n (f 0) (j+1) = 0 | |
| Β· rw [hp,min_eq_right (hzm j),zero_mul] | |
| exact mul_nonneg hA hE | |
| have hm' : 0 < nodeMass C n (f 0) j := lt_of_le_of_ne (hzm j) (Ne.symm hm) | |
| have hp' : 0 < nodeMass C n (f 0) (j+1) := lt_of_le_of_ne (hzm (j+1)) (Ne.symm hp) | |
| have hb : InBox (fun _ => (C:β€)) (adjacentDisplay C j) := by | |
| intro b; cases b <;> dsimp [adjacentDisplay] <;> omega | |
| have ht : adjacentDisplay C j true+adjacentDisplay C j false = (C:β€)+1 := by | |
| simp [adjacentDisplay]; ring | |
| have hv := zero_root_transport C hC n f hc hf hs H (adjacentDisplay C j) hb ht | |
| (by simpa only [minusMass,adjacent_minus,nodeMass] using hm') | |
| (by simpa only [plusMass,adjacent_plus,nodeMass] using hp') | |
| simp only [minusMass,plusMass,adjacent_minus,adjacent_plus] at hv | |
| exact transport_repair_arithmetic _ _ _ _ _ d C hm' hp' hE hd ha hv | |
| theorem node_variance_bound (C : β) (z H : β β β) (A E : β) | |
| (hz : β j β€ C, 0 β€ z j) (hA : 0 β€ A) (hE : 0 β€ E) | |
| (hmin : β a b j, a β€ j β j β€ b β b β€ C β min (z a) (z b) β€ z j) | |
| (hadj : β j < C, min (z j) (z (j+1))*(H j-H (j+1))^2 β€ A*E) : | |
| weightedVariance (fun j : Fin (C+1) => z j) (fun j => H j) β€ | |
| ((C:β)+1)^4*A*E := by | |
| let w : Fin (C+1) β β := fun j => z j | |
| have hw : β j, 0 β€ w j := fun j => hz j (by omega) | |
| have hZ : 0 β€ totalWeight w := Finset.sum_nonneg fun j _ => hw j | |
| by_cases hZ0 : totalWeight w = 0 | |
| Β· have hh := weight_zero_of_total_zero w hw hZ0 | |
| have he : weightedVariance w (fun j => H j)=0 := by | |
| unfold weightedVariance; simp only [hh,zero_mul,Finset.sum_const_zero] | |
| change weightedVariance w _ β€ _ | |
| rw [he]; positivity | |
| have hZ' : 0 < totalWeight w := lt_of_le_of_ne hZ (Ne.symm hZ0) | |
| have hzZ (j : β) (hj : j β€ C) : z j β€ totalWeight w := by | |
| exact Finset.single_le_sum (fun i _ => hw i) (Finset.mem_univ (β¨j,by omegaβ© : Fin (C+1))) | |
| have hp (a b : Fin (C+1)) : | |
| w a*w b/totalWeight w*(H a-H b)^2 β€ (C:β)^2*A*E := by | |
| rcases le_total a.val b.val with hab | hba | |
| Β· exact child_pair_bound C z H (totalWeight w) A E hZ' hz hzZ hA hE hmin hadj a b hab (by omega) | |
| Β· have hh := child_pair_bound C z H (totalWeight w) A E hZ' hz hzZ hA hE hmin hadj b a hba (by omega) | |
| have he : w a*w b/totalWeight w*(H a-H b)^2 = | |
| z b*z a/totalWeight w*(H b-H a)^2 := by dsimp [w]; ring | |
| rw [he]; exact hh | |
| have hv := variance_le_card_sq w (fun j => H j) hZ' ((C:β)^2*A*E) (by positivity) hp | |
| have hf : ((C:β)+1)^2*(C:β)^2 β€ ((C:β)+1)^4 := by | |
| have hh : (C:β)^2 β€ ((C:β)+1)^2 := by nlinarith [Nat.cast_nonneg (Ξ±:=β) C] | |
| calc | |
| _ β€ ((C:β)+1)^2*((C:β)+1)^2 := mul_le_mul_of_nonneg_left hh (sq_nonneg _) | |
| _ = _ := by ring | |
| calc | |
| _ β€ (Fintype.card (Fin (C+1)):β)^2*((C:β)^2*A*E) := hv | |
| _ = (((C:β)+1)^2*(C:β)^2)*(A*E) := by simp; ring | |
| _ β€ ((C:β)+1)^4*(A*E) := mul_le_mul_of_nonneg_right hf (mul_nonneg hA hE) | |
| _ = _ := by ring | |
| end Contingency | |
| end | |
| end OAI | |