For an integrable real-valued random variable \(X\), its expectation is the integral \(\int X\,d\mathbb P\). A nonnegative random variable also has an extended expectation, which may equal \(+\infty\). On a finite or countable discrete space, the integral is a probability-weighted sum over atoms. For an atomless real law, it is not a sum of “the probability of each exact value”: every singleton has probability zero. Expectation is not the result at one outcome, and it need not belong to the range \(X(\Omega)\).

Expectation is an integral with respect to a probability measure . The probability normalization matters: integrating the same quantity against a general measure of total mass \(2\) doubles the raw integral.

Start with three possible payoffs

Let the outcome space be

\[ \Omega=\{L,M,H\}. \]

Define a real-valued payoff \(X\) and probability measure \(\mathbb P\) by

Outcome \(\omega\)Payoff \(X(\omega)\)Probability \(\mathbb P(\{\omega\})\)
\(L\)\(-1\)\(1/2\)
\(M\)\(2\)\(1/3\)
\(H\)\(5\)\(1/6\)

The three probabilities add to one:

\[ \frac12+\frac13+\frac16 =\frac36+\frac26+\frac16 =1. \]

Suppose one run produces \(\omega=M\). The realized payoff is then

\[ X(M)=2. \]

That single observation does not erase the other possibilities. The law of \(X\) still assigns mass \(1/2\) to payoff \(-1\), mass \(1/3\) to payoff \(2\), and mass \(1/6\) to payoff \(5\). A realization is one selected value. In this finite example, the law is the complete weighted list of its three atoms.

Compute the weighted average exactly

On a finite probability space, expectation is the sum

\[ \mathbb E_{\mathbb P}[X] =\sum_{\omega\in\Omega}X(\omega)\mathbb P(\{\omega\}). \]

For this payoff,

\[ \begin{aligned} \mathbb E_{\mathbb P}[X] &=\frac12(-1)+\frac13(2)+\frac16(5)\\ &=-\frac36+\frac46+\frac56\\ &=\frac66\\ &=1. \end{aligned} \]

The negative payoff contributes \(-3/6\), while the two positive payoffs contribute \(4/6\) and \(5/6\). Expectation combines contributions; it does not choose the most likely payoff.

There is no outcome with payoff \(1\):

\[ X(\Omega)=\{-1,2,5\}, \qquad 1\notin X(\Omega). \]

Thus an expectation need not be attainable in a single realization. It is the center of the probability-weighted values, not an additional attained value.

A three-outcome experiment has payoffs minus one, two, and five with probabilities one half, one third, and one sixth. One realized draw selects payoff two, but all three weighted contributions combine to expectation one. A lower comparison doubles the measure to total mass two and raw integral two, then divides by total mass to recover normalized expectation one. A final strip checks linearity for Y equal to two X plus three.
FigureFinding: one realization \(M\) produces \(X(M)=2\), while the law retains all three branches. Their exact weighted contributions are \((1/2)(-1)=-3/6\), \((1/3)2=4/6\), and \((1/6)5=5/6\), so \(\mathbb E_{\mathbb P}[X]=1\), even though \(1\) is not an attainable payoff. Replacing \(\mathbb P\) by the mass-two measure \(\nu=2\mathbb P\) doubles the raw integral to \(2\). Normalizing by \(\nu(\Omega)=2\) restores the probability average \(1\). The patterned cards and labels identify the three branches without relying on color.

From a finite sum to an integral

For an integrable real random variable

\[ X:\Omega\longrightarrow\mathbb R \]

on a probability space \((\Omega,\mathcal F,\mathbb P)\), expectation is

\[ \mathbb E_{\mathbb P}[X] =\int_\Omega X(\omega)\,d\mathbb P(\omega). \]

The sigma algebra \(\mathcal F\) specifies the measurable events , and \(\mathbb P\) assigns them probability. The function \(X\) must be measurable so that value-space questions pull back to events. Integrability ensures that the positive and negative contributions combine into a finite real number.

In the three-outcome example, the integral is exactly the weighted sum already computed. The integral notation is not a different average. It is the form that continues to work on continuous and mixed outcome spaces where listing all outcomes is impossible.

Expectation can also be computed from the law \(\mathcal L_{\mathbb P}(X)=X_*\mathbb P\):

\[ \mathbb E_{\mathbb P}[X] =\int_{\mathbb R}x\,d\mathcal L_{\mathbb P}(X)(x). \]

The first integral averages over source outcomes. The second averages the identity function over the real value space. They agree because the law is the pushforward of \(\mathbb P\) through \(X\).

Raw mass is not probability expectation

Now define a new measure

\[ \nu=2\mathbb P. \]

Its atomic masses are \(1\), \(2/3\), and \(1/3\), and its total mass is

\[ \nu(\Omega)=2. \]

The raw integral scales with the measure:

\[ \int_\Omega X\,d\nu =2\int_\Omega X\,d\mathbb P =2. \]

This number is not the probability expectation of \(X\) under \(\nu\), because \(\nu\) is not a probability measure. If the intent is to turn a positive finite measure into a probability measure, normalization is an explicit operation:

\[ \widehat\nu=\frac{\nu}{\nu(\Omega)} =\frac{\nu}{2} =\mathbb P. \]

The normalized average is then

\[ \frac{1}{\nu(\Omega)}\int_\Omega X\,d\nu =\frac12\cdot2 =1. \]

Under a probability measure, the denominator is already one, so expectation is the raw integral. Under a mass-two measure, saying “expectation” without either normalizing or declaring a different convention hides a factor of two.

Linearity: transform first or average first

Expectation is linear. For integrable real random variables \(X\) and \(Z\) and real constants \(a\) and \(b\),

\[ \mathbb E[aX+bZ] =a\,\mathbb E[X]+b\,\mathbb E[Z]. \]

A constant function has expectation equal to that constant on a probability space. Therefore, if

\[ Y=2X+3, \]

then

\[ \mathbb E[Y]=2\mathbb E[X]+3=2(1)+3=5. \]

The direct three-outcome calculation agrees. The transformed payoffs are \(1\), \(7\), and \(13\), so

\[ \frac12(1)+\frac13(7)+\frac16(13) =\frac36+\frac{14}{6}+\frac{13}{6} =\frac{30}{6} =5. \]

Linearity does not say \(\mathbb E[XZ]=\mathbb E[X]\mathbb E[Z]\). That product identity requires additional assumptions such as independence and integrability of the product.

In Lean: type the integral that expectation names

One idea, three languages Read across, then read the syntax map
A human says
Average the real quantity X over all outcomes using the probability measure mu.
On paper
\(\mathbb E_\mu[X]=\int_\Omega X(\omega)\,d\mu(\omega).\)
In Lean
∫ ω, X ω ∂μ
Syntax map
  • ∫ begins Lean’s integral notation.
  • ω is the bound outcome variable. Its scope extends through the integrand that follows the comma.
  • X ω is function application, read as the paper expression \(X(\omega)\).
  • ∂μ names the measure used for integration. It is the source notation corresponding to \(d\mu(\omega)\).
  • The literal line a human places in a Lean file is ∫ ω, X ω ∂μ. The complete worksheet below supplies the import, types, and hypotheses that give every symbol meaning.
  • The notation itself only forms a raw integral. Calling it an expectation is semantically justified when μ is a probability measure; a finite real interpretation also requires the appropriate integrability evidence.

The project makes those two gates visible in its finite-horizon cocycle API:

One idea, three languages Read across, then read the syntax map
A human says
At horizon k, take the expected log-positive norm of the cocycle product; hC supplies the integrability proof and the surrounding typeclass supplies probability normalization.
On paper
\(\mathbb E_\mu[P_k]=\int_\Omega P_k(\omega)\,d\mu(\omega),\quad P_k(\omega)=\log^+\lVert\Phi_k(\omega)\rVert.\)
In Lean
C.finiteHorizonLogPlusExpectation hC k
Syntax map
  • C is a discrete matrix cocycle over the source measure μ.
  • k : ℕ is the finite time horizon.
  • C.logPlusNormObservable k ω is the project function \(P_k(\omega)=\log^+\lVert\Phi_k(\omega)\rVert\).
  • hC : C.HasIntegrableGeneratorLogPlus proves the one-step hypothesis from which the project derives integrability at every finite horizon.
  • [IsProbabilityMeasure μ] is present in the complete definition even though it is not printed at the call site. Square brackets ask Lean to synthesize the visible total-mass-one certificate from context.
  • finiteHorizonLogPlusExpectation is a semantic name for the same real integral already called integratedLogPlusNorm. It performs no hidden division.

The following definition and theorem are exact excerpts from the checked project source:

def finiteHorizonLogPlusExpectation [IsProbabilityMeasure μ]
    (C : DiscreteMatrixCocycle (ι := ι) μ)
    (_hC : C.HasIntegrableGeneratorLogPlus) (k : ℕ) : ℝ :=
  ∫ ω, C.logPlusNormObservable k ω ∂μ

@[simp] theorem finiteHorizonLogPlusExpectation_eq_integratedLogPlusNorm
    [IsProbabilityMeasure μ]
    {C : DiscreteMatrixCocycle (ι := ι) μ}
    (hC : C.HasIntegrableGeneratorLogPlus) (k : ℕ) :
    C.finiteHorizonLogPlusExpectation hC k = C.integratedLogPlusNorm k := by
  rfl

The underscore in _hC records that the proof is deliberately part of the interface even though the definition body does not compute with it. The equality proof is rfl: after unfolding the two project names, both sides are literally the same integral. The theorem is not a normalization formula. The probability typeclass has already required total mass one before the expectation name can be formed.

Try the three-payoff ledger locally

This first worksheet imports only Lean’s small Std library. It stores every probability as a numerator over the common denominator six, so the paper calculation

\[ \frac{-3+4+5}{6}=1 \]

becomes exact integer arithmetic. Save this as /tmp/ExpectationScratch.lean on a normal Mac or Linux computer:

import Std

namespace ExpectationScratch

def payoffs : List Int := [-1, 2, 5]
def weightsSixths : List Nat := [3, 2, 1]

def contributionsSixths : List Int :=
  List.zipWith
    (fun payoff weight => payoff * Int.ofNat weight)
    payoffs weightsSixths

def totalSixths : Int :=
  contributionsSixths.foldl (fun total term => total + term) 0

def transformedPayoffs : List Int :=
  payoffs.map (fun payoff => 2 * payoff + 3)

def transformedContributionsSixths : List Int :=
  List.zipWith
    (fun payoff weight => payoff * Int.ofNat weight)
    transformedPayoffs weightsSixths

def transformedTotalSixths : Int :=
  transformedContributionsSixths.foldl (fun total term => total + term) 0

#eval contributionsSixths
#eval totalSixths
#eval totalSixths / 6
#eval transformedContributionsSixths
#eval transformedTotalSixths / 6

example : contributionsSixths = [-3, 4, 5] := by decide
example : totalSixths = 6 := by decide
example : totalSixths / 6 = 1 := by decide
example : transformedContributionsSixths = [3, 14, 13] := by decide
example : transformedTotalSixths / 6 = 5 := by decide

end ExpectationScratch

Type these two commands exactly:

source "$HOME/.elan/env"
elan run leanprover/lean4:v4.32.0 lean /tmp/ExpectationScratch.lean

This exact standalone worksheet was executed successfully with Lean 4.32.0. It printed:

[-3, 4, 5]
6
1
[3, 14, 13]
5

The three entries on the first line are the weighted contributions in sixths, not sampled payoffs. The proof lines ask Lean to check the same total and the linearity example \(Y=2X+3\). This bounded worksheet neither imports Mathlib nor constructs a measure-theoretic integral.

Full project check

The next worksheet uses the repository’s Mathlib-backed integral interface. Type it in a clone with the repository’s pinned Lean and Mathlib dependencies installed:

import NonlinearDynamics.Random.RandomCocycles.ProbabilityErgodicBase

open MeasureTheory

#check integral_add
#check NonlinearDynamics.Random.RandomCocycles.DiscreteMatrixCocycle.finiteHorizonLogPlusExpectation
#check NonlinearDynamics.Random.RandomCocycles.DiscreteMatrixCocycle.finiteHorizonLogPlusExpectation_eq_integratedLogPlusNorm

variable {Ω : Type*} [MeasurableSpace Ω]
variable (μ : Measure Ω) (X Y : Ω → ℝ)

#check ∫ ω, X ω ∂μ

example (hX : Integrable X μ) (hY : Integrable Y μ) :
    (∫ ω, X ω + Y ω ∂μ) =
      (∫ ω, X ω ∂μ) + (∫ ω, Y ω ∂μ) := by
  exact integral_add hX hY

The first #check asks for Mathlib’s integral-linearity theorem. The next two inspect the project’s probability-normalized expectation definition and its equality with the raw integrated observable. The local variables make the line #check ∫ ω, X ω ∂μ meaningful. Finally, the example supplies explicit integrability proofs to integral_add, and Lean’s kernel checks the resulting additivity proof term. It is the typed counterpart of \(\mathbb E[X+Y]=\mathbb E[X]+\mathbb E[Y]\) when \(\mu\) is a probability measure, and a valid raw-integral identity for general \(\mu\).

Try it in the repository NonlinearDynamics/Random/RandomCocycles/ProbabilityErgodicBase.lean
The authoritative source is formalization/NonlinearDynamics/Random/RandomCocycles/ProbabilityErgodicBase.lean. That module imports the finite-horizon log-positive observable and its integrability theory, requires [IsProbabilityMeasure μ] before using the expectation name, and proves by rfl that the named expectation equals integratedLogPlusNorm. The worksheet above uses the same project import and exact declaration names. The full-project command checks the complete module with the repository’s pinned dependencies installed.
Full project check, from the repository root
cd formalization
lake env lean -DwarningAsError=true NonlinearDynamics/Random/RandomCocycles/ProbabilityErgodicBase.lean

Resource note: this exact file uses the repository's pinned Lean and Mathlib dependencies. Initial project setup can require substantial disk space and build time. For a lightweight first step on macOS or Linux, use the page's standalone Lean-core or Std tutorial.

Distinctions and failure modes

Tempting shortcutWhat is wrongCorrect repair
“The expectation is what happened”One realization is \(X(\omega)\); expectation averages the whole lawKeep the observed value and distribution-level average separate
“The expectation must be an attained value”A weighted center can lie between listed atoms and therefore outside the attained finite setCheck the range \(X(\Omega)\) separately
“The most likely value is the expectation”Mode and expectation answer different questionsCompute probability times value for every branch
“Any raw integral is an expectation”A measure may have total mass other than oneRequire a probability measure or explicitly normalize a positive finite measure
“The law and one sample contain the same information”One sample selects one value; the law records weights for all valuesUse repeated data to estimate the law, not to redefine it after one draw
“Finite values guarantee finite expectation”On an infinite outcome space, tails can make a real random variable nonintegrableProve integrability or state an extended nonnegative expectation
“Changing a function on a null set changes its expectation”Integrals identify functions that agree almost everywhereUse the null set and almost-everywhere interface explicitly
“Linearity makes products factor”\(\mathbb E[XZ]=\mathbb E[X]\mathbb E[Z]\) is not linearityAdd independence and product-integrability hypotheses when appropriate

Where to continue

Read event for the measurable yes-or-no questions underlying the outcome space. Read measure and probability measure for the difference between raw mass and normalized mass. Read probability law for the value-space distribution that also determines expectation, and null set for changes that do not affect an integral.

The chapter Probability Normalization and Ergodic Rigidity Before Kingman places the project’s finite-horizon expectation beside its integrability and ergodicity assumptions.

References

Mathlib contributors. Bochner integral basics, Mathlib 4 documentation. This official implementation reference contains the real and vector-valued integral API, including integral_add and the integral of a constant.

Mathlib contributors. Probability measure typeclass, Mathlib 4 documentation. This official source records the total-mass-one assumption used by the project’s expectation interface.

Olav Kallenberg. Foundations of Modern Probability, third edition, Springer, 2021. This is a standard reference for expectation, integration, laws of random elements, and almost-everywhere equivalence.