This is the human-readable version of the proof that Lean checks in SampleSdMse.lean, accompanying the post MSE of sample standard deviation (Lean by AI). The Lean name of each step is given in brackets.
0. Setting and statement
Assumptions [SampleModel]. $X_1, X_2, \ldots$ are i.i.d. real random variables on a probability space, with all moments finite and $\mathrm{Var}(X_1) > 0$. Write
Then $E Z_i = 0$ and $E Z_i^2 = 1$ [lam_one, lam_two]. The $Z_i$ are i.i.d. as measurable functions of the $X_i$ [Zr_indep, Zr_ident].
Estimators [sampleSD, besselSD]. With $\bar X = \frac1n \sum_{i=1}^n X_i$,
Theorem [textbook_certificate]. As $n \to \infty$,
and therefore $MSE(S_n) - MSE(\hat\sigma_n) = \dfrac{\sigma^2(\lambda_4 - 3)}{8n^2} + o(n^{-2})$. Here $MSE(T) = E[(T - \sigma)^2]$.
Integrability. Every random variable below is a polynomial in finitely many $Z_i$, or is dominated by one (Step 5 shows $|\sqrt{1+x} - 1| \le |x|$). All moments of $Z_1$ are finite, so all of these are integrable and expectation is linear on them [momAlg, E_lm].
1. Reduction to standardized fluctuations
Define
$$ A_i = Z_i^2 - 1,\qquad U_n = \frac1n\sum_{i=1}^n A_i,\qquad V_n = \bar Z = \frac1n \sum_{i=1}^n Z_i,\qquad D_n = U_n - V_n^2 . $$We have $X_i - \bar X = \sigma (Z_i - \bar Z)$ and $\frac1n\sum Z_i^2 = 1 + U_n$, so for $n \ge 1$
$$ \frac1n \sum_{i=1}^n (X_i - \bar X)^2 = \sigma^2 \Big(\frac1n \sum Z_i^2 - \bar Z^2\Big) = \sigma^2 (1 + D_n) $$[sum_sq_dev_eq]
Hence $\hat\sigma_n = \sigma\sqrt{1 + D_n}$ for $n \ge 1$ [sampleSD_eq]. With
we get $S_n = \sigma \sqrt{1 + \Delta_n}$ for $n \ge 2$ [besselSD_eq]. In particular $1 + D_n \ge 0$ and $1 + \Delta_n \ge 0$ [one_add_D_nonneg, one_add_Δ_nonneg]. The identities hold for all large $n$, so it suffices to prove the expansions for $\sigma\sqrt{1 + D_n}$ and $\sigma\sqrt{1 + \Delta_n}$.
2. Exact finite sample moments of $U_n$ and $V_n$
Independence gives $E\big[\prod_{i\in s} f_i(Z_i)\big] = \prod_{i \in s} E f_i(Z_i)$ for distinct indices and measurable $f_i$ [indep_E, from Mathlib’s iIndepFun.integral_fun_prod_comp]. With $E Z = E A = 0$, any product in which some index occurs exactly once has expectation zero. The moments needed are
together with $E A^4 = \lambda_8 - 4\lambda_6 + 6\lambda_4 - 3$ [E_A2, E_A3, E_AZ, E_AZ2, E_A2Z2, E_A4].
Expanding the sums and keeping only index patterns with no index occurring exactly once gives the following, with the surviving patterns in parentheses [cov2_of_indep, cov3_of_indep, cov4_of_indep, sampleAvg_moment1 to sampleAvg_moment4]:
- $E U_n = 0$ (no surviving pattern).
- $E V_n^2 = 1/n$ (pattern $i=j$).
- $E U_n^2 = (\lambda_4 - 1)/n$ (pattern $i=j$).
- $E U_n^3 = (\lambda_6 - 3\lambda_4 + 2)/n^2$ (pattern $i=j=k$).
- $E [U_n V_n^2] = (\lambda_4 - 1)/n^2$ (pattern $i=j=k$).
- $E V_n^4 = 3/n^2 + (\lambda_4 - 3)/n^3$ (all four indices equal, or two distinct pairs).
- $E [U_n^2 V_n^2] = (\lambda_4 - 1 + 2\lambda_3^2)/n^2 + O(n^{-3})$ (all equal, the pairs $i=j$ and $k=l$, or the two cross pairings).
- $E U_n^4 = 3(\lambda_4-1)^2/n^2 + O(n^{-3})$ (all equal, or two distinct pairs).
For example, $E[U_n^2V_n^2] = n^{-4}\big[\thinspace n E[A^2Z^2] + n(n-1) E A^2\thinspace E Z^2 + 2n(n-1)(E[AZ])^2\big]$. Each $O(n^{-3})$ term is an explicit constant over $n^3$, hence $o(n^{-2})$ [sample_mean_moments, o_div_n3].
3. Moment growth bound (replaces any rate assumption)
Lemma [moment_growth, sum_moment_bound]. Let $W_1, W_2, \ldots$ be i.i.d. with all moments finite and $E W = 0$, and let $T_n = \sum_{i=1}^n W_i$. For every $m$ there is $B_m$ with
Proof. $T_n$ is a function of $W_1, \ldots, W_n$, so it is independent of $W_{n+1}$ [Mathlib iIndepFun.indepFun_finsetSum_of_notMem]. Write $a_m(n) = E T_n^m$ and $M_l = E W^l$, so $M_0 = 1$ and $M_1 = 0$. The binomial theorem and independence give
The $j = m$ term is $a_m(n)$, and the $j = m-1$ term vanishes because $M_1 = 0$. Hence
$$ a_m(n+1) - a_m(n) = \sum_{j=0}^{m-2} \binom{m}{j} a_j(n) M_{m-j}. $$Induct on $m$. For $m = 0$, $a_0 \equiv 1$. Suppose the bound holds for all $j < m$, with $m \ge 1$, and let $q = \lfloor m/2 \rfloor$. For $j \le m-2$ we have $\lfloor j/2 \rfloor \le q - 1$, so the increment is at most $K (n+1)^{q-1}$ in absolute value, where $K = \max_{j<m} B_j \sum_{j \le m-2}\binom{m}{j}|M_{m-j}|$. For $m = 1$ the sum is empty and $K = 0$. Since $a_m(0) = 0$,
$$ |a_m(n)| \le K \sum_{t=0}^{n-1} (t+1)^{q-1} \le K\thinspace n\thinspace (n+1)^{q-1} \le K (n+1)^q. \qquad\blacksquare $$Consequence [rate_of_sum, remainder_order]. Apply the lemma with $W_i = Z_i$ and with $W_i = A_i$. Since $U_n = T_n/n$ for $W = A$ and $V_n = T_n/n$ for $W = Z$, for $n \ge 1$
In particular $E U_n^8, E V_n^8 = O(n^{-4})$ and $E V_n^{16} = O(n^{-8})$. Since $(u - v^2)^8 \le 128(u^8 + v^{16})$ [sub_sq_pow_eight_le], we get $E D_n^8 \le 128(E U_n^8 + E V_n^{16}) = O(n^{-4})$.
4. Second order moments of $D_n$ and $\Delta_n$
Cauchy Schwarz [E_mul_sq_le, isBigO_E_mul]. $(E[XY])^2 \le E X^2\thinspace E Y^2$. So if $E X^2 = O(n^{-a})$ and $E Y^2 = O(n^{-b})$, then $E[XY] = O(n^{-(a+b)/2})$. With Step 3 this gives
so all of these are $o(n^{-2})$.
Moments of $D_n$ [derived_moments]. Expanding powers of $D = U - V^2$ and using Step 2:
Moments of $\Delta_n$ [derived_moments]. Since $\Delta_n = (c_n - 1) + c_n D_n$, each $E\Delta_n^k$ is an exact combination of $E D_n^j$ with coefficients polynomial in $c_n$. For $n \ge 2$, $c_n - 1 = \frac1{n-1} = \frac{c_n}{n}$ and $c_n = 1 + O(1/n)$. This gives:
- $E\Delta_n = c_n(1 + E D_n) - 1 = c_n \frac{n-1}{n} - 1 = 0$.
- $E\Delta_n^2 = (c_n-1)^2 + 2(c_n-1)c_n E D_n + c_n^2 E D_n^2 = c_n^2\big(E D_n^2 - \frac1{n^2}\big)$. With $c_n^2 = 1 + \frac2n + O(n^{-2})$ this is $\frac{\lambda_4 - 1}{n} + \frac{2}{n^2} + o(n^{-2})$.
- $E\Delta_n^3 = E D_n^3 + 3(c_n - 1) E D_n^2 + O(n^{-3}) = \frac{\lambda_6 - 3\lambda_4 - 6\lambda_3^2 + 2}{n^2} + o(n^{-2})$.
- $E\Delta_n^4 = E D_n^4 + O(n^{-3}) = \frac{3(\lambda_4 - 1)^2}{n^2} + o(n^{-2})$.
In Lean, each leftover rational error is written exactly as $c_n^k P_k(1/n)/n^3$ for an explicit polynomial $P_k$. That error is $o(n^{-2})$ because $(c_n, 1/n) \to (1, 0)$ [bdd_cu, o_of_bdd_div_n3].
Rates [moment_bounds]. $E D_n^4, E\Delta_n^4 = O(n^{-2})$ from the expansions above, $E D_n^8 = O(n^{-4})$ from Step 3, and $E\Delta_n^8 \le 128\big((c_n-1)^8 + c_n^8 E D_n^8\big) = O(n^{-4})$ because $(a+b)^8 \le 128(a^8 + b^8)$ [add_pow_eight_le].
5. Taylor expansion of the square root with exact remainder
Let $x \ge -1$ and $\delta = \sqrt{1 + x} - 1$, so $(1 + \delta)^2 = 1 + x$.
Exact identity [taylorSqrt4]. With $T_4(x) = 1 + \frac{x}{2} - \frac{x^2}{8} + \frac{x^3}{16} - \frac{5x^4}{128}$,
This follows by substituting $x = 2\delta + \delta^2$ and expanding.
Domination [abs_sqrt_one_add_sub_one_le]. With $s = \sqrt{1+x} \ge 0$, we have $|x| = |s^2 - 1| = |s - 1|(s + 1) \ge |s - 1|$, so $|\delta| \le |x|$. Hence $E\delta^{2k} \le E x^{2k}$ [isBigO_mom_of_abs_le].
Remainder in expectation [taylor_remainder_E_small]. Suppose $E x_n^4 = O(n^{-2})$ and $E x_n^8 = O(n^{-4})$. Then $E\delta_n^4 = O(n^{-2})$ and $E\delta_n^8 = O(n^{-4})$, and by Cauchy Schwarz
Taking expectations in the exact identity,
$$ E(1 + \delta_n) - E\thinspace T_4(x_n) = \tfrac78 E\delta_n^5 + \tfrac78 E\delta_n^6 + \tfrac5{16}E\delta_n^7 + \tfrac5{128}E\delta_n^8 = o(n^{-2}). $$By Step 4, both $x_n = D_n$ (with $\delta_n = \sqrt{1+D_n}-1$) and $x_n = \Delta_n$ (with $\delta_n = \sqrt{1+\Delta_n}-1$) satisfy the hypotheses.
6. Expectation and MSE of $\sigma\sqrt{1 + x_n}$
Expectation [E_sqrt_expansion]. From Step 5,
MSE [MSE_sqrt_expansion]. Since $(1+\delta)^2 = 1 + x$,
where the last step substitutes $E(1+\delta) = E\thinspace T_4(x) + o(n^{-2})$.
7. Assembling the four expansions
$\hat\sigma_n$, with $x = D_n$ [E_sigmaHat_formula, MSE_sigmaHat_formula]. Insert the Step 4 moments of $D_n$:
- $E(\hat\sigma_n)/\sigma$: the $1/n$ term is $-\frac12 - \frac{\lambda_4 - 1}{8} = -\frac{\lambda_4 + 3}{8}$. The $1/n^2$ term, in units of $\frac1{128}$, is $16(2\lambda_4 - 5) + 8(\lambda_6 - 6\lambda_4 - 6\lambda_3^2 + 5) - 15(\lambda_4 - 1)^2 = 8\lambda_6 - 15\lambda_4^2 + 14\lambda_4 - 48\lambda_3^2 - 55$.
- $MSE(\hat\sigma_n)/\sigma^2$: the $1/n$ term is $\frac{\lambda_4 - 1}{4}$. The $1/n^2$ term, in units of $\frac1{64}$, is $16(5 - 2\lambda_4) - 8(\lambda_6 - 6\lambda_4 - 6\lambda_3^2 + 5) + 15(\lambda_4 - 1)^2 = 48\lambda_3^2 + 15\lambda_4^2 - 14\lambda_4 - 8\lambda_6 + 55$.
$S_n$, with $x = \Delta_n$ [E_Sn_formula, MSE_Sn_formula]. Insert the Step 4 moments of $\Delta_n$; note $E\Delta_n = 0$:
- $E(S_n)/\sigma$: the $1/n$ term is $-\frac{\lambda_4 - 1}{8}$. The $1/n^2$ term, in units of $\frac1{128}$, is $-32 + 8(\lambda_6 - 3\lambda_4 - 6\lambda_3^2 + 2) - 15(\lambda_4 - 1)^2 = 8\lambda_6 - 15\lambda_4^2 + 6\lambda_4 - 48\lambda_3^2 - 31$.
- $MSE(S_n)/\sigma^2$: the $1/n$ term is $\frac{\lambda_4 - 1}{4}$. The $1/n^2$ term, in units of $\frac1{64}$, is $32 - 8(\lambda_6 - 3\lambda_4 - 6\lambda_3^2 + 2) + 15(\lambda_4 - 1)^2 = 48\lambda_3^2 + 15\lambda_4^2 - 6\lambda_4 - 8\lambda_6 + 31$.
By Step 1, these are the expansions of $E(\hat\sigma_n)$, $MSE(\hat\sigma_n)$, $E(S_n)$ and $MSE(S_n)$. $\blacksquare$
8. Corollaries
MSE difference [MSE_diff_formula]. Subtracting the two MSE expansions, the $1/n$ terms cancel, and the $1/n^2$ coefficients differ by $\frac{\sigma^2}{64}\big((-6\lambda_4 + 31) - (-14\lambda_4 + 55)\big) = \frac{\sigma^2}{64}(8\lambda_4 - 24)$. Therefore
Threshold at $\lambda_4 = 3$ [MSE_eq_at_kurtosis_three, MSE_leading_diff_pos_of_kurtosis_gt_three, MSE_leading_diff_neg_of_kurtosis_lt_three]. The leading difference vanishes exactly when $\lambda_4 = 3$. It is positive for $\lambda_4 > 3$, where $\hat\sigma_n$ has smaller MSE, and negative for $\lambda_4 < 3$, where $S_n$ has smaller MSE.
Shared expansion at $\lambda_4 = 3$ [MSE_Sn_at_kurtosis_three, E_Sn_at_kurtosis_three]. Substituting $\lambda_4 = 3$ gives
Normal case ($\lambda_3 = 0$, $\lambda_4 = 3$, $\lambda_6 = 15$) [E_Sn_normal, MSE_Sn_normal, MSE_sigmaHat_normal]. This gives
As a check, $E(\hat\sigma_n) = \sqrt{\frac{n-1}{n}}\thinspace E(S_n) = \sigma - \frac{3\sigma}{4n} - \frac{7\sigma}{32n^2} + o(n^{-2})$, which agrees with the general $E(\hat\sigma_n)$ formula at these values.
Remarks
- Moments actually used. Step 3 needs $E V_n^{16}$, so the argument uses moments of $X$ up to order 16. “All moments finite” is assumed only to keep the integrability bookkeeping simple.
- What Lean adds. Every identity and inequality above, including the polynomial algebra in Steps 2, 4 and 7 and the asymptotic bookkeeping, is checked by Lean’s kernel. The final theorem depends only on the axioms
propext,Classical.choiceandQuot.sound.