Samplinglib
Lean gate not recorded for this source state main · ed709a7f320d
test module

Tests.WeightedC1GradientDomain

6 named declarations scanned from Tests/WeightedC1GradientDomain.lean.

Imports
Imported by
Placeholder scan
0 declaration(s) flagged
Gate status
Partial

Declarations

def Tests.WeightedC1GradientDomain.potential Partial Not mapped

No declaration docstring.

private def potential (x : ℝ) : ℝ := (3/8)*x^2 + (1/8)*Real.sin x
theorem Tests.WeightedC1GradientDomain.potential_curvature Partial Not mapped

No declaration docstring.

private theorem potential_curvature :
    ∀ z v : ℝ, (1/(2*(1:ℝ)))*‖v‖^2 ≤ (fderiv ℝ (fderiv ℝ potential) z v) v ∧
      (fderiv ℝ (fderiv ℝ potential) z v) v ≤ ‖v‖^2 := by
  have hder (z : ℝ) : HasDerivAt potential ((3/4)*z+(1/8)*Real.cos z) z := by
    convert (((hasDerivAt_id z).pow 2).const_mul (3/8)).add
      ((Real.hasDerivAt_sin z).const_mul (1/8)) using 1 <;> first | rfl | (simp [potential, Pi.add_apply, mul_comm]; ring)
  have hD : fderiv ℝ potential = fun z =>
      ((3/4)*z+(1/8)*Real.cos z) • ContinuousLinearMap.id ℝ ℝ := by
    funext z
    ext
    rw [fderiv_eq_smul_deriv, (hder z).deriv]
    simp
  have hDD (z v : ℝ) : (fderiv ℝ (fderiv ℝ potential) z v) v =
      ((3/4)-(1/8)*Real.sin z)*v^2 := by
    have hd : HasDerivAt (fun w : ℝ => (3/4)*w+(1/8)*Real.cos w)
        ((3/4)-(1/8)*Real.sin z) z := by
      convert ((hasDerivAt_id z).const_mul (3/4)).add
        ((Real.hasDerivAt_cos z).const_mul (1/8)) using 1 <;> (try dsimp only [id]) <;> first | rfl | ring
    rw [hD, fderiv_eq_smul_deriv,
      (hd.smul_const (ContinuousLinearMap.id ℝ ℝ)).deriv]
    simp
    ring
  intro z v
  rw [hDD]
  simp only [Real.norm_eq_abs, sq_abs]
  constructor <;> nlinarith [Real.sin_le_one z, Real.neg_one_le_sin z, sq_nonneg v]
theorem Tests.WeightedC1GradientDomain.actual_nonquadratic_score_original_domain Partial Not mapped

No declaration docstring.

theorem actual_nonquadratic_score_original_domain :
    let η : ℝ := 1/2
    let μ := (volume : Measure ℝ).tilted (fun x => -potential x)
    let J := Measure.map (fun p : ℝ × ℝ => (p.1,p.1+Real.sqrt η • p.2)) (μ.prod (stdGaussian ℝ))
    let W := fun y u : ℝ => potential ((1/2:ℝ) • (y+u)) + ‖u-y‖^2/(8*η)
    let s := fun y u : ℝ => -(1/2:ℝ) • fderiv ℝ potential ((1/2:ℝ) • (y+u)) -
      (1/(4*η)) • innerSL ℝ (y-u)
    ∃ R S : Kernel ℝ ℝ, IsMarkovKernel R ∧ IsMarkovKernel S ∧
      (J.map Prod.swap).IsCondKernel R ∧
      (∀ y, S y = (R y).map (fun x => (2:ℝ) • x-y)) ∧
      ∀ y, S y = (volume : Measure ℝ).tilted (fun u => -W y u) ∧
        ContDiff ℝ 2 (W y) ∧ Integrable (fun u => Real.exp (-W y u)) ∧
        0 < (∫ u, Real.exp (-W y u)) ∧
        ∃ D : Lp ℝ 2 (S y) →ₗ.[ℝ] Lp ℝ 2 (S y),
          Dense (D.domain : Set (Lp ℝ 2 (S y))) ∧ D.IsClosable ∧ D.closure.IsClosed ∧
          (∀ (u : Lp ℝ 2 (S y)) (v : Lp ℝ 2 (S y)), (u,v) ∈ D.graph ↔
            ∃ f : ℝ → ℝ, ContDiff ℝ ∞ f ∧ HasCompactSupport f ∧
              u =ᵐ[S y] f ∧ v =ᵐ[S y] gradient f) ∧
          (∀ c : ℝ, ∃ u : D.closure.domain,
            (u : Lp ℝ 2 (S y)) =ᵐ[S y] (fun _ => c) ∧ D.closure u=0) ∧
          (∀ u : D.closure.domain, D.closure u=0 ↔
            ∃ c : ℝ, (u : Lp ℝ 2 (S y)) =ᵐ[S y] (fun _ => c)) ∧
          ∀ a : ℝ, ContDiff ℝ 1 (fun u => s y u a) ∧
            (∀ u, ‖gradient (fun z => s y z a) u‖ ≤ ((1/η-(1/2:ℝ))/4)*‖a‖) ∧
            ∃ hp : MemLp (fun u => s y u a) 2 (S y),
              ∃ hq : MemLp (gradient (fun u => s y u a)) 2 (S y),
                (hp.toLp _,hq.toLp _) ∈ D.closure.graph := by
  have hV : ContDiff ℝ 2 potential := by unfold potential; fun_prop
  have hh : ∀ x v : ℝ, ((1/2:ℝ≥0):ℝ)*‖v‖^2 ≤ fderiv ℝ (fderiv ℝ potential) x v v ∧
      fderiv ℝ (fderiv ℝ potential) x v v ≤ ((1:ℝ≥0):ℝ)*‖v‖^2 := by
    intro x v
    simpa using potential_curvature x v
  exact AutoSamplingTheory.ExampleCases.ProximalBPS.ConditionalScoreClosedDomain.conditional_score_closed_gradient_domain
    (α := (1/2:NNReal)) (β := (1:NNReal)) (η := (1/2:ℝ))
    (by norm_num) (by norm_num) hV hh (by norm_num) (by norm_num)
abbrev Tests.WeightedC1GradientDomain.E0 Partial Not mapped

No declaration docstring.

abbrev E0 := EuclideanSpace ℝ (Fin 0)
def Tests.WeightedC1GradientDomain.W0 Partial Not mapped

No declaration docstring.

private def W0 (_ : E0) : ℝ := 7
theorem Tests.WeightedC1GradientDomain.actual_zero_dim_constant_original_domain Partial Not mapped

No declaration docstring.

theorem actual_zero_dim_constant_original_domain :
    let μ := (volume : Measure E0).tilted (fun x => -W0 x)
    μ Set.univ=1 ∧
    ∃ D : Lp ℝ 2 μ →ₗ.[ℝ] Lp E0 2 μ,
      Dense (D.domain : Set (Lp ℝ 2 μ)) ∧ D.IsClosable ∧ D.closure.IsClosed ∧
      (∀ (a : Lp ℝ 2 μ) (H : Lp E0 2 μ), (a,H) ∈ D.graph ↔
        ∃ φ : E0 → ℝ, ContDiff ℝ ∞ φ ∧ HasCompactSupport φ ∧
          a =ᵐ[μ] φ ∧ H =ᵐ[μ] gradient φ) ∧
      (∃ u : D.closure.domain, (u : Lp ℝ 2 μ) =ᵐ[μ] (fun _ => (7:ℝ)) ∧ D.closure u=0) ∧
      ∀ u : D.closure.domain, D.closure u=0 ↔
        ∃ c : ℝ, (u : Lp ℝ 2 μ) =ᵐ[μ] (fun _ => c) := by
  have hW : ContDiff ℝ 1 W0 := contDiff_const
  have hI : Integrable (fun x : E0 => Real.exp (-W0 x)) volume := by
    simpa only [W0] using (integrable_const (Real.exp (-(7:ℝ))) :
      Integrable (fun _ : E0 => Real.exp (-(7:ℝ))) volume)
  let μ := (volume : Measure E0).tilted (fun x => -W0 x)
  have : IsProbabilityMeasure μ := isProbabilityMeasure_tilted hI
  obtain ⟨D,hd,hD,hDc,hgraph⟩ :=
    AutoSamplingTheory.TechnicalLemmas.FunctionalInequalities.WeightedGradient.compact_gradient_closable W0 hW hI
  dsimp only
  exact ⟨measure_univ,D,hd,hD,hDc,hgraph,AutoSamplingTheory.TechnicalLemmas.FunctionalInequalities.WeightedC1GradientDomain.constants_in_closed_gradient μ D hD hgraph 7,
    AutoSamplingTheory.TechnicalLemmas.FunctionalInequalities.GibbsGradientKernelEquality.closed_gradient_zero_iff_ae_constant W0 hW hI D hD hgraph⟩
#print axioms actual_nonquadratic_score_original_domain
#print axioms actual_zero_dim_constant_original_domain

#print axioms AutoSamplingTheory.TechnicalLemmas.FunctionalInequalities.WeightedC1GradientDomain.c1_in_closed_gradient
#print axioms AutoSamplingTheory.TechnicalLemmas.FunctionalInequalities.WeightedC1GradientDomain.constants_in_closed_gradient
#print axioms AutoSamplingTheory.TechnicalLemmas.FunctionalInequalities.GibbsGradientKernelEquality.closed_gradient_zero_iff_ae_constant
#print axioms AutoSamplingTheory.ExampleCases.ProximalBPS.ConditionalScoreClosedDomain.conditional_score_closed_gradient_domain

end Tests.WeightedC1GradientDomain

Complete Lean source

Tests/WeightedC1GradientDomain.lean — full module with imports and context
Download module (.lean)
import AutoSamplingTheory.ExampleCases.ProximalBPS.ConditionalScoreClosedDomain
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv
import Mathlib.Analysis.InnerProductSpace.PiL2
set_option autoImplicit false
noncomputable section
open MeasureTheory Filter InnerProductSpace
open scoped Topology RealInnerProductSpace ContDiff
open ProbabilityTheory
open scoped NNReal
namespace Tests.WeightedC1GradientDomain

private def potential (x : ℝ) : ℝ := (3/8)*x^2 + (1/8)*Real.sin x
private theorem potential_curvature :
    ∀ z v : ℝ, (1/(2*(1:ℝ)))*‖v‖^2 ≤ (fderiv ℝ (fderiv ℝ potential) z v) v ∧
      (fderiv ℝ (fderiv ℝ potential) z v) v ≤ ‖v‖^2 := by
  have hder (z : ℝ) : HasDerivAt potential ((3/4)*z+(1/8)*Real.cos z) z := by
    convert (((hasDerivAt_id z).pow 2).const_mul (3/8)).add
      ((Real.hasDerivAt_sin z).const_mul (1/8)) using 1 <;> first | rfl | (simp [potential, Pi.add_apply, mul_comm]; ring)
  have hD : fderiv ℝ potential = fun z =>
      ((3/4)*z+(1/8)*Real.cos z) • ContinuousLinearMap.id ℝ ℝ := by
    funext z
    ext
    rw [fderiv_eq_smul_deriv, (hder z).deriv]
    simp
  have hDD (z v : ℝ) : (fderiv ℝ (fderiv ℝ potential) z v) v =
      ((3/4)-(1/8)*Real.sin z)*v^2 := by
    have hd : HasDerivAt (fun w : ℝ => (3/4)*w+(1/8)*Real.cos w)
        ((3/4)-(1/8)*Real.sin z) z := by
      convert ((hasDerivAt_id z).const_mul (3/4)).add
        ((Real.hasDerivAt_cos z).const_mul (1/8)) using 1 <;> (try dsimp only [id]) <;> first | rfl | ring
    rw [hD, fderiv_eq_smul_deriv,
      (hd.smul_const (ContinuousLinearMap.id ℝ ℝ)).deriv]
    simp
    ring
  intro z v
  rw [hDD]
  simp only [Real.norm_eq_abs, sq_abs]
  constructor <;> nlinarith [Real.sin_le_one z, Real.neg_one_le_sin z, sq_nonneg v]





theorem actual_nonquadratic_score_original_domain :
    let η : ℝ := 1/2
    let μ := (volume : Measure ℝ).tilted (fun x => -potential x)
    let J := Measure.map (fun p : ℝ × ℝ => (p.1,p.1+Real.sqrt η • p.2)) (μ.prod (stdGaussian ℝ))
    let W := fun y u : ℝ => potential ((1/2:ℝ) • (y+u)) + ‖u-y‖^2/(8*η)
    let s := fun y u : ℝ => -(1/2:ℝ) • fderiv ℝ potential ((1/2:ℝ) • (y+u)) -
      (1/(4*η)) • innerSL ℝ (y-u)
    ∃ R S : Kernel ℝ ℝ, IsMarkovKernel R ∧ IsMarkovKernel S ∧
      (J.map Prod.swap).IsCondKernel R ∧
      (∀ y, S y = (R y).map (fun x => (2:ℝ) • x-y)) ∧
      ∀ y, S y = (volume : Measure ℝ).tilted (fun u => -W y u) ∧
        ContDiff ℝ 2 (W y) ∧ Integrable (fun u => Real.exp (-W y u)) ∧
        0 < (∫ u, Real.exp (-W y u)) ∧
        ∃ D : Lp ℝ 2 (S y) →ₗ.[ℝ] Lp ℝ 2 (S y),
          Dense (D.domain : Set (Lp ℝ 2 (S y))) ∧ D.IsClosable ∧ D.closure.IsClosed ∧
          (∀ (u : Lp ℝ 2 (S y)) (v : Lp ℝ 2 (S y)), (u,v) ∈ D.graph ↔
            ∃ f : ℝ → ℝ, ContDiff ℝ ∞ f ∧ HasCompactSupport f ∧
              u =ᵐ[S y] f ∧ v =ᵐ[S y] gradient f) ∧
          (∀ c : ℝ, ∃ u : D.closure.domain,
            (u : Lp ℝ 2 (S y)) =ᵐ[S y] (fun _ => c) ∧ D.closure u=0) ∧
          (∀ u : D.closure.domain, D.closure u=0 ↔
            ∃ c : ℝ, (u : Lp ℝ 2 (S y)) =ᵐ[S y] (fun _ => c)) ∧
          ∀ a : ℝ, ContDiff ℝ 1 (fun u => s y u a) ∧
            (∀ u, ‖gradient (fun z => s y z a) u‖ ≤ ((1/η-(1/2:ℝ))/4)*‖a‖) ∧
            ∃ hp : MemLp (fun u => s y u a) 2 (S y),
              ∃ hq : MemLp (gradient (fun u => s y u a)) 2 (S y),
                (hp.toLp _,hq.toLp _) ∈ D.closure.graph := by
  have hV : ContDiff ℝ 2 potential := by unfold potential; fun_prop
  have hh : ∀ x v : ℝ, ((1/2:ℝ≥0):ℝ)*‖v‖^2 ≤ fderiv ℝ (fderiv ℝ potential) x v v ∧
      fderiv ℝ (fderiv ℝ potential) x v v ≤ ((1:ℝ≥0):ℝ)*‖v‖^2 := by
    intro x v
    simpa using potential_curvature x v
  exact AutoSamplingTheory.ExampleCases.ProximalBPS.ConditionalScoreClosedDomain.conditional_score_closed_gradient_domain
    (α := (1/2:NNReal)) (β := (1:NNReal)) (η := (1/2:ℝ))
    (by norm_num) (by norm_num) hV hh (by norm_num) (by norm_num)

abbrev E0 := EuclideanSpace ℝ (Fin 0)
private def W0 (_ : E0) : ℝ := 7
theorem actual_zero_dim_constant_original_domain :
    let μ := (volume : Measure E0).tilted (fun x => -W0 x)
    μ Set.univ=1 ∧
    ∃ D : Lp ℝ 2 μ →ₗ.[ℝ] Lp E0 2 μ,
      Dense (D.domain : Set (Lp ℝ 2 μ)) ∧ D.IsClosable ∧ D.closure.IsClosed ∧
      (∀ (a : Lp ℝ 2 μ) (H : Lp E0 2 μ), (a,H) ∈ D.graph ↔
        ∃ φ : E0 → ℝ, ContDiff ℝ ∞ φ ∧ HasCompactSupport φ ∧
          a =ᵐ[μ] φ ∧ H =ᵐ[μ] gradient φ) ∧
      (∃ u : D.closure.domain, (u : Lp ℝ 2 μ) =ᵐ[μ] (fun _ => (7:ℝ)) ∧ D.closure u=0) ∧
      ∀ u : D.closure.domain, D.closure u=0 ↔
        ∃ c : ℝ, (u : Lp ℝ 2 μ) =ᵐ[μ] (fun _ => c) := by
  have hW : ContDiff ℝ 1 W0 := contDiff_const
  have hI : Integrable (fun x : E0 => Real.exp (-W0 x)) volume := by
    simpa only [W0] using (integrable_const (Real.exp (-(7:ℝ))) :
      Integrable (fun _ : E0 => Real.exp (-(7:ℝ))) volume)
  let μ := (volume : Measure E0).tilted (fun x => -W0 x)
  have : IsProbabilityMeasure μ := isProbabilityMeasure_tilted hI
  obtain ⟨D,hd,hD,hDc,hgraph⟩ :=
    AutoSamplingTheory.TechnicalLemmas.FunctionalInequalities.WeightedGradient.compact_gradient_closable W0 hW hI
  dsimp only
  exact ⟨measure_univ,D,hd,hD,hDc,hgraph,AutoSamplingTheory.TechnicalLemmas.FunctionalInequalities.WeightedC1GradientDomain.constants_in_closed_gradient μ D hD hgraph 7,
    AutoSamplingTheory.TechnicalLemmas.FunctionalInequalities.GibbsGradientKernelEquality.closed_gradient_zero_iff_ae_constant W0 hW hI D hD hgraph⟩
#print axioms actual_nonquadratic_score_original_domain
#print axioms actual_zero_dim_constant_original_domain

#print axioms AutoSamplingTheory.TechnicalLemmas.FunctionalInequalities.WeightedC1GradientDomain.c1_in_closed_gradient
#print axioms AutoSamplingTheory.TechnicalLemmas.FunctionalInequalities.WeightedC1GradientDomain.constants_in_closed_gradient
#print axioms AutoSamplingTheory.TechnicalLemmas.FunctionalInequalities.GibbsGradientKernelEquality.closed_gradient_zero_iff_ae_constant
#print axioms AutoSamplingTheory.ExampleCases.ProximalBPS.ConditionalScoreClosedDomain.conditional_score_closed_gradient_domain

end Tests.WeightedC1GradientDomain