Download data/lean/OAI/Computability/MinUncut/Graphs/SignedGraph.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 7.63 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MinUncut/Graphs/SignedGraph.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/MinUncut/Graphs/SignedGraph.lean
-
curl -L -o SignedGraph.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MinUncut/Graphs/SignedGraph.lean
7.63 kB
| import Mathlib | |
| import OAI.Computability.MinUncut.Model | |
| namespace OAI | |
| noncomputable section | |
| open scoped BigOperators | |
| namespace MinUncut.PathRealization | |
| attribute [local instance] Classical.propDecidable | |
| structure Demand (V : Type*) where | |
| left : V | |
| right : V | |
| equal : Bool | |
| variable {V D : Type*} | |
| abbrev Vertex (V D : Type*) := V β (D Γ Fin 3) | |
| def failure (e : Demand V) (s : V β Bool) : β := | |
| if (s e.left == s e.right) = e.equal then 0 else 1 | |
| def mono (x y : Bool) : β := if x=y then 1 else 0 | |
| def localCost (equal x y a b c : Bool) : β := | |
| mono x a + mono a b + if equal then mono b c+mono c y else mono b y | |
| lemma local_lower (equal x y a b c : Bool) : | |
| (if (x==y) = equal then 0 else 1) β€ localCost equal x y a b c := by | |
| cases equal <;> cases x <;> cases y <;> cases a <;> cases b <;> cases c <;> | |
| decide | |
| lemma local_extension (equal x y : Bool) : | |
| localCost equal x y (!x) x (!x) = (if (x==y)=equal then 0 else 1) := by | |
| cases equal <;> cases x <;> cases y <;> decide | |
| abbrev EdgeIndex (e : D β Demand V) := {p : DΓFin 4 // p.2.val < if (e p.1).equal then 4 else 3} | |
| def ends (e : D β Demand V) (p : DΓFin 4) : Vertex V D Γ Vertex V D := | |
| match p.2.val with | |
| | 0 => (.inl (e p.1).left,.inr (p.1,0)) | |
| | 1 => (.inr (p.1,0),.inr (p.1,1)) | |
| | 2 => if (e p.1).equal then (.inr (p.1,1),.inr (p.1,2)) | |
| else (.inr (p.1,1),.inl (e p.1).right) | |
| | _ => (.inr (p.1,2),.inl (e p.1).right) | |
| def edge (e : D β Demand V) (p : EdgeIndex e) : Sym2 (Vertex V D) := | |
| s((ends e p.val).1,(ends e p.val).2) | |
| lemma ends_ne (e : D β Demand V) (p : EdgeIndex e) : | |
| (ends e p.val).1 β (ends e p.val).2 := by | |
| obtain β¨β¨d,iβ©,hiβ© := p | |
| fin_cases i <;> simp only [ends] <;> (try split_ifs) <;> simp | |
| lemma edge_injective (e : D β Demand V) : Function.Injective (edge e) := by | |
| intro p q he | |
| obtain β¨β¨d,iβ©,hiβ© := p | |
| obtain β¨β¨f,jβ©,hjβ© := q | |
| apply Subtype.ext | |
| fin_cases i <;> fin_cases j <;> | |
| simp only [edge,ends] at he <;> (try split_ifs at he) <;> | |
| simp_all | |
| variable [Fintype V] [Fintype D] [DecidableEq V] [DecidableEq D] | |
| def edgeSet (e : D β Demand V) : Finset (Sym2 (Vertex V D)) := | |
| Finset.univ.image (edge e) | |
| omit [Fintype V] in | |
| lemma edgeSet_nondiag (e : D β Demand V) (z : Sym2 (Vertex V D)) (hz : z β edgeSet e) : | |
| Β¬ z.IsDiag := by | |
| obtain β¨p,_,rflβ© := Finset.mem_image.mp hz | |
| simpa only [edge,Sym2.mk_isDiag_iff] using ends_ne e p | |
| def graph (e : D β Demand V) : SimpleGraph (Vertex V D) where | |
| Adj x y := s(x,y) β edgeSet e | |
| symm := β¨by intro x y h; simpa only [Sym2.eq_swap] using hβ© | |
| loopless := β¨by intro x hx; exact edgeSet_nondiag e s(x,x) hx (by simp)β© | |
| instance (e : D β Demand V) : DecidableRel (graph e).Adj := Classical.decRel _ | |
| lemma graph_edgeFinset (e : D β Demand V) : (graph e).edgeFinset=edgeSet e := by | |
| ext z | |
| induction z using Sym2.inductionOn with | |
| | _ x y => | |
| simp only [SimpleGraph.edgeFinset, Set.mem_toFinset] | |
| rfl | |
| def uncut (e : D β Demand V) (s : Vertex V D β Bool) : β := | |
| β p : EdgeIndex e, mono (s (ends e p.val).1) (s (ends e p.val).2) | |
| def totalFailure (e : D β Demand V) (s : V β Bool) : β := β d, failure (e d) s | |
| def extend (e : D β Demand V) (s : V β Bool) : Vertex V D β Bool | |
| | .inl v => s v | |
| | .inr (d,i) => if i.val=1 then s (e d).left else !(s (e d).left) | |
| omit [Fintype V] [DecidableEq V] [DecidableEq D] in | |
| lemma uncut_locals (e : D β Demand V) (s : Vertex V D β Bool) : | |
| uncut e s = β d, localCost (e d).equal (s (.inl (e d).left)) (s (.inl (e d).right)) | |
| (s (.inr (d,0))) (s (.inr (d,1))) (s (.inr (d,2))) := by | |
| unfold uncut | |
| rw [β Finset.sum_subtype (Finset.univ.filter (fun p : DΓFin 4 => p.2.val < if (e p.1).equal then 4 else 3)) (by simp) (fun p : DΓFin 4 => mono (s (ends e p).1) (s (ends e p).2))] | |
| rw [Finset.sum_filter] | |
| simp only [Fintype.sum_prod_type] | |
| apply Finset.sum_congr rfl | |
| intro d _ | |
| rw [Fin.sum_univ_four] | |
| cases h : (e d).equal <;> simp [h,ends,localCost,add_assoc] | |
| omit [Fintype V] [DecidableEq V] [DecidableEq D] in | |
| lemma uncut_lower (e : D β Demand V) (s : Vertex V D β Bool) : | |
| totalFailure e (fun v => s (.inl v)) β€ uncut e s := by | |
| rw [uncut_locals] | |
| exact Finset.sum_le_sum (fun d _ => local_lower _ _ _ _ _ _) | |
| omit [Fintype V] [DecidableEq V] [DecidableEq D] in | |
| lemma uncut_extend (e : D β Demand V) (s : V β Bool) : uncut e (extend e s)=totalFailure e s := by | |
| rw [uncut_locals] | |
| apply Finset.sum_congr rfl | |
| intro d _ | |
| simpa [extend,failure] using | |
| local_extension (e d).equal (s (e d).left) (s (e d).right) | |
| end MinUncut.PathRealization | |
| end | |
| namespace MinUncut.FiniteProof | |
| def orient (b x : Bool) : Bool := if b then x else !x | |
| def rep {A : Type*} (a : A) (P : A β Bool) : {R : A β Bool // R a=true} := | |
| β¨fun x => P a == P x, by simpβ© | |
| lemma rep_not {A : Type*} (a : A) (P : A β Bool) : | |
| rep a (fun x => !(P x))=rep a P := by | |
| apply Subtype.ext | |
| funext x | |
| simp [rep] | |
| lemma rep_restore {A : Type*} (a : A) (P : A β Bool) : | |
| (fun x => orient (P a) ((rep a P).val x))=P := by | |
| funext x | |
| cases h : P a <;> cases hx : P x <;> simp [orient,rep,h,hx] | |
| lemma rep_fixed {A : Type*} (a : A) (R : {R : A β Bool // R a=true}) : | |
| rep a R.val=R := by | |
| apply Subtype.ext | |
| funext x | |
| simp [rep,R.property] | |
| variable {Q : Type*} {A : Q β Type*} (base : β q, A q) | |
| abbrev Query := Ξ£ q, A q β Bool | |
| abbrev Variable := Ξ£ q, {R : A q β Bool // R (base q)=true} | |
| def vertex (p : Query (A := A)) : Variable base := β¨p.1,rep (base p.1) p.2β© | |
| def answer (y : Variable base β Bool) (q : Q) (P : A q β Bool) : Bool := | |
| orient (P (base q)) (y (vertex base β¨q,Pβ©)) | |
| def Folded (f : β q, (A q β Bool) β Bool) : Prop := | |
| β q P, f q (fun x => !(P x))= !(f q P) | |
| lemma answer_folded (y : Variable base β Bool) : Folded (answer base y) := by | |
| intro q P | |
| simp only [answer,vertex,rep_not] | |
| cases h : P (base q) <;> simp [orient] | |
| lemma answer_rep (y : Variable base β Bool) (q : Q) | |
| (R : {R : A q β Bool // R (base q)=true}) : answer base y q R.val=y β¨q,Rβ© := by | |
| simp [answer,vertex,R.property,rep_fixed,orient] | |
| lemma answer_of_folded (f : β q, (A q β Bool) β Bool) (hf : Folded f) : | |
| answer base (fun p => f p.1 p.2.val)=f := by | |
| funext q P | |
| unfold answer vertex | |
| cases h : P (base q) | |
| Β· have hr : (rep (base q) P).val=(fun x => !(P x)) := by | |
| funext x | |
| simp [rep,h] | |
| simp only [hr,orient,Bool.false_eq_true,ite_false,hf q P,Bool.not_not] | |
| Β· have hr : (rep (base q) P).val=P := by | |
| funext x | |
| simp [rep,h] | |
| simp [hr,orient] | |
| structure QueryDemand where | |
| left : Query (A := A) | |
| right : Query (A := A) | |
| equal : Bool | |
| def QueryDemand.signed (d : QueryDemand (A := A)) : PathRealization.Demand (Variable base) where | |
| left := vertex base d.left | |
| right := vertex base d.right | |
| equal := if d.equal then (d.left.2 (base d.left.1)==d.right.2 (base d.right.1)) | |
| else !(d.left.2 (base d.left.1)==d.right.2 (base d.right.1)) | |
| def QueryDemand.failure (d : QueryDemand (A := A)) | |
| (f : β q, (A q β Bool) β Bool) : β := | |
| if (f d.left.1 d.left.2 == f d.right.1 d.right.2)=d.equal then 0 else 1 | |
| lemma QueryDemand.failure_signed (d : QueryDemand (A := A)) (y : Variable base β Bool) : | |
| PathRealization.failure (d.signed base) y=d.failure (answer base y) := by | |
| unfold PathRealization.failure QueryDemand.signed QueryDemand.failure answer | |
| cases d.equal <;> cases d.left.2 (base d.left.1) <;> cases d.right.2 (base d.right.1) <;> | |
| cases y (vertex base d.left) <;> cases y (vertex base d.right) <;> rfl | |
| end MinUncut.FiniteProof | |
| end OAI | |