Samplinglib
Lean gate not recorded for this source state main · ed709a7f320d
Registry leaf card · analysis.quadratic-feature-risk-6

joint_empirical_squared_risk_replacement

compiled Samplinglib leaf Not mapped explicit smoke test

Compiled generic library interface. Exact hypotheses, actual integrals and remaining global-law boundaries are exposed in the authored lesson. Current public context-bound independent semantic reviews are accepted; serialized stabilization remains pending; no stochastic algorithm or model theorem is claimed.

Plain-English statement

Compiled generic library interface. Exact hypotheses, actual integrals and remaining global-law boundaries are exposed in the authored lesson. Current public context-bound independent semantic reviews are accepted; serialized stabilization remains pending; no stochastic algorithm or model theorem is claimed.

Scope guard. This card records a compiled local declaration. Its mathematical scope is exactly the Lean statement below; the Registry note and source correspondence may describe motivation but do not strengthen it.
Lean learning studio · mathematics → formal proof

Read the mathematics first, then descend into Lean

You do not need to know Lean before opening this panel. The page keeps the paper-level theorem, rigorous proof obligations, exact Lean declaration, and proof dependencies as separate layers so a first-time reader can move down one layer at a time.

BeginnerWhy this theorem exists → intuition → statement → one hand calculation. Hide proof-engineering detail.
RigorousExpose assumptions, hidden measure/limit/domain issues, proof route, and rigorous references.
Lean learnerOpen the exact declaration, proof tree/network, syntax glossary, and line-by-line explanation.

Proof architecture

Start with the tree when learning: prerequisites sit below the theorem and downstream results sit above it. Switch to the network when you want to understand where this declaration lives in the local formal library. Every mapped node is clickable.

Loading source-derived dependency evidence…

Graph rule: only dependencies found by the ASTIS source scan are drawn. Missing tactic indirection is treated as an under-approximation; the site never invents an edge just to make a prettier graph.

How to read the exact Lean declaration

Read a Lean theorem left-to-right exactly as you would unpack a mathematical sentence: name → ambient types → automatically inferred structures → explicit hypotheses → conclusion → proof. Then read the proof top-to-bottom as transformations of the current goal.

  1. NameWhat reusable mathematical fact is being created?
  2. ParametersWhich symbols are arbitrary, and which structures are inferred by typeclass search?
  3. PropositionAfter the colon, translate the Lean expression back into a paper statement.
  4. Proof actionsAfter by, ask what each tactic does to the mathematical goal—not only what syntax it uses.

Syntax used on this page

This glossary is filtered to syntax that actually occurs in the declaration above. Open a symbol only when you meet it, rather than memorizing Lean grammar in advance.

Source voice and ASTIS voice stay separate

When Samplinglib shows a short quotation from Chewi, it is labeled as a source excerpt and linked to the canonical book page. Intuition, expanded proof steps, hidden regularity assumptions, and Lean explanations are ASTIS-authored commentary. A quotation never substitutes for a formal proof, and an ASTIS explanation is never attributed to the textbook author.

Lean statement

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

Proof architecture

Reusable squared-loss, genuine integral and indexed replacement calculations

Lean proof walkthrough

  • Read the quantified variables and typeclass brackets as part of the mathematical statement; inferred arguments are not missing assumptions.
  • `intro` introduces quantified hypotheses into the local proof context.
  • `have` creates a named intermediate mathematical fact.
  • `calc` records an equality or inequality chain matching a paper calculation.
  • `rw` rewrites by an established identity.
  • `simp` normalizes through registered definitional and theorem rewrites.
  • `apply` reduces the goal to the hypotheses of a reusable theorem.
  • `refine` instantiates a reusable theorem while leaving explicit subgoals.

Why the statement has this shape

The declaration is kept at the reusable level recorded by its Registry tags and direct consumers. Explicit measures, spaces, wrappers, and regularity hypotheses expose interfaces that paper notation often infers. A theorem card explains those interfaces but never widens the compiled statement.

Hidden assumptions and non-claims

  • Measurability is represented explicitly or must be supplied by a dependency.
  • Integrability is an input or proved output; a displayed integral alone does not supply it.
  • Almost-everywhere hypotheses depend on the stated measure and representative.
Common pitfall. A wrapper or display identity is not a new analytic theorem merely because it has its own Lean name. Check the statement, hypotheses, and downstream consumers before interpreting its mathematical contribution.