import Mathlib import OAI.Combinatorics.MatchingCount.Algorithm.FiniteTrialLaw import OAI.Combinatorics.MatchingCount.Algorithm.OutputLengthBound import OAI.Combinatorics.MatchingCount.Algorithm.OnlineStage import OAI.Combinatorics.MatchingCount.Probability.OnlineLawBridge import OAI.Combinatorics.MatchingCount.Algorithm.OnlineLaw namespace OAI namespace MatchingFPRAS.OnlineStage open PhysicalStream TreeTyped ExecutableSource NumericLadder TreeFraction ExecutableScaling open UnitRefresh Transport Enlargement TreeTyped.Numbered ExecutableAdaptive Variation attribute [local instance] NumberedHierarchy.labelOrder attribute [local instance] Transport.sym2Order Transport.bagEdgeOrder Transport.bagEdgeFintype attribute [local instance] UnitRefresh.Computable.allowedDec Transport.prodOrder Transport.sumOrder variable {n : ℕ} [Nontrivial (Fin n)] variable (w : Fin n→Fin n→ℚ) (K D m : ℕ) noncomputable local instance : Fintype (BagPM (RationalSource.bags w K)) := Fintype.ofFinite _ noncomputable local instance : Fintype (RationalSource.Marked w K) := Fintype.ofFinite _ noncomputable local instance : Fintype (SourceMarked (fun a b=>(w a b:ℝ)) K) := Fintype.ofFinite _ noncomputable def realRawDraw (hw : ∀ a b,0(w a b:ℝ)) K := (RationalSource.sourceMarkedEquiv w K).symm ∘ rawDraw w K D m hw hD hu hq he η lemma realRawDraw_law (hw : ∀ a b,0index (orderedEnum (BagEdge (RationalSource.bags s.activity p.K)) i)))) noncomputable def fixedData {j : ℕ} (p : Trial.Parameters G) (s : FiniteTrial.ScaleState G j) : SparseStageData := data s p.K (FiniteTrial.sourceD (G:=G) p.K) (List.replicate (tierCount (n:=G.n) p.K (FiniteTrial.sourceD (G:=G) p.K)) false) (List.replicate (copies (n:=G.n) p.K (FiniteTrial.sourceD (G:=G) p.K)) false) noncomputable def transition {j : ℕ} (p : Trial.Parameters G) (s : FiniteTrial.ScaleState G j) : Experiment (Fraction×Vector) := execute (fixedData p s,(p.S,fixedRequest p s)) lemma transition_mean {j : ℕ} (p : Trial.Parameters G) (hj : j≤p.K) (s : FiniteTrial.ScaleState G j) (h : Fraction×Vector→ℚ) : (transition p s).mean h= qaverage (fun bits : Fin (FiniteTrial.stageBits p)→Bool=> let x := RationalSource.sourceMarkedEquiv s.activity p.K ∘ s.drawStage p hj bits h (repr (s.ratioEstimate x),vectorRep (s.update p.hn x).scale)) := by have hD : 0fun i=>raw (bs i)) = imageLaw (s.drawStage p hj) := by rw [imageLaw_componentwise,hr,FiniteTrial.ScaleState.drawStage_law] rfl have hmean := qaverage_eq_of_imageLaw_eq _ _ hp (fun y=> let x:=RationalSource.sourceMarkedEquiv s.activity p.K ∘ y h (repr (s.ratioEstimate x),vectorRep (s.update p.hn x).scale)) apply Eq.trans _ hmean apply qaverage_congr intro bs have hx : (fun i=>generatedSourceSample p.even s.activity s.activity_pos p.K (FiniteTrial.sourceD (G:=G) p.K) hD (s.cap hj) (List.replicate (tierCount (n:=G.n) p.K (FiniteTrial.sourceD (G:=G) p.K)) false) (List.replicate (copies (n:=G.n) p.K (FiniteTrial.sourceD (G:=G) p.K)) false) (by simpa using hq) (bs i).1 (fun e=>(bs i).2 ((orderedEnum _).symm e))) = RationalSource.sourceMarkedEquiv s.activity p.K ∘ (fun i=>raw (bs i)) := by funext i rw [generated_eq_raw] exact (realRawDraw_inverse ..).symm rw [hx] end MatchingFPRAS.OnlineStage end OAI