math / data /lean /OAI /Combinatorics /ContingencyTables /Transport /ChoiceContextEnumeration.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
5.26 kB
import OAI.Combinatorics.ContingencyTables.Transport.ContextWeightedEnumeration
import OAI.Combinatorics.ContingencyTables.Sampling.PhysicalPrefixEnergies
import OAI.Combinatorics.ContingencyTables.Transport.FiniteChoiceFibres
namespace OAI
/-! # Literal finite choice fibres equal the transport child sums -/
namespace ContingencyTables.SmallContextEnumeration
open scoped BigOperators Classical
open SmallContextCoordinates SmallContextFibres PhysicalCompletionFibres
open LargePairEnumeration BalancedEnumeration BalancedFamily
open FirstPaperContextTransport FirstPaperPhysicalMarginal ExcessContextProfiles SmallGraphProfiles
open FiniteExposureVariance
open IntegerWeightedTransport
universe u
variable {I J : Type u} [Fintype I] [Fintype J] [LinearOrder I] [LinearOrder J]
def rawChoice (small : I β†’ J β†’ Bool) (U : β„•) (x : Cells small β†’ Fin (U+1)) :
SmallProfile small := fun p => if p.2 then U-(x p.1).val else (x p.1).val
def earlierChoices (small : I β†’ J β†’ Bool) (s : IΓ—J) (U : β„•)
(x : Cells small β†’ Fin (U+1)) : Earlier small s β†’ Fin (U+1) := fun a => x a.val
omit [Fintype I] [Fintype J] in
lemma earlierChoices_eq_iff (small : I β†’ J β†’ Bool) (s : IΓ—J) (U : β„•)
(x : Cells small β†’ Fin (U+1)) (Ο„ : Earlier small s β†’ Fin (U+1)) :
earlierChoices small s U x=Ο„ ↔ βˆ€ a : Earlier small s,x a.val=Ο„ a :=
funext_iff
def ChoiceContext (small : I β†’ J β†’ Bool) (s : IΓ—J) (hs : small s.1 s.2=true) (U : β„•)
(Ο„ : Earlier small s β†’ Fin (U+1)) (k : Fin (U+1)) :=
{x : Cells small β†’ Fin (U+1) // earlierChoices small s U x=Ο„ ∧ x ⟨s,hs⟩=k}
noncomputable instance choiceContextFintype (small : I β†’ J β†’ Bool) (s : IΓ—J)
(hs : small s.1 s.2=true) (U : β„•) (Ο„ : Earlier small s β†’ Fin (U+1)) (k : Fin (U+1)) :
Fintype (ChoiceContext small s hs U Ο„ k) := by unfold ChoiceContext; infer_instance
noncomputable def choiceContextEquiv (small : I β†’ J β†’ Bool) (s : IΓ—J)
(hs : small s.1 s.2=true) (U : β„•) (Ο„ : Earlier small s β†’ Fin (U+1)) (k : Fin (U+1)) :
(Later small s β†’ Fin (U+1)) ≃ ChoiceContext small s hs U Ο„ k where
toFun y := ⟨splitChoices small s hs U Ο„ k y,funext (splitChoices_prefix small s hs U Ο„ k y),
splitChoices_special small s hs U Ο„ k y⟩
invFun x := fun a => x.val a.val
left_inv y := by funext a; exact splitChoices_later small s hs U Ο„ k y a
right_inv x := by
apply Subtype.ext
funext a
obtain ⟨v,rfl⟩ := (cellSplitEquiv small s hs).surjective a
rcases v with p|(_|t)
Β· exact (splitChoices_prefix small s hs U Ο„ k _ p).trans (congrFun x.property.1 p).symm
Β· exact (splitChoices_special small s hs U Ο„ k _).trans x.property.2.symm
Β· exact splitChoices_later small s hs U Ο„ k _ t
lemma choice_fibre_sum (small : I β†’ J β†’ Bool) (s : IΓ—J) (hs : small s.1 s.2=true)
(U : β„•) (Ο„ : Earlier small s β†’ Fin (U+1)) (k : Fin (U+1))
(F : (Cells small β†’ Fin (U+1)) β†’ ℝ) :
(βˆ‘ x,fibreWeight (fibreWeight F (earlierChoices small s U) Ο„) (fun x => x ⟨s,hs⟩) k x)=
βˆ‘ x : ChoiceContext small s hs U Ο„ k,F x.val := by
exact double_fibre_sum F (earlierChoices small s U) (fun x => x ⟨s,hs⟩) Ο„ k
omit [Fintype I] [Fintype J] in
lemma prefixChoices_extension (small : I β†’ J β†’ Bool) (s : IΓ—J) (U : β„•)
(Ο„ : Earlier small s β†’ Fin (U+1)) :
prefixChoices small s (prefixExtension small s U Ο„) U (prefixExtension_bounded small s U Ο„)=Ο„ := by
funext a
apply Fin.ext
exact prefixExtension_at small s U Ο„ a
/-- The child mass and every child moment are the actual finite fibre
sums of balanced physical choices, retaining all large completions. -/
theorem eliminate_context_eq_choice_fibre (small : I β†’ J β†’ Bool) (B : I β†’ J β†’ β„•)
(s : IΓ—J) (hs : small s.1 s.2=true) (U : β„•)
(hB : βˆ€ i j,small i j=true β†’ B i j=U)
(Ο„ : Earlier small s β†’ Fin (U+1)) (k : Fin (U+1))
{n : β„•} (e : Fin n ≃ Later small s) (F : SmallProfile small β†’ ℝ) :
eliminate (widths (fun _ : Fin n => U))
(fun p => F (assemble small s hs (prefixExtension small s U Ο„) U e p)) (childProfile U k.val)=
βˆ‘ x,fibreWeight (fibreWeight (fun x => F (rawChoice small U x))
(earlierChoices small s U) Ο„) (fun x => x ⟨s,hs⟩) k x := by
rw [eliminate_context_eq_weighted_sum small B s hs _ U hB
(prefixExtension_bounded small s U Ο„),choice_fibre_sum]
have he := Fintype.sum_equiv
(balancedContextEquiv small B s hs (prefixExtension small s U Ο„) U hB
(prefixExtension_bounded small s U Ο„) k)
(fun y => F (rawChoice small U (splitChoices small s hs U Ο„ k y)))
(fun z => F (naturalProfile z.val)) (fun y => by
change F (rawChoice small U (splitChoices small s hs U Ο„ k y))=
F (rawChoice small U (splitChoices small s hs U
(prefixChoices small s (prefixExtension small s U Ο„) U (prefixExtension_bounded small s U Ο„)) k y))
rw [prefixChoices_extension])
have hc := Fintype.sum_equiv (choiceContextEquiv small s hs U Ο„ k)
(fun y => F (rawChoice small U (splitChoices small s hs U Ο„ k y)))
(fun x => F (rawChoice small U x.val)) (fun _ => rfl)
exact he.symm.trans hc
end ContingencyTables.SmallContextEnumeration
end OAI