ClassicalMerging.lean
1module23public import SubentropyCertificates.ClassicalSSAKernel4import Mathlib.Tactic.Linarith5import Mathlib.Algebra.Order.BigOperators.Group.Finset6import Mathlib.Tactic.Ring78/-! The determinant deficit decreases under arbitrary row and column9mergings. A map sends each original label to its merged label; it need10not be surjective. -/11@[expose] public section12noncomputable section13open scoped BigOperators14namespace SubentropyCertificates.ClassicalSSA15variable {I J G : Type*} [Fintype I] [Fintype J] [Fintype G]1617def tableDeficit (t : ℝ) (p : I → J → ℝ) :=18 cells t Finset.univ p + factor t (mass Finset.univ p) - rows t Finset.univ p - cols t Finset.univ p1920def mergeRows [DecidableEq G] (f : I → G) (p : I → J → ℝ) (g : G) (j : J) :=21 ∑ i, if f i = g then p i j else 02223theorem table_deficit_nonnegative {t : ℝ} (ht : 0 ≤ t) (p : I → J → ℝ)24 (hp : ∀ i j, 0 ≤ p i j) : 0 ≤ tableDeficit t p := by25 unfold tableDeficit26 linarith only [table_subadditivity ht Finset.univ p hp]2728/-- Proposition classical-merging, for any map of row labels. -/29theorem merge_rows_deficit [DecidableEq G] (f : I → G) (p : I → J → ℝ)30 (hp : ∀ i j, 0 ≤ p i j) {t : ℝ} (ht : 0 ≤ t) :31 0 ≤ tableDeficit t (mergeRows f p) ∧ tableDeficit t (mergeRows f p) ≤ tableDeficit t p := by32 classical33 let q := mergeRows f p34 have hq (g j) : 0 ≤ q g j :=35 Finset.sum_nonneg (fun i _ => by split <;> simp [hp])36 refine ⟨table_deficit_nonnegative ht q hq, ?_⟩37 let w : I × G × J → ℝ := fun u => if f u.1 = u.2.1 then p u.1 u.2.2 else 038 have hw (u) : 0 ≤ w u := by dsimp [w]; split <;> simp [hp]39 have H := classical_ssa_kernel w hw ht40 have hAB : kernel t (marginalAB w) = rows t Finset.univ p := by41 simp [kernel, rows, marginalAB, rowMass, w, Fintype.prod_prod_type, apply_ite (factor t)]42 have hBC : kernel t (marginalBC w) = cells t Finset.univ q := by43 simp only [kernel, marginalBC, cells, Fintype.prod_prod_type, q, mergeRows, w]44 have hABC : kernel t w = cells t Finset.univ p := by45 simp [kernel, cells, w, Fintype.prod_prod_type, apply_ite (factor t)]46 have hB : marginalB w = rowMass q := by47 funext g48 exact Finset.sum_comm49 have hcol : colMass Finset.univ q = colMass Finset.univ p := by50 funext j51 simp only [colMass, q, mergeRows]52 rw [Finset.sum_comm]53 simp54 have hmass : mass Finset.univ q = mass Finset.univ p := by55 rw [← sum_colMass, hcol, sum_colMass]56 rw [hAB, hBC, hABC, hB] at H57 change rows t Finset.univ p + cells t Finset.univ q ≤ cells t Finset.univ p + rows t Finset.univ q at H58 change tableDeficit t q ≤ tableDeficit t p59 unfold tableDeficit cols60 rw [hmass, hcol]61 linarith only [H]6263private theorem deficit_transpose (t : ℝ) (p : I → J → ℝ) :64 tableDeficit t (fun j i => p i j) = tableDeficit t p := by65 simp only [tableDeficit, cells, kernel, mass, rows, cols, rowMass, colMass]66 rw [Finset.prod_comm (f := fun j i => factor t (p i j)), Finset.sum_comm (f := fun j i => p i j)]67 ring6869def mergeColumns [DecidableEq G] (f : J → G) (p : I → J → ℝ) (i : I) (g : G) :=70 ∑ j, if f j = g then p i j else 07172theorem merge_columns_deficit [DecidableEq G] (f : J → G) (p : I → J → ℝ)73 (hp : ∀ i j, 0 ≤ p i j) {t : ℝ} (ht : 0 ≤ t) :74 0 ≤ tableDeficit t (mergeColumns f p) ∧ tableDeficit t (mergeColumns f p) ≤ tableDeficit t p := by75 have h := merge_rows_deficit f (fun j i => p i j) (fun j i => hp i j) ht76 rw [deficit_transpose t p] at h77 rw [← deficit_transpose t (mergeColumns f p)]78 exact h7980end SubentropyCertificates.ClassicalSSA
Axioms used
Choose a statement to see which axioms its proof uses.