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 later by Causalean.ML.Core.Bridge: * the parametric view (Predictor): a parameter type Θ together with an admissible set and a prediction map Θ → ★ Predictor★ HypothesisClass★ FeatureMap
Hypothesis classes and parametrized predictors
The standalone ML spine carries two views of a learning method, connected later
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: loss ŷ y compares a prediction ŷ to a label y.
Definition (Lean source)
The empirical risk criterion of a prediction rule is the sample loss sum scaled by the inverse cardinality of a nonempty finite sample index. The nonemptiness assumption rules out the empty-sample convention where the average would collapse to zero without data.
Definition (Lean source)
The empirical risk criterion of a model parameter is the finite-sample criterion over a nonempty sample applied to the prediction rule selected by that parameter.
Definition (Lean source)
The population risk criterion of a prediction rule is the Bochner integral of its pointwise loss under the joint law. This definition does not by itself assert integrability or finite expected loss.
Definition (Lean source)
The population risk criterion of a model parameter is the Bochner-integral criterion applied to the prediction rule selected by that parameter.
Definition (Lean source)
The empirical risk along the first n points of an i.i.d. sample, expressed through Stat.IIDSample.sampleMean.
Definition (Lean source)
The loss-integrand of h is integrable, so the population risk is finite.
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★ IsApproxERMP★ RegularizedERM★ IsERM★ IsPopulationRiskMinimizer
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)
θhat minimizes a penalized objective objective θ + lam · penalty θ with a nonnegative regularization weight lam.
Definition (Lean source)
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)
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)
Losses 6 core · 7 supporting This file collects the elementary pointwise loss functions used throughout Causalean.ML: the squared loss for regression, and the sigmoid / softplus / score-space logistic loss for binary classification. ★ squaredLoss★ logisticScoreLoss★ bool01_true
Loss functions for the standalone ML module
This file collects the elementary pointwise loss functions used throughout
Causalean.ML: the squared loss for regression, and the sigmoid / softplus /
score-space logistic loss for binary classification. Everything here is
causal-free real analysis; no probability or causal layer is imported.
Squared loss measures prediction error by squaring the difference between the observed label and the prediction.
Definition (Lean source)
Boolean labels are encoded as real zero-one outcomes.
The logistic sigmoid maps any real score to a probability-like number between zero and one.
Softplus is a smooth positive transformation used to write logistic losses in score space.
Logistic score loss is the binary cross-entropy loss written as a function of the raw prediction score.
Definition (Lean source)
A true Boolean label is encoded as the real number one.
7 supporting declarations (lemmas, instances)
-
squaredLoss_nonneglemma — Squared loss is always nonnegative.Proof (Lean source)
-
sigmoid_poslemma — The logistic sigmoid is strictly positive at every score.Proof (Lean source)
lemma sigmoid_pos (t : ℝ) : 0 < sigmoid t := by have : 0 < 1 + exp (-t) := by positivity exact inv_pos.mpr this -
sigmoid_lt_onelemma — The logistic sigmoid is strictly below one at every score. -
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 hypothesis class realized by a predictor: the image of its admissible parameter set under the prediction map.
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)
g is a subgradient of f at x relative to s: the affine support inequality f x + ⟪g, y − x⟫ ≤ f y holds for all y ∈ s (and x ∈ s).
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.hypothesesM :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.hypothesesProof (Lean source)
theorem convexOn_comp_inner {φ : ℝ → ℝ} (hφ : ConvexOn ℝ univ φ) (x : E) : ConvexOn ℝ univ (fun θ : E => φ (inner ℝ θ x)) := by simpa [Function.comp_def, innerSL_apply_apply, real_inner_comm] using hφ.comp_linearMap ((innerSL ℝ x).toLinearMap) -
exists_isMinOn_of_isCompacttheorem — Existence of a minimizer on a nonempty compact set (Weierstrass).hypothesesobjective :Θ → ℝΘset :Set Θhne :Θset.Nonemptyhcompact :IsCompact Θsethcont :ContinuousOn objective Θsetconclusion∃ θ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. ★ IsL2Projection★ square_loss_population_target_of_isL2Projection
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, IsL2Projection
records the residual-orthogonality property of an L² projection, and
square_loss_population_target_of_isL2Projection proves that such a projection
minimizes squared population risk. The conditional-expectation bridge is
isolated in ML/CausalApplication/RegressionBridge.lean, so this layer stays self-contained
and causal-free.
The residual of m is orthogonal to every (integrable, measurable) function of the covariate. This is the defining property of the L²-projection onto the σ-algebra generated by the covariate, i.e. of the regression function x ↦ E[Y ∣ X = x]. Measurability of the test function g is required because orthogonality of the residual is only meaningful for measurable functions of X (it is what links this to condExp; see ML/CausalApplication/RegressionBridge.lean).
Definition (Lean source)
For a joint covariate–response law P and a competitor function h, if the residual of m is orthogonal to every function of the covariate, i.e. m is an L² projection onto functions of the covariate, m is measurable, the competitor h is measurable, m attains finite squared population risk, h attains finite squared population risk, and the cross term (Y − m(X))·(m(X) − h(X)) is integrable, then the squared population risk of m is at most that of h: m minimizes squared population risk against any such competitor.
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.hypothesesH :HypothesisClass X Yloss :Loss YP :Measure (X × Y)h₁ h₂ :X → YH1 :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.hypothesesH :HypothesisClass X Yloss :Loss YP :Measure (X × Y)target hstar :X → YhStar :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)
The L² estimation error has a finite seminorm at every sample size and experiment outcome, and that finite seminorm is stochastically bounded at the supplied rate under the experiment law. The L² seminorm is computed using the covariate marginal of the joint law, so the real-valued stochastic-order claim never comes from converting an infinite extended norm to zero.
Definition (Lean source)
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 lt_of_le_of_lt hmul (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 hδpos : 0 < δ.toReal := ENNReal.toReal_pos (ne_of_gt hδ) hδtop let α : ℝ := δ.toReal / 2 have hαpos : 0 < α := by dsimp [α] linarith rcases h α hαpos with ⟨M0, 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 hlimB : limsup (fun n => μ (B n)) atTop ≤ ofReal α := by refine le_trans (Filter.limsup_le_limsup (Eventually.of_forall ?_)) hM0 intro n apply measure_mono intro ω hω dsimp [B] at hω ⊢ have hrate_nonneg : 0 ≤ (sqrt (n : ℝ))⁻¹ := inv_nonneg.mpr (Real.sqrt_nonneg _) exact lt_of_le_of_lt (mul_le_mul_of_nonneg_right hM0le hrate_nonneg) hω have hα_lt_delta : ofReal α < δ := by rw [ENNReal.ofReal_lt_iff_lt_toReal] · dsimp [α] linarith · dsimp [α] linarith [le_of_lt hδpos] · exact hδtop have hBevent := Filter.eventually_lt_of_limsup_lt (lt_of_le_of_lt hlimB hα_lt_delta) 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 lt_of_le_of_lt hthr hω have heq : {ω | ε * (fun n => (n : ℝ) ^ (-(1 / 4 : ℝ))) n < |Xn n ω|} = A n := by ext ω simp [A] rw [heq] exact le_of_lt (lt_of_le_of_lt (measure_mono hsubset) hBn)