roseking's picture
Add lean source and binary files (part 16)
159357f verified
Raw History Blame Contribute Delete
6.95 kB
17
lemma compactNoiseWeight_eq_glue (u : ℝ) :
    compactNoiseWeight u = expNegInvGlue (1-u^2) := by
proof · 4 lines
  have hh : |u| < 1 ↔ ¬ 1-u^2 ≤ 0 := by
    rw [not_le, sub_pos, sq_lt_one_iff_abs_lt_one]
  simp only [compactNoiseWeight, expNegInvGlue, hh]
  split_ifs <;> rfl
24
lemma compactNoiseWeight_contDiff {n : ℕ∞} : ContDiff ℝ n compactNoiseWeight := by
proof · 2 lines
  simp_rw [funext compactNoiseWeight_eq_glue]
  exact expNegInvGlue.contDiff.comp (contDiff_const.sub (contDiff_id.pow 2))
28
lemma compactNoiseDensity_contDiff {n : ℕ∞} : ContDiff ℝ n compactNoiseDensity :=
proof · 1 line
  contDiff_const.mul compactNoiseWeight_contDiff
31
lemma compactNoiseWeight_hasDerivAt (u : ℝ) :
    HasDerivAt compactNoiseWeight (compactNoiseScore u * compactNoiseWeight u) u := by
proof · 12 lines
  have hc : HasDerivAt expNegInvGlue ((1-u^2)⁻¹^2 * expNegInvGlue (1-u^2)) (1-u^2) := by
    simpa using expNegInvGlue.hasDerivAt_polynomial_eval_inv_mul 1 (1-u^2)
  have hh := hc.comp u ((hasDerivAt_const u 1).sub ((hasDerivAt_id u).pow 2))
  simp only [Nat.cast_ofNat, mul_one, zero_sub, id_eq, Nat.reduceSub, pow_one] at hh
  have he : ((((1-u^2)⁻¹^2 * expNegInvGlue (1-u^2)) * -(2*u))) =
      compactNoiseScore u * compactNoiseWeight u := by
    rw [← compactNoiseWeight_eq_glue]
    by_cases hu : |u| < 1
    · simp only [compactNoiseScore, ite_eq_left hu, div_eq_mul_inv, inv_pow]; ring
    · simp [compactNoiseScore, compactNoiseWeight, hu]
  rw [he] at hh
  simpa only [Function.comp_def, Pi.sub_apply, Pi.pow_apply, id_eq, ← compactNoiseWeight_eq_glue] using hh
46
lemma compactNoiseDensity_hasDerivAt (u : ℝ) :
    HasDerivAt compactNoiseDensity (compactNoiseScore u * compactNoiseDensity u) u := by
proof · 3 lines
  convert! (compactNoiseWeight_hasDerivAt u).const_mul compactNoiseNormalizer using 1
  dsimp [compactNoiseDensity]
  ring
52
lemma compactNoiseWeight_compactSupport : HasCompactSupport compactNoiseWeight := by
proof · 7 lines
  apply HasCompactSupport.intro (isCompact_Icc : IsCompact (Icc (-1:ℝ) 1))
  intro u hu
  have hh : ¬ |u| < 1 := by
    intro h
    apply hu
    exact ⟨(abs_lt.mp h).1.le, (abs_lt.mp h).2.le⟩
  simp [compactNoiseWeight, hh]
61
lemma compactNoiseDensity_compactSupport : HasCompactSupport compactNoiseDensity :=
proof · 1 line
  compactNoiseWeight_compactSupport.mul_left
69
def compactNoiseKernel {ι : Type*} [Fintype ι] (u : ι → ℝ) : ℝ :=
body · 1 line
  ∏ i, compactNoiseDensity (u i)
72
lemma compactNoiseKernel_nonneg {ι : Type*} [Fintype ι] (u : ι → ℝ) :
    0 ≤ compactNoiseKernel u := prod_nonneg (fun _ _ => compactNoiseDensity_nonneg _)
75
lemma compactNoiseKernel_even {ι : Type*} [Fintype ι] (u : ι → ℝ) :
    compactNoiseKernel (-u) = compactNoiseKernel u := by
proof · 1 line
  simp only [compactNoiseKernel, Pi.neg_apply, compactNoiseDensity, compactNoiseWeight_even]
79
lemma compactNoiseKernel_contDiff {ι : Type*} [Fintype ι] {n : ℕ∞} :
    ContDiff ℝ n (compactNoiseKernel : (ι → ℝ) → ℝ) := by
proof · 1 line
  exact contDiff_prod (fun i _ => compactNoiseDensity_contDiff.comp (contDiff_apply ℝ ℝ i))
83
lemma compactNoiseKernel_integrable {ι : Type*} [Fintype ι] :
    Integrable (compactNoiseKernel : (ι → ℝ) → ℝ) := by
proof · 1 line
  exact Integrable.fintype_prod (fun _ => compactNoiseDensity_integrable)
87
lemma compactNoiseKernel_compactSupport {ι : Type*} [Fintype ι] :
    HasCompactSupport (compactNoiseKernel : (ι → ℝ) → ℝ) := by
proof · 11 lines
  classical
  apply HasCompactSupport.intro (isCompact_univ_pi (fun _ : ι => isCompact_Icc (a := (-1:ℝ)) (b := 1)))
  intro u hu
  simp only [mem_univ_pi] at hu
  push Not at hu
  obtain ⟨i, hi⟩ := hu
  apply prod_eq_zero (mem_univ i)
  have hh : ¬|u i| < 1 := by
    intro h
    exact hi ⟨(abs_lt.mp h).1.le, (abs_lt.mp h).2.le⟩
  simp [compactNoiseDensity, compactNoiseWeight, hh]
101
lemma compactNoiseLaw_apply {s : Set ℝ} (hs : MeasurableSet s) :
    compactNoiseLaw s = ENNReal.ofReal (∫ u in s, compactNoiseDensity u) := by
proof · 3 lines
  rw [compactNoiseLaw, withDensity_apply _ hs]
  exact (ofReal_integral_eq_lintegral_ofReal compactNoiseDensity_integrable.integrableOn
    (ae_of_all _ compactNoiseDensity_nonneg)).symm
107
lemma compactNoiseLaw_pi {ι : Type*} [Fintype ι] :
    Measure.pi (fun _ : ι => compactNoiseLaw) =
      volume.withDensity (fun u : ι → ℝ => ENNReal.ofReal (compactNoiseKernel u)) := by
proof · 9 lines
  apply Measure.pi_eq
  intro s hs
  rw [withDensity_apply _ (MeasurableSet.univ_pi hs),
    ← ofReal_integral_eq_lintegral_ofReal compactNoiseKernel_integrable.integrableOn
      (ae_of_all _ compactNoiseKernel_nonneg)]
  simp only [volume_pi, Measure.restrict_pi_pi, compactNoiseKernel,
    integral_fintype_prod_eq_prod, compactNoiseLaw_apply (hs _)]
  exact ENNReal.ofReal_prod_of_nonneg (fun i _ =>
    integral_nonneg (fun _ => compactNoiseDensity_nonneg _))
120
lemma compactNoiseLaw_pi_integral {ι : Type*} [Fintype ι] (f : (ι → ℝ) → ℝ) :
    (∫ u, f u ∂Measure.pi (fun _ : ι => compactNoiseLaw)) =
      ∫ u, compactNoiseKernel u * f u := by
proof · 4 lines
  rw [compactNoiseLaw_pi, integral_withDensity_eq_integral_toReal_smul
    (compactNoiseKernel_contDiff (n := 0)).continuous.measurable.ennreal_ofReal
    (ae_of_all _ (fun _ => ENNReal.ofReal_lt_top))]
  simp only [ENNReal.toReal_ofReal (compactNoiseKernel_nonneg _), smul_eq_mul]
128
lemma compactNoiseKernel_hasFDerivAt {ι : Type*} [Fintype ι] (u : ι → ℝ) :
    HasFDerivAt compactNoiseKernel
      (∑ i, (compactNoiseScore (u i) * compactNoiseKernel u) •
        (ContinuousLinearMap.proj i : (ι → ℝ) →L[ℝ] ℝ)) u := by
proof · 14 lines
  classical
  have hi (i : ι) : HasFDerivAt (fun v : ι → ℝ => compactNoiseDensity (v i))
      ((compactNoiseScore (u i) * compactNoiseDensity (u i)) •
        (ContinuousLinearMap.proj i : (ι → ℝ) →L[ℝ] ℝ)) u :=
    by
      convert! HasDerivAt.comp_hasFDerivAt (f := fun v : ι → ℝ => v i) u
        (compactNoiseDensity_hasDerivAt (u i)) (ContinuousLinearMap.proj i : (ι → ℝ) →L[ℝ] ℝ).hasFDerivAt using 1
  convert! HasFDerivAt.finsetProd (u := univ) (fun i _ => hi i) using 1
  apply sum_congr rfl
  intro i _
  rw [smul_smul]
  congr 1
  rw [mul_left_comm, prod_erase_mul _ _ (mem_univ i)]
  rfl
147
lemma compactNoiseKernel_fderiv_apply {ι : Type*} [Fintype ι] (u v : ι → ℝ) :
    fderiv ℝ compactNoiseKernel u v =
      compactNoiseKernel u * ∑ i, compactNoiseScore (u i) * v i := by
proof · 6 lines
  rw [(compactNoiseKernel_hasFDerivAt u).fderiv]
  simp only [_root_.sum_apply, smul_apply,
    ContinuousLinearMap.proj_apply, smul_eq_mul, mul_sum]
  apply sum_congr rfl
  intro i _
  ring