ML.Core
Roll-up of the causal-free machine-learning spine: losses, parametrized predictors and extensional hypothesis classes, empirical/population risk, the ERM-minimizer predicates, the parametric↔extensional bridge, the conve
Hypothesis 3 core · 0 supporting The standalone ML spine carries two views of a learning method, connected by Causalean.ML.Core.Bridge: * the parametric view (Predictor): a parameter type Θ together with an admissible set and a prediction map Θ → X → Y. ★ Predictor★ HypothesisClass★ FeatureMap
Hypothesis classes and parametrized predictors
The standalone ML spine carries two views of a learning method, connected by
Causalean.ML.Core.Bridge:
* the parametric view (Predictor): a parameter type Θ together with an
admissible set and a prediction map Θ → X → Y. Optimization, convexity and
regularization live here.
* the extensional view (HypothesisClass): a set of measurable functions
X → Y. Population-risk targets and best-in-class statements live here.
FeatureMap packages a feature transform X → (K → ℝ) so that linear-in-features
regression (and hence series/sieve regression) is a single object.
A parametrized family of predictors bundles an admissible set of parameter values together with a map sending each parameter to a prediction function from the covariates to the outcome.
Definition (Lean source)
A hypothesis class packaged extensionally as a set of admissible prediction functions from the covariates to the outcome, subject to the requirement that every function admitted to the class is measurable.
Definition (Lean source)
A finite feature map bundles a transform sending each input to its vector of K feature values. Linear-in-features predictors use x ↦ ⟪β, φ x⟫; the identity feature map recovers ordinary linear regression, and other choices of the transform recover polynomial, spline, or Fourier (sieve) regression.
Definition (Lean source)
Risk 7 core · 0 supporting Risk criteria for the ML spine, in both the parametric and extensional views. ★ Loss★ empiricalRisk★ populationRisk
Empirical and population risk
Risk criteria for the ML spine, in both the parametric and extensional views.
Loss is a pointwise prediction-label loss, empiricalRisk and
empiricalRiskP are nonempty finite-sample averages, populationRisk and
populationRiskP are Bochner-integral population criteria, and
iidEmpiricalRisk expresses empirical risk through Stat.IIDSample.sampleMean.
The separate predicate HasFinitePopulationRisk records when the population
integral has the usual finite expected-loss interpretation.
A pointwise loss assigns a real penalty to predicted and observed labels by comparing one label-space value with another.
Definition (Lean source)
Empirical risk is average loss over a nonempty finite sample. It evaluates a prediction rule with a pointwise loss on sampled input--label pairs indexed by a finite nonempty set, with input and label spaces.
Parametric empirical risk assigns a parameter value the sample-average loss of its prediction rule. The rule comes from a parametrized predictor on parameter, input, and label spaces, using the chosen loss and sample over a nonempty finite index set.
Definition (Lean source)
Population risk is the expected pointwise prediction loss of a prediction rule under a joint input--label law, using a chosen loss function on measurable input and label spaces.
Definition (Lean source)
Parametric population risk assigns a parameter value the expected loss of its prediction rule. The rule comes from a parametrized predictor on parameter, measurable input, and measurable label spaces, and is evaluated with the chosen loss under the joint input--label law.
Definition (Lean source)
The i.i.d. empirical risk is random average loss over the requested prefix from an i.i.d. input--label sample. It evaluates a prediction rule with the chosen loss at the sample size, under experiment and population laws on the measurable sample, input, and label spaces.
Finite population risk requires integrability of prediction loss under the joint law. It applies to a prediction rule and pointwise loss under that joint law on measurable input and label spaces.
Definition (Lean source)
ERM 5 core · 0 supporting Minimizer predicates for the ML spine, stated candidate-wise via Mathlib's IsMinOn (or a comparison + ε form), never via sInf/argmin — this avoids pathological real-infimum defaults on empty or unbounded sets, matching t ★ IsERMP★ RegularizedERM★ IsERM
Empirical-risk-minimizer predicates
Minimizer predicates for the ML spine, stated candidate-wise via Mathlib's
IsMinOn (or a comparison + ε form), never via sInf/argmin — this avoids
pathological real-infimum defaults on empty or unbounded sets, matching the
existing Estimation.OrthogonalLearning.PluginERM idiom.
The file provides exact, approximate, and regularized parametric ERM predicates
(IsERMP, IsApproxERMP, RegularizedERM), plus extensional empirical and
population minimizer predicates (IsERM, IsPopulationRiskMinimizer) over a
HypothesisClass. The parametric and extensional views are connected in
Causalean.ML.Core.Bridge.
θhat exactly minimizes a parametric objective over the admissible set.
θhat minimizes a parametric objective up to slack ε ≥ 0.
Definition (Lean source)
The slack is nonnegative.
The candidate is admissible.
Its objective is within ε of every competitor's.
θhat minimizes a penalized objective objective θ + lam · penalty θ with a nonnegative regularization weight lam.
Definition (Lean source)
The regularization weight is nonnegative.
The minimizer is admissible.
It minimizes the penalized objective over Θset.
An empirical-risk minimizer is an admissible prediction rule whose finite-sample risk criterion is no larger than that of any other admissible rule. The criterion is the inverse-cardinality-scaled loss sum over a nonempty finite sample.
Definition (Lean source)
The minimizer belongs to the class.
It minimizes empirical risk over the class.
A population-risk minimizer bundles the claim that a prediction rule belongs to the hypothesis class, that it has finite expected loss under the population measure, that every other rule admissible in the class also has finite expected loss, and that its population risk is no larger than that of any other rule in the class.
Definition (Lean source)
The minimizer belongs to the class.
Every admissible competitor has finite expected loss.
It minimizes population risk over the class.
Losses 5 core · 5 supporting This file collects the elementary pointwise loss functions used throughout Causalean.ML: squared loss for regression, Boolean-to-real encoding, softplus, and score-space logistic loss for binary classification. ★ squaredLoss★ logisticScoreLoss★ squaredLoss_nonneg
Loss functions for the standalone ML module
This file collects the elementary pointwise loss functions used throughout
Causalean.ML: squared loss for regression, Boolean-to-real encoding, softplus,
and score-space logistic loss for binary classification. Logistic models use
Mathlib's canonical Real.sigmoid. Everything here is causal-free real
analysis; no probability or causal layer is imported.
Squared loss measures a real-valued prediction against the observed outcome by squaring their difference.
Definition (Lean source)
The zero--one real encoding makes a Boolean label available to real-valued loss formulas by mapping true to one and false to zero.
Definition (Lean source)
Softplus turns an unrestricted real score into the log of one plus its exponential, a smooth positive quantity used in logistic loss.
The score-space logistic loss evaluates a binary outcome at an unrestricted prediction score as softplus minus the zero--one label times the score.
Squared prediction error cannot be negative, regardless of the predicted and observed values.
Formal statement
Proof (Lean source)
5 supporting declarations (lemmas, instances)
-
softplus_poslemma — Softplus is strictly positive at every score.Proof (Lean source)
lemma softplus_pos (t : ℝ) : 0 < softplus t := by have hpos : (0 : ℝ) < exp t := Real.exp_pos _ have h1 : (1 : ℝ) < 1 + exp t := by linarith exact Real.log_pos h1
Bridge 2 core · 1 supporting The image of a Predictor under its prediction map is a HypothesisClass, and a *parametric* minimizer pushes forward to an *extensional* minimizer over that image class. ★ populationTarget_pushforward
Bridge between the parametric and extensional views
The image of a Predictor under its prediction map is a HypothesisClass, and a
parametric minimizer pushes forward to an extensional minimizer over that
image class. These two lemmas are the only glue between the two views of a
method: properties stated in parameter space (convexity, regularization,
optimization) transfer to the function-class statements (best-in-class,
population target).
The realized hypothesis class turns a parametrized predictor into exactly its admissible prediction rules. Measurability of every admissible rule supplies the class-wide measurability guarantee needed for population-risk analysis.
Definition (Lean source)
Population-target pushforward. For a predictor M with loss loss and population law P, suppose every admissible parameter's prediction function is measurable, the parameter θhat is itself admissible, every admissible parameter attains finite population risk, and θhat minimizes the population risk over the admissible parameter set. Then the predictor M.predict θhat is a population-risk minimizer over the hypothesis class realized by M's image: a parametric population-risk minimizer pushes forward to an extensional minimizer over the realized function class.
Formal statement
Proof (Lean source)
1 supporting declaration (lemmas, instances)
-
isERMP_to_extensionaltheorem — A parametric empirical-risk minimizer pushes forward to an extensional empirical-risk minimizer over the realized hypothesis class.hypothesesι Θ X Y :M :Predictor Θ X Yloss :Loss YS :ι → X × Yhmeas :∀ θ ∈ M.paramSet, Measurable (M.predict θ)θhat :Θh :IsERMP (empiricalRiskP M loss S) M.paramSet θhatconclusionProof (Lean source)
theorem isERMP_to_extensional {ι Θ X Y : Type*} [Fintype ι] [Nonempty ι] [MeasurableSpace X] [MeasurableSpace Y] (M : Predictor Θ X Y) (loss : Loss Y) (S : ι → X × Y) (hmeas : ∀ θ ∈ M.paramSet, Measurable (M.predict θ)) {θhat : Θ} (h : IsERMP (empiricalRiskP M loss S) M.paramSet θhat) : IsERM (imageClass M hmeas) loss S (M.predict θhat) where mem := ⟨θhat, h.mem, rfl⟩ isMin := by rw [isMinOn_iff] rintro g ⟨θ, hθ, rfl⟩ simpa [empiricalRiskP] using (isMinOn_iff.mp h.isMin) θ hθ
Convex 2 core · 5 supporting Reusable convexity, existence, first-order-optimality and subgradient facts that the convex methods (logistic regression, lasso, generic convex ERM) instantiate. ★ exists_isMinOn_univ_of_coercive
Convex-analysis substrate for ERM
Reusable convexity, existence, first-order-optimality and subgradient facts that the convex methods (logistic regression, lasso, generic convex ERM) instantiate. This file is method-agnostic: it speaks only about an abstract objective on a real vector / inner-product / normed space.
Existence via coercivity. On a proper normed real vector space, if the objective function is continuous and it tends to infinity along the cocompact filter, i.e. it is coercive — it grows without bound as the argument leaves every compact set, then a global minimizer of the objective over the whole space exists.
Formal statement
Proof (Lean source)
A vector is a relative subgradient when the point lies in the set and the vector supports an affine minorant on that set. The definition applies to the function and constraint set at the vector and evaluation point in a real inner-product space.
Definition (Lean source)
5 supporting declarations (lemmas, instances)
-
empiricalRiskP_convexOn_of_loss_convextheorem — If every per-sample parameter loss is convex on Θset, so is the empirical risk of the predictor.hypothesesι :sharedType u_1Θ :sharedType u_2X :sharedType u_3Y :sharedType u_4M :Predictor Θ X Yloss :Loss YS :ι → X × YΘset :Set Θhconv :Convex ℝ Θsethloss :∀ i, ConvexOn ℝ Θset (fun θ => loss (M.predict θ (S i).1) (S i).2)conclusionConvexOn ℝ Θset (empiricalRiskP M loss S)Proof (Lean source)
theorem empiricalRiskP_convexOn_of_loss_convex (M : Predictor Θ X Y) (loss : Loss Y) (S : ι → X × Y) (Θset : Set Θ) (hconv : Convex ℝ Θset) (hloss : ∀ i, ConvexOn ℝ Θset (fun θ => loss (M.predict θ (S i).1) (S i).2)) : ConvexOn ℝ Θset (empiricalRiskP M loss S) := by unfold empiricalRiskP empiricalRisk have hsum : ConvexOn ℝ Θset (fun θ => ∑ i, loss (M.predict θ (S i).1) (S i).2) := by classical have hfin : ∀ t : Finset ι, ConvexOn ℝ Θset (fun θ => t.sum (fun i => loss (M.predict θ (S i).1) (S i).2)) := by intro t induction t using Finset.induction_on with | empty => simpa using (convexOn_const (𝕜 := ℝ) (E := Θ) (β := ℝ) (s := Θset) (0 : ℝ) hconv) | insert i t hi ht => have hadd := (hloss i).add ht have hfun : ((fun θ => loss (M.predict θ (S i).1) (S i).2) + fun θ => t.sum (fun i => loss (M.predict θ (S i).1) (S i).2)) = fun θ => (insert i t).sum (fun i => loss (M.predict θ (S i).1) (S i).2) := by funext θ simp [Finset.sum_insert hi] rwa [hfun] at hadd simpa using hfin univ simpa [smul_eq_mul] using hsum.smul (inv_nonneg.mpr (Nat.cast_nonneg (card ι))) -
convexOn_comp_innertheorem — A convex scalar function precomposed with the linear score θ ↦ ⟪θ, x⟫ is convex. This is the workhorse turning convexity of a margin loss into convexity of the parameter objective.hypotheses -
exists_isMinOn_of_isCompacttheorem — Existence of a minimizer on a nonempty compact set (Weierstrass).hypothesesconclusion∃ θhat ∈ Θset, IsMinOn objective Θset θhatProof (Lean source)
theorem exists_isMinOn_of_isCompact {objective : Θ → ℝ} {Θset : Set Θ} (hne : Θset.Nonempty) (hcompact : IsCompact Θset) (hcont : ContinuousOn objective Θset) : ∃ θhat ∈ Θset, IsMinOn objective Θset θhat := by exact hcompact.exists_isMinOn hne hcont -
fderiv_eq_zero_of_isMinOn_univtheorem — First-order optimality on the whole space: at an unconstrained minimizer the Fréchet derivative vanishes.hypothesesconclusionf' = 0Proof (Lean source)
theorem fderiv_eq_zero_of_isMinOn_univ {f : E → ℝ} {f' : E →L[ℝ] ℝ} {a : E} (hmin : IsMinOn f univ a) (hderiv : HasFDerivAt f f' a) : f' = 0 := by exact (hmin.isLocalMin univ_mem).hasFDerivAt_eq_zero hderiv -
subgradientAt_zero_iff_isMinOntheorem — Fermat's rule, subgradient form: 0 is a subgradient at x over s iff x minimizes f over s.Proof (Lean source)
theorem subgradientAt_zero_iff_isMinOn {f : E → ℝ} {s : Set E} {x : E} (hx : x ∈ s) : SubgradientAt f s 0 x ↔ IsMinOn f s x := by constructor · intro h exact isMinOn_iff.2 fun y hy => by have := h.2 y hy simpa [SubgradientAt, inner_zero_left] using this · intro hmin refine ⟨hx, ?_⟩ intro y hy simpa [SubgradientAt, inner_zero_left] using (isMinOn_iff.1 hmin y hy)
PopulationTarget 2 core · 2 supporting This file collects reusable statements about what a population-risk minimizer recovers. ★ IsResidualOrthogonal★ square_loss_population_target_of_isResidualOrthogonal
Population-risk targets
This file collects reusable statements about what a population-risk minimizer
recovers. populationRisk_eq_of_both_minimizers shows that any two minimizers
attain the same risk, while populationRisk_minimizer_eq_target turns a unique
target minimizer into equality of functions. For squared loss, IsResidualOrthogonal
records a conditional-mean normal equation, and
square_loss_population_target_of_isResidualOrthogonal proves that a function
satisfying it minimizes squared population risk. The conditional-expectation bridge is
isolated in ML/CausalApplication/RegressionBridge.lean, so this layer stays self-contained
and causal-free.
A candidate regression function is residual-orthogonal under a joint covariate--response law precisely when its residual is orthogonal to every admissible covariate function.
Definition (Lean source)
A residual-orthogonal candidate beats any admissible competitor in squared population risk under the joint covariate--response law. The guarantee compares it with the chosen competitor and requires residual orthogonality, measurability of both functions, finite squared risks, and an integrable cross term.
Formal statement
Proof (Lean source)
2 supporting declarations (lemmas, instances)
-
populationRisk_eq_of_both_minimizerstheorem — Any two population-risk minimizers over the same class attain the same risk.hypothesesX :sharedType u_1H1 :IsPopulationRiskMinimizer H loss P h₁H2 :IsPopulationRiskMinimizer H loss P h₂conclusionpopulationRisk loss P h₁ = populationRisk loss P h₂Proof (Lean source)
theorem populationRisk_eq_of_both_minimizers {H : HypothesisClass X Y} {loss : Loss Y} {P : Measure (X × Y)} {h₁ h₂ : X → Y} (H1 : IsPopulationRiskMinimizer H loss P h₁) (H2 : IsPopulationRiskMinimizer H loss P h₂) : populationRisk loss P h₁ = populationRisk loss P h₂ := le_antisymm ((isMinOn_iff.mp H1.isMin) h₂ H2.mem) ((isMinOn_iff.mp H2.isMin) h₁ H1.mem) -
populationRisk_minimizer_eq_targettheorem — If a target is known to be the unique population-risk minimizer, every population-risk minimizer equals it.hypothesesX :sharedType u_1hStar :IsPopulationRiskMinimizer H loss P hstarhTarget :IsPopulationRiskMinimizer H loss P targethUnique :∀ h₁ h₂conclusionhstar = targetProof (Lean source)
theorem populationRisk_minimizer_eq_target {H : HypothesisClass X Y} {loss : Loss Y} {P : Measure (X × Y)} {target hstar : X → Y} (hStar : IsPopulationRiskMinimizer H loss P hstar) (hTarget : IsPopulationRiskMinimizer H loss P target) (hUnique : ∀ h₁ h₂, IsPopulationRiskMinimizer H loss P h₁ → IsPopulationRiskMinimizer H loss P h₂ → h₁ = h₂) : hstar = target := hUnique hstar target hStar hTarget
Rate 2 core · 2 supporting The causal-free common currency between the method folders (which prove per-method L²-estimation rates) and ML/CausalApplication (which assembles them to discharge DML's nuisance-rate conditions). ★ isLittleOp_mul_quarter★ AchievesL2Rate
Learning-rate abstraction and rate algebra
The causal-free common currency between the method folders (which prove per-method
L²-estimation rates) and ML/CausalApplication (which assembles them to discharge DML's
nuisance-rate conditions).
* AchievesL2Rate ĥ h⋆ P rₙ μ — every L² seminorm of the estimation error is
finite, and its real-number conversion is O_p(rₙ) under the experiment law.
* generic probabilistic stochastic-order facts: an o_p(rₙ) with rₙ ≤ 1 is
o_p(1); a product of two o_p(n^{-1/4}) is o_p(n^{-1/2}); and an
O_p(n^{-1/2}) rate is o_p(n^{-1/4}) (turning a method's root-n IsBigOp
into the o_p(n^{-1/4}) the DML side consumes).
The n^{-1/4} product rule. If the sequence Xn is o_p(n^{-1/4}) and the sequence Yn is o_p(n^{-1/4}) under the probability law μ, then their pointwise product Xn·Yn is o_p(n^{-1/2}) — the DML product-rate condition from per-nuisance n^{-1/4} rates.
Formal statement
Proof (Lean source)
Achieving an L² estimation rate means that experiment-indexed regression estimates approach a target under a joint law with finite L² error everywhere, and that those errors are stochastically bounded by the claimed rate under the experiment law at the supplied rate sequence.
2 supporting declarations (lemmas, instances)
-
isLittleOp_one_of_le_onetheorem — Rate weakening: an o_p(rn) sequence with rn ≤ 1 is o_p(1).hypothesesconclusionIsLittleOp Xn (fun _ => 1) μProof (Lean source)
theorem isLittleOp_one_of_le_one {rn : ℕ → ℝ} (hr : ∀ n, rn n ≤ 1) (h : IsLittleOp Xn rn μ) : IsLittleOp Xn (fun _ => 1) μ := by intro ε hε have hlim : Tendsto (fun n => μ {ω | ε * rn n ≤ |Xn n ω|}) atTop (𝓝 0) := h ε hε refine tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds hlim (fun n => zero_le) ?_ intro n apply measure_mono intro ω hω have hmul : ε * rn n ≤ ε * 1 := mul_le_mul_of_nonneg_left (hr n) (le_of_lt hε) exact hmul.trans (by simpa using hω) -
isLittleOp_quarter_of_isBigOp_sqrttheorem — An O_p(n^{-1/2}) (root-n) rate is o_p(n^{-1/4}): a method's root-n estimation rate clears the DML o_p(n^{-1/4}) bar.hypothesesconclusionIsLittleOp Xn (fun n => (n : ℝ) ^ (-(1 / 4 : ℝ))) μProof (Lean source)
theorem isLittleOp_quarter_of_isBigOp_sqrt (h : IsBigOp Xn (fun n => (sqrt (n : ℝ))⁻¹) μ) : IsLittleOp Xn (fun n => (n : ℝ) ^ (-(1 / 4 : ℝ))) μ := by intro ε hε rw [ENNReal.tendsto_nhds_zero] intro δ hδ by_cases hδtop : δ = ⊤ · filter_upwards with n simp [hδtop] have hhalfpos : 0 < δ / 2 := ENNReal.div_pos hδ.ne' (by norm_num) rcases h (δ / 2) hhalfpos with ⟨M0, hM0pos, hM0⟩ let M : ℝ := max M0 1 have hMpos : 0 < M := by dsimp [M] exact lt_of_lt_of_le zero_lt_one (le_max_right M0 1) have hM0le : M0 ≤ M := by dsimp [M] exact le_max_left M0 1 let A : ℕ → Set Ω := fun n => {ω | ε * (n : ℝ) ^ (-(1 / 4 : ℝ)) ≤ |Xn n ω|} let B : ℕ → Set Ω := fun n => {ω | M * (sqrt (n : ℝ))⁻¹ ≤ |Xn n ω|} have hhalf_lt : δ / 2 < δ := ENNReal.half_lt_self hδ.ne' hδtop have hBevent : ∀ᶠ n : ℕ in atTop, μ (B n) < δ := by filter_upwards [hM0] with n hn have hrate_nonneg : 0 ≤ (sqrt (n : ℝ))⁻¹ := inv_nonneg.mpr (Real.sqrt_nonneg _) have hsubset : B n ⊆ {ω | M0 * (sqrt (n : ℝ))⁻¹ ≤ |Xn n ω|} := by intro ω hω exact (mul_le_mul_of_nonneg_right hM0le hrate_nonneg).trans hω exact (le_trans (measure_mono hsubset) hn).trans_lt hhalf_lt have hthreshold : ∀ᶠ n : ℕ in atTop, M * (sqrt (n : ℝ))⁻¹ ≤ ε * (n : ℝ) ^ (-(1 / 4 : ℝ)) := by have ht : Tendsto (fun n : ℕ => (M / ε) * (n : ℝ) ^ (-(1 / 4 : ℝ))) atTop (𝓝 0) := by have hp : Tendsto (fun x : ℝ => x ^ (-(1 / 4 : ℝ))) atTop (𝓝 0) := by exact tendsto_rpow_neg_atTop (by norm_num : (0 : ℝ) < (1 / 4 : ℝ)) simpa using (Tendsto.const_mul (M / ε) (hp.comp tendsto_natCast_atTop_atTop)) have hevent_abs : ∀ᶠ n : ℕ in atTop, |(M / ε) * (n : ℝ) ^ (-(1 / 4 : ℝ))| < 1 := by have hnear := (Metric.tendsto_nhds.mp ht) 1 (by norm_num : (0 : ℝ) < (1 : ℝ)) simpa [Real.dist_eq, abs_mul, abs_div] using hnear filter_upwards [hevent_abs, eventually_ge_atTop 1] with n hnabs hn_ge have hnsmall : (M / ε) * (n : ℝ) ^ (-(1 / 4 : ℝ)) < 1 := (abs_lt.mp hnabs).2 have hnpos : 0 < (n : ℝ) := by exact_mod_cast hn_ge let q : ℝ := (n : ℝ) ^ (-(1 / 4 : ℝ)) have hqpos : 0 < q := by dsimp [q] exact Real.rpow_pos_of_pos hnpos _ have hinv_eq : (sqrt (n : ℝ))⁻¹ = (n : ℝ) ^ (-(1 / 2 : ℝ)) := by rw [Real.sqrt_eq_rpow] rw [← Real.rpow_neg (le_of_lt hnpos)] have hpow_add : q * q = (n : ℝ) ^ (-(1 / 2 : ℝ)) := by dsimp [q] rw [← Real.rpow_add hnpos] congr 1 norm_num have hmul : (M / ε * q) * (ε * q) ≤ 1 * (ε * q) := by exact mul_le_mul_of_nonneg_right (le_of_lt hnsmall) (le_of_lt (mul_pos hε hqpos)) have hleft : (M / ε * q) * (ε * q) = M * (n : ℝ) ^ (-(1 / 2 : ℝ)) := by rw [← hpow_add] field_simp [hε.ne'] calc M * (sqrt (n : ℝ))⁻¹ = M * (n : ℝ) ^ (-(1 / 2 : ℝ)) := by rw [hinv_eq] _ = (M / ε * q) * (ε * q) := by rw [hleft] _ ≤ 1 * (ε * q) := hmul _ = ε * (n : ℝ) ^ (-(1 / 4 : ℝ)) := by simp [q] filter_upwards [hBevent, hthreshold] with n hBn hthr have hsubset : A n ⊆ B n := by intro ω hω dsimp [A, B] at hω ⊢ exact hthr.trans hω calc μ {ω | ε * (fun n => (n : ℝ) ^ (-(1 / 4 : ℝ))) n ≤ ‖Xn n ω‖} = μ (A n) := by congr 1 _ ≤ δ := le_of_lt (lt_of_le_of_lt (measure_mono hsubset) hBn)