Download data/lean/OAI/Combinatorics/ListHadwiger/Exchanges.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 24.3 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/ListHadwiger/Exchanges.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/ListHadwiger/Exchanges.lean
-
curl -L -o Exchanges.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/ListHadwiger/Exchanges.lean
24.3 kB
| import OAI.Combinatorics.ListHadwiger.BagContraction | |
| namespace OAI | |
| namespace LinearListHadwiger | |
| open SimpleGraph PathPacking | |
| open scoped Classical | |
| namespace BagRouting | |
| variable {V I J : Type} {G : SimpleGraph V} {s : I β V} {B : J β Set V} | |
| def used (D : BagRouting G s B) : Set V := | |
| {v | β i, v β (D.paths i).2.val.support} | |
| def Minimal [Fintype I] (D : BagRouting G s B) : Prop := | |
| β E : BagRouting G s B, D.totalLength β€ E.totalLength | |
| lemma exists_minimal [Fintype I] (h : Nonempty (BagRouting G s B)) : | |
| β D : BagRouting G s B, D.Minimal := by | |
| classical | |
| have hex : β n : β, β D : BagRouting G s B, D.totalLength = n := by | |
| obtain β¨Dβ© := h | |
| exact β¨D.totalLength, D, rflβ© | |
| obtain β¨D, hdβ© := Nat.find_spec hex | |
| refine β¨D, fun E => ?_β© | |
| rw [hd] | |
| exact Nat.find_min' hex β¨E, rflβ© | |
| noncomputable def replace [DecidableEq I] (D : BagRouting G s B) (i : I) | |
| (p : G.Path (s i) (D.paths i).1) | |
| (hp : β j, i β j β β v β p.val.support, | |
| v β (D.paths j).2.val.support β v = s i β§ v = s j) : BagRouting G s B := by | |
| let paths : β a, Ξ£ w, G.Path (s a) w := | |
| fun a => if h : a = i then h.symm βΈ (β¨(D.paths i).1, pβ© : Ξ£ w, G.Path (s i) w) else D.paths a | |
| refine β¨paths, D.bag, D.bag_injective, ?_, ?_β© | |
| Β· intro a | |
| by_cases ha : a = i | |
| Β· subst a | |
| have he : paths i = β¨(D.paths i).1, pβ© := dite_eq_left rfl | |
| rw [he] | |
| exact D.endpoint_mem i | |
| Β· have he : paths a = D.paths a := dite_eq_right ha | |
| rw [he] | |
| exact D.endpoint_mem a | |
| Β· intro a b hab v hva hvb | |
| by_cases ha : a = i | |
| Β· subst a | |
| have he : paths i = β¨(D.paths i).1, pβ© := dite_eq_left rfl | |
| have he' : paths b = D.paths b := dite_eq_right (Ne.symm hab) | |
| rw [he] at hva | |
| rw [he'] at hvb | |
| exact hp b hab v hva hvb | |
| Β· have he : paths a = D.paths a := dite_eq_right ha | |
| rw [he] at hva | |
| by_cases hb : b = i | |
| Β· subst b | |
| have he' : paths i = β¨(D.paths i).1, pβ© := dite_eq_left rfl | |
| rw [he'] at hvb | |
| exact (hp a (Ne.symm ha) v hvb hva).symm | |
| Β· have he' : paths b = D.paths b := dite_eq_right hb | |
| rw [he'] at hvb | |
| exact D.overlap a b hab v hva hvb | |
| lemma replace_shorter [Fintype I] [DecidableEq I] (D : BagRouting G s B) (i : I) | |
| (p : G.Path (s i) (D.paths i).1) | |
| (hp : β j, i β j β β v β p.val.support, | |
| v β (D.paths j).2.val.support β v = s i β§ v = s j) | |
| (hlt : p.val.length < (D.paths i).2.val.length) : | |
| (D.replace i p hp).totalLength < D.totalLength := by | |
| have hi : (D.replace i p hp).paths i = β¨(D.paths i).1, pβ© := dite_eq_left rfl | |
| have ha : β a, a β i β (D.replace i p hp).paths a = D.paths a := fun a h => dite_eq_right h | |
| apply Finset.sum_lt_sum | |
| Β· intro a _ | |
| by_cases h : a = i | |
| Β· subst a | |
| rw [hi] | |
| exact hlt.le | |
| Β· rw [ha a h] | |
| Β· refine β¨i, Finset.mem_univ _, ?_β© | |
| rw [hi] | |
| exact hlt | |
| lemma Minimal.walk_length_le [Fintype I] [DecidableEq V] [DecidableEq I] | |
| {D : BagRouting G s B} (hD : D.Minimal) (i : I) | |
| (p : G.Walk (s i) (D.paths i).1) | |
| (hp : β j, i β j β β v β p.support, | |
| v β (D.paths j).2.val.support β v = s i β§ v = s j) : | |
| (D.paths i).2.val.length β€ p.length := by | |
| have hp' : β j, i β j β β v β p.toPath.val.support, | |
| v β (D.paths j).2.val.support β v = s i β§ v = s j := by | |
| intro j hij v hv hvj | |
| exact hp j hij v (p.support_toPath_subset_support hv) hvj | |
| have hle : (D.paths i).2.val.length β€ p.toPath.val.length := by | |
| by_contra hn | |
| exact (not_lt_of_ge (hD (D.replace i p.toPath hp'))) | |
| (D.replace_shorter i p.toPath hp' (Nat.lt_of_not_ge hn)) | |
| exact hle.trans p.length_bypass_le_length | |
| lemma Minimal.no_long_shortcut [Fintype I] [DecidableEq V] [DecidableEq I] | |
| {D : BagRouting G s B} (hD : D.Minimal) (i : I) (v : V) (hv : v β D.used) | |
| (a b : β) (ha : a β€ (D.paths i).2.val.length) (hb : b β€ (D.paths i).2.val.length) | |
| (hva : G.Adj ((D.paths i).2.val.getVert a) v) | |
| (hvb : G.Adj v ((D.paths i).2.val.getVert b)) : b β€ a + 2 := by | |
| let p := (D.paths i).2.val | |
| let q : G.Walk (s i) (D.paths i).1 := ((p.take a).concat hva).append (Walk.cons hvb (p.drop b)) | |
| change a β€ p.length at ha | |
| change b β€ p.length at hb | |
| have hq := hD.walk_length_le i q (by | |
| intro j hij w hw hwj | |
| have hw' : w β p.support β¨ w = v := by | |
| simp only [q, Walk.mem_support_append_iff, Walk.support_concat, Walk.support_cons, | |
| List.mem_append, List.mem_cons, List.not_mem_nil, or_false] at hw | |
| rcases hw with (hw | hw) | (hw | hw) | |
| Β· left | |
| rw [Walk.support_take] at hw | |
| exact List.mem_of_mem_take hw | |
| Β· exact Or.inr hw | |
| Β· exact Or.inr hw | |
| Β· left | |
| rw [Walk.drop_support_eq_support_drop_min] at hw | |
| exact List.mem_of_mem_drop hw | |
| rcases hw' with hw | rfl | |
| Β· exact D.overlap i j hij w hw hwj | |
| Β· exact (hv β¨j, hwjβ©).elim) | |
| have hlen : q.length = a + 2 + (p.length - b) := by | |
| simp [q, Walk.take_length, Nat.min_eq_left ha, Walk.drop_length] | |
| omega | |
| change p.length β€ q.length at hq | |
| rw [hlen] at hq | |
| omega | |
| lemma Minimal.path_neighbors_le_three [Fintype I] [DecidableEq V] [DecidableEq I] | |
| [DecidableRel G.Adj] | |
| {D : BagRouting G s B} (hD : D.Minimal) (i : I) (v : V) (hv : v β D.used) : | |
| ((D.paths i).2.val.support.toFinset.filter fun w => G.Adj v w).card β€ 3 := by | |
| classical | |
| let p := (D.paths i).2.val | |
| let R := (Finset.range (p.length + 1)).filter fun a => G.Adj v (p.getVert a) | |
| have hR : R.card β€ 3 := by | |
| obtain he | hn := R.eq_empty_or_nonempty | |
| Β· simp [he] | |
| let a := R.min' hn | |
| have haR : a β R := R.min'_mem hn | |
| have ha : a β€ p.length := by | |
| have hh := (Finset.mem_filter.mp haR).1 | |
| simp only [Finset.mem_range] at hh | |
| omega | |
| have hsub : R β Finset.Icc a (a + 2) := by | |
| intro b hbR | |
| have hb : b β€ p.length := by | |
| have hh := (Finset.mem_filter.mp hbR).1 | |
| simp only [Finset.mem_range] at hh | |
| omega | |
| have hab := hD.no_long_shortcut i v hv a b ha hb | |
| (Finset.mem_filter.mp haR).2.symm (Finset.mem_filter.mp hbR).2 | |
| exact Finset.mem_Icc.mpr β¨R.min'_le b hbR, habβ© | |
| exact (Finset.card_le_card hsub).trans (by simp; omega) | |
| have hsub : (p.support.toFinset.filter fun w => G.Adj v w) β R.image p.getVert := by | |
| intro w hw | |
| obtain β¨hwp, hvwβ© := Finset.mem_filter.mp hw | |
| obtain β¨a, ha, hlenβ© := Walk.mem_support_iff_exists_getVert.mp (List.mem_toFinset.mp hwp) | |
| refine Finset.mem_image.mpr β¨a, Finset.mem_filter.mpr β¨?_, ?_β©, haβ© | |
| Β· exact Finset.mem_range.mpr (by omega) | |
| Β· rwa [ha] | |
| exact (Finset.card_le_card hsub).trans ((Finset.card_image_le).trans hR) | |
| noncomputable def usedFinset [Fintype I] [DecidableEq V] (D : BagRouting G s B) : Finset V := | |
| Finset.univ.biUnion fun i => (D.paths i).2.val.support.toFinset | |
| lemma mem_usedFinset [Fintype I] [DecidableEq V] (D : BagRouting G s B) (v : V) : | |
| v β D.usedFinset β v β D.used := by | |
| simp [usedFinset, used] | |
| lemma Minimal.used_neighbors_le [Fintype I] [DecidableEq V] [DecidableEq I] | |
| [DecidableRel G.Adj] | |
| {D : BagRouting G s B} (hD : D.Minimal) (v : V) (hv : v β D.used) : | |
| (D.usedFinset.filter fun w => G.Adj v w).card β€ 3 * Fintype.card I := by | |
| classical | |
| have he : D.usedFinset.filter (fun w => G.Adj v w) = | |
| Finset.univ.biUnion (fun i => (D.paths i).2.val.support.toFinset.filter fun w => G.Adj v w) := by | |
| ext w | |
| simp only [Finset.mem_filter, usedFinset, Finset.mem_biUnion, Finset.mem_univ, true_and] | |
| constructor | |
| Β· rintro β¨β¨i, hiβ©, hwβ© | |
| exact β¨i, hi, hwβ© | |
| Β· rintro β¨i, hi, hwβ© | |
| exact β¨β¨i, hiβ©, hwβ© | |
| rw [he] | |
| calc | |
| _ β€ β i : I, ((D.paths i).2.val.support.toFinset.filter fun w => G.Adj v w).card := Finset.card_biUnion_le | |
| _ β€ β _i : I, 3 := Finset.sum_le_sum (fun i _ => hD.path_neighbors_le_three i v hv) | |
| _ = 3 * Fintype.card I := by simp [Nat.mul_comm] | |
| lemma mem_take_indices {u w : V} (p : G.Walk u w) (a : β) {v : V} | |
| (hv : v β (p.take a).support) : | |
| β n, n β€ a β§ n β€ p.length β§ p.getVert n = v := by | |
| obtain β¨n, hn, hlenβ© := Walk.mem_support_iff_exists_getVert.mp hv | |
| rw [Walk.take_length] at hlen | |
| have hna := (Nat.le_min.mp hlen).1 | |
| have hnl := (Nat.le_min.mp hlen).2 | |
| rw [Walk.take_getVert, Nat.min_eq_right hna] at hn | |
| exact β¨n, hna, hnl, hnβ© | |
| lemma mem_drop_indices {u w : V} (p : G.Walk u w) (b : β) (hb : b β€ p.length) | |
| {v : V} (hv : v β (p.drop b).support) : | |
| β n, b β€ n β§ n β€ p.length β§ p.getVert n = v := by | |
| obtain β¨n, hn, hlenβ© := Walk.mem_support_iff_exists_getVert.mp hv | |
| rw [Walk.drop_length] at hlen | |
| rw [Walk.drop_getVert] at hn | |
| exact β¨b + n, by omega, by omega, hnβ© | |
| lemma take_drop_disjoint {u w : V} (p : G.Path u w) (a b : β) | |
| (hab : a < b) (hb : b β€ p.val.length) : | |
| Disjoint {v | v β (p.val.take a).support} {v | v β (p.val.drop b).support} := by | |
| rw [Set.disjoint_left] | |
| intro v hv ht | |
| obtain β¨c, hca, hcl, hcβ© := mem_take_indices p.val a hv | |
| obtain β¨d, hbd, hdl, hdβ© := mem_drop_indices p.val b hb ht | |
| have he := p.property.getVert_injOn hcl hdl (hc.trans hd.symm) | |
| omega | |
| lemma source_not_mem_drop {u w : V} (p : G.Path u w) (b : β) | |
| (hpos : 0 < b) (hb : b β€ p.val.length) : u β (p.val.drop b).support := by | |
| intro hu | |
| obtain β¨n, hbn, hnl, hnβ© := mem_drop_indices p.val b hb hu | |
| have h0 : p.val.getVert 0 = u := p.val.getVert_zero | |
| have he := p.property.getVert_injOn (show 0 β€ p.val.length by omega) hnl (h0.trans hn.symm) | |
| omega | |
| structure Exchange (D : BagRouting G s B) where | |
| active : Finset I | |
| e : Equiv.Perm I | |
| fixed : β i, i β active β e i = i | |
| stable : β i, i β active β e i β active | |
| a : I β β | |
| b : I β β | |
| bounds : β i β active, a i + 2 β€ b i β§ b i β€ (D.paths i).2.val.length | |
| edge : β i β active, | |
| G.Adj ((D.paths i).2.val.getVert (a i)) ((D.paths (e i)).2.val.getVert (b (e i))) | |
| namespace Exchange | |
| variable [DecidableEq V] [DecidableEq I] {D : BagRouting G s B} | |
| noncomputable def front (E : D.Exchange) (i : I) : Set V := | |
| if i β E.active then {v | v β ((D.paths i).2.val.take (E.a i)).support} | |
| else {v | v β (D.paths i).2.val.support} | |
| noncomputable def tail (E : D.Exchange) (i : I) : Set V := | |
| if i β E.active then {v | v β ((D.paths i).2.val.drop (E.b i)).support} else β | |
| lemma front_subset {V I J : Type} {G : SimpleGraph V} {s : I β V} {B : J β Set V} | |
| [DecidableEq V] [DecidableEq I] {D : BagRouting G s B} | |
| (E : D.Exchange) (i : I) : E.front i β {v | v β (D.paths i).2.val.support} := by | |
| intro v hv | |
| by_cases hi : i β E.active | |
| Β· rw [front, ite_eq_left hi] at hv | |
| rw [Walk.support_take] at hv | |
| exact List.mem_of_mem_take hv | |
| Β· simpa [front, hi] using hv | |
| lemma tail_subset {V I J : Type} {G : SimpleGraph V} {s : I β V} {B : J β Set V} | |
| [DecidableEq V] [DecidableEq I] {D : BagRouting G s B} | |
| (E : D.Exchange) (i : I) : E.tail i β {v | v β (D.paths i).2.val.support} := by | |
| intro v hv | |
| by_cases hi : i β E.active | |
| Β· rw [tail, ite_eq_left hi] at hv | |
| rw [Walk.drop_support_eq_support_drop_min] at hv | |
| exact List.mem_of_mem_drop hv | |
| Β· simp [tail, hi] at hv | |
| lemma not_source_tail {V I J : Type} {G : SimpleGraph V} {s : I β V} {B : J β Set V} | |
| [DecidableEq V] [DecidableEq I] {D : BagRouting G s B} | |
| (E : D.Exchange) (i : I) : s i β E.tail i := by | |
| by_cases hi : i β E.active | |
| Β· rw [tail, ite_eq_left hi] | |
| exact source_not_mem_drop _ _ (by have := (E.bounds i hi).1; omega) (E.bounds i hi).2 | |
| Β· simp [tail, hi] | |
| lemma front_tail_disjoint {V I J : Type} {G : SimpleGraph V} {s : I β V} {B : J β Set V} | |
| [DecidableEq V] [DecidableEq I] {D : BagRouting G s B} | |
| (E : D.Exchange) (i : I) : Disjoint (E.front i) (E.tail i) := by | |
| by_cases hi : i β E.active | |
| Β· rw [front, tail, ite_eq_left hi, ite_eq_left hi] | |
| exact take_drop_disjoint _ _ _ (by have := (E.bounds i hi).1; omega) (E.bounds i hi).2 | |
| Β· simp [tail, hi] | |
| noncomputable def walk (E : D.Exchange) (i : I) (hi : i β E.active) : | |
| G.Walk (s i) (D.paths (E.e i)).1 := | |
| (((D.paths i).2.val.take (E.a i)).concat (E.edge i hi)).append | |
| ((D.paths (E.e i)).2.val.drop (E.b (E.e i))) | |
| lemma walk_support {V I J : Type} {G : SimpleGraph V} {s : I β V} {B : J β Set V} | |
| [DecidableEq V] [DecidableEq I] {D : BagRouting G s B} | |
| (E : D.Exchange) (i : I) (hi : i β E.active) {v : V} | |
| (hv : v β (E.walk i hi).support) : v β E.front i βͺ E.tail (E.e i) := by | |
| have hei := (E.stable i).mp hi | |
| rw [front, tail, ite_eq_left hi, ite_eq_left hei] | |
| simp only [walk, Walk.mem_support_append_iff, Walk.support_concat, List.mem_append, | |
| List.mem_cons, List.not_mem_nil, or_false] at hv | |
| rcases hv with (hv | hv) | hv | |
| Β· exact Or.inl hv | |
| Β· subst v | |
| exact Or.inr (Walk.start_mem_support _) | |
| Β· exact Or.inr hv | |
| lemma support_overlap (E : D.Exchange) (i j : I) (hij : i β j) (v : V) | |
| (hi : v β E.front i βͺ E.tail (E.e i)) | |
| (hj : v β E.front j βͺ E.tail (E.e j)) : v = s i β§ v = s j := by | |
| rcases hi with hi | hi <;> rcases hj with hj | hj | |
| Β· exact D.overlap i j hij v (E.front_subset i hi) (E.front_subset j hj) | |
| Β· by_cases he : i = E.e j | |
| Β· subst i | |
| exact (Set.disjoint_left.mp (E.front_tail_disjoint _) hi hj).elim | |
| Β· have h := D.overlap i (E.e j) he v (E.front_subset i hi) (E.tail_subset _ hj) | |
| exact (E.not_source_tail _ (h.2 βΈ hj)).elim | |
| Β· by_cases he : j = E.e i | |
| Β· subst j | |
| exact (Set.disjoint_left.mp (E.front_tail_disjoint _) hj hi).elim | |
| Β· have h := D.overlap j (E.e i) he v (E.front_subset j hj) (E.tail_subset _ hi) | |
| exact (E.not_source_tail _ (h.2 βΈ hi)).elim | |
| Β· have he : E.e i β E.e j := fun h => hij (E.e.injective h) | |
| have h := D.overlap _ _ he v (E.tail_subset _ hi) (E.tail_subset _ hj) | |
| exact (E.not_source_tail _ (h.1 βΈ hi)).elim | |
| noncomputable def routing (E : D.Exchange) : BagRouting G s B := by | |
| let paths : β i, Ξ£ v, G.Path (s i) v := fun i => | |
| if hi : i β E.active then β¨(D.paths (E.e i)).1, (E.walk i hi).toPathβ© else D.paths i | |
| refine β¨paths, D.bag β E.e, D.bag_injective.comp E.e.injective, ?_, ?_β© | |
| Β· intro i | |
| by_cases hi : i β E.active | |
| Β· have he : paths i = β¨(D.paths (E.e i)).1, (E.walk i hi).toPathβ© := dite_eq_left hi | |
| rw [he] | |
| exact D.endpoint_mem _ | |
| Β· have he : paths i = D.paths i := dite_eq_right hi | |
| rw [he] | |
| simpa [E.fixed i hi] using D.endpoint_mem i | |
| Β· intro i j hij v hvi hvj | |
| apply E.support_overlap i j hij v | |
| Β· by_cases hi : i β E.active | |
| Β· have he : paths i = β¨(D.paths (E.e i)).1, (E.walk i hi).toPathβ© := dite_eq_left hi | |
| rw [he] at hvi | |
| exact E.walk_support i hi ((E.walk i hi).support_toPath_subset_support hvi) | |
| Β· have he : paths i = D.paths i := dite_eq_right hi | |
| rw [he] at hvi | |
| exact Or.inl (by simpa [front, hi] using hvi) | |
| Β· by_cases hj : j β E.active | |
| Β· have he : paths j = β¨(D.paths (E.e j)).1, (E.walk j hj).toPathβ© := dite_eq_left hj | |
| rw [he] at hvj | |
| exact E.walk_support j hj ((E.walk j hj).support_toPath_subset_support hvj) | |
| Β· have he : paths j = D.paths j := dite_eq_right hj | |
| rw [he] at hvj | |
| exact Or.inl (by simpa [front, hj] using hvj) | |
| lemma length_inequality (E : D.Exchange) (i : I) : | |
| (E.routing.paths i).2.val.length + (if E.e i β E.active then E.b (E.e i) else 0) β€ | |
| (D.paths (E.e i)).2.val.length + (if i β E.active then E.a i + 1 else 0) := by | |
| by_cases hi : i β E.active | |
| Β· have he : E.routing.paths i = β¨(D.paths (E.e i)).1, (E.walk i hi).toPathβ© := dite_eq_left hi | |
| rw [he, ite_eq_left hi, ite_eq_left ((E.stable i).mp hi)] | |
| have hlen : (E.walk i hi).toPath.val.length β€ (E.walk i hi).length := | |
| (E.walk i hi).length_bypass_le_length | |
| have ha := (E.bounds i hi).1 | |
| have hb := E.bounds (E.e i) ((E.stable i).mp hi) | |
| have hia := E.bounds i hi | |
| have hleni : E.a i β€ (D.paths i).2.val.length := by omega | |
| have hwlen : (E.walk i hi).length = E.a i + 1 + | |
| ((D.paths (E.e i)).2.val.length - E.b (E.e i)) := by | |
| simp only [walk, Walk.length_append, Walk.length_concat, Walk.take_length, | |
| Nat.min_eq_left hleni, Walk.drop_length] | |
| rw [hwlen] at hlen | |
| change (E.walk i hi).toPath.val.length + E.b (E.e i) β€ _ | |
| omega | |
| Β· have he : E.routing.paths i = D.paths i := dite_eq_right hi | |
| rw [he, E.fixed i hi] | |
| simp only [ite_eq_right hi, le_refl] | |
| lemma shorter [Fintype I] (E : D.Exchange) (hE : E.active.Nonempty) : | |
| E.routing.totalLength < D.totalLength := by | |
| let a : I β β := fun i => if i β E.active then E.a i + 1 else 0 | |
| let b : I β β := fun i => if i β E.active then E.b i else 0 | |
| have hlt : (β i, a i) < β i, b i := by | |
| apply Finset.sum_lt_sum | |
| Β· intro i _ | |
| by_cases hi : i β E.active | |
| Β· have := (E.bounds i hi).1 | |
| simp only [a, b, ite_eq_left hi] | |
| omega | |
| Β· simp [a, b, hi] | |
| Β· obtain β¨i, hiβ© := hE | |
| refine β¨i, Finset.mem_univ _, ?_β© | |
| have := (E.bounds i hi).1 | |
| simp only [a, b, ite_eq_left hi] | |
| omega | |
| have hs := Finset.sum_le_sum (s := Finset.univ) (fun i _ => E.length_inequality i) | |
| change (β i, ((E.routing.paths i).2.val.length + b (E.e i))) β€ | |
| β i, ((D.paths (E.e i)).2.val.length + a i) at hs | |
| rw [Finset.sum_add_distrib, Finset.sum_add_distrib, Equiv.sum_comp E.e b, | |
| Equiv.sum_comp E.e (fun i => (D.paths i).2.val.length)] at hs | |
| change E.routing.totalLength + (β i, b i) β€ D.totalLength + (β i, a i) at hs | |
| omega | |
| end Exchange | |
| lemma Minimal.no_exchange [Fintype I] [DecidableEq V] [DecidableEq I] | |
| {D : BagRouting G s B} (hD : D.Minimal) (E : D.Exchange) : Β¬ E.active.Nonempty := by | |
| intro hE | |
| exact (not_lt_of_ge (hD E.routing)) (E.shorter hE) | |
| lemma cycle_permutation [Fintype I] [DecidableEq I] (Q : Finset I) (hQ : Q.Nonempty) | |
| (f : I β I) (hf : β i β Q, f i β Q) : | |
| β T : Finset I, T β Q β§ T.Nonempty β§ β e : Equiv.Perm I, | |
| (β i, i β T β e i = i) β§ (β i, i β T β e i β T) β§ | |
| (β i β T, e i = f i) := by | |
| classical | |
| let C := Q.powerset.filter fun T => T.Nonempty β§ β i β T, f i β T | |
| have hQC : Q β C := Finset.mem_filter.mpr β¨Finset.mem_powerset.mpr (by rfl), hQ, hfβ© | |
| obtain β¨T, hTC, hminβ© := C.exists_min_image Finset.card β¨Q, hQCβ© | |
| obtain β¨hTQ, hn, hclosedβ© := Finset.mem_filter.mp hTC | |
| have hsub : T.image f β T := by | |
| intro i hi | |
| obtain β¨j, hj, rflβ© := Finset.mem_image.mp hi | |
| exact hclosed j hj | |
| have hIC : T.image f β C := by | |
| refine Finset.mem_filter.mpr β¨Finset.mem_powerset.mpr (hsub.trans (Finset.mem_powerset.mp hTQ)), | |
| hn.image f, ?_β© | |
| intro i hi | |
| exact Finset.mem_image.mpr β¨i, hsub hi, rflβ© | |
| have heq : T.image f = T := Finset.eq_of_subset_of_card_le hsub (hmin _ hIC) | |
| let g : β₯T β β₯T := fun i => β¨f i, hclosed i i.propertyβ© | |
| have hsurj : Function.Surjective g := by | |
| intro i | |
| have hi : i.val β T.image f := heq.symm βΈ i.property | |
| obtain β¨j, hj, heβ© := Finset.mem_image.mp hi | |
| exact β¨β¨j, hjβ©, Subtype.ext heβ© | |
| let e0 : Equiv.Perm β₯T := Equiv.ofBijective g (Finite.surjective_iff_bijective.mp hsurj) | |
| let e := Equiv.Perm.ofSubtype e0 | |
| refine β¨T, Finset.mem_powerset.mp hTQ, hn, e, ?_, ?_, ?_β© | |
| Β· intro i hi | |
| exact Equiv.Perm.ofSubtype_apply_of_not_mem e0 hi | |
| Β· intro i | |
| exact (Equiv.Perm.ofSubtype_apply_mem_iff_mem e0 i).symm | |
| Β· intro i hi | |
| exact Equiv.Perm.ofSubtype_apply_of_mem e0 hi | |
| lemma Minimal.low_degree [Fintype I] [DecidableEq V] [DecidableEq I] | |
| [DecidableRel G.Adj] {D : BagRouting G s B} (hD : D.Minimal) | |
| (S : Finset V) (hS : S β D.usedFinset) (hne : S.Nonempty) : | |
| β v β S, (S.filter (G.Adj v)).card β€ 2 * Fintype.card I := by | |
| classical | |
| by_contra hno | |
| have hdeg : β v β S, 2 * Fintype.card I < (S.filter (G.Adj v)).card := by | |
| intro v hv | |
| exact Nat.lt_of_not_ge (fun hh => hno β¨v, hv, hhβ©) | |
| let R : I β Finset β := fun i => (Finset.range ((D.paths i).2.val.length + 1)).filter | |
| fun a => (D.paths i).2.val.getVert a β S | |
| let Q : Finset I := Finset.univ.filter fun i => (R i).Nonempty | |
| let a : I β β := fun i => if hi : (R i).Nonempty then (R i).min' hi else 0 | |
| have hQiff : β i, i β Q β (R i).Nonempty := by simp [Q] | |
| have hamin : β i β Q, a i β R i := by | |
| intro i hi | |
| have hn := (hQiff i).mp hi | |
| dsimp [a] | |
| rw [dite_eq_left hn] | |
| exact Finset.min'_mem _ _ | |
| have haS : β i β Q, (D.paths i).2.val.getVert (a i) β S := by | |
| intro i hi | |
| exact (Finset.mem_filter.mp (hamin i hi)).2 | |
| have hfind : β v β S, β i β Q, β b, b β R i β§ (D.paths i).2.val.getVert b = v := by | |
| intro v hv | |
| obtain β¨i, hiβ© := (D.mem_usedFinset v).mp (hS hv) | |
| obtain β¨b, hb, hblenβ© := Walk.mem_support_iff_exists_getVert.mp hi | |
| have hbR : b β R i := Finset.mem_filter.mpr β¨Finset.mem_range.mpr (by omega), hb βΈ hvβ© | |
| exact β¨i, (hQiff i).mpr β¨b, hbRβ©, b, hbR, hbβ© | |
| have hQ : Q.Nonempty := by | |
| obtain β¨v, hvβ© := hne | |
| obtain β¨i, hi, _β© := hfind v hv | |
| exact β¨i, hiβ© | |
| let M := Finset.univ.biUnion fun i : I => | |
| {(D.paths i).2.val.getVert (a i), (D.paths i).2.val.getVert (a i + 1)} | |
| have hM : M.card β€ 2 * Fintype.card I := by | |
| calc | |
| _ β€ β i : I, ({(D.paths i).2.val.getVert (a i), | |
| (D.paths i).2.val.getVert (a i + 1)} : Finset V).card := Finset.card_biUnion_le | |
| _ β€ β i : I, 2 := Finset.sum_le_sum fun _ _ => Finset.card_le_two | |
| _ = _ := by simp [Nat.mul_comm] | |
| have hm0 : β i, (D.paths i).2.val.getVert (a i) β M := by | |
| intro i | |
| exact Finset.mem_biUnion.mpr β¨i, Finset.mem_univ _, by simpβ© | |
| have hm1 : β i, (D.paths i).2.val.getVert (a i + 1) β M := by | |
| intro i | |
| exact Finset.mem_biUnion.mpr β¨i, Finset.mem_univ _, by simpβ© | |
| have hout : β i, β j b, i β Q β j β Q β§ a j + 2 β€ b β§ | |
| b β€ (D.paths j).2.val.length β§ | |
| G.Adj ((D.paths i).2.val.getVert (a i)) ((D.paths j).2.val.getVert b) := by | |
| intro i | |
| by_cases hi : i β Q | |
| Β· have hlarge := hdeg _ (haS i hi) | |
| have hex : β v β S.filter (G.Adj ((D.paths i).2.val.getVert (a i))), v β M := by | |
| by_contra hh | |
| have hsub : S.filter (G.Adj ((D.paths i).2.val.getVert (a i))) β M := by | |
| intro v hv | |
| by_contra hvm | |
| exact hh β¨v, hv, hvmβ© | |
| have hle := (Finset.card_le_card hsub).trans hM | |
| omega | |
| obtain β¨v, hv, hvmβ© := hex | |
| obtain β¨hvS, hvadjβ© := Finset.mem_filter.mp hv | |
| obtain β¨j, hj, b, hbR, hbβ© := hfind v hvS | |
| have hbj : a j β€ b := by | |
| have hn := (hQiff j).mp hj | |
| dsimp [a] | |
| rw [dite_eq_left hn] | |
| exact Finset.min'_le _ _ hbR | |
| have hb0 : b β a j := by | |
| intro he | |
| apply hvm | |
| rw [he] at hb | |
| exact hb βΈ hm0 j | |
| have hb1 : b β a j + 1 := by | |
| intro he | |
| apply hvm | |
| rw [he] at hb | |
| exact hb βΈ hm1 j | |
| have hblen : b β€ (D.paths j).2.val.length := by | |
| have hh := (Finset.mem_filter.mp hbR).1 | |
| simp only [Finset.mem_range] at hh | |
| omega | |
| refine β¨j, b, fun _ => β¨hj, by omega, hblen, ?_β©β© | |
| rwa [hb] | |
| Β· exact β¨i, 0, fun hh => (hi hh).elimβ© | |
| choose f c hfc using hout | |
| obtain β¨T, hTQ, hT, e, hfix, hstable, heqβ© := | |
| cycle_permutation Q hQ f (fun i hi => (hfc i hi).1) | |
| let E : D.Exchange := { | |
| active := T | |
| e := e | |
| fixed := hfix | |
| stable := hstable | |
| a := a | |
| b := fun i => c (e.symm i) | |
| bounds := by | |
| intro i hi | |
| have hpre : e.symm i β T := (hstable _).mpr (by simpa using hi) | |
| have he : f (e.symm i) = i := (heq _ hpre).symm.trans (e.apply_symm_apply i) | |
| have hc := (hfc _ (hTQ hpre)).2 | |
| rw [he] at hc | |
| exact β¨hc.1, hc.2.1β© | |
| edge := by | |
| intro i hi | |
| have hc := (hfc i (hTQ hi)).2.2.2 | |
| rw [β heq i hi] at hc | |
| simpa only [Equiv.symm_apply_apply] using hc | |
| } | |
| exact hD.no_exchange E hT | |
| end BagRouting | |
| end LinearListHadwiger | |
| end OAI | |