introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
17.6 kB
import Mathlib
import OAI.Combinatorics.MatchingCount.Sampling.PM
namespace OAI
namespace MatchingFPRAS.Transport
open Finset
variable {V J : Type*} [Fintype V] [DecidableEq V] [Fintype J] [DecidableEq J]
variable {bags : V β†’ Finset J} {G : SimpleGraph J}
noncomputable local instance cumulativeBagEdgeFintype : Fintype (BagEdge bags) :=
Fintype.ofFinite _
noncomputable local instance cumulativeBagEdgePMDecidableEq :
DecidableEq (PM (BagEdge.Incident (bags := bags))) := Classical.decEq _
end MatchingFPRAS.Transport
namespace MatchingFPRAS.FiniteChoice
open Finset
def cumulative {r : β„•} (p : Fin r β†’ β„š) (i : β„•) : β„š := βˆ‘ j, if j.val < i then p j else 0
lemma cumulative_zero {r : β„•} (p : Fin r β†’ β„š) : cumulative p 0 = 0 := by simp [cumulative]
lemma cumulative_total {r : β„•} (p : Fin r β†’ β„š) (hs : βˆ‘ j, p j = 1) : cumulative p r = 1 := by
simp only [cumulative,Fin.isLt,ite_true]; exact hs
lemma options_pos {r : β„•} (p : Fin r β†’ β„š) (hs : βˆ‘ j, p j = 1) : 0 < r := by
by_contra h
have hr : r=0 := by omega
subst r
simp at hs
lemma cumulative_mono {r : β„•} (p : Fin r β†’ β„š) (hp : βˆ€ j, 0 ≀ p j) : Monotone (cumulative p) := by
intro a b hab
apply Finset.sum_le_sum
intro j _
by_cases ha : j.val<a
Β· simp only [ite_eq_left ha,ite_eq_left (lt_of_lt_of_le ha hab),le_refl]
Β· simp only [ite_eq_right ha]
split_ifs <;> [exact hp j; exact le_refl _]
def candidates {r K : β„•} (p : Fin r β†’ β„š) (J : Fin K) : Finset (Fin r) :=
Finset.univ.filter (fun i => (J.val:β„š)/K < cumulative p (i.val+1))
lemma candidates_nonempty {r K : β„•} (p : Fin r β†’ β„š) (hs : βˆ‘ j, p j = 1)
(hK : 0 < K) (J : Fin K) : (candidates p J).Nonempty := by
have hr := options_pos p hs
refine ⟨⟨r-1,by omega⟩,?_⟩
simp only [candidates,Finset.mem_filter,Finset.mem_univ,true_and]
have he : r-1+1=r := by omega
rw [he,cumulative_total p hs]
apply (div_lt_one (by exact_mod_cast hK : (0:β„š)<K)).mpr
exact_mod_cast J.isLt
def choose {r K : β„•} (p : Fin r β†’ β„š) (hs : βˆ‘ j, p j = 1) (hK : 0 < K) (J : Fin K) : Fin r :=
(candidates p J).min' (candidates_nonempty p hs hK J)
def outputLaw {r K : β„•} (p : Fin r β†’ β„š) (hs : βˆ‘ j, p j = 1) (hK : 0 < K) (i : Fin r) : β„š :=
((Finset.univ.filter (fun J : Fin K => choose p hs hK J=i)).card:β„š)/K
def gridInterval (K : β„•) (a b : β„š) : Finset β„• :=
(Finset.range K).filter (fun j => a ≀ (j:β„š)/K ∧ (j:β„š)/K < b)
lemma gridInterval_eq (K : β„•) (hK : 0 < K) (a b : β„š) (hb : b ≀ 1) :
gridInterval K a b = Finset.Ico ⌈(K:β„š)*aβŒ‰β‚Š ⌈(K:β„š)*bβŒ‰β‚Š := by
have hKr : (0:β„š)<K := by exact_mod_cast hK
have hlast : ⌈(K:β„š)*bβŒ‰β‚Š ≀ K := Nat.ceil_le.mpr (by nlinarith)
ext j
simp only [gridInterval,Finset.mem_filter,Finset.mem_range,Finset.mem_Ico,
Nat.ceil_le,Nat.lt_ceil]
constructor
· rintro ⟨_,ha,hb⟩
constructor
Β· have := (le_div_iffβ‚€ hKr).mp ha; nlinarith
Β· have := (div_lt_iffβ‚€ hKr).mp hb; nlinarith
· rintro ⟨ha,hb⟩
constructor
Β· exact lt_of_lt_of_le (Nat.lt_ceil.mpr hb) hlast
Β· constructor
Β· apply (le_div_iffβ‚€ hKr).mpr; nlinarith
Β· apply (div_lt_iffβ‚€ hKr).mpr; nlinarith
lemma gridInterval_card (K : β„•) (hK : 0 < K) (a b : β„š) (hab : a ≀ b) (hb : b ≀ 1) :
((gridInterval K a b).card:β„š) = (⌈(K:β„š)*bβŒ‰β‚Š:β„š)-(⌈(K:β„š)*aβŒ‰β‚Š:β„š) := by
rw [gridInterval_eq K hK a b hb,Nat.card_Ico,Nat.cast_sub]
exact Nat.ceil_mono (mul_le_mul_of_nonneg_left hab (by positivity))
lemma gridInterval_error (K : β„•) (hK : 0 < K) (a b : β„š) (ha : 0 ≀ a) (hab : a ≀ b) (hb : b ≀ 1) :
|((gridInterval K a b).card:β„š)/K-(b-a)| ≀ 2/(K:β„š) := by
have hKr : (0:β„š)<K := by exact_mod_cast hK
rw [gridInterval_card K hK a b hab hb]
have haβ‚€ := Nat.le_ceil ((K:β„š)*a)
have hbβ‚€ := Nat.le_ceil ((K:β„š)*b)
have ha₁ := Nat.ceil_lt_add_one (mul_nonneg hKr.le ha)
have hb₁ := Nat.ceil_lt_add_one (mul_nonneg hKr.le (ha.trans hab))
rw [abs_sub_le_iff]
constructor
Β· apply (le_div_iffβ‚€ hKr).mpr
simp only [sub_mul,div_mul_cancelβ‚€ _ (ne_of_gt hKr)]
nlinarith
Β· apply (le_div_iffβ‚€ hKr).mpr
simp only [sub_mul,div_mul_cancelβ‚€ _ (ne_of_gt hKr)]
nlinarith
lemma cumulative_nonneg {r : β„•} (p : Fin r β†’ β„š) (hp : βˆ€ j, 0 ≀ p j) (i : β„•) :
0 ≀ cumulative p i := by
apply Finset.sum_nonneg; intro j _; split_ifs <;> [exact hp j; exact le_rfl]
lemma cumulative_le_one {r : β„•} (p : Fin r β†’ β„š) (hp : βˆ€ j, 0 ≀ p j)
(hs : βˆ‘ j, p j = 1) (i : β„•) (hi : i ≀ r) : cumulative p i ≀ 1 := by
rw [← cumulative_total p hs]; exact cumulative_mono p hp hi
lemma cumulative_step {r : β„•} (p : Fin r β†’ β„š) (i : Fin r) :
cumulative p (i.val+1)-cumulative p i.val = p i := by
unfold cumulative
rw [← Finset.sum_sub_distrib]
have he (j : Fin r) : (if j.val < i.val+1 then p j else 0)-(if j.val < i.val then p j else 0) =
if j=i then p j else 0 := by
by_cases h : j=i
Β· subst j; simp
Β· have hn : j.val β‰  i.val := fun hval => h (Fin.ext hval)
by_cases hj : j.val < i.val
Β· simp [h,hj,show j.val < i.val+1 by omega]
Β· simp [h,hj,show Β¬j.val < i.val+1 by omega]
simp_rw [he]
simp
lemma choose_upper {r K : β„•} (p : Fin r β†’ β„š) (hs : βˆ‘ j, p j = 1)
(hK : 0 < K) (J : Fin K) :
(J.val:β„š)/K < cumulative p ((choose p hs hK J).val+1) := by
have hm := Finset.min'_mem (candidates p J) (candidates_nonempty p hs hK J)
exact (Finset.mem_filter.mp hm).2
lemma choose_le {r K : β„•} (p : Fin r β†’ β„š) (hs : βˆ‘ j, p j = 1)
(hK : 0 < K) (J : Fin K) (i : Fin r)
(hi : (J.val:β„š)/K < cumulative p (i.val+1)) : choose p hs hK J ≀ i := by
exact Finset.min'_le (candidates p J) i (Finset.mem_filter.mpr ⟨Finset.mem_univ _,hi⟩)
lemma choose_lower {r K : β„•} (p : Fin r β†’ β„š) (hs : βˆ‘ j, p j = 1)
(hK : 0 < K) (J : Fin K) :
cumulative p (choose p hs hK J).val ≀ (J.val:β„š)/K := by
let i := choose p hs hK J
by_cases hi : i.val=0
Β· rw [show (choose p hs hK J).val=0 from hi,cumulative_zero]
positivity
Β· by_contra hh
have hx : (J.val:β„š)/K < cumulative p i.val := lt_of_not_ge hh
let j : Fin r := ⟨i.val-1,by have := i.isLt; omega⟩
have he : j.val+1=i.val := by dsimp [j]; omega
have hj : (J.val:β„š)/K < cumulative p (j.val+1) := by rw [he]; exact hx
have hm := choose_le p hs hK J j hj
have hv : i.val ≀ j.val := hm
dsimp [j] at hv
omega
lemma choose_eq_iff {r K : β„•} (p : Fin r β†’ β„š) (hp : βˆ€ j, 0 ≀ p j)
(hs : βˆ‘ j, p j = 1) (hK : 0 < K) (J : Fin K) (i : Fin r) :
choose p hs hK J=i ↔ cumulative p i.val ≀ (J.val:β„š)/K ∧
(J.val:β„š)/K < cumulative p (i.val+1) := by
constructor
Β· intro he
have hl := choose_lower p hs hK J
have hu := choose_upper p hs hK J
rw [he] at hl hu
exact ⟨hl,hu⟩
· rintro ⟨hl,hu⟩
apply le_antisymm (choose_le p hs hK J i hu)
by_contra h
have hlt : (choose p hs hK J).val+1 ≀ i.val := by
have hh : choose p hs hK J < i := lt_of_not_ge h
exact hh
have hm := cumulative_mono p hp hlt
have hh := choose_upper p hs hK J
linarith
lemma outputLaw_grid {r K : β„•} (p : Fin r β†’ β„š) (hp : βˆ€ j, 0 ≀ p j)
(hs : βˆ‘ j, p j = 1) (hK : 0 < K) (i : Fin r) :
outputLaw p hs hK i = ((gridInterval K (cumulative p i.val) (cumulative p (i.val+1))).card:β„š)/K := by
unfold outputLaw
congr 2
apply Finset.card_bij (fun J _ => J.val)
Β· intro J hJ
have he := (Finset.mem_filter.mp hJ).2
have hc := (choose_eq_iff p hp hs hK J i).mp he
exact Finset.mem_filter.mpr ⟨Finset.mem_range.mpr J.isLt,hc⟩
Β· intro J _ J' _ h; exact Fin.ext h
Β· intro j hj
have hh := Finset.mem_filter.mp hj
let J : Fin K := ⟨j,Finset.mem_range.mp hh.1⟩
refine ⟨J,Finset.mem_filter.mpr ⟨Finset.mem_univ _,?_⟩,rfl⟩
exact (choose_eq_iff p hp hs hK J i).mpr hh.2
lemma outputLaw_error {r K : β„•} (p : Fin r β†’ β„š) (hp : βˆ€ j, 0 ≀ p j)
(hs : βˆ‘ j, p j = 1) (hK : 0 < K) (i : Fin r) :
|outputLaw p hs hK i-p i| ≀ 2/(K:β„š) := by
rw [outputLaw_grid p hp hs hK i,← cumulative_step p i]
exact gridInterval_error K hK _ _ (cumulative_nonneg p hp i.val)
(cumulative_mono p hp (by omega)) (cumulative_le_one p hp hs _ (by have := i.isLt; omega))
theorem fixed_bit_choice {r : β„•} (p : Fin r β†’ β„š) (hp : βˆ€ i, 0 ≀ p i)
(hs : βˆ‘ i, p i = 1) (k : β„•) :
(βˆ‘ i, |outputLaw p hs (pow_pos (by norm_num : 0 < (2:β„•)) k) i-p i|)/2 ≀
2*r/(2:β„š)^k := by
have hK : 0 < (2:β„•)^k := pow_pos (by norm_num) k
have hh := Finset.sum_le_sum (fun i (_ : i ∈ Finset.univ) => outputLaw_error p hp hs hK i)
simp only [Finset.sum_const,Finset.card_fin,nsmul_eq_mul,Nat.cast_pow,Nat.cast_ofNat] at hh
have hr : (0:β„š) ≀ r := Nat.cast_nonneg r
have hpow : (0:β„š) < 2^k := pow_pos (by norm_num) k
have hz : 0 ≀ r/(2:β„š)^k := div_nonneg hr hpow.le
calc
(βˆ‘ i, |outputLaw p hs hK i-p i|)/2 ≀ ((r:β„š)*(2/(2:β„š)^k))/2 :=
div_le_div_of_nonneg_right hh (by norm_num)
_ = (r:β„š)/(2:β„š)^k := by ring
_ ≀ 2*r/(2:β„š)^k := div_le_div_of_nonneg_right (by linarith) hpow.le
lemma outputLaw_nonneg {r K : β„•} (p : Fin r β†’ β„š) (hs : βˆ‘ j, p j = 1)
(hK : 0 < K) (i : Fin r) : 0 ≀ outputLaw p hs hK i := by unfold outputLaw; positivity
lemma outputLaw_sum {r K : β„•} (p : Fin r β†’ β„š) (hs : βˆ‘ j, p j = 1)
(hK : 0 < K) : βˆ‘ i, outputLaw p hs hK i = 1 := by
have hc (i : Fin r) : ((univ.filter (fun J : Fin K => choose p hs hK J=i)).card:β„š) =
βˆ‘ J : Fin K, if choose p hs hK J=i then (1:β„š) else 0 := by simp
simp only [outputLaw,hc,← Finset.sum_div]
rw [Finset.sum_comm]
simp only [Finset.sum_ite_eq,Finset.mem_univ,ite_true,Finset.sum_const,Finset.card_fin,nsmul_eq_mul,mul_one]
exact div_self (by exact_mod_cast hK.ne' : (K:β„š) β‰  0)
lemma fixed_bit_l1 {r : β„•} (p : Fin r β†’ β„š) (hp : βˆ€ i, 0 ≀ p i)
(hs : βˆ‘ i, p i = 1) (k : β„•) :
βˆ‘ i, |outputLaw p hs (pow_pos (by norm_num : 0 < (2:β„•)) k) i-p i| ≀ 4*r/(2:β„š)^k := by
have h := fixed_bit_choice p hp hs k
calc
_ = 2 * ((βˆ‘ i, |outputLaw p hs (pow_pos (by norm_num : 0 < (2:β„•)) k) i-p i|) / 2) := by ring
_ ≀ 2 * (2 * (r:β„š) / 2^k) := mul_le_mul_of_nonneg_left h (by norm_num)
_ = _ := by ring
end MatchingFPRAS.FiniteChoice
namespace MatchingFPRAS.BoundedSimulation
open Finset
variable {Ξ© : Type*} [Fintype Ξ©] [DecidableEq Ξ©]
def categoricalStep {r : β„•} (ΞΌ : Ξ© β†’ β„š) (p : Ξ© β†’ Fin r β†’ β„š)
(next : Ξ© β†’ Fin r β†’ Ξ©) (t : Ξ©) : β„š :=
βˆ‘ s, ΞΌ s * βˆ‘ i, if next s i=t then p s i else 0
def idealRun {r : β„•} (ΞΌ : Ξ© β†’ β„š) (p : β„• β†’ Ξ© β†’ Fin r β†’ β„š)
(next : β„• β†’ Ξ© β†’ Fin r β†’ Ξ©) : β„• β†’ Ξ© β†’ β„š
| 0 => ΞΌ
| n+1 => categoricalStep (idealRun ΞΌ p next n) (p n) (next n)
def bitRun {r : β„•} (ΞΌ : Ξ© β†’ β„š) (p : β„• β†’ Ξ© β†’ Fin r β†’ β„š)
(hs : βˆ€ n s, βˆ‘ i, p n s i = 1) (next : β„• β†’ Ξ© β†’ Fin r β†’ Ξ©) (k : β„•) : β„• β†’ Ξ© β†’ β„š
| 0 => ΞΌ
| n+1 => categoricalStep (bitRun ΞΌ p hs next k n)
(fun s => MatchingFPRAS.FiniteChoice.outputLaw (p n s) (hs n s) (pow_pos (by norm_num : 0 < (2:β„•)) k)) (next n)
omit [Fintype Ξ©] in
lemma row_nonneg [Fintype Ξ©] {r : β„•} (p : Fin r β†’ β„š) (hp : βˆ€ i, 0 ≀ p i)
(next : Fin r β†’ Ξ©) (t) : 0 ≀ βˆ‘ i, if next i=t then p i else 0 := by
apply sum_nonneg; intro i _; split_ifs <;> simp_all
lemma row_sum {r : β„•} (p : Fin r β†’ β„š) (hs : βˆ‘ i, p i = 1)
(next : Fin r β†’ Ξ©) : (βˆ‘ t, βˆ‘ i, if next i=t then p i else 0) = 1 := by
rw [sum_comm]; simp only [sum_ite_eq,mem_univ,ite_true]; exact hs
lemma step_nonneg {r : β„•} (ΞΌ : Ξ© β†’ β„š) (hΞΌ : βˆ€ s, 0 ≀ ΞΌ s)
(p : Ξ© β†’ Fin r β†’ β„š) (hp : βˆ€ s i, 0 ≀ p s i) (next : Ξ© β†’ Fin r β†’ Ξ©) (t) :
0 ≀ categoricalStep ΞΌ p next t :=
sum_nonneg (fun s _ => mul_nonneg (hΞΌ s) (row_nonneg _ (hp s) _ _))
lemma step_sum {r : β„•} (ΞΌ : Ξ© β†’ β„š) (hΞΌs : βˆ‘ s, ΞΌ s=1)
(p : Ξ© β†’ Fin r β†’ β„š) (hs : βˆ€ s, βˆ‘ i, p s i=1) (next : Ξ© β†’ Fin r β†’ Ξ©) :
βˆ‘ t, categoricalStep ΞΌ p next t=1 := by
unfold categoricalStep
rw [sum_comm]
simp_rw [← mul_sum,row_sum _ (hs _),mul_one]
exact hΞΌs
lemma row_l1 {r : β„•} (p q : Fin r β†’ β„š) (next : Fin r β†’ Ξ©) :
βˆ‘ t, |(βˆ‘ i, if next i=t then p i else 0)-(βˆ‘ i, if next i=t then q i else 0)| ≀
βˆ‘ i, |p i-q i| := by
calc
_ = βˆ‘ t, |βˆ‘ i, if next i=t then p i-q i else 0| := by
apply sum_congr rfl; intro t _; congr 1
rw [← sum_sub_distrib]; apply sum_congr rfl; intro i _; split_ifs <;> simp
_ ≀ βˆ‘ t, βˆ‘ i, |if next i=t then p i-q i else 0| :=
sum_le_sum (fun t _ => abs_sum_le_sum_abs _ _)
_ = _ := by rw [sum_comm]; simp only [apply_ite abs,abs_zero,sum_ite_eq,mem_univ,ite_true]
lemma step_l1 {r : β„•} (ΞΌ Ξ½ : Ξ© β†’ β„š) (hΞ½ : βˆ€ s, 0 ≀ Ξ½ s) (hΞ½s : βˆ‘ s, Ξ½ s=1)
(p q : Ξ© β†’ Fin r β†’ β„š) (hp : βˆ€ s i, 0 ≀ p s i) (hps : βˆ€ s, βˆ‘ i, p s i=1)
(next : Ξ© β†’ Fin r β†’ Ξ©) (Ξ΅ : β„š)
(he : βˆ€ s, βˆ‘ i, |p s i-q s i| ≀ Ξ΅) :
βˆ‘ t, |categoricalStep ΞΌ p next t-categoricalStep Ξ½ q next t| ≀ (βˆ‘ s, |ΞΌ s-Ξ½ s|)+Ξ΅ := by
let P (s t : Ξ©) := βˆ‘ i, if next s i=t then p s i else 0
let Q (s t : Ξ©) := βˆ‘ i, if next s i=t then q s i else 0
have hb (s t) : |ΞΌ s*P s t-Ξ½ s*Q s t| ≀ |ΞΌ s-Ξ½ s| *P s t+Ξ½ s*|P s t-Q s t| := by
have heq : ΞΌ s*P s t-Ξ½ s*Q s t=(ΞΌ s-Ξ½ s)*P s t+Ξ½ s*(P s t-Q s t) := by ring
rw [heq]
have h := abs_add_le ((ΞΌ s-Ξ½ s)*P s t) (Ξ½ s*(P s t-Q s t))
have hP0 : 0 ≀ P s t := row_nonneg _ (hp s) (next s) t
simpa only [abs_mul,abs_of_nonneg (hΞ½ s),abs_of_nonneg hP0] using h
calc
_ = βˆ‘ t, |βˆ‘ s, (ΞΌ s*P s t-Ξ½ s*Q s t)| := by simp only [categoricalStep,P,Q,sum_sub_distrib]
_ ≀ βˆ‘ t, βˆ‘ s, |ΞΌ s*P s t-Ξ½ s*Q s t| := sum_le_sum (fun t _ => abs_sum_le_sum_abs _ _)
_ ≀ βˆ‘ t, βˆ‘ s, (|ΞΌ s-Ξ½ s| *P s t+Ξ½ s*|P s t-Q s t|) := sum_le_sum (fun t _ => sum_le_sum (fun s _ => hb s t))
_ = (βˆ‘ s, |ΞΌ s-Ξ½ s|)+(βˆ‘ s, Ξ½ s*βˆ‘ t, |P s t-Q s t|) := by
rw [sum_comm]; simp only [sum_add_distrib,← mul_sum,P,row_sum _ (hps _),mul_one]
_ ≀ (βˆ‘ s, |ΞΌ s-Ξ½ s|)+(βˆ‘ s, Ξ½ s*Ξ΅) := by
apply add_le_add le_rfl
apply sum_le_sum; intro s _
exact mul_le_mul_of_nonneg_left ((row_l1 (p s) (q s) (next s)).trans (he s)) (hΞ½ s)
_ = _ := by rw [← sum_mul,hΞ½s,one_mul]
lemma idealRun_prob {r : β„•} (ΞΌ : Ξ© β†’ β„š) (hΞΌ : βˆ€ s, 0 ≀ ΞΌ s) (hΞΌs : βˆ‘ s, ΞΌ s=1)
(p : β„• β†’ Ξ© β†’ Fin r β†’ β„š) (hp : βˆ€ n s i, 0 ≀ p n s i)
(hs : βˆ€ n s, βˆ‘ i, p n s i=1) (next : β„• β†’ Ξ© β†’ Fin r β†’ Ξ©) (n : β„•) :
(βˆ€ s, 0 ≀ idealRun ΞΌ p next n s) ∧ βˆ‘ s, idealRun ΞΌ p next n s=1 := by
induction n with
| zero => exact ⟨hμ,hμs⟩
| succ n ih => exact ⟨step_nonneg _ ih.1 _ (hp n) _, step_sum _ ih.2 _ (hs n) _⟩
lemma bitRun_step_l1 {r : β„•} (ΞΌ : Ξ© β†’ β„š) (hΞΌ : βˆ€ s, 0 ≀ ΞΌ s)
(hΞΌs : βˆ‘ s, ΞΌ s = 1) (p : β„• β†’ Ξ© β†’ Fin r β†’ β„š)
(hp : βˆ€ n s i, 0 ≀ p n s i) (hs : βˆ€ n s, βˆ‘ i, p n s i = 1)
(next : β„• β†’ Ξ© β†’ Fin r β†’ Ξ©) (k n : β„•) :
(βˆ‘ s, |bitRun ΞΌ p hs next k (n+1) s-idealRun ΞΌ p next (n+1) s|) ≀
(βˆ‘ s, |bitRun ΞΌ p hs next k n s-idealRun ΞΌ p next n s|)+4*r/(2:β„š)^k := by
have hΞ½ := idealRun_prob ΞΌ hΞΌ hΞΌs p hp hs next n
exact step_l1 (bitRun ΞΌ p hs next k n) (idealRun ΞΌ p next n) hΞ½.1 hΞ½.2
(fun s => MatchingFPRAS.FiniteChoice.outputLaw (p n s) (hs n s) (pow_pos (by norm_num : 0 < (2:β„•)) k))
(p n) (fun s i => MatchingFPRAS.FiniteChoice.outputLaw_nonneg _ _ _ _)
(fun s => MatchingFPRAS.FiniteChoice.outputLaw_sum _ _ _) (next n) (4*r/(2:β„š)^k)
(fun s => MatchingFPRAS.FiniteChoice.fixed_bit_l1 (p n s) (hp n s) (hs n s) k)
theorem finite_bit_simulation {r : β„•} (ΞΌ : Ξ© β†’ β„š) (hΞΌ : βˆ€ s, 0 ≀ ΞΌ s)
(hΞΌs : βˆ‘ s, ΞΌ s = 1) (p : β„• β†’ Ξ© β†’ Fin r β†’ β„š)
(hp : βˆ€ n s i, 0 ≀ p n s i) (hs : βˆ€ n s, βˆ‘ i, p n s i = 1)
(next : β„• β†’ Ξ© β†’ Fin r β†’ Ξ©) (k n : β„•) :
(βˆ‘ s, |bitRun ΞΌ p hs next k n s-idealRun ΞΌ p next n s|)/2 ≀
2*n*r/(2:β„š)^k := by
have hmain : βˆ‘ s, |bitRun ΞΌ p hs next k n s-idealRun ΞΌ p next n s| ≀
4*n*r/(2:β„š)^k := by
induction n with
| zero => simp [bitRun,idealRun]
| succ n ih =>
have hh := bitRun_step_l1 ΞΌ hΞΌ hΞΌs p hp hs next k n
calc
_ ≀ (βˆ‘ s, |bitRun ΞΌ p hs next k n s-idealRun ΞΌ p next n s|)+4*r/(2:β„š)^k := hh
_ ≀ 4*n*r/(2:β„š)^k+4*r/(2:β„š)^k := add_le_add ih le_rfl
_ = _ := by push_cast; ring
calc
_ ≀ (4*n*r/(2:β„š)^k)/2 := div_le_div_of_nonneg_right hmain (by norm_num)
_ = _ := by ring
end MatchingFPRAS.BoundedSimulation
namespace MatchingFPRAS.FiniteChoice
open Finset
def tapeIndex (k : β„•) : (Fin k β†’ Bool) ≃ Fin (2^k) :=
(Equiv.piCongrRight (fun _ : Fin k => finTwoEquiv.symm)).trans finFunctionFinEquiv
def chooseBits {r : β„•} (p : Fin r β†’ β„š) (hs : βˆ‘ i, p i = 1) (k : β„•)
(bits : Fin k β†’ Bool) : Fin r :=
choose p hs (pow_pos (by norm_num : 0 < (2:β„•)) k) (tapeIndex k bits)
def tapeLaw {r : β„•} (p : Fin r β†’ β„š) (hs : βˆ‘ i, p i = 1) (k : β„•) (i : Fin r) : β„š :=
((univ.filter (fun bits : Fin k β†’ Bool => chooseBits p hs k bits=i)).card:β„š)/(2:β„š)^k
end MatchingFPRAS.FiniteChoice
end OAI