Samplinglib
Lean gate not recorded for this source state main · 9bb7a7394ab0

QuadraticFeatureRisk: mathematical reading route

Read the statements and derivations in source order. Every result has its own optional Lean statement and proof. Source assumptions, library reuse and unproved boundaries are kept explicit.

  1. Differentiate a moving feature and scale the risk
  2. A literal finite-average risk equals its L² norm
  3. Construct the empirical law and evaluate its actual risk
  4. One indexed replacement has an exact quadratic remainder
  5. Integrate the quadratic potential before taking the remainder
  6. A true joint-data risk has a positive empirical replacement budget
Samplinglib mathematical lesson

Differentiate a moving feature and scale the risk

AutoSamplingTheory.TechnicalLemmas.Analysis.QuadraticFeatureRisk.empirical_squared_feature_risk_derivatives · theorem · Teaching coverage

Read this first

Mathematical statement

Let H be a real inner-product normed space, with no completeness assumption. Let N be a positive natural number, lambda any real number, phi:R→H, and a,y,v in H. At a real time t assume the genuine derivative of phi is v. Then s↦||(a+phi(s))/N-y||² has derivative (2/N) inner((a+phi(t))/N-y,v) at t. Multiplying that risk by N/lambda gives derivative (2/lambda) times the same inner product. All divisions are real totalized divisions; lambda=0 is an algebraic zero-scaling case, not a temperature model.

\[R(s)=\|N^{-1}(a+\phi(s))-y\|^2,\quad R\prime(t)=\frac2N\langle N^{-1}(a+\phi(t))-y,v\rangle,\quad (NR/\lambda)\prime(t)=\frac2\lambda\langle N^{-1}(a+\phi(t))-y,v\rangle.\]
Lean statement · empirical_squared_feature_risk_derivatives

Let H be a real inner-product normed space, with no completeness assumption. Let N be a positive natural number, lambda any real number, phi:R->H, and a,y,v in H. At a real time t assume the genuine derivative of phi is v. Then s↦||(a+phi(s))/N-y||² has derivative (2/N) inner((a+phi(t))/N-y,v) at t. Multiplying that risk by N/lambda gives derivative (2/lambda) times the same inner product. All divisions are real totalized divisions; lambda=0 is an algebraic zero-scaling case, not a temperature model.

Braces mark parameters Lean can infer; square brackets request structures such as a measurable space or probability measure. Named hypotheses are mathematical premises, not facts established by this declaration. Section parameters are described in the mathematical hypotheses above; the module link retains their exact source context.

theorem empirical_squared_feature_risk_derivatives
    {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H]
    {N : ℕ} (hN : 0 < N) (lambda : ℝ)
    {phi : ℝ → H} {v a y : H} {t : ℝ} (hphi : HasDerivAt phi v t) :
    HasDerivAt (fun s => ‖(N : ℝ)⁻¹ • (a + phi s) - y‖ ^ 2)
      ((2 / (N : ℝ)) * ⟪(N : ℝ)⁻¹ • (a + phi t) - y, v⟫_ℝ) t ∧
    HasDerivAt (fun s => ((N : ℝ) / lambda) * ‖(N : ℝ)⁻¹ • (a + phi s) - y‖ ^ 2)
      ((2 / lambda) * ⟪(N : ℝ)⁻¹ • (a + phi t) - y, v⟫_ℝ) t

Exact module and namespace context

Proof roadmap

  1. 1Differentiate the actual mean

    The derivative of N^{-1}(a+phi(s))-y is N^{-1}v; translations by fixed vectors contribute zero.

  2. 2Differentiate the squared norm

    Apply the real Hilbert squared-norm chain rule to this residual, yielding its inner product with the derived derivative.

  3. 3Cancel the genuine nonzero particle count

    Multiply by N/lambda and use N>0 to cancel N. This does not require lambda to be nonzero; totalized zero scaling remains valid.

Full assumptions and notation

All objects and hypotheses

  • N>0; phi has actual scalar-parameter derivative v at t.
  • H is a real inner-product normed space; a and y are fixed arbitrary vectors; lambda is any real number.

Mathematical proof

1. Differentiate the actual mean

The derivative of N^{-1}(a+phi(s))-y is N^{-1}v; translations by fixed vectors contribute zero.

\[\frac{d}{ds}(N^{-1}(a+\phi(s))-y)_{s=t}=N^{-1}v.\]
Corresponding Lean step

The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

2. Differentiate the squared norm

Apply the real Hilbert squared-norm chain rule to this residual, yielding its inner product with the derived derivative.

\[R\prime(t)=2\langle N^{-1}(a+\phi(t))-y,N^{-1}v\rangle.\]
Corresponding Lean step

The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

3. Cancel the genuine nonzero particle count

Multiply by N/lambda and use N>0 to cancel N. This does not require lambda to be nonzero; totalized zero scaling remains valid.

\[\frac N\lambda\frac2N=\frac2\lambda.\]
Corresponding Lean step

The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

Lean verification

The exact proof begins folded immediately after the mathematical argument; the statement is folded beside the claim above.

Lean proof · empirical_squared_feature_risk_derivatives

See the adjacent exact Lean and the mathematical proof steps.

Braces mark parameters Lean can infer; square brackets request structures such as a measurable space or probability measure. Named hypotheses are mathematical premises, not facts established by this declaration. Section parameters are described in the mathematical hypotheses above; the module link retains their exact source context.

Download module (.lean)
theorem empirical_squared_feature_risk_derivatives
    {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H]
    {N : ℕ} (hN : 0 < N) (lambda : ℝ)
    {phi : ℝ → H} {v a y : H} {t : ℝ} (hphi : HasDerivAt phi v t) :
    HasDerivAt (fun s => ‖(N : ℝ)⁻¹ • (a + phi s) - y‖ ^ 2)
      ((2 / (N : ℝ)) * ⟪(N : ℝ)⁻¹ • (a + phi t) - y, v⟫_ℝ) t ∧
    HasDerivAt (fun s => ((N : ℝ) / lambda) * ‖(N : ℝ)⁻¹ • (a + phi s) - y‖ ^ 2)
      ((2 / lambda) * ⟪(N : ℝ)⁻¹ • (a + phi t) - y, v⟫_ℝ) t := by
  have hNr : (N : ℝ) ≠ 0 := by exact_mod_cast hN.ne'
  have hsum : HasDerivAt (fun s => a + phi s) v t := hphi.const_add a
  have hmean : HasDerivAt (fun s => (N : ℝ)⁻¹ • (a + phi s)) ((N : ℝ)⁻¹ • v) t :=
    HasDerivAt.const_smul (N : ℝ)⁻¹ hsum
  have hcurve : HasDerivAt (fun s => (N : ℝ)⁻¹ • (a + phi s) - y) ((N : ℝ)⁻¹ • v) t :=
    hmean.sub_const y
  have hsq : HasDerivAt (fun s => ‖(N : ℝ)⁻¹ • (a + phi s) - y‖ ^ 2)
      ((2 / (N : ℝ)) * ⟪(N : ℝ)⁻¹ • (a + phi t) - y, v⟫_ℝ) t := by
    simpa only [real_inner_smul_right, div_eq_mul_inv, mul_assoc] using hcurve.norm_sq
  have hcancel : ((N : ℝ) / lambda) *
        ((2 / (N : ℝ)) * ⟪(N : ℝ)⁻¹ • (a + phi t) - y, v⟫_ℝ) =
      (2 / lambda) * ⟪(N : ℝ)⁻¹ • (a + phi t) - y, v⟫_ℝ := by
    simp only [div_eq_mul_inv]
    calc
      (N : ℝ) * lambda⁻¹ * (2 * (N : ℝ)⁻¹ * ⟪(N : ℝ)⁻¹ • (a + phi t) - y, v⟫_ℝ) =
          ((N : ℝ) * (N : ℝ)⁻¹) *
            (2 * lambda⁻¹ * ⟪(N : ℝ)⁻¹ • (a + phi t) - y, v⟫_ℝ) := by ring
      _ = 2 * lambda⁻¹ * ⟪(N : ℝ)⁻¹ • (a + phi t) - y, v⟫_ℝ := by
        rw [mul_inv_cancel₀ hNr, one_mul]
  have hscaled := HasDerivAt.const_mul ((N : ℝ) / lambda) hsq
  rw [hcancel] at hscaled
  exact ⟨hsq, hscaled⟩

Exact module and namespace context

Scope and omitted-condition boundaries
  • No actual parameter-feature differentiability is constructed.
  • The algebraic lambda=0 case is not a statistical or dynamical interpretation.
Sources, dependencies, and reuse

Source and reuse

Samplinglib parents called

    Mathlib API called (external library)

    • HasDerivAt.const_smul
    • HasDerivAt.norm_sq
    • HasDerivAt.const_mul
    • mul_inv_cancel₀

    Mathematical sources

    Samplinglib prose is not a quotation or a source-equivalence certificate. Definitions and aliases are explained as constructions, not counted as new mathematical proofs.

    Samplinglib mathematical lesson

    A literal finite-average risk equals its L² norm

    AutoSamplingTheory.TechnicalLemmas.Analysis.QuadraticFeatureRisk.empirical_squared_risk_eq_L2_norm · theorem · Teaching coverage

    Read this first

    Mathematical statement

    Let P be any measure on a measurable space Omega, N any natural number, a_j:Omega→R for j:Fin N, and y:Omega→R. Suppose every a_j and y belongs to L²(P). Then the actual scalar squared residual (N^{-1} sum_j a_j-y)^2 is integrable, and its integral equals the squared L² norm of N^{-1} sum_j [a_j]-[y], where brackets are the equivalence classes of the stated functions. No probability or finite-measure hypothesis is needed. N=0 uses the empty sum and totalized real inverse.

    \[\int\left(N^{-1}\sum_j a_j-y\right)^2dP=\left\|N^{-1}\sum_j[a_j]-[y]\right\|_{L^2(P)}^2.\]
    Lean statement · empirical_squared_risk_eq_L2_norm

    Let P be any measure on a measurable space Omega, N any natural number, a_j:Omega->R for j:Fin N, and y:Omega->R. Suppose every a_j and y belongs to L²(P). Then the actual scalar squared residual (N^{-1} sum_j a_j-y)^2 is integrable, and its integral equals the squared L² norm of N^{-1} sum_j [a_j]-[y], where brackets are the equivalence classes of the stated functions. No probability or finite-measure hypothesis is needed. N=0 uses the empty sum and totalized real inverse.

    Braces mark parameters Lean can infer; square brackets request structures such as a measurable space or probability measure. Named hypotheses are mathematical premises, not facts established by this declaration. Section parameters are described in the mathematical hypotheses above; the module link retains their exact source context.

    theorem empirical_squared_risk_eq_L2_norm
        {Omega : Type*} [MeasurableSpace Omega] (mu : Measure Omega) (N : ℕ)
        (feature : Fin N → Omega → ℝ) (label : Omega → ℝ)
        (hfeature : ∀ i, MemLp (feature i) 2 mu) (hlabel : MemLp label 2 mu) :
        Integrable (fun omega => ((N : ℝ)⁻¹ * ∑ i, feature i omega - label omega) ^ 2) mu ∧
        (∫ omega, ((N : ℝ)⁻¹ * ∑ i, feature i omega - label omega) ^ 2 ∂mu) =
          ‖(N : ℝ)⁻¹ • ∑ i, (hfeature i).toLp (feature i) - hlabel.toLp label‖ ^ 2

    Exact module and namespace context

    Proof roadmap

    1. 1Produce the actual residual in L²

      Finite sums, scalar multiplication and subtraction preserve L² membership. Therefore its square is integrable.

    2. 2Identify the representative

      Use the almost-everywhere representative identities for each actual toLp class, finite sum, scalar multiple and difference. The assembled class represents the actual scalar residual.

    3. 3Evaluate the Hilbert norm

      The L² inner product is the actual integral of pointwise products, and the squared norm is the self inner product.

    Full assumptions and notation

    All objects and hypotheses

    • Every selected scalar feature a_j and the label function y is genuinely MemLp at exponent2 under P.
    • P is any measure; N may be zero in this finite-average identity.

    Mathematical proof

    1. Produce the actual residual in L²

    Finite sums, scalar multiplication and subtraction preserve L² membership. Therefore its square is integrable.

    \[r=N^{-1}\sum_j a_j-y\in L^2(P).\]
    Corresponding Lean step

    The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

    2. Identify the representative

    Use the almost-everywhere representative identities for each actual toLp class, finite sum, scalar multiple and difference. The assembled class represents the actual scalar residual.

    \[[r]=N^{-1}\sum_j[a_j]-[y].\]
    Corresponding Lean step

    The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

    3. Evaluate the Hilbert norm

    The L² inner product is the actual integral of pointwise products, and the squared norm is the self inner product.

    \[\|[r]\|_2^2=\langle[r],[r]\rangle=\int r^2dP.\]
    Corresponding Lean step

    The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

    Lean verification

    The exact proof begins folded immediately after the mathematical argument; the statement is folded beside the claim above.

    Lean proof · empirical_squared_risk_eq_L2_norm

    See the adjacent exact Lean and the mathematical proof steps.

    Braces mark parameters Lean can infer; square brackets request structures such as a measurable space or probability measure. Named hypotheses are mathematical premises, not facts established by this declaration. Section parameters are described in the mathematical hypotheses above; the module link retains their exact source context.

    Download module (.lean)
    theorem empirical_squared_risk_eq_L2_norm
        {Omega : Type*} [MeasurableSpace Omega] (mu : Measure Omega) (N : ℕ)
        (feature : Fin N → Omega → ℝ) (label : Omega → ℝ)
        (hfeature : ∀ i, MemLp (feature i) 2 mu) (hlabel : MemLp label 2 mu) :
        Integrable (fun omega => ((N : ℝ)⁻¹ * ∑ i, feature i omega - label omega) ^ 2) mu ∧
        (∫ omega, ((N : ℝ)⁻¹ * ∑ i, feature i omega - label omega) ^ 2 ∂mu) =
          ‖(N : ℝ)⁻¹ • ∑ i, (hfeature i).toLp (feature i) - hlabel.toLp label‖ ^ 2 := by
      classical
      let z : Lp ℝ 2 mu :=
        (N : ℝ)⁻¹ • ∑ i, (hfeature i).toLp (feature i) - hlabel.toLp label
      have hres : MemLp (fun omega => (N : ℝ)⁻¹ * ∑ i, feature i omega - label omega) 2 mu := by
        have hs := memLp_finsetSum Finset.univ (fun i _ => hfeature i)
        exact (hs.const_smul (N : ℝ)⁻¹).sub hlabel
      refine ⟨hres.integrable_sq, ?_⟩
      have hz : (fun omega => z omega) =ᵐ[mu]
          (fun omega => (N : ℝ)⁻¹ * ∑ i, feature i omega - label omega) := by
        filter_upwards [Lp.coeFn_sub ((N : ℝ)⁻¹ • ∑ i, (hfeature i).toLp (feature i))
            (hlabel.toLp label),
          Lp.coeFn_smul (N : ℝ)⁻¹ (∑ i, (hfeature i).toLp (feature i)),
          Lp.coeFn_fun_finsetSum Finset.univ (fun i => (hfeature i).toLp (feature i)),
          ae_all_iff.2 (fun i => (hfeature i).coeFn_toLp), hlabel.coeFn_toLp]
          with omega hsub hsmul hsum hf hy
        change (((N : ℝ)⁻¹ • ∑ i, (hfeature i).toLp (feature i) - hlabel.toLp label) omega) = _
        simp only [Pi.sub_apply, Pi.smul_apply, smul_eq_mul] at hsub hsmul
        rw [hsub, hsmul, hsum, hy]
        simp only [hf]
      change (∫ omega, ((N : ℝ)⁻¹ * ∑ i, feature i omega - label omega) ^ 2 ∂mu) = ‖z‖ ^ 2
      rw [← real_inner_self_eq_norm_sq, L2.inner_def]
      symm
      apply integral_congr_ae
      filter_upwards [hz] with omega homega
      simp only [homega, real_inner_self_eq_norm_sq, Real.norm_eq_abs, sq_abs]

    Exact module and namespace context

    Scope and omitted-condition boundaries
    • This identity alone does not identify a weight-law predictor with this finite average.
    • It supplies no all-law first variation or feature differentiability.
    Sources, dependencies, and reuse

    Source and reuse

    Samplinglib parents called

      Mathlib API called (external library)

      • memLp_finsetSum
      • MemLp.integrable_sq
      • Lp.coeFn_sub
      • Lp.coeFn_smul
      • Lp.coeFn_fun_finsetSum
      • MemLp.coeFn_toLp
      • L2.inner_def
      • integral_congr_ae

      Mathematical sources

      Samplinglib prose is not a quotation or a source-equivalence certificate. Definitions and aliases are explained as constructions, not counted as new mathematical proofs.

      Samplinglib mathematical lesson

      Construct the empirical law and evaluate its actual risk

      AutoSamplingTheory.TechnicalLemmas.Analysis.QuadraticFeatureRisk.empirical_law_squared_risk_eq_L2_norm · theorem · Teaching coverage

      Read this first

      Mathematical statement

      Let W be a measurable space with measurable singleton points, Omega a measurable data space and P any measure on Omega. Let N>0, w:Fin N→W, scalar features K:W→Omega→R, and a label y:Omega→R. Suppose K(w_j) and y are in L²(P). Define rho=N^{-1} sum_j Dirac(w_j), using reciprocal N as an ENNReal measure weight. Then rho is a probability measure, the actual loss (integral K(q,omega) drho(q)-y(omega))² is integrable under P, and its integral equals ||N^{-1} sum_j [K(w_j)]-[y]||². Particle values may coincide. No global measurability in q or probability assumption on P is required for this finite atomic assertion.

      \[\rho=\frac1N\sum_j\delta_{w_j},\qquad \int\left(\int K(q,\omega)d\rho(q)-y(\omega)\right)^2dP=\left\|\frac1N\sum_j[K(w_j)]-[y]\right\|_2^2.\]
      Lean statement · empirical_law_squared_risk_eq_L2_norm

      Let W be a measurable space with measurable singleton points, Omega a measurable data space and P any measure on Omega. Let N>0, w:Fin N->W, scalar features K:W->Omega->R, and a label y:Omega->R. Suppose K(w_j) and y are in L²(P). Define rho=N^{-1} sum_j Dirac(w_j), using reciprocal N as an ENNReal measure weight. Then rho is a probability measure, the actual loss (integral K(q,omega) drho(q)-y(omega))² is integrable under P, and its integral equals ||N^{-1} sum_j [K(w_j)]-[y]||². Particle values may coincide. No global measurability in q or probability assumption on P is required for this finite atomic assertion.

      Braces mark parameters Lean can infer; square brackets request structures such as a measurable space or probability measure. Named hypotheses are mathematical premises, not facts established by this declaration. Section parameters are described in the mathematical hypotheses above; the module link retains their exact source context.

      theorem empirical_law_squared_risk_eq_L2_norm
          {W Omega : Type*} [MeasurableSpace W] [MeasurableSingletonClass W]
          [MeasurableSpace Omega] (P : Measure Omega) {N : ℕ} (hN : 0 < N)
          (w : Fin N → W) (K : W → Omega → ℝ) (label : Omega → ℝ)
          (hfeature : ∀ i, MemLp (K (w i)) 2 P) (hlabel : MemLp label 2 P) :
          let rho : Measure W := (N : ℝ≥0∞)⁻¹ • ∑ i, Measure.dirac (w i)
          IsProbabilityMeasure rho ∧
          Integrable (fun omega => ((∫ q, K q omega ∂rho) - label omega) ^ 2) P ∧
          (∫ omega, ((∫ q, K q omega ∂rho) - label omega) ^ 2 ∂P) =
            ‖(N : ℝ)⁻¹ • ∑ i, (hfeature i).toLp (K (w i)) - hlabel.toLp label‖ ^ 2

      Exact module and namespace context

      Proof roadmap

      1. 1Normalize the actual finite measure

        The sum of N Dirac masses has total mass N. Its nonzero finite reciprocal weight gives total mass one.

      2. 2Evaluate each actual predictor slice

        Every function is integrable under a Dirac at a measurable singleton point. Finite-measure-sum and scalar integration give the literal predictor for every data point.

      3. 3Apply the finite residual identity

        The actual predictor is now the finite average, so the previous L² residual theorem yields both loss integrability and the exact risk norm.

      Full assumptions and notation

      All objects and hypotheses

      • N>0; W has measurable singleton points.
      • Every selected feature K(w_j) and y is in L²(P); repeated atoms are allowed.

      Mathematical proof

      1. Normalize the actual finite measure

      The sum of N Dirac masses has total mass N. Its nonzero finite reciprocal weight gives total mass one.

      \[\rho(W)=N^{-1}N=1.\]
      Corresponding Lean step

      The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

      2. Evaluate each actual predictor slice

      Every function is integrable under a Dirac at a measurable singleton point. Finite-measure-sum and scalar integration give the literal predictor for every data point.

      \[\int K(q,\omega)d\rho(q)=N^{-1}\sum_jK(w_j,\omega).\]
      Corresponding Lean step

      The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

      3. Apply the finite residual identity

      The actual predictor is now the finite average, so the previous L² residual theorem yields both loss integrability and the exact risk norm.

      \[F(\rho)=\left\|N^{-1}\sum_j[K(w_j)]-[y]\right\|_2^2.\]
      Corresponding Lean step

      The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

      Lean verification

      The exact proof begins folded immediately after the mathematical argument; the statement is folded beside the claim above.

      Lean proof · empirical_law_squared_risk_eq_L2_norm

      See the adjacent exact Lean and the mathematical proof steps.

      Braces mark parameters Lean can infer; square brackets request structures such as a measurable space or probability measure. Named hypotheses are mathematical premises, not facts established by this declaration. Section parameters are described in the mathematical hypotheses above; the module link retains their exact source context.

      Download module (.lean)
      theorem empirical_law_squared_risk_eq_L2_norm
          {W Omega : Type*} [MeasurableSpace W] [MeasurableSingletonClass W]
          [MeasurableSpace Omega] (P : Measure Omega) {N : ℕ} (hN : 0 < N)
          (w : Fin N → W) (K : W → Omega → ℝ) (label : Omega → ℝ)
          (hfeature : ∀ i, MemLp (K (w i)) 2 P) (hlabel : MemLp label 2 P) :
          let rho : Measure W := (N : ℝ≥0∞)⁻¹ • ∑ i, Measure.dirac (w i)
          IsProbabilityMeasure rho ∧
          Integrable (fun omega => ((∫ q, K q omega ∂rho) - label omega) ^ 2) P ∧
          (∫ omega, ((∫ q, K q omega ∂rho) - label omega) ^ 2 ∂P) =
            ‖(N : ℝ)⁻¹ • ∑ i, (hfeature i).toLp (K (w i)) - hlabel.toLp label‖ ^ 2 := by
        classical
        dsimp only
        let rho : Measure W := (N : ℝ≥0∞)⁻¹ • ∑ i, Measure.dirac (w i)
        have hprob : IsProbabilityMeasure rho := by
          constructor
          simpa [rho, Measure.smul_apply] using
            ENNReal.inv_mul_cancel (show (N : ℝ≥0∞) ≠ 0 by exact_mod_cast hN.ne') (by simp)
        have hpred : ∀ omega, (∫ q, K q omega ∂rho) = (N : ℝ)⁻¹ * ∑ i, K (w i) omega := by
          intro omega
          change (∫ q, K q omega ∂((N : ℝ≥0∞)⁻¹ • ∑ i, Measure.dirac (w i))) = _
          rw [integral_smul_measure]
          rw [integral_finsetSum_measure (fun i _ => integrable_dirac (by simp))]
          simp [smul_eq_mul]
        have hbase := empirical_squared_risk_eq_L2_norm P N
          (fun i => K (w i)) label hfeature hlabel
        refine ⟨hprob, ?_, ?_⟩
        · change Integrable (fun omega => ((∫ q, K q omega ∂rho) - label omega) ^ 2) P
          simpa only [hpred] using hbase.1
        · change (∫ omega, ((∫ q, K q omega ∂rho) - label omega) ^ 2 ∂P) = _
          simpa only [hpred] using hbase.2

      Exact module and namespace context

      Scope and omitted-condition boundaries
      • Fixed finite atomic laws only; no arbitrary parameter-law integration or parameter measurability is inferred.
      • No general first variation is identified.
      Sources, dependencies, and reuse

      Source and reuse

      Samplinglib parents called

      Mathlib API called (external library)

      • ENNReal.inv_mul_cancel
      • integral_smul_measure
      • integral_finsetSum_measure
      • integrable_dirac

      Mathematical sources

      Samplinglib prose is not a quotation or a source-equivalence certificate. Definitions and aliases are explained as constructions, not counted as new mathematical proofs.

      Samplinglib mathematical lesson

      One indexed replacement has an exact quadratic remainder

      AutoSamplingTheory.TechnicalLemmas.Analysis.QuadraticFeatureRisk.empirical_squared_loss_replacement · theorem · Teaching coverage

      Read this first

      Mathematical statement

      Let H be any real inner-product normed space, N>0, a:Fin N→H, i:Fin N, and u,y in H. Let b be any real number and assume ||a_i||≤b and ||u||≤b. Define m=N^{-1} sum_j a_j and mNew=N^{-1} sum_j Function.update(a,i,u)_j. Then ||mNew-y||²-||m-y||²-2 inner(m-y,mNew-m)=||mNew-m||², and this squared remainder is at most4b²/N². The mean displacement is derived, not assumed. No bound on y or the other features, completeness, or measure hypothesis is needed.

      \[\Delta=m^{\rm new}-m=\frac{u-a_i}{N},\quad \|m^{\rm new}-y\|^2-\|m-y\|^2-2\langle m-y,\Delta\rangle=\|\Delta\|^2\le\frac{4b^2}{N^2}.\]
      Lean statement · empirical_squared_loss_replacement

      Let H be any real inner-product normed space, N>0, a:Fin N->H, i:Fin N, and u,y in H. Let b be any real number and assume ||a_i||<=b and ||u||<=b. Define m=N^{-1} sum_j a_j and mNew=N^{-1} sum_j Function.update(a,i,u)_j. Then ||mNew-y||²-||m-y||²-2 inner(m-y,mNew-m)=||mNew-m||², and this squared remainder is at most4b²/N². The mean displacement is derived, not assumed. No bound on y or the other features, completeness, or measure hypothesis is needed.

      Braces mark parameters Lean can infer; square brackets request structures such as a measurable space or probability measure. Named hypotheses are mathematical premises, not facts established by this declaration. Section parameters are described in the mathematical hypotheses above; the module link retains their exact source context.

      theorem empirical_squared_loss_replacement
          {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H]
          {N : ℕ} (hN : 0 < N) (feature : Fin N → H) (i : Fin N)
          (replacement label : H) (b : ℝ)
          (hold : ‖feature i‖ ≤ b) (hnew : ‖replacement‖ ≤ b) :
          let m : H := (N : ℝ)⁻¹ • ∑ j, feature j
          let mNew : H := (N : ℝ)⁻¹ • ∑ j, Function.update feature i replacement j
          (‖mNew - label‖ ^ 2 - ‖m - label‖ ^ 2 -
            2 * ⟪m - label, mNew - m⟫_ℝ = ‖mNew - m‖ ^ 2) ∧
          ‖mNew - m‖ ^ 2 ≤ 4 * b ^ 2 / (N : ℝ) ^ 2

      Exact module and namespace context

      Proof roadmap

      1. 1Cancel exactly one index

        In the difference of the two finite sums all j≠i terms cancel, including terms whose vector values equal a_i.

      2. 2Bound the actual displacement

        The triangle inequality and the two individual norm bounds give a bound on the derived displacement.

      3. 3Expand the unhalved quadratic loss

        Write mNew-y=(m-y)+Delta and use the real inner-product norm expansion. The exact cross term has factor2.

      4. 4Square the nonnegative norm bound

        Both norms and 2b/N are nonnegative; squaring produces the stated constant.

      Full assumptions and notation

      All objects and hypotheses

      • N>0; only the selected old feature and its replacement have norm at most b.
      • Repeated feature values are allowed; Function.update changes one index. The two norm bounds imply b≥0.

      Mathematical proof

      1. Cancel exactly one index

      In the difference of the two finite sums all j≠i terms cancel, including terms whose vector values equal a_i.

      \[\Delta=N^{-1}(u-a_i).\]
      Corresponding Lean step

      The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

      2. Bound the actual displacement

      The triangle inequality and the two individual norm bounds give a bound on the derived displacement.

      \[\|\Delta\|\le N^{-1}(\|u\|+\|a_i\|)\le2b/N.\]
      Corresponding Lean step

      The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

      3. Expand the unhalved quadratic loss

      Write mNew-y=(m-y)+Delta and use the real inner-product norm expansion. The exact cross term has factor2.

      \[\|r+\Delta\|^2=\|r\|^2+2\langle r,\Delta\rangle+\|\Delta\|^2.\]
      Corresponding Lean step

      The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

      4. Square the nonnegative norm bound

      Both norms and 2b/N are nonnegative; squaring produces the stated constant.

      \[\|\Delta\|^2\le4b^2/N^2.\]
      Corresponding Lean step

      The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

      Lean verification

      The exact proof begins folded immediately after the mathematical argument; the statement is folded beside the claim above.

      Lean proof · empirical_squared_loss_replacement

      See the adjacent exact Lean and the mathematical proof steps.

      Braces mark parameters Lean can infer; square brackets request structures such as a measurable space or probability measure. Named hypotheses are mathematical premises, not facts established by this declaration. Section parameters are described in the mathematical hypotheses above; the module link retains their exact source context.

      Download module (.lean)
      theorem empirical_squared_loss_replacement
          {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H]
          {N : ℕ} (hN : 0 < N) (feature : Fin N → H) (i : Fin N)
          (replacement label : H) (b : ℝ)
          (hold : ‖feature i‖ ≤ b) (hnew : ‖replacement‖ ≤ b) :
          let m : H := (N : ℝ)⁻¹ • ∑ j, feature j
          let mNew : H := (N : ℝ)⁻¹ • ∑ j, Function.update feature i replacement j
          (‖mNew - label‖ ^ 2 - ‖m - label‖ ^ 2 -
            2 * ⟪m - label, mNew - m⟫_ℝ = ‖mNew - m‖ ^ 2) ∧
          ‖mNew - m‖ ^ 2 ≤ 4 * b ^ 2 / (N : ℝ) ^ 2 := by
        classical
        dsimp only
        let m : H := (N : ℝ)⁻¹ • ∑ j, feature j
        let mNew : H := (N : ℝ)⁻¹ • ∑ j, Function.update feature i replacement j
        change (‖mNew - label‖ ^ 2 - ‖m - label‖ ^ 2 -
            2 * ⟪m - label, mNew - m⟫_ℝ = ‖mNew - m‖ ^ 2) ∧ _
        have hsum : (∑ j, Function.update feature i replacement j) - ∑ j, feature j =
            replacement - feature i := by
          rw [← Finset.sum_sub_distrib, Finset.sum_eq_single i]
          · simp
          · intro j _ hji
            simp [Function.update_of_ne hji]
          · simp
        have hmean : mNew - m = (N : ℝ)⁻¹ • (replacement - feature i) := by
          dsimp only [mNew, m]
          rw [← smul_sub, hsum]
        have hb : 0 ≤ b := (norm_nonneg (feature i)).trans hold
        have hinv : 0 ≤ (N : ℝ)⁻¹ := (inv_pos.mpr (show (0 : ℝ) < N by exact_mod_cast hN)).le
        have hsmall : ‖mNew - m‖ ≤ (N : ℝ)⁻¹ * (2 * b) := by
          rw [hmean, norm_smul, Real.norm_eq_abs, abs_of_nonneg hinv]
          apply mul_le_mul_of_nonneg_left _ hinv
          calc
            ‖replacement - feature i‖ ≤ ‖replacement‖ + ‖feature i‖ := norm_sub_le _ _
            _ ≤ b + b := add_le_add hnew hold
            _ = 2 * b := by ring
        constructor
        · have hsplit : mNew - label = (m - label) + (mNew - m) := by abel
          rw [hsplit, norm_add_sq_real]
          ring
        · calc
            ‖mNew - m‖ ^ 2 ≤ ((N : ℝ)⁻¹ * (2 * b)) ^ 2 := by gcongr
            _ = 4 * b ^ 2 / (N : ℝ) ^ 2 := by
              simp only [div_eq_mul_inv]
              ring

      Exact module and namespace context

      Scope and omitted-condition boundaries
      • This Hilbert expression alone is not a measure-functional Bregman identity.
      • At b=0 the estimate is valid but4b² is not a strictly positive witness.
      Sources, dependencies, and reuse

      Source and reuse

      Samplinglib parents called

        Mathlib API called (external library)

        • Finset.sum_sub_distrib
        • Finset.sum_eq_single
        • norm_sub_le
        • norm_add_sq_real

        Mathematical sources

        Samplinglib prose is not a quotation or a source-equivalence certificate. Definitions and aliases are explained as constructions, not counted as new mathematical proofs.

        Samplinglib mathematical lesson

        Integrate the quadratic potential before taking the remainder

        AutoSamplingTheory.TechnicalLemmas.Analysis.QuadraticFeatureRisk.quadratic_feature_mean_calculus · theorem · Teaching coverage

        Read this first

        Mathematical statement

        Let W be measurable and H a complete real inner-product space. Let mu and nu be arbitrary measures, feature:W→H Bochner integrable under each, and y in H. Put m=integral feature dmu, n=integral feature dnu and V(q)=2 inner(m-y,feature(q)). Then V is integrable under both measures. With D=integral V dnu-integral V dmu, one has D=2 inner(m-y,n-m), ||n-y||²-||m-y||²-D=||n-m||², and ||m-y||²+D≤||n-y||². The real function t↦||m+t(n-m)-y||² has derivative D at zero. No probability, finite-mass or equal-mass hypothesis is imposed: m and n are unnormalized integrals.

        \[D=\int Vd\nu-\int Vd\mu=2\langle m-y,n-m\rangle,\qquad \|n-y\|^2-\|m-y\|^2-D=\|n-m\|^2.\]
        Lean statement · quadratic_feature_mean_calculus

        Let W be measurable and H a complete real inner-product space. Let mu and nu be arbitrary measures, feature:W->H Bochner integrable under each, and y in H. Put m=integral feature dmu, n=integral feature dnu and V(q)=2 inner(m-y,feature(q)). Then V is integrable under both measures. With D=integral V dnu-integral V dmu, one has D=2 inner(m-y,n-m), ||n-y||²-||m-y||²-D=||n-m||², and ||m-y||²+D<=||n-y||². The real function t↦||m+t(n-m)-y||² has derivative D at zero. No probability, finite-mass or equal-mass hypothesis is imposed: m and n are unnormalized integrals.

        Braces mark parameters Lean can infer; square brackets request structures such as a measurable space or probability measure. Named hypotheses are mathematical premises, not facts established by this declaration. Section parameters are described in the mathematical hypotheses above; the module link retains their exact source context.

        theorem quadratic_feature_mean_calculus
            {W H : Type*} [MeasurableSpace W]
            [NormedAddCommGroup H] [InnerProductSpace ℝ H] [CompleteSpace H]
            (μ ν : Measure W) (feature : W → H) (label : H)
            (hμ : Integrable feature μ) (hν : Integrable feature ν) :
            let m : H := ∫ w, feature w ∂μ
            let n : H := ∫ w, feature w ∂ν
            let potential : W → ℝ := fun w => 2 * ⟪m - label, feature w⟫_ℝ
            Integrable potential μ ∧ Integrable potential ν ∧
            ((∫ w, potential w ∂ν) - (∫ w, potential w ∂μ) =
              2 * ⟪m - label, n - m⟫_ℝ) ∧
            (‖n - label‖ ^ 2 - ‖m - label‖ ^ 2 -
              ((∫ w, potential w ∂ν) - (∫ w, potential w ∂μ)) = ‖n - m‖ ^ 2) ∧
            (‖m - label‖ ^ 2 + ((∫ w, potential w ∂ν) - (∫ w, potential w ∂μ)) ≤
              ‖n - label‖ ^ 2) ∧
            HasDerivAt (fun t : ℝ => ‖m + t • (n - m) - label‖ ^ 2)
              ((∫ w, potential w ∂ν) - (∫ w, potential w ∂μ)) 0

        Exact module and namespace context

        Proof roadmap

        1. 1Produce scalar potential integrability

          Pairing the actual feature with a fixed Hilbert vector is a continuous linear functional. It preserves Bochner integrability under either measure.

        2. 2Commute each integral with the linear pairing

          Subtract the two actual finite scalar integrals and use linearity in the second inner-product argument. Here eta is restricted to mu or nu, precisely the two supplied integrability domains.

        3. 3Expand the loss and use positivity

          Expand n-y=(m-y)+(n-m); the leftover squared norm is nonnegative and yields the support inequality.

        4. 4Differentiate the literal affine Hilbert curve

          Its residual derivative is n-m. The squared-norm chain rule gives precisely D at zero.

        Full assumptions and notation

        All objects and hypotheses

        • H is complete; the H-valued feature is genuinely Bochner integrable under both measures.
        • The fixed label is any vector. The measures may have unequal or infinite total mass.

        Mathematical proof

        1. Produce scalar potential integrability

        Pairing the actual feature with a fixed Hilbert vector is a continuous linear functional. It preserves Bochner integrability under either measure.

        \[V(q)=2\langle m-y,\Phi(q)\rangle\in L^1(\mu)\cap L^1(\nu).\]
        Corresponding Lean step

        The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

        2. Commute each integral with the linear pairing

        Subtract the two actual finite scalar integrals and use linearity in the second inner-product argument. Here eta is restricted to mu or nu, precisely the two supplied integrability domains.

        \[\eta\in\{\mu,\nu\}:\quad\int Vd\eta=2\langle m-y,\int\Phi d\eta\rangle,\qquad D=2\langle m-y,n-m\rangle.\]
        Corresponding Lean step

        The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

        3. Expand the loss and use positivity

        Expand n-y=(m-y)+(n-m); the leftover squared norm is nonnegative and yields the support inequality.

        \[\|n-y\|^2=\|m-y\|^2+D+\|n-m\|^2.\]
        Corresponding Lean step

        The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

        4. Differentiate the literal affine Hilbert curve

        Its residual derivative is n-m. The squared-norm chain rule gives precisely D at zero.

        \[\frac d{dt}\|m+t(n-m)-y\|^2\big|_{t=0}=D.\]
        Corresponding Lean step

        The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

        Lean verification

        The exact proof begins folded immediately after the mathematical argument; the statement is folded beside the claim above.

        Lean proof · quadratic_feature_mean_calculus

        See the adjacent exact Lean and the mathematical proof steps.

        Braces mark parameters Lean can infer; square brackets request structures such as a measurable space or probability measure. Named hypotheses are mathematical premises, not facts established by this declaration. Section parameters are described in the mathematical hypotheses above; the module link retains their exact source context.

        Download module (.lean)
        theorem quadratic_feature_mean_calculus
            {W H : Type*} [MeasurableSpace W]
            [NormedAddCommGroup H] [InnerProductSpace ℝ H] [CompleteSpace H]
            (μ ν : Measure W) (feature : W → H) (label : H)
            (hμ : Integrable feature μ) (hν : Integrable feature ν) :
            let m : H := ∫ w, feature w ∂μ
            let n : H := ∫ w, feature w ∂ν
            let potential : W → ℝ := fun w => 2 * ⟪m - label, feature w⟫_ℝ
            Integrable potential μ ∧ Integrable potential ν ∧
            ((∫ w, potential w ∂ν) - (∫ w, potential w ∂μ) =
              2 * ⟪m - label, n - m⟫_ℝ) ∧
            (‖n - label‖ ^ 2 - ‖m - label‖ ^ 2 -
              ((∫ w, potential w ∂ν) - (∫ w, potential w ∂μ)) = ‖n - m‖ ^ 2) ∧
            (‖m - label‖ ^ 2 + ((∫ w, potential w ∂ν) - (∫ w, potential w ∂μ)) ≤
              ‖n - label‖ ^ 2) ∧
            HasDerivAt (fun t : ℝ => ‖m + t • (n - m) - label‖ ^ 2)
              ((∫ w, potential w ∂ν) - (∫ w, potential w ∂μ)) 0 := by
          dsimp only
          let m : H := ∫ w, feature w ∂μ
          let n : H := ∫ w, feature w ∂ν
          let potential : W → ℝ := fun w => 2 * ⟪m - label, feature w⟫_ℝ
          change Integrable potential μ ∧ Integrable potential ν ∧ _
          have hpotμ : Integrable potential μ :=
            (Integrable.const_inner (m - label) hμ).const_mul 2
          have hpotν : Integrable potential ν :=
            (Integrable.const_inner (m - label) hν).const_mul 2
          have hpμ : (∫ w, potential w ∂μ) = 2 * ⟪m - label, m⟫_ℝ := by
            dsimp only [potential, m]
            rw [integral_const_mul, integral_inner hμ]
          have hpν : (∫ w, potential w ∂ν) = 2 * ⟪m - label, n⟫_ℝ := by
            dsimp only [potential, n]
            rw [integral_const_mul, integral_inner hν]
          have hpair : (∫ w, potential w ∂ν) - (∫ w, potential w ∂μ) =
              2 * ⟪m - label, n - m⟫_ℝ := by
            rw [hpν, hpμ, inner_sub_right]
            ring
          have hbre : ‖n - label‖ ^ 2 - ‖m - label‖ ^ 2 -
              ((∫ w, potential w ∂ν) - (∫ w, potential w ∂μ)) = ‖n - m‖ ^ 2 := by
            rw [hpair]
            have hsplit : n - label = (m - label) + (n - m) := by abel
            rw [hsplit, norm_add_sq_real]
            ring
          refine ⟨hpotμ, hpotν, hpair, hbre, ?_, ?_⟩
          · linarith [sq_nonneg ‖n - m‖]
          · rw [hpair]
            have hcurve : HasDerivAt (fun t : ℝ => m + t • (n - m) - label) (n - m) 0 := by
              have hsmul : HasDerivAt (fun t : ℝ => t • (n - m)) (n - m) 0 := by
                simpa only [one_smul, id_eq] using (hasDerivAt_id (0 : ℝ)).smul_const (n - m)
              have hadd : HasDerivAt (fun t : ℝ => m + t • (n - m)) (n - m) 0 :=
                hsmul.const_add m
              exact hadd.sub_const label
            simpa only [zero_smul, add_zero] using hcurve.norm_sq

        Exact module and namespace context

        Scope and omitted-condition boundaries
        • No identification of a pointwise statistical predictor with this Bochner mean is supplied.
        • The affine Hilbert derivative is not by itself a probability-measure-segment first variation.
        • For arbitrary measures, adding a constant to V need not preserve D.
        Sources, dependencies, and reuse

        Source and reuse

        Samplinglib parents called

          Mathlib API called (external library)

          • Integrable.const_inner
          • Integrable.const_mul
          • integral_const_mul
          • integral_inner
          • inner_sub_right
          • norm_add_sq_real
          • HasDerivAt.norm_sq

          Mathematical sources

          Samplinglib prose is not a quotation or a source-equivalence certificate. Definitions and aliases are explained as constructions, not counted as new mathematical proofs.

          Samplinglib mathematical lesson

          A true joint-data risk has a positive empirical replacement budget

          AutoSamplingTheory.TechnicalLemmas.Analysis.QuadraticFeatureRisk.joint_empirical_squared_risk_replacement · theorem · Teaching coverage

          Read this first

          Mathematical statement

          Let W be measurable with measurable singleton points, X measurable, and P a probability measure on X×R with input marginal PX=P.map fst. Let K:W→X→R. Suppose each K(q) is genuinely in L²(PX), every corresponding L² norm is at most the same b>0, and the true response coordinate z↦z.2 is in L²(P). For any N>0, configuration w:Fin N→W, index i and replacement u, define rho=N^{-1} sum_j Dirac(w_j), rhoNew by replacing only index i, predictor_law(x)=integral K(q,x) dlaw(q), risk(law)=integral(predictor_law(z.1)-z.2)² dP(z), and V(q)=2 integral(predictor_rho(z.1)-z.2)K(q,z.1) dP(z). Put D=integral V drhoNew-integral V drho. Then4b²>0; both empirical laws are probabilities; both actual losses and both finite-law potential integrals are integrable; D=(V(u)-V(w_i))/N; and risk(rhoNew)-risk(rho)-D equals the input-marginal integral of (predictor_rhoNew-predictor_rho)². This remainder is nonnegative and at most4b²/N². No independence of input and response, global parameter measurability, or assumed pairing/remainder/displacement bound is used.

          \[D=\frac{V(u)-V(w_i)}N,\quad F(\rho^{\rm new})-F(\rho)-D=\int(f_{\rho^{\rm new}}-f_\rho)^2dP_X\in[0,4b^2/N^2],\quad4b^2>0.\]
          Lean statement · joint_empirical_squared_risk_replacement

          Let W be measurable with measurable singleton points, X measurable, and P a probability measure on X×R with input marginal PX=P.map fst. Let K:W->X->R. Suppose each K(q) is genuinely in L²(PX), every corresponding L² norm is at most the same b>0, and the true response coordinate z↦z.2 is in L²(P). For any N>0, configuration w:Fin N->W, index i and replacement u, define rho=N^{-1} sum_j Dirac(w_j), rhoNew by replacing only index i, predictor_law(x)=integral K(q,x) dlaw(q), risk(law)=integral(predictor_law(z.1)-z.2)² dP(z), and V(q)=2 integral(predictor_rho(z.1)-z.2)K(q,z.1) dP(z). Put D=integral V drhoNew-integral V drho. Then4b²>0; both empirical laws are probabilities; both actual losses and both finite-law potential integrals are integrable; D=(V(u)-V(w_i))/N; and risk(rhoNew)-risk(rho)-D equals the input-marginal integral of (predictor_rhoNew-predictor_rho)². This remainder is nonnegative and at most4b²/N². No independence of input and response, global parameter measurability, or assumed pairing/remainder/displacement bound is used.

          Braces mark parameters Lean can infer; square brackets request structures such as a measurable space or probability measure. Named hypotheses are mathematical premises, not facts established by this declaration. Section parameters are described in the mathematical hypotheses above; the module link retains their exact source context.

          theorem joint_empirical_squared_risk_replacement
              {W X : Type*} [MeasurableSpace W] [MeasurableSingletonClass W]
              [MeasurableSpace X] (P : Measure (X × ℝ)) [IsProbabilityMeasure P]
              (K : W → X → ℝ) (b : ℝ) (hb : 0 < b)
              (hfeature : ∀ q, MemLp (K q) 2 (P.map Prod.fst))
              (hbound : ∀ q, ‖(hfeature q).toLp (K q)‖ ≤ b)
              (hlabel : MemLp (fun z : X × ℝ => z.2) 2 P)
              {N : ℕ} (hN : 0 < N) (w : Fin N → W) (i : Fin N) (u : W) :
              let rho : Measure W := (N : ℝ≥0∞)⁻¹ • ∑ j, Measure.dirac (w j)
              let rhoNew : Measure W :=
                (N : ℝ≥0∞)⁻¹ • ∑ j, Measure.dirac (Function.update w i u j)
              let predictor : Measure W → X → ℝ := fun law x => ∫ q, K q x ∂law
              let risk : Measure W → ℝ :=
                fun law => ∫ z, (predictor law z.1 - z.2) ^ 2 ∂P
              let potential : W → ℝ :=
                fun q => 2 * ∫ z, (predictor rho z.1 - z.2) * K q z.1 ∂P
              let pairing : ℝ := (∫ q, potential q ∂rhoNew) - (∫ q, potential q ∂rho)
              (0 < 4 * b ^ 2) ∧ IsProbabilityMeasure rho ∧ IsProbabilityMeasure rhoNew ∧
              Integrable (fun z : X × ℝ => (predictor rho z.1 - z.2) ^ 2) P ∧
              Integrable (fun z : X × ℝ => (predictor rhoNew z.1 - z.2) ^ 2) P ∧
              Integrable potential rho ∧ Integrable potential rhoNew ∧
              (pairing = (N : ℝ)⁻¹ * (potential u - potential (w i))) ∧
              (risk rhoNew - risk rho - pairing =
                ∫ x, (predictor rhoNew x - predictor rho x) ^ 2 ∂(P.map Prod.fst)) ∧
              (0 ≤ risk rhoNew - risk rho - pairing) ∧
              (risk rhoNew - risk rho - pairing ≤ 4 * b ^ 2 / (N : ℝ) ^ 2)

          Exact module and namespace context

          Proof roadmap

          1. 1Construct and evaluate both empirical laws

            Normalize the actual N Dirac masses, and integrate each fixed scalar slice by the finite-sum identity. Updating the configuration changes exactly one index.

          2. 2Lift through the true marginal

            Work in H=L²(P). Write a_q=[K(q) composed with fst], y=[z↦z.2], m=N^{-1} sum_j a_(w_j), and mNew=N^{-1} sum_j a_(updated w_j). The map fst preserves P to its actual pushforward PX. Its L² pullback is an isometry. Thus the actual lifted features have the supplied norm bound under the same joint P, and the actual residual is in L².

          3. 3Identify the actual potential

            Identify the actual finite predictor residual with its L² class. Integrating its product with each actual lifted feature gives the Hilbert inner product; both factors are in L².

          4. 4Produce the finite signed pairing

            Integrate this same potential under each actual empirical law. Finite-sum cancellation and linearity give both the indexed update and the mean-displacement pairing.

          5. 5Identify the exact scalar remainder

            Apply the finite Hilbert replacement identity and identify both risk norms with their actual scalar losses. Push the squared predictor difference back to the true input marginal.

          6. 6Obtain the uniform positive budget

            The two actual lifted feature norms are at most b; their indexed average changes by at most2b/N. Square that derived estimate. The supplied positive b makes the shared budget coefficient strictly positive.

          Full assumptions and notation

          All objects and hypotheses

          • P is the true joint data probability; PX is its pushforward by fst, and z.2 is the actual response.
          • For every q, K(q) is in L²(PX) with norm at most one common b>0; z.2 is in L²(P).
          • N>0; measurable singleton points permit actual finite Dirac integration. Repeated particle values are allowed.

          Mathematical proof

          1. Construct and evaluate both empirical laws

          Normalize the actual N Dirac masses, and integrate each fixed scalar slice by the finite-sum identity. Updating the configuration changes exactly one index.

          \[\rho=N^{-1}\sum_j\delta_{w_j},\quad f_\rho(x)=N^{-1}\sum_jK(w_j,x).\]
          Corresponding Lean step

          The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

          2. Lift through the true marginal

          Work in H=L²(P). Write a_q=[K(q) composed with fst], y=[z↦z.2], m=N^{-1} sum_j a_(w_j), and mNew=N^{-1} sum_j a_(updated w_j). The map fst preserves P to its actual pushforward PX. Its L² pullback is an isometry. Thus the actual lifted features have the supplied norm bound under the same joint P, and the actual residual is in L².

          \[\|[K(q)\circ\mathrm{fst}]\|_{L^2(P)}=\|[K(q)]\|_{L^2(P_X)}\le b.\]
          Corresponding Lean step

          The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

          3. Identify the actual potential

          Identify the actual finite predictor residual with its L² class. Integrating its product with each actual lifted feature gives the Hilbert inner product; both factors are in L².

          \[V(q)=2\langle m-y,[K(q)\circ\mathrm{fst}]\rangle_{L^2(P)}.\]
          Corresponding Lean step

          The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

          4. Produce the finite signed pairing

          Integrate this same potential under each actual empirical law. Finite-sum cancellation and linearity give both the indexed update and the mean-displacement pairing.

          \[D=(V(u)-V(w_i))/N=2\langle m-y,m^{\rm new}-m\rangle.\]
          Corresponding Lean step

          The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

          5. Identify the exact scalar remainder

          Apply the finite Hilbert replacement identity and identify both risk norms with their actual scalar losses. Push the squared predictor difference back to the true input marginal.

          \[F(\rho^{\rm new})-F(\rho)-D=\|m^{\rm new}-m\|_{L^2(P)}^2=\int(f_{\rho^{\rm new}}-f_\rho)^2dP_X.\]
          Corresponding Lean step

          The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

          6. Obtain the uniform positive budget

          The two actual lifted feature norms are at most b; their indexed average changes by at most2b/N. Square that derived estimate. The supplied positive b makes the shared budget coefficient strictly positive.

          \[\|m^{\rm new}-m\|\le2b/N,\quad0\le F(\rho^{\rm new})-F(\rho)-D\le4b^2/N^2,\quad4b^2>0.\]
          Corresponding Lean step

          The exact statement and proof are extracted from the adjacent compiled module; the mathematical step is explained here.

          Lean verification

          The exact proof begins folded immediately after the mathematical argument; the statement is folded beside the claim above.

          Lean proof · joint_empirical_squared_risk_replacement

          See the adjacent exact Lean and the mathematical proof steps.

          Braces mark parameters Lean can infer; square brackets request structures such as a measurable space or probability measure. Named hypotheses are mathematical premises, not facts established by this declaration. Section parameters are described in the mathematical hypotheses above; the module link retains their exact source context.

          Download module (.lean)
          theorem joint_empirical_squared_risk_replacement
              {W X : Type*} [MeasurableSpace W] [MeasurableSingletonClass W]
              [MeasurableSpace X] (P : Measure (X × ℝ)) [IsProbabilityMeasure P]
              (K : W → X → ℝ) (b : ℝ) (hb : 0 < b)
              (hfeature : ∀ q, MemLp (K q) 2 (P.map Prod.fst))
              (hbound : ∀ q, ‖(hfeature q).toLp (K q)‖ ≤ b)
              (hlabel : MemLp (fun z : X × ℝ => z.2) 2 P)
              {N : ℕ} (hN : 0 < N) (w : Fin N → W) (i : Fin N) (u : W) :
              let rho : Measure W := (N : ℝ≥0∞)⁻¹ • ∑ j, Measure.dirac (w j)
              let rhoNew : Measure W :=
                (N : ℝ≥0∞)⁻¹ • ∑ j, Measure.dirac (Function.update w i u j)
              let predictor : Measure W → X → ℝ := fun law x => ∫ q, K q x ∂law
              let risk : Measure W → ℝ :=
                fun law => ∫ z, (predictor law z.1 - z.2) ^ 2 ∂P
              let potential : W → ℝ :=
                fun q => 2 * ∫ z, (predictor rho z.1 - z.2) * K q z.1 ∂P
              let pairing : ℝ := (∫ q, potential q ∂rhoNew) - (∫ q, potential q ∂rho)
              (0 < 4 * b ^ 2) ∧ IsProbabilityMeasure rho ∧ IsProbabilityMeasure rhoNew ∧
              Integrable (fun z : X × ℝ => (predictor rho z.1 - z.2) ^ 2) P ∧
              Integrable (fun z : X × ℝ => (predictor rhoNew z.1 - z.2) ^ 2) P ∧
              Integrable potential rho ∧ Integrable potential rhoNew ∧
              (pairing = (N : ℝ)⁻¹ * (potential u - potential (w i))) ∧
              (risk rhoNew - risk rho - pairing =
                ∫ x, (predictor rhoNew x - predictor rho x) ^ 2 ∂(P.map Prod.fst)) ∧
              (0 ≤ risk rhoNew - risk rho - pairing) ∧
              (risk rhoNew - risk rho - pairing ≤ 4 * b ^ 2 / (N : ℝ) ^ 2) := by
            classical
            dsimp only
            let rhoOf : (Fin N → W) → Measure W :=
              fun cfg => (N : ℝ≥0∞)⁻¹ • ∑ j, Measure.dirac (cfg j)
            let cfgNew := Function.update w i u
            let predictor : Measure W → X → ℝ := fun law x => ∫ q, K q x ∂law
            let risk : Measure W → ℝ := fun law => ∫ z, (predictor law z.1 - z.2) ^ 2 ∂P
            let potential : W → ℝ :=
              fun q => 2 * ∫ z, (predictor (rhoOf w) z.1 - z.2) * K q z.1 ∂P
            let pairing : ℝ := (∫ q, potential q ∂rhoOf cfgNew) - (∫ q, potential q ∂rhoOf w)
            change (0 < 4 * b ^ 2) ∧ IsProbabilityMeasure (rhoOf w) ∧
              IsProbabilityMeasure (rhoOf cfgNew) ∧ _
            have hmarg : MeasurePreserving (Prod.fst : X × ℝ → X) P (P.map Prod.fst) :=
              measurable_fst.measurePreserving P
            have hfeatureP (q : W) : MemLp (fun z : X × ℝ => K q z.1) 2 P :=
              (hfeature q).comp_measurePreserving hmarg
            let feature : W → Lp ℝ 2 P :=
              fun q => (hfeatureP q).toLp (fun z : X × ℝ => K q z.1)
            let label : Lp ℝ 2 P := hlabel.toLp (fun z : X × ℝ => z.2)
            let mean : (Fin N → W) → Lp ℝ 2 P :=
              fun cfg => (N : ℝ)⁻¹ • ∑ j, feature (cfg j)
            have hfeatureClass (q : W) : feature q =
                Lp.compMeasurePreserving Prod.fst hmarg ((hfeature q).toLp (K q)) := rfl
            have hnorm (q : W) : ‖feature q‖ ≤ b := by
              rw [hfeatureClass, Lp.norm_compMeasurePreserving]
              exact hbound q
            have hinv : (N : ℝ≥0∞)⁻¹ ≠ ∞ := by
              apply ENNReal.inv_ne_top.mpr
              exact_mod_cast hN.ne'
            have hInt (cfg : Fin N → W) (g : W → ℝ) :
                Integrable g (rhoOf cfg) := by
              apply Integrable.smul_measure (c := (N : ℝ≥0∞)⁻¹) _ hinv
              exact integrable_finsetSum_measure.mpr (fun j _ => integrable_dirac (by simp))
            have hEval (cfg : Fin N → W) (g : W → ℝ) :
                (∫ q, g q ∂rhoOf cfg) = (N : ℝ)⁻¹ * ∑ j, g (cfg j) := by
              dsimp only [rhoOf]
              rw [integral_smul_measure,
                integral_finsetSum_measure (fun j _ => integrable_dirac (by simp))]
              simp [smul_eq_mul]
            have hPred (cfg : Fin N → W) (x : X) :
                predictor (rhoOf cfg) x = (N : ℝ)⁻¹ * ∑ j, K (cfg j) x :=
              hEval cfg (fun q => K q x)
            have hBase (cfg : Fin N → W) :=
              empirical_law_squared_risk_eq_L2_norm P hN cfg
                (fun q z => K q z.1) (fun z => z.2) (fun j => hfeatureP (cfg j)) hlabel
            have hRisk (cfg : Fin N → W) : risk (rhoOf cfg) = ‖mean cfg - label‖ ^ 2 := by
              simpa only [risk, predictor, rhoOf, mean, feature, label] using (hBase cfg).2.2
            have hMean (cfg : Fin N → W) :
                (fun z => mean cfg z) =ᵐ[P] (fun z : X × ℝ => predictor (rhoOf cfg) z.1) := by
              filter_upwards [Lp.coeFn_smul (N : ℝ)⁻¹ (∑ j, feature (cfg j)),
                Lp.coeFn_fun_finsetSum Finset.univ (fun j => feature (cfg j)),
                ae_all_iff.2 (fun j => (hfeatureP (cfg j)).coeFn_toLp)]
                with z hsmul hsum hf
              change (((N : ℝ)⁻¹ • ∑ j, feature (cfg j)) z) = _
              simp only [Pi.smul_apply, smul_eq_mul] at hsmul
              rw [hsmul, hsum, hPred]
              congr 1
              apply Finset.sum_congr rfl
              intro j _
              exact hf j
            have hResidual : (fun z => (mean w - label) z) =ᵐ[P]
                (fun z : X × ℝ => predictor (rhoOf w) z.1 - z.2) := by
              filter_upwards [Lp.coeFn_sub (mean w) label, hMean w, hlabel.coeFn_toLp]
                with z hsub hm hy
              simp only [Pi.sub_apply] at hsub
              rw [hsub, hm, hy]
            have hPotential (q : W) : potential q = 2 * ⟪mean w - label, feature q⟫_ℝ := by
              dsimp only [potential]
              rw [L2.inner_def]
              congr 1
              apply integral_congr_ae
              filter_upwards [hResidual, (hfeatureP q).coeFn_toLp] with z hr hq
              change feature q z = K q z.1 at hq
              simp only [Real.inner_apply, hr, hq]
            have hPotMean (cfg : Fin N → W) :
                (∫ q, potential q ∂rhoOf cfg) = 2 * ⟪mean w - label, mean cfg⟫_ℝ := by
              rw [hEval]
              simp_rw [hPotential]
              dsimp only [mean]
              rw [real_inner_smul_right, inner_sum, ← Finset.mul_sum]
              ring
            have hPair : pairing = 2 * ⟪mean w - label, mean cfgNew - mean w⟫_ℝ := by
              dsimp only [pairing]
              rw [hPotMean, hPotMean, inner_sub_right]
              ring
            have hUpdate : (fun j => feature (cfgNew j)) =
                Function.update (fun j => feature (w j)) i (feature u) := by
              funext j
              by_cases hji : j = i
              · subst j
                simp [cfgNew]
              · simp [cfgNew, Function.update_of_ne hji]
            have hBudget := empirical_squared_loss_replacement hN
              (fun j => feature (w j)) i (feature u) label b (hnorm (w i)) (hnorm u)
            change (‖(N : ℝ)⁻¹ • ∑ j, Function.update (fun j => feature (w j)) i (feature u) j - label‖ ^ 2 -
                ‖mean w - label‖ ^ 2 -
                2 * ⟪mean w - label,
                  (N : ℝ)⁻¹ • ∑ j, Function.update (fun j => feature (w j)) i (feature u) j - mean w⟫_ℝ =
                ‖(N : ℝ)⁻¹ • ∑ j, Function.update (fun j => feature (w j)) i (feature u) j - mean w‖ ^ 2) ∧ _ at hBudget
            rw [← hUpdate] at hBudget
            change (‖mean cfgNew - label‖ ^ 2 - ‖mean w - label‖ ^ 2 -
                2 * ⟪mean w - label, mean cfgNew - mean w⟫_ℝ = ‖mean cfgNew - mean w‖ ^ 2) ∧
              ‖mean cfgNew - mean w‖ ^ 2 ≤ 4 * b ^ 2 / (N : ℝ) ^ 2 at hBudget
            have hBre : risk (rhoOf cfgNew) - risk (rhoOf w) - pairing =
                ‖mean cfgNew - mean w‖ ^ 2 := by
              rw [hRisk, hRisk, hPair]
              exact hBudget.1
            have hMeanDiff : (fun z => (mean cfgNew - mean w) z) =ᵐ[P]
                (fun z : X × ℝ => predictor (rhoOf cfgNew) z.1 - predictor (rhoOf w) z.1) := by
              filter_upwards [Lp.coeFn_sub (mean cfgNew) (mean w), hMean cfgNew, hMean w]
                with z hsub hn hm
              simp only [Pi.sub_apply] at hsub
              rw [hsub, hn, hm]
            have hPredLp (cfg : Fin N → W) : MemLp (predictor (rhoOf cfg)) 2 (P.map Prod.fst) := by
              have havg := (memLp_finsetSum Finset.univ (fun j _ => hfeature (cfg j))).const_smul (N : ℝ)⁻¹
              exact MemLp.ae_eq (Filter.Eventually.of_forall (fun x => (hPred cfg x).symm)) havg
            have hDiffLp := (hPredLp cfgNew).sub (hPredLp w)
            have hNormInt : ‖mean cfgNew - mean w‖ ^ 2 =
                ∫ x, (predictor (rhoOf cfgNew) x - predictor (rhoOf w) x) ^ 2 ∂(P.map Prod.fst) := by
              rw [← real_inner_self_eq_norm_sq, L2.inner_def]
              calc
                (∫ z, ⟪(mean cfgNew - mean w) z, (mean cfgNew - mean w) z⟫_ℝ ∂P) =
                    ∫ z : X × ℝ, (predictor (rhoOf cfgNew) z.1 - predictor (rhoOf w) z.1) ^ 2 ∂P := by
                  apply integral_congr_ae
                  filter_upwards [hMeanDiff] with z hz
                  simp only [Real.inner_apply, hz, pow_two]
                _ = _ := (integral_map measurable_fst.aemeasurable hDiffLp.integrable_sq.aestronglyMeasurable).symm
            have hPairUpdate : pairing = (N : ℝ)⁻¹ * (potential u - potential (w i)) := by
              dsimp only [pairing]
              rw [hEval, hEval, ← mul_sub, ← Finset.sum_sub_distrib, Finset.sum_eq_single i]
              · simp [cfgNew]
              · intro j _ hji
                simp [cfgNew, Function.update_of_ne hji]
              · simp
            refine ⟨mul_pos (by norm_num) (sq_pos_of_pos hb), (hBase w).1, (hBase cfgNew).1,
              (hBase w).2.1, (hBase cfgNew).2.1, hInt w potential, hInt cfgNew potential,
              hPairUpdate, ?_, ?_, ?_⟩
            · exact hBre.trans hNormInt
            · rw [hBre]
              exact sq_nonneg _
            · rw [hBre]
              exact hBudget.2
          
          end AutoSamplingTheory.TechnicalLemmas.Analysis.QuadraticFeatureRisk

          Exact module and namespace context

          Scope and omitted-condition boundaries
          • The literal residual potential is identified on fixed finite empirical laws; no global first-variation interface on all probability laws is asserted.
          • Sectionwise L² membership does not produce global parameter measurability or non-atomic/random-configuration averaging.
          • Specific activation and data families must supply their actual uniform moments; no stochastic convergence or geometric derivative theorem is included.
          Sources, dependencies, and reuse

          Source and reuse

          Samplinglib parents called

          Mathlib API called (external library)

          • Measurable.measurePreserving
          • MemLp.comp_measurePreserving
          • Lp.compMeasurePreserving
          • Lp.norm_compMeasurePreserving
          • L2.inner_def
          • integral_map
          • integrable_dirac
          • Integrable.smul_measure
          • integrable_finsetSum_measure
          • MemLp.ae_eq

          Mathematical sources

          Samplinglib prose is not a quotation or a source-equivalence certificate. Definitions and aliases are explained as constructions, not counted as new mathematical proofs.