Download lean/OAI/Combinatorics/ListHadwiger/PathPacking.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 10.5 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/ListHadwiger/PathPacking.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Combinatorics/ListHadwiger/PathPacking.lean
-
curl -L -o PathPacking.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/ListHadwiger/PathPacking.lean
10.5 kB
| import OAI.Combinatorics.ListHadwiger.Palette | |
| namespace OAI | |
| namespace LinearListHadwiger.PathPacking | |
| open SimpleGraph | |
| def AvoidingConnection {V : Type} (G : SimpleGraph V) (A B X : Finset V) : Prop := | |
| ∃ a ∈ A, ∃ b ∈ B, ∃ p : G.Walk a b, ∀ v ∈ p.support, v ∉ X | |
| theorem successor_of_no_small_separator {V : Type} [Fintype V] [DecidableEq V] | |
| (G : SimpleGraph V) (A B : Finset V) | |
| (hconn : ∀ X : Finset V, X.card < A.card → AvoidingConnection G A B X) : | |
| ∃ f : {v // v ∉ B} → {v // v ∉ A}, | |
| Function.Injective f ∧ ∀ v, v.val = (f v).val ∨ G.Adj v.val (f v).val := by | |
| classical | |
| let L : {v // v ∉ B} → Finset {v // v ∉ A} := | |
| fun v => Finset.univ.filter fun w => v.val = w.val ∨ G.Adj v.val w.val | |
| have hHall : ∀ S : Finset {v // v ∉ B}, S.card ≤ (S.biUnion L).card := by | |
| intro S | |
| by_contra hn | |
| have hbad : (S.biUnion L).card < S.card := by omega | |
| let T : Finset V := S.image Subtype.val | |
| let N : Finset V := (S.biUnion L).image Subtype.val | |
| have hTcard : T.card = S.card := Finset.card_image_of_injective _ Subtype.val_injective | |
| have hNcard : N.card = (S.biUnion L).card := | |
| Finset.card_image_of_injective _ Subtype.val_injective | |
| have hTB : ∀ v ∈ T, v ∉ B := by | |
| intro v hv | |
| obtain ⟨w, _, rfl⟩ := Finset.mem_image.mp hv | |
| exact w.property | |
| have hNA : Disjoint N A := by | |
| apply Finset.disjoint_left.mpr | |
| intro v hv ha | |
| obtain ⟨w, _, rfl⟩ := Finset.mem_image.mp hv | |
| exact w.property ha | |
| have hTN : T ⊆ A ∪ N := by | |
| intro v hv | |
| by_cases ha : v ∈ A | |
| · exact Finset.mem_union_left _ ha | |
| · apply Finset.mem_union_right | |
| obtain ⟨w, hw, hweq⟩ := Finset.mem_image.mp hv | |
| apply Finset.mem_image.mpr | |
| refine ⟨⟨v, ha⟩, Finset.mem_biUnion.mpr ⟨w, hw, ?_⟩, rfl⟩ | |
| exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, Or.inl hweq⟩ | |
| let X := (A ∪ N) \ T | |
| have hcard : X.card < A.card := by | |
| have hh := Finset.card_sdiff_add_card_eq_card hTN | |
| have hh' := Finset.card_union_of_disjoint hNA.symm | |
| change X.card + T.card = (A ∪ N).card at hh | |
| omega | |
| have hclosed : ∀ v ∈ T, ∀ w, G.Adj v w → w ∉ X → w ∈ T := by | |
| intro v hv w hadj hw | |
| by_contra hwT | |
| apply hw | |
| apply Finset.mem_sdiff.mpr | |
| refine ⟨?_, hwT⟩ | |
| by_cases hwA : w ∈ A | |
| · exact Finset.mem_union_left _ hwA | |
| · apply Finset.mem_union_right | |
| obtain ⟨v', hv', heq⟩ := Finset.mem_image.mp hv | |
| apply Finset.mem_image.mpr | |
| refine ⟨⟨w, hwA⟩, Finset.mem_biUnion.mpr ⟨v', hv', ?_⟩, rfl⟩ | |
| apply Finset.mem_filter.mpr | |
| refine ⟨Finset.mem_univ _, Or.inr ?_⟩ | |
| simpa only [heq] using hadj | |
| have hwalk : ∀ {v w : V} (p : G.Walk v w), v ∈ T → | |
| (∀ z ∈ p.support, z ∉ X) → w ∈ T := by | |
| intro v w p | |
| induction p with | |
| | nil => exact fun hv _ => hv | |
| | @cons v w u hadj p ih => | |
| intro hv hp | |
| apply ih (hclosed v hv w hadj (hp w (by simp))) | |
| intro z hz | |
| exact hp z (by simp [hz]) | |
| obtain ⟨a, ha, b, hb, p, hp⟩ := hconn X hcard | |
| have haT : a ∈ T := by | |
| by_contra hn | |
| exact hp a (by simp) (Finset.mem_sdiff.mpr ⟨Finset.mem_union_left _ ha, hn⟩) | |
| exact hTB b (hwalk p haT hp) hb | |
| obtain ⟨f, hf, hmem⟩ := (Finset.all_card_le_biUnion_card_iff_exists_injective L).mp hHall | |
| exact ⟨f, hf, fun v => (Finset.mem_filter.mp (hmem v)).2⟩ | |
| section Orbits | |
| variable {V : Type} [Fintype V] [DecidableEq V] | |
| variable (A B : Finset V) (f : {v // v ∉ B} → {v // v ∉ A}) | |
| noncomputable def next (v : V) : V := if h : v ∈ B then v else (f ⟨v, h⟩).val | |
| lemma next_not_source {V : Type} [Fintype V] [DecidableEq V] | |
| (A B : Finset V) (f : {v // v ∉ B} → {v // v ∉ A}) {v : V} (hv : v ∉ B) : next A B f v ∉ A := by | |
| simpa [next, hv] using (f ⟨v, hv⟩).property | |
| lemma next_injective_off_target {V : Type} [Fintype V] [DecidableEq V] | |
| (A B : Finset V) (f : {v // v ∉ B} → {v // v ∉ A}) (hf : Function.Injective f) {v w : V} | |
| (hv : v ∉ B) (hw : w ∉ B) (h : next A B f v = next A B f w) : v = w := by | |
| simp only [next, dite_eq_right hv, dite_eq_right hw] at h | |
| have hh := hf (Subtype.ext h) | |
| exact congrArg Subtype.val hh | |
| lemma orbit_collision (hf : Function.Injective f) {a b : V} | |
| (ha : a ∈ A) (hb : b ∈ A) (n m : ℕ) | |
| (hn : ∀ i < n, (next A B f)^[i] a ∉ B) | |
| (hm : ∀ i < m, (next A B f)^[i] b ∉ B) | |
| (heq : (next A B f)^[n] a = (next A B f)^[m] b) : n = m ∧ a = b := by | |
| induction n generalizing m with | |
| | zero => | |
| cases m with | |
| | zero => simpa using heq | |
| | succ m => | |
| have hh := next_not_source A B f (hm m (Nat.lt_succ_self m)) | |
| rw [Function.iterate_succ_apply'] at heq | |
| exact (hh (by simpa only [Function.iterate_zero, id_eq] using (heq ▸ ha))).elim | |
| | succ n ih => | |
| cases m with | |
| | zero => | |
| have hh := next_not_source A B f (hn n (Nat.lt_succ_self n)) | |
| rw [Function.iterate_succ_apply'] at heq | |
| exact (hh (by simpa only [Function.iterate_zero, id_eq] using (heq.symm ▸ hb))).elim | |
| | succ m => | |
| have heq' : (next A B f)^[n] a = (next A B f)^[m] b := by | |
| apply next_injective_off_target A B f hf (hn n (Nat.lt_succ_self n)) | |
| (hm m (Nat.lt_succ_self m)) | |
| simpa only [Function.iterate_succ_apply'] using heq | |
| obtain ⟨hnm, hab⟩ := ih m (fun i hi => hn i (by omega)) | |
| (fun i hi => hm i (by omega)) heq' | |
| exact ⟨congrArg Nat.succ hnm, hab⟩ | |
| lemma orbit_hits_target (hf : Function.Injective f) {a : V} (ha : a ∈ A) : | |
| ∃ n : ℕ, (next A B f)^[n] a ∈ B := by | |
| by_contra hn | |
| have havoid : ∀ n : ℕ, (next A B f)^[n] a ∉ B := by simpa using hn | |
| let g : Fin (Fintype.card V + 1) → V := fun i => (next A B f)^[i.val] a | |
| have hg : Function.Injective g := by | |
| intro i j hij | |
| apply Fin.ext | |
| exact (orbit_collision A B f hf ha ha i.val j.val | |
| (fun n _ => havoid n) (fun n _ => havoid n) hij).1 | |
| have hh := Fintype.card_le_of_injective g hg | |
| simp at hh | |
| lemma orbit_walk (G : SimpleGraph V) (hf : Function.Injective f) | |
| (hstep : ∀ v, v.val = (f v).val ∨ G.Adj v.val (f v).val) | |
| {a : V} (ha : a ∈ A) (n : ℕ) | |
| (hn : ∀ i < n, (next A B f)^[i] a ∉ B) : | |
| ∃ p : G.Walk a ((next A B f)^[n] a), | |
| ∀ v ∈ p.support, ∃ i ≤ n, v = (next A B f)^[i] a := by | |
| induction n with | |
| | zero => | |
| refine ⟨Walk.nil, ?_⟩ | |
| intro v hv | |
| exact ⟨0, le_rfl, by simpa using hv⟩ | |
| | succ n ih => | |
| have hn' : ∀ i < n, (next A B f)^[i] a ∉ B := fun i hi => hn i (by omega) | |
| obtain ⟨p, hp⟩ := ih hn' | |
| have hx := hn n (Nat.lt_succ_self n) | |
| have hne : (next A B f)^[n] a ≠ (next A B f)^[n + 1] a := by | |
| intro heq | |
| have hh := (orbit_collision A B f hf ha ha n (n + 1) hn' hn heq).1 | |
| omega | |
| have hadj : G.Adj ((next A B f)^[n] a) ((next A B f)^[n + 1] a) := by | |
| rw [Function.iterate_succ_apply', next, dite_eq_right hx] | |
| rcases hstep ⟨(next A B f)^[n] a, hx⟩ with hh | hh | |
| · exact (hne (by simpa only [Function.iterate_succ_apply', next, dite_eq_right hx] | |
| using hh)).elim | |
| · exact hh | |
| refine ⟨p.concat hadj, ?_⟩ | |
| intro v hv | |
| rw [Walk.support_concat] at hv | |
| rcases List.mem_append.mp hv with hv | hv | |
| · obtain ⟨i, hi, heq⟩ := hp v hv | |
| exact ⟨i, by omega, heq⟩ | |
| · exact ⟨n + 1, le_rfl, List.mem_singleton.mp hv⟩ | |
| end Orbits | |
| structure FullPacking {V : Type} (G : SimpleGraph V) (A B : Finset V) where | |
| target : ↥A → ↥B | |
| route : ∀ a : ↥A, G.Path a.val (target a).val | |
| disjoint : ∀ a b : ↥A, a ≠ b → | |
| Disjoint {v | v ∈ (route a).val.support} {v | v ∈ (route b).val.support} | |
| source_only : ∀ a : ↥A, ∀ v ∈ (route a).val.support, v ∈ A → v = a.val | |
| target_only : ∀ a : ↥A, ∀ v ∈ (route a).val.support, v ∈ B → v = (target a).val | |
| theorem fullPacking_of_successor {V : Type} [Fintype V] [DecidableEq V] | |
| (G : SimpleGraph V) (A B : Finset V) | |
| (f : {v // v ∉ B} → {v // v ∉ A}) (hf : Function.Injective f) | |
| (hstep : ∀ v, v.val = (f v).val ∨ G.Adj v.val (f v).val) : | |
| Nonempty (FullPacking G A B) := by | |
| classical | |
| have hhit : ∀ a : ↥A, ∃ n : ℕ, (next A B f)^[n] a.val ∈ B := | |
| fun a => orbit_hits_target A B f hf a.property | |
| let n : ↥A → ℕ := fun a => Nat.find (hhit a) | |
| have hn : ∀ a : ↥A, (next A B f)^[n a] a.val ∈ B := fun a => Nat.find_spec (hhit a) | |
| have hbefore : ∀ a : ↥A, ∀ i < n a, (next A B f)^[i] a.val ∉ B := by | |
| intro a i hi hb | |
| have hh := Nat.find_min' (hhit a) hb | |
| change n a ≤ i at hh | |
| omega | |
| have hp : ∀ a : ↥A, ∃ p : G.Walk a.val ((next A B f)^[n a] a.val), | |
| ∀ v ∈ p.support, ∃ i ≤ n a, v = (next A B f)^[i] a.val := | |
| fun a => orbit_walk A B f G hf hstep a.property (n a) (hbefore a) | |
| choose p hp using hp | |
| refine ⟨⟨(fun a => ⟨_, hn a⟩), (fun a => (p a).toPath), ?_, ?_, ?_⟩⟩ | |
| · intro a b hab | |
| apply Set.disjoint_left.mpr | |
| intro v hva hvb | |
| obtain ⟨i, hi, hiv⟩ := hp a v ((p a).support_toPath_subset_support hva) | |
| obtain ⟨j, hj, hjv⟩ := hp b v ((p b).support_toPath_subset_support hvb) | |
| have heq : (next A B f)^[i] a.val = (next A B f)^[j] b.val := hiv.symm.trans hjv | |
| have hh := orbit_collision A B f hf a.property b.property i j | |
| (fun l hl => hbefore a l (by omega)) (fun l hl => hbefore b l (by omega)) heq | |
| exact hab (Subtype.ext hh.2) | |
| · intro a v hv hA | |
| obtain ⟨i, hi, hiv⟩ := hp a v ((p a).support_toPath_subset_support hv) | |
| have hh := orbit_collision A B f hf a.property hA i 0 | |
| (fun l hl => hbefore a l (by omega)) (by simp) hiv.symm | |
| exact hh.2.symm | |
| · intro a v hv hB | |
| obtain ⟨i, hi, hiv⟩ := hp a v ((p a).support_toPath_subset_support hv) | |
| have hin : i = n a := by | |
| by_contra hne | |
| exact hbefore a i (by omega) (hiv ▸ hB) | |
| simpa only [hin] using hiv | |
| theorem fullPacking_of_no_small_separator {V : Type} [Fintype V] [DecidableEq V] | |
| (G : SimpleGraph V) (A B : Finset V) | |
| (hconn : ∀ X : Finset V, X.card < A.card → AvoidingConnection G A B X) : | |
| Nonempty (FullPacking G A B) := by | |
| obtain ⟨f, hf, hstep⟩ := successor_of_no_small_separator G A B hconn | |
| exact fullPacking_of_successor G A B f hf hstep | |
| end LinearListHadwiger.PathPacking | |
| end OAI | |