AppendixChapter A2

Glossary

A Lean-to-statistics dictionary, plus every definition and theorem this library exports, one line each with a link to where it is introduced.

Contents
  1. Lean ↔ statistics
  2. The library’s vocabulary
    1. MrCLean/Basic.lean — potential outcomes
    2. MrCLean/Design.lean, Bernoulli.lean, CompleteRandomization.lean — designs
    3. MrCLean/Estimators.lean — unbiasedness
    4. MrCLean/Variance.lean — variance
    5. MrCLean/Blocking.lean — blocking and clustering
    6. MrCLean/Regression.lean — regression as linear algebra
    7. MrCLean/Fisher.lean — Fisher randomization tests
    8. MrCLean/Bridge.lean — bridge to Mathlib probability

Two tables. The first translates Lean/type-theory vocabulary into terms a statistician already has. The second is the library’s own vocabulary — every headline name in the library, with the chapter that introduces it.

Lean ↔ statistics

LeanStatistics analogueNote
TermA value, of some typeAnything with a type is a term — 3, fun x => x + 1, and a completed proof are all terms.
TypeThe set/space a value lives inx : T reads ”x is an element of T”; ℝ, Fin n → ℝ, Design n are all types.
Proposition (Prop)A statement that could be true or falseA p : Prop names a claim; a term hp : p is a specific proof that it holds — under Curry–Howard, propositions are types and proofs are their elements.
ProofA construction the type-checker verifiesProving p means building a term of type p; there is no separate “proof checker” step, elaboration is the check.
Prop vs BoolA claim vs. a computed answerProp has no runtime representation — you cannot ask “is it true?” by running code. Bool is true/false, computable and pattern-matchable. decide bridges a decidable Prop to the Bool check.
Fin nUnit labels 1,…,nA natural number below n, bundled with a proof that it is. Fin n → ℝ is exactly an outcome vector over n units.
Finset αA finite subset, with membership you can testAssignment n := Finset (Fin n) is the treated set; ∑ i ∈ s, f i sums over one.
Fintype α”α is finite, and Lean can enumerate it”Lets you write ∑ i, f i / ∏ i, f i over all of α (Finset.univ) without naming a subset.
∑ (Finset.sum)∑∑ i ∈ s, f i is Finset.sum s f; ∑ i, f i sums over univ when the index type is a Fintype.
Coercion ↑An implicit cast, made explicit(n : ℝ) / ↑n turns a ℕ into the real number it denotes. Missing or misapplied coercions are the single most common “wrong type” bug in this library.
noncomputable“Exists, but Lean won’t execute it”Marks a definition Lean cannot run — real division and Classical.choice aren’t computable. It changes nothing about what is proved; #eval just won’t work on it.
structure fieldsThe assumptions of a modelA structure’s fields are exactly what you’d list before a theorem on paper: Design’s three fields are a pmf, its nonnegativity, and that it sums to one.
Design.prob / Design.expect vs. pmf / expectationThe same objects, spelled as codeD.prob z is Pr(Z=z) for one specific assignment; D.expect f is E[f]=∑zD.prob(z)⋅f(z) — a finite sum, because there are only 2n assignments and no measure theory is needed.
propensityπi=Pr(unit i treated)D.propensity i = D.expect (fun z => Z z i), the marginal probability unit i lands in the treated set.
Assignment nThe treated set, not an indicator vectorabbrev Assignment n := Finset (Fin n). z : Assignment n is the set of treated units; Z z i recovers the familiar 0/1 indicator from it.
sorryAn admitted gap, flaggedCloses any goal, emits a warning, and is recorded as the axiom sorryAx forever after — visible to #print axioms. Never appears in any theorem of this library.
axiomA trusted, unproven assumptionEvery Lean development rests on a short axiom list — propext, Classical.choice, Quot.sound here, see the appendix on verification. #print axioms shows exactly which ones a given proof used.
instanceTypeclass evidence, found automaticallyDeclares e.g. “here is how Fin n is a Fintype”; Lean’s elaborator searches for these silently, which is why ∑ i, f i just works once the instance exists.
namespaceA dot-notation prefix, not a modulenamespace Design … end lets Design.expect_add be written D.expect_add for D : Design n. Purely notational.
openBring names into scopeopen Finset BigOperators lets you write sum for Finset.sum and use ∑ notation. Can also shadow names — Mathlib’s bernoulli : ℕ → ℚ is why this library uses bernoulliDesign.
simp lemmaA rewrite rule in the default simplification setAny @[simp]-tagged equation simp fires automatically; generally one with an unambiguous left-to-right normal form.
@[simp]Registers a lemma with simp’s databaseTags a theorem for automatic use. This library prefers simp only [named, lemmas] in proofs meant to be read, and reserves plain simp for genuinely routine steps.
DecidableA proposition with an algorithm that settles itDecidableEq, DecidablePred are what let if i ∈ z then … else … and decide work. Every proposition about a Finset/Fin n here is decidable.
ClassicalNon-constructive reasoning, on tapClassical.choice and Classical.em (excluded middle) cover propositions with no algorithm. by_cases, and every fact about ℝ, uses it — ℝ itself is built with Classical.choice.
ENNReal (ℝ≥0∞)Nonnegative extended reals, with a genuine ∞The value type of a PMF. Needs open ENNReal (or open scoped ENNReal) for the ≥/∞ notation to parse; ordinary probability arithmetic mostly wants the .toReal cast back to ℝ.
PMF αA measure-theoretic probability mass function on αMathlib’s object, not this library’s Design. Design.toPMF / PMF.toDesign round-trip between the two — see the bridge chapter.
MeasureTheory.integral (∫)E[f], in measure-theoretic language∫ z, f z ∂μ is Mathlib’s expectation. Design.integral_toMeasure proves it equals D.expect f for a design’s induced measure: two vocabularies, one number.
∀ᵐ (a.e., “almost everywhere”)“except possibly on a probability-zero set”Appears only in the bridge chapter. ae_of_forall: a statement true at every assignment is true a.e., for free. of_ae_of_prob_pos: the converse holds only at assignments the design gives positive probability — a design’s null sets are the assignments it never produces, and an a.e. statement says nothing about them.

The library’s vocabulary

Every headline definition and theorem, grouped by the file (and chapter) that owns it. D is a Design n, P a Population n, z an Assignment n, π the propensity.

MrCLean/Basic.lean — potential outcomes

NameWhat it is
PopulationA structure: y1, y0 — the two potential outcomes per unit. SUTVA is enforced by the type, not assumed.
mean(∑ i, v i) / n, the average of a vector over all units.
Population.tauThe population ATE, mean P.effect.
Assignment nFinset (Fin n) — the treated set.
ZThe indicator, if i ∈ z then 1 else 0, valued in ℝ so ordinary algebra applies.
YobsThe observed outcome, Z z i * P.y1 i + (1 - Z z i) * P.y0 i.

MrCLean/Design.lean, Bernoulli.lean, CompleteRandomization.lean — designs

NameWhat it is
DesignA structure: an explicit pmf over assignments, its nonnegativity, and that it sums to one.
Design.expect∑ z, D.prob z * f z — expectation as a finite sum.
Design.propensity, Design.jointPropensityFirst- and second-order inclusion probabilities, πi and πij.
Design.var, Design.covDesign-based variance and covariance of a statistic.
Design.probOfThe probability of an event on assignments.
bernoulliDesignEach unit independently treated with probability p.
completeRandomizationUniform over assignments of exactly n₁ treated units.
completeRandomization_propensityπi=n1/n, for every unit, with no lower bound on n₁.
completeRandomization_jointPropensityπij=n1(n1−1)/(n(n−1)) for i≠j.

MrCLean/Estimators.lean — unbiasedness

NameWhat it is
HTThe Horvitz–Thompson estimator: inverse-propensity-weighted outcomes.
DiMThe difference-in-means estimator.
HT_unbiasedE[HT]=τ under any design with 0<πi<1 for every unit.
DiM_unbiased_completeRandomizationE[DiM]=τ under complete randomization with 0<n1<n.

MrCLean/Variance.lean — variance

NameWhat it is
fpVar, fpCovFinite-population variance and covariance, ∑(v - mean v)² / (n - 1) and its two-argument analogue.
Population.S1sq, S0sq, StausqfpVar of y1, y0, and the treatment effect — the S12,S02,Sτ2 of Neyman’s formula.
neyman_varianceVar(DiM)=S12/n1+S02/n0−Sτ2/n under complete randomization.
neymanVarEstThe usual variance estimator, s1²/n1 + s0²/n0.
neymanVarEst_biasE[v^]=Var(DiM)+Sτ2/n — the estimator is conservative, and the bias is identified exactly.

MrCLean/Blocking.lean — blocking and clustering

NameWhat it is
Design.mapPushforward of a design along a map of assignments — the tool both designs below are built from.
stratifiedDesignComplete randomization done independently within each block, as a uniform design over the jointly-balanced support.
blockedDiMThe blockwise difference-in-means, reweighted by block size — plain DiM is biased once blocks differ in treated fraction.
blockedDiM_unbiasedE[blockedDiM]=τ under the stratified design.
clusterDesignAny design on the clusters, pushed down to unit-level assignments by treating every member of a treated cluster. clusterHT_unbiased specialises it to complete randomization of the clusters.
clusterHT_unbiasedE[HT]=τ under cluster-randomized assignment.

MrCLean/Regression.lean — regression as linear algebra

NameWhat it is
IsOLSThe normal equations, (Xᵀ * X) *ᵥ β = Xᵀ *ᵥ y, stated for any candidate β — no rank condition.
ols(Xᵀ * X)⁻¹ *ᵥ (Xᵀ *ᵥ y), the closed-form solution (defined even when singular; meaningful only when Xᵀ X is invertible).
simpleMatrix_ols_coeffThe slope on a single treatment dummy, regressed with an intercept, equals DiM — a finite algebraic identity, no asymptotics.
ols_simpleMatrix_unbiased_completeRandomizationThat regression coefficient is unbiased under complete randomization — inherited from DiM_unbiased_completeRandomization.
groupMatrix_ols_coeffRegression on group dummies alone recovers each group’s mean.
isOLS_interactedMatrix_iffThe decoupling lemma: fully-interacted (Lin) regression is equivalent to two separate simple regressions, one per treatment arm.
lin_coeffThe treatment coefficient in Lin’s fully-interacted regression, as an exact finite-sample identity.

MrCLean/Fisher.lean — Fisher randomization tests

NameWhat it is
SharpNull∀ i, P.y1 i = P.y0 i — every unit’s effect is exactly zero.
Design.probEventThe design’s probability of an event on assignments (a renamed probOf, used throughout the Fisher chapter).
pValueD.probEvent (fun z => T z₀ ≤ T z) — the fraction of the randomization distribution at least as extreme as what was observed.
pValue_validPr(p-value≤α)≤α, for any test statistic, as a finite counting fact.
randomization_test_validThe same, with the statistic built from the observed data under the sharp null — the form you actually run.

MrCLean/Bridge.lean — bridge to Mathlib probability

NameWhat it is
Design.toPMF, PMF.toDesignThe round-trip between this library’s Design and Mathlib’s PMF.
Design.integral_toMeasure∫ z, f z ∂μ = D.expect f — the two notions of expectation agree.
Design.variance_toMeasureProbabilityTheory.variance f μ = D.var f.
HT_unbiased_integral, DiM_unbiased_completeRandomization_integralThis chapter’s two theorems, restated in measure-theoretic language — same proofs, translated statements.
bernoulli_iIndepSet_treated, bernoulli_iIndepFun_ZIndependence of treatment across units under the Bernoulli design, in Mathlib’s iIndepSet/iIndepFun vocabulary.