Download data/lean/OAI/Combinatorics/EditApproximation/Probability/ThresholdMoments.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 5.78 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Probability/ThresholdMoments.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/EditApproximation/Probability/ThresholdMoments.lean
-
curl -L -o ThresholdMoments.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Probability/ThresholdMoments.lean
5.78 kB
| import OAI.Combinatorics.EditApproximation.Geometry.Seed | |
| namespace OAI | |
| /-! | |
| # Discrete threshold moments | |
| The initial estimator samples an integer uniformly from `1, β¦, B`. | |
| The finite count below proves its rounding bias exactly; no continuous | |
| threshold distribution is substituted for the executable sampler. | |
| -/ | |
| namespace EditApproximation | |
| open Finset | |
| theorem threshold_count (B : β) (scale value : β) | |
| (hB : 0 < B) (hscale : 0 < scale) (hvalue : 0 β€ value) (hupper : value < scale) : | |
| ((Icc 1 B).filter fun (r : β) => scale * (r : β) / B β€ value).card = | |
| β(B : β) * value / scaleββ := by | |
| have hBr : (0 : β) < B := by exact_mod_cast hB | |
| have hq : 0 β€ (B : β) * value / scale := by positivity | |
| have hqB : (B : β) * value / scale < B := by | |
| apply (div_lt_iffβ hscale).2 | |
| nlinarith | |
| have hfloor : β(B : β) * value / scaleββ < B := (Nat.floor_lt hq).2 hqB | |
| have hiff (r : β) : scale * r / B β€ value β r β€ β(B : β) * value / scaleββ := by | |
| rw [Nat.le_floor_iff hq, div_le_iffβ hBr, le_div_iffβ hscale] | |
| constructor <;> intro h <;> nlinarith | |
| have hfilter : (Icc 1 B).filter (fun (r : β) => scale * (r : β) / B β€ value) = | |
| Icc 1 β(B : β) * value / scaleββ := by | |
| ext r | |
| simp only [mem_filter, mem_Icc, hiff] | |
| constructor | |
| Β· intro h | |
| exact β¨h.1.1, h.2β© | |
| Β· intro h | |
| exact β¨β¨h.1, h.2.trans hfloor.leβ©, h.2β© | |
| rw [hfilter] | |
| simp only [Nat.card_Icc, Nat.add_sub_cancel] | |
| /-- Exact discrete first moment below the scale; dividing the sum by `B` | |
| gives `scale * floor(B * value / scale) / B`. -/ | |
| theorem threshold_sum (B : β) (scale value : β) | |
| (hB : 0 < B) (hscale : 0 < scale) (hvalue : 0 β€ value) (hupper : value < scale) : | |
| (β r β Icc 1 B, thresholdContribution (scale * r / B) scale value) = | |
| (β(B : β) * value / scaleββ : β) * scale := by | |
| have hpoint (r : β) : thresholdContribution (scale * r / B) scale value = | |
| if scale * r / B β€ value then scale else 0 := by | |
| simp only [thresholdContribution, max_eq_right hupper.le] | |
| simp_rw [hpoint] | |
| rw [β sum_filter] | |
| simp only [sum_const, nsmul_eq_mul, | |
| threshold_count B scale value hB hscale hvalue hupper] | |
| /-- Bias bound used in the coarse estimator: the discrete mean is below | |
| the true argument by at most one grid unit. -/ | |
| theorem threshold_bias (B : β) (scale value : β) | |
| (hB : 0 < B) (hscale : 0 < scale) (hvalue : 0 β€ value) (hupper : value < scale) : | |
| 0 β€ value - (β r β Icc 1 B, | |
| thresholdContribution (scale * r / B) scale value) / B β§ | |
| value - (β r β Icc 1 B, | |
| thresholdContribution (scale * r / B) scale value) / B β€ scale / B := by | |
| rw [threshold_sum B scale value hB hscale hvalue hupper] | |
| have hBr : (0 : β) < B := by exact_mod_cast hB | |
| have hq : 0 β€ (B : β) * value / scale := by positivity | |
| have hflo := Nat.floor_le hq | |
| have hfhi := Nat.lt_floor_add_one ((B : β) * value / scale) | |
| have hl := (le_div_iffβ hscale).1 hflo | |
| have hh := (div_lt_iffβ hscale).1 hfhi | |
| constructor | |
| Β· apply sub_nonneg.mpr | |
| exact (div_le_iffβ hBr).2 (by nlinarith) | |
| Β· apply (le_div_iffβ hBr).2 | |
| have hid : (value - (β(B : β) * value / scaleββ : β) * scale / B) * B = | |
| value * B - (β(B : β) * value / scaleββ : β) * scale := by | |
| field_simp | |
| rw [hid] | |
| nlinarith | |
| theorem uniform_centered_square_identity {ΞΉ : Type*} (samples : Finset ΞΉ) | |
| (value : ΞΉ β β) (hcard : 0 < samples.card) : | |
| (β i β samples, (value i - (β j β samples, value j) / samples.card) ^ 2) / | |
| samples.card = | |
| (β i β samples, value i ^ 2) / samples.card - | |
| ((β i β samples, value i) / samples.card) ^ 2 := by | |
| let mean := (β i β samples, value i) / samples.card | |
| have hcardr : (0 : β) < samples.card := by exact_mod_cast hcard | |
| have hexpand : (β i β samples, (value i - mean) ^ 2) = | |
| (β i β samples, value i ^ 2) - 2 * mean * (β i β samples, value i) + | |
| (samples.card : β) * mean ^ 2 := by | |
| calc | |
| _ = β i β samples, (value i ^ 2 - 2 * mean * value i + mean ^ 2) := | |
| sum_congr rfl fun _ _ => by ring | |
| _ = _ := by | |
| rw [sum_add_distrib, sum_sub_distrib, β mul_sum, sum_const, nsmul_eq_mul] | |
| change (β i β samples, (value i - mean) ^ 2) / samples.card = _ | |
| rw [hexpand] | |
| dsimp [mean] | |
| field_simp | |
| ring | |
| /-- The centered second moment of the actual finite threshold sampler is | |
| at most `scale * value`, as used in the Bernstein variance proxy. -/ | |
| theorem threshold_variance_bound (B : β) (scale value : β) | |
| (hB : 0 < B) (hscale : 0 < scale) (hvalue : 0 β€ value) (hupper : value < scale) : | |
| (β r β Icc 1 B, | |
| (thresholdContribution (scale * r / B) scale value - | |
| (β s β Icc 1 B, thresholdContribution (scale * s / B) scale value) / B) ^ 2) / B β€ | |
| scale * value := by | |
| have hcard : (Icc 1 B).card = B := by simp only [Nat.card_Icc, Nat.add_sub_cancel] | |
| have hvariance := uniform_centered_square_identity (Icc 1 B) | |
| (fun r => thresholdContribution (scale * r / B) scale value) (by omega) | |
| rw [hcard] at hvariance | |
| rw [hvariance] | |
| have hpoint (r : β) : thresholdContribution (scale * r / B) scale value ^ 2 = | |
| scale * thresholdContribution (scale * r / B) scale value := by | |
| simp only [thresholdContribution, max_eq_right hupper.le] | |
| split_ifs <;> ring | |
| simp_rw [hpoint] | |
| rw [β mul_sum, mul_div_assoc] | |
| have hmean := (threshold_bias B scale value hB hscale hvalue hupper).1 | |
| have hscaled := mul_le_mul_of_nonneg_left (sub_nonneg.mp hmean) hscale.le | |
| nlinarith [sq_nonneg ((β r β Icc 1 B, | |
| thresholdContribution (scale * r / B) scale value) / B)] | |
| end EditApproximation | |
| end OAI | |