import OAI.Combinatorics.ContingencyTables.Transport.FinitePartialDraw import OAI.Combinatorics.MatchingCount.Complexity.TreeChoiceCosts namespace OAI /-! # Exact integer-weighted choice for the residual correction branch -/ namespace ContingencyTables.ExactIntegerChoice open MatchingFPRAS MatchingFPRAS.FiniteChoice ResidualMixture FirstSuccess FairBits open scoped BigOperators Classical noncomputable section variable {r : ℕ} (w : Fin r → ℕ) def totalWeight : ℕ := ∑ i,w i def normalized : Fin r → ℚ := fun i => (w i:ℚ)/totalWeight w def prefixWeight (n : ℕ) : ℕ := ∑ i,if i.val simp lemma grid_scaled_cumulative (h : 0 z.val) he exact hj (hv ▸ x.isLt) simp only [intervalTrial,dite_eq_right hj,reduceCtorEq,hn] lemma intervalTrial_mass {V Q : ℕ} [NeZero Q] (h : V≤Q) (x : Fin V) : (mapLaw (uniformLaw (α := Fin Q)) (intervalTrial h)).mass (some x)=1/(Q:ℚ) := by simp only [mapLaw,uniformLaw,uniformMass,Fintype.card_fin] simp_rw [intervalTrial_eq_some] simp /-- A rational choice with integer weights, after a single binary rejection trial. The sum of these masses is totalWeight / 2^k. -/ def weightedTrial (h : 0 choose (normalized w) (normalized_total w h) h j=i)).card:ℚ)=w i := by change _/(totalWeight w:ℚ)=(w i:ℚ)/totalWeight w at he exact (div_left_inj' hVpos.ne').mp he have hsum : (∑ j : Fin (totalWeight w), if choose (normalized w) (normalized_total w h) h j=i then 1/(Q:ℚ) else 0)= (∑ j : Fin (totalWeight w), if choose (normalized w) (normalized_total w h) h j=i then (1:ℚ) else 0)/(Q:ℚ) := by rw [Finset.sum_div] apply Finset.sum_congr rfl intro j _ split_ifs <;> simp rw [hsum,Finset.sum_boole,hc] end end ContingencyTables.ExactIntegerChoice end OAI