File size: 17,589 Bytes
e5a97c6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | import Mathlib
import OAI.Combinatorics.MatchingCount.Graphs.SumLiftMate
namespace OAI
namespace MatchingFPRAS.Subdivision
open Finset
lemma valid_step_eq_iff {m : ℕ} {U : Finset (Fin m)} {b c : Selection m}
(hb : Valid U b) (hc : Valid U c) (i : Fin m) :
b i.castSucc = c i.castSucc ↔ b i.succ = c i.succ := by
by_cases hi : i ∈ U
· have hb' := hb i
have hc' := hc i
simp only [hi, ↓reduceIte] at hb' hc'
simp [hb'.1,hb'.2,hc'.1,hc'.2]
· have hb' : b i.succ = !(b i.castSucc) := by
apply (bool_ne_iff_eq_not _ _).mp
simpa only [hi, ↓reduceIte] using hb i
have hc' : c i.succ = !(c i.castSucc) := by
apply (bool_ne_iff_eq_not _ _).mp
simpa only [hi, ↓reduceIte] using hc i
rw [hb',hc']
simp
lemma valid_eq_iff_zero {m : ℕ} {U : Finset (Fin m)} {b c : Selection m}
(hb : Valid U b) (hc : Valid U c) (i : Fin (m+1)) :
b i = c i ↔ b 0 = c 0 := by
have aux (k : ℕ) (hk : k < m+1) : b ⟨k,hk⟩ = c ⟨k,hk⟩ ↔ b 0 = c 0 := by
induction k with
| zero => rfl
| succ k ih =>
have hk' : k < m := by omega
exact ((valid_step_eq_iff hb hc ⟨k,hk'⟩).symm).trans (ih (by omega))
exact aux i.val i.isLt
theorem broken_unique {m : ℕ} {U : Finset (Fin m)} (hU : U.Nonempty)
{b c : Selection m} (hb : Valid U b) (hc : Valid U c) : b = c := by
obtain ⟨j,hj⟩ := hU
have hb' := hb j
have hc' := hc j
simp only [hj, ↓reduceIte] at hb' hc'
have hzero := (valid_eq_iff_zero hb hc j.castSucc).mp (hb'.1.trans hc'.1.symm)
funext i
exact (valid_eq_iff_zero hb hc i).mpr hzero
noncomputable def profile (p : ℕ) (B Hu Hv lam : ℝ) : List ℝ :=
duplicate (List.ofFn fun r : Fin p => max B (Hu / 2^r.val)) ++ [lam] ++
duplicate ((List.ofFn fun r : Fin p => max B (Hv / 2^r.val)).reverse)
@[simp] theorem profile_length (p : ℕ) (B Hu Hv lam : ℝ) :
(profile p B Hu Hv lam).length = 4*p+1 := by simp [profile]; omega
noncomputable def profileActivity (p : ℕ) (B Hu Hv lam : ℝ) (i : Fin (4*p+1)) : ℝ :=
(profile p B Hu Hv lam).get (i.cast (profile_length p B Hu Hv lam).symm)
theorem profileActivity_ofFn (p : ℕ) (B Hu Hv lam : ℝ) :
List.ofFn (profileActivity p B Hu Hv lam) = profile p B Hu Hv lam := by
apply List.ext_getElem
· simp
· intro i hi hj
simp only [List.getElem_ofFn, profileActivity, List.get_eq_getElem, Fin.val_cast]
theorem exact_profile_weight (p : ℕ) (B Hu Hv lam : ℝ) (a : Bool) :
selectedWeight (profileActivity p B Hu Hv lam)
(fun i => alternating a i.val) =
((∏ r : Fin p, max B (Hu / 2^r.val)) *
(∏ r : Fin p, max B (Hv / 2^r.val))) * (if a then lam else 1) := by
rw [intact_weight _ _ (alternating_valid _ _),profileActivity_ofFn]
simpa [profile,List.prod_ofFn] using
profile_weight a (List.ofFn fun r : Fin p => max B (Hu / 2^r.val))
((List.ofFn fun r : Fin p => max B (Hv / 2^r.val)).reverse) lam
section Deletion
variable {V E : Type*} [Fintype V] [Fintype E]
def Uses {m : ℕ} (u v : E → V) (b : E → Selection m) (e : E) (x : V) : Prop :=
(b e 0 = true ∧ u e = x) ∨ (b e (Fin.last m) = true ∧ v e = x)
def FamilyHoles (u v : E → V) (m : ℕ) (R₀ : Finset V) (U : E → Finset (Fin m))
(b : E → Selection m) : Prop :=
(∀ e, Valid (U e) (b e)) ∧
(∀ x ∈ R₀, ∀ e, ¬ Uses u v b e x) ∧
(∀ x ∉ R₀, ∃! e, Uses u v b e x)
noncomputable def broken {m : ℕ} (U : E → Finset (Fin m)) : Finset E := by
classical
exact Finset.univ.filter fun e => (U e).Nonempty
@[simp] lemma mem_broken {m : ℕ} (U : E → Finset (Fin m)) (e : E) :
e ∈ broken U ↔ (U e).Nonempty := by
classical
simp [broken]
noncomputable def residualHoles {m : ℕ} (u v : E → V) (R₀ : Finset V)
(U : E → Finset (Fin m)) (b : E → Selection m) : Finset V := by
classical
exact R₀ ∪ Finset.univ.filter (fun x => ∃ e ∈ broken U, Uses u v b e x)
@[simp] lemma mem_residualHoles {m : ℕ} (u v : E → V) (R₀ : Finset V)
(U : E → Finset (Fin m)) (b : E → Selection m) (x : V) :
x ∈ residualHoles u v R₀ U b ↔ x ∈ R₀ ∨ ∃ e ∈ broken U, Uses u v b e x := by
classical
simp [residualHoles]
theorem residualHoles_independent {m : ℕ} (u v : E → V) (R₀ : Finset V)
(U : E → Finset (Fin m)) {b c : E → Selection m}
(hb : FamilyHoles u v m R₀ U b) (hc : FamilyHoles u v m R₀ U c) :
residualHoles u v R₀ U b = residualHoles u v R₀ U c := by
classical
have he (e) (h : e ∈ broken U) : b e = c e :=
broken_unique ((mem_broken U e).mp h) (hb.1 e) (hc.1 e)
ext x
simp only [mem_residualHoles]
apply or_congr Iff.rfl
apply exists_congr
intro e
constructor <;> rintro ⟨h,hx⟩ <;> refine ⟨h,?_⟩
· simpa only [Uses,he e h] using hx
· simpa only [Uses,he e h] using hx
def LogicalHoles (u v : E → V) (R : Finset V) (forbidden : Finset E)
(s : E → Bool) : Prop :=
(∀ e ∈ forbidden, s e = false) ∧
(∀ x ∈ R, ∀ e, ¬ (s e = true ∧ (u e = x ∨ v e = x))) ∧
(∀ x ∉ R, ∃! e, s e = true ∧ (u e = x ∨ v e = x))
noncomputable def extract {m : ℕ} (U : E → Finset (Fin m))
(b : E → Selection m) (e : E) : Bool :=
if (U e).Nonempty then false else b e 0
omit [Fintype V] [Fintype E] in
lemma intact_uses {m : ℕ} (hm : Even m) (u v : E → V) (b : E → Selection m)
(e : E) (x : V) (hb : Valid ∅ (b e)) :
Uses u v b e x ↔ b e 0 = true ∧ (u e = x ∨ v e = x) := by
rw [Uses,intact_terminals hm _ hb]
exact and_or_left.symm
theorem extract_legal {m : ℕ} (hm : Even m) (u v : E → V) (R₀ : Finset V)
(U : E → Finset (Fin m)) (b : E → Selection m)
(hb : FamilyHoles u v m R₀ U b) :
LogicalHoles u v (residualHoles u v R₀ U b) (broken U) (extract U b) := by
classical
have he (e x) : extract U b e = true ∧ (u e = x ∨ v e = x) ↔
e ∉ broken U ∧ Uses u v b e x := by
by_cases h : (U e).Nonempty
· simp [extract,h]
· have hu : U e = ∅ := Finset.not_nonempty_iff_eq_empty.mp h
simp only [extract,h,↓reduceIte,mem_broken,not_false_eq_true,true_and]
exact (intact_uses hm u v b e x (by simpa [hu] using hb.1 e)).symm
refine ⟨?_,?_,?_⟩
· intro e he'
simp [extract,(mem_broken U e).mp he']
· intro x hx e hxe
rw [he] at hxe
rcases (mem_residualHoles u v R₀ U b x).mp hx with hx | ⟨f,hf,hfx⟩
· exact hb.2.1 x hx e hxe.2
· have hx0 : x ∉ R₀ := by intro hx0; exact hb.2.1 x hx0 f hfx
obtain ⟨a,ha,hu⟩ := hb.2.2 x hx0
have hef : e = f := (hu e hxe.2).trans (hu f hfx).symm
exact hxe.1 (hef.symm ▸ hf)
· intro x hx
have hx0 : x ∉ R₀ := by intro h; exact hx ((mem_residualHoles _ _ _ _ _ _).mpr (Or.inl h))
obtain ⟨e,he',hu⟩ := hb.2.2 x hx0
have hn : e ∉ broken U := by
intro h
exact hx ((mem_residualHoles _ _ _ _ _ _).mpr (Or.inr ⟨e,h,he'⟩))
refine ⟨e,(he e x).mpr ⟨hn,he'⟩,?_⟩
intro f hf
exact hu f ((he f x).mp hf).2
noncomputable def rebuild {m : ℕ} (U : E → Finset (Fin m))
(base : E → Selection m) (s : E → Bool) (e : E) : Selection m :=
if (U e).Nonempty then base e else fun i => alternating (s e) i.val
omit [Fintype V] in
lemma rebuild_uses {m : ℕ} (hm : Even m) (u v : E → V)
(U : E → Finset (Fin m)) (base : E → Selection m) (s : E → Bool) (e : E) (x : V) :
Uses u v (rebuild U base s) e x ↔
(e ∈ broken U ∧ Uses u v base e x) ∨
(e ∉ broken U ∧ s e = true ∧ (u e = x ∨ v e = x)) := by
classical
by_cases h : (U e).Nonempty
· simp [rebuild,h,Uses]
· simp [rebuild,h,Uses,alternating,Nat.even_iff.mp hm,and_or_left]
theorem rebuild_legal {m : ℕ} (hm : Even m) (u v : E → V) (R₀ : Finset V)
(U : E → Finset (Fin m)) (base : E → Selection m)
(hb : FamilyHoles u v m R₀ U base) (s : E → Bool)
(hs : LogicalHoles u v (residualHoles u v R₀ U base) (broken U) s) :
FamilyHoles u v m R₀ U (rebuild U base s) := by
classical
let R := residualHoles u v R₀ U base
have hu (e x) := rebuild_uses hm u v U base s e x
refine ⟨?_,?_,?_⟩
· intro e
by_cases he : (U e).Nonempty
· simpa [rebuild,he] using hb.1 e
· have he' : U e = ∅ := Finset.not_nonempty_iff_eq_empty.mp he
simpa [rebuild,he,he'] using alternating_valid m (s e)
· intro x hx e he
have hxR : x ∈ R := (mem_residualHoles _ _ _ _ _ _).mpr (Or.inl hx)
rcases (hu e x).mp he with ⟨_,he⟩ | ⟨_,he⟩
· exact hb.2.1 x hx e he
· exact hs.2.1 x hxR e he
· intro x hx
by_cases hxR : x ∈ R
· obtain hx0 | ⟨e,he,hxe⟩ := (mem_residualHoles _ _ _ _ _ _).mp hxR
· exact (hx hx0).elim
obtain ⟨a,ha,hauniq⟩ := hb.2.2 x hx
refine ⟨e,(hu e x).mpr (Or.inl ⟨he,hxe⟩),?_⟩
intro f hf
rcases (hu f x).mp hf with ⟨_,hf⟩ | ⟨_,hf⟩
· exact (hauniq f hf).trans (hauniq e hxe).symm
· exact (hs.2.1 x hxR f hf).elim
· obtain ⟨e,he,heuniq⟩ := hs.2.2 x hxR
have hen : e ∉ broken U := by
intro he'
have := hs.1 e he'
simp [this] at he
refine ⟨e,(hu e x).mpr (Or.inr ⟨hen,he⟩),?_⟩
intro f hf
rcases (hu f x).mp hf with ⟨hfb,hf⟩ | ⟨_,hf⟩
· exact (hxR ((mem_residualHoles _ _ _ _ _ _).mpr (Or.inr ⟨f,hfb,hf⟩))).elim
· exact heuniq f hf
omit [Fintype V] [Fintype E] in
theorem rebuild_extract [Fintype V] [Fintype E] {m : ℕ} (u v : E → V) (R₀ : Finset V)
(U : E → Finset (Fin m)) (base b : E → Selection m)
(hb0 : FamilyHoles u v m R₀ U base) (hb : FamilyHoles u v m R₀ U b) :
rebuild U base (extract U b) = b := by
classical
funext e i
by_cases he : (U e).Nonempty
· have hbe := broken_unique he (hb0.1 e) (hb.1 e)
simp [rebuild,he,hbe]
· have he' : U e = ∅ := Finset.not_nonempty_iff_eq_empty.mp he
have hl := (intact_iff (b e)).mp (by simpa [he'] using hb.1 e) i
simpa [rebuild,extract,he] using hl.symm
omit [Fintype V] [Fintype E] in
theorem extract_rebuild [Fintype V] [Fintype E] {m : ℕ} (u v : E → V) (R : Finset V)
(U : E → Finset (Fin m)) (base : E → Selection m) (s : E → Bool)
(hs : LogicalHoles u v R (broken U) s) :
extract U (rebuild U base s) = s := by
classical
funext e
by_cases he : (U e).Nonempty
· have hs' := hs.1 e ((mem_broken U e).mpr he)
simp [extract,he,hs']
· simp [extract,rebuild,he]
noncomputable def deletionEquiv {m : ℕ} (hm : Even m) (u v : E → V) (R₀ : Finset V)
(U : E → Finset (Fin m)) (base : E → Selection m)
(hb : FamilyHoles u v m R₀ U base) :
{b : E → Selection m // FamilyHoles u v m R₀ U b} ≃
{s : E → Bool // LogicalHoles u v (residualHoles u v R₀ U base) (broken U) s} where
toFun b := ⟨extract U b.val, by
have h := extract_legal hm u v R₀ U b.val b.property
rwa [residualHoles_independent u v R₀ U b.property hb] at h⟩
invFun s := ⟨rebuild U base s.val,rebuild_legal hm u v R₀ U base hb s.val s.property⟩
left_inv b := Subtype.ext (rebuild_extract u v R₀ U base b.val hb b.property)
right_inv s := Subtype.ext (extract_rebuild u v _ U base s.val s.property)
noncomputable def realHolePartition (u v : E → V) (m : ℕ) (R₀ : Finset V)
(U : E → Finset (Fin m)) (w : E → Fin (m+1) → ℝ) : ℝ := by
classical
letI := Fintype.ofFinite {b : E → Selection m // FamilyHoles u v m R₀ U b}
exact ∑ b : {b : E → Selection m // FamilyHoles u v m R₀ U b},
∏ e, selectedWeight (w e) (b.val e)
noncomputable def logicalHolePartition (u v : E → V) (R : Finset V)
(forbidden : Finset E) (lam : E → ℝ) : ℝ := by
classical
letI := Fintype.ofFinite {s : E → Bool // LogicalHoles u v R forbidden s}
exact ∑ s : {s : E → Bool // LogicalHoles u v R forbidden s},
∏ e, if s.val e then lam e else 1
noncomputable def deletionConstant {m : ℕ} (U : E → Finset (Fin m))
(base : E → Selection m) (w : E → Fin (m+1) → ℝ) (C : E → ℝ) : ℝ :=
∏ e, if (U e).Nonempty then selectedWeight (w e) (base e) else C e
omit [Fintype V] [Fintype E] in
theorem deletion_weight [Fintype V] [Fintype E] {m : ℕ} (u v : E → V) (R₀ : Finset V)
(U : E → Finset (Fin m)) (base b : E → Selection m)
(hb0 : FamilyHoles u v m R₀ U base) (hb : FamilyHoles u v m R₀ U b)
(w : E → Fin (m+1) → ℝ) (left right : E → List ℝ) (lam : E → ℝ)
(hw : ∀ e, List.ofFn (w e) = duplicate (left e) ++ [lam e] ++ duplicate (right e)) :
(∏ e, selectedWeight (w e) (b e)) =
deletionConstant U base w (fun e => (left e).prod * (right e).prod) *
∏ e, if extract U b e then lam e else 1 := by
classical
unfold deletionConstant
rw [← Finset.prod_mul_distrib]
apply Finset.prod_congr rfl
intro e _
by_cases he : (U e).Nonempty
· have heq := broken_unique he (hb0.1 e) (hb.1 e)
simp [extract,he,heq]
· have he' : U e = ∅ := Finset.not_nonempty_iff_eq_empty.mp he
simp only [extract,he,↓reduceIte]
rw [intact_weight _ _ (by simpa [he'] using hb.1 e),hw e,profile_weight]
theorem deletion_partition_identity {m : ℕ} (hm : Even m) (u v : E → V) (R₀ : Finset V)
(U : E → Finset (Fin m)) (base : E → Selection m)
(hb : FamilyHoles u v m R₀ U base)
(w : E → Fin (m+1) → ℝ) (left right : E → List ℝ) (lam : E → ℝ)
(hw : ∀ e, List.ofFn (w e) = duplicate (left e) ++ [lam e] ++ duplicate (right e)) :
realHolePartition u v m R₀ U w =
deletionConstant U base w (fun e => (left e).prod * (right e).prod) *
logicalHolePartition u v (residualHoles u v R₀ U base) (broken U) lam := by
classical
let := Fintype.ofFinite {b : E → Selection m // FamilyHoles u v m R₀ U b}
let := Fintype.ofFinite {s : E → Bool //
LogicalHoles u v (residualHoles u v R₀ U base) (broken U) s}
unfold realHolePartition logicalHolePartition
rw [Finset.mul_sum]
apply Fintype.sum_equiv (deletionEquiv hm u v R₀ U base hb)
intro b
exact deletion_weight u v R₀ U base b.val hb b.property w left right lam hw
end Deletion
theorem selectedWeight_vertex_factor {m : ℕ} (U : Finset (Fin m))
(b : Selection m) (hb : Valid U b) (z : Fin (m+2) → ℝ) :
selectedWeight (fun i => z i.castSucc * z i.succ) b =
(if b 0 then z 0 else 1) * (if b (Fin.last m) then z (Fin.last (m+1)) else 1) *
∏ i : Fin m, if i ∈ U then 1 else z i.succ.castSucc := by
classical
unfold selectedWeight
have hsplit (i : Fin (m+1)) :
(if b i then z i.castSucc * z i.succ else 1) =
(if b i then z i.castSucc else 1) * (if b i then z i.succ else 1) := by
cases b i <;> simp
simp_rw [hsplit]
rw [Finset.prod_mul_distrib,
Fin.prod_univ_succ (fun i : Fin (m+1) => if b i then z i.castSucc else 1),
Fin.prod_univ_castSucc (fun i : Fin (m+1) => if b i then z i.succ else 1)]
have he : ∀ i : Fin m,
(if b i.succ then z i.succ.castSucc else 1) *
(if b i.castSucc then z i.castSucc.succ else 1) =
if i ∈ U then 1 else z i.succ.castSucc := by
intro i
have hz : i.castSucc.succ = i.succ.castSucc := rfl
rw [hz]
have h := hb i
by_cases hi : i ∈ U
· simp only [hi,↓reduceIte] at h ⊢
simp [h.1,h.2]
· simp only [hi,↓reduceIte] at h ⊢
cases h₁ : b i.castSucc <;> cases h₂ : b i.succ <;> simp_all
calc
_ = (if b 0 then z 0 else 1) * (if b (Fin.last m) then z (Fin.last (m+1)) else 1) *
∏ i : Fin m, ((if b i.succ then z i.succ.castSucc else 1) *
(if b i.castSucc then z i.castSucc.succ else 1)) := by
rw [Finset.prod_mul_distrib]
simp only [Fin.castSucc_zero, Fin.succ_last]
ring
_ = _ := by simp_rw [he]
theorem valid_interval {m : ℕ} {U : Finset (Fin m)} {b : Selection m}
(hb : Valid U b) (a k : ℕ) (hak : a+k ≤ m)
(hfree : ∀ i : Fin m, a ≤ i.val → i.val < a+k → i ∉ U) :
b ⟨a+k,by omega⟩ = alternating (b ⟨a,by omega⟩) k := by
induction k with
| zero => simp
| succ k ih =>
have hai : a+k < m := by omega
have hf := hb ⟨a+k,hai⟩
simp only [hfree ⟨a+k,hai⟩ (by dsimp; omega) (by dsimp; omega),↓reduceIte] at hf
have he := (bool_ne_iff_eq_not _ _).mp hf
have hi := ih (by omega) (fun i hi hj => hfree i hi (by omega))
simpa only [Fin.succ_mk, Fin.castSucc_mk, Nat.add_assoc,
alternating_succ, hi] using he
theorem first_hole_terminal {m : ℕ} {U : Finset (Fin m)} {b : Selection m}
(hb : Valid U b) (j : Fin m) (hj : j ∈ U)
(hfirst : ∀ i ∈ U, j ≤ i) :
b 0 = true ↔ j.val % 2 = 1 := by
have hv := valid_interval hb 0 j.val (by omega) (by
intro i hi hij him
have hh := hfirst i him
have : j.val ≤ i.val := hh
omega)
have hz : b j.castSucc = false := by
have h := hb j
simp only [hj,↓reduceIte] at h
exact h.1
have he : b j.castSucc = alternating (b 0) j.val := by
have ez : (⟨0,by omega⟩ : Fin (m+1)) = 0 := Fin.ext rfl
have ee : (⟨0+j.val,by omega⟩ : Fin (m+1)) = j.castSucc := by
apply Fin.ext; dsimp; omega
rw [ee,ez] at hv
exact hv
rw [hz] at he
by_cases h : j.val%2=0
· simp only [alternating,h,↓reduceIte] at he
simp [← he,h]
· have h1 : j.val%2=1 := by omega
simp only [alternating,h,↓reduceIte] at he
cases hbool : b 0
· rw [hbool] at he; contradiction
· simp only [h1]
end MatchingFPRAS.Subdivision
end OAI
|