Stat.Nonparametric.MomentProblems.ResidualQuadratic
Residual-quadratic moment problems: moment-coordinate formulas, measure-level L² projection residuals, and projection residual orthogonality identities.
MomentAlgebra 15 core · 7 supporting This is the measure-free algebra layer for the MomentProblems folder. ★ residualQuad_optimalCoeff★ momentResidual_le_envelope
Moment-coordinate algebra for residual quadratic moment problems
This is the measure-free algebra layer for the MomentProblems folder. It works only with raw
moments m₁, m₂, m₃, m₄, and proves the identities used by the measure-level L² projection and
bounded-outcome envelope files.
The central residual is the squared L²(μ)-distance of y² to span{1, y}, i.e. the residual
variance of regressing y² on 1 and y:
r(μ) = min_{b₀, b₁} ∫ (y² − b₀ − b₁ y)² dμ.
For any law with moments m₁, m₂, m₃, m₄ (and m₀ = 1) this residual has the closed form
momentResidual m₁ m₂ m₃ m₄, the ratio of the two leading Hankel determinants. This file proves,
purely at the level of moments (no measure theory):
* residualQuad_ge_momentResidual / residualQuad_optimalCoeff — momentResidual is exactly the
minimum over (b₀, b₁) of the regression objective, whenever the design is nondegenerate
(m₁² < m₂, i.e. positive variance). This is the reusable residual-variance formula.
* extremalResidual_eq_envelope — the extremal three-point law on {0, xᵥ, 1} with second moment
q, encoded through its moments M₁ = t, M₂ = q, M₃, M₄ (single fractions of the free
support parameter t and q), has residual exactly the closed form
momentEnvelope t q = ((t − q)(q − t²)) / (4 t (1 − t)), for every admissible t.
* momentEnvelope_hasDerivAt / momentEnvelope_stationary_of_quartic — as a function of the
support parameter t, the family residual momentEnvelope t q has derivative
envelopeQuartic t q / (4 t² (t − 1)²), so its stationary points are exactly the roots of the
quartic t⁴ − 2t³ + 2q t² − 2q² t + q² = 0. The maximizing root t = μᵥ ∈ (q, √q) therefore
selects the value ρ(v) = momentEnvelope μᵥ q of the envelope.
* momentResidual_le_momentEnvelope / momentEnvelope_le_root / momentResidual_le_envelope — the
sharp upper bound r(μ) ≤ ρ(v) for every admissible law μ on [0,1] with ∫ y² = q,
proved by an explicit dual (SOS) certificate rather than general moment-problem machinery: a
pointwise polynomial identity whose right side y(1−y)(y−xᵥ)² is manifestly nonnegative on
[0,1], plus the quartic-root maximality of the envelope over admissible first moments.
The existence/uniqueness of the maximizing root (u = μᵥ, taken here as a hypothesis of the sharp
bound) is packaged at the measure/envelope layer in
MomentProblems.BoundedOutcomeEnvelope.QuarticRoot.
The regression objective, in moment coordinates: the second moment about the linear fit b₀ + b₁ y of y², i.e. ∫ (y² − b₀ − b₁ y)² dμ expressed through the raw moments m₁ = ∫ y, m₂ = ∫ y², m₃ = ∫ y³, m₄ = ∫ y⁴ (with m₀ = 1).
Definition (Lean source)
The closed-form residual variance of regressing y² on {1, y}: the value at the optimal coefficients of residualQuad, equal to the ratio of the two leading Hankel determinants det [[1,m₁,m₂],[m₁,m₂,m₃],[m₂,m₃,m₄]] / det [[1,m₁],[m₁,m₂]].
Definition (Lean source)
The optimal intercept b₀* in the regression of y² on {1, y}.
Definition (Lean source)
The optimal slope b₁* in the regression of y² on {1, y}.
Definition (Lean source)
Attainment at the optimal coefficients. For raw moments m1, m2, m3, m4 of a law with first moment squared strictly below the second moment (positive variance), the regression objective, evaluated at the optimal intercept and slope (optIntercept m1 m2 m3, optSlope m1 m2 m3), equals the closed-form residual momentResidual m1 m2 m3 m4.
Formal statement
Proof (Lean source)
The envelope value ρ, as a function of the support parameter t = μᵥ and q = v²: ρ = ((t − q)(q − t²)) / (4 t (1 − t)).
Definition (Lean source)
First moment M₁ = ∫ y of the extremal three-point law: the support parameter t = μᵥ.
Definition (Lean source)
Third moment M₃ = ∫ y³ of the extremal three-point law.
Definition (Lean source)
Fourth moment M₄ = ∫ y⁴ of the extremal three-point law.
Definition (Lean source)
The quartic whose stationary root in (q, √q) is the envelope maximizer t = μᵥ.
Definition (Lean source)
The interior support point xᵥ = (m² − 2 m q + q) / (2 m (1 − m)) of the extremal three-point law realizing first moment m and second moment q.
Definition (Lean source)
The intercept b₀ of the certificate's linear fit: the regression coefficient of y² on 1 for the extremal three-point law at first moment m, second moment q.
Definition (Lean source)
The slope b₁ of the certificate's linear fit: the regression coefficient of y² on y for the extremal three-point law at first moment m, second moment q.
Definition (Lean source)
The certificate cross moment ∫ y (1 − y) (y − xᵥ)² dμ of a law with moments (1, m, q, m₃, m₄), expanded in the moments (xᵥ = extremalMid m q). It is nonnegative for every law supported in [0,1] — the integral of a nonnegative polynomial — and equals the certificate slack momentEnvelope m q − residualQuad m q m₃ m₄ b₀ b₁.
Definition (Lean source)
Conditional moment-level envelope bound. Consider raw moments m, q, m3, m4 of a law and a candidate root u. If the second moment q lies strictly between 0 and 1, if the first moment m is at least q while m² still lies below q, i.e. the design has positive variance, if a supplied cross-moment combination of m, q, m3, m4 is nonnegative, and if u satisfies q < u, u² < q, and solves the envelope's stationarity quartic exactly, then the moment-level residual variance of regressing y² on {1, y} under moments (m, q, m3, m4) is at most the envelope value momentEnvelope u q.
Formal statement
Proof (Lean source)
7 supporting declarations (lemmas, instances)
-
residualQuad_ge_momentResidualtheorem — The closed-form residual momentResidual is a lower bound for the regression objective at every choice of coefficients, when the design is nondegenerate (m₁² < m₂, positive variance). Together with residualQuad_optimalCoeff this shows momentResidual is the minimum min_{b₀,b₁} ∫ (y² − b₀ − b₁ y)² dμ.hypothesesm1 m2 m3 m4 b0 b1 :ℝh :m1 ^ 2 < m2conclusionmomentResidual m1 m2 m3 m4 ≤ residualQuad m1 m2 m3 m4 b0 b1Proof (Lean source)
theorem residualQuad_ge_momentResidual (m1 m2 m3 m4 b0 b1 : ℝ) (h : m1 ^ 2 < m2) : momentResidual m1 m2 m3 m4 ≤ residualQuad m1 m2 m3 m4 b0 b1 := by have hd : m1 ^ 2 - m2 ≠ 0 := by nlinarith have key : residualQuad m1 m2 m3 m4 b0 b1 - momentResidual m1 m2 m3 m4 = (b0 - optIntercept m1 m2 m3 + m1 * (b1 - optSlope m1 m2 m3)) ^ 2 + (m2 - m1 ^ 2) * (b1 - optSlope m1 m2 m3) ^ 2 := by unfold residualQuad momentResidual optIntercept optSlope field_simp ring nlinarith [sq_nonneg (b0 - optIntercept m1 m2 m3 + m1 * (b1 - optSlope m1 m2 m3)), sq_nonneg (b1 - optSlope m1 m2 m3), key, h] -
extremalResidual_eq_envelopetheorem — Family residual identity. For every nondegenerate support parameter t (with t ≠ 0, t ≠ 1, and second moment q ≠ t²), the residual variance of regressing y² on {1, y} under the three-point law with moments (t, q, M₃, M₄) equals the closed form momentEnvelope t q. In particular ρ(v) is attained by an admissible law at second moment q = v².hypothesest q :ℝht0 :t ≠ 0ht1 :t ≠ 1htq :t ^ 2 ≠ qconclusionProof (Lean source)
theorem extremalResidual_eq_envelope (t q : ℝ) (ht0 : t ≠ 0) (ht1 : t ≠ 1) (htq : t ^ 2 ≠ q) : momentResidual (extremalM1 t) q (extremalM3 t q) (extremalM4 t q) = momentEnvelope t q := by unfold momentResidual momentEnvelope extremalM1 extremalM3 extremalM4 have h1 : t - 1 ≠ 0 := sub_ne_zero.mpr ht1 have h1' : (1 : ℝ) - t ≠ 0 := by intro h apply ht1 linarith have h2 : (t : ℝ) ^ 2 - q ≠ 0 := sub_ne_zero.mpr htq have h2' : q - t ^ 2 ≠ 0 := by intro h apply h2 linarith field_simp [ht0, h1, h1', h2, h2'] ring -
momentEnvelope_hasDerivAttheorem — Stationarity / envelope FOC. As a function of the support parameter t, the family residual momentEnvelope t q has derivative envelopeQuartic t q / (4 t² (t − 1)²). Hence the quartic is exactly the numerator of dρ/dt, and the envelope's stationary points are its roots.hypothesest q :ℝht0 :t ≠ 0ht1 :t ≠ 1conclusionProof (Lean source)
theorem momentEnvelope_hasDerivAt (t q : ℝ) (ht0 : t ≠ 0) (ht1 : t ≠ 1) : HasDerivAt (fun s => momentEnvelope s q) (envelopeQuartic t q / (4 * t ^ 2 * (t - 1) ^ 2)) t := by have hN : HasDerivAt (fun s : ℝ => (s - q) * (q - s ^ 2)) (1 * (q - t ^ 2) + (t - q) * (-(2 * t))) t := by have h1 : HasDerivAt (fun s : ℝ => s - q) 1 t := (hasDerivAt_id t).sub_const q have h2 : HasDerivAt (fun s : ℝ => q - s ^ 2) (-(2 * t)) t := by have hp : HasDerivAt (fun s : ℝ => s ^ 2) (2 * t) t := by simpa using (hasDerivAt_pow 2 t) exact HasDerivAt.const_sub q hp exact h1.fun_mul h2 have hD : HasDerivAt (fun s : ℝ => 4 * s * (1 - s)) (4 * (1 - t) + 4 * t * (-1)) t := by have h3 : HasDerivAt (fun s : ℝ => 4 * s) 4 t := by simpa using (hasDerivAt_id t).const_mul (4 : ℝ) have h4 : HasDerivAt (fun s : ℝ => 1 - s) (-1) t := HasDerivAt.const_sub (1 : ℝ) (hasDerivAt_id t) exact h3.fun_mul h4 have hDne : 4 * t * (1 - t) ≠ 0 := by have ht1' : (1 : ℝ) - t ≠ 0 := by intro h apply ht1 linarith exact mul_ne_zero (mul_ne_zero (by norm_num) ht0) ht1' have hderiv := hN.fun_div hD hDne have hval : envelopeQuartic t q / (4 * t ^ 2 * (t - 1) ^ 2) = ((1 * (q - t ^ 2) + (t - q) * (-(2 * t))) * (4 * t * (1 - t)) - (t - q) * (q - t ^ 2) * (4 * (1 - t) + 4 * t * (-1))) / (4 * t * (1 - t)) ^ 2 := by unfold envelopeQuartic field_simp [ht0, ht1] ring unfold momentEnvelope rw [hval] exact hderiv -
momentEnvelope_stationary_of_quartictheorem — At a root t of the quartic, the family residual momentEnvelope · q is stationary. The maximizing root t = μᵥ ∈ (q, √q) therefore realizes the envelope value ρ(v).hypothesesconclusionderiv (fun s => momentEnvelope s q) t = 0Proof (Lean source)
theorem momentEnvelope_stationary_of_quartic (t q : ℝ) (ht0 : t ≠ 0) (ht1 : t ≠ 1) (hquar : envelopeQuartic t q = 0) : deriv (fun s => momentEnvelope s q) t = 0 := by rw [(momentEnvelope_hasDerivAt t q ht0 ht1).deriv, hquar, zero_div] -
residualQuad_extremalCoeff_eqtheorem — Dual-certificate identity (integrated). For the certificate's linear-fit coefficients, the regression objective equals the envelope value minus the cross moment: residualQuad m q m₃ m₄ b₀ b₁ = momentEnvelope m q − crossMoment m q m₃ m₄. This is the moment-level form of the pointwise SOS certificate, a pure algebraic identity (ring) valid for m ≠ 0, m ≠ 1, m² ≠ q.hypothesesm q m3 m4 :ℝhm0 :m ≠ 0hm1 :m ≠ 1hmq :m ^ 2 ≠ qconclusionresidualQuad m q m3 m4 (extremalCoeff0 m q) (extremalCoeff1 m q)= momentEnvelope m q - crossMoment m q m3 m4Proof (Lean source)
theorem residualQuad_extremalCoeff_eq (m q m3 m4 : ℝ) (hm0 : m ≠ 0) (hm1 : m ≠ 1) (hmq : m ^ 2 ≠ q) : residualQuad m q m3 m4 (extremalCoeff0 m q) (extremalCoeff1 m q) = momentEnvelope m q - crossMoment m q m3 m4 := by have h1m : (1 : ℝ) - m ≠ 0 := by intro h apply hm1 linarith have hm1' : m - 1 ≠ 0 := sub_ne_zero.mpr hm1 have hmq' : m ^ 2 - q ≠ 0 := sub_ne_zero.mpr hmq unfold residualQuad momentEnvelope crossMoment extremalCoeff0 extremalCoeff1 extremalM3 extremalMid field_simp [hm0, hm1', h1m, hmq'] ring -
momentResidual_le_momentEnvelopetheorem — Sharp per-instance bound. For an admissible moment tuple (1, m, q, m₃, m₄) of a law on [0,1] with positive variance (m² < q) and nonnegative cross moment (0 ≤ crossMoment m q m₃ m₄, automatic for any law on [0,1]), the residual variance of regressing y² on {1, y} is at most the envelope value at the law's own first moment: momentResidual m q m₃ m₄ ≤ momentEnvelope m q.hypothesesconclusionmomentResidual m q m3 m4 ≤ momentEnvelope m qProof (Lean source)
theorem momentResidual_le_momentEnvelope (m q m3 m4 : ℝ) (hm0 : 0 < m) (hm1 : m < 1) (hmq : m ^ 2 < q) (hcross : 0 ≤ crossMoment m q m3 m4) : momentResidual m q m3 m4 ≤ momentEnvelope m q := by have hmq' : m ^ 2 ≠ q := ne_of_lt hmq have hlb := residualQuad_ge_momentResidual m q m3 m4 (extremalCoeff0 m q) (extremalCoeff1 m q) hmq have heq := residualQuad_extremalCoeff_eq m q m3 m4 (ne_of_gt hm0) (ne_of_lt hm1) hmq' rw [heq] at hlb linarith -
momentEnvelope_le_roottheorem — Envelope maximality. Among admissible first moments the envelope momentEnvelope · q is maximized at a quartic root u = μᵥ: if q < u, u² < q, and envelopeQuartic u q = 0, then for every admissible first moment m with q ≤ m, m² < q, one has momentEnvelope m q ≤ momentEnvelope u q.hypothesesm q u :ℝhq0 :0 < qhq1 :q < 1hqm :q ≤ mhmq :m ^ 2 < qhqu :q < uhuq :u ^ 2 < qhroot :envelopeQuartic u q = 0conclusionmomentEnvelope m q ≤ momentEnvelope u qProof (Lean source)
theorem momentEnvelope_le_root (m q u : ℝ) (hq0 : 0 < q) (hq1 : q < 1) (hqm : q ≤ m) (hmq : m ^ 2 < q) (hqu : q < u) (huq : u ^ 2 < q) (hroot : envelopeQuartic u q = 0) : momentEnvelope m q ≤ momentEnvelope u q := by have hm0 : 0 < m := lt_of_lt_of_le hq0 hqm have hu0 : 0 < u := lt_trans hq0 hqu have hm1 : m < 1 := by nlinarith have hu1 : u < 1 := by nlinarith have hDpos : 0 < 4 * m * u * (m - 1) * (u - 1) := by nlinarith [mul_pos hm0 hu0] have hLneg : m * u ^ 2 - m * u - q ^ 2 + 2 * q * u + u ^ 3 - 2 * u ^ 2 < 0 := by nlinarith [mul_nonneg (sub_nonneg.mpr hqm) (le_of_lt (sub_pos.mpr hqu)), mul_nonneg (le_of_lt hu0) (le_of_lt (sub_pos.mpr hqu)), mul_nonneg (le_of_lt hm0) (le_of_lt (sub_pos.mpr huq)), mul_nonneg (le_of_lt hu0) (le_of_lt (sub_pos.mpr huq))] have hmne : m ≠ 0 := ne_of_gt hm0 have hune : u ≠ 0 := ne_of_gt hu0 have hm1ne : m - 1 ≠ 0 := by intro h nlinarith have hu1ne : u - 1 ≠ 0 := by intro h nlinarith have h1mne : (1 : ℝ) - m ≠ 0 := by intro h nlinarith have h1une : (1 : ℝ) - u ≠ 0 := by intro h nlinarith have key : momentEnvelope u q - momentEnvelope m q = (u - m) ^ 2 * (-(m * u ^ 2 - m * u - q ^ 2 + 2 * q * u + u ^ 3 - 2 * u ^ 2)) / (4 * m * u * (m - 1) * (u - 1)) + (u - m) / (4 * m * u * (m - 1) * (u - 1)) * envelopeQuartic u q := by unfold momentEnvelope envelopeQuartic field_simp [hmne, hune, hm1ne, hu1ne, h1mne, h1une] ring rw [hroot, mul_zero, add_zero] at key have hpos : 0 ≤ (u - m) ^ 2 * (-(m * u ^ 2 - m * u - q ^ 2 + 2 * q * u + u ^ 3 - 2 * u ^ 2)) / (4 * m * u * (m - 1) * (u - 1)) := by apply div_nonneg _ (le_of_lt hDpos) exact mul_nonneg (sq_nonneg _) (by linarith) linarith [key, hpos]
MeasureBridge 7 core · 4 supporting This file is the measure bridge for the MomentProblems stack. ★ iInf_residualQuad
Measure-level L² projection residual of y ↦ y² onto span{1, y}
This file is the measure bridge for the MomentProblems stack. MomentAlgebra.lean proves the
closed-form residual purely in moment coordinates; this file turns that algebra into the actual
L²(μ) projection residual for probability measures on ℝ with finite fourth moment:
r(μ) = ⨅_{b₀,b₁} ∫ (y² − b₀ − b₁ y)² dμ.
Writing mₖ = ∫ yᵏ dμ for the raw moments, the closed form is the Hankel-determinant ratio
r(μ) = (m₄ − m₂²) − (m₃ − m₁ m₂)² / (m₂ − m₁²) = det H₃ / det H₂,
attained at the least-squares optimal coefficients b₁* = (m₃ − m₁ m₂)/(m₂ − m₁²),
b₀* = m₂ − b₁* m₁ (here written optIntercept, optSlope).
Design
The moment-level algebra — that the quadratic objective residualQuad m₁ m₂ m₃ m₄ b₀ b₁ in
(b₀, b₁) has minimum the Hankel ratio, via a completed-square / SOS certificate — is proven,
measure-free, in Causalean.Stat.MomentProblems.ResidualQuadratic.MomentAlgebra
(residualQuad_optimalCoeff, residualQuad_ge_momentResidual). This module supplies the
measure-theoretic bridge:
* residualQuad_eq — the bridge: expanding the square and integrating term by term,
∫ (y² − b₀ − b₁ y)² dμ equals the moment polynomial
MomentAlgebra.residualQuad m₁ m₂ m₃ m₄ b₀ b₁ (uses IsProbabilityMeasure for the constant
term ∫ b₀² = b₀² and integrability of y, …, y⁴ to split the integral).
* residualQuad_opt_eq, l2ResidualQuadratic_le, l2ResidualQuadratic_nonneg,
iInf_residualQuad — the optimality / infimum bridge transporting the moment-level minimum to
the ∫-form and the conditional infimum ⨅ b₀ b₁.
Finite fourth moment is packaged as FiniteMoment4 μ (integrability of y, y², y³, y⁴); for a
probability measure with ∫ y⁴ < ∞ all these lower moments are finite, so this is exactly the
"finite 4th moment" hypothesis. Non-degeneracy is m₁² < m₂ (positive variance).
The raw k-th moment mₖ = ∫ yᵏ ∂μ of a measure μ on ℝ.
Finite-fourth-moment hypothesis bundle: integrability of y, of y², of y³, and of y⁴ against μ. For a probability measure with ∫ y⁴ ∂μ < ∞ all four hold, so this is exactly "μ has a finite fourth moment".
Definition (Lean source)
The quadratic regression objective in L²(μ): the mean squared residual of the linear fit b₀ + b₁ y to y², i.e. ∫ (y² − b₀ − b₁ y)² ∂μ.
Definition (Lean source)
The closed-form minimal residual r(μ) = (m₄ − m₂²) − (m₃ − m₁ m₂)² / (m₂ − m₁²), expressed as the Hankel-determinant ratio MomentAlgebra.momentResidual of the raw moments m₁, m₂, m₃, m₄.
Definition (Lean source)
The least-squares optimal intercept b₀* = (m₁ m₃ − m₂²)/(m₁² − m₂) = m₂ − b₁* m₁.
Definition (Lean source)
The least-squares optimal slope b₁* = (m₃ − m₁ m₂)/(m₂ − m₁²).
Headline infimum identity. For a probability measure μ on ℝ with a finite fourth moment and first moment squared strictly below the second moment (positive variance), the infimum, over every intercept and slope, of the mean squared residual of fitting b₀ + b₁y to y² equals the closed-form Hankel-determinant residual l2ResidualQuadratic μ, attained at the least-squares-optimal coefficients (optIntercept μ, optSlope μ):
Formal statement
Proof (Lean source)
4 supporting declarations (lemmas, instances)
-
residualQuad_eqtheorem — Bridge (integral → moments). For a probability measure with finite fourth moment, the integral objective equals the moment polynomial: expanding (y² − b₀ − b₁ y)² = y⁴ − 2b₁ y³ + (b₁² − 2b₀) y² + 2b₀b₁ y + b₀² and integrating term by term (using ∫ 1 ∂μ = 1),hypothesesconclusionresidualQuad μ b₀ b₁Proof (Lean source)
theorem residualQuad_eq (μ : Measure ℝ) [IsProbabilityMeasure μ] (h : FiniteMoment4 μ) (b₀ b₁ : ℝ) : residualQuad μ b₀ b₁ = Causalean.Stat.MomentProblems.ResidualQuadratic.MomentAlgebra.residualQuad (moment μ 1) (moment μ 2) (moment μ 3) (moment μ 4) b₀ b₁ := by unfold residualQuad moment Causalean.Stat.MomentProblems.ResidualQuadratic.MomentAlgebra.residualQuad have hpoly : (fun y : ℝ => (y ^ 2 - b₀ - b₁ * y) ^ 2) = fun y : ℝ => (((((y ^ 4 + (-(2 * b₁)) * y ^ 3) + (-(2 * b₀)) * y ^ 2) + (b₁ ^ 2) * y ^ 2) + (2 * b₀ * b₁) * y) + b₀ ^ 2) := by funext y ring rw [hpoly] have hi3 : Integrable (fun y : ℝ => (-(2 * b₁)) * y ^ 3) μ := h.int3.const_mul _ have hi2a : Integrable (fun y : ℝ => (-(2 * b₀)) * y ^ 2) μ := h.int2.const_mul _ have hi2b : Integrable (fun y : ℝ => (b₁ ^ 2) * y ^ 2) μ := h.int2.const_mul _ have hi1 : Integrable (fun y : ℝ => (2 * b₀ * b₁) * y) μ := h.int1.const_mul _ have hic : Integrable (fun _ : ℝ => b₀ ^ 2) μ := integrable_const _ have hs1 : Integrable (fun y : ℝ => y ^ 4 + (-(2 * b₁)) * y ^ 3) μ := h.int4.add hi3 have hs2 : Integrable (fun y : ℝ => (y ^ 4 + (-(2 * b₁)) * y ^ 3) + (-(2 * b₀)) * y ^ 2) μ := hs1.add hi2a have hs3 : Integrable (fun y : ℝ => ((y ^ 4 + (-(2 * b₁)) * y ^ 3) + (-(2 * b₀)) * y ^ 2) + (b₁ ^ 2) * y ^ 2) μ := hs2.add hi2b have hs4 : Integrable (fun y : ℝ => (((y ^ 4 + (-(2 * b₁)) * y ^ 3) + (-(2 * b₀)) * y ^ 2) + (b₁ ^ 2) * y ^ 2) + (2 * b₀ * b₁) * y) μ := hs3.add hi1 rw [MeasureTheory.integral_add hs4 hic] rw [MeasureTheory.integral_add hs3 hi1] rw [MeasureTheory.integral_add hs2 hi2b] rw [MeasureTheory.integral_add hs1 hi2a] rw [MeasureTheory.integral_add h.int4 hi3] simp [MeasureTheory.integral_const_mul, MeasureTheory.integral_mul_const, MeasureTheory.integral_neg, MeasureTheory.integral_const, mul_assoc, mul_left_comm, mul_comm] ring -
residualQuad_opt_eqtheorem — Attainment. At the optimal coefficients (optIntercept μ, optSlope μ) the integral objective attains the closed-form residual l2ResidualQuadratic μ, whenever the design is non-degenerate (m₁² < m₂).hypothesesconclusionresidualQuad μ (optIntercept μ) (optSlope μ) = l2ResidualQuadratic μProof (Lean source)
theorem residualQuad_opt_eq (μ : Measure ℝ) [IsProbabilityMeasure μ] (h : FiniteMoment4 μ) (hnd : moment μ 1 ^ 2 < moment μ 2) : residualQuad μ (optIntercept μ) (optSlope μ) = l2ResidualQuadratic μ := by rw [residualQuad_eq μ h] exact residualQuad_optimalCoeff (moment μ 1) (moment μ 2) (moment μ 3) (moment μ 4) hnd -
l2ResidualQuadratic_letheorem — Lower bound (infimum). The closed-form residual is a lower bound of the integral objective at every choice of coefficients, when the design is non-degenerate. Together with residualQuad_opt_eq this identifies l2ResidualQuadratic μ as the minimum ⨅ b₀ b₁, ∫ (y² − b₀ − b₁ y)² ∂μ.hypothesesconclusionl2ResidualQuadratic μ ≤ residualQuad μ b₀ b₁Proof (Lean source)
theorem l2ResidualQuadratic_le (μ : Measure ℝ) [IsProbabilityMeasure μ] (h : FiniteMoment4 μ) (hnd : moment μ 1 ^ 2 < moment μ 2) (b₀ b₁ : ℝ) : l2ResidualQuadratic μ ≤ residualQuad μ b₀ b₁ := by rw [residualQuad_eq μ h] exact residualQuad_ge_momentResidual (moment μ 1) (moment μ 2) (moment μ 3) (moment μ 4) b₀ b₁ hnd -
l2ResidualQuadratic_nonnegtheorem — Non-negativity. The closed-form residual is non-negative (it is the value at the optimum of an integral of a square), for a non-degenerate design.hypothesesconclusion0 ≤ l2ResidualQuadratic μProof (Lean source)
theorem l2ResidualQuadratic_nonneg (μ : Measure ℝ) [IsProbabilityMeasure μ] (h : FiniteMoment4 μ) (hnd : moment μ 1 ^ 2 < moment μ 2) : 0 ≤ l2ResidualQuadratic μ := by rw [← residualQuad_opt_eq μ h hnd] exact integral_nonneg (fun y => sq_nonneg _)
ProjectionResidual 2 core · 7 supporting This file is the functional bridge between MomentProblems.ResidualQuadratic.MeasureBridge and the constrained score program. ★ integral_sq_projResidual
Projection residual function for the moment score program
This file is the functional bridge between MomentProblems.ResidualQuadratic.MeasureBridge and the
constrained score program. For a probability measure μ on ℝ with finite fourth moment and
positive variance (m₁² < m₂), MeasureBridge.lean computes the closed-form residual value
r(μ) = l2ResidualQuadratic μ; this file identifies the residual function that attains that value,
q(y) := y² − (optIntercept μ + optSlope μ · y),
and proves the four facts that make it the orthogonal projection residual of y² onto span{1,y}:
integral_projResidual:∫ q dμ = 0(orthogonal to the constant1)integral_id_mul_projResidual:∫ y·q dμ = 0(orthogonal toy)integral_sq_projResidual:∫ q² dμ = r(its own L² norm² is the residualr)integral_sq_mul_projResidual:∫ y²·q dμ = r(y²-moment ofqequalsr)
The first two are the normal equations of least squares; here they reduce, after splitting the
integral into raw moments mₖ = ∫ yᵏ, to pure moment algebra in the definitions of
optIntercept/optSlope (division by m₁² − m₂ ≠ 0). The last two reuse
MeasureBridge.residualQuad_opt_eq, the attainment lemma for the closed-form residual.
These are the ingredients consumed by ScoreProgram.lean to solve the constrained minimum-norm
"score program" dual to this projection.
The L² projection residual function of y ↦ y² onto span{1, y}: q(y) = y² − (optIntercept μ + optSlope μ · y), i.e. y² minus its least-squares linear fit.
Definition (Lean source)
Self L²-norm of the projection residual. For a probability measure μ on ℝ with a finite fourth moment and first moment squared strictly below the second moment (positive variance), the squared L² norm of the projection residual q(y) = y² − (optIntercept μ + optSlope μ · y) equals the closed-form residual l2ResidualQuadratic μ: ∫ q² dμ = l2ResidualQuadratic μ.
Formal statement
Proof (Lean source)
7 supporting declarations (lemmas, instances)
-
memL2_idtheorem — y ↦ y is in L²(μ) when the second moment is finite.Proof (Lean source)
theorem memL2_id (μ : Measure ℝ) [IsFiniteMeasure μ] (h : FiniteMoment4 μ) : MemLp (fun y : ℝ => y) 2 μ := by refine (memLp_two_iff_integrable_sq (continuous_id.aestronglyMeasurable)).2 ?_ simpa using h.int2 -
memL2_sqtheorem — y ↦ y² is in L²(μ) when the fourth moment is finite.Proof (Lean source)
theorem memL2_sq (μ : Measure ℝ) [IsFiniteMeasure μ] (h : FiniteMoment4 μ) : MemLp (fun y : ℝ => y ^ 2) 2 μ := by refine (memLp_two_iff_integrable_sq ((continuous_pow 2).aestronglyMeasurable)).2 ?_ simpa [pow_mul] using h.int4.congr (by filter_upwards with y; ring) -
projResidual_memL2theorem — The residual function q is square-integrable (q ∈ L²(μ)): it is a degree-2 polynomial in y and μ has a finite fourth moment.Proof (Lean source)
theorem projResidual_memL2 (μ : Measure ℝ) [IsFiniteMeasure μ] (h : FiniteMoment4 μ) : MemLp (projResidual μ) 2 μ := by -- `q = y² − b₁·y − b₀` is a linear combination of the L²-functions `y²`, `y`, `1`. have hsq := memL2_sq μ h have hid := memL2_id μ h have hconst : MemLp (fun _ : ℝ => optIntercept μ) 2 μ := memLp_const _ have : MemLp (fun y : ℝ => y ^ 2 - (optIntercept μ + optSlope μ * y)) 2 μ := by have h1 : MemLp (fun y : ℝ => optSlope μ * y) 2 μ := hid.const_mul _ exact (hsq.sub (hconst.add h1)) exact this -
integrable_projResidualtheorem — q is integrable (finite measure + q ∈ L²).Proof (Lean source)
theorem integrable_projResidual (μ : Measure ℝ) [IsFiniteMeasure μ] (h : FiniteMoment4 μ) : Integrable (projResidual μ) μ := (projResidual_memL2 μ h).integrable (by norm_num) -
integral_projResidualtheorem — Orthogonality to the constant. ∫ q dμ = 0.hypothesesconclusion∫ y, projResidual μ y ∂μ = 0Proof (Lean source)
theorem integral_projResidual (μ : Measure ℝ) [IsProbabilityMeasure μ] (h : FiniteMoment4 μ) (hnd : moment μ 1 ^ 2 < moment μ 2) : ∫ y, projResidual μ y ∂μ = 0 := by have hsq : Integrable (fun y : ℝ => y ^ 2) μ := (memL2_sq μ h).integrable (by norm_num) have hid : Integrable (fun y : ℝ => y) μ := (memL2_id μ h).integrable (by norm_num) have hlin : Integrable (fun y : ℝ => optIntercept μ + optSlope μ * y) μ := (integrable_const (optIntercept μ)).add (hid.const_mul (optSlope μ)) unfold projResidual rw [MeasureTheory.integral_sub hsq hlin] rw [MeasureTheory.integral_add (integrable_const (optIntercept μ)) (hid.const_mul (optSlope μ))] rw [MeasureTheory.integral_const_mul] simp only [MeasureTheory.integral_const, smul_eq_mul] rw [show μ.real univ = 1 by simp] rw [show (∫ a : ℝ, a ∂μ) = moment μ 1 by simp [moment]] change moment μ 2 - (1 * optIntercept μ + optSlope μ * moment μ 1) = 0 ring_nf have hd : moment μ 1 ^ 2 - moment μ 2 ≠ 0 := by nlinarith unfold optIntercept optSlope optIntercept optSlope field_simp [hd] ring -
integral_id_mul_projResidualtheorem — Orthogonality to y. ∫ y·q dμ = 0.hypothesesconclusion∫ y, y * projResidual μ y ∂μ = 0Proof (Lean source)
theorem integral_id_mul_projResidual (μ : Measure ℝ) [IsProbabilityMeasure μ] (h : FiniteMoment4 μ) (hnd : moment μ 1 ^ 2 < moment μ 2) : ∫ y, y * projResidual μ y ∂μ = 0 := by have hid : Integrable (fun y : ℝ => y) μ := (memL2_id μ h).integrable (by norm_num) have hsq : Integrable (fun y : ℝ => y ^ 2) μ := (memL2_sq μ h).integrable (by norm_num) have hfun : (fun y : ℝ => y * projResidual μ y) = fun y : ℝ => y ^ 3 - optIntercept μ * y - optSlope μ * y ^ 2 := by funext y simp [projResidual] ring rw [hfun] have hterm1 : Integrable (fun y : ℝ => y ^ 3 - optIntercept μ * y) μ := h.int3.sub (hid.const_mul (optIntercept μ)) have hterm2 : Integrable (fun y : ℝ => optSlope μ * y ^ 2) μ := hsq.const_mul (optSlope μ) rw [MeasureTheory.integral_sub hterm1 hterm2] rw [MeasureTheory.integral_sub h.int3 (hid.const_mul (optIntercept μ))] rw [MeasureTheory.integral_const_mul] rw [MeasureTheory.integral_const_mul] rw [show (∫ a : ℝ, a ∂μ) = moment μ 1 by simp [moment]] change moment μ 3 - optIntercept μ * moment μ 1 - optSlope μ * moment μ 2 = 0 have hd : moment μ 1 ^ 2 - moment μ 2 ≠ 0 := by nlinarith unfold optIntercept optSlope optIntercept optSlope field_simp [hd] ring -
integral_sq_mul_projResidualtheorem — y²-moment. ∫ y²·q dμ = r.hypothesesconclusion∫ y, y ^ 2 * projResidual μ y ∂μ = l2ResidualQuadratic μProof (Lean source)
theorem integral_sq_mul_projResidual (μ : Measure ℝ) [IsProbabilityMeasure μ] (h : FiniteMoment4 μ) (hnd : moment μ 1 ^ 2 < moment μ 2) : ∫ y, y ^ 2 * projResidual μ y ∂μ = l2ResidualQuadratic μ := by have hfun : (fun y : ℝ => y ^ 2 * projResidual μ y) = fun y : ℝ => projResidual μ y ^ 2 + optIntercept μ * projResidual μ y + optSlope μ * (y * projResidual μ y) := by funext y simp [projResidual] ring rw [hfun] have hq : Integrable (projResidual μ) μ := integrable_projResidual μ h have hq2 : Integrable (fun y : ℝ => projResidual μ y ^ 2) μ := (projResidual_memL2 μ h).integrable_sq have hyq : Integrable (fun y : ℝ => y * projResidual μ y) μ := (memL2_id μ h).integrable_mul (projResidual_memL2 μ h) have hbq : Integrable (fun y : ℝ => optIntercept μ * projResidual μ y) μ := hq.const_mul (optIntercept μ) have hcyq : Integrable (fun y : ℝ => optSlope μ * (y * projResidual μ y)) μ := hyq.const_mul (optSlope μ) have hsplit1 : (∫ y, (projResidual μ y ^ 2 + optIntercept μ * projResidual μ y) + optSlope μ * (y * projResidual μ y) ∂μ) = (∫ y, projResidual μ y ^ 2 + optIntercept μ * projResidual μ y ∂μ) + ∫ y, optSlope μ * (y * projResidual μ y) ∂μ := by simpa using MeasureTheory.integral_add (hq2.add hbq) hcyq have hsplit2 : (∫ y, projResidual μ y ^ 2 + optIntercept μ * projResidual μ y ∂μ) = (∫ y, projResidual μ y ^ 2 ∂μ) + ∫ y, optIntercept μ * projResidual μ y ∂μ := by simpa using MeasureTheory.integral_add hq2 hbq rw [hsplit1, hsplit2] rw [MeasureTheory.integral_const_mul] rw [MeasureTheory.integral_const_mul] rw [integral_sq_projResidual μ h hnd] rw [integral_projResidual μ h hnd] rw [integral_id_mul_projResidual μ h hnd] ring