math / data /lean /OAI /Analysis /FiniteFactor /Sampling /Cancellation.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
5.71 kB
import OAI.Analysis.FiniteFactor.Sampling.IntegratedCorrelation
namespace OAI
namespace FiniteFactor
open MeasureTheory Filter Finset
open scoped Classical
noncomputable section
/-- Exact finite-average expansion, before bounding or discarding any term. -/
theorem sampling_average_square_expansion {ΞΉ Ξ© : Type*} [MeasurableSpace Ξ©]
(ΞΌ : Measure Ξ©) (S : Finset ΞΉ) (f : ΞΉ β†’ Ξ© β†’ ℝ) (g : Ξ© β†’ ℝ)
(hpair : βˆ€ n ∈ S, βˆ€ k ∈ S, Integrable (fun x => f n x*f k x) ΞΌ)
(hmix : βˆ€ n ∈ S, Integrable (fun x => f n x*g x) ΞΌ)
(hg : Integrable (fun x => g x^2) ΞΌ) :
(∫ x, ((βˆ‘ n ∈ S, f n x)/(S.card : ℝ)-g x)^2 βˆ‚ΞΌ) =
(βˆ‘ n ∈ S, βˆ‘ k ∈ S, ∫ x, f n x*f k x βˆ‚ΞΌ)/(S.card : ℝ)^2 -
2*(βˆ‘ n ∈ S, ∫ x, f n x*g x βˆ‚ΞΌ)/(S.card : ℝ)+(∫ x, g x^2 βˆ‚ΞΌ) := by
have he (x : Ξ©) : ((βˆ‘ n ∈ S, f n x)/(S.card : ℝ)-g x)^2 =
(βˆ‘ n ∈ S, βˆ‘ k ∈ S, f n x*f k x)/(S.card : ℝ)^2 -
2*(βˆ‘ n ∈ S, f n x*g x)/(S.card : ℝ)+g x^2 := by
have hsq : (βˆ‘ n ∈ S, βˆ‘ k ∈ S, f n x*f k x) = (βˆ‘ n ∈ S, f n x)^2 := by
rw [pow_two]; simp_rw [Finset.sum_mul,Finset.mul_sum]
rw [hsq,← Finset.sum_mul]
ring
have hpi := integrable_finsetSum S (fun n hn => integrable_finsetSum S (fun k hk => hpair n hn k hk))
have hmi := integrable_finsetSum S (fun n hn => hmix n hn)
have hiP : Integrable (fun x => (βˆ‘ n ∈ S, βˆ‘ k ∈ S, f n x*f k x)/(S.card : ℝ)^2) ΞΌ := hpi.div_const _
have hiM : Integrable (fun x => 2*(βˆ‘ n ∈ S, f n x*g x)/(S.card : ℝ)) ΞΌ := (hmi.const_mul 2).div_const _
have hiSub : Integrable (fun x => (βˆ‘ n ∈ S, βˆ‘ k ∈ S, f n x*f k x)/(S.card : ℝ)^2 -
2*(βˆ‘ n ∈ S, f n x*g x)/(S.card : ℝ)) ΞΌ := hiP.sub hiM
have hpis : (∫ x, βˆ‘ n ∈ S, βˆ‘ k ∈ S, f n x*f k x βˆ‚ΞΌ) =
βˆ‘ n ∈ S, βˆ‘ k ∈ S, ∫ x, f n x*f k x βˆ‚ΞΌ := by
rw [integral_finsetSum S (fun n hn => integrable_finsetSum S (fun k hk => hpair n hn k hk))]
apply sum_congr rfl
intro n hn
exact integral_finsetSum S (fun k hk => hpair n hn k hk)
simp_rw [he]
rw [integral_add hiSub hg,integral_sub hiP hiM,integral_div,integral_div,integral_const_mul,
hpis,integral_finsetSum S (fun n hn => hmix n hn)]
/-- Integrability of the full error follows from the same finite expansion. -/
theorem sampling_average_square_integrable {ΞΉ Ξ© : Type*} [MeasurableSpace Ξ©]
(ΞΌ : Measure Ξ©) (S : Finset ΞΉ) (f : ΞΉ β†’ Ξ© β†’ ℝ) (g : Ξ© β†’ ℝ)
(hpair : βˆ€ n ∈ S, βˆ€ k ∈ S, Integrable (fun x => f n x*f k x) ΞΌ)
(hmix : βˆ€ n ∈ S, Integrable (fun x => f n x*g x) ΞΌ)
(hg : Integrable (fun x => g x^2) ΞΌ) :
Integrable (fun x => ((βˆ‘ n ∈ S, f n x)/(S.card : ℝ)-g x)^2) ΞΌ := by
have hpi := integrable_finsetSum S (fun n hn => integrable_finsetSum S (fun k hk => hpair n hn k hk))
have hmi := integrable_finsetSum S (fun n hn => hmix n hn)
have h : Integrable (fun x => (βˆ‘ n ∈ S, βˆ‘ k ∈ S, f n x*f k x)/(S.card : ℝ)^2 -
2*(βˆ‘ n ∈ S, f n x*g x)/(S.card : ℝ)+g x^2) ΞΌ :=
((hpi.div_const _).sub ((hmi.const_mul 2).div_const _)).add hg
apply h.congr
apply Eventually.of_forall
intro x
have hsq : (βˆ‘ n ∈ S, βˆ‘ k ∈ S, f n x*f k x) = (βˆ‘ n ∈ S, f n x)^2 := by
rw [pow_two]; simp_rw [Finset.sum_mul,Finset.mul_sum]
dsimp only
rw [hsq,← Finset.sum_mul]
ring
/-- The distinct-pair and mixed main terms cancel to -A/P. Since A is
nonnegative, the surviving upper bound is the actual diagonal term plus 3Ξ΅. -/
theorem sampling_finite_cancellation {ΞΉ : Type*} (S : Finset ΞΉ) (hS : S.Nonempty)
(B : ΞΉ β†’ ΞΉ β†’ ℝ) (M : ΞΉ β†’ ℝ) (A Ξ΅ : ℝ) (hA : 0 ≀ A) (hΞ΅ : 0 ≀ Ξ΅)
(hpair : βˆ€ n ∈ S, βˆ€ k ∈ S, n β‰  k β†’ |B n k-A| ≀ Ξ΅)
(hmix : βˆ€ n ∈ S, |M n-A| ≀ Ξ΅) :
(βˆ‘ n ∈ S, βˆ‘ k ∈ S, B n k)/(S.card : ℝ)^2 -
2*(βˆ‘ n ∈ S, M n)/(S.card : ℝ)+A ≀
(βˆ‘ n ∈ S, B n n)/(S.card : ℝ)^2+3*Ξ΅ := by
let N : ℝ := S.card
have hN : 0 < N := by dsimp [N]; exact_mod_cast hS.card_pos
have hN1 : 1 ≀ N := by dsimp [N]; exact_mod_cast (show 1 ≀ S.card from hS.card_pos)
have hp (n : ι) (hn : n ∈ S) :
(βˆ‘ k ∈ S, B n k) ≀ B n n+(N-1)*(A+Ξ΅) := by
have hoff : (βˆ‘ k ∈ S.erase n, B n k) ≀ ((S.erase n).card : ℝ)*(A+Ξ΅) := by
calc
_ ≀ βˆ‘ _k ∈ S.erase n, (A+Ξ΅) := sum_le_sum (fun k hk => by
have hmem := mem_erase.mp hk
have hb := (abs_le.mp (hpair n hn k hmem.2 (Ne.symm hmem.1))).2
linarith)
_ = _ := by simp; ring
have hc : ((S.erase n).card : ℝ) = N-1 := by
rw [card_erase_of_mem hn,Nat.cast_sub (by exact hS.card_pos),Nat.cast_one]
rw [hc] at hoff
have he := sum_erase_add S (fun k => B n k) hn
linarith
have hpall : (βˆ‘ n ∈ S, βˆ‘ k ∈ S, B n k) ≀
(βˆ‘ n ∈ S, B n n)+N*(N-1)*(A+Ξ΅) := by
calc
_ ≀ βˆ‘ n ∈ S, (B n n+(N-1)*(A+Ξ΅)) := sum_le_sum hp
_ = _ := by rw [sum_add_distrib]; simp [N]; ring
have hmall : N*(A-Ξ΅) ≀ βˆ‘ n ∈ S, M n := by
calc
_ = βˆ‘ _n ∈ S, (A-Ξ΅) := by simp [N]; ring
_ ≀ _ := sum_le_sum (fun n hn => by have hh := (abs_le.mp (hmix n hn)).1; linarith)
change _/N^2-2*_/N+A ≀ _/N^2+3*Ξ΅
have hpdiv := div_le_div_of_nonneg_right hpall (sq_nonneg N)
have hmdiv := div_le_div_of_nonneg_right hmall hN.le
have hcancel : ((βˆ‘ n ∈ S, B n n)+N*(N-1)*(A+Ξ΅))/N^2-
2*(N*(A-Ξ΅))/N+A =
(βˆ‘ n ∈ S, B n n)/N^2+3*Ξ΅-(A+Ξ΅)/N := by field_simp; ring
have hnneg : 0 ≀ (A+Ξ΅)/N := div_nonneg (add_nonneg hA hΞ΅) hN.le
simp only [mul_div_assoc] at hmdiv hcancel ⊒
nlinarith
end
end FiniteFactor
end OAI