Download lean/OAI/Combinatorics/ListHadwiger/Routing.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 12.2 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/ListHadwiger/Routing.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Combinatorics/ListHadwiger/Routing.lean
-
curl -L -o Routing.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/ListHadwiger/Routing.lean
12.2 kB
| import OAI.Combinatorics.ListHadwiger.PathPacking | |
| namespace OAI | |
| namespace LinearListHadwiger | |
| open SimpleGraph PathPacking | |
| theorem avoidingConnection_of_kConnectedOn {V : Type} [Fintype V] [DecidableEq V] | |
| (G : SimpleGraph V) (S A B X : Finset V) {k : ℕ} | |
| (hc : KConnectedOn G S k) (haS : A ⊆ S) (hbS : B ⊆ S) | |
| (ha : X.card < A.card) (hb : X.card < B.card) (hk : X.card < k) : | |
| AvoidingConnection G A B X := by | |
| classical | |
| have hAX : ¬ A ⊆ X := fun hh => (Nat.not_le_of_lt ha) (Finset.card_le_card hh) | |
| have hBX : ¬ B ⊆ X := fun hh => (Nat.not_le_of_lt hb) (Finset.card_le_card hh) | |
| simp only [Finset.subset_iff, not_forall] at hAX hBX | |
| obtain ⟨a, haA, haX⟩ := hAX | |
| obtain ⟨b, hbB, hbX⟩ := hBX | |
| let Z := S ∩ X | |
| have hZ : Z ⊆ S := Finset.inter_subset_left | |
| have hZk : Z.card < k := (Finset.card_le_card Finset.inter_subset_right).trans_lt hk | |
| have hc' := (hc.2 Z hZ hZk).preconnected | |
| have ha' : a ∈ S \ Z := Finset.mem_sdiff.mpr ⟨haS haA, fun hh => haX (Finset.mem_inter.mp hh).2⟩ | |
| have hb' : b ∈ S \ Z := Finset.mem_sdiff.mpr ⟨hbS hbB, fun hh => hbX (Finset.mem_inter.mp hh).2⟩ | |
| obtain ⟨p⟩ := hc' ⟨a, ha'⟩ ⟨b, hb'⟩ | |
| refine ⟨a, haA, b, hbB, p.map (Embedding.induce (↑(S \ Z) : Set V)).toHom, ?_⟩ | |
| intro v hv | |
| have hv' : v ∈ (p.map (Embedding.induce (↑(S \ Z) : Set V)).toHom).support := hv | |
| rw [Walk.support_map] at hv' | |
| obtain ⟨w, _, rfl⟩ := List.mem_map.mp hv' | |
| intro hwX | |
| exact (Finset.mem_sdiff.mp w.property).2 | |
| (Finset.mem_inter.mpr ⟨(Finset.mem_sdiff.mp w.property).1, hwX⟩) | |
| theorem packing_of_kConnectedOn {V : Type} [Fintype V] [DecidableEq V] | |
| (G : SimpleGraph V) (S A B : Finset V) {k : ℕ} | |
| (hc : KConnectedOn G S k) (haS : A ⊆ S) (hbS : B ⊆ S) | |
| (ha : A.card ≤ k) (hb : A.card ≤ B.card) : Nonempty (FullPacking G A B) := by | |
| apply fullPacking_of_no_small_separator | |
| intro X hX | |
| exact avoidingConnection_of_kConnectedOn G S A B X hc haS hbS hX | |
| (hX.trans_le hb) (hX.trans_le ha) | |
| noncomputable def deletedFibers {V W : Type} [Fintype V] (π : W → V) (X : Finset W) : | |
| Finset V := by | |
| classical | |
| exact Finset.univ.filter fun v => ∀ w, π w = v → w ∈ X | |
| lemma deletedFibers_card {V W : Type} [Fintype V] [DecidableEq W] | |
| (π : W → V) (s : V → W) (hs : ∀ v, π (s v) = v) (X : Finset W) : | |
| (deletedFibers π X).card ≤ X.card := by | |
| classical | |
| have hinj : Function.Injective s := by | |
| intro v w h | |
| simpa only [hs] using congrArg π h | |
| have hh : (deletedFibers π X).image s ⊆ X := by | |
| intro w hw | |
| obtain ⟨v, hv, rfl⟩ := Finset.mem_image.mp hw | |
| exact (Finset.mem_filter.mp hv).2 (s v) (hs v) | |
| simpa only [Finset.card_image_of_injective _ hinj] using Finset.card_le_card hh | |
| lemma avoiding_walk_comap {V W : Type} [Fintype V] [DecidableEq V] | |
| (G : SimpleGraph V) (π : W → V) (X : Finset W) {a b : W} | |
| (ha : a ∉ X) (hb : b ∉ X) (hab : π a ≠ π b) | |
| (hc : (G.induce (↑(Finset.univ \ deletedFibers π X) : Set V)).Connected) : | |
| ∃ p : (G.comap π).Walk a b, ∀ w ∈ p.support, w ∉ X := by | |
| classical | |
| let S := Finset.univ \ deletedFibers π X | |
| have haS : π a ∈ S := by | |
| simp only [S, Finset.mem_sdiff, Finset.mem_univ, true_and] | |
| intro hh | |
| exact ha ((Finset.mem_filter.mp hh).2 a rfl) | |
| have hbS : π b ∈ S := by | |
| simp only [S, Finset.mem_sdiff, Finset.mem_univ, true_and] | |
| intro hh | |
| exact hb ((Finset.mem_filter.mp hh).2 b rfl) | |
| have hex : ∀ v : ↥S, ∃ w : W, w ∉ X ∧ π w = v.val := by | |
| intro v | |
| have hh := (Finset.mem_sdiff.mp v.property).2 | |
| simp only [deletedFibers, Finset.mem_filter, Finset.mem_univ, true_and, | |
| not_forall] at hh | |
| obtain ⟨w, heq, hw⟩ := hh | |
| exact ⟨w, hw, heq⟩ | |
| choose f hfX hfπ using hex | |
| let g : ↥S → W := fun v => if v.val = π a then a else if v.val = π b then b else f v | |
| have hgX : ∀ v, g v ∉ X := by | |
| intro v | |
| simp only [g] | |
| split_ifs | |
| · exact ha | |
| · exact hb | |
| · exact hfX v | |
| have hgπ : ∀ v, π (g v) = v.val := by | |
| intro v | |
| dsimp only [g] | |
| split_ifs with hh hh | |
| · exact hh.symm | |
| · exact hh.symm | |
| · exact hfπ v | |
| let φ : G.induce (↑S : Set V) →g G.comap π := | |
| { toFun := g | |
| map_rel' := by | |
| intro v w hvw | |
| change G.Adj (π (g v)) (π (g w)) | |
| rw [hgπ, hgπ] | |
| exact hvw } | |
| obtain ⟨p⟩ := hc.preconnected (⟨π a, haS⟩ : ↥S) ⟨π b, hbS⟩ | |
| have hga : φ ⟨π a, haS⟩ = a := by simp [φ, g] | |
| have hgb : φ ⟨π b, hbS⟩ = b := by simp [φ, g, hab.symm] | |
| refine ⟨(p.map φ).copy hga hgb, ?_⟩ | |
| intro w hw | |
| have hw' : w ∈ (p.map φ).support := by simpa using hw | |
| rw [Walk.support_map] at hw' | |
| obtain ⟨v, _, rfl⟩ := List.mem_map.mp hw' | |
| exact hgX v | |
| lemma packing_in_comap {V W : Type} [Fintype V] [Fintype W] | |
| [DecidableEq V] [DecidableEq W] (G : SimpleGraph V) | |
| (π : W → V) (s : V → W) (hs : ∀ v, π (s v) = v) | |
| (A B : Finset W) {k : ℕ} (hc : KConnectedOn G Finset.univ k) | |
| (ha : A.card ≤ k) (hb : A.card ≤ B.card) | |
| (hdis : ∀ a ∈ A, ∀ b ∈ B, π a ≠ π b) : | |
| Nonempty (FullPacking (G.comap π) A B) := by | |
| classical | |
| apply fullPacking_of_no_small_separator | |
| intro X hX | |
| have hAX : ¬ A ⊆ X := fun hh => (Nat.not_le_of_lt hX) (Finset.card_le_card hh) | |
| have hBX : ¬ B ⊆ X := fun hh => (Nat.not_le_of_lt (hX.trans_le hb)) (Finset.card_le_card hh) | |
| simp only [Finset.subset_iff, not_forall] at hAX hBX | |
| obtain ⟨a, haA, haX⟩ := hAX | |
| obtain ⟨b, hbB, hbX⟩ := hBX | |
| have hc' := hc.2 (deletedFibers π X) (Finset.subset_univ _) <| | |
| (deletedFibers_card π s hs X).trans_lt (hX.trans_le ha) | |
| obtain ⟨p, hp⟩ := avoiding_walk_comap G π X haX hbX (hdis a haA b hbB) hc' | |
| exact ⟨a, haA, b, hbB, p, hp⟩ | |
| namespace PathPacking | |
| lemma FullPacking.target_injective {V : Type} {G : SimpleGraph V} {A B : Finset V} | |
| (P : FullPacking G A B) : Function.Injective P.target := by | |
| intro a b hab | |
| by_contra hn | |
| have hh := Set.disjoint_left.mp (P.disjoint a b hn) | |
| apply hh (show (P.target a).val ∈ (P.route a).val.support by simp) | |
| simpa only [hab, Set.mem_ofPred_eq] using | |
| (show (P.target b).val ∈ (P.route b).val.support by simp) | |
| end PathPacking | |
| structure DoublePacking {V : Type} (G : SimpleGraph V) (A B : Finset V) where | |
| target : (↥A × Bool) → ↥B | |
| target_injective : Function.Injective target | |
| route : ∀ i : ↥A × Bool, G.Path i.1.val (target i).val | |
| source_only : ∀ i, ∀ v ∈ (route i).val.support, v ∈ A → v = i.1.val | |
| target_only : ∀ i, ∀ v ∈ (route i).val.support, v ∈ B → v = (target i).val | |
| overlap : ∀ i j, i ≠ j → ∀ v ∈ (route i).val.support, | |
| v ∈ (route j).val.support → v = i.1.val ∧ v = j.1.val | |
| theorem double_packing {V : Type} [Fintype V] [DecidableEq V] | |
| (G : SimpleGraph V) (A B : Finset V) (hab : Disjoint A B) | |
| (hc : KConnectedOn G Finset.univ (2 * A.card)) (hb : 2 * A.card ≤ B.card) : | |
| Nonempty (DoublePacking G A B) := by | |
| classical | |
| let W := {x : V × Bool // x.2 = false ∨ x.1 ∈ A} | |
| let : Fintype W := Fintype.ofFinite W | |
| let π : W → V := fun w => w.val.1 | |
| let sec : V → W := fun v => ⟨(v, false), Or.inl rfl⟩ | |
| have hs : ∀ v, π (sec v) = v := fun _ => rfl | |
| let ι : (↥A × Bool) → W := fun i => ⟨(i.1.val, i.2), Or.inr i.1.property⟩ | |
| have hi : Function.Injective ι := by | |
| intro i j hij | |
| apply Prod.ext | |
| · exact Subtype.ext (congrArg (fun w : W => w.val.1) hij) | |
| · exact congrArg (fun w : W => w.val.2) hij | |
| let AC := Finset.univ.image ι | |
| let BC := (Finset.univ : Finset ↥B).image fun b => sec b.val | |
| have hAC : AC.card = 2 * A.card := by | |
| simp only [AC, Finset.card_image_of_injective _ hi, Finset.card_univ, | |
| Fintype.card_prod, Fintype.card_coe, Fintype.card_bool] | |
| omega | |
| have hBS : Function.Injective (fun b : ↥B => sec b.val) := by | |
| intro b c h | |
| exact Subtype.ext (congrArg π h) | |
| have hBC : BC.card = B.card := by | |
| simp only [BC, Finset.card_image_of_injective _ hBS, | |
| Finset.card_univ, Fintype.card_coe] | |
| have hmemAC : ∀ w : W, w ∈ AC ↔ π w ∈ A := by | |
| intro w | |
| constructor | |
| · intro hw | |
| obtain ⟨i, _, rfl⟩ := Finset.mem_image.mp hw | |
| exact i.1.property | |
| · intro hw | |
| exact Finset.mem_image.mpr ⟨(⟨π w, hw⟩, w.val.2), Finset.mem_univ _, rfl⟩ | |
| have hsec : ∀ w : W, π w ∉ A → sec (π w) = w := by | |
| intro w hw | |
| apply Subtype.ext | |
| change (π w, false) = w.val | |
| exact Prod.ext rfl (w.property.resolve_right hw).symm | |
| have hmemBC : ∀ w : W, w ∈ BC ↔ π w ∈ B := by | |
| intro w | |
| constructor | |
| · intro hw | |
| obtain ⟨b, _, rfl⟩ := Finset.mem_image.mp hw | |
| exact b.property | |
| · intro hw | |
| have hwA : π w ∉ A := fun ha => Finset.disjoint_left.mp hab ha hw | |
| exact Finset.mem_image.mpr ⟨⟨π w, hw⟩, Finset.mem_univ _, hsec w hwA⟩ | |
| obtain ⟨P⟩ := packing_in_comap G π sec hs AC BC hc (by omega) (by omega) (by | |
| intro a ha b hb heq | |
| exact Finset.disjoint_left.mp hab ((hmemAC a).mp ha) | |
| (heq.symm ▸ (hmemBC b).mp hb)) | |
| let src : (↥A × Bool) → ↥AC := fun i => | |
| ⟨ι i, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ | |
| have hsrc : Function.Injective src := by | |
| intro i j hij | |
| exact hi (congrArg Subtype.val hij) | |
| let tar : (↥A × Bool) → ↥B := fun i => | |
| ⟨π (P.target (src i)), (hmemBC _).mp (P.target (src i)).property⟩ | |
| have htar : Function.Injective tar := by | |
| intro i j hij | |
| apply hsrc | |
| apply P.target_injective | |
| apply Subtype.ext | |
| have heq : π (P.target (src i)) = π (P.target (src j)) := congrArg Subtype.val hij | |
| have hiB : π (P.target (src i)) ∈ B := (tar i).property | |
| have hjB : π (P.target (src j)) ∈ B := (tar j).property | |
| have hiA : π (P.target (src i)) ∉ A := fun h => Finset.disjoint_left.mp hab h hiB | |
| have hjA : π (P.target (src j)) ∉ A := fun h => Finset.disjoint_left.mp hab h hjB | |
| rw [← hsec _ hiA, ← hsec _ hjA, heq] | |
| let raw : ∀ i : ↥A × Bool, G.Walk i.1.val (tar i).val := | |
| fun i => (P.route (src i)).val.map (Hom.comap π G) | |
| let route : ∀ i : ↥A × Bool, G.Path i.1.val (tar i).val := fun i => (raw i).toPath | |
| have hsupport : ∀ i, ∀ v ∈ (route i).val.support, | |
| ∃ w ∈ (P.route (src i)).val.support, π w = v := by | |
| intro i v hv | |
| have hv' : v ∈ (raw i).support := (raw i).support_toPath_subset_support hv | |
| have hv'' : v ∈ ((P.route (src i)).val.map (Hom.comap π G)).support := hv' | |
| rw [Walk.support_map] at hv'' | |
| obtain ⟨w, hw, heq⟩ := List.mem_map.mp hv'' | |
| exact ⟨w, hw, heq⟩ | |
| have hsource : ∀ i, ∀ v ∈ (route i).val.support, v ∈ A → v = i.1.val := by | |
| intro i v hv hvA | |
| obtain ⟨w, hw, heq⟩ := hsupport i v hv | |
| have hwA : w ∈ AC := (hmemAC w).mpr (heq ▸ hvA) | |
| have hh := P.source_only (src i) w hw hwA | |
| exact heq.symm.trans (congrArg π hh) | |
| have htarget : ∀ i, ∀ v ∈ (route i).val.support, v ∈ B → v = (tar i).val := by | |
| intro i v hv hvB | |
| obtain ⟨w, hw, heq⟩ := hsupport i v hv | |
| have hwB : w ∈ BC := (hmemBC w).mpr (heq ▸ hvB) | |
| have hh := P.target_only (src i) w hw hwB | |
| exact heq.symm.trans (congrArg π hh) | |
| refine ⟨⟨tar, htar, route, hsource, htarget, ?_⟩⟩ | |
| intro i j hij v hvi hvj | |
| by_cases hvA : v ∈ A | |
| · exact ⟨hsource i v hvi hvA, hsource j v hvj hvA⟩ | |
| · obtain ⟨w, hw, heq⟩ := hsupport i v hvi | |
| obtain ⟨w', hw', heq'⟩ := hsupport j v hvj | |
| have hwA : π w ∉ A := heq ▸ hvA | |
| have hwA' : π w' ∉ A := heq' ▸ hvA | |
| have hww : w = w' := by rw [← hsec w hwA, ← hsec w' hwA', heq, heq'] | |
| have hne : src i ≠ src j := fun h => hij (hsrc h) | |
| exact (Set.disjoint_left.mp (P.disjoint (src i) (src j) hne) hw (hww ▸ hw')).elim | |
| structure MinorModel {V W : Type} (G : SimpleGraph V) (H : SimpleGraph W) where | |
| branch : W → Set V | |
| connected : ∀ w, (G.induce (branch w)).Connected | |
| disjoint : ∀ u v, u ≠ v → Disjoint (branch u) (branch v) | |
| adjacent : ∀ ⦃u v⦄, H.Adj u v → ∃ x ∈ branch u, ∃ y ∈ branch v, G.Adj x y | |
| end LinearListHadwiger | |
| end OAI | |