math / data /lean /OAI /Combinatorics /ListHadwiger /Exchanges.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
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