math / data /lean /OAI /Combinatorics /ContingencyTables /Transport /BalancedEnumeration.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
2.51 kB
import OAI.Combinatorics.ContingencyTables.Transport.BalancedFamily
namespace OAI
/-!
# Balanced elimination as a finite assignment sum
The recursive integer marginal equals the finite sum over the choices in
all eliminated large-cell pairs. This identifies the signature marginal
with the completion count.
-/
namespace ContingencyTables.BalancedEnumeration
open scoped BigOperators Classical
open BalancedFamily IntegerMarginal BalancedBox
@[reducible] def Assignments : List β„• β†’ Type
| [] => PUnit
| M::Ms => Assignments Ms Γ— Fin (M+1)
@[reducible] instance assignmentsFintype (Ms : List β„•) : Fintype (Assignments Ms) := by
induction Ms with
| nil => exact inferInstanceAs (Fintype PUnit)
| cons M Ms ih =>
letI := ih
exact inferInstanceAs (Fintype (Assignments Ms Γ— Fin (M+1)))
def embedding {I : Type*} : (Ms : List β„•) β†’ (I β†’ β„•) β†’ Assignments Ms β†’ Coordinates I Ms β†’ β„•
| [],z,_ => z
| M::Ms,z,a => profile (embedding Ms z a.1) a.2.val (M-a.2.val)
theorem eliminate_eq_sum {I : Type*} (Ms : List β„•)
(F : (Coordinates I Ms β†’ β„•) β†’ ℝ) (z : I β†’ β„•) :
eliminate Ms F z=βˆ‘ a : Assignments Ms, F (embedding Ms z a) := by
induction Ms with
| nil => simp only [eliminate,Assignments,embedding,Fintype.sum_unique]
| cons M Ms ih =>
change eliminate Ms (marginal F M) z=
βˆ‘ a : Assignments Ms Γ— Fin (M+1), F (profile (embedding Ms z a.1) a.2.val (M-a.2.val))
rw [ih,Fintype.sum_prod_type]
apply Finset.sum_congr rfl
intro a _
unfold marginal
exact (Fin.sum_univ_eq_sum_range (fun j => F (profile (embedding Ms z a) j (M-j))) (M+1)).symm
lemma embedding_inBox {I : Type*} (Ms : List β„•) (m : I β†’ β„•) (z : I β†’ β„•)
(hz : InBox m z) (a : Assignments Ms) : InBox (bounds m Ms) (embedding Ms z a) := by
induction Ms with
| nil => exact hz
| cons M Ms ih =>
apply profile_inBox (bounds m Ms) (embedding Ms z a.1) M a.2.val (M-a.2.val)
Β· exact ih a.1
Β· have ha := a.2.isLt; omega
Β· exact Nat.sub_le _ _
lemma embedding_total {I : Type*} [Fintype I] (Ms : List β„•) (z : I β†’ β„•)
(a : Assignments Ms) :
(βˆ‘ i, embedding Ms z a i)=(βˆ‘ i, z i)+Ms.sum := by
induction Ms with
| nil => simp only [embedding,List.sum_nil,add_zero]
| cons M Ms ih =>
change (βˆ‘ i, profile (embedding Ms z a.1) a.2.val (M-a.2.val) i)=_
rw [profile_total,ih]
have ha := a.2.isLt
simp only [List.sum_cons]
omega
end ContingencyTables.BalancedEnumeration
end OAI