Download data/lean/OAI/Computability/MinUncut/Graphs/GraphOutput.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 10.2 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MinUncut/Graphs/GraphOutput.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/MinUncut/Graphs/GraphOutput.lean
-
curl -L -o GraphOutput.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MinUncut/Graphs/GraphOutput.lean
10.2 kB
| import Mathlib | |
| import OAI.Computability.MinUncut.Graphs.SignedGraph | |
| namespace OAI | |
| noncomputable section | |
| open scoped BigOperators | |
| namespace MinUncut.PathRealization | |
| attribute [local instance] Classical.propDecidable | |
| variable {V D : Type*} [Fintype V] [Fintype D] [DecidableEq V] [DecidableEq D] | |
| variable {N : β} | |
| def output (e : D β Demand V) (number : Vertex V D β Fin N) (k : β) (hk : 1 β€ k) : MinUncut.Output where | |
| vertices := N | |
| adjacent u v := decide ((graph e).Adj (number.symm u) (number.symm v)) | |
| symmetric u v := by simp only [decide_eq_decide]; exact (graph e).adj_comm _ _ | |
| loopless u := by simp | |
| threshold := k | |
| threshold_pos := hk | |
| def edgePair (e : D β Demand V) (number : Vertex V D β Fin N) (p : EdgeIndex e) : Fin N Γ Fin N := | |
| (Sym2.sortEquiv (Sym2.map number (edge e p))).val | |
| omit [Fintype V] [Fintype D] [DecidableEq V] [DecidableEq D] in | |
| lemma edgePair_sym (e : D β Demand V) (number : Vertex V D β Fin N) (p : EdgeIndex e) : | |
| s((edgePair e number p).1,(edgePair e number p).2)=Sym2.map number (edge e p) := | |
| Sym2.sortEquiv.symm_apply_apply _ | |
| omit [Fintype V] [Fintype D] [DecidableEq V] [DecidableEq D] in | |
| lemma edgePair_injective (e : D β Demand V) (number : Vertex V D β Fin N) : | |
| Function.Injective (edgePair e number) := by | |
| intro p q h | |
| apply edge_injective e | |
| apply Sym2.map.injective number.injective | |
| rw [β edgePair_sym,β edgePair_sym,h] | |
| omit [Fintype V] [Fintype D] [DecidableEq V] [DecidableEq D] in | |
| lemma edgePair_lt (e : D β Demand V) (number : Vertex V D β Fin N) (p : EdgeIndex e) : | |
| (edgePair e number p).1 < (edgePair e number p).2 := by | |
| have hl := (Sym2.sortEquiv (Sym2.map number (edge e p))).property | |
| apply lt_of_le_of_ne hl | |
| intro he | |
| have hd : (Sym2.map number (edge e p)).IsDiag := by | |
| rw [β edgePair_sym,Sym2.mk_isDiag_iff] | |
| exact he | |
| exact ends_ne e p ((Sym2.isDiag_map number.injective).mp hd) | |
| omit [Fintype V] in | |
| lemma output_adjacent_iff (e : D β Demand V) (number : Vertex V D β Fin N) (k : β) (hk : 1 β€ k) | |
| (u v : Fin N) : | |
| (output e number k hk).adjacent u v=true β β p : EdgeIndex e, s(u,v)=Sym2.map number (edge e p) := by | |
| simp only [output,decide_eq_true_eq,graph,edgeSet,Finset.mem_image,Finset.mem_univ,true_and] | |
| constructor | |
| Β· rintro β¨p,hpβ© | |
| refine β¨p,?_β© | |
| simpa using (congrArg (Sym2.map number) hp).symm | |
| Β· rintro β¨p,hpβ© | |
| refine β¨p,?_β© | |
| apply Sym2.map.injective number.injective | |
| simpa using hp.symm | |
| omit [Fintype V] in | |
| lemma output_forward_edge_iff (e : D β Demand V) (number : Vertex V D β Fin N) (k : β) (hk : 1 β€ k) | |
| (u v : Fin N) : | |
| (u<v β§ (output e number k hk).adjacent u v=true) β β p : EdgeIndex e, edgePair e number p=(u,v) := by | |
| rw [output_adjacent_iff] | |
| constructor | |
| Β· rintro β¨hu,p,hpβ© | |
| refine β¨p,?_β© | |
| unfold edgePair | |
| rw [β hp] | |
| simp [Sym2.sortEquiv,le_of_lt hu] | |
| Β· rintro β¨p,hpβ© | |
| refine β¨?_,p,?_β© | |
| Β· simpa only [hp] using edgePair_lt e number p | |
| Β· rw [β edgePair_sym,hp] | |
| omit [Fintype V] [Fintype D] [DecidableEq V] [DecidableEq D] in | |
| lemma edgePair_mono (e : D β Demand V) (number : Vertex V D β Fin N) | |
| (s : Fin N β Bool) (p : EdgeIndex e) : | |
| mono (s (edgePair e number p).1) (s (edgePair e number p).2)= | |
| mono (s (number (ends e p.val).1)) (s (number (ends e p.val).2)) := by | |
| have he := edgePair_sym e number p | |
| change s((edgePair e number p).1,(edgePair e number p).2)=s(number (ends e p.val).1,number (ends e p.val).2) at he | |
| rcases Sym2.eq_iff.mp he with h|h | |
| Β· rw [h.1,h.2] | |
| Β· rw [h.1,h.2]; simp only [mono,eq_comm] | |
| omit [Fintype V] in | |
| lemma output_uncut (e : D β Demand V) (number : Vertex V D β Fin N) (k : β) (hk : 1 β€ k) | |
| (s : Fin N β Bool) : | |
| (output e number k hk).uncut s=uncut e (s β number) := by | |
| have he : (Finset.univ.filter fun uv : Fin NΓFin N => | |
| uv.1<uv.2 β§ (output e number k hk).adjacent uv.1 uv.2=true β§ s uv.1=s uv.2)= | |
| (Finset.univ.filter fun p : EdgeIndex e => s (edgePair e number p).1=s (edgePair e number p).2).image (edgePair e number) := by | |
| ext uv | |
| simp only [Finset.mem_filter,Finset.mem_univ,true_and,Finset.mem_image] | |
| constructor | |
| Β· rintro β¨hu,ha,hsβ© | |
| obtain β¨p,hpβ© := (output_forward_edge_iff e number k hk uv.1 uv.2).mp β¨hu,haβ© | |
| exact β¨p,by simpa only [hp] using hs,hpβ© | |
| Β· rintro β¨p,hs,hpβ© | |
| have hh := (output_forward_edge_iff e number k hk uv.1 uv.2).mpr β¨p,hpβ© | |
| exact β¨hh.1,hh.2,by simpa only [hp] using hsβ© | |
| unfold MinUncut.Output.uncut | |
| erw [he,Finset.card_image_of_injective _ (edgePair_injective e number)] | |
| change _=β p : EdgeIndex e, mono (s (number (ends e p.val).1)) (s (number (ends e p.val).2)) | |
| simp_rw [β edgePair_mono] | |
| simp only [mono,Finset.card_filter] | |
| lemma output_opt_le (G : MinUncut.Output) (s : Fin G.vertices β Bool) : G.opt β€ G.uncut s := by | |
| exact Finset.min'_le _ _ (Finset.mem_image.mpr β¨s,Finset.mem_univ _,rflβ©) | |
| lemma le_output_opt (G : MinUncut.Output) (r : β) (h : β s, r β€ G.uncut s) : r β€ G.opt := by | |
| apply Finset.le_min' | |
| intro x hx | |
| obtain β¨s,_,rflβ© := Finset.mem_image.mp hx | |
| exact h s | |
| omit [Fintype V] in | |
| lemma output_yes (e : D β Demand V) (number : Vertex V D β Fin N) (k : β) (hk : 1 β€ k) | |
| (s : V β Bool) (h : totalFailure e s β€ k) : (output e number k hk).opt β€ k := by | |
| apply (output_opt_le _ ((extend e s) β number.symm)).trans | |
| erw [output_uncut] | |
| have he : ((extend e s) β number.symm) β number=extend e s := by ext v; simp | |
| erw [he,uncut_extend] | |
| exact h | |
| omit [Fintype V] in | |
| lemma output_no (e : D β Demand V) (number : Vertex V D β Fin N) (k : β) (hk : 1 β€ k) | |
| (R : β) (h : β s : V β Bool, R<totalFailure e s) : R<(output e number k hk).opt := by | |
| apply lt_of_lt_of_le (Nat.lt_succ_self R) | |
| apply le_output_opt | |
| intro s | |
| erw [output_uncut] | |
| exact (h (fun v => s (number (.inl v)))).trans_le (uncut_lower e (s β number)) | |
| end MinUncut.PathRealization | |
| open scoped BigOperators | |
| namespace MinUncut.FiniteProof | |
| open PathRealization | |
| variable {E V : Type*} [Fintype E] | |
| def multiplicity (D : β) (w : β) : β := w.num.toNat*(D/w.den) | |
| lemma multiplicity_cast {D : β} {w : β} (hw : 0β€w) (hD : w.den β£ D) : | |
| (multiplicity D w:β)=(D:β)*w := by | |
| have hn : 0β€w.num := Rat.num_nonneg.mpr hw | |
| have hncast : (w.num.toNat:β)=(w.num:β) := by exact_mod_cast Int.toNat_of_nonneg hn | |
| calc | |
| (multiplicity D w:β)=(w.num:β)*((D:β)/(w.den:β)) := by | |
| unfold multiplicity | |
| rw [Nat.cast_mul,Nat.cast_div_charZero hD,hncast] | |
| _ = (D:β)*((w.num:β)/(w.den:β)) := by ring | |
| _ = (D:β)*w := by rw [Rat.num_div_den] | |
| abbrev UnitDemand (D : β) (w : E β β) := Ξ£ e, Fin (multiplicity D (w e)) | |
| def expanded (D : β) (w : E β β) (d : E β Demand V) : UnitDemand D w β Demand V := | |
| fun p => d p.1 | |
| lemma expanded_failure (D : β) (w : E β β) (d : E β Demand V) (y : V β Bool) : | |
| totalFailure (expanded D w d) y = β e, multiplicity D (w e)*failure (d e) y := by | |
| simp [totalFailure,expanded,Fintype.sum_sigma] | |
| lemma expanded_weight (D : β) (w : E β β) (hw : β e, 0β€w e) (hD : β e, (w e).den β£ D) | |
| (d : E β Demand V) (y : V β Bool) : | |
| (totalFailure (expanded D w d) y:β)=(D:β)*β e, (w e:β)*(failure (d e) y:β) := by | |
| rw [expanded_failure] | |
| push_cast | |
| rw [Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro e _ | |
| have h : (multiplicity D (w e):β)=(D:β)*(w e:β) := by | |
| exact_mod_cast multiplicity_cast (hw e) (hD e) | |
| rw [h,mul_assoc] | |
| lemma expanded_card (D : β) (w : E β β) : | |
| Fintype.card (UnitDemand D w)=β e, multiplicity D (w e) := by | |
| simp [Fintype.card_sigma] | |
| lemma expanded_card_cast (D : β) (w : E β β) (hw : β e, 0β€w e) (hD : β e, (w e).den β£ D) : | |
| (Fintype.card (UnitDemand D w):β)=(D:β)*β e, w e := by | |
| rw [expanded_card,Nat.cast_sum,Finset.mul_sum] | |
| exact Finset.sum_congr rfl (fun e _ => multiplicity_cast (hw e) (hD e)) | |
| open scoped BigOperators | |
| open PathRealization | |
| attribute [local instance] Classical.propDecidable | |
| variable {E V : Type*} [Fintype E] [Fintype V] [DecidableEq V] | |
| lemma threshold_positive {D : β} (hD : 0<D) : 1β€5*D := by omega | |
| def rationalGraph (D : β) (hD : 0<D) (w : E β β) (d : E β Demand V) : MinUncut.Output := | |
| output (expanded D w d) (Fintype.equivFin _) (5*D) (threshold_positive hD) | |
| lemma rationalGraph_threshold (D : β) (hD : 0<D) (w : E β β) (d : E β Demand V) : | |
| (rationalGraph D hD w d).threshold=5*D := rfl | |
| lemma rationalGraph_vertices (D : β) (hD : 0<D) (w : E β β) (d : E β Demand V) : | |
| (rationalGraph D hD w d).vertices=Fintype.card V+3*β e, multiplicity D (w e) := by | |
| simp [rationalGraph,output,Vertex,Fintype.card_sum,Fintype.card_prod,mul_comm] | |
| lemma rationalGraph_yes (D : β) (hD : 0<D) (w : E β β) (hw : β e, 0β€w e) | |
| (hden : β e, (w e).den β£ D) (d : E β Demand V) (y : V β Bool) | |
| (hc : (β e, (w e:β)*(failure (d e) y:β))β€9/2) : | |
| (rationalGraph D hD w d).optβ€(rationalGraph D hD w d).threshold := by | |
| apply output_yes | |
| have he := expanded_weight D w hw hden d y | |
| have hD' : (0:β)<D := by exact_mod_cast hD | |
| have hh := mul_le_mul_of_nonneg_left hc hD'.le | |
| have hz : (totalFailure (expanded D w d) y:β)β€5*D := by rw [he]; nlinarith | |
| exact_mod_cast hz | |
| lemma rationalGraph_no {K : β} (hK : 2β€K) (D : β) (hD : 0<D) (w : E β β) | |
| (hw : β e, 0β€w e) (hden : β e, (w e).den β£ D) (d : E β Demand V) | |
| (hc : β y, 8*(K:β)-1/2 < β e, (w e:β)*(failure (d e) y:β)) : | |
| K*(rationalGraph D hD w d).threshold < (rationalGraph D hD w d).opt := by | |
| apply output_no | |
| intro y | |
| have he := expanded_weight D w hw hden d y | |
| have hK' : (2:β)β€K := by exact_mod_cast hK | |
| have hg : 5*(K:β) < β e, (w e:β)*(failure (d e) y:β) := lt_trans (by linarith) (hc y) | |
| have hD' : (0:β)<D := by exact_mod_cast hD | |
| have hh := mul_lt_mul_of_pos_left hg hD' | |
| have hz : (K:β)*(5*D) < (totalFailure (expanded D w d) y:β) := by rw [he]; nlinarith | |
| exact_mod_cast hz | |
| end MinUncut.FiniteProof | |
| end | |
| end OAI | |