introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
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