Download data/lean/OAI/Combinatorics/CycleDecomposition/Representatives.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 11.8 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/CycleDecomposition/Representatives.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/CycleDecomposition/Representatives.lean
-
curl -L -o Representatives.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/CycleDecomposition/Representatives.lean
11.8 kB
| import OAI.Combinatorics.CycleDecomposition.EdgeSplitting | |
| namespace OAI | |
| universe cycleUniverse1 cycleUniverse2 | |
| section | |
| open Filter Asymptotics Real | |
| open scoped Topology | |
| noncomputable section | |
| open MeasureTheory ProbabilityTheory Finset | |
| noncomputable section | |
| namespace ErdosGallai.Representatives | |
| noncomputable section | |
| open Finset | |
| variable {I : Type cycleUniverse1} {V : Type cycleUniverse2} [DecidableEq I] [DecidableEq V] [Nonempty V] | |
| lemma choose_with_mates (A : Finset I) (mate : I β I) | |
| (hmate : Function.Involutive mate) (hfix : β i, mate i β i) | |
| (N : I β Finset V) (k : β) | |
| (hroom : β i β A, A.card β€ ((N i).card - 1) * k) : | |
| β f : I β V, (β i β A, f i β N i) β§ | |
| (β i β A, mate i β A β f i β f (mate i)) β§ | |
| (β v, (A.filter (fun i => f i = v)).card β€ k) := by | |
| induction A using Finset.induction_on with | |
| | empty => exact β¨fun _ => Classical.choice inferInstance, by simpβ© | |
| | @insert i A hi ih => | |
| obtain β¨f,hf,hsep,hcapβ© := ih (by | |
| intro j hj | |
| exact (Finset.card_le_card (Finset.subset_insert i A)).trans (hroom j (by simp [hj]))) | |
| have hlt : A.card < ((N i).erase (f (mate i))).card * k := by | |
| have h := hroom i (by simp) | |
| have hcard := Finset.pred_card_le_card_erase (s := N i) (a := f (mate i)) | |
| have hmul := Nat.mul_le_mul_right k hcard | |
| rw [Finset.card_insert_of_notMem hi] at h | |
| omega | |
| obtain β¨v,hv,hloadβ© := Finset.exists_card_fiber_lt_of_card_lt_mul (f := f) hlt | |
| have hvN := (Finset.mem_erase.mp hv).2 | |
| have hvne := (Finset.mem_erase.mp hv).1 | |
| let g := Function.update f i v | |
| have gi : g i = v := by simp [g] | |
| have gold : β j, j β i β g j = f j := by | |
| intro j hj | |
| simp [g, hj] | |
| refine β¨g, ?_, ?_, ?_β© | |
| Β· intro j hj | |
| rcases Finset.mem_insert.mp hj with rfl | hj | |
| Β· simpa only [gi] using hvN | |
| Β· rw [gold j (ne_of_mem_of_not_mem hj hi)] | |
| exact hf j hj | |
| Β· intro j hj hmj | |
| by_cases hji : j = i | |
| Β· subst j | |
| rw [gi, gold (mate i) (hfix i)] | |
| exact hvne | |
| Β· rw [gold j hji] | |
| by_cases hmi : mate j = i | |
| Β· rw [hmi, gi] | |
| have hjm : j = mate i := by rw [β hmi, hmate] | |
| simpa [hjm] using hvne.symm | |
| Β· rw [gold (mate j) hmi] | |
| exact hsep j (Finset.mem_of_mem_insert_of_ne hj hji) | |
| (Finset.mem_of_mem_insert_of_ne hmj hmi) | |
| Β· intro w | |
| have hold : A.filter (fun j => g j = w) = A.filter (fun j => f j = w) := by | |
| apply Finset.filter_congr | |
| intro j hj | |
| rw [gold j (ne_of_mem_of_not_mem hj hi)] | |
| rw [Finset.filter_insert, hold] | |
| by_cases hvw : v = w | |
| Β· simp only [gi, hvw, ite_eq_left] | |
| rw [Finset.card_insert_of_notMem (fun h => hi (Finset.mem_filter.mp h).1)] | |
| simpa only [hvw] using Nat.succ_le_of_lt hload | |
| Β· simp only [gi, hvw, ite_false] | |
| exact hcap w | |
| theorem two_distinct_representatives (S : Finset I) (N : I β Finset V) (k : β) | |
| (hroom : β i β S, 2*S.card β€ ((N i).card-1)*k) : | |
| β f : I Γ Fin 2 β V, | |
| (β i β S, β t, f (i,t) β N i) β§ | |
| (β i β S, f (i,0) β f (i,1)) β§ | |
| (β v, ((S ΓΛ’ Finset.univ).filter (fun i => f i = v)).card β€ k) := by | |
| let mate : I Γ Fin 2 β I Γ Fin 2 := fun i => (i.1, 1-i.2) | |
| have hm : Function.Involutive mate := by | |
| rintro β¨i,tβ© | |
| fin_cases t <;> rfl | |
| have hfix : β i, mate i β i := by | |
| rintro β¨i,tβ© | |
| fin_cases t <;> (intro h; have hh := congrArg Prod.snd h; norm_num [mate] at hh) | |
| obtain β¨f,hf,hsep,hcapβ© := choose_with_mates (S ΓΛ’ Finset.univ) mate hm hfix | |
| (fun i => N i.1) k (by | |
| intro i hi | |
| simpa [Finset.card_product, mul_comm] using hroom i.1 (Finset.mem_product.mp hi).1) | |
| refine β¨f, ?_, ?_, hcapβ© | |
| Β· intro i hi t | |
| exact hf (i,t) (by simp [hi]) | |
| Β· intro i hi | |
| exact hsep (i,0) (by simp [hi]) (by simp [mate, hi]) | |
| theorem reservoir_representatives (S : Finset I) (N : I β Finset V) | |
| (r d : β) (hr : (S.card : β) β€ r) (hd : 4 β€ d) | |
| (hN : β i β S, d/2 β€ ((N i).card : β)) : | |
| β f : I Γ Fin 2 β V, | |
| (β i β S, β t, f (i,t) β N i) β§ | |
| (β i β S, f (i,0) β f (i,1)) β§ | |
| (β v, ((S ΓΛ’ Finset.univ).filter (fun i => f i = v)).card β€ β8*r/dββ) := by | |
| apply two_distinct_representatives | |
| intro i hi | |
| have hd0 : 0 < d := by linarith | |
| have hr0 : 0 β€ r := le_trans (Nat.cast_nonneg _) hr | |
| have hNi := hN i hi | |
| have hNi1 : 1 β€ (N i).card := by exact_mod_cast (by linarith : (1 : β) β€ (N i).card) | |
| have hn : d/4 β€ (((N i).card - 1 : β) : β) := by | |
| rw [Nat.cast_sub hNi1] | |
| push_cast | |
| linarith | |
| have hk : 8*r/d β€ (β8*r/dββ : β) := Nat.le_ceil _ | |
| have hk0 : 0 β€ (β8*r/dββ : β) := Nat.cast_nonneg _ | |
| have hprod : 2*(S.card : β) β€ (((N i).card - 1 : β) : β)*(β8*r/dββ : β) := by | |
| calc | |
| _ β€ 2*r := by linarith | |
| _ = (d/4)*(8*r/d) := by field_simp; ring | |
| _ β€ (d/4)*(β8*r/dββ : β) := mul_le_mul_of_nonneg_left hk (by positivity) | |
| _ β€ _ := mul_le_mul_of_nonneg_right hn hk0 | |
| exact_mod_cast hprod | |
| end | |
| end ErdosGallai.Representatives | |
| namespace ErdosGallai | |
| noncomputable section | |
| open Finset Real Filter | |
| attribute [local instance] Classical.propDecidable | |
| noncomputable def reservoirProbability (Ξ· : β) : β := min (Ξ·/12) (1/12) | |
| noncomputable def reservoirExpansionCoefficient (c : β) : β := min c 1 / 6 | |
| universe u | |
| theorem reservoir_preparation (c Ξ· : β) (hc : 0 < c) (hΞ· : 0 < Ξ·) : | |
| β Dβ : β, β D : β, Dβ β€ D β β (V : Type u) [Fintype V] [DecidableEq V] | |
| (G P : SimpleGraph V) [DecidableRel P.Adj], P β€ G β | |
| D^(9/10 : β) β€ (Fintype.card V : β) β | |
| (Fintype.card V : β) β€ D^(51/50 : β) β | |
| Splitting.CutExpansion P (c*D^(9/10 : β)) β | |
| β (Ο : Sym2 V β Fin 3) (W : Fin 3 β Finset V) (f : Fin 3 β V Γ Fin 2 β V), | |
| (β i, Splitting.colorGraph P Ο i β€ G) β§ | |
| (β i j, i β j β Disjoint (Splitting.colorGraph P Ο i).edgeSet | |
| (Splitting.colorGraph P Ο j).edgeSet) β§ | |
| (β i, Splitting.CutExpansion (Splitting.colorGraph P Ο i) | |
| (reservoirExpansionCoefficient c * D^(9/10 : β))) β§ | |
| (β i j, i β j β Disjoint (W i) (W j)) β§ | |
| (β i, 2 β€ (W i).card) β§ | |
| (β i, ((W i).card : β) β€ 2*reservoirProbability Ξ·*Fintype.card V) β§ | |
| (β i, (W i).card < Fintype.card V) β§ | |
| ((β i, (W i).card : β) : β) β€ Ξ· * Fintype.card V β§ | |
| (β i, Sampling.CutExpansionOn (Splitting.colorGraph P Ο i) (W i) | |
| (D^(37/50 : β))) β§ | |
| (β i v, v β W i β β t, f i (v,t) β W i β§ | |
| (Splitting.colorGraph P Ο i).Adj v (f i (v,t))) β§ | |
| (β i v, v β W i β f i (v,0) β f i (v,1)) β§ | |
| (β i w, (((W i)αΆ ΓΛ’ Finset.univ).filter (fun x => f i x = w)).card β€ | |
| β8*(Fintype.card V : β) / | |
| (reservoirProbability Ξ· * (reservoirExpansionCoefficient c * D^(9/10 : β)))ββ) := by | |
| let cβ := min c 1 | |
| let a := reservoirExpansionCoefficient c | |
| let q := reservoirProbability Ξ· | |
| have hcβ : 0 < cβ := lt_min hc (by norm_num) | |
| have ha : 0 < a := by dsimp [a, reservoirExpansionCoefficient]; positivity | |
| have hq : 0 < q := by dsimp [q, reservoirProbability]; positivity | |
| have hq12 : q β€ 1/12 := min_le_right _ _ | |
| have hqΞ· : q β€ Ξ·/12 := min_le_left _ _ | |
| have hq3 : 3*q β€ 1 := by linarith | |
| have hq6 : 6*q β€ Ξ· := by linarith | |
| have hq2 : 2*q < 1 := by linarith | |
| let p : unitInterval := β¨q, hq.le, by linarithβ© | |
| obtain β¨Dβ,hDββ© := Splitting.edge_splitting_uniform.{u} cβ hcβ 3 (by norm_num) | |
| obtain β¨Dβ,hDββ© := Sampling.three_reservoirs_uniform.{u} a ha p hq hq3 | |
| have ht : βαΆ D : β in atTop, 4/(q*a) β€ D^(9/10 : β) := | |
| (tendsto_rpow_atTop (by norm_num : (0 : β) < 9/10)).eventually | |
| (eventually_ge_atTop _) | |
| obtain β¨Dβ,hDββ© := ht.exists_forall_of_atTop | |
| refine β¨max 1 (max Dβ (max Dβ Dβ)), ?_β© | |
| intro D hD V _ _ G P _ hPG hlo hhi hexp | |
| have hD1 : 1 β€ D := (le_max_left _ _).trans hD | |
| have hDsplit : Dβ β€ D := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hD | |
| have hDsample : Dβ β€ D := | |
| (le_trans (le_max_left _ _) (le_trans (le_max_right _ _) (le_max_right _ _))).trans hD | |
| have hDpower : Dβ β€ D := | |
| (le_trans (le_max_right _ _) (le_trans (le_max_right _ _) (le_max_right _ _))).trans hD | |
| have hpow : 0 < D^(9/10 : β) := Real.rpow_pos_of_pos (by linarith) _ | |
| have hd : 4 β€ q*(a*D^(9/10 : β)) := by | |
| have hh := (div_le_iffβ (mul_pos hq ha)).mp (hDβ D hDpower) | |
| nlinarith | |
| have hr : 0 < (Fintype.card V : β) := hpow.trans_le hlo | |
| have : Nonempty V := Fintype.card_pos_iff.mp (by exact_mod_cast hr) | |
| have hexpβ : Splitting.CutExpansion P (cβ*D^(9/10 : β)) := by | |
| intro U | |
| exact (mul_le_mul_of_nonneg_right | |
| (mul_le_mul_of_nonneg_right (min_le_left c 1) hpow.le) | |
| (le_min (Nat.cast_nonneg _) (Nat.cast_nonneg _))).trans (hexp U) | |
| obtain β¨Ο,hcut,hcover,hdisjβ© := hDβ D hDsplit V P | |
| (cβ*D^(9/10 : β)) le_rfl hlo hhi hexpβ | |
| have hcut' : β i, Sampling.CutExpansion (Splitting.colorGraph P Ο i) | |
| (a*D^(9/10 : β)) := by | |
| intro i | |
| have heq : a*D^(9/10 : β) = cβ*D^(9/10 : β)/(2*(3 : β)) := by | |
| dsimp [a, reservoirExpansionCoefficient, cβ] | |
| ring | |
| rw [heq] | |
| exact hcut i | |
| obtain β¨W,hWdisj,hWsize,hWneigh,hWcutβ© := hDβ D hDsample V | |
| (fun i => Splitting.colorGraph P Ο i) hlo hhi hcut' | |
| have hWtwo : β i, 2 β€ (W i).card := by | |
| intro i | |
| let v : V := Classical.choice inferInstance | |
| have hn := hWneigh i v | |
| have hsub : Sampling.neighborsIn (Splitting.colorGraph P Ο i) v (W i) β W i := | |
| Finset.filter_subset _ _ | |
| have hh := Finset.card_le_card hsub | |
| have hn' : (2 : β) β€ (Sampling.neighborsIn (Splitting.colorGraph P Ο i) v (W i)).card := by | |
| change q*(a*D^(9/10 : β))/2 β€ _ at hn | |
| linarith | |
| have hn'' : 2 β€ (Sampling.neighborsIn (Splitting.colorGraph P Ο i) v (W i)).card := by | |
| exact_mod_cast hn' | |
| omega | |
| have hWlt : β i, (W i).card < Fintype.card V := by | |
| intro i | |
| have hh := (hWsize i).trans_lt (mul_lt_of_lt_one_left hr hq2) | |
| exact_mod_cast hh | |
| have hWsum : ((β i, (W i).card : β) : β) β€ Ξ· * Fintype.card V := by | |
| have hh := Finset.sum_le_sum (fun i (_ : i β (Finset.univ : Finset (Fin 3))) => hWsize i) | |
| simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] at hh | |
| rw [Nat.cast_sum] | |
| exact hh.trans (by dsimp [p]; nlinarith [mul_le_mul_of_nonneg_right hq6 hr.le]) | |
| have hrep : β i, β f : V Γ Fin 2 β V, | |
| (β v β (W i)αΆ, β t, f (v,t) β Sampling.neighborsIn (Splitting.colorGraph P Ο i) v (W i)) β§ | |
| (β v β (W i)αΆ, f (v,0) β f (v,1)) β§ | |
| (β w, (((W i)αΆ ΓΛ’ Finset.univ).filter (fun x => f x = w)).card β€ | |
| β8*(Fintype.card V : β)/(q*(a*D^(9/10 : β)))ββ) := by | |
| intro i | |
| exact Representatives.reservoir_representatives (W i)αΆ | |
| (fun v => Sampling.neighborsIn (Splitting.colorGraph P Ο i) v (W i)) | |
| (Fintype.card V) (q*(a*D^(9/10 : β))) | |
| (by exact_mod_cast (Finset.card_le_univ ((W i)αΆ))) hd | |
| (fun v _ => hWneigh i v) | |
| choose f hf hsep hcap using hrep | |
| refine β¨Ο,W,f,?_,hdisj,?_,hWdisj,hWtwo,hWsize,hWlt,hWsum,hWcut,?_,?_,hcapβ© | |
| Β· intro i x y hxy | |
| exact hPG hxy.1 | |
| Β· exact hcut' | |
| Β· intro i v hv t | |
| exact Finset.mem_filter.mp (hf i v (Finset.mem_compl.mpr hv) t) | |
| Β· intro i v hv | |
| exact hsep i v (Finset.mem_compl.mpr hv) | |
| end | |
| end ErdosGallai | |
| end | |
| end | |
| end | |
| end OAI | |