File size: 12,643 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
import Mathlib
import OAI.Combinatorics.MatchingCount.Graphs.IndexedCycle
import OAI.Combinatorics.MatchingCount.Graphs.ArcData

namespace OAI

namespace MatchingFPRAS.Cells
open SimpleGraph

variable {L : Type*} {G : SimpleGraph L}
namespace CycleData

variable [DecidableEq L] {m : β„•} (C : CycleData G m)

def sets (i : β„€) : Finset L := {C.labels (i - 1), C.labels i}

def Admissible (x y : β„•) : Prop := βˆƒ l, l ∈ C.sets x ∧ l ∈ C.sets y

def Good (x y : β„•) : Prop := y = x + 1 ∨ C.Admissible (x + 1) (y - 1)

def ExteriorGood (x y : β„•) : Prop :=
  y + 1 = x + m ∨ βˆƒ l, l ∈ C.sets ((y : β„€) + 1) ∧ l ∈ C.sets ((x : β„€) - 1)

lemma sets_clique (i : β„€) : βˆ€ u ∈ C.sets i, βˆ€ v ∈ C.sets i, u = v ∨ G.Adj u v := by
  intro u hu v hv
  simp only [sets, Finset.mem_insert, Finset.mem_singleton] at hu hv
  rcases hu with rfl | rfl <;> rcases hv with rfl | rfl
  Β· exact Or.inl rfl
  Β· exact C.adjacent i
  Β· exact (C.adjacent i).imp Eq.symm (fun h => h.symm)
  Β· exact Or.inl rfl

def arc (x s : β„•) : ArcData G s where
  labels i := C.labels ((x : β„€) + i)
  sets i := C.sets ((x : β„€) + i)
  left_mem i _ := by simp [sets]
  right_mem i _ := by
    simp only [sets, Finset.mem_insert, Finset.mem_singleton]
    left
    congr 1
    push_cast
    omega
  clique i _ := C.sets_clique ((x : β„€) + i)

lemma arc_admissible (x s u v : β„•) :
    (C.arc x s).Admissible u v ↔ C.Admissible (x + u) (x + v) := by
  simp only [ArcData.Admissible, Admissible, arc, Nat.cast_add]

lemma arc_good (x s u v : β„•) (huv : u < v) :
    (C.arc x s).Good u v ↔ C.Good (x + u) (x + v) := by
  have hv : 1 ≀ v := by omega
  have h₁ : x + u + 1 = x + (u + 1) := by omega
  have hβ‚‚ : x + v - 1 = x + (v - 1) := by omega
  simp only [ArcData.Good, Good, h₁, hβ‚‚, ← C.arc_admissible x s]
  constructor
  Β· rintro (h | h)
    Β· exact Or.inl (by omega)
    Β· exact Or.inr h
  Β· rintro (h | h)
    Β· exact Or.inl (by omega)
    Β· exact Or.inr h

lemma bad_exterior_boundary (x s : β„•) (hs : 0 < s) (P : L)
    (hPβ‚€ : P ∈ (C.arc x s).sets 0) (hPβ‚› : P ∈ (C.arc x s).sets s)
    (hbad : Β¬ C.ExteriorGood x (x + s)) :
    (C.arc x s).labels 0 = P ∨ (C.arc x s).labels (s - 1) = P := by
  by_contra h
  push Not at h
  rcases h with ⟨hleft, hright⟩
  have hcast : (↑(s - 1) : β„€) = (s : β„€) - 1 := by omega
  simp only [arc, Nat.cast_zero, add_zero] at hleft hPβ‚€
  simp only [arc, hcast] at hright
  have hβ‚€ : P = C.labels ((x : β„€) - 1) := by
    simpa only [sets, Finset.mem_insert, Finset.mem_singleton, or_iff_left hleft.symm] using hPβ‚€
  have hβ‚› : P = C.labels ((x : β„€) + s) := by
    have hne : P β‰  C.labels ((x : β„€) + s - 1) := by
      intro hh
      apply hright
      convert hh.symm using 1
      congr 1
      omega
    simpa only [arc, sets, Finset.mem_insert, Finset.mem_singleton, or_iff_right hne] using hPβ‚›
  apply hbad
  right
  refine ⟨P, ?_, ?_⟩
  Β· simp only [sets, Finset.mem_insert, Finset.mem_singleton]
    left
    convert hβ‚› using 1
    congr 1
    push_cast
    omega
  Β· simp only [sets, Finset.mem_insert, Finset.mem_singleton]
    exact Or.inr hβ‚€

structure Cell (x p q y : β„•) : Prop where
  first_pos : x < p
  middle_pos : p < q
  third_pos : q < y
  odd_first : (p - x) % 2 = 1
  odd_middle : (q - p) % 2 = 1
  odd_third : (y - q) % 2 = 1
  odd_exterior : (m - (y - x)) % 2 = 1
  first : C.Admissible x p
  middle : C.Admissible p q
  third : C.Admissible q y
  exterior : C.Admissible y x
  some_good : (C.Good x p ∧ C.Good q y) ∨ (C.Good p q ∧ C.ExteriorGood x y)
  outer_long : 1 < p - x β†’ 1 < y - q β†’ C.Good p q ∧ C.ExteriorGood x y
  middle_exterior_long : 1 < q - p β†’ 1 < m - (y - x) β†’ C.Good x p ∧ C.Good q y

inductive Subdivision (C : CycleData G m) : β„• β†’ β„• β†’ Type _ where
  | edge {x y} (short : y = x + 1) : Subdivision C x y
  | node {x p q y} (cell : C.Cell x p q y)
      (first : Subdivision C x p) (middle : Subdivision C p q)
      (third : Subdivision C q y) : Subdivision C x y

lemma cell_of_split (x s : β„•) (hm : m % 2 = 0) (hs : s % 2 = 1)
    (hbound : x + s < m) (hadm : C.Admissible x (x + s))
    (T : (C.arc x s).Split (C.ExteriorGood x (x + s))) :
    C.Cell x (x + T.p₁) (x + T.pβ‚‚) (x + s) := by
  have h₁ := T.positive
  have hβ‚‚ := T.ordered
  have h₃ := T.inside
  have ho := T.odd₁
  have he := T.evenβ‚‚
  have ha₁ : C.Admissible x (x + T.p₁) := by
    simpa only [Nat.add_zero] using (C.arc_admissible x s 0 T.p₁).mp T.first
  have haβ‚‚ := (C.arc_admissible x s T.p₁ T.pβ‚‚).mp T.middle
  have ha₃ := (C.arc_admissible x s T.pβ‚‚ s).mp T.third
  have hae : C.Admissible (x + s) x := by
    obtain ⟨l, hl₁, hlβ‚‚βŸ© := hadm
    exact ⟨l, hlβ‚‚, hlβ‚βŸ©
  have g₁ : (C.arc x s).Good 0 T.p₁ β†’ C.Good x (x + T.p₁) := by
    intro h
    simpa only [Nat.add_zero] using (C.arc_good x s 0 T.p₁ h₁).mp h
  have gβ‚‚ := (C.arc_good x s T.p₁ T.pβ‚‚ hβ‚‚).mp
  have g₃ := (C.arc_good x s T.pβ‚‚ s h₃).mp
  refine ⟨by omega, by omega, by omega, by omega, by omega, by omega, by omega,
      ha₁, haβ‚‚, ha₃, hae, ?_, ?_, ?_⟩
  · rcases T.some_good with ⟨hf, ht⟩ | ⟨hm, hg⟩
    Β· exact Or.inl ⟨g₁ hf, g₃ ht⟩
    Β· exact Or.inr ⟨gβ‚‚ hm, hg⟩
  Β· intro hf ht
    obtain ⟨hm, hg⟩ := T.outer_long (by omega) (by omega)
    exact ⟨gβ‚‚ hm, hg⟩
  Β· intro hmiddle _
    obtain ⟨hf, ht⟩ := T.middle_long (by omega)
    exact ⟨g₁ hf, g₃ ht⟩

theorem quadrangulate_arc (hG : G.IsAcyclic) (heven : m % 2 = 0)
    (s : β„•) : βˆ€ x, 0 < s β†’ s % 2 = 1 β†’ x + s < m β†’
      C.Admissible x (x + s) β†’ Nonempty (Subdivision C x (x + s)) := by
  induction s using Nat.strong_induction_on with
  | h s ih =>
    intro x hs hsodd hbound hadm
    by_cases hshort : s = 1
    · exact ⟨.edge (by omega)⟩
    have hslarge : 3 ≀ s := by omega
    obtain ⟨P, hPβ‚€, hPβ‚›βŸ© := hadm
    have hPβ‚€' : P ∈ (C.arc x s).sets 0 := by simpa only [arc, Nat.cast_zero, add_zero] using hPβ‚€
    have hPβ‚›' : P ∈ (C.arc x s).sets s := by simpa only [arc, Nat.cast_add] using hPβ‚›
    obtain ⟨T⟩ := (C.arc x s).split hG (C.ExteriorGood x (x + s)) hslarge hsodd P
      hPβ‚€' hPβ‚›' (C.bad_exterior_boundary x s hs P hPβ‚€' hPβ‚›')
    have h₁ := T.positive
    have hβ‚‚ := T.ordered
    have h₃ := T.inside
    have ho := T.odd₁
    have he := T.evenβ‚‚
    have cell := C.cell_of_split x s heven hsodd hbound ⟨P, hPβ‚€, hPβ‚›βŸ© T
    obtain ⟨Qβ‚βŸ© := ih T.p₁ (by omega) x h₁ ho (by omega) cell.first
    have eqβ‚‚ : x + T.p₁ + (T.pβ‚‚ - T.p₁) = x + T.pβ‚‚ := by omega
    have eq₃ : x + T.pβ‚‚ + (s - T.pβ‚‚) = x + s := by omega
    obtain ⟨Qβ‚‚βŸ© := ih (T.pβ‚‚ - T.p₁) (by omega) (x + T.p₁) (by omega) (by omega)
      (by omega) (by simpa only [eqβ‚‚] using cell.middle)
    obtain ⟨Qβ‚ƒβŸ© := ih (s - T.pβ‚‚) (by omega) (x + T.pβ‚‚) (by omega) (by omega)
      (by omega) (by simpa only [eq₃] using cell.third)
    rw [eqβ‚‚] at Qβ‚‚
    rw [eq₃] at Q₃
    exact ⟨.node cell Q₁ Qβ‚‚ Qβ‚ƒβŸ©

theorem quadrangulate (hG : G.IsAcyclic) (hm : 4 ≀ m) (heven : m % 2 = 0) :
    Nonempty (Subdivision C 0 (m - 1)) := by
  have hclose : C.labels ((m : β„€) - 1) = C.labels (-1) := by
    calc
      C.labels ((m : β„€) - 1) = C.labels (-1 + (m : β„€)) := congrArg C.labels (by omega)
      _ = C.labels (-1) := C.periodic (-1)
  have hadm : C.Admissible 0 (0 + (m - 1)) := by
    refine ⟨C.labels (-1), ?_, ?_⟩
    Β· simp [sets]
    Β· simp only [Nat.zero_add, sets, Finset.mem_insert, Finset.mem_singleton]
      right
      rw [← hclose]
      congr 1
      omega
  simpa only [Nat.zero_add] using
    C.quadrangulate_arc hG heven (m - 1) 0 (by omega) (by omega) (by omega) hadm

namespace Subdivision

variable {C} {x y : β„•}

def cells : {x y : β„•} β†’ Subdivision C x y β†’ β„•
  | _, _, .edge _ => 0
  | _, _, .node _ Q₁ Qβ‚‚ Q₃ => 1 + Q₁.cells + Qβ‚‚.cells + Q₃.cells

def leaves : {x y : β„•} β†’ Subdivision C x y β†’ β„•
  | _, _, .edge _ => 1
  | _, _, .node _ Q₁ Qβ‚‚ Q₃ => Q₁.leaves + Qβ‚‚.leaves + Q₃.leaves

lemma cells_length (Q : Subdivision C x y) : 2 * Q.cells + 1 + x = y := by
  induction Q with
  | edge h => simp only [cells]; omega
  | node cell Q₁ Qβ‚‚ Q₃ h₁ hβ‚‚ h₃ => simp only [cells]; omega

lemma leaves_length (Q : Subdivision C x y) : Q.leaves + x = y := by
  induction Q with
  | edge h => simp only [leaves]; omega
  | node cell Q₁ Qβ‚‚ Q₃ h₁ hβ‚‚ h₃ => simp only [leaves]; omega

def interiorDiagonals (Q : Subdivision C x y) : β„• := Q.cells - 1

lemma counts (hm : 4 ≀ m) (Q : Subdivision C 0 (m - 1)) :
    Q.cells = (m - 2) / 2 ∧ Q.interiorDiagonals = (m - 4) / 2 ∧
    Q.leaves = m - 1 := by
  have hc := Q.cells_length
  have hl := Q.leaves_length
  simp only [interiorDiagonals]
  omega

def sumCells : {x y : β„•} β†’ Subdivision C x y β†’ (β„• β†’ β„• β†’ β„• β†’ β„• β†’ ℝ) β†’ ℝ
  | _, _, .edge _, _ => 0
  | x, y, .node (p := p) (q := q) _ Q₁ Qβ‚‚ Q₃, localTerm =>
      localTerm x p q y + Q₁.sumCells localTerm + Qβ‚‚.sumCells localTerm + Q₃.sumCells localTerm

lemma signed_cancellation (Q : Subdivision C x y)
    (gain : β„• β†’ β„• β†’ ℝ) (localTerm : β„• β†’ β„• β†’ β„• β†’ β„• β†’ ℝ)
    (hshort : βˆ€ x, gain x (x + 1) = 0)
    (hcell : βˆ€ x p q y, C.Cell x p q y β†’
      gain x y = localTerm x p q y + gain x p + gain p q + gain q y) :
    gain x y = Q.sumCells localTerm := by
  induction Q with
  | edge h => simpa only [h, sumCells] using hshort _
  | node cell Q₁ Qβ‚‚ Q₃ h₁ hβ‚‚ h₃ =>
    simpa only [sumCells, h₁, hβ‚‚, h₃] using hcell _ _ _ _ cell

end Subdivision

end CycleData

end MatchingFPRAS.Cells

namespace MatchingFPRAS.Transport

variable {V E L : Type*}

namespace IndexedCycle

variable {inc : E β†’ V β†’ Prop} (c : IndexedCycle inc)

def zindex (i : β„€) : Fin c.size :=
  ⟨(i % (c.size : β„€)).toNat, (Int.toNat_lt (Int.emod_nonneg _ (by
    have := c.four_le; omega))).mpr (Int.emod_lt_of_pos _ (by have := c.four_le; omega))⟩

def vertexAtZ (i : β„€) : V := c.vertex (c.zindex i)

def edgeAtZ (i : β„€) : E := c.edge (c.zindex i)

lemma zindex_nat (i : β„•) : c.zindex i = c.index i := by
  apply Fin.ext
  change ((i : β„€) % (c.size : β„€)).toNat = i % c.size
  rw [← Int.natCast_emod, Int.toNat_natCast]

lemma zindex_periodic (i : β„€) : c.zindex (i + c.size) = c.zindex i := by
  apply Fin.ext
  simp [zindex]

lemma vertexAtZ_nat (i : β„•) : c.vertexAtZ i = c.vertexAt i := by
  simp [vertexAtZ, vertexAt, c.zindex_nat]

lemma edgeAtZ_nat (i : β„•) : c.edgeAtZ i = c.edgeAt i := by
  simp [edgeAtZ, edgeAt, c.zindex_nat]

lemma vertexAtZ_periodic (i : β„€) : c.vertexAtZ (i + c.size) = c.vertexAtZ i := by
  simp [vertexAtZ, c.zindex_periodic]

lemma edgeAtZ_periodic (i : β„€) : c.edgeAtZ (i + c.size) = c.edgeAtZ i := by
  simp [edgeAtZ, c.zindex_periodic]

lemma zindex_succ (i : β„€) : c.zindex (i + 1) =
    ⟨((c.zindex i).val + 1) % c.size, Nat.mod_lt _ (by have := c.four_le; omega)⟩ := by
  have hsz : (c.size : β„€) β‰  0 := by have := c.four_le; omega
  apply Fin.ext
  apply Int.natCast_inj.mp
  change (((i + 1) % (c.size : β„€)).toNat : β„€) =
    (((((i % (c.size : β„€)).toNat + 1) % c.size) : β„•) : β„€)
  rw [Int.toNat_of_nonneg (Int.emod_nonneg _ hsz), Int.natCast_emod,
    Nat.cast_add, Nat.cast_one, Int.toNat_of_nonneg (Int.emod_nonneg _ hsz)]
  simp only [Int.add_emod, Int.emod_emod]

lemma edgeAtZ_incidence (i : β„€) (v : V) :
    inc (c.edgeAtZ i) v ↔ v = c.vertexAtZ i ∨ v = c.vertexAtZ (i+1) := by
  simpa [edgeAtZ, vertexAtZ, c.zindex_succ] using c.incidence (c.zindex i) v

end IndexedCycle

namespace BagEdge

variable {bags : V β†’ Finset L}

def color (e : BagEdge bags) : L := e.val.color

lemma color_mem (e : BagEdge bags) {v : V} (hv : e.Incident v) : e.color ∈ bags v :=
  e.property v hv

def ofEndpoints (v w : V) (hvw : v β‰  w) (l : L)
    (hlv : l ∈ bags v) (hlw : l ∈ bags w) : BagEdge bags :=
  ⟨⟨(s(v,w),l), by simpa using hvw⟩, by
    intro u hu
    change u ∈ s(v,w) at hu
    change l ∈ bags u
    rcases Sym2.mem_iff.mp hu with rfl | rfl
    Β· exact hlv
    · exact hlw⟩

lemma ofEndpoints_incidence (v w : V) (hvw : v β‰  w) (l : L)
    (hlv : l ∈ bags v) (hlw : l ∈ bags w) (u : V) :
    (ofEndpoints v w hvw l hlv hlw).Incident u ↔ u = v ∨ u = w :=
  Sym2.mem_iff

lemma ofEndpoints_color (v w : V) (hvw : v β‰  w) (l : L)
    (hlv : l ∈ bags v) (hlw : l ∈ bags w) :
    (ofEndpoints v w hvw l hlv hlw).color = l := rfl

end BagEdge

end MatchingFPRAS.Transport

end OAI