⚖️ Expectation, inequalities & limits
The toolkit behind almost every "what's the expected…" or "bound the probability that…" question: what an average really is, how spread is measured, how to bound tails when you can't compute them, how to update beliefs with evidence, and why averages always end up Gaussian.
Expectation & variance
Expectation: the balance point
The expectation $\E[X]$ is the probability-weighted average of the values $X$ can take. Physically, if you place a mass $P(X=x)$ at each point $x$ on a ruler, $\E[X]$ is where the ruler balances. It is also what the average of many independent draws settles down to (that is the law of large numbers).
The original notes wrote $\sum_x x\,P(X=k)$. The index must match: it is $\sum_x x\,P(X=x)$.
Expectation of a function (sometimes called LOTUS, the "law of the unconscious statistician"). To get $\E[g(X)]$ you do not need the distribution of $g(X)$. Just average $g$ over the distribution of $X$:
$$\E[g(X)]=\sum_x g(x)\,P(X=x)\qquad\text{or}\qquad \int_{-\infty}^{\infty}g(x)\,f(x)\,dx$$Worked example. A fair die $X$: $\E[X]=\frac{1+2+\dots+6}{6}=3.5$ and $\E[X^2]=\frac{1+4+9+16+25+36}{6}=\frac{91}{6}$. Note that $\E[X^2]\neq(\E[X])^2=12.25$. The gap between them is exactly the variance (next).
The tail formula
For a non-negative random variable you can skip the density entirely and integrate the survival function $P(X>x)=1-F(x)$:
Think of $X$ as a length. A length is the sum of all the little $dx$ slices you pass on the way from $0$ to $X$. Each slice at height $x$ is "counted" exactly when $X>x$, which happens with probability $P(X>x)$. Adding up those probabilities over all slices gives the average length.
Proof (one line with indicators)
Write $X=\int_0^\infty \1[X>x]\,dx$ (the indicator is 1 for $x\in[0,X)$, so the integral is exactly $X$). Take expectations and swap $\E$ with $\int$ (fine for non-negative integrands):
$$\E[X]=\int_0^\infty \E\big[\1[X>x]\big]\,dx=\int_0^\infty P(X>x)\,dx.$$The discrete version is the same with $X=\sum_{k=0}^{\infty}\1[X>k]$.
Where it shines: maxima and minima. For a min, $P(\min>x)=\prod_i P(X_i>x)$ is easy, so the tail formula gives $\E[\min]$ immediately. Example: $n$ iid $\Unif(0,1)$ have $\E[\min]=\int_0^1(1-x)^n\,dx=\frac{1}{n+1}$. See max/min of n RVs. For a geometric, $\E[X]=\sum_{k\ge0}(1-p)^k=1/p$ in one line.
Variance: average squared distance from the mean
Variance measures spread: how far, on average, $X$ lands from its mean, where "far" is measured by the squared distance. The standard deviation $\sigma=\sqrt{\Var(X)}$ brings it back to the original units.
The first form is the definition ("mean of squares of deviations"). The second form ("mean of square minus square of mean") is almost always easier to compute.
Proof that the two forms agree
Let $\mu=\E[X]$, a constant. Expand and use linearity:
$$\E[(X-\mu)^2]=\E[X^2]-2\mu\,\E[X]+\mu^2=\E[X^2]-2\mu^2+\mu^2=\E[X^2]-\mu^2.$$Since the left side is an average of squares, it is $\ge0$, which proves $\E[X^2]\ge(\E[X])^2$ for free.
Why squares and not absolute distances? Squares make the algebra beautiful: variances of independent pieces add, and $\E[X^2]-(\E X)^2$ falls out. Squares also punish big deviations heavily, which is why one outlier can blow up the variance (try dragging one dot far away).
Shifting and scaling. Adding a constant moves every value and the mean together, so the spread is unchanged. Scaling by $a$ scales every deviation by $a$ and every squared deviation by $a^2$:
Linearity of expectation
This is the single most useful fact in probability interviews. The trick is to write a complicated count as a sum of simple indicators and add up their expectations, completely ignoring how they depend on one another.
Classic: $n$ people throw their hats in a pile and each picks one at random. Expected number who get their own hat? Let $X_i=\1[\text{person } i \text{ gets own hat}]$. By symmetry $P(X_i=1)=1/n$, so $\E[\sum X_i]=n\cdot\frac1n=1$, for every $n$. The $X_i$ are dependent, and it doesn't matter. More in counting in expectation.
Proof (discrete case)
$$\E[X+Y]=\sum_{x,y}(x+y)P(X=x,Y=y)=\sum_x x\underbrace{\sum_y P(x,y)}_{P(X=x)}+\sum_y y\underbrace{\sum_x P(x,y)}_{P(Y=y)}=\E[X]+\E[Y].$$Only marginals appear, so no independence is needed.
Products, sums of variances & covariance
Products and variances are where dependence starts to matter. Covariance measures how $X$ and $Y$ move together:
$$\Cov(X,Y)=\E\big[(X-\E X)(Y-\E Y)\big]=\E[XY]-\E[X]\,\E[Y],\qquad \rho=\frac{\Cov(X,Y)}{\sigma_X\sigma_Y}\in[-1,1].$$Proof of the variance-of-a-sum formula
Let $\tilde X=X-\E X$ and $\tilde Y=Y-\E Y$. Then
$$\Var(X+Y)=\E[(\tilde X+\tilde Y)^2]=\E[\tilde X^2]+\E[\tilde Y^2]+2\E[\tilde X\tilde Y]=\Var X+\Var Y+2\Cov(X,Y).$$More generally $\Var\big(\sum_i X_i\big)=\sum_i\Var X_i+2\sum_{i<j}\Cov(X_i,X_j)$.
The original notes say $\Var(X+Y)=\Var X+\Var Y$ "if independent". That is true, but stronger than needed: it holds whenever $X$ and $Y$ are uncorrelated ($\Cov=0$). Independence implies uncorrelated, but not the other way round.
Two classic traps. (1) $\Var(X-Y)=\Var X+\Var Y$ for independent $X,Y$. The variances still add, because $(-1)^2=1$. (2) Uncorrelated does not mean independent: take $X$ uniform on $\{-1,0,1\}$ and $Y=X^2$. Then $\Cov(X,Y)=\E[X^3]-\E[X]\E[X^2]=0$, yet $Y$ is a function of $X$.
- $5$
- $-1$
- $25$
- $32$
The zoo of functions: PMF, PDF, CDF
Three ways to describe a distribution. Know which one you are holding, and how to convert between them.
| What it gives | Properties | |
|---|---|---|
| PMF (discrete) $p(k)=P(X=k)$ | an actual probability for each value | $p(k)\ge0$, $\ \sum_k p(k)=1$ |
| PDF (continuous) $f(x)$ | a probability density: $P(a\le X\le b)=\int_a^b f(x)\,dx$ | $f(x)\ge0$, $\ \int f=1$, $\ f=F'$. Can exceed 1! |
| CDF (both) $F(x)=P(X\le x)$ | probability of landing at or below $x$ | non-decreasing, from 0 to 1, right-continuous |
A PDF is like mass per unit length on a rod. A single point has zero mass ($P(X=x)=0$ for continuous $X$), but a short interval of width $dx$ has mass $\approx f(x)\,dx$. The CDF is the running total of mass as you walk from left to right, so its slope is the density.
Two small fixes to the original. (1) It wrote $F(x)=\int_{-\infty}^x f(x)\,dx$, reusing $x$ as both the limit and the integration variable. Use a dummy variable: $\int_{-\infty}^x f(t)\,dt$. (2) "$P(a\le X\le b)=F(b)-F(a)$" is only right for continuous $X$, where single points have probability zero. In general $F(b)-F(a)=P(a<X\le b)$. For an integer-valued $X$, $P(a\le X\le b)=F(b)-F(a-1)$.
- It can't be more than 1, so the question is ill-posed
- $4$
- $0.25$
- $0$, because $P(X=0.1)=0$
Inequalities
When you can't compute a probability exactly (or don't know the distribution), you can still bound it using only a mean or a variance. These bounds are loose, but they are universal, and they power the proofs of the limit theorems.
Markov's inequality
For any non-negative random variable $X$ and any $a>0$:
If the average income is 50k, at most 1 in 10 people can earn 500k or more. Otherwise those people alone would push the average above 50k. Non-negativity matters: no one can have negative income to "cancel out" the rich.
Proof
Drop the part of the sum below $a$ (it's non-negative), then replace each remaining $x$ by the smaller value $a$:
$$\E[X]\ge\sum_{x\ge a}x\,P(X=x)\ge a\sum_{x\ge a}P(X=x)=a\,P(X\ge a).$$Slicker version for any $X\ge0$: pointwise $a\,\1[X\ge a]\le X$. Take expectations to get $a\,P(X\ge a)\le\E[X]$.
Chebyshev's inequality
For any random variable with mean $\mu$ and variance $\sigma^2$ (no non-negativity needed):
The right form substitutes $\epsilon=k\sigma$. Equivalently, at least $1-1/k^2$ of the probability lies within $k$ standard deviations of the mean. For example, at least 75% lies within 2 sd and at least 89% within 3 sd, for any distribution. Compare with the normal's 95% and 99.7%.
Proof: apply Markov to $(X-\mu)^2$
$$P(|X-\mu|\ge k\sigma)=P\big((X-\mu)^2\ge k^2\sigma^2\big)\le\frac{\E[(X-\mu)^2]}{k^2\sigma^2}=\frac{\sigma^2}{k^2\sigma^2}=\frac1{k^2}.$$The square makes the variable non-negative, which is exactly what Markov needs.
In an interview, if you are asked to "bound" a probability with only a mean, reach for Markov. With a variance, reach for Chebyshev. If you have independence and want an exponentially small bound, mention Chernoff/Hoeffding bounds (apply Markov to $e^{tX}$).
- $2/5$ (Markov)
- $1/25$
- $1/4$
- $1/9$ (Chebyshev)
Jensen's inequality
Jensen tells you how expectations interact with curved functions:
A convex function curves upward like a bowl. Every chord between two points on the curve lies above the curve. $\E[\varphi(X)]$ is a point on such a chord (an average of the endpoint heights), while $\varphi(\E X)$ is on the curve directly below it. To remember the direction, use $\varphi(x)=x^2$ with $X=\pm1$: $\varphi(\E X)=\varphi(0)=0$ but $\E[\varphi(X)]=1$. This is just $\Var X\ge0$.
Convex ($\varphi''\ge0$, slope increasing):
- $x^2,\ x^4,\dots$ ($x^n$ for even $n$)
- $|x|$
- $a^x$ for $a>1$ (e.g. $e^x$)
- $1/x$ for $x>0$
- $\max(x_1,x_2,\dots)$
Concave ($\varphi''\le0$, slope decreasing):
- $\sqrt x$
- $\log x$
- $x^p$ for $0<p<1$
- $\min(x_1,x_2,\dots)$
Linear functions are both convex and concave, so Jensen holds with equality: that is linearity of expectation. ($|x|$ and $\max$ aren't twice differentiable, but they are convex by the chord definition.)
Worth memorizing: $\log\E[X]\ge\E[\log X]$, and $\E[1/X]\ge1/\E[X]$ for positive $X$.
- More, since $t=60/v$ is convex in $v$
- Less, since $t=60/v$ is concave in $v$
- Exactly 1 hour, by linearity
AM–GM inequality
For non-negative numbers, the arithmetic mean is at least the geometric mean, with equality iff all $a_i$ are equal:
The original notes wrote the inequality sign backwards ($\le$), contradicting their own sentence "arithmetic mean always ≥ geometric mean". Sanity check: $a=(1,4)$ gives AM $=2.5\ge$ GM $=2$.
Proof via Jensen
Let $X$ be uniform on $\{a_1,\dots,a_n\}$ (all $a_i>0$; if some $a_i=0$ the GM is 0 and there's nothing to prove). Since $\log$ is concave, $\log\E[X]\ge\E[\log X]$:
$$\log\frac{a_1+\dots+a_n}{n}\ \ge\ \frac1n\sum_i\log a_i=\log\sqrt[n]{a_1\cdots a_n}.$$Exponentiate both sides ($e^x$ is increasing, so the inequality is preserved).
Cauchy–Schwarz inequality
Geometrically, it is $|\langle x,y\rangle|\le\|x\|\,\|y\|$: a dot product can't exceed the product of the lengths. Applied to the centered variables $X-\E X$ and $Y-\E Y$, it says $|\Cov(X,Y)|\le\sigma_X\sigma_Y$, i.e. correlation is always between −1 and 1.
Proof (the discriminant trick)
For every real $t$, $0\le\E[(X-tY)^2]=\E[X^2]-2t\,\E[XY]+t^2\,\E[Y^2]$. A quadratic in $t$ that is never negative has at most one root, so its discriminant is $\le0$:
$$4\,\E[XY]^2-4\,\E[X^2]\,\E[Y^2]\le0.$$Union bound
Adding the probabilities double-counts the overlaps, so the sum can only overshoot. It needs no independence at all, and it is tight when the events are disjoint. Proof in one line: $\1[\cup A_i]\le\sum_i\1[A_i]$ pointwise, then take expectations.
Typical use: "show that with high probability none of $n$ bad things happen". If each has probability $\le\delta/n$, the union bound gives $P(\text{any})\le\delta$.
Conditional probability
Conditioning on $B$ means: throw away every outcome where $B$ didn't happen, and renormalize what's left so it sums to 1.
$$P(A\mid B)=\frac{P(A\cap B)}{P(B)}$$With two random variables $X$ and $Y$ there are three related distributions. Here is a small example joint table:
| $Y=0$ | $Y=1$ | marginal $P(X=x)$ | |
|---|---|---|---|
| $X=0$ | 0.30 | 0.10 | 0.40 |
| $X=1$ | 0.20 | 0.40 | 0.60 |
| marginal $P(Y=y)$ | 0.50 | 0.50 | 1 |
- Joint $P(X=x,Y=y)$: the cells. For example $P(X=1,Y=1)=0.40$.
- Marginal $P(X=x)=\sum_yP(X=x,Y=y)$: the row sums, written in the "margin". For example $P(X=1)=0.6$.
- Conditional $P(X=x\mid Y=y)=\frac{P(X=x,Y=y)}{P(Y=y)}$: one column, rescaled. For example $P(X=1\mid Y=1)=0.40/0.50=0.8$.
Bayes' rule
- $P(A)$ is the prior: what we believed before seeing $B$.
- $P(B\mid A)$ is the likelihood: how well $A$ explains the evidence.
- $P(A\mid B)$ is the posterior: what we believe after seeing $B$.
- The denominator $P(B)$ comes from the law of total probability.
Proof
Write the joint probability two ways: $P(A\cap B)=P(A\mid B)P(B)=P(B\mid A)P(A)$. Divide by $P(B)$.
Natural frequencies beat formulas. Disease prevalence 1%, test sensitivity 90%, false-positive rate 9%. In 1,000 people: 10 sick, of whom 9 test positive. 990 healthy, of whom about 89 test positive. So only $9/(9+89)\approx9\%$ of positives are sick. The prior matters enormously.
Odds form (fast mental math): posterior odds = prior odds × likelihood ratio.
$$\frac{P(A\mid B)}{P(A^c\mid B)}=\frac{P(A)}{P(A^c)}\cdot\frac{P(B\mid A)}{P(B\mid A^c)}$$Above: prior odds $1:99$, likelihood ratio $0.9/0.09=10$, posterior odds $10:99$, so $P\approx 10/109\approx9\%$. For repeated independent tests, just multiply in another likelihood ratio.
- $1/100$
- $32/131$
- $31/32$
- $1/2$
Law of total probability
Split the world into disjoint cases $Y=y$ (a partition), compute the probability in each case, and average using how likely each case is:
This is the "branching tree" picture: multiply along each branch, then add over the branches. It is how you compute the denominator in Bayes' rule.
Law of total expectation (tower property)
The same idea for averages. The overall average is the weighted average of the case-by-case averages:
In the compact form, $\E[X\mid Y]$ is itself a random variable: a function of $Y$ that takes the value $\E[X\mid Y=y]$ when $Y=y$. This is the engine behind first-step analysis, where you condition on the first step.
Proof (discrete)
$$\sum_y\E[X\mid Y=y]P(Y=y)=\sum_y\sum_x x\,\frac{P(X=x,Y=y)}{P(Y=y)}P(Y=y)=\sum_x x\sum_yP(X=x,Y=y)=\sum_x x\,P(X=x)=\E[X].$$- $3.5$
- $7$
- $5.25$
- $4.5$
Bonus: law of total variance ("Eve's law")
$$\Var(X)=\underbrace{\E\big[\Var(X\mid Y)\big]}_{\text{average spread within groups}}+\underbrace{\Var\big(\E[X\mid Y]\big)}_{\text{spread between group means}}$$In the die-and-coins example with a fair die and fair coins: $\Var(X\mid Y)=Y/4$ and $\E[X\mid Y]=Y/2$, so $\Var X=\E[Y]/4+\Var(Y)/4=\tfrac{3.5}{4}+\tfrac{35/12}{4}\approx1.604$.
Limit theorems
Two theorems about the sample mean $\bar X_n=\frac1n\sum_{i=1}^nX_i$ of $n$ iid draws with mean $\mu$ and variance $\sigma^2$. The LLN says where $\bar X_n$ goes (to $\mu$). The CLT says how it fluctuates on the way (Gaussian, with width $\sigma/\sqrt n$).
Law of large numbers
In words, the running average of many independent draws gets arbitrarily close to the true mean with probability approaching 1. This is why casinos always win in the long run, and why "expected value" is the right thing to optimize for repeated bets.
Proof from Chebyshev (when $\sigma^2<\infty$)
$\E[\bar X_n]=\mu$ and $\Var(\bar X_n)=\sigma^2/n$ (derived below). Apply Chebyshev in its $\epsilon$-form:
$$P\big(|\bar X_n-\mu|>\epsilon\big)\le\frac{\Var(\bar X_n)}{\epsilon^2}=\frac{\sigma^2}{n\epsilon^2}\ \to\ 0.$$The gambler's fallacy is not the LLN. After 10 heads in a row the next flip is still 50/50. The average converges not because the coin "compensates", but because the early streak is diluted by an ever larger number of ordinary flips.
Central limit theorem
Whatever the shape of the distribution of each $X_i$ (skewed, bimodal, discrete…), as long as it has finite variance, the sample mean is approximately Gaussian for large $n$:
Adding many independent random pieces washes out the individual quirks: lumps in one draw get averaged against dips in others, and only the mean and the variance survive. You already saw a preview with sums of uniforms.
Where $\sigma^2/n$ comes from (this part is exact, no approximation):
$$\Var(\bar X_n)=\Var\!\Big(\frac1n\sum_{i=1}^nX_i\Big)=\frac1{n^2}\Var\!\Big(\sum_{i=1}^nX_i\Big)=\frac1{n^2}\sum_{i=1}^n\Var(X_i)=\frac{n\sigma^2}{n^2}=\frac{\sigma^2}{n}$$Step 2 uses $\Var(aX)=a^2\Var X$. Step 3 uses independence (uncorrelated is enough).
The standard error is the standard deviation of $\bar X_n$:
The error shrinks like $1/\sqrt n$. To make the error 10× smaller you need 100× more samples. Halving it costs 4×.
The original notes said "error shrinks like $\sqrt n$". It shrinks like $1/\sqrt n$ (equivalently, precision grows like $\sqrt n$). The "100× samples for 10× less error" conclusion was right.
A $(1-\alpha)$ confidence interval for $\mu$ (with known $\sigma$) is
$$\bar X_n\pm z_{1-\alpha/2}\cdot\frac{\sigma}{\sqrt n},$$for example $\bar X_n\pm1.96\,\sigma/\sqrt n$ for 95%. See the z-table.
Fine print. The CLT is an approximation for large $n$, not an exact statement (unless the $X_i$ are themselves Gaussian). It needs finite variance: averages of Cauchy variables never converge to anything. Convergence is slower for very skewed sources (try Bernoulli(0.05) above with small $n$). The original notes' "is Gaussian" should be read as "is approximately Gaussian".
Typical question: "A fair coin is flipped 10,000 times. Roughly what is the probability of more than 5,100 heads?" The count of heads has mean 5,000 and sd $\sqrt{10000\cdot\tfrac14}=50$. 5,100 is 2 sd above the mean, so the answer is about $P(Z>2)\approx2.3\%$.
- 2,000
- 800
- 4,000
- 10,000
Cheat sheet
| Fact | Formula | Needs |
|---|---|---|
| Linearity | $\E[aX+bY+c]=a\E X+b\E Y+c$ | nothing |
| Tail formula | $\E X=\int_0^\infty P(X>x)\,dx$ | $X\ge0$ |
| Variance | $\E[X^2]-(\E X)^2$; $\ \Var(aX+b)=a^2\Var X$ | nothing |
| Sum of variances | $\Var(X+Y)=\Var X+\Var Y$ | uncorrelated |
| Product | $\E[XY]=\E X\,\E Y$ | independent (or uncorrelated) |
| Markov | $P(X\ge a)\le\E X/a$ | $X\ge0$ |
| Chebyshev | $P(|X-\mu|\ge k\sigma)\le1/k^2$ | finite variance |
| Jensen | $\varphi(\E X)\le\E\varphi(X)$ | $\varphi$ convex |
| Bayes | $P(A\mid B)=P(B\mid A)P(A)/P(B)$ | $P(B)>0$ |
| Tower | $\E X=\E[\E[X\mid Y]]$ | nothing |
| LLN | $\bar X_n\to\mu$ | iid, finite mean |
| CLT | $\bar X_n\approx\N(\mu,\sigma^2/n)$ | iid, finite variance, large $n$ |