roseking's picture
Add lean source and binary files (part 42)
d5b7741 verified
Raw History Blame Contribute Delete
4.14 kB
import OAI.Combinatorics.ContingencyTables.Rooted.LargeMarginSemantics
import OAI.Combinatorics.ContingencyTables.Dense.DenseCanonicalSemantics
namespace OAI
/-! # Computed reference coordinates for the large completion rectangle -/
namespace ContingencyTables.SmallGraphProfiles
open ProfilePrograms DensePrograms SmallContextCoordinates SmallContextFibres
open PhysicalCompletionFibres FirstPaperProfiles PaddedCompletions CompletionCounts
open scoped BigOperators Classical
noncomputable section
variable {m n q : ℕ}
def optionIndexEquiv (k : ℕ) (hk : 0 < k) : Option (Fin (k-1)) ≃ Fin k := by
cases k with
| zero => omega
| succ k => exact (finSuccEquiv k).symm
lemma optionIndex_marginCode (k : ℕ) (hk : 0 < k) (f : Fin k → ℕ) :
marginCode (fun i => f (optionIndexEquiv k hk i))=List.ofFn f := by
cases k with
| zero => omega
| succ k =>
rw [marginCode_ofFn]
apply congrArg List.ofFn
funext i
exact congrArg f ((finSuccEquiv k).symm_apply_apply i)
def largeOptionEquiv (r : Fin m → ℕ) (U : ℕ)
(hr : 0 < (largeIndices (U,List.ofFn r)).length) :
Option (Fin ((largeIndices (U,List.ofFn r)).length-1)) ≃ LargeRows r U :=
(optionIndexEquiv _ hr).trans (largeIndexEquiv r U)
lemma largeIndices_pos (r : Fin m → ℕ) (U : ℕ) (i : LargeRows r U) :
0 < (largeIndices (U,List.ofFn r)).length := by
apply List.length_pos_iff.mpr
intro he
have hm := (largeIndices_ofFn_mem r U i.val).mpr i.property
simp only [he,List.not_mem_nil] at hm
lemma largeOption_marginCode (r : Fin m → ℕ) (U : ℕ)
(hr : 0 < (largeIndices (U,List.ofFn r)).length) (f : LargeRows r U → ℕ) :
marginCode (fun i => f (largeOptionEquiv r U hr i))=
List.ofFn (fun i => f (largeIndexEquiv r U i)) :=
optionIndex_marginCode _ hr (fun i => f (largeIndexEquiv r U i))
def listedRows (r : Fin m → ℕ) (c : Fin n → ℕ) (U L : ℕ)
(B : Fin m → Fin n → ℕ) (hr : 0 < (largeIndices (U,List.ofFn r)).length)
(z : PhysicalStates (firstPaperSmall r c U) B r c L) :
Option (Fin ((largeIndices (U,List.ofFn r)).length-1)) → ℕ :=
fun i => residualRows (firstPaperSmall r c U) B r c L z (largeOptionEquiv r U hr i).val
def listedColumns (r : Fin m → ℕ) (c : Fin n → ℕ) (U L : ℕ)
(B : Fin m → Fin n → ℕ) (hc : 0 < (largeIndices (U,List.ofFn c)).length)
(z : PhysicalStates (firstPaperSmall r c U) B r c L) :
Option (Fin ((largeIndices (U,List.ofFn c)).length-1)) → ℕ :=
fun j => residualColumns (firstPaperSmall r c U) B r c L z (largeOptionEquiv c U hc j).val
theorem listedRows_code (r : Fin m → ℕ) (c : Fin n → ℕ) (U L : ℕ)
(B : Fin m → Fin n → ℕ) (hr : 0 < (largeIndices (U,List.ofFn r)).length)
(e : Fin q ≃ Cells (firstPaperSmall r c U))
(z : PhysicalStates (firstPaperSmall r c U) B r c L) :
marginCode (listedRows r c U L B hr z)=largePaddedMargins true
(((((cellCatalog (firstPaperSmall r c U) e,
viewList (firstPaperSmall r c U) e (physicalProfile _ B r c L z) false),
(List.ofFn r,List.ofFn c)),U),L)) := by
unfold listedRows
rw [largeOption_marginCode r U hr
(fun i : LargeRows r U => residualRows (firstPaperSmall r c U) B r c L z i.val),
largePaddedRows_code]
rfl
theorem listedColumns_code (r : Fin m → ℕ) (c : Fin n → ℕ) (U L : ℕ)
(B : Fin m → Fin n → ℕ) (hc : 0 < (largeIndices (U,List.ofFn c)).length)
(e : Fin q ≃ Cells (firstPaperSmall r c U))
(hB : ∀ a : Cells (firstPaperSmall r c U),B a.val.1 a.val.2=U)
(z : PhysicalStates (firstPaperSmall r c U) B r c L) :
marginCode (listedColumns r c U L B hc z)=largePaddedMargins false
(((((cellCatalog (firstPaperSmall r c U) e,
complementValues (U,viewList (firstPaperSmall r c U) e (physicalProfile _ B r c L z) true)),
(List.ofFn r,List.ofFn c)),U),L)) := by
unfold listedColumns
rw [largeOption_marginCode c U hc
(fun j : LargeColumns c U => residualColumns (firstPaperSmall r c U) B r c L z j.val),
largePaddedColumns_code r c U L e B hB]
rfl
end
end ContingencyTables.SmallGraphProfiles
end OAI