math / data /lean /OAI /Probability /Contingency /ConcreteContexts.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
25.2 kB
import Mathlib
import OAI.Probability.Contingency.ConcreteKernel
namespace OAI
/-! Concrete Contexts. -/
noncomputable section
open scoped BigOperators
open scoped BigOperators
namespace Contingency.PaddedGraph
variable {m n : β„•}
def smallRank (U : β„•) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•) (s : SmallSlot U r c) : Fin (m*n) :=
finProdFinEquiv s.val
theorem smallRank_injective (U : β„•) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•) :
Function.Injective (smallRank U r c) := by
intro s t h
exact Subtype.ext (finProdFinEquiv.injective h)
noncomputable def smallIndex (U : β„•) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•) :
Fin (Fintype.card (SmallSlot U r c)) ≃ SmallSlot U r c := by
letI := LinearOrder.lift' (smallRank U r c) (smallRank_injective U r c)
exact (monoEquivOfFin (SmallSlot U r c) rfl).toEquiv
theorem smallRank_lt_iff (U : β„•) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•)
(s t : SmallSlot U r c) : smallRank U r c s < smallRank U r c t ↔ Before s.val t.val := by
change s.val.2.val+n*s.val.1.val < t.val.2.val+n*t.val.1.val ↔ _
have hs := s.val.2.isLt
have ht := t.val.2.isLt
unfold Before
constructor
Β· intro hh
by_cases hi : s.val.1 < t.val.1
Β· exact Or.inl hi
Β· have hti : t.val.1 ≀ s.val.1 := le_of_not_gt hi
have he : s.val.1=t.val.1 := by
apply Fin.ext
by_contra hn
have hlt : t.val.1.val+1 ≀ s.val.1.val := by omega
have hm := Nat.mul_le_mul_left n hlt
simp only [Nat.mul_add,Nat.mul_one] at hm
omega
exact Or.inr ⟨he,by rw [he] at hh; omega⟩
· rintro (hi | ⟨hi,hj⟩)
Β· have hm := Nat.mul_le_mul_left n (show s.val.1.val+1 ≀ t.val.1.val by omega)
simp only [Nat.mul_add,Nat.mul_one] at hm
omega
Β· rw [hi]; omega
theorem smallIndex_lt (U : β„•) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•)
(s t : Fin (Fintype.card (SmallSlot U r c))) :
Before (smallIndex U r c s).val (smallIndex U r c t).val ↔ s < t := by
let := LinearOrder.lift' (smallRank U r c) (smallRank_injective U r c)
rw [← smallRank_lt_iff]
exact @OrderIso.lt_iff_lt _ _ _
(LinearOrder.lift' (smallRank U r c) (smallRank_injective U r c)).toPreorder
(monoEquivOfFin (SmallSlot U r c) rfl) s t
noncomputable def contextCoordinates (U : β„•) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•)
(k a : β„•) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) :
SmallCoord U r c ≃ ((Fin k Γ— Bool) βŠ• PairCoords Bool a) :=
(((smallIndex U r c).symm.trans (finCongr h)).trans finSumFinEquiv.symm |>.prodCongr (Equiv.refl Bool)).trans
((Equiv.sumProdDistrib (Fin k) (Fin (a+1)) Bool).trans
(Equiv.sumCongr (Equiv.refl _) (smallCoords a).symm))
noncomputable def contextKernel (Ξ· : ℝ) (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)) (p : PairCoords Bool a β†’ β„€) : ℝ :=
smallKernel Ξ· U L C r c ((Sum.elim (balanceProfile (fun _ => U) Οƒ) p) ∘
contextCoordinates U r c k a h)
theorem balanceProfile_box (U k : β„•) (Οƒ : Fin k β†’ Fin (U+1)) :
InBox (fun _ => (U:β„€)) (balanceProfile (fun _ => U) Οƒ) := by
intro ⟨s,b⟩
have hs := (Οƒ s).isLt
cases b <;> dsimp [balanceProfile] <;> omega
theorem balanceProfile_total (U k : β„•) (Οƒ : Fin k β†’ Fin (U+1)) :
(βˆ‘ w, balanceProfile (fun _ => U) Οƒ w) = (k:β„€)*U := by
rw [Fintype.sum_prod_type]
simp [balanceProfile]
theorem contextKernel_signature (Ξ· : ℝ) (hΞ· : 0 < Ξ·) (hΞ·1 : Ξ· < 1)
(U L C : β„•) (hC : 2 ≀ C) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•)
(k a : β„•) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Οƒ : Fin k β†’ Fin (U+1)) :
PositiveSlice (contextKernel Ξ· U L C r c k a h Οƒ) (fun _ => (U:β„€)) (((a+1:β„•):β„€)*U) ∧
HasSignature (contextKernel Ξ· U L C r c k a h Οƒ) (fun _ => (U:β„€)) (((a+1:β„•):β„€)*U) := by
obtain ⟨hp,hs⟩ := smallKernel_signature η hη hη1 U L C hC r c
have hp' := hp.reindex (contextCoordinates U r c k a h)
have hs' := hs.reindex (contextCoordinates U r c k a h)
have hbox : (fun _ : SmallCoord U r c => (U:β„€)) ∘ (contextCoordinates U r c k a h).symm =
Sum.elim (fun _ : Fin k Γ— Bool => (U:β„€)) (fun _ : PairCoords Bool a => (U:β„€)) := by
funext w; cases w <;> rfl
rw [hbox] at hp' hs'
have hp'' := hp'.fixedContext _ (balanceProfile_box U k Οƒ)
have hs'' := hs'.fixedContext _ (balanceProfile_box U k Οƒ)
rw [balanceProfile_total,h] at hp'' hs''
have he : ((k+(a+1):β„•):β„€)*U-(k:β„€)*U = ((a+1:β„•):β„€)*U := by push_cast; ring
rw [he] at hp'' hs''
exact ⟨hp'',hs''⟩
theorem contextKernel_continuous (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)) (p : PairCoords Bool a β†’ β„€) :
Continuous (fun Ξ· => contextKernel Ξ· U L C r c k a h Οƒ p) :=
smallKernel_continuous U L C r c _
theorem contextKernel_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)) (p : PairCoords Bool a β†’ β„€) :
0 ≀ contextKernel 0 U L C r c k a h Οƒ p :=
smallKernel_nonneg 0 (by norm_num) U L C r c _
theorem context_child_no_holes (U L C : β„•) (hU : 2 ≀ U) (hC : 2 ≀ C)
(r : Fin m β†’ β„•) (c : Fin n β†’ β„•) (k a : β„•)
(h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Οƒ : Fin k β†’ Fin (U+1))
(u v j : β„•) (huj : u ≀ j) (hjv : j ≀ v) (hv : v ≀ U) :
min (nodeMass U a (contextKernel 0 U L C r c k a h Οƒ) u)
(nodeMass U a (contextKernel 0 U L C r c k a h Οƒ) v) ≀
nodeMass U a (contextKernel 0 U L C r c k a h Οƒ) j :=
nodeMass_min U hU a _ (contextKernel_continuous U L C r c k a h Οƒ)
(fun Ξ· hΞ· hΞ·' => (contextKernel_signature Ξ· hΞ· hΞ·' U L C hC r c k a h Οƒ).1)
(fun Ξ· hΞ· hΞ·' => (contextKernel_signature Ξ· hΞ· hΞ·' U L C hC r c k a h Οƒ).2)
u v j huj hjv hv
end Contingency.PaddedGraph
open scoped BigOperators
namespace Contingency
universe u
noncomputable def branchEquiv (C : β„•) : (n : β„•) β†’ Branches 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 (branchEquiv C n)).trans
(piHeadEquiv (fun _ : Fin (n+1) => Fin (C+1))).symm
theorem branchEquiv_value (C n : β„•) (a : Branches C n) (s : Fin n) :
branchEquiv C n a s = branchValue C n a s := by
induction n with
| zero => exact Fin.elim0 s
| succ n ih =>
refine Fin.cases ?_ (fun t => ?_) s
Β· rfl
Β· exact ih a.2 t
theorem allBalance_sum_leaf {ΞΉ : Type u} (C n : β„•)
(f : (PairCoords ΞΉ n β†’ β„€) β†’ ℝ) (p : ΞΉ β†’ β„€) :
allBalance C n f p = βˆ‘ a : Branches C n, f (leafDisplay C n p a) := by
induction n generalizing ΞΉ with
| zero => simp [allBalance,leafDisplay]
| succ n ih =>
change (βˆ‘ j ∈ Finset.range (C+1), allBalance C n f (pairAssembly p (j:β„€) ((C:β„€)-j))) = _
rw [← Fin.sum_univ_eq_sum_range]
simp_rw [ih]
change _ = βˆ‘ a : Fin (C+1) Γ— Branches C n, f (leafDisplay C (n+1) p a)
rw [Fintype.sum_prod_type]
rfl
noncomputable def mixedDisplay {ΞΉ : Type u} (n : β„•) (D : Fin n β†’ β„•)
(p : ΞΉ β†’ β„€) (a : βˆ€ s, Fin (D s+1)) : PairCoords ΞΉ n β†’ β„€ :=
Sum.elim p (balanceProfile D a) ∘ pairCoordsEquiv ι n
@[simp] theorem mixedDisplay_base {ΞΉ : Type u} (n : β„•) (D : Fin n β†’ β„•)
(p : ΞΉ β†’ β„€) (a : βˆ€ s, Fin (D s+1)) (i : ΞΉ) :
mixedDisplay n D p a ((pairCoordsEquiv ΞΉ n).symm (.inl i)) = p i := by
simp [mixedDisplay]
@[simp] theorem mixedDisplay_slot {ΞΉ : Type u} (n : β„•) (D : Fin n β†’ β„•)
(p : ΞΉ β†’ β„€) (a : βˆ€ s, Fin (D s+1)) (s : Fin n) (b : Bool) :
mixedDisplay n D p a ((pairCoordsEquiv ΞΉ n).symm (.inr (s,b))) =
if b then ((a s:β„•):β„€) else (D s:β„€)-(a s:β„•) := by
simp [mixedDisplay,balanceProfile]
theorem leafDisplay_mixed {ΞΉ : Type u} (C n : β„•) (p : ΞΉ β†’ β„€) (a : Branches C n) :
leafDisplay C n p a = mixedDisplay n (fun _ => C) p (branchEquiv C n a) := by
funext i
obtain ⟨q,rfl⟩ := (pairCoordsEquiv ι n).symm.surjective i
rcases q with i | ⟨s,b⟩
Β· rw [leafDisplay_base,mixedDisplay_base]
Β· rw [leafDisplay_slot,mixedDisplay_slot,branchEquiv_value]
theorem mixedDisplay_injective {ΞΉ : Type u} (n : β„•) (D : Fin n β†’ β„•) (p : ΞΉ β†’ β„€) :
Function.Injective (mixedDisplay n D p) := by
intro a b hab
funext s
have hh := congrFun hab ((pairCoordsEquiv ΞΉ n).symm (.inr (s,true)))
simp only [mixedDisplay_slot,ite_true] at hh
apply Fin.ext
exact_mod_cast hh
theorem leafDisplay_injective {ΞΉ : Type u} (C n : β„•) (p : ΞΉ β†’ β„€) :
Function.Injective (leafDisplay C n p) := by
intro a b hab
simp only [leafDisplay_mixed] at hab
exact (branchEquiv C n).injective (mixedDisplay_injective n _ p hab)
noncomputable def mixedBalance {ΞΉ : Type u} (n : β„•) (D : Fin n β†’ β„•)
(f : (PairCoords ΞΉ n β†’ β„€) β†’ ℝ) (p : ΞΉ β†’ β„€) : ℝ :=
βˆ‘ a : βˆ€ s, Fin (D s+1), f (mixedDisplay n D p a)
theorem allBalance_mixed {ΞΉ : Type u} (C n : β„•)
(f : (PairCoords ΞΉ n β†’ β„€) β†’ ℝ) (p : ΞΉ β†’ β„€) :
allBalance C n f p = mixedBalance n (fun _ => C) f p := by
rw [allBalance_sum_leaf]
simp only [leafDisplay_mixed,mixedBalance]
exact Equiv.sum_comp (branchEquiv C n) (fun a => f (mixedDisplay n (fun _ => C) p a))
theorem mixedDisplay_succ {ΞΉ : Type u} (n : β„•) (D : Fin (n+1) β†’ β„•)
(p : ΞΉ β†’ β„€) (a : βˆ€ s, Fin (D s+1)) :
mixedDisplay (n+1) D p a = mixedDisplay n (fun s => D s.succ)
(pairAssembly p (a 0:β„•) ((D 0:β„€)-(a 0:β„•))) (fun s => a s.succ) := by
funext i
obtain ⟨q,rfl⟩ := (pairCoordsEquiv (ΞΉ βŠ• Bool) n).symm.surjective i
rcases q with (i | b) | ⟨s,b⟩ <;>
simp only [mixedDisplay, Function.comp_apply, pairCoordsEquiv, Equiv.trans_apply,
Equiv.apply_symm_apply, joinPairHead, Equiv.coe_fn_mk, balanceProfile, pairAssembly,
Sum.elim_inl, Sum.elim_inr]
theorem mixedBalance_succ {ΞΉ : Type u} (n : β„•) (D : Fin (n+1) β†’ β„•)
(f : (PairCoords ΞΉ (n+1) β†’ β„€) β†’ ℝ) (p : ΞΉ β†’ β„€) :
mixedBalance (n+1) D f p = βˆ‘ j : Fin (D 0+1),
mixedBalance n (fun s => D s.succ) f (pairAssembly p (j:β„•) ((D 0:β„€)-(j:β„•))) := by
unfold mixedBalance
rw [← Equiv.sum_comp (piHeadEquiv (fun s => Fin (D s+1))).symm]
rw [Fintype.sum_prod_type]
apply Finset.sum_congr rfl; intro j hj
apply Finset.sum_congr rfl; intro a ha
congr 1
rw [mixedDisplay_succ]
rfl
noncomputable def surplusCaps (C n : β„•) (t : Fin n) (s : Fin n) : β„• :=
if s=t then C+1 else C
theorem allSurplus_sum_types {ΞΉ : Type u} (C n : β„•)
(f : (PairCoords ΞΉ n β†’ β„€) β†’ ℝ) (p : ΞΉ β†’ β„€) :
allSurplus C n f p = βˆ‘ t : Fin n, mixedBalance n (surplusCaps C n t) f p := by
induction n generalizing ΞΉ with
| zero => simp [allSurplus]
| succ n ih =>
rw [Fin.sum_univ_succ]
change balancedMarginal (allBalance C n f) (C+1) p +
balancedMarginal (allSurplus C n f) C p = _
congr 1
Β· rw [mixedBalance_succ]
simp only [surplusCaps,ite_eq_left,Fin.succ_ne_zero,ite_false]
unfold balancedMarginal
rw [← Fin.sum_univ_eq_sum_range]
apply Finset.sum_congr rfl; intro j hj
exact allBalance_mixed C n f _
Β· have hs (t : Fin n) : mixedBalance (n+1) (surplusCaps C (n+1) t.succ) f p =
βˆ‘ j : Fin (C+1), mixedBalance n (surplusCaps C n t) f
(pairAssembly p (j:β„•) ((C:β„€)-(j:β„•))) := by
have he : surplusCaps C (n+1) t.succ = Fin.cases C (surplusCaps C n t) := by
funext s
refine Fin.cases ?_ (fun v => ?_) s
Β· simp [surplusCaps,Ne.symm (Fin.succ_ne_zero t)]
Β· simp [surplusCaps]
rw [he,mixedBalance_succ]
rfl
simp_rw [hs]
rw [Finset.sum_comm]
unfold balancedMarginal
rw [← Fin.sum_univ_eq_sum_range]
apply Finset.sum_congr rfl; intro j hj
exact ih f _
end Contingency
open scoped BigOperators
namespace Contingency.PaddedGraph
variable {m n : β„•}
noncomputable def splitSlots (U : β„•) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•)
(k a : β„•) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) :
SmallSlot U r c ≃ (Fin k βŠ• Fin (a+1)) :=
((smallIndex U r c).symm.trans (finCongr h)).trans finSumFinEquiv.symm
noncomputable def prefixSlot (U : β„•) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•)
(k a : β„•) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (s : Fin k) :=
(splitSlots U r c k a h).symm (.inl s)
noncomputable def suffixSlot (U : β„•) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•)
(k a : β„•) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (s : Fin (a+1)) :=
(splitSlots U r c k a h).symm (.inr s)
@[simp] theorem contextCoordinates_prefix (U : β„•) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•)
(k a : β„•) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (s : Fin k) (b : Bool) :
contextCoordinates U r c k a h (prefixSlot U r c k a h s,b) = .inl (s,b) := by
change ((Equiv.sumCongr (Equiv.refl _) (smallCoords a).symm)
((Equiv.sumProdDistrib (Fin k) (Fin (a+1)) Bool)
(splitSlots U r c k a h ((splitSlots U r c k a h).symm (.inl s)),b))) = _
rw [Equiv.apply_symm_apply]; rfl
@[simp] theorem contextCoordinates_suffix (U : β„•) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•)
(k a : β„•) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (s : Fin (a+1)) (b : Bool) :
contextCoordinates U r c k a h (suffixSlot U r c k a h s,b) =
.inr ((smallCoords a).symm (s,b)) := by
change ((Equiv.sumCongr (Equiv.refl _) (smallCoords a).symm)
((Equiv.sumProdDistrib (Fin k) (Fin (a+1)) Bool)
(splitSlots U r c k a h ((splitSlots U r c k a h).symm (.inr s)),b))) = _
rw [Equiv.apply_symm_apply]; rfl
theorem prefix_before_suffix (U : β„•) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•)
(k a : β„•) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (s : Fin k) (t : Fin (a+1)) :
Before (prefixSlot U r c k a h s).val (suffixSlot U r c k a h t).val := by
apply (smallIndex_lt U r c _ _).2
change ((finCongr h).symm (finSumFinEquiv (.inl s))) <
((finCongr h).symm (finSumFinEquiv (.inr t)))
change s.val < k+t.val
omega
theorem suffix_before (U : β„•) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•)
(k a : β„•) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (s t : Fin (a+1)) (hst : s<t) :
Before (suffixSlot U r c k a h s).val (suffixSlot U r c k a h t).val := by
apply (smallIndex_lt U r c _ _).2
change k+s.val < k+t.val
exact Nat.add_lt_add_left hst k
theorem slot_cases (U : β„•) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•)
(k a : β„•) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (w : SmallSlot U r c) :
(βˆƒ s, w=prefixSlot U r c k a h s) ∨ (βˆƒ s, w=suffixSlot U r c k a h s) := by
obtain ⟨v,rfl⟩ := (splitSlots U r c k a h).symm.surjective w
cases v with
| inl s => exact Or.inl ⟨s,rfl⟩
| inr s => exact Or.inr ⟨s,rfl⟩
noncomputable def contextState (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 β†’ β„€) : State m n :=
coordinatesState U r c (Sum.elim (balanceProfile (fun _ => U) Οƒ) p ∘ contextCoordinates U r c k a h)
@[simp] theorem contextState_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) :
(contextState U r c k a h Οƒ p).x (prefixSlot U r c k a h s).val = (Οƒ s:β„•) ∧
(contextState U r c k a h Οƒ p).q (prefixSlot U r c k a h s).val = (Οƒ s:β„•) := by
simp [contextState,balanceProfile]
@[simp] theorem contextState_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)) :
(contextState U r c k a h Οƒ p).x (suffixSlot U r c k a h s).val = p ((smallCoords a).symm (s,true)) ∧
(contextState U r c k a h Οƒ p).q (suffixSlot U r c k a h s).val = U-p ((smallCoords a).symm (s,false)) := by
simp [contextState]
theorem contextState_supported (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 β†’ β„€) (w : Cell m n) (hw : IsLarge U r c w) :
(contextState U r c k a h Οƒ p).x w=0 ∧ (contextState U r c k a h Οƒ p).q w=0 :=
coordinatesState_supported U r c _ w hw
theorem contextState_injective (U : β„•) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•)
(k a : β„•) (h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Οƒ : Fin k β†’ Fin (U+1)) :
Function.Injective (contextState U r c k a h Οƒ) := by
intro p q hpq
have he := congrArg (stateCoordinates U r c) hpq
dsimp [contextState] at he
simp only [stateCoordinates_coordinatesState] at he
funext i
have hh := congrFun he ((contextCoordinates U r c k a h).symm (.inr i))
simpa using hh
theorem contextKernel_weight (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))
(p : PairCoords Bool a β†’ β„€) :
contextKernel 0 U L C r c k a h Οƒ p = (weight U L r c (contextState U r c k a h Οƒ p):ℝ) := by
classical
let X := contextState U r c k a h Οƒ p
by_cases hx : Feasible U r c X
Β· rw [weight,ite_eq_left hx]
have he := smallKernel_zero_count U L C r c hrc X hx hC
simpa only [X,contextState,stateCoordinates_coordinatesState,contextKernel] using he
Β· rw [weight,ite_eq_right hx,Nat.cast_zero]
exact smallKernel_zero_infeasible U L C r c _ hx
end Contingency.PaddedGraph
open scoped BigOperators
namespace Contingency.PaddedGraph
variable {m n : β„•}
@[ext] theorem State.ext {X Y : State m n} (hx : X.x=Y.x) (hq : X.q=Y.q) : X=Y := by
cases X; cases Y; simp_all
variable (U : β„•) (r : Fin m β†’ β„•) (c : Fin n β†’ β„•) (k a : β„•)
(h : Fintype.card (SmallSlot U r c)=k+(a+1)) (Οƒ : Fin k β†’ Fin (U+1))
@[simp] theorem suffixSlot_val_inj (s t : Fin (a+1)) :
(suffixSlot U r c k a h s).val=(suffixSlot U r c k a h t).val ↔ s=t := by
constructor
Β· intro he
have he' := Subtype.ext he
exact Sum.inr.inj ((splitSlots U r c k a h).symm.injective he')
Β· rintro rfl; rfl
@[simp] theorem prefix_suffix_ne (s : Fin k) (t : Fin (a+1)) :
(prefixSlot U r c k a h s).val β‰  (suffixSlot U r c k a h t).val := by
intro he
have he' := Subtype.ext he
have hh := (splitSlots U r c k a h).symm.injective he'
cases hh
@[simp] theorem mixedDisplay_current (D : Fin a β†’ β„•) (p : Bool β†’ β„€)
(Ξ± : βˆ€ s, Fin (D s+1)) (b : Bool) :
mixedDisplay a D p Ξ± ((smallCoords a).symm (0,b)) = p b := by
exact mixedDisplay_base a D p Ξ± b
@[simp] theorem mixedDisplay_ordinary (D : Fin a β†’ β„•) (p : Bool β†’ β„€)
(Ξ± : βˆ€ s, Fin (D s+1)) (s : Fin a) (b : Bool) :
mixedDisplay a D p Ξ± ((smallCoords a).symm (s.succ,b)) =
if b then ((Ξ± s:β„•):β„€) else (D s:β„€)-(Ξ± s:β„•) := by
exact mixedDisplay_slot a D p Ξ± s b
def defectProfile (j : β„•) : Bool β†’ β„€ := fun b => if b then (j:β„€) else (U:β„€)-j-1
@[simp] theorem adjacent_removePair (j : β„•) :
removePair (adjacentDisplay U j) true false = defectProfile U j := by
funext b; cases b <;> simp [removePair,adjacentDisplay,defectProfile]
noncomputable def defectState (j : β„•) (t : Fin a) (Ξ± : βˆ€ v, Fin (surplusCaps U a t v+1)) : State m n :=
contextState U r c k a h Οƒ (mixedDisplay a (surplusCaps U a t) (defectProfile U j) Ξ±)
@[simp] theorem defectState_current (j : β„•) (t : Fin a) (Ξ± : βˆ€ v, Fin (surplusCaps U a t v+1)) :
(defectState U r c k a h Οƒ j t Ξ±).x (suffixSlot U r c k a h 0).val = j ∧
(defectState U r c k a h Οƒ j t Ξ±).q (suffixSlot U r c k a h 0).val = (j:β„€)+1 := by
have hh := contextState_suffix U r c k a h Οƒ (mixedDisplay a (surplusCaps U a t) (defectProfile U j) Ξ±) 0
refine ⟨hh.1.trans ?_,hh.2.trans ?_⟩
Β· simp only [mixedDisplay_current,defectProfile,ite_true]
Β· simp only [mixedDisplay_current,defectProfile,Bool.false_eq_true,ite_false]
ring
@[simp] theorem defectState_ordinary (j : β„•) (t v : Fin a) (Ξ± : βˆ€ v, Fin (surplusCaps U a t v+1)) :
(defectState U r c k a h Οƒ j t Ξ±).x (suffixSlot U r c k a h v.succ).val = (Ξ± v:β„•) ∧
(defectState U r c k a h Οƒ j t Ξ±).q (suffixSlot U r c k a h v.succ).val =
(Ξ± v:β„•)-(if v=t then (1:β„€) else 0) := by
have hh := contextState_suffix U r c k a h Οƒ (mixedDisplay a (surplusCaps U a t) (defectProfile U j) Ξ±) v.succ
simp only [mixedDisplay_ordinary,Bool.false_eq_true,ite_true,ite_false] at hh
refine ⟨hh.1,hh.2.trans ?_⟩
unfold surplusCaps
split_ifs <;> push_cast <;> ring
theorem defectState_defect (j : β„•) (t : Fin a) (Ξ± : βˆ€ v, Fin (surplusCaps U a t v+1)) :
DefectAt 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 Ξ±) := by
refine ⟨(suffixSlot U r c k a h 0).property,(suffixSlot U r c k a h t.succ).property,?_,?_⟩
Β· rw [ne_eq,suffixSlot_val_inj]
exact Ne.symm (Fin.succ_ne_zero t)
Β· funext w
by_cases hw : IsSmall U r c w
· rcases slot_cases U r c k a h ⟨w,hw⟩ with ⟨v,hv⟩ | ⟨v,hv⟩
Β· have he : w=(prefixSlot U r c k a h v).val := congrArg Subtype.val hv
subst w
have hp := contextState_prefix U r c k a h Οƒ
(mixedDisplay a (surplusCaps U a t) (defectProfile U j) Ξ±) v
dsimp [defectState] at *
rw [hp.1,hp.2]
simp [unit]
Β· have he : w=(suffixSlot U r c k a h v).val := congrArg Subtype.val hv
subst w
refine Fin.cases ?_ (fun v => ?_) v
Β· rw [(defectState_current U r c k a h Οƒ j t Ξ±).1,
(defectState_current U r c k a h Οƒ j t Ξ±).2]
simp [unit,Ne.symm (Fin.succ_ne_zero t)]
Β· rw [(defectState_ordinary U r c k a h Οƒ j t v Ξ±).1,
(defectState_ordinary U r c k a h Οƒ j t v Ξ±).2]
simp [unit]
Β· have hl : IsLarge U r c w := Classical.not_not.mp hw
have hh := contextState_supported U r c k a h Οƒ
(mixedDisplay a (surplusCaps U a t) (defectProfile U j) Ξ±) w hl
have hs : w β‰  (suffixSlot U r c k a h 0).val := by
rintro rfl; exact (suffixSlot U r c k a h 0).property hl
have ht : w β‰  (suffixSlot U r c k a h t.succ).val := by
rintro rfl; exact (suffixSlot U r c k a h t.succ).property hl
change _ = _-unit _ _+unit _ _
simp only [defectState] at *
rw [hh.1,hh.2]; simp [unit,hs,ht]
noncomputable def stateSuffix (X : State m n) (hf : Feasible U r c X) : Fin a β†’ Fin (U+1) :=
fun v => ⟨(X.x (suffixSlot U r c k a h v.succ).val).toNat,by
have hh := hf.1 (suffixSlot U r c k a h v.succ).val; omega⟩
theorem contextState_reconstruct (X : State m n) (hf : Feasible U r c X)
(htr : Transversal X) (hp : βˆ€ v, X.x (prefixSlot U r c k a h v).val=(Οƒ v:β„•))
(j : β„•) (hj : X.x (suffixSlot U r c k a h 0).val=(j:β„€)) :
contextState U r c k a h Οƒ (mixedDisplay a (fun _ => U) (childProfile U j)
(stateSuffix U r c k a h X hf)) = X := by
apply State.ext
Β· funext w
by_cases hw : IsSmall U r c w
· rcases slot_cases U r c k a h ⟨w,hw⟩ with ⟨v,hv⟩ | ⟨v,hv⟩
Β· have he : w=(prefixSlot U r c k a h v).val := congrArg Subtype.val hv
subst w
rw [(contextState_prefix U r c k a h Οƒ _ v).1,hp]
Β· have he : w=(suffixSlot U r c k a h v).val := congrArg Subtype.val hv
subst w
rw [(contextState_suffix U r c k a h Οƒ _ v).1]
refine Fin.cases ?_ (fun t => ?_) v
Β· simpa [childProfile] using hj.symm
Β· simp only [mixedDisplay_ordinary,ite_true,stateSuffix]
exact Int.toNat_of_nonneg (hf.1 _).1
Β· exact (contextState_supported U r c k a h Οƒ _ w (Classical.not_not.mp hw)).1.trans
((hf.2.1 w (Classical.not_not.mp hw)).1.symm)
Β· funext w
by_cases hw : IsSmall U r c w
· rcases slot_cases U r c k a h ⟨w,hw⟩ with ⟨v,hv⟩ | ⟨v,hv⟩
Β· have he : w=(prefixSlot U r c k a h v).val := congrArg Subtype.val hv
subst w
rw [(contextState_prefix U r c k a h Οƒ _ v).2,htr,hp]
Β· have he : w=(suffixSlot U r c k a h v).val := congrArg Subtype.val hv
subst w
rw [(contextState_suffix U r c k a h Οƒ _ v).2,htr]
refine Fin.cases ?_ (fun t => ?_) v
Β· simp [childProfile,hj]
Β· simp only [mixedDisplay_ordinary,Bool.false_eq_true,ite_false,stateSuffix]
rw [Int.toNat_of_nonneg (hf.1 _).1]; ring
Β· exact (contextState_supported U r c k a h Οƒ _ w (Classical.not_not.mp hw)).2.trans
((hf.2.1 w (Classical.not_not.mp hw)).2.symm)
end Contingency.PaddedGraph
end
end OAI