import Mathlib import OAI.Combinatorics.MatchingCount.Probability.AdaptiveLaw import OAI.Combinatorics.MatchingCount.Graphs.LabelOrder import OAI.Combinatorics.MatchingCount.Sampling.TableMarking namespace OAI namespace MatchingFPRAS.Variation lemma imageLaw_instances {A B : Type*} (F₁ F₂ : Fintype A) (f : A → B) : @imageLaw A B F₁ f=@imageLaw A B F₂ f := by cases Subsingleton.elim F₁ F₂ rfl lemma tv_instances {A : Type*} (F₁ F₂ : Fintype A) (p q : A → ℝ) : @tv A F₁ p q=@tv A F₂ p q := by cases Subsingleton.elim F₁ F₂ rfl 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 (BagPM (bags w K)) := Classical.decEq _ noncomputable local instance (w : V → V → ℚ) (K : ℕ) : Fintype (BagPM (bags w K)) := Fintype.ofFinite _ def centralEdge (w : V → V → ℚ) (K : ℕ) (e : LogicalEdge V) : BagEdge (bags w K) := coloredReal w K (e,⟨2*(2*K+2),by omega⟩) def probePortion (w : V → V → ℚ) (K D : ℕ) (e : BagEdge (bags w K)) : ℚ := if ∃ q,centralEdge w K q=e then 1/(D:ℚ) else 0 def portions (w : V → V → ℚ) (K D : ℕ) (e : BagEdge (bags w K)) : Fin 3 → ℚ := ![realPortion w K e,bagHeight w K e.color/D-probePortion w K D e,probePortion w K D e] lemma portions_sum (w : V → V → ℚ) (K D : ℕ) (e : BagEdge (bags w K)) : ∑ i,portions w K D e i=bagWeight w K D e := by simp [portions,Fin.sum_univ_succ,bagWeight] lemma portions_nonneg (w : V → V → ℚ) (hw : ∀ x y,0 positivity lemma bagWeight_pos (w : V → V → ℚ) (hw : ∀ x y,0(bagWeight w K D e:ℝ))) (fun M=>product (fun e : M.val=>fun i=>(portions w K D e.val i/bagWeight w K D e.val:ℚ))) def markedSampler (w : V → V → ℚ) (hw : ∀ x y,0(bagWeight w K D e:ℝ)))+ 6*Fintype.card (BagEdge (bags w K))/(2:ℝ)^k := by have he : TableMarking.law BagEdge.Incident (fun e=>(bagWeight w K D e:ℝ)) (markingTable w hw K D hD)=markedLaw w K D := by unfold TableMarking.law TableMarking.portion markedLaw simp only [markingTable_law] have hh:=TableMarking.draw_tv_size BagEdge.Incident f (fun e=>(bagWeight w K D e:ℝ)) (markingTable w hw K D hD) k 3 (fun _=>rfl) rw [he] at hh norm_num only [Nat.cast_ofNat] at hh rw [imageLaw_instances _ (sourceMarkingBitsFintype w K k), tv_instances _ (sourceMarkedFintype w K)] at hh exact hh noncomputable def markedSamplerLaw (w : V → V → ℚ) (hw : ∀ x y,0