introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
8.73 kB
import OAI.Combinatorics.ContingencyTables.Rooted.MaximumForest
import OAI.Combinatorics.ContingencyTables.Transport.RowColumnPenalties
namespace OAI
/-!
# Signed cut equations for the actual physical table views
Small row and column views may disagree. Their two incidences therefore
remain separate in the cut formula. Large cells have a single physical
value at both endpoints, so every internal large-cell contribution cancels.
-/
namespace ContingencyTables.ForestCut
open scoped BigOperators Classical
variable {I J : Type*} [Fintype I] [Fintype J]
def indicator (s : Bool) : ℝ := if s then 1 else 0
omit [Fintype I] [Fintype J] in
lemma abs_indicator_sub {a b : Bool} (h : a≠b) : |indicator a-indicator b|=1 := by
cases a <;> cases b <;> simp_all [indicator]
noncomputable def rowDifference (small : I β†’ J β†’ Bool) (x z X : I β†’ J β†’ ℝ) (i : I) : ℝ :=
βˆ‘ j, if small i j then x i j-X i j else z i j-X i j
noncomputable def columnDifference (small : I β†’ J β†’ Bool) (q z X : I β†’ J β†’ ℝ) (j : J) : ℝ :=
βˆ‘ i, if small i j then q i j-X i j else z i j-X i j
noncomputable def cutTerm (small : I β†’ J β†’ Bool) (rowU : I β†’ Bool) (colU : J β†’ Bool)
(x q z X : I β†’ J β†’ ℝ) (i : I) (j : J) : ℝ :=
if small i j then indicator (rowU i)*(x i j-X i j)-indicator (colU j)*(q i j-X i j)
else (indicator (rowU i)-indicator (colU j))*(z i j-X i j)
/-- Literal signed summation of the nonroot margin differences. -/
theorem signed_cut_identity (small : I β†’ J β†’ Bool) (rowU : I β†’ Bool) (colU : J β†’ Bool)
(x q z X : I β†’ J β†’ ℝ) :
(βˆ‘ i, indicator (rowU i)*rowDifference small x z X i)-
(βˆ‘ j, indicator (colU j)*columnDifference small q z X j) =
βˆ‘ i, βˆ‘ j, cutTerm small rowU colU x q z X i j := by
unfold rowDifference columnDifference cutTerm
simp_rw [Finset.mul_sum]
rw [Finset.sum_comm (f := fun j i => indicator (colU j)*
(if small i j then q i j-X i j else z i j-X i j))]
rw [← Finset.sum_sub_distrib]
apply Finset.sum_congr rfl
intro i _
rw [← Finset.sum_sub_distrib]
apply Finset.sum_congr rfl
intro j _
cases small i j <;> simp [sub_mul]
/-- When U avoids roots, all selected nonroot equations hold, giving
the source's cut cancellation even on unbalanced small profiles. -/
theorem cut_sum_zero (small : I β†’ J β†’ Bool) (rowU : I β†’ Bool) (colU : J β†’ Bool)
(x q z X : I β†’ J β†’ ℝ)
(hr : βˆ€ i, rowU i=true β†’ rowDifference small x z X i=0)
(hc : βˆ€ j, colU j=true β†’ columnDifference small q z X j=0) :
(βˆ‘ i, βˆ‘ j, cutTerm small rowU colU x q z X i j)=0 := by
rw [← signed_cut_identity]
have hrow : βˆ€ i, indicator (rowU i)*rowDifference small x z X i=0 := by
intro i
cases hi : rowU i
Β· simp [indicator]
Β· simp [indicator,hr i hi]
have hcol : βˆ€ j, indicator (colU j)*columnDifference small q z X j=0 := by
intro j
cases hj : colU j
Β· simp [indicator]
Β· simp [indicator,hc j hj]
simp only [hrow,hcol,Finset.sum_const_zero,sub_self]
omit [Fintype I] [Fintype J] in
lemma small_term_bound (small : I β†’ J β†’ Bool) (rowU : I β†’ Bool) (colU : J β†’ Bool)
(x q z X : I β†’ J β†’ ℝ) (i : I) (j : J) (b B : ℝ)
(hs : small i j=true) (hb : b≀B)
(hx : 0≀x i j ∧ x i j≀b) (hq : 0≀q i j ∧ q i j≀b)
(hX : 0≀X i j ∧ X i j≀b) :
|cutTerm small rowU colU x q z X i j|≀2*B := by
simp only [cutTerm,hs,ite_true]
have hmul : βˆ€ s : Bool, βˆ€ a : ℝ, |indicator s*a|≀|a| := by
intro s a
cases s <;> simp [indicator]
have hx' : |x i j-X i j|≀b := by
apply abs_le.mpr
constructor <;> linarith [hx.1,hx.2,hX.1,hX.2]
have hq' : |q i j-X i j|≀b := by
apply abs_le.mpr
constructor <;> linarith [hq.1,hq.2,hX.1,hX.2]
calc
_≀|indicator (rowU i)*(x i j-X i j)|+|indicator (colU j)*(q i j-X i j)| := abs_sub _ _
_≀|x i j-X i j|+|q i j-X i j| := add_le_add (hmul _ _) (hmul _ _)
_≀2*B := by linarith
omit [Fintype I] [Fintype J] in
lemma free_term_bound (small : I β†’ J β†’ Bool) (rowU : I β†’ Bool) (colU : J β†’ Bool)
(x q z X : I β†’ J β†’ ℝ) (i : I) (j : J) (b B : ℝ)
(hs : small i j=false) (hB : 1≀B)
(hcap : rowU iβ‰ colU j β†’ b≀B)
(hz : 0≀z i j ∧ z i j≀b+1) (hX : 0≀X i j ∧ X i j≀b) :
|cutTerm small rowU colU x q z X i j|≀2*B := by
by_cases hc : rowU i=colU j
Β· simp [cutTerm,hs,hc]
linarith
Β· have hb := hcap hc
have hdiff : |z i j-X i j|≀2*B := by
apply abs_le.mpr
constructor <;> linarith [hz.1,hz.2,hX.1,hX.2]
simp only [cutTerm,hs,Bool.false_eq_true,ite_false,abs_mul,abs_indicator_sub hc,one_mul]
exact hdiff
/-- Isolating the sole crossing tree edge in the actual signed cut
equations gives the forest displacement bound. Small cells retain both
incidences, so the statement covers every unbalanced small profile. -/
theorem displacement_bound (small tree : I β†’ J β†’ Bool)
(rowU : I β†’ Bool) (colU : J β†’ Bool) (x q z X b : I β†’ J β†’ ℝ)
(iβ‚€ : I) (jβ‚€ : J) (d : ℝ)
(hd : (Fintype.card I*Fintype.card J : β„•)≀d)
(hB : 1≀b iβ‚€ jβ‚€) (hsβ‚€ : small iβ‚€ jβ‚€=false)
(hcross : rowU iβ‚€β‰ colU jβ‚€)
(hr : βˆ€ i, rowU i=true β†’ rowDifference small x z X i=0)
(hc : βˆ€ j, colU j=true β†’ columnDifference small q z X j=0)
(hX : βˆ€ i j, 0≀X i j ∧ X i j≀b i j)
(hsmall : βˆ€ i j, small i j=true β†’
b i j≀b iβ‚€ jβ‚€ ∧ (0≀x i j ∧ x i j≀b i j) ∧ (0≀q i j ∧ q i j≀b i j))
(htree : βˆ€ i j, tree i j=true β†’ (i,j)β‰ (iβ‚€,jβ‚€) β†’ rowU i=colU j)
(hfree : βˆ€ i j, small i j=false β†’ tree i j=false β†’
(0≀z i j ∧ z i j≀b i j+1) ∧ (rowU iβ‰ colU j β†’ b i j≀b iβ‚€ jβ‚€)) :
|z iβ‚€ jβ‚€-X iβ‚€ jβ‚€|≀4*d*b iβ‚€ jβ‚€ := by
let f : IΓ—J β†’ ℝ := fun a => cutTerm small rowU colU x q z X a.1 a.2
have hsum : (βˆ‘ a, f a)=0 := by
simpa only [Fintype.sum_prod_type,f] using cut_sum_zero small rowU colU x q z X hr hc
have hrest : βˆ€ a∈(Finset.univ.erase (iβ‚€,jβ‚€) : Finset (IΓ—J)), |f a|≀2*b iβ‚€ jβ‚€ := by
rintro ⟨i,j⟩ ha
have hne : (i,j)β‰ (iβ‚€,jβ‚€) := (Finset.mem_erase.mp ha).1
by_cases hs : small i j=true
Β· exact small_term_bound small rowU colU x q z X i j (b i j) (b iβ‚€ jβ‚€)
hs (hsmall i j hs).1 (hsmall i j hs).2.1 (hsmall i j hs).2.2 (hX i j)
Β· have hs' : small i j=false := Bool.eq_false_iff.mpr hs
by_cases ht : tree i j=true
Β· have he := htree i j ht hne
simp [f,cutTerm,hs',he]
linarith
Β· have ht' : tree i j=false := Bool.eq_false_iff.mpr ht
exact free_term_bound small rowU colU x q z X i j (b i j) (b iβ‚€ jβ‚€)
hs' hB (hfree i j hs' ht').2 (hfree i j hs' ht').1 (hX i j)
have hsplit := Finset.sum_erase_add (s := (Finset.univ : Finset (IΓ—J)))
(a := (iβ‚€,jβ‚€)) f (Finset.mem_univ _)
have hisolate : f (iβ‚€,jβ‚€)=-(βˆ‘ a∈Finset.univ.erase (iβ‚€,jβ‚€), f a) := by
rw [hsum] at hsplit
linarith
have htarget : |f (iβ‚€,jβ‚€)|=|z iβ‚€ jβ‚€-X iβ‚€ jβ‚€| := by
simp only [f,cutTerm,hsβ‚€,Bool.false_eq_true,ite_false,abs_mul,
abs_indicator_sub hcross,one_mul]
have hbound : |f (iβ‚€,jβ‚€)|≀(Fintype.card I*Fintype.card J:β„•)*(2*b iβ‚€ jβ‚€) := by
rw [hisolate,abs_neg]
calc
|βˆ‘ a∈Finset.univ.erase (iβ‚€,jβ‚€), f a|≀
βˆ‘ a∈Finset.univ.erase (iβ‚€,jβ‚€), |f a| := Finset.abs_sum_le_sum_abs _ _
_β‰€βˆ‘ _a∈(Finset.univ.erase (iβ‚€,jβ‚€) : Finset (IΓ—J)), 2*b iβ‚€ jβ‚€ :=
Finset.sum_le_sum hrest
_≀(Fintype.card I*Fintype.card J:β„•)*(2*b iβ‚€ jβ‚€) := by
simp only [Finset.sum_const,Finset.card_erase_of_mem (Finset.mem_univ _),
Finset.card_univ,Fintype.card_prod,nsmul_eq_mul]
have hn : (Fintype.card I*Fintype.card J-1:β„•)≀Fintype.card I*Fintype.card J := Nat.sub_le _ _
exact mul_le_mul_of_nonneg_right (by exact_mod_cast hn) (by linarith)
rw [htarget] at hbound
have hdb : 0≀d := le_trans (Nat.cast_nonneg _) hd
have hn : (Fintype.card I*Fintype.card J:β„•)* (2*b iβ‚€ jβ‚€)≀2*d*b iβ‚€ jβ‚€ := by
nlinarith
exact hbound.trans (hn.trans (by nlinarith))
/-- The interval bound needed in the equality-softening count argument
follows from the proved cut displacement estimate, with ample slack. -/
lemma physical_interval_of_displacement (d b X z : ℝ) (hd : 1 ≀ d) (hb : 0 ≀ b)
(hX : 0 ≀ X ∧ X ≀ b) (hz : |z-X| ≀ 4*d*b) :
-10*d*b ≀ z ∧ z ≀ 10*d*b := by
have h := abs_le.mp hz
have hdb : 0 ≀ d*b := mul_nonneg (by linarith) hb
have hbdb : b ≀ d*b := by nlinarith
constructor <;> nlinarith
end ContingencyTables.ForestCut
end OAI