Download data/lean/OAI/Combinatorics/ContingencyTables/Rooted/ForestCut.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.73 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/ContingencyTables/Rooted/ForestCut.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/ContingencyTables/Rooted/ForestCut.lean
-
curl -L -o ForestCut.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/ContingencyTables/Rooted/ForestCut.lean
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 | |