Download data/lean/OAI/Probability/Contingency/ConditionalTransport.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 33.2 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Contingency/ConditionalTransport.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/Contingency/ConditionalTransport.lean
-
curl -L -o ConditionalTransport.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Contingency/ConditionalTransport.lean
33.2 kB
| import Mathlib | |
| import OAI.Probability.Contingency.ConcreteContexts | |
| namespace OAI | |
| /-! Conditional Transport. -/ | |
| noncomputable section | |
| open scoped BigOperators | |
| open scoped BigOperators | |
| namespace Contingency.PaddedGraph | |
| variable {m n : β} | |
| variable (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| noncomputable def repairedChild (j : β) (t : Fin a) : β := | |
| if (suffixSlot U r c k a h t.succ).val.1=(suffixSlot U r c k a h 0).val.1 then j+1 else j | |
| abbrev FeasibleBranches (j : β) (t : Fin a) := | |
| {Ξ± : β v, Fin (surplusCaps U a t v+1) // Feasible U r c (defectState U r c k a h Ο j t Ξ±)} | |
| noncomputable instance feasibleBranchesFintype (j : β) (t : Fin a) : | |
| Fintype (FeasibleBranches U r c k a h Ο j t) := by | |
| classical | |
| unfold FeasibleBranches | |
| infer_instance | |
| noncomputable def repairedBranch (j : β) (t : Fin a) (Ξ± : FeasibleBranches U r c k a h Ο j t) : | |
| Fin a β Fin (U+1) := | |
| stateSuffix U r c k a h | |
| (repair U r c (suffixSlot U r c k a h 0).val (suffixSlot U r c k a h t.succ).val | |
| (defectState U r c k a h Ο j t Ξ±.val)) | |
| (repair_feasible U r c _ _ _ Ξ±.property (defectState_defect U r c k a h Ο j t Ξ±.val)) | |
| theorem repairedBranch_state (j : β) (t : Fin a) (Ξ± : FeasibleBranches U r c k a h Ο j t) : | |
| contextState U r c k a h Ο (mixedDisplay a (fun _ => U) | |
| (childProfile U (repairedChild U r c k a h j t)) (repairedBranch U r c k a h Ο j t Ξ±)) = | |
| repair U r c (suffixSlot U r c k a h 0).val (suffixSlot U r c k a h t.succ).val | |
| (defectState U r c k a h Ο j t Ξ±.val) := by | |
| apply contextState_reconstruct | |
| Β· exact repair_transversal U r c _ _ _ | |
| Β· intro v | |
| have hp := repair_prefix U r c _ _ _ (defectState_defect U r c k a h Ο j t Ξ±.val) | |
| (suffix_before U r c k a h 0 t.succ (Fin.succ_pos t)) | |
| (prefixSlot U r c k a h v).val (prefix_before_suffix U r c k a h v 0) | |
| exact hp.1.trans (contextState_prefix U r c k a h Ο _ v).1 | |
| Β· have hs := repair_special U r c _ _ _ (defectState_defect U r c k a h Ο j t Ξ±.val) | |
| ((j:β€)+1) (by simp) | |
| simpa only [repairedChild, Nat.cast_ite,Nat.cast_add,Nat.cast_one,add_sub_cancel_right] using hs | |
| theorem repairedBranch_injective (j : β) (t : Fin a) : | |
| Function.Injective (repairedBranch U r c k a h Ο j t) := by | |
| intro Ξ± Ξ² he | |
| apply Subtype.ext | |
| have hs := congrArg (fun v => contextState U r c k a h Ο (mixedDisplay a (fun _ => U) | |
| (childProfile U (repairedChild U r c k a h j t)) v)) he | |
| rw [repairedBranch_state,repairedBranch_state] at hs | |
| have hx := repair_injective U r c _ _ _ _ (defectState_defect U r c k a h Ο j t Ξ±.val) | |
| (defectState_defect U r c k a h Ο j t Ξ².val) hs | |
| exact mixedDisplay_injective a _ _ (contextState_injective U r c k a h Ο hx) | |
| theorem mixedBalance_repair (hrc : (β i, r i)=β j, c j) | |
| (hC : β i, paddedRow U L r c i β€ C) (j : β) (t : Fin a) : | |
| mixedBalance a (surplusCaps U a t) (contextKernel 0 U L C r c k a h Ο) (defectProfile U j) β€ | |
| nodeMass U a (contextKernel 0 U L C r c k a h Ο) (repairedChild U r c k a h j t) := by | |
| classical | |
| let P : (β v, Fin (surplusCaps U a t v+1)) β Prop := | |
| fun Ξ± => Feasible U r c (defectState U r c k a h Ο j t Ξ±) | |
| let F := fun Ξ± => contextKernel 0 U L C r c k a h Ο | |
| (mixedDisplay a (surplusCaps U a t) (defectProfile U j) Ξ±) | |
| let G := fun Ξ² => contextKernel 0 U L C r c k a h Ο | |
| (mixedDisplay a (fun _ => U) (childProfile U (repairedChild U r c k a h j t)) Ξ²) | |
| have h0 (Ξ± : β v, Fin (surplusCaps U a t v+1)) (hΞ± : Β¬P Ξ±) : F Ξ±=0 := | |
| smallKernel_zero_infeasible U L C r c _ hΞ± | |
| have hsum : (β Ξ± : FeasibleBranches U r c k a h Ο j t, F Ξ±.val) = β Ξ±, F Ξ± := by | |
| have he := Fintype.sum_subtype_add_sum_subtype P F | |
| have hz : (β Ξ± : {Ξ± // Β¬P Ξ±}, F Ξ±.val)=0 := | |
| Finset.sum_eq_zero fun Ξ± _ => h0 Ξ±.val Ξ±.property | |
| rw [hz,add_zero] at he | |
| exact he | |
| have hle (Ξ± : FeasibleBranches U r c k a h Ο j t) : | |
| F Ξ±.val β€ G (repairedBranch U r c k a h Ο j t Ξ±) := by | |
| dsimp [F,G] | |
| rw [contextKernel_weight U L C r c hrc hC,contextKernel_weight U L C r c hrc hC, | |
| repairedBranch_state] | |
| exact_mod_cast weight_repair_le U L r c _ _ _ (defectState_defect U r c k a h Ο j t Ξ±.val) | |
| have hg (Ξ² : Fin a β Fin (U+1)) : 0 β€ G Ξ² := contextKernel_nonneg U L C r c k a h Ο _ | |
| change (β Ξ±, F Ξ±) β€ _ | |
| rw [β hsum] | |
| change _ β€ allBalance U a (contextKernel 0 U L C r c k a h Ο) | |
| (childProfile U (repairedChild U r c k a h j t)) | |
| rw [allBalance_mixed] | |
| change _ β€ β Ξ², G Ξ² | |
| calc | |
| _ β€ β Ξ± : FeasibleBranches U r c k a h Ο j t, G (repairedBranch U r c k a h Ο j t Ξ±) := | |
| Finset.sum_le_sum fun Ξ± _ => hle Ξ± | |
| _ = β Ξ² β Finset.univ.image (repairedBranch U r c k a h Ο j t), G Ξ² := by | |
| rw [Finset.sum_image (fun x _ y _ he => repairedBranch_injective U r c k a h Ο j t he)] | |
| _ β€ β Ξ², G Ξ² := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) | |
| (fun Ξ² _ _ => hg Ξ²) | |
| theorem mixedBalance_repair_max (hrc : (β i, r i)=β j, c j) | |
| (hC : β i, paddedRow U L r c i β€ C) (j : β) (t : Fin a) : | |
| mixedBalance a (surplusCaps U a t) (contextKernel 0 U L C r c k a h Ο) (defectProfile U j) β€ | |
| max (nodeMass U a (contextKernel 0 U L C r c k a h Ο) j) | |
| (nodeMass U a (contextKernel 0 U L C r c k a h Ο) (j+1)) := by | |
| have hh := mixedBalance_repair U L C r c k a h Ο hrc hC j t | |
| unfold repairedChild at hh | |
| split_ifs at hh | |
| Β· exact hh.trans (le_max_right _ _) | |
| Β· exact hh.trans (le_max_left _ _) | |
| theorem context_auxiliary_bound (hrc : (β i, r i)=β j, c j) | |
| (hC : β i, paddedRow U L r c i β€ C) (j : β) : | |
| auxiliaryMass a U (contextKernel 0 U L C r c k a h Ο) (adjacentDisplay U j) β€ | |
| (a:β)*max (nodeMass U a (contextKernel 0 U L C r c k a h Ο) j) | |
| (nodeMass U a (contextKernel 0 U L C r c k a h Ο) (j+1)) := by | |
| rw [auxiliaryMass,adjacent_removePair,allSurplus_sum_types] | |
| calc | |
| _ β€ β t : Fin a, max (nodeMass U a (contextKernel 0 U L C r c k a h Ο) j) | |
| (nodeMass U a (contextKernel 0 U L C r c k a h Ο) (j+1)) := | |
| Finset.sum_le_sum fun t _ => mixedBalance_repair_max U L C r c k a h Ο hrc hC j t | |
| _ = _ := by simp | |
| theorem concrete_conditional_transport (hU : 2 β€ U) (hC2 : 2 β€ C) | |
| (hrc : (β i, r i)=β j, c j) (hC : β i, paddedRow U L r c i β€ C) | |
| (H : (PairCoords Bool a β β€) β β) (j : β) (hj : j<U) : | |
| min (nodeMass U a (contextKernel 0 U L C r c k a h Ο) j) | |
| (nodeMass U a (contextKernel 0 U L C r c k a h Ο) (j+1)) * | |
| (nodeMean U a (contextKernel 0 U L C r c k a h Ο) H j- | |
| nodeMean U a (contextKernel 0 U L C r c k a h Ο) H (j+1))^2 β€ | |
| (2+2*(a:β)*((U:β)+1)^2) * β e β smallUnitEdges U a, | |
| edgeEnergy (contextKernel 0 U L C r c k a h Ο) H e := | |
| node_adjacent_bound U hU a _ (contextKernel_continuous U L C r c k a h Ο) | |
| (fun Ξ· hΞ· hΞ·' => (contextKernel_signature Ξ· hΞ· hΞ·' U L C hC2 r c k a h Ο).1) | |
| (fun Ξ· hΞ· hΞ·' => (contextKernel_signature Ξ· hΞ· hΞ·' U L C hC2 r c k a h Ο).2) | |
| (contextKernel_nonneg U L C r c k a h Ο) H a (by positivity) j hj | |
| (context_auxiliary_bound U L C r c k a h Ο hrc hC j) | |
| theorem concrete_node_variance (hU : 2 β€ U) (hC2 : 2 β€ C) | |
| (hrc : (β i, r i)=β j, c j) (hC : β i, paddedRow U L r c i β€ C) | |
| (H : (PairCoords Bool a β β€) β β) : | |
| weightedVariance (fun j : Fin (U+1) => nodeMass U a (contextKernel 0 U L C r c k a h Ο) j) | |
| (fun j => nodeMean U a (contextKernel 0 U L C r c k a h Ο) H j) β€ | |
| ((U:β)+1)^4*(2+2*(a:β)*((U:β)+1)^2) * β e β smallUnitEdges U a, | |
| edgeEnergy (contextKernel 0 U L C r c k a h Ο) H e := by | |
| apply node_variance_bound | |
| Β· intro j hj | |
| exact allBalance_nonneg U a _ (contextKernel_nonneg U L C r c k a h Ο) _ | |
| Β· positivity | |
| Β· exact Finset.sum_nonneg fun e _ => | |
| edgeEnergy_nonneg _ H (contextKernel_nonneg U L C r c k a h Ο) e | |
| Β· exact context_child_no_holes U L C hU hC2 r c k a h Ο | |
| Β· exact concrete_conditional_transport U L C r c k a h Ο hU hC2 hrc hC H | |
| end Contingency.PaddedGraph | |
| open scoped BigOperators | |
| namespace Contingency | |
| noncomputable def profileEquiv (C : β) : (n : β) β Profiles C n β (Fin n β Fin (C+1)) | |
| | 0 => { toFun := fun _ i => Fin.elim0 i | |
| invFun := fun _ => PUnit.unit | |
| left_inv := fun x => by cases x; rfl | |
| right_inv := fun x => by funext i; exact Fin.elim0 i } | |
| | n+1 => ((Equiv.refl (Fin (C+1))).prodCongr (profileEquiv C n)).trans | |
| (piHeadEquiv (fun _ : Fin (n+1) => Fin (C+1))).symm | |
| @[simp] theorem profileEquiv_succ (C n : β) (j : Fin (C+1)) (Ξ± : Profiles C n) : | |
| profileEquiv C (n+1) (j,Ξ±) = Fin.cons j (profileEquiv C n Ξ±) := rfl | |
| namespace PaddedGraph | |
| variable {m n : β} | |
| noncomputable def tupleState (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (Ξ± : SmallSlot U r c β Fin (U+1)) : State m n := | |
| coordinatesState U r c (fun w => if w.2 then (Ξ± w.1:β) else (U:β€)-(Ξ± w.1:β)) | |
| @[simp] theorem tupleState_x (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (Ξ± : SmallSlot U r c β Fin (U+1)) (s : SmallSlot U r c) : | |
| (tupleState U r c Ξ±).x s.val=(Ξ± s:β) := by simp [tupleState] | |
| @[simp] theorem tupleState_q (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (Ξ± : SmallSlot U r c β Fin (U+1)) (s : SmallSlot U r c) : | |
| (tupleState U r c Ξ±).q s.val=(Ξ± s:β) := by simp [tupleState] | |
| noncomputable def appendAssignment (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+a) | |
| (Ο : Fin k β Fin (U+1)) (Ο : Fin a β Fin (U+1)) : SmallSlot U r c β Fin (U+1) := | |
| Fin.append Ο Ο β finCongr h β (smallIndex U r c).symm | |
| @[simp] theorem appendAssignment_prefix (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (Ο : Fin (a+1) β Fin (U+1)) (s : Fin k) : | |
| appendAssignment U r c k (a+1) h Ο Ο (prefixSlot U r c k a h s)=Ο s := by | |
| simp only [appendAssignment,Function.comp_apply,prefixSlot,splitSlots,Equiv.symm_trans_apply, | |
| Equiv.symm_symm,Equiv.symm_apply_apply,Equiv.apply_symm_apply] | |
| exact Fin.append_left Ο Ο s | |
| @[simp] theorem appendAssignment_suffix (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (Ο : Fin (a+1) β Fin (U+1)) (s : Fin (a+1)) : | |
| appendAssignment U r c k (a+1) h Ο Ο (suffixSlot U r c k a h s)=Ο s := by | |
| simp only [appendAssignment,Function.comp_apply,suffixSlot,splitSlots,Equiv.symm_trans_apply, | |
| Equiv.symm_symm,Equiv.symm_apply_apply,Equiv.apply_symm_apply] | |
| exact Fin.append_right Ο Ο s | |
| @[simp] theorem appendAssignment_cons (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (j : Fin (U+1)) (Ο : Fin a β Fin (U+1)) : | |
| appendAssignment U r c k (a+1) h Ο (Fin.cons j Ο) = | |
| appendAssignment U r c (k+1) a (by omega) (Fin.snoc Ο j) Ο := by | |
| funext s | |
| simp only [appendAssignment,Function.comp_apply,Fin.append_right_cons] | |
| rfl | |
| noncomputable def profileState (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+a) (Ο : Fin k β Fin (U+1)) | |
| (Ο : Profiles U a) : State m n := | |
| tupleState U r c (appendAssignment U r c k a h Ο (profileEquiv U a Ο)) | |
| @[simp] theorem profileState_succ (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (j : Fin (U+1)) (Ο : Profiles U a) : | |
| profileState U r c k (a+1) h Ο (j,Ο) = | |
| profileState U r c (k+1) a (by omega) (Fin.snoc Ο j) Ο := by | |
| simp only [profileState,profileEquiv_succ,appendAssignment_cons] | |
| theorem contextState_profile (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (j : Fin (U+1)) (Ο : Profiles U a) : | |
| contextState U r c k a h Ο | |
| (mixedDisplay a (fun _ => U) (childProfile U j) (profileEquiv U a Ο)) = | |
| profileState U r c k (a+1) h Ο (j,Ο) := by | |
| apply State.ext <;> funext w | |
| all_goals | |
| by_cases hw : IsSmall U r c w | |
| Β· rcases slot_cases U r c k a h β¨w,hwβ© with β¨s,hsβ© | β¨s,hsβ© | |
| Β· have he : w = _ := congrArg Subtype.val hs | |
| subst w | |
| simp only [profileState,profileEquiv_succ,tupleState_x,tupleState_q, | |
| appendAssignment_prefix] | |
| first | exact (contextState_prefix U r c k a h Ο _ s).1 | | |
| exact (contextState_prefix U r c k a h Ο _ s).2 | |
| Β· have he : w = _ := congrArg Subtype.val hs | |
| subst w | |
| simp only [profileState,profileEquiv_succ,tupleState_x,tupleState_q, | |
| appendAssignment_suffix] | |
| first | |
| | rw [(contextState_suffix U r c k a h Ο _ s).1] | |
| | rw [(contextState_suffix U r c k a h Ο _ s).2] | |
| all_goals | |
| refine Fin.cases ?_ (fun v => ?_) s | |
| Β· simp [mixedDisplay_current,childProfile] | |
| Β· simp [mixedDisplay_ordinary] | |
| Β· have hl : IsLarge U r c w := Classical.not_not.mp hw | |
| have h1 := contextState_supported U r c k a h Ο | |
| (mixedDisplay a (fun _ => U) (childProfile U j) (profileEquiv U a Ο)) w hl | |
| have h2 := coordinatesState_supported U r c | |
| (fun w => if w.2 then | |
| (appendAssignment U r c k (a+1) h Ο (profileEquiv U (a+1) (j,Ο)) w.1:β) | |
| else (U:β€)-(appendAssignment U r c k (a+1) h Ο (profileEquiv U (a+1) (j,Ο)) w.1:β)) w hl | |
| first | exact h1.1.trans h2.1.symm | exact h1.2.trans h2.2.symm | |
| theorem nodeMass_profile (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (hrc : (β i, r i)=β j, c j) (hC : β i, paddedRow U L r c i β€ C) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (j : Fin (U+1)) : | |
| nodeMass U a (contextKernel 0 U L C r c k a h Ο) j = | |
| totalWeight (fun Ο : Profiles U a => | |
| (weight U L r c (profileState U r c k (a+1) h Ο (j,Ο)):β)) := by | |
| rw [nodeMass,allBalance_mixed] | |
| unfold mixedBalance totalWeight | |
| rw [β Equiv.sum_comp (profileEquiv U a)] | |
| apply Finset.sum_congr rfl | |
| intro Ο hΟ | |
| rw [contextKernel_weight U L C r c hrc hC,contextState_profile] | |
| theorem nodeMean_profile (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (hrc : (β i, r i)=β j, c j) (hC : β i, paddedRow U L r c i β€ C) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (H : State m n β β) (j : Fin (U+1)) : | |
| nodeMean U a (contextKernel 0 U L C r c k a h Ο) | |
| (H β contextState U r c k a h Ο) j = | |
| weightedMean (fun Ο : Profiles U a => | |
| (weight U L r c (profileState U r c k (a+1) h Ο (j,Ο)):β)) | |
| (fun Ο => H (profileState U r c k (a+1) h Ο (j,Ο))) := by | |
| rw [nodeMean,nodeMass_profile U L C r c hrc hC] | |
| unfold weightedMean | |
| congr 1 | |
| rw [nodeMass,allBalance_mixed] | |
| unfold mixedBalance | |
| rw [β Equiv.sum_comp (profileEquiv U a)] | |
| apply Finset.sum_congr rfl | |
| intro Ο hΟ | |
| simp only [Function.comp_apply,contextKernel_weight U L C r c hrc hC,contextState_profile] | |
| end PaddedGraph | |
| end Contingency | |
| open scoped BigOperators | |
| namespace Contingency.PaddedGraph | |
| variable {m n : β} | |
| noncomputable def contextEnergy (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (H : State m n β β) : β := | |
| β e β smallUnitEdges U a, edgeEnergy (contextKernel 0 U L C r c k a h Ο) | |
| (H β contextState U r c k a h Ο) e | |
| theorem contextEnergy_nonneg (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (H : State m n β β) : 0 β€ contextEnergy U L C r c k a h Ο H := | |
| Finset.sum_nonneg fun e _ => edgeEnergy_nonneg _ _ (contextKernel_nonneg U L C r c k a h Ο) e | |
| noncomputable def contextTree (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (H : State m n β β) : (a k : β) β | |
| (h : Fintype.card (SmallSlot U r c)=k+a) β (Fin k β Fin (U+1)) β ExposureEnergies U a | |
| | 0, _, _, _ => PUnit.unit | |
| | a+1, k, h, Ο => (contextEnergy U L C r c k a h Ο H, | |
| fun j => contextTree U L C r c H a (k+1) (by omega) (Fin.snoc Ο j)) | |
| theorem local_constant_le (U d a : β) (_hd : 1 β€ d) (ha : a<d) : | |
| ((U:β)+1)^4*(2+2*(a:β)*((U:β)+1)^2) β€ 4*(d:β)*((U:β)+1)^6 := by | |
| have hU : 1 β€ ((U:β)+1)^2 := by nlinarith [show 0 β€ (U:β) by positivity] | |
| have had : (a:β)+1 β€ d := by exact_mod_cast ha | |
| have h1 : 2+2*(a:β)*((U:β)+1)^2 β€ 4*(d:β)*((U:β)+1)^2 := by | |
| have ha0 : 0 β€ (a:β) := by positivity | |
| have hmul := mul_le_mul_of_nonneg_right had (show 0 β€ ((U:β)+1)^2 by positivity) | |
| nlinarith | |
| calc | |
| _ β€ ((U:β)+1)^4*(4*(d:β)*((U:β)+1)^2) := mul_le_mul_of_nonneg_left h1 (by positivity) | |
| _ = _ := by ring | |
| theorem contextTree_childBounds (U L C d : β) (r : Fin m β β) (c : Fin n β β) | |
| (hU : 2 β€ U) (hC2 : 2 β€ C) (hd : 1 β€ d) (hslots : Fintype.card (SmallSlot U r c) β€ d) | |
| (hrc : (β i, r i)=β j, c j) (hC : β i, paddedRow U L r c i β€ C) | |
| (H : State m n β β) (a k : β) (h : Fintype.card (SmallSlot U r c)=k+a) | |
| (Ο : Fin k β Fin (U+1)) : | |
| ChildVarianceBounds U (4*(d:β)*((U:β)+1)^6) a | |
| (fun Ο => (weight U L r c (profileState U r c k a h Ο Ο):β)) | |
| (fun Ο => H (profileState U r c k a h Ο Ο)) | |
| (contextTree U L C r c H a k h Ο) := by | |
| induction a generalizing k with | |
| | zero => trivial | |
| | succ a ih => | |
| constructor | |
| Β· change weightedVariance | |
| (fun j => totalWeight (fun Ο : Profiles U a => | |
| (weight U L r c (profileState U r c k (a+1) h Ο (j,Ο)):β))) | |
| (fun j => weightedMean | |
| (fun Ο : Profiles U a => (weight U L r c (profileState U r c k (a+1) h Ο (j,Ο)):β)) | |
| (fun Ο => H (profileState U r c k (a+1) h Ο (j,Ο)))) β€ | |
| (4*(d:β)*((U:β)+1)^6)*contextEnergy U L C r c k a h Ο H | |
| simp_rw [β nodeMass_profile U L C r c hrc hC, β nodeMean_profile U L C r c hrc hC] | |
| have hb := concrete_node_variance U L C r c k a h Ο hU hC2 hrc hC | |
| (H β contextState U r c k a h Ο) | |
| exact hb.trans (mul_le_mul_of_nonneg_right (local_constant_le U d a hd (by omega)) | |
| (contextEnergy_nonneg U L C r c k a h Ο H)) | |
| Β· intro j | |
| simpa only [profileState_succ,contextTree] using ih (k+1) (by omega) (Fin.snoc Ο j) | |
| theorem concrete_exposure_variance (U L C d : β) (r : Fin m β β) (c : Fin n β β) | |
| (hU : 2 β€ U) (hC2 : 2 β€ C) (hd : 1 β€ d) (hslots : Fintype.card (SmallSlot U r c) β€ d) | |
| (hrc : (β i, r i)=β j, c j) (hC : β i, paddedRow U L r c i β€ C) | |
| (H : State m n β β) (a k : β) (h : Fintype.card (SmallSlot U r c)=k+a) | |
| (Ο : Fin k β Fin (U+1)) : | |
| weightedVariance | |
| (fun Ο => (weight U L r c (profileState U r c k a h Ο Ο):β)) | |
| (fun Ο => H (profileState U r c k a h Ο Ο)) β€ | |
| 4*(d:β)*((U:β)+1)^6 * exposureEnergy U a (contextTree U L C r c H a k h Ο) := | |
| exposure_variance_bound U _ a _ _ (fun Ο => by positivity) _ | |
| (contextTree_childBounds U L C d r c hU hC2 hd hslots hrc hC H a k h Ο) | |
| end Contingency.PaddedGraph | |
| open scoped BigOperators | |
| namespace Contingency.PaddedGraph | |
| variable {m n : β} | |
| noncomputable def fullOccupancy (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (p : SmallCoord U r c β β€) (s : SmallSlot U r c) : β€ := p (s,true)+p (s,false) | |
| def fullPattern (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (p : SmallCoord U r c β β€) : Prop := | |
| (β s, fullOccupancy U r c p s=U) β¨ | |
| β s t, sβ t β§ fullOccupancy U r c p s=(U:β€)-1 β§ fullOccupancy U r c p t=(U:β€)+1 β§ | |
| β v, vβ s β vβ t β fullOccupancy U r c p v=U | |
| noncomputable def fullVertices (U : β) (r : Fin m β β) (c : Fin n β β) : | |
| Finset (SmallCoord U r c β β€) := by | |
| classical | |
| exact (Fintype.piFinset (fun _ => Finset.Icc 0 (U:β€))).filter (fullPattern U r c) | |
| theorem mem_fullVertices (U : β) (r : Fin m β β) (c : Fin n β β) (p : SmallCoord U r c β β€) : | |
| pβfullVertices U r c β InBox (fun _ => (U:β€)) p β§ fullPattern U r c p := by | |
| classical | |
| simp [fullVertices,Fintype.mem_piFinset,InBox] | |
| noncomputable def fullUnitEdges (U : β) (r : Fin m β β) (c : Fin n β β) : | |
| Finset (Sym2 (SmallCoord U r c β β€)) := by | |
| classical | |
| exact (fullVertices U r c).sym2.filter (fun e => β D i j, iβ j β§ | |
| e=s(removeOne D i,removeOne D j)) | |
| noncomputable def contextDisplay (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (p : PairCoords Bool a β β€) : SmallCoord U r c β β€ := | |
| Sum.elim (balanceProfile (fun _ => U) Ο) p β contextCoordinates U r c k a h | |
| @[simp] theorem contextDisplay_prefix (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (p : PairCoords Bool a β β€) (s : Fin k) (b : Bool) : | |
| contextDisplay U r c k a h Ο p (prefixSlot U r c k a h s,b) = | |
| if b then ((Ο s:β):β€) else (U:β€)-(Ο s:β) := by simp [contextDisplay,balanceProfile] | |
| @[simp] theorem contextDisplay_suffix (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (p : PairCoords Bool a β β€) (s : Fin (a+1)) (b : Bool) : | |
| contextDisplay U r c k a h Ο p (suffixSlot U r c k a h s,b) = | |
| p ((smallCoords a).symm (s,b)) := by simp [contextDisplay] | |
| theorem contextDisplay_joint_inj (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) | |
| (Ο Ο : Fin k β Fin (U+1)) (p q : PairCoords Bool a β β€) | |
| (he : contextDisplay U r c k a h Ο p=contextDisplay U r c k a h Ο q) : Ο=Ο β§ p=q := by | |
| constructor | |
| Β· funext s | |
| have hh := congrFun he (prefixSlot U r c k a h s,true) | |
| simp only [contextDisplay_prefix,ite_true] at hh | |
| apply Fin.ext | |
| exact_mod_cast hh | |
| Β· funext i | |
| have hh := congrFun he ((contextCoordinates U r c k a h).symm (.inr i)) | |
| simpa [contextDisplay] using hh | |
| theorem contextDisplay_box (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (p : PairCoords Bool a β β€) (hp : InBox (fun _ => (U:β€)) p) : | |
| InBox (fun _ => (U:β€)) (contextDisplay U r c k a h Ο p) := by | |
| intro w | |
| obtain β¨z,rflβ© := (contextCoordinates U r c k a h).symm.surjective w | |
| cases z with | |
| | inl z => simpa [contextDisplay] using balanceProfile_box U k Ο z | |
| | inr z => simpa [contextDisplay] using hp z | |
| theorem contextDisplay_pattern (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (p : PairCoords Bool a β β€) (hp : smallPattern U a p) : | |
| fullPattern U r c (contextDisplay U r c k a h Ο p) := by | |
| have hpre (s : Fin k) : fullOccupancy U r c (contextDisplay U r c k a h Ο p) | |
| (prefixSlot U r c k a h s)=U := by simp [fullOccupancy] | |
| have hsuf (s : Fin (a+1)) : fullOccupancy U r c (contextDisplay U r c k a h Ο p) | |
| (suffixSlot U r c k a h s)=smallOccupancy a p s := by simp [fullOccupancy,smallOccupancy] | |
| rcases hp with ht | β¨s,t,hst,hs,ht,hrestβ© | |
| Β· left | |
| intro w | |
| rcases slot_cases U r c k a h w with β¨s,rflβ© | β¨s,rflβ© | |
| Β· exact hpre s | |
| Β· rw [hsuf,ht] | |
| Β· right | |
| refine β¨suffixSlot U r c k a h s,suffixSlot U r c k a h t,?_,?_,?_,?_β© | |
| Β· intro he | |
| have hh := congrArg Subtype.val he | |
| exact hst ((suffixSlot_val_inj U r c k a h s t).mp hh) | |
| Β· rw [hsuf,hs] | |
| Β· rw [hsuf,ht] | |
| Β· intro w hws hwt | |
| rcases slot_cases U r c k a h w with β¨v,rflβ© | β¨v,rflβ© | |
| Β· exact hpre v | |
| Β· rw [hsuf] | |
| exact hrest v (fun he => hws (congrArg _ he)) (fun he => hwt (congrArg _ he)) | |
| theorem contextDisplay_vertex (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (p : PairCoords Bool a β β€) (hp : pβsmallVertexSet U a) : | |
| contextDisplay U r c k a h Ο pβfullVertices U r c := by | |
| rw [mem_smallVertexSet] at hp | |
| exact (mem_fullVertices U r c _).mpr β¨contextDisplay_box U r c k a h Ο p hp.1, | |
| contextDisplay_pattern U r c k a h Ο p hp.2β© | |
| theorem contextDisplay_removeOne (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (p : PairCoords Bool a β β€) (i : PairCoords Bool a) : | |
| contextDisplay U r c k a h Ο (removeOne p i) = | |
| removeOne (contextDisplay U r c k a h Ο p) ((contextCoordinates U r c k a h).symm (.inr i)) := by | |
| funext w | |
| obtain β¨z,rflβ© := (contextCoordinates U r c k a h).symm.surjective w | |
| cases z with | |
| | inl z => simp [contextDisplay,removeOne] | |
| | inr z => simp [contextDisplay,removeOne] | |
| noncomputable def contextEdge (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) | |
| (e : (Fin k β Fin (U+1)) Γ Sym2 (PairCoords Bool a β β€)) : Sym2 (SmallCoord U r c β β€) := | |
| Sym2.map (contextDisplay U r c k a h e.1) e.2 | |
| theorem contextEdge_injective (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) : | |
| Function.Injective (contextEdge U r c k a h) := by | |
| rintro β¨Ο,eβ© β¨Ο,fβ© he | |
| refine Sym2.inductionOnβ e f (fun x y z w => ?_) he | |
| intro he | |
| change s(contextDisplay U r c k a h Ο x,contextDisplay U r c k a h Ο y)= | |
| s(contextDisplay U r c k a h Ο z,contextDisplay U r c k a h Ο w) at he | |
| rcases Sym2.eq_iff.mp he with β¨hx,hyβ© | β¨hx,hyβ© | |
| Β· obtain β¨rfl,rflβ© := contextDisplay_joint_inj U r c k a h Ο Ο x z hx | |
| obtain β¨_,rflβ© := contextDisplay_joint_inj U r c k a h Ο Ο y w hy | |
| rfl | |
| Β· obtain β¨rfl,rflβ© := contextDisplay_joint_inj U r c k a h Ο Ο x w hx | |
| obtain β¨_,rflβ© := contextDisplay_joint_inj U r c k a h Ο Ο y z hy | |
| exact Prod.ext rfl Sym2.eq_swap | |
| theorem contextEdge_mem (U : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (e : Sym2 (PairCoords Bool a β β€)) (he : eβsmallUnitEdges U a) : | |
| contextEdge U r c k a h (Ο,e)βfullUnitEdges U r c := by | |
| classical | |
| obtain β¨hv,D,i,j,hij,rflβ© := Finset.mem_filter.mp he | |
| rw [Finset.mk_mem_sym2_iff] at hv | |
| apply Finset.mem_filter.mpr | |
| constructor | |
| Β· change s(contextDisplay U r c k a h Ο (removeOne D i), | |
| contextDisplay U r c k a h Ο (removeOne D j)) β (fullVertices U r c).sym2 | |
| exact Finset.mk_mem_sym2_iff.mpr β¨contextDisplay_vertex U r c k a h Ο _ hv.1, | |
| contextDisplay_vertex U r c k a h Ο _ hv.2β© | |
| Β· refine β¨contextDisplay U r c k a h Ο D, | |
| (contextCoordinates U r c k a h).symm (.inr i), | |
| (contextCoordinates U r c k a h).symm (.inr j),?_,?_β© | |
| Β· intro he | |
| exact hij (Sum.inr.inj ((contextCoordinates U r c k a h).symm.injective he)) | |
| Β· change s(contextDisplay U r c k a h Ο (removeOne D i), | |
| contextDisplay U r c k a h Ο (removeOne D j)) = _ | |
| rw [contextDisplay_removeOne,contextDisplay_removeOne] | |
| @[simp] theorem contextEdge_energy (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Ο : Fin k β Fin (U+1)) | |
| (H : State m n β β) (e : Sym2 (PairCoords Bool a β β€)) : | |
| edgeEnergy (smallKernel 0 U L C r c) (H β coordinatesState U r c) | |
| (contextEdge U r c k a h (Ο,e)) = | |
| edgeEnergy (contextKernel 0 U L C r c k a h Ο) | |
| (H β contextState U r c k a h Ο) e := by | |
| induction e using Sym2.ind with | |
| | _ x y => rfl | |
| noncomputable def fullUnitEnergy (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (H : State m n β β) : β := | |
| β e β fullUnitEdges U r c, edgeEnergy (smallKernel 0 U L C r c) (H β coordinatesState U r c) e | |
| theorem fullUnitEnergy_nonneg (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (H : State m n β β) : 0 β€ fullUnitEnergy U L C r c H := | |
| Finset.sum_nonneg fun e _ => edgeEnergy_nonneg _ _ (smallKernel_nonneg 0 (by positivity) U L C r c) e | |
| theorem contextEnergy_sum_le (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (k a : β) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (H : State m n β β) : | |
| (β Ο : Fin k β Fin (U+1), contextEnergy U L C r c k a h Ο H) β€ fullUnitEnergy U L C r c H := by | |
| classical | |
| let E := edgeEnergy (smallKernel 0 U L C r c) (H β coordinatesState U r c) | |
| have hh : (β Ο : Fin k β Fin (U+1), contextEnergy U L C r c k a h Ο H) = | |
| β q β Finset.univ ΓΛ’ smallUnitEdges U a, E (contextEdge U r c k a h q) := by | |
| rw [Finset.sum_product] | |
| simp only [E,contextEdge_energy,contextEnergy] | |
| rw [hh] | |
| rw [β Finset.sum_image (fun x _ y _ he => contextEdge_injective U r c k a h he)] | |
| apply Finset.sum_le_sum_of_subset_of_nonneg | |
| Β· intro e he | |
| obtain β¨β¨Ο,eβ©,hq,rflβ© := Finset.mem_image.mp he | |
| exact contextEdge_mem U r c k a h Ο e (Finset.mem_product.mp hq).2 | |
| Β· intro e he hne | |
| exact edgeEnergy_nonneg _ _ (smallKernel_nonneg 0 (by positivity) U L C r c) e | |
| end Contingency.PaddedGraph | |
| open scoped BigOperators | |
| namespace Contingency.PaddedGraph | |
| variable {m n : β} | |
| theorem sum_snoc (U k : β) (F : (Fin (k+1) β Fin (U+1)) β β) : | |
| (β Ο : Fin k β Fin (U+1), β j : Fin (U+1), F (Fin.snoc Ο j)) = β Ο, F Ο := by | |
| rw [Finset.sum_comm] | |
| have he := Equiv.sum_comp (Fin.snocEquiv (fun _ : Fin (k+1) => Fin (U+1))) F | |
| rw [Fintype.sum_prod_type] at he | |
| exact he | |
| theorem contextTree_level_sum_le (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (H : State m n β β) (l a k : β) (h : Fintype.card (SmallSlot U r c)=k+a) (hl : l<a) : | |
| (β Ο : Fin k β Fin (U+1), exposureLevel U a (contextTree U L C r c H a k h Ο) l) β€ | |
| fullUnitEnergy U L C r c H := by | |
| induction l generalizing a k with | |
| | zero => | |
| cases a with | |
| | zero => omega | |
| | succ a => exact contextEnergy_sum_le U L C r c k a h H | |
| | succ l ih => | |
| cases a with | |
| | zero => omega | |
| | succ a => | |
| simp only [contextTree,exposureLevel] | |
| have h' : Fintype.card (SmallSlot U r c) = (k+1)+a := by omega | |
| change (β Ο : Fin k β Fin (U+1), β j : Fin (U+1), | |
| exposureLevel U a (contextTree U L C r c H a (k+1) h' (Fin.snoc Ο j)) l) β€ _ | |
| rw [sum_snoc U k (fun Ο => exposureLevel U a | |
| (contextTree U L C r c H a (k+1) h' Ο) l)] | |
| exact ih a (k+1) h' (by omega) | |
| theorem root_level_le (U L C : β) (r : Fin m β β) (c : Fin n β β) | |
| (H : State m n β β) (l : β) (hl : l<Fintype.card (SmallSlot U r c)) : | |
| exposureLevel U (Fintype.card (SmallSlot U r c)) | |
| (contextTree U L C r c H (Fintype.card (SmallSlot U r c)) 0 (by omega) Fin.elim0) l β€ | |
| fullUnitEnergy U L C r c H := by | |
| have hh := contextTree_level_sum_le U L C r c H l (Fintype.card (SmallSlot U r c)) 0 (by omega) hl | |
| simp only [Fintype.sum_unique] at hh | |
| convert hh using 1 | |
| congr 2 | |
| theorem concrete_transversal_variance (U L C d : β) (r : Fin m β β) (c : Fin n β β) | |
| (hU : 2 β€ U) (hC2 : 2 β€ C) (hd : 1 β€ d) (hslots : Fintype.card (SmallSlot U r c) β€ d) | |
| (hrc : (β i, r i)=β j, c j) (hC : β i, paddedRow U L r c i β€ C) | |
| (H : State m n β β) : | |
| weightedVariance | |
| (fun Ο => (weight U L r c (profileState U r c 0 (Fintype.card (SmallSlot U r c)) | |
| (by omega) Fin.elim0 Ο):β)) | |
| (fun Ο => H (profileState U r c 0 (Fintype.card (SmallSlot U r c)) (by omega) Fin.elim0 Ο)) β€ | |
| 4*(d:β)^2*((U:β)+1)^6 * fullUnitEnergy U L C r c H := by | |
| have hb := exposure_variance_level_bound U (4*(d:β)*((U:β)+1)^6) (by positivity) | |
| (Fintype.card (SmallSlot U r c)) | |
| (fun Ο => (weight U L r c (profileState U r c 0 (Fintype.card (SmallSlot U r c)) | |
| (by omega) Fin.elim0 Ο):β)) | |
| (fun Ο => H (profileState U r c 0 (Fintype.card (SmallSlot U r c)) (by omega) Fin.elim0 Ο)) | |
| (fun Ο => by positivity) _ | |
| (contextTree_childBounds U L C d r c hU hC2 hd hslots hrc hC H _ 0 (by omega) Fin.elim0) | |
| (fullUnitEnergy U L C r c H) (root_level_le U L C r c H) | |
| refine hb.trans ?_ | |
| have hs : (Fintype.card (SmallSlot U r c):β) β€ d := by exact_mod_cast hslots | |
| have hm := mul_le_mul_of_nonneg_right hs | |
| (show 0 β€ (4*(d:β)*((U:β)+1)^6)*fullUnitEnergy U L C r c H from | |
| mul_nonneg (by positivity) (fullUnitEnergy_nonneg U L C r c H)) | |
| nlinarith only [hm] | |
| end Contingency.PaddedGraph | |
| end | |
| end OAI | |