Download data/lean/OAI/Combinatorics/MatchingCount/Algorithm/Guard.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 14.3 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/MatchingCount/Algorithm/Guard.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/MatchingCount/Algorithm/Guard.lean
-
curl -L -o Guard.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/MatchingCount/Algorithm/Guard.lean
14.3 kB
| import Mathlib | |
| import OAI.Combinatorics.MatchingCount.Algorithm.OutputLengthBound | |
| namespace OAI | |
| namespace MatchingFPRAS.WeightedOptions | |
| open Finset FiniteChoice | |
| lemma draw_law_pos {Ξ© : Type*} [Fintype Ξ©] [DecidableEq Ξ©] | |
| (c : WeightedOptions Ξ©) (k : β) (bits : Fin k β Bool) : | |
| 0 < c.law (c.draw k bits) := by | |
| let i := chooseBits c.mass c.total k bits | |
| have hi : 0 < c.mass i := chooseBits_pos c.mass c.total k bits | |
| apply hi.trans_le | |
| unfold law | |
| calc | |
| c.mass i = (if c.out i = c.draw k bits then c.mass i else 0) := by simp [draw, i] | |
| _ β€ β j, if c.out j = c.draw k bits then c.mass j else 0 := | |
| single_le_sum (f := fun j => if c.out j = c.draw k bits then c.mass j else 0) | |
| (fun j _ => by split_ifs <;> [exact c.nonneg j; exact le_rfl]) (mem_univ i) | |
| end MatchingFPRAS.WeightedOptions | |
| namespace MatchingFPRAS.Enlargement | |
| open Finset Switching Subdivision RealGeometry MatchingFPRAS.Representation | |
| theorem intact_partition_identity_even {V : Type*} [Fintype V] [LinearOrder V] | |
| (he : Even (Fintype.card V)) (w : V β V β β) | |
| (p : β) (B Hu Hv : LogicalEdge V β β) : | |
| realHolePartition source target (4*p) β (fun _ => β ) | |
| (pathActivity p B Hu Hv (logicalActivity w)) = | |
| (β e, pathConstant p (B e) (Hu e) (Hv e)) * partition w β := by | |
| classical | |
| have hz := StageAnalysis.partition_pos_of_even (fun _ _ : V => (1:β)) (by intros; norm_num) β | |
| (by simpa using he) | |
| have hn : (matchings (β : Finset V)).Nonempty := by | |
| by_contra hn | |
| have hz0 : partition (fun _ _ : V => (1:β)) β = 0 := by | |
| simp [partition, Finset.not_nonempty_iff_eq_empty.mp hn] | |
| linarith | |
| obtain β¨m, hmβ© := hn | |
| let b := fun (e : LogicalEdge V) (i : Fin (4*p+1)) => alternating (select m e) i.val | |
| have hb := intact_family p m ((mem_matchings m β ).mp hm) | |
| have hid := deletion_partition_identity (show Even (4*p) from β¨2*p,by omegaβ©) | |
| source target β (fun _ => β ) b hb (pathActivity p B Hu Hv (logicalActivity w)) | |
| (fun e => List.ofFn fun r : Fin p => max (B e) (Hu e/2^r.val)) | |
| (fun e => (List.ofFn fun r : Fin p => max (B e) (Hv e/2^r.val)).reverse) _ | |
| (fun e => profileActivity_ofFn p (B e) (Hu e) (Hv e) (logicalActivity w e)) | |
| simpa [residualHoles, broken, deletionConstant, List.prod_ofFn, pathConstant, | |
| logical_partition_eq] using hid | |
| open Transport | |
| open scoped Classical | |
| variable {V : Type*} [Fintype V] [LinearOrder V] [Nontrivial V] | |
| noncomputable local instance (w : V β V β β) (K : β) : DecidableEq (SourceLabel w K) := Classical.decEq _ | |
| noncomputable local instance (w : V β V β β) (K : β) : Fintype (BagEdge (sourceBags w K)) := Fintype.ofFinite _ | |
| theorem frozenPortion_full_even (he : Even (Fintype.card V)) | |
| (w wβ : V β V β β) (K : β) : | |
| Transport.partitionWeight BagEdge.Incident (frozenPortion w wβ K) Finset.univ = | |
| sourceC w K * Switching.partition wβ β := by | |
| rw [βsurvivors_empty (V:=V) K, frozenPortion_partition, | |
| intact_partition_identity_even he wβ] | |
| rfl | |
| theorem observableD_mean_even (he : Even (Fintype.card V)) | |
| (w wβ : V β V β β) (hw : β x y, 0 < w x y) (K D : β) : | |
| (β a : SourceMarked w K, sourceLaw w K D a * observableD w wβ K a) = | |
| sourceC w K * Switching.partition wβ β / sourceBagZ w K D := by | |
| classical | |
| have h := Marking.allReal_mean BagEdge.Incident (sourcePortions w K D) (0 : Fin 3) (bagReweight w wβ K) | |
| simp only [sourcePortions, Matrix.cons_val_zero] at h | |
| rw [bagReweight_identity w wβ hw K, frozenPortion_full_even he w wβ] at h | |
| simpa only [sourceLaw, observableD, sourcePortions_collapse, sourceBagZ] using h | |
| theorem observableD_zero_of_partition_zero (he : Even (Fintype.card V)) | |
| (w wβ : V β V β β) (hw : β x y, 0 < w x y) | |
| (hwβ : β x y, 0 β€ wβ x y) (hle : β x y, wβ x y β€ w x y) | |
| (hz : 0 < Switching.partition w β ) (K D : β) | |
| (hzβ : Switching.partition wβ β = 0) (a : SourceMarked w K) | |
| (ha : 0 < sourceLaw w K D a) : observableD w wβ K a = 0 := by | |
| have hB : 0 < sourceBagZ w K D := sourceBagZ_pos w hw hz K D | |
| have hmean := observableD_mean_even he w wβ hw K D | |
| rw [hzβ, mul_zero, zero_div] at hmean | |
| have hnonneg (b : SourceMarked w K) : 0 β€ sourceLaw w K D b * observableD w wβ K b := | |
| mul_nonneg (sourceLaw_nonneg w hw K D hB.le b) | |
| (observableD_range w wβ hw hwβ hle K b).1 | |
| have hz' := (sum_eq_zero_iff_of_nonneg (fun b _ => hnonneg b)).mp hmean a (mem_univ a) | |
| exact (mul_eq_zero.mp hz').resolve_left ha.ne' | |
| end MatchingFPRAS.Enlargement | |
| namespace MatchingFPRAS.TableMarking | |
| open Finset Transport Variation | |
| variable {V E I : Type*} [Fintype V] [Fintype E] [DecidableEq E] [Fintype I] [DecidableEq I] | |
| variable (inc : E β V β Prop) | |
| variable {A : Type*} [Fintype A] [Nonempty A] | |
| omit [Fintype A] [Nonempty A] [DecidableEq E] in | |
| lemma draw_law_pos [DecidableEq E] (f : A β PM inc) (w : E β β) (hw : β e, 0 < w e) | |
| (c : E β WeightedOptions I) (k : β) (bits : A Γ (E β Fin k β Bool)) : | |
| 0 < law inc w c (draw inc f c k bits) := by | |
| classical | |
| change 0 < gibbs w (f bits.1) * β e : (f bits.1).val, ((c e.val).law ((c e.val).draw k (bits.2 e.val)) : β) | |
| apply mul_pos (gibbs_pos w hw _) | |
| exact Finset.prod_pos fun e _ => by exact_mod_cast (c e.val).draw_law_pos k (bits.2 e.val) | |
| end MatchingFPRAS.TableMarking | |
| namespace MatchingFPRAS.RationalSource | |
| open Finset Transport Variation Enlargement | |
| variable {V : Type*} [Fintype V] [LinearOrder V] [Nontrivial V] | |
| attribute [local instance] NumberedHierarchy.labelOrder sym2Order bagEdgeOrder bagEdgeFintype | |
| attribute [local instance] UnitRefresh.Computable.allowedDec prodOrder sumOrder | |
| noncomputable local instance (w : V β V β β) (K : β) : | |
| DecidableEq (SourceLabel (fun x y=>(w x y:β)) K) := Classical.decEq _ | |
| noncomputable local instance (w : V β V β β) (K : β) : | |
| Fintype (BagEdge (sourceBags (fun x y=>(w x y:β)) K)) := Fintype.ofFinite _ | |
| noncomputable local instance (w : V β V β β) (K : β) : | |
| DecidableEq (BagPM (bags w K)) := Classical.decEq _ | |
| noncomputable local instance (w : V β V β β) (K : β) : | |
| Fintype (BagPM (bags w K)) := Fintype.ofFinite _ | |
| noncomputable local instance (w : V β V β β) (K : β) : | |
| Fintype (Marked w K) := Fintype.ofFinite _ | |
| lemma marking_law_eq (w : V β V β β) (hw : β x y, 0 < w x y) | |
| (K D : β) (hD : 0 < D) : | |
| TableMarking.law BagEdge.Incident (fun e => (bagWeight w K D e : β)) | |
| (markingTable w hw K D hD) = markedLaw w K D := by | |
| funext a | |
| simp only [TableMarking.law, markedLaw, Variation.sigmaLift, Variation.product, TableMarking.portion, markingTable_law] | |
| theorem source_draw_support {A : Type*} [Fintype A] [Nonempty A] | |
| (w : V β V β β) (hw : β x y, 0 < w x y) (K D k : β) (hD : 0 < D) | |
| (f : A β BagPM (bags w K)) (bits : A Γ (BagEdge (bags w K) β Fin k β Bool)) : | |
| 0 < sourceLaw (fun x y => (w x y : β)) K D | |
| ((sourceMarkedEquiv w K).symm | |
| (TableMarking.draw BagEdge.Incident f (markingTable w hw K D hD) k bits)) := by | |
| rw [βmarkedLaw_equiv w hw K D hD, Equiv.apply_symm_apply, βmarking_law_eq w hw K D hD] | |
| apply TableMarking.draw_law_pos | |
| intro e | |
| exact_mod_cast bagWeight_pos w hw K D hD e | |
| end MatchingFPRAS.RationalSource | |
| namespace MatchingFPRAS.GraphBridge | |
| open Finset Switching | |
| lemma unpadded_partition (G : GraphInput) : | |
| partition (rawActivity G 0) β = (Z G : β) := by | |
| have h := raw_padding_bound G 0 (by norm_num) (by norm_num) | |
| have he : rawPartition G 0 = (Z G : β) := le_antisymm (by simpa using h.2) h.1 | |
| have hc := raw_partition G 0 | |
| rw [he] at hc | |
| simpa using hc.symm | |
| end MatchingFPRAS.GraphBridge | |
| namespace MatchingFPRAS.Trial | |
| open Finset Switching Transport Enlargement StageAnalysis | |
| open scoped Classical | |
| variable {G : GraphInput} {j K : β} [Nontrivial (Fin G.n)] | |
| noncomputable local instance (w : Fin G.n β Fin G.n β β) (K : β) : | |
| DecidableEq (SourceLabel w K) := Classical.decEq _ | |
| noncomputable local instance (w : Fin G.n β Fin G.n β β) (K : β) : | |
| Fintype (BagEdge (sourceBags w K)) := Fintype.ofFinite _ | |
| noncomputable def ScaleState.certificateActivity (s : ScaleState G j) : Fin G.n β Fin G.n β β := | |
| fun a b => GraphBridge.rawActivity G 0 a b * s.scale a * s.scale b | |
| omit [Nontrivial (Fin G.n)] in | |
| lemma ScaleState.certificateActivity_nonneg (s : ScaleState G j) (a b : Fin G.n) : | |
| 0 β€ s.certificateActivity a b := by | |
| unfold ScaleState.certificateActivity GraphBridge.rawActivity | |
| split_ifs | |
| Β· simpa only [one_mul] using mul_nonneg (s.positive a).le (s.positive b).le | |
| Β· simp | |
| omit [Nontrivial (Fin G.n)] in | |
| lemma ScaleState.certificateActivity_le (s : ScaleState G j) (a b : Fin G.n) : | |
| s.certificateActivity a b β€ s.activity a b := by | |
| unfold ScaleState.certificateActivity ScaleState.activity raw GraphBridge.rawActivity | |
| split_ifs | |
| Β· rfl | |
| Β· simp only [zero_mul] | |
| exact mul_nonneg (mul_nonneg (pow_pos (cooling_pos G.n) j).le (s.positive a).le) (s.positive b).le | |
| omit [Nontrivial (Fin G.n)] in | |
| lemma ScaleState.certificateActivity_partition (s : ScaleState G j) : | |
| Switching.partition s.certificateActivity β = (Z G : β) * β i, s.scale i := by | |
| change Switching.partition (fun a b => GraphBridge.rawActivity G 0 a b * s.scale a * s.scale b) β = _ | |
| rw [partition_vertex_scaling, GraphBridge.unpadded_partition] | |
| simp | |
| theorem ScaleState.certificate_zero (s : ScaleState G j) (he : Even G.n) | |
| (hZ : Z G = 0) (D : β) (a : SourceMarked s.activity K) | |
| (ha : 0 < sourceLaw s.activity K D a) : | |
| observableD s.activity s.certificateActivity K a = 0 := by | |
| apply observableD_zero_of_partition_zero (by simpa using he) s.activity s.certificateActivity | |
| s.activity_pos s.certificateActivity_nonneg s.certificateActivity_le | |
| (s.partition_pos he) K D | |
| Β· rw [s.certificateActivity_partition, hZ] | |
| simp | |
| Β· exact ha | |
| open Finset Switching Transport Enlargement StageAnalysis | |
| open scoped Classical | |
| variable {G : GraphInput} [Nontrivial (Fin G.n)] | |
| noncomputable local instance (w : Fin G.n β Fin G.n β β) (K : β) : | |
| DecidableEq (SourceLabel w K) := Classical.decEq _ | |
| noncomputable local instance (w : Fin G.n β Fin G.n β β) (K : β) : | |
| Fintype (BagEdge (sourceBags w K)) := Fintype.ofFinite _ | |
| theorem ScaleState.certificate_mean_lower (p : Parameters G) (s : ScaleState G p.K) | |
| (hs : s.Balanced p.hn) (hZ : 0 < Z G) : | |
| (1:β)/4 β€ β a : SourceMarked s.activity p.K, | |
| sourceLaw s.activity p.K p.D a * observableD s.activity s.certificateActivity p.K a := by | |
| have hm : (β a : SourceMarked s.activity p.K, | |
| sourceLaw s.activity p.K p.D a * observableD s.activity s.certificateActivity p.K a) = | |
| sourceC s.activity p.K * partition s.certificateActivity β / sourceBagZ s.activity p.K p.D := by | |
| convert observableD_mean_even (by simpa using p.even) s.activity s.certificateActivity | |
| s.activity_pos p.K p.D using 1 | |
| exact Variation.sum_instances _ _ _ | |
| rw [hm] | |
| have hB := (sourceBagZ_bounds (by simpa using p.hn) s.activity s.activity_pos | |
| (s.partition_pos p.even) hs.1 hs.2 p.K (s.cap le_rfl)).2 | |
| have hp := (final_padding G p.epsilon p.epsilon_pos p.K p.schedule hZ).2 | |
| have hsmall : partition (raw G p.K) β β€ 2 * (Z G : β) := by | |
| have hz : (0:β) β€ Z G := Nat.cast_nonneg _ | |
| have he := p.epsilon_real_lt_one | |
| nlinarith | |
| have hprod : 0 < β i, s.scale i := prod_pos fun i _ => s.positive i | |
| have hact : partition s.activity β β€ 2 * partition s.certificateActivity β := by | |
| rw [s.certificateActivity_partition] | |
| change partition (fun a b => raw G p.K a b * s.scale a * s.scale b) β β€ _ | |
| rw [partition_vertex_scaling] | |
| simpa [mul_assoc] using mul_le_mul_of_nonneg_right hsmall hprod.le | |
| have hc := sourceC_pos s.activity p.K | |
| have hb0 := sourceBagZ_pos s.activity s.activity_pos (s.partition_pos p.even) p.K p.D | |
| apply (le_div_iffβ hb0).mpr | |
| change sourceBagZ s.activity p.K (sourceD (V:=Fin G.n) p.K) β€ _ at hB | |
| have hmul := mul_le_mul_of_nonneg_left hact hc.le | |
| change (1:β)/4 * sourceBagZ s.activity p.K (sourceD (V:=Fin G.n) p.K) β€ _ | |
| nlinarith | |
| end MatchingFPRAS.Trial | |
| namespace MatchingFPRAS.Variation | |
| open Finset | |
| open scoped Classical | |
| variable {Ξ© : Type*} [Fintype Ξ©] | |
| lemma mean_le_positive_event (p X : Ξ© β β) (hp : β x, 0 β€ p x) | |
| (hX : β x, 0 β€ X x β§ X x β€ 1) : | |
| (β x, p x * X x) β€ event p (fun x => 0 < X x) := by | |
| apply sum_le_sum | |
| intro x _ | |
| change p x * X x β€ if 0 < X x then p x else 0 | |
| by_cases hx : 0 < X x | |
| Β· simp only [hx, ite_true] | |
| exact mul_le_of_le_one_right (hp x) (hX x).2 | |
| Β· have hz : X x = 0 := le_antisymm (le_of_not_gt hx) (hX x).1 | |
| simp [hz] | |
| end MatchingFPRAS.Variation | |
| namespace MatchingFPRAS.RationalSource | |
| open Finset Transport Variation Enlargement | |
| variable {V : Type*} [Fintype V] [LinearOrder V] [Nontrivial V] | |
| attribute [local instance] NumberedHierarchy.labelOrder sym2Order bagEdgeOrder bagEdgeFintype | |
| attribute [local instance] UnitRefresh.Computable.allowedDec prodOrder sumOrder | |
| noncomputable local instance (w : V β V β β) (K : β) : | |
| DecidableEq (SourceLabel (fun x y=>(w x y:β)) K) := Classical.decEq _ | |
| noncomputable local instance (w : V β V β β) (K : β) : | |
| Fintype (BagEdge (sourceBags (fun x y=>(w x y:β)) K)) := Fintype.ofFinite _ | |
| noncomputable local instance (w : V β V β β) (K : β) : | |
| DecidableEq (BagPM (bags w K)) := Classical.decEq _ | |
| noncomputable local instance (w : V β V β β) (K : β) : | |
| Fintype (BagPM (bags w K)) := Fintype.ofFinite _ | |
| theorem fixedSampler_support (w : V β V β β) (hw : β x y,0<w x y) (K D m : β) | |
| (hD : 0<D) (hN : 0<Fintype.card (SourceVertex V K)) | |
| (h : β x y,xβ y β BottleneckAlgorithm.edge w x yβ€(4:β)^K) | |
| (hq : 0<ladderQ (Fintype.card (SourceVertex V K)) D) (M : BagPM (bags w K)) (Ξ· : β) | |
| (bits : Fin (totalBitsPolynomial (Fintype.card (SourceVertex V K)) D K m βΞ·β»ΒΉββ) β Bool) : | |
| 0 < sourceLaw (fun x y => (w x y : β)) K D | |
| (fixedSampler w hw K D m hD hN h hq M Ξ· bits) := by | |
| simp only [fixedSampler, padSampler, bitSampler, Function.comp_apply, markedSampler] | |
| exact source_draw_support w hw K D _ hD _ _ | |
| end MatchingFPRAS.RationalSource | |
| end OAI | |