math / data /lean /OAI /Computability /MatchingCount /CutAlgebra.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
4.5 kB
import OAI.Computability.MatchingCount.UnitFlow
namespace OAI
section
namespace BinaryMatching.CutAlgebra
open Finset UnitFlow
variable {V W : Type*} [Fintype V] [DecidableEq V] [Fintype W] [DecidableEq W]
abbrev cross (S : Finset V) (i j : V) : Prop := i∈S ∧ jβˆ‰S
lemma cutCapacity_eq (c : V β†’ V β†’ β„•) (S : Finset V) :
cutCapacity c S = βˆ‘ i, βˆ‘ j, if cross S i j then c i j else 0 := by
simp only [cutCapacity,cross,ite_and]
simp [Finset.sum_ite_irrel]
apply sum_congr rfl; intro i hi
have hSc : Sᢜ = univ.filter (fun j => jβˆ‰S) := by ext j; simp
rw [hSc,sum_filter]
simp
lemma cut_compl (c : V β†’ V β†’ β„•) (hc : βˆ€ i j, c i j=c j i) (S : Finset V) :
cutCapacity c Sᢜ = cutCapacity c S := by
rw [cutCapacity_eq,cutCapacity_eq,sum_comm]
apply sum_congr rfl; intro i hi
apply sum_congr rfl; intro j hj
simp only [cross,mem_compl,not_not]
rw [hc j i]
by_cases his : i∈S <;> by_cases hjs : j∈S <;> simp [his,hjs]
lemma cut_submodular (c : V β†’ V β†’ β„•) (S A : Finset V) :
cutCapacity c (S∩A) + cutCapacity c (SβˆͺA) ≀ cutCapacity c S + cutCapacity c A := by
simp only [cutCapacity_eq,← sum_add_distrib]
apply sum_le_sum; intro i hi
apply sum_le_sum; intro j hj
by_cases his : i∈S <;> by_cases hia : i∈A <;>
by_cases hjs : j∈S <;> by_cases hja : j∈A <;>
simp [cross,his,hia,hjs,hja]
def push (c : V β†’ V β†’ β„•) (f : V β†’ W) (i j : W) : β„• :=
if i=j then 0 else βˆ‘ u, βˆ‘ v, if f u=i ∧ f v=j then c u v else 0
def lift (f : V β†’ W) (T : Finset W) : Finset V := univ.filter (fun v => f v∈T)
omit [DecidableEq V] [Fintype W] in
lemma mem_lift (f : V β†’ W) (T : Finset W) (v : V) : v∈lift f T ↔ f v∈T := by
simp [lift]
omit [DecidableEq V] [Fintype W] in
lemma push_symm (c : V β†’ V β†’ β„•) (hc : βˆ€ i j, c i j=c j i) (f : V β†’ W) :
βˆ€ i j, push c f i j=push c f j i := by
intro i j
by_cases hij : i=j
Β· subst j; rfl
simp only [push,ite_eq_right hij,ite_eq_right (Ne.symm hij)]
rw [sum_comm]
apply sum_congr rfl; intro u hu
apply sum_congr rfl; intro v hv
rw [hc v u]
simp only [and_comm]
omit [DecidableEq V] [Fintype W] in
lemma push_diag (c : V β†’ V β†’ β„•) (f : V β†’ W) (i : W) : push c f i i=0 := by
simp [push]
omit [DecidableEq V] [DecidableEq W] in
lemma sum_four_swap (h : W β†’ W β†’ V β†’ V β†’ β„•) :
(βˆ‘ i, βˆ‘ j, βˆ‘ u, βˆ‘ v, h i j u v) = βˆ‘ u, βˆ‘ v, βˆ‘ i, βˆ‘ j, h i j u v := by
calc
_ = βˆ‘ i, βˆ‘ u, βˆ‘ j, βˆ‘ v, h i j u v := by
apply sum_congr rfl; intro i hi
rw [sum_comm]
_ = βˆ‘ u, βˆ‘ i, βˆ‘ j, βˆ‘ v, h i j u v := by rw [sum_comm]
_ = βˆ‘ u, βˆ‘ i, βˆ‘ v, βˆ‘ j, h i j u v := by
apply sum_congr rfl; intro u hu
apply sum_congr rfl; intro i hi
rw [sum_comm]
_ = _ := by
apply sum_congr rfl; intro u hu
rw [sum_comm]
lemma cut_push (c : V β†’ V β†’ β„•) (f : V β†’ W) (T : Finset W) :
cutCapacity (push c f) T = cutCapacity c (lift f T) := by
rw [cutCapacity_eq,cutCapacity_eq]
have he : βˆ€ i j, (if cross T i j then push c f i j else 0) =
βˆ‘ u, βˆ‘ v, if cross T (f u) (f v) ∧ f u=i ∧ f v=j then c u v else 0 := by
intro i j
by_cases hh : cross T i j
· have hij : i≠j := by intro h; subst j; exact hh.2 hh.1
simp only [ite_eq_left hh,push,ite_eq_right hij]
apply sum_congr rfl; intro u hu
apply sum_congr rfl; intro v hv
by_cases hui : f u=i <;> by_cases hvj : f v=j <;> simp_all
Β· simp only [ite_eq_right hh]
symm
apply sum_eq_zero; intro u hu
apply sum_eq_zero; intro v hv
by_cases hui : f u=i <;> by_cases hvj : f v=j <;> simp_all
simp_rw [he]
rw [sum_four_swap]
apply sum_congr rfl; intro u hu
apply sum_congr rfl; intro v hv
simp only [cross,mem_lift]
by_cases hh : f u∈T ∧ f vβˆ‰T
Β· simp only [hh,true_and]
simp [ite_and,Finset.sum_ite_irrel,eq_comm]
Β· simp [hh]
omit [DecidableEq V] in
lemma push_total_le (c : V β†’ V β†’ β„•) (f : V β†’ W) :
(βˆ‘ i, βˆ‘ j, push c f i j) ≀ βˆ‘ u, βˆ‘ v, c u v := by
calc
_ ≀ βˆ‘ i, βˆ‘ j, βˆ‘ u, βˆ‘ v, if f u=i ∧ f v=j then c u v else 0 := by
apply sum_le_sum; intro i hi
apply sum_le_sum; intro j hj
simp only [push]
split_ifs <;> omega
_ = _ := by
rw [sum_four_swap]
apply sum_congr rfl; intro u hu
apply sum_congr rfl; intro v hv
simp [ite_and,Finset.sum_ite_irrel,eq_comm]
end BinaryMatching.CutAlgebra
end
end OAI