File size: 16,964 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
411
412
413
414
415
416
417
418
419
420
421
import Mathlib
import OAI.Combinatorics.MatchingCount.Sampling.ChosenChord

namespace OAI

namespace MatchingFPRAS.Transport.CellDemands
variable {V L : Type*} [Fintype V] [DecidableEq V] [Fintype L] [DecidableEq L]
variable {bags : V → Finset L}
variable {G : SimpleGraph L}
variable (hbags : ∀ v, ∀ a ∈ bags v, ∀ b ∈ bags v, a = b ∨ G.Adj a b)
variable (hG : G.IsAcyclic)
namespace Demand

variable {hbags hG} (d : Demand hbags hG)

noncomputable def cycle := d.2.1.cycle

omit [Fintype L] in
lemma cell : (d.cycle.labelCycle hbags).Cell d.2.2.val.x d.2.2.val.p d.2.2.val.q d.2.2.val.y :=
  ((d.2.1.cycle.subdivision hbags hG).mem_cellList (List.mem_toFinset.mp d.2.2.property)).2.2

omit [Fintype L] in
lemma last_lt : d.2.2.val.y < d.cycle.size := by
  have hy := ((d.2.1.cycle.subdivision hbags hG).mem_cellList (List.mem_toFinset.mp d.2.2.property)).2.1
  have hsize := d.cycle.four_le
  change d.2.2.val.y ≤ d.cycle.size-1 at hy
  omega

noncomputable def corners : d.cycle.Corners := d.cycle.cellCorners hbags d.cell d.last_lt

noncomputable def raw (flags : Fin 64) : RawDemand (BagEdge.Incident (bags := bags)) :=
  d.corners.rawDemand d.1.1 d.1.2 flags

omit [Fintype L] in
theorem raw_injective (flags : Fin 64) : Function.Injective (fun d : Demand hbags hG => d.raw flags) := by
  intro d e h
  obtain ⟨p,S,a⟩ := d
  obtain ⟨q,T,b⟩ := e
  have heq : p = q := by
    apply Prod.ext
    · exact congrArg RawDemand.first h
    · exact congrArg RawDemand.second h
  subst q
  have hanc : S.cycle.edgeAt 0 = T.cycle.edgeAt 0 := congrArg RawDemand.anchor h
  have hST : S = T := S.anchor_recovers hanc
  subst T
  have hcorn := congrArg RawDemand.corners h
  have ha := ((S.cycle.subdivision hbags hG).mem_cellList (List.mem_toFinset.mp a.property))
  have hb := ((S.cycle.subdivision hbags hG).mem_cellList (List.mem_toFinset.mp b.property))
  have hsize := S.cycle.four_le
  have hax := ha.2.2.first_pos
  have hap := ha.2.2.middle_pos
  have haq := ha.2.2.third_pos
  have hbx := hb.2.2.first_pos
  have hbp := hb.2.2.middle_pos
  have hbq := hb.2.2.third_pos
  have hidx (i : Fin 4) := congrFun hcorn i
  have hpos : 0 < S.cycle.size := by omega
  have hinj {i j : ℕ} (hi : i < S.cycle.size) (hj : j < S.cycle.size)
      (hh : S.cycle.vertexAt i = S.cycle.vertexAt j) : i = j :=
    (S.cycle.vertexAt_eq_iff hpos ⟨by omega,by omega⟩ ⟨by omega,by omega⟩).mp hh
  have hab : a = b := by
    apply Subtype.ext
    apply MatchingFPRAS.Cells.CycleData.CellIndex.ext
    · apply hinj (by omega) (by omega)
      exact hidx 0
    · apply hinj (by omega) (by omega)
      exact hidx 1
    · apply hinj (by omega) (by omega)
      exact hidx 2
    · apply hinj (by omega) (by omega)
      exact hidx 3
  subst b
  rfl

end Demand

end MatchingFPRAS.Transport.CellDemands

namespace MatchingFPRAS.Transport

variable {V E : Type*} [Fintype V] [DecidableEq V] [DecidableEq E]

variable {inc : E → V → Prop}

omit [Fintype V] [DecidableEq V] in
lemma OddPath.closed_eq_through_of_short (p : OddPath inc) (chord : E)
    (hl : p.length = 1) (he : chord = p.edge 0) : p.closed chord = p.through := by
  simp [OddPath.closed,OddPath.through,OddPath.interior,pathPattern,hl,he,Finset.filter_singleton]

end MatchingFPRAS.Transport

namespace MatchingFPRAS.Transport.IndexedCycle

variable {V L : Type*} [Fintype V] [DecidableEq V] [Fintype L] [DecidableEq L]

variable {bags : V → Finset L} (c : IndexedCycle (BagEdge.Incident (bags := bags)))

variable {G : SimpleGraph L}

variable (hbags : ∀ v, ∀ a ∈ bags v, ∀ b ∈ bags v, a = b ∨ G.Adj a b)

omit [Fintype V] [Fintype L] in
lemma cellShort_chord {x p q y : ℕ} (hc : (c.labelCycle hbags).Cell x p q y)
    (hy : y < c.size) (i : Fin 4) (hl : ((c.pathsOfCell hbags hc hy).side i).length = 1) :
    (c.pathsOfCell hbags hc hy).chord i = ((c.pathsOfCell hbags hc hy).side i).edge 0 := by
  have hxp := hc.first_pos
  have hpq := hc.middle_pos
  have hqy := hc.third_pos
  change (c.cellChords hbags hc hy) i = ((c.cellCorners hbags hc hy).side i).edge 0
  change (c.cellCorners hbags hc hy).length i = 1 at hl
  fin_cases i
  · simp only [Corners.length,Corners.start,Corners.stop,cellCorners] at hl
    have h : p = x+1 := by simp at hl; omega
    simpa [cellChords,Corners.side,arc,Corners.start,cellCorners] using c.chord_short hbags x p _ _ hc.first h
  · simp only [Corners.length,Corners.start,Corners.stop,cellCorners] at hl
    have h : q = p+1 := by simp at hl; omega
    simpa [cellChords,Corners.side,arc,Corners.start,cellCorners] using c.chord_short hbags p q _ _ hc.middle h
  · simp only [Corners.length,Corners.start,Corners.stop,cellCorners] at hl
    have h : y = q+1 := by simp at hl; omega
    simpa [cellChords,Corners.side,arc,Corners.start,cellCorners] using c.chord_short hbags q y _ _ hc.third h
  · simp only [Corners.length,Corners.start,Corners.stop,cellCorners] at hl
    have h : x = 0 ∧ y+1=c.size := by simp at hl; omega
    simpa [cellChords,Corners.side,arc,Corners.start,cellCorners] using c.chord_wrap hbags x y _ _ _ h

omit [Fintype V] [Fintype L] in
lemma cellShort_pattern {x p q y : ℕ} (hc : (c.labelCycle hbags).Cell x p q y)
    (hy : y < c.size) (i : Fin 4) (hl : ((c.pathsOfCell hbags hc hy).side i).length = 1) :
    ((c.pathsOfCell hbags hc hy).side i).closed ((c.pathsOfCell hbags hc hy).chord i) =
      ((c.pathsOfCell hbags hc hy).side i).through :=
  OddPath.closed_eq_through_of_short _ _ hl (c.cellShort_chord hbags hc hy i hl)

end MatchingFPRAS.Transport.IndexedCycle

namespace MatchingFPRAS.Transport.CellDemands

variable {V L : Type*} [Fintype V] [DecidableEq V] [Fintype L] [DecidableEq L]

variable {bags : V → Finset L} {G : SimpleGraph L}

noncomputable local instance : Fintype (BagEdge bags) := Fintype.ofFinite _

variable {hbags : ∀ v, ∀ a ∈ bags v, ∀ b ∈ bags v, a = b ∨ G.Adj a b}

variable {hG : G.IsAcyclic}

noncomputable instance : Fintype (Demand hbags hG) := Fintype.ofFinite _

namespace Demand

noncomputable def paths (d : Demand hbags hG) := d.cycle.pathsOfCell hbags d.cell d.last_lt

noncomputable def outside (d : Demand hbags hG) := d.1.1.val \ d.cycle.edgeSet

end Demand

abbrev ErrorDemand (hbags : ∀ v, ∀ a ∈ bags v, ∀ b ∈ bags v, a = b ∨ G.Adj a b)
    (hG : G.IsAcyclic) :=
  {e : Bool × Demand hbags hG // ∀ i : Fin 4, CellPaths.sideBit i = e.1 →
    (e.2.paths.side i).length ≠ 1}

noncomputable instance : Fintype (ErrorDemand hbags hG) := Fintype.ofFinite _

namespace ErrorDemand

variable (e : ErrorDemand hbags hG)

def bit : Bool := e.val.1

def demand : Demand hbags hG := e.val.2

def X : Fin 4 := if e.bit then 2 else 3

def Y : Fin 4 := if e.bit then 0 else 1

omit [Fintype L] in
lemma X_bit : CellPaths.sideBit e.X = e.bit := by cases hb : e.bit <;> simp [X,hb,CellPaths.sideBit]

omit [Fintype L] in
lemma Y_bit : CellPaths.sideBit e.Y = e.bit := by cases hb : e.bit <;> simp [Y,hb,CellPaths.sideBit]

omit [Fintype L] in
lemma X_ne_Y : e.X ≠ e.Y := by cases hb : e.bit <;> simp [X,Y,hb]

def flags : Fin 64 := if e.bit then 2 else 1

noncomputable def raw := e.demand.raw e.flags

omit [Fintype L] in
lemma raw_injective : Function.Injective (raw (hbags := hbags) (hG := hG)) := by
  intro e f h
  have hf : e.flags = f.flags := congrArg RawDemand.flags h
  have hb : e.bit = f.bit := by
    cases he : e.bit <;> cases hh : f.bit <;> simp_all [flags]
  have hd : e.demand = f.demand := by
    apply Demand.raw_injective e.flags
    simpa only [raw,hf] using h
  apply Subtype.ext
  exact Prod.ext hb hd

end ErrorDemand

variable (height : L → ℝ) (hheight : ∀ l, 0 < height l)

variable (hstep : ∀ a b, G.Adj a b → height a ≤ 2 * height b)

variable (D : ℝ) (hD : 1 ≤ D) (w : BagEdge bags → ℝ)

variable (hw : ∀ e, height e.color / D ≤ w e ∧ w e ≤ 3 * height e.color)

variable (lo hi : ℝ) (hlo : 0 < lo) (hlohi : lo ≤ hi)

namespace Demand

variable (d : Demand hbags hG)

include hheight hstep hD hw hlo hlohi in
lemma exists_switch : ∃ enc : DemandEncoding BagEdge.Incident (d.raw 0),
    enc.first.val = d.outside ∪ d.paths.switched true ∧
    gibbs (fun e => max lo (min hi (w e))) d.1.1 * gibbs (fun e => max lo (min hi (w e))) d.1.2 ≤
      (1000*D)^4 * gibbs (fun e => max lo (min hi (w e))) enc.first *
        gibbs (fun e => max lo (min hi (w e))) enc.second := by
  obtain ⟨enc,he,hw⟩ := d.cycle.actual_switch_encoding hbags height hheight hstep
    d.1.1 d.1.2 d.2.1.cycle_union d.cell d.last_lt 0 true D hD w hw lo hi hlo hlohi
  refine ⟨enc,?_,hw⟩
  exact he.trans (congrArg (fun R => R ∪ d.paths.switched true)
    (d.corners.embeddedPair_outside d.1.1 d.1.2 d.2.1.cycle_union d.paths.chord d.paths.chord_incidence 0))

noncomputable def switchChoice : DemandEncoding BagEdge.Incident (d.raw 0) :=
  (d.exists_switch height hheight hstep D hD w hw lo hi hlo hlohi).choose

lemma switchChoice_spec :
    (d.switchChoice height hheight hstep D hD w hw lo hi hlo hlohi).first.val =
      d.outside ∪ d.paths.switched true ∧
    gibbs (fun e => max lo (min hi (w e))) d.1.1 * gibbs (fun e => max lo (min hi (w e))) d.1.2 ≤
      (1000*D)^4 * gibbs (fun e => max lo (min hi (w e)))
        (d.switchChoice height hheight hstep D hD w hw lo hi hlo hlohi).first *
        gibbs (fun e => max lo (min hi (w e)))
        (d.switchChoice height hheight hstep D hD w hw lo hi hlo hlohi).second :=
  (d.exists_switch height hheight hstep D hD w hw lo hi hlo hlohi).choose_spec

lemma switchChoice_injective : Function.Injective (fun d : Demand hbags hG =>
    (d.switchChoice height hheight hstep D hD w hw lo hi hlo hlohi).finiteCode) := by
  intro d e h
  exact Demand.raw_injective 0 (DemandEncoding.finiteCode_recovers _ _ h)

end Demand

namespace ErrorDemand

variable (e : ErrorDemand hbags hG)

include hheight hstep hD hw hlo hlohi in
lemma exists_errors : ∃ enc₀ enc₁ : DemandEncoding BagEdge.Incident e.raw,
    enc₀.first.val = e.demand.outside ∪ e.demand.paths.orientation e.bit ∧
    enc₁.first.val = e.demand.outside ∪ e.demand.paths.contextOne e.bit e.Y ∧
    (e.demand.paths.side e.X).closed (e.demand.paths.chord e.X) ⊆ enc₀.second.val ∧
    (e.demand.paths.side e.X).closed (e.demand.paths.chord e.X) ⊆ enc₁.second.val ∧
    gibbs (fun e => max lo (min hi (w e))) e.demand.1.1 *
      gibbs (fun e => max lo (min hi (w e))) e.demand.1.2 ≤
      (1000*D)^4 * gibbs (fun e => max lo (min hi (w e))) enc₀.first *
        gibbs (fun e => max lo (min hi (w e))) enc₀.second ∧
    gibbs (fun e => max lo (min hi (w e))) e.demand.1.1 *
      gibbs (fun e => max lo (min hi (w e))) e.demand.1.2 ≤
      (1000*D)^4 * gibbs (fun e => max lo (min hi (w e))) enc₁.first *
        gibbs (fun e => max lo (min hi (w e))) enc₁.second := by
  obtain ⟨enc₀,enc₁,h₀,h₁,hr⟩ := e.demand.cycle.actual_error_encodings hbags height hheight hstep
    e.demand.1.1 e.demand.1.2 e.demand.2.1.cycle_union e.demand.cell e.demand.last_lt
    e.flags e.bit e.X e.Y e.X_bit e.Y_bit e.X_ne_Y e.property D hD w hw lo hi hlo hlohi
  refine ⟨enc₀,enc₁,?_,?_,hr⟩
  · exact h₀.trans (congrArg (fun R => R ∪ e.demand.paths.orientation e.bit)
      (e.demand.corners.embeddedPair_outside e.demand.1.1 e.demand.1.2 e.demand.2.1.cycle_union
        e.demand.paths.chord e.demand.paths.chord_incidence e.flags))
  · exact h₁.trans (congrArg (fun R => R ∪ e.demand.paths.contextOne e.bit e.Y)
      (e.demand.corners.embeddedPair_outside e.demand.1.1 e.demand.1.2 e.demand.2.1.cycle_union
        e.demand.paths.chord e.demand.paths.chord_incidence e.flags))

noncomputable def errorZero : DemandEncoding BagEdge.Incident e.raw :=
  (e.exists_errors height hheight hstep D hD w hw lo hi hlo hlohi).choose

noncomputable def errorOne : DemandEncoding BagEdge.Incident e.raw :=
  (e.exists_errors height hheight hstep D hD w hw lo hi hlo hlohi).choose_spec.choose

lemma errorZero_injective : Function.Injective (fun e : ErrorDemand hbags hG =>
    (e.errorZero height hheight hstep D hD w hw lo hi hlo hlohi).finiteCode) := by
  intro e f h
  exact raw_injective (DemandEncoding.finiteCode_recovers _ _ h)

lemma errorOne_injective : Function.Injective (fun e : ErrorDemand hbags hG =>
    (e.errorOne height hheight hstep D hD w hw lo hi hlo hlohi).finiteCode) := by
  intro e f h
  exact raw_injective (DemandEncoding.finiteCode_recovers _ _ h)

end ErrorDemand

end MatchingFPRAS.Transport.CellDemands

namespace MatchingFPRAS.Transport.OddPath

variable {V E : Type*} [Fintype V] [DecidableEq V] [DecidableEq E]

variable {inc : E → V → Prop} (p : OddPath inc) (chord : E)

variable (hlong : 3 ≤ p.length)

variable (hc : ∀ v, inc chord v ↔ v = p.vertex 0 ∨ v = p.vertex p.length)

def closedCycle : IndexedCycle inc where
  size := p.length + 1
  four_le := by omega
  even := by have := p.odd; omega
  vertex i := p.vertex i
  simple := by
    intro i j h
    exact Fin.ext (p.simple ⟨by omega,by omega⟩ ⟨by omega,by omega⟩ h)
  edge i := if i.val < p.length then p.edge i else chord
  incidence := by
    intro i v
    by_cases hi : i.val < p.length
    · rw [ite_eq_left hi,p.incidence i hi]
      have hm : (i.val + 1) % (p.length + 1) = i.val + 1 := Nat.mod_eq_of_lt (by omega)
      simp only [hm]
    · have hil : i.val = p.length := by omega
      rw [ite_eq_right hi,hc]
      simp only [hil,Nat.mod_self]
      exact or_comm

omit [Fintype V] [DecidableEq V] [DecidableEq E] in
lemma closedCycle_edgeAt (i : ℕ) (hi : i < p.length) :
    (p.closedCycle chord hlong hc).edgeAt i = p.edge i := by
  simp only [IndexedCycle.edgeAt,IndexedCycle.index,closedCycle]
  rw [Nat.mod_eq_of_lt (by omega),ite_eq_left hi]

omit [Fintype V] [DecidableEq V] [DecidableEq E] in
lemma closedCycle_chord :
    (p.closedCycle chord hlong hc).edgeAt p.length = chord := by
  simp [IndexedCycle.edgeAt,IndexedCycle.index,closedCycle,Nat.mod_eq_of_lt (by omega : p.length < p.length+1)]

omit [Fintype V] [DecidableEq V] in
lemma closedCycle_parity_zero :
    (p.closedCycle chord hlong hc).parityPattern 0 = p.through := by
  ext e
  simp only [IndexedCycle.parityPattern,IndexedCycle.mem_intervalPattern,through,
    pathPattern,Finset.mem_image,Finset.mem_filter,Finset.mem_Ico]
  constructor
  · rintro ⟨i,hi,hj,hp,he⟩
    have hil : i < p.length := by
      change i < p.length + 1 at hj
      have := p.odd
      omega
    exact ⟨i,⟨⟨by omega,hil⟩,by simpa using hp⟩,
      (p.closedCycle_edgeAt chord hlong hc i hil).symm.trans he⟩
  · rintro ⟨i,⟨hi,hp⟩,he⟩
    refine ⟨i,by omega,by change i < p.length+1; omega,?_,?_⟩
    · simpa using hp
    · exact (p.closedCycle_edgeAt chord hlong hc i hi.2).trans he

omit [Fintype V] [DecidableEq V] in
lemma closedCycle_parity_one :
    (p.closedCycle chord hlong hc).parityPattern 1 = p.closed chord := by
  ext e
  simp only [IndexedCycle.parityPattern,IndexedCycle.mem_intervalPattern,closed,
    interior,pathPattern,Finset.mem_union,Finset.mem_image,Finset.mem_filter,
    Finset.mem_Ico,Finset.mem_singleton]
  constructor
  · rintro ⟨i,hi,hj,hp,he⟩
    change i < p.length+1 at hj
    by_cases hil : i < p.length
    · left
      refine ⟨i,⟨⟨by omega,?_⟩,?_⟩, (p.closedCycle_edgeAt chord hlong hc i hil).symm.trans he⟩
      · have := p.odd; omega
      · omega
    · right
      have hie : i = p.length := by omega
      subst i
      exact he.symm.trans (p.closedCycle_chord chord hlong hc)
  · rintro (⟨i,⟨hi,hp⟩,he⟩ | he)
    · refine ⟨i,by omega,by change i < p.length+1; omega,by omega,?_⟩
      exact (p.closedCycle_edgeAt chord hlong hc i (by omega)).trans he
    · exact ⟨p.length,by omega,by change p.length < p.length+1; omega,
        p.odd,(p.closedCycle_chord chord hlong hc).trans he.symm⟩

end MatchingFPRAS.Transport.OddPath

namespace MatchingFPRAS.Transport

variable {V E : Type*} [Fintype V] [DecidableEq V] [DecidableEq E]

variable {inc : E → V → Prop}

namespace IndexedCycle

variable (c : IndexedCycle inc)

omit [Fintype V] [DecidableEq V] in
lemma edgeSet_eq_parity_union : c.edgeSet = c.parityPattern 0 ∪ c.parityPattern 1 := by
  ext e
  simp only [mem_edgeSet,parityPattern,mem_intervalPattern,Finset.mem_union]
  constructor
  · rintro ⟨i,hi,he⟩
    have hp : i % 2 = 0 ∨ i % 2 = 1 := by omega
    rcases hp with hp | hp
    · exact Or.inl ⟨i,by omega,hi,hp,he⟩
    · exact Or.inr ⟨i,by omega,hi,hp,he⟩
  · rintro (⟨i,_,hi,_,he⟩ | ⟨i,_,hi,_,he⟩) <;> exact ⟨i,hi,he⟩

omit [Fintype V] [DecidableEq V] in
lemma zero_mem_parity : c.edgeAt 0 ∈ c.parityPattern 0 := by
  apply (c.mem_intervalPattern _ _ _ _).mpr
  exact ⟨0,le_rfl,by have := c.four_le; omega,rfl,rfl⟩

end IndexedCycle

abbrev PatternCode (inc : E → V → Prop) :=
  {s : Finset E × Finset E // ∃ c : IndexedCycle inc,
    c.parityPattern 0 = s.1 ∧ c.parityPattern 1 = s.2}

end MatchingFPRAS.Transport

end OAI