Download data/lean/OAI/Combinatorics/MatchingCount/Graphs/Cumulative.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 17.6 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/MatchingCount/Graphs/Cumulative.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/MatchingCount/Graphs/Cumulative.lean
-
curl -L -o Cumulative.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/MatchingCount/Graphs/Cumulative.lean
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 | |