Download data/lean/OAI/Combinatorics/ContingencyTables/Counting/CompanionEstimatorRange.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 6.13 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/ContingencyTables/Counting/CompanionEstimatorRange.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/ContingencyTables/Counting/CompanionEstimatorRange.lean
-
curl -L -o CompanionEstimatorRange.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/ContingencyTables/Counting/CompanionEstimatorRange.lean
6.13 kB
| import OAI.Combinatorics.ContingencyTables.Counting.CompanionOracleEstimator | |
| namespace OAI | |
| /-! # Output range on every execution of the finite-word estimator -/ | |
| namespace ContingencyTables.CompanionOracleDensity | |
| open CompanionFactorialApplication ForestAssignmentSplit GridBoundary ResidualMixture FirstSuccess | |
| open CommonBasesFPRAS FiniteIndependentAverages | |
| open scoped BigOperators Classical | |
| noncomputable section | |
| variable {I J : Type*} [Fintype I] [Fintype J] | |
| lemma rationalAverage_bounds {X : Type*} (g : X β β) (N : β) (hN : 0 < N) | |
| (L U : β) (hg : β x,L β€ (g x:β) β§ (g x:β) β€ U) (draws : Fin N β X) : | |
| L β€ (rationalAverage g N draws:β) β§ (rationalAverage g N draws:β) β€ U := by | |
| have hNR : (0:β) < N := by exact_mod_cast hN | |
| have hl := Finset.sum_le_sum (s := Finset.univ) (fun i _ => (hg (draws i)).1) | |
| have hu := Finset.sum_le_sum (s := Finset.univ) (fun i _ => (hg (draws i)).2) | |
| simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] at hl hu | |
| simp only [rationalAverage,Rat.cast_div,Rat.cast_sum,Rat.cast_natCast] | |
| exact β¨(le_div_iffβ hNR).mpr (by linarith),(div_le_iffβ hNR).mpr (by linarith)β© | |
| lemma observed_ratio_bounds (A : Instance I J) (C : β) (hC : 0 < C) (z : View A β β) | |
| (hz : BalancedBox.InBox (bounds A) z) (K : β) (hK : 1 β€ K) (hW : 100*A.d*K β€ A.W) | |
| (hB : (K:β)=binWidth A C) (j : β) (delta failure : β) (hd : 0 < delta) (hf : 0 < failure) | |
| (v : Grid (I := Fin (dimension A)) K) (draws : EstimatorInput A C K j delta failure) (a : Fin j) : | |
| 1/2 β€ (observedFactor A C z K hK hW j delta failure v draws (some a):β) β§ | |
| (observedFactor A C z K hK hW j delta failure v draws (some a):β) β€ 1 := by | |
| apply rationalAverage_bounds _ _ (sampleCount_positive j delta failure hd hf) | |
| intro bits | |
| rw [ratioSample_cast] | |
| exact ratioObservable_bounds A C (by exact_mod_cast hC) a.val z hz hB.le _ | |
| lemma observed_correction_bounds (A : Instance I J) (C : β) (hC : 0 < C) (z : View A β β) | |
| (K : β) (hK : 1 β€ K) (hW : 100*A.d*K β€ A.W) (hB : (K:β)=binWidth A C) | |
| (j : β) (hj : j β€ rationalHeight A C) (delta failure : β) (hd : 0 < delta) (hd1 : delta < 1) | |
| (hf : 0 < failure) (v : Grid (I := Fin (dimension A)) K) | |
| (draws : EstimatorInput A C K j delta failure) : | |
| 1/16 β€ (observedFactor A C z K hK hW j delta failure v draws none:β) β§ | |
| (observedFactor A C z K hK hW j delta failure v draws none:β) β€ 8 := by | |
| apply rationalAverage_bounds _ _ (sampleCount_positive j delta failure hd hf) | |
| intro bits | |
| apply computedCorrection_bounds A C j hC hj z K (by omega) hW hB (roundingTolerance delta) | |
| Β· unfold roundingTolerance | |
| positivity | |
| Β· unfold roundingTolerance | |
| linarith | |
| /-- These bounds hold for every Boolean input, including executions on | |
| which the empirical averages are statistically inaccurate. -/ | |
| theorem estimateValue_range (A : Instance I J) (C : β) (hC : 0 < C) (z : View A β β) | |
| (hz : BalancedBox.InBox (bounds A) z) (K : β) (hK : 1 β€ K) (hW : 100*A.d*K β€ A.W) | |
| (hB : (K:β)=binWidth A C) (j : β) (hj : j β€ rationalHeight A C) | |
| (delta failure : β) (hd : 0 < delta) (hd1 : delta < 1) (hf : 0 < failure) | |
| (v : Grid (I := Fin (dimension A)) K) (draws : EstimatorInput A C K j delta failure) : | |
| (assignmentCount A:β)*(1/2:β)^j/16 β€ (estimateValue A C z K hK hW j delta failure v draws:β) β§ | |
| (estimateValue A C z K hK hW j delta failure v draws:β) β€ 8*assignmentCount A := by | |
| let r := fun a : Fin j => (observedFactor A C z K hK hW j delta failure v draws (some a):β) | |
| let q := (observedFactor A C z K hK hW j delta failure v draws none:β) | |
| have hr := observed_ratio_bounds A C hC z hz K hK hW hB j delta failure hd hf v draws | |
| have hq := observed_correction_bounds A C hC z K hK hW hB j hj delta failure hd hd1 hf v draws | |
| have hrlow : (1/2:β)^j β€ β a,r a := by | |
| have hh := Finset.prod_le_prodβ (s := Finset.univ) | |
| (fun _ _ => by norm_num : β a : Fin j,aβFinset.univ β (0:β) β€ 1/2) | |
| (fun a _ => (hr a).1) | |
| simpa only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] using hh | |
| have hrup : (β a,r a) β€ 1 := by | |
| have hh := Finset.prod_le_prodβ (s := Finset.univ) | |
| (fun a _ => show (0:β) β€ r a from (by have h := (hr a).1; linarith)) (fun a _ => (hr a).2) | |
| simpa only [Finset.prod_const_one] using hh | |
| have hr0 : (0:β) β€ β a,r a := Finset.prod_nonneg (fun a _ => by have h := (hr a).1; linarith) | |
| have hq0 : 0 β€ q := by dsimp only [q]; linarith [hq.1] | |
| have hlow : (1/16:β)*(1/2:β)^j β€ q*(β a,r a) := | |
| mul_le_mul hq.1 hrlow (by positivity) hq0 | |
| have hupp : q*(β a,r a) β€ 8 := by | |
| calc | |
| _ β€ 8*1 := mul_le_mul hq.2 hrup hr0 (by norm_num) | |
| _ = _ := by norm_num | |
| have hMf : (0:β) β€ assignmentCount A := Nat.cast_nonneg _ | |
| have he : (estimateValue A C z K hK hW j delta failure v draws:β)= | |
| (assignmentCount A:β)*(q*β a,r a) := by | |
| simp only [estimateValue,Rat.cast_mul,Rat.cast_natCast,Rat.cast_prod,Fintype.prod_option] | |
| rfl | |
| rw [he] | |
| constructor | |
| Β· have hh := mul_le_mul_of_nonneg_left hlow hMf | |
| nlinarith | |
| Β· have hh := mul_le_mul_of_nonneg_left hupp hMf | |
| nlinarith | |
| theorem estimateValue_positive (A : Instance I J) (C : β) (hC : 0 < C) (z : View A β β) | |
| (hz : BalancedBox.InBox (bounds A) z) (K : β) (hK : 1 β€ K) (hW : 100*A.d*K β€ A.W) | |
| (hB : (K:β)=binWidth A C) (j : β) (hj : j β€ rationalHeight A C) | |
| (delta failure : β) (hd : 0 < delta) (hd1 : delta < 1) (hf : 0 < failure) | |
| (v : Grid (I := Fin (dimension A)) K) (draws : EstimatorInput A C K j delta failure) : | |
| 0 < estimateValue A C z K hK hW j delta failure v draws := by | |
| have hMf : (0:β) < assignmentCount A := by exact_mod_cast assignmentCount_positive A | |
| have hh := (estimateValue_range A C hC z hz K hK hW hB j hj delta failure hd hd1 hf v draws).1 | |
| have hp : (0:β) < (assignmentCount A:β)*(1/2:β)^j/16 := by positivity | |
| exact_mod_cast lt_of_lt_of_le hp hh | |
| end | |
| end ContingencyTables.CompanionOracleDensity | |
| end OAI | |