File size: 15,201 Bytes
4a56cd6 | 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 | import Mathlib
import OAI.Combinatorics.MatchingCount.Sampling.Components
namespace OAI
namespace MatchingFPRAS.Transport
section
variable {V E : Type*} [DecidableEq V] [DecidableEq E]
variable {inc : E β V β Prop}
namespace IndexedCycle.Corners
variable {c : IndexedCycle inc} (k : c.Corners)
lemma embeddedPair_outside [Fintype V] (M N : PM inc) (hU : β i, c.edgeAt i β M.val βͺ N.val)
(chord : Fin 4 β E)
(hc : β i v, inc (chord i) v β
v = (k.side i).vertex 0 β¨ v = (k.side i).vertex (k.side i).length)
(flags : Fin 64) :
(k.embeddedPair M N hU chord hc flags).outsideFirst = M.val \ c.edgeSet := by
classical
change M.val \ (k.cellPaths chord hc).orientation
(decide (k.aβ % 2 = if c.edgeAt 0 β M.val then 0 else 1)) = _
rw [k.cell_orientation_parity]
have hp := c.inter_edgeSet_parity M.property N.property hU
have he : (if decide (k.aβ % 2 = if c.edgeAt 0 β M.val then 0 else 1)
then k.aβ % 2 else 1-k.aβ % 2) = (if c.edgeAt 0 β M.val then 0 else 1) := by
by_cases hz : c.edgeAt 0 β M.val <;> simp only [hz,ite_true,ite_false]
all_goals split_ifs <;> simp_all
rw [he,β hp]
ext e
simp
end IndexedCycle.Corners
namespace CellPaths
variable (c : CellPaths inc)
lemma through_subset_contextOne (b : Bool) (X Y : Fin 4)
(hX : sideBit X = b) (hY : sideBit Y = b) (hne : X β Y)
(hinc : β e, β v, inc e v) :
(c.side X).through β c.contextOne b Y := by
have hd := (c.side X).through_matching.disjoint_edges (c.side Y).through_matching hinc
(c.same_bit_spans X Y hne (hX.trans hY.symm))
intro e he
exact Finset.mem_union_left _ (Finset.mem_sdiff.mpr
β¨c.through_subset_orientation b X hX he,fun hy => Finset.disjoint_left.mp hd he hyβ©)
lemma contextOne_self (b : Bool) (i : Fin 4) (hi : sideBit i = b)
(he : (c.side i).closed (c.chord i) = (c.side i).through) :
c.contextOne b i = c.orientation b := by
rw [contextOne,he,Finset.sdiff_union_of_subset (c.through_subset_orientation b i hi)]
lemma contextError_short_left (R : Finset E) (f : Finset E β β) (b : Bool)
(X Y : Fin 4) (hX : sideBit X = b) (hY : sideBit Y = b) (hne : X β Y)
(hinc : β e, β v, inc e v)
(he : (c.side X).closed (c.chord X) = (c.side X).through) :
c.contextError R f b X Y = 0 := by
rw [contextError,he,Finset.sdiff_union_of_subset
(c.through_subset_contextOne b X Y hX hY hne hinc),c.contextOne_self b X hX he]
ring
lemma contextError_short_right (R : Finset E) (f : Finset E β β) (b : Bool)
(X Y : Fin 4) (hY : sideBit Y = b)
(he : (c.side Y).closed (c.chord Y) = (c.side Y).through) :
c.contextError R f b X Y = 0 := by
rw [contextError,c.contextOne_self b Y hY he]
simp only [contextOne,sub_self]
lemma contextError_derivative (R : Finset E) (f : Finset E β β) (b : Bool)
(X Y : Fin 4) (hdis : Disjoint R (c.side X).through) :
c.contextError R f b X Y =
(f (R βͺ c.contextOne b Y) -
f (((R βͺ c.contextOne b Y) \ (c.side X).through) βͺ (c.side X).closed (c.chord X))) -
(f (R βͺ c.orientation b) -
f (((R βͺ c.orientation b) \ (c.side X).through) βͺ (c.side X).closed (c.chord X))) := by
have h (S : Finset E) :
((R βͺ S) \ (c.side X).through) βͺ (c.side X).closed (c.chord X) =
R βͺ ((S \ (c.side X).through) βͺ (c.side X).closed (c.chord X)) := by
have hr : R \ (c.side X).through = R := by
ext e
simp only [Finset.mem_sdiff]
exact β¨And.left,fun he => β¨he,fun hn => Finset.disjoint_left.mp hdis he hnβ©β©
rw [Finset.union_sdiff_distrib,hr,Finset.union_assoc]
rw [h,h]
rfl
end CellPaths
end
section
variable {V E : Type*}
variable {inc : E β V β Prop}
namespace IndexedCycle
variable (c : IndexedCycle inc)
lemma edgeAt_injective_range {i j : β} (hi : i < c.size) (hj : j < c.size)
(he : c.edgeAt i = c.edgeAt j) : i = j := by
have hf := c.four_le
have hβ := (c.edgeAt_incidence j (c.vertexAt i)).mp
(he βΈ (c.edgeAt_incidence i _).mpr (Or.inl rfl))
have hβ := (c.edgeAt_incidence j (c.vertexAt (i+1))).mp
(he βΈ (c.edgeAt_incidence i _).mpr (Or.inr rfl))
have hv : β a b, c.vertexAt a = c.vertexAt b β a % c.size = b % c.size := by
intro a b h
exact congrArg Fin.val (c.simple h)
rcases hβ with hβ | hβ
Β· have hh := hv _ _ hβ
simpa only [Nat.mod_eq_of_lt hi, Nat.mod_eq_of_lt hj] using hh
Β· have hhβ := hv _ _ hβ
rcases hβ with hβ | hβ <;> have hhβ := hv _ _ hβ <;>
rw [Nat.mod_eq_of_lt hi, mod_of_lt_twice (by omega)] at hhβ <;>
rw [mod_of_lt_twice (by omega)] at hhβ
Β· rw [Nat.mod_eq_of_lt hj] at hhβ
split_ifs at hhβ hhβ <;> omega
Β· rw [mod_of_lt_twice (by omega)] at hhβ
split_ifs at hhβ hhβ <;> omega
lemma edgeAt_eq_iff {a x y : β} (ha : a < c.size)
(hx : a β€ x β§ x < a+c.size) (hy : a β€ y β§ y < a+c.size) :
c.edgeAt x = c.edgeAt y β x = y := by
constructor
Β· intro he
have hh := c.edgeAt_injective_range
(Nat.mod_lt x (by have := c.four_le; omega))
(Nat.mod_lt y (by have := c.four_le; omega))
(by simpa only [c.edgeAt_mod] using he)
rw [mod_of_lt_twice (by omega), mod_of_lt_twice (by omega)] at hh
split_ifs at hh <;> omega
Β· exact congrArg c.edgeAt
variable [DecidableEq E]
lemma intervalPattern_disjoint {x y z : β} (hx : x < c.size)
(hxy : x β€ y) (hyz : y β€ z) (hz : z β€ x+c.size) (a b : β) :
Disjoint (c.intervalPattern x y a) (c.intervalPattern y z b) := by
apply Finset.disjoint_left.mpr
intro e he hf
obtain β¨i,hi,hj,_,heβ© := (c.mem_intervalPattern e _ _ _).mp he
obtain β¨j,hk,hl,_,hfβ© := (c.mem_intervalPattern e _ _ _).mp hf
have hh := (c.edgeAt_eq_iff hx β¨hi,by omegaβ© β¨by omega,by omegaβ©).mp (he.trans hf.symm)
omega
lemma parity_sdiff_interval {x y : β} (hx : x < c.size)
(hxy : x β€ y) (hy : y β€ x+c.size) (a : β) :
c.parityPattern a \ c.intervalPattern x y a = c.intervalPattern y (x+c.size) a := by
have hu := c.intervalPattern_union hxy hy a
rw [c.rotatedPattern (by omega) a] at hu
rw [β hu]
have hd := c.intervalPattern_disjoint hx hxy hy (by omega) a a
ext e
simp only [Finset.mem_sdiff, Finset.mem_union]
have hh : Β¬ (e β c.intervalPattern x y a β§ e β c.intervalPattern y (x+c.size) a) := by
rintro β¨h,h'β©
exact Finset.disjoint_left.mp hd h h'
tauto
def sewn (x y : β) (e : E) : Finset E :=
(c.intervalPattern x y (1-x%2) βͺ c.intervalPattern y (x+c.size) (x%2)) βͺ {e}
lemma forward_conversion {x y : β} (hx : x < c.size) (hxy : x < y)
(hy : y < c.size) (ho : (y-x)%2=1) (e : E) :
(c.parityPattern (x%2) \ (c.arc x (y-x) hx (by omega) (by omega) ho).through) βͺ
(c.arc x (y-x) hx (by omega) (by omega) ho).closed e = c.sewn x y e := by
rw [OddPath.closed, c.arc_through, c.arc_interior]
have he : x+(y-x)=y := by omega
rw [he, c.parity_sdiff_interval hx (by omega) (by omega)]
unfold sewn
ext z
simp only [Finset.mem_union]
tauto
lemma complementary_conversion {x y : β} (_hx : x < c.size) (hxy : x < y)
(hy : y < c.size) (ho : (y-x)%2=1) (e : E) :
(c.parityPattern (y%2) \
(c.arc y (c.size+x-y) hy (by omega) (by omega) (by have := c.even; omega)).through) βͺ
(c.arc y (c.size+x-y) hy (by omega) (by omega) (by have := c.even; omega)).closed e =
c.sewn x y e := by
have hev := c.even
have hp : y%2=1-x%2 := by omega
have hp' : 1-y%2=x%2 := by omega
have he : y+(c.size+x-y)=x+c.size := by omega
rw [OddPath.closed, c.arc_through, c.arc_interior, he,
c.parity_sdiff_interval hy (by omega) (by omega)]
have hshift : c.intervalPattern (x+c.size) (y+c.size) (y%2) =
c.intervalPattern x y (y%2) := c.intervalPattern_periodic _
rw [hshift, hp', hp]
unfold sewn
ext z
simp only [Finset.mem_union]
tauto
lemma edgeAt_mem_parity (i : β) : c.edgeAt i β c.parityPattern (i%2) := by
rw [parityPattern, c.mem_intervalPattern]
have hdiv : 2 β£ c.size := Nat.dvd_of_mod_eq_zero c.even
exact β¨i%c.size,by omega,Nat.mod_lt _ (by have := c.four_le; omega),
Nat.mod_mod_of_dvd i hdiv,c.edgeAt_mod iβ©
lemma short_through (x : β) (hx : x < c.size) :
(c.arc x 1 hx (by omega) (by have := c.four_le; omega) (by omega)).through =
{c.edgeAt x} := by
norm_num [OddPath.through, pathPattern, arc]
rw [show ({i β ({0} : Finset β) | i % 2 = 0}) = {0} by decide]
simp
lemma short_closed (x : β) (hx : x < c.size) :
(c.arc x 1 hx (by omega) (by have := c.four_le; omega) (by omega)).closed (c.edgeAt x) =
{c.edgeAt x} := by
simp [OddPath.closed, OddPath.interior, pathPattern, arc]
lemma sewn_short (x : β) (hx : x+1 < c.size) :
c.sewn x (x+1) (c.edgeAt x) = c.parityPattern (x%2) := by
have hh := c.forward_conversion (x := x) (y := x+1) (by omega) (by omega) hx (by omega) (c.edgeAt x)
have ord : x+1-x=1 := by omega
simp only [ord] at hh
rw [c.short_through, c.short_closed] at hh
rw [β hh]
have hm : {c.edgeAt x} β c.parityPattern (x%2) := by
simpa only [Finset.singleton_subset_iff] using c.edgeAt_mem_parity x
exact Finset.sdiff_union_of_subset hm
lemma sewn_root : c.sewn 0 (c.size-1) (c.edgeAt (c.size-1)) = c.parityPattern 1 := by
have hf := c.four_le
have hev := c.even
have hh := c.complementary_conversion (x := 0) (y := c.size-1) (by omega) (by omega)
(by omega) (by omega) (c.edgeAt (c.size-1))
have he : c.size+0-(c.size-1)=1 := by omega
have hp : (c.size-1)%2=1 := by omega
simp only [he, hp] at hh
rw [c.short_through, c.short_closed] at hh
rw [β hh]
have hm : {c.edgeAt (c.size-1)} β c.parityPattern 1 := by
simpa only [Finset.singleton_subset_iff, hp] using c.edgeAt_mem_parity (c.size-1)
exact Finset.sdiff_union_of_subset hm
end IndexedCycle
end
variable {V E : Type*} [DecidableEq E]
variable {inc : E β V β Prop}
namespace IndexedCycle
variable (c : IndexedCycle inc)
def signedGain (R : Finset E) (f : Finset E β β) (x y : β) (e : E) : β :=
if x%2=0 then f (R βͺ c.parityPattern 0) - f (R βͺ c.sewn x y e)
else f (R βͺ c.sewn x y e) - f (R βͺ c.parityPattern 1)
lemma signedGain_short (R : Finset E) (f : Finset E β β) (x : β) (hx : x+1<c.size) :
c.signedGain R f x (x+1) (c.edgeAt x) = 0 := by
unfold signedGain
rw [c.sewn_short x hx]
split_ifs with h
Β· simp [h]
Β· have hh : x%2=1 := by omega
simp [hh]
lemma signedGain_root (R : Finset E) (f : Finset E β β) :
c.signedGain R f 0 (c.size-1) (c.edgeAt (c.size-1)) =
f (R βͺ c.parityPattern 0) - f (R βͺ c.parityPattern 1) := by
simp [signedGain, c.sewn_root]
namespace Corners
variable {c} (k : c.Corners)
def cornerSewn (chord : Fin 4 β E) : Fin 4 β Finset E :=
![c.sewn k.aβ k.aβ (chord 0), c.sewn k.aβ k.aβ (chord 1),
c.sewn k.aβ k.aβ (chord 2), c.sewn k.aβ k.aβ (chord 3)]
variable [DecidableEq V]
lemma context_eq_sewn (chord : Fin 4 β E)
(hc : β i v, inc (chord i) v β
v = (k.side i).vertex 0 β¨ v = (k.side i).vertex (k.side i).length)
(i : Fin 4) :
(k.cellPaths chord hc).contextOne (CellPaths.sideBit i) i = k.cornerSewn chord i := by
have eh := k.cell_orientation_parity chord hc (CellPaths.sideBit i)
rw [β k.parity_start i] at eh
change ((k.cellPaths chord hc).orientation (CellPaths.sideBit i) \ (k.side i).through) βͺ
(k.side i).closed (chord i) = _
rw [eh]
have hβ := k.ltβ
have hβ := k.ltβ
have hβ := k.ltβ
have hβ := k.ltβ
fin_cases i
Β· exact c.forward_conversion (by omega) hβ (by omega) k.oddβ _
Β· exact c.forward_conversion (by omega) hβ (by omega) k.oddβ _
Β· exact c.forward_conversion (by omega) hβ hβ k.oddβ _
Β· exact c.complementary_conversion (by omega) (by omega) hβ
(by have := k.oddβ; have := k.oddβ; have := k.oddβ; omega) _
def signedLocalTerm (chord : Fin 4 β E)
(hc : β i v, inc (chord i) v β
v = (k.side i).vertex 0 β¨ v = (k.side i).vertex (k.side i).length)
(R : Finset E) (f : Finset E β β) : β :=
let P := k.cellPaths chord hc
let t := (f (R βͺ P.switched true) - f (R βͺ P.switched false)) +
P.contextError R f true 2 0 - P.contextError R f false 3 1
if k.aβ%2=0 then t else -t
theorem signed_cell_recurrence (chord : Fin 4 β E)
(hc : β i v, inc (chord i) v β
v = (k.side i).vertex 0 β¨ v = (k.side i).vertex (k.side i).length)
(R : Finset E) (f : Finset E β β) (hinc : β e, β v, inc e v) :
c.signedGain R f k.aβ k.aβ (chord 3) =
k.signedLocalTerm chord hc R f +
c.signedGain R f k.aβ k.aβ (chord 0) +
c.signedGain R f k.aβ k.aβ (chord 1) +
c.signedGain R f k.aβ k.aβ (chord 2) := by
have hh := (k.cellPaths chord hc).single_cell_identity R f hinc
have hcβ := k.context_eq_sewn chord hc 0
have hcβ := k.context_eq_sewn chord hc 1
have hcβ := k.context_eq_sewn chord hc 2
have hcβ := k.context_eq_sewn chord hc 3
norm_num [CellPaths.sideBit, Fin.isValue, cornerSewn, Matrix.cons_val_zero,
Matrix.cons_val_one, Matrix.cons_val, Matrix.head_cons, Matrix.tail_cons] at hcβ hcβ hcβ hcβ
change (k.cellPaths chord hc).contextOne true 2 = c.sewn k.aβ k.aβ (chord 2) at hcβ
change (k.cellPaths chord hc).contextOne false 3 = c.sewn k.aβ k.aβ (chord 3) at hcβ
unfold CellPaths.canonicalGain at hh
rw [hcβ, hcβ, hcβ, hcβ, k.cell_orientation_parity chord hc true,
k.cell_orientation_parity chord hc false] at hh
simp only [ite_true, Bool.false_eq_true, ite_false] at hh
have hoβ := k.oddβ
have hoβ := k.oddβ
have hlβ := k.ltβ
have hlβ := k.ltβ
by_cases h : k.aβ%2=0
Β· have hβ : k.aβ%2=1 := by omega
have hβ : k.aβ%2=0 := by omega
simp only [signedGain, signedLocalTerm, h, hβ, hβ,
Nat.one_ne_zero, Nat.sub_zero, ite_true, ite_false] at hh β’
linarith
Β· have hβ : k.aβ%2=1 := by omega
have hβ : k.aβ%2=0 := by omega
have hβ : k.aβ%2=1 := by omega
simp only [signedGain, signedLocalTerm, hβ, hβ, hβ,
Nat.one_ne_zero, Nat.sub_self, ite_true, ite_false] at hh β’
linarith
end Corners
end IndexedCycle
end MatchingFPRAS.Transport
namespace MatchingFPRAS.Cells.CycleData.Subdivision
variable {L : Type*} [DecidableEq L] {G : SimpleGraph L} {m : β} {C : CycleData G m} {x y : β}
lemma signed_cancellation_bounded (Q : Subdivision C x y)
(gain : β β β β β) (localTerm : β β β β β β β β β)
(hshort : β x, x + 1 < m β gain x (x+1)=0)
(hcell : β x p q y, C.Cell x p q y β y < m β
gain x y = localTerm x p q y + gain x p + gain p q + gain q y)
(hy : y < m) : gain x y = Q.sumCells localTerm := by
induction Q with
| edge h => simpa only [h, sumCells] using hshort _ (by omega)
| node cell Qβ Qβ Qβ hβ hβ hβ =>
have hpq := cell.middle_pos
have hqy := cell.third_pos
simpa only [sumCells, hβ (by omega), hβ (by omega), hβ hy]
using hcell _ _ _ _ cell hy
end MatchingFPRAS.Cells.CycleData.Subdivision
end OAI
|