math / data /lean /OAI /Probability /Contingency /ConditionalTransport.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
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