EECS 126 (UC Berkeley) · Spring 2026 · January 20, 2026
A probability space provides the mathematical framework for modeling random experiments. In this lecture we define the axioms of probability, introduce sample spaces and events, work through several foundational examples, and derive the birthday paradox bound.
Probability Spaces
Definition 1.1 (Probability space)
A probability space is a triple (Ω,F,P) where:
Ω is the sample space: the set of all possible outcomes of the experiment.
F⊆2Ω is a σ-algebra of subsets of Ω, called events.
P:F→[0,1] is a probability measure satisfying the Kolmogorov axioms.
The elements ω∈Ω are called base outcomes (or samples). A σ-algebra F is a family of subsets of Ω that is closed under countable unions, countable intersections, and complements, and that contains Ω itself. In many discrete settings we simply take F=2Ω (the power set), so that every subset of Ω is an event.
Example 1.1 (Tossing two fair coins)
Toss two fair coins. The sample space is
Ω={HH,HT,TH,TT}.
Each base outcome is equally likely, so we assign P({ω})=41 for each ω∈Ω. The event space is the power set F=2Ω, which has ∣F∣=2∣Ω∣=24=16 elements.
Example 1.2 (Toss until heads)
Toss a coin repeatedly until the first heads. Then
Ω={H,TH,TTH,TTTH,…}
is a countably infinite sample space.
Example 1.3 (Waiting for a bus)
Wait at a bus stop for the next bus, which arrives at some time in [0,T]. Now
Ω=[0,T]
is an uncountably infinite (continuous) sample space. In this setting the choice of F becomes nontrivial; one typically takes F to be the Borel σ-algebra on [0,T].
Kolmogorov Axioms
Definition 1.2 (Kolmogorov axioms)
A function P:F→R is a probability measure on (Ω,F) if it satisfies:
Nonnegativity.P(A)≥0 for all A∈F.
Normalization.P(Ω)=1.
Countable additivity. If A1,A2,…∈F are pairwise disjoint (Ai∩Aj=∅ for i=j), then
P(i≥1⋃Ai)=i≥1∑P(Ai).
Why countable additivity? In a continuous sample space such as Ω=[0,1], every individual point has probability zero: P({x})=0. If we only had finite additivity, we could not recover P([0,1])=1 from the probabilities of individual points. Countable additivity bridges this gap and is essential for the theory of continuous distributions.
Example 1.4 (Biased coin)
Flip a biased coin: heads with probability p, tails with probability 1−p. Set
Ω={H,T},F=2Ω={∅,{H},{T},{H,T}}.
Define
P(H)=p,P(T)=1−p,P(∅)=0,P({H,T})=1.
Then (Ω,F,P) is a valid probability space.
Fundamental Probability Facts
The following basic identities are direct consequences of the Kolmogorov axioms.
Theorem 1.1 (Complement rule)
For any event A∈F,
P(Ac)=1−P(A).
Proof.
Since A and Ac are disjoint with A∪Ac=Ω, countable additivity gives P(A)+P(Ac)=P(Ω)=1.
Define B1=A1 and Bk=Ak∖⋃i<kAi for k≥2. The Bk are disjoint with ⋃Bk=⋃Ak, and P(Bk)≤P(Ak), so P(⋃Ak)=∑P(Bk)≤∑P(Ak).
Discrete Probability and Counting
In a discrete sample space, the probability of an event is just the sum of the probabilities of its base outcomes:
P(A)=ω∈A∑P({ω}).
Definition 1.3 (Uniform sample space)
When all outcomes are equally likely, we say Ω is a uniform sample space, and for any event A,
P(A)=∣Ω∣∣A∣.
The Birthday Paradox
Example 1.5 (Birthday paradox)
Let n people be in a room. What is the probability that at least two share a birthday? Let K=365 and assume birthdays are uniform. Let A = “at least two people share a birthday.” Compute via the complement:
P(Ac)=KnK(K−1)(K−2)⋯(K−n+1)=j=0∏n−1(1−Kj).
Using 1−x≤e−x:
P(Ac)≤j=0∏n−1e−j/K=e−∑j=0n−1j/K=e−n(n−1)/(2K).
Theorem 1.4 (Birthday bound)
P(A)≥1−e−n(n−1)/(2K). For K=365 and n=23, this gives P(A)≥50%.
Balls-and-bins interpretation. The birthday problem is equivalent to throwing n balls uniformly into K bins and asking for the probability of a collision. This connection arises frequently in hashing, load balancing, and networking.
EECS 126 (UC Berkeley) · Spring 2026 · January 22, 2026
In this lecture we introduce conditional probability, derive the multiplication (chain) rule, state the law of total probability and Bayes’ rule, work through the classic false-positive medical testing example, and then develop the theory of independence and conditional independence.
Conditional Probability
Definition 2.1 (Conditional probability)
Let A,B be events with P(B)>0. The conditional probability of A given B is
P(A∣B)=P(B)P(A∩B).
Intuitively, P(A∣B) is the probability that A occurs when we know that B has occurred. Conditioning on B restricts the sample space from Ω to B; the event B becomes the new “Ω” for A.
In a uniform sample space, P(A)=∣A∣/∣Ω∣. Conditioning on B gives P(A∣B)=∣A∩B∣/∣B∣, which is simply the fraction of outcomes in B that also lie in A.
Example 2.1 (Two dice – conditioning on the sum)
Roll two standard dice. Let A={1st die is 6}, B={sum of two dice is 7}, and C={sum of two dice is 11}.
Computing P(A∣B): The outcomes in B (sum = 7) are {(1,6),(2,5),(3,4),(4,3),(5,2),(6,1)}, so P(B)=6/36. The only outcome in A∩B is (6,1), so P(A∩B)=1/36. Therefore
P(A∣B)=6/361/36=61.
Computing P(A∣C): The outcomes in C (sum = 11) are {(5,6),(6,5)}, so P(C)=2/36. The only outcome in A∩C is (6,5), so
P(A∣C)=2/361/36=21.
Multiplication Rule (Chain Rule)
Theorem 2.1 (Chain rule of probability)
For any events A1,A2,…,An with P(A1∩A2∩⋯∩An−1)>0,
By repeated application of the definition of conditional probability. Write P(A1∩A2)=P(A1)P(A2∣A1), then P(A1∩A2∩A3)=P(A1∩A2)P(A3∣A1∩A2), and continue inductively. Each factor is well-defined because P(A1∩⋯∩Ak−1)>0 implies P(A1∩⋯∩Ak)≤P(A1∩⋯∩Ak−1), and we are given the intersection has positive probability up to n−1 terms.
Birthday paradox via the chain rule. The chain rule gives an alternative derivation of the birthday bound. Let Ai={person i doesn’t share a birthday with persons 1,…,i−1}. Then
Let A1,A2,…,AN be a partition of Ω (i.e. the Ai are pairwise disjoint — mutually exclusive — and their union is Ω — collectively exhaustive). Then for any event B,
P(B)=i=1∑NP(Ai)P(B∣Ai).
Proof.
Since {Ai} partitions Ω, we can decompose B as B=⋃i=1N(Ai∩B), and these pieces are disjoint. By countable additivity, P(B)=∑i=1NP(Ai∩B)=∑i=1NP(Ai)P(B∣Ai), where the last step uses the definition of conditional probability.
Bayes’ Rule
Theorem 2.3 (Bayes’ rule)
Let A1,…,AN partition Ω. Given an event B with P(B)>0,
P(Ai∣B)=∑j=1NP(B∣Aj)P(Aj)P(B∣Ai)P(Ai).
The numerator uses the definition of conditional probability, and the denominator is P(B) expanded by the law of total probability.
Example 2.2 (False positive quiz – testing for a rare disease)
A medical test for a rare disease has the following properties:
If a person has the disease, the test is positive with probability 0.95 (sensitivity).
If a person does not have the disease, the test is negative with probability 0.95 (specificity), i.e. false positive rate =0.05.
The prior prevalence is P(A)=0.001 (1 in 1000 people have the disease).
A person tests positive. What is P(disease∣positive)?
Define A={has disease}, B={tests positive}. By Bayes’ rule:
Despite the test being 95% accurate, a positive result only indicates a ≈1.87% chance of actually having the disease. This is because the disease is so rare that the false positives from healthy people vastly outnumber the true positives.
Sensitivity to the prior. If the prior were P(A)=0.01 instead (10× more common), then P(A∣B)≈16% — still low, but dramatically higher. The base rate (prior) has an enormous effect on the posterior.
Independence
Definition 2.2 (Independence of two events)
Two events A and B are independent if the occurrence of one provides no information about the occurrence of the other. Formally:
P(A∣B)=P(A),or equivalently,P(A∩B)=P(A)P(B).
The second form says the joint probability equals the product of the marginals.
Key remarks on independence:
Disjoint = independent.A,B disjoint means P(A∩B)=0. For this to equal P(A)P(B), we need P(A)=0 or P(B)=0. So disjoint events with positive probability are dependent, not independent.
Base outcomes are always dependent. Individual outcomes {ω} in any finite Ω are always dependent (knowing one occurred rules out the others).
Example 2.3 (Dice: independence depends on the conditioning event)
Roll two fair dice. Let A={1st die is 6}, B={sum is 7}, C={sum is 11}.
Are A and B independent?P(A∣B)=1/6=P(A), so yes, A⊥B.
Are A and C independent?P(A∣C)=1/2=1/6=P(A), so no, A and C are dependent. Intuitively, knowing the sum is 11 makes it more likely that the first die was a 6 (since (6,5) is one of only two outcomes).
Conditional Independence
Definition 2.3 (Conditional independence)
Events A and B are conditionally independent given C if
P(A∩B∣C)=P(A∣C)P(B∣C).
Independence and conditional independence are distinct concepts:
Dependent events can become conditionally independent.
Independent events can become conditionally dependent.
Example 2.4 (Two indistinguishable coins)
You have two coins: one is double-headed, the other is double-tailed. You pick one at random and flip it twice. Let Hi={flip i is heads}, i=1,2.
Q1: Are H1,H2 (unconditionally) independent? No. P(H1∣H2)=1=1/2=P(H1). If the second flip is heads, you certainly picked the double-headed coin, so the first flip is heads with certainty.
Q2: Conditioning on the coin, are they independent? Let A={picked the double-headed coin}. Then P(H1∩H2∣A)=P(H1∣A)P(H2∣H1∩A)=1⋅1=1, and P(H1∣A)P(H2∣A)=1⋅1=1. These are equal, so H1⊥H2∣A. Once we know which coin was picked, each flip is determined and independent.
Example 2.5 (Fair coin – independent but conditionally dependent)
Toss a fair coin twice. Let H1={1st toss is H}, H2={2nd toss is H}, and D={1st toss=2nd toss}.
Q1: H1⊥H2? Yes, by independence of fair coin flips.
Q2: H1⊥H2∣D? No. P(H1∣D)P(H2∣D)=21⋅21=41. But P(H1∩H2∣D)=0, since both flips being heads contradicts D (the flips must differ). Since 0=1/4, the events are conditionally dependent given D.
Joint Independence vs. Pairwise Independence
Definition 2.4 (Independence of a collection)
Events {Ai}i∈S are jointly (mutually) independent if for every subset T⊆S,
P(i∈T⋂Ai)=i∈T∏P(Ai).
Pairwise independence only requires this for all pairs ∣T∣=2.
Pairwise independence ⇏ joint independence. Consider the fair coin example: H1,H2,D are pairwise independent (check all three pairs), but they are not jointly independent because P(H1∩H2∩D)=0=P(H1)P(H2)P(D)=1/8.
Renewal: Rolling a 6 Before a 7
Example 2.6 (Roll a sum of 6 before a sum of 7)
Roll two fair dice independently and repeatedly. Let E={a sum of 6 appears before a sum of 7}.
The outcomes that sum to 6 are {(1,5),(2,4),(3,3),(4,2),(5,1)}, so P(S)=5/36 where S={1st roll sums to 6}. Similarly, P(T)=6/36 where T={1st roll sums to 7}.
By the law of total probability, conditioning on the first roll:
P(E)=P(E∣S)P(S)+P(E∣T)P(T)+P(E∣(S∪T)c)P((S∪T)c).
We have P(E∣S)=1, P(E∣T)=0, and P(E∣(S∪T)c)=P(E) by the renewal/memoryless property (each roll is independent, so if neither 6 nor 7 appears, we restart). Thus
P(E)=1⋅365+0⋅366+P(E)⋅3625.
Solving: P(E)(1−25/36)=5/36, so P(E)(11/36)=5/36, giving
EECS 126 (UC Berkeley) · Spring 2026 · January 27, 2026
We transition from events to random variables — functions that assign numerical values to outcomes — and develop the key tools of expectation, linearity, LOTUS, and variance.
Random Variables and PMFs
Definition 3.1 (Random variable)
A (discrete) random variable is a function X:Ω→R that assigns a real number to each outcome ω∈Ω. We write P(X=x) for the probability of the event {ω∈Ω:X(ω)=x}.
Definition 3.2 (Probability mass function)
The probability mass function (PMF) of a discrete random variable X is the function pX:R→[0,1] defined by
pX(x)=P(X=x).
The PMF satisfies ∑x∈XpX(x)=1, where X denotes the set of all values taken by X (the support).
Example 3.1 (Functions of random variables)
Let X be a random variable with pX(x)=1/5 for x∈{−2,−1,0,1,2}. Define Y=∣X∣. Then Y takes values in {0,1,2} and
In general, if Y=g(X), then pY(y)=∑{x:g(x)=y}pX(x).
Popular Discrete Distributions
Definition 3.3 (Bernoulli distribution)
X∼Bernoulli(p): a single coin toss.
P(X=k)={1−ppk=0,k=1.
Definition 3.4 (Binomial distribution)
X∼Binomial(n,p): number of successes in n independent Bernoulli(p) trials.
P(X=k)=(kn)pk(1−p)n−k,k=0,1,…,n.
Note: ∑k=0n(kn)pk(1−p)n−k=(p+(1−p))n=1 by the binomial theorem, confirming this is a valid PMF.
Definition 3.5 (Geometric distribution)
X∼Geometric(p): number of trials until the first success.
P(X=k)=(1−p)k−1p,k=1,2,3,…
The geometric distribution is the discrete analog of “waiting time.”
Definition 3.6 (Poisson distribution)
X∼Poisson(λ): models the number of arrivals in a fixed interval.
P(X=k)=k!λke−λ,k=0,1,2,…
The Poisson is the limiting distribution of Binomial(n,λ/n) as n→∞, and arises naturally in modeling rare events and arrival processes.
Example 3.2 (Chess match – a PMF computation)*
Alice and Bob play a match: the first to win a game wins the match. If there are 10 consecutive draws, the match is declared drawn. Each game independently: P(A wins)=0.3, P(B wins)=0.4, P(draw)=0.3.
Let L be the duration (number of games). Then for ℓ=1,2,…,9:
pL(ℓ)=(0.3)ℓ−1(1−0.3)=(0.3)ℓ−1(0.7),
since the first ℓ−1 games must be draws and the ℓ-th decisive. For ℓ=10: pL(10)=(0.3)9 (all 9 games drawn, match ends).
P(Alice wins match)=∑ℓ=19(0.3)ℓ−1(0.3)=0.3∑k=08(0.3)k. Using ∑k=0∞rk=1/(1−r) for ∣r∣<1, in the limit of no cap on draws: P(Alice wins)=0.3/(1−0.3)=3/7.
Expectation
Definition 3.7 (Expected value)
The expected value (or mean) of a discrete random variable X is
E[X]=ω∈Ω∑X(ω)P({ω})=x∈X∑x⋅P(X=x),
provided the sum converges absolutely (i.e. ∑∣x∣P(X=x)<∞).
Theorem 3.1 (Linearity of expectation)
For any random variables X,Y (not necessarily independent) and constant c:
E[X+Y]=E[X]+E[Y],E[cX]=cE[X].
No independence assumption is needed. This is the single most useful property of expectation.
Definition 3.8 (Indicator random variable)
For an event A, the indicator1A is
1A(ω)={10ω∈A,ω∈/A.
Observe that 1A∼Bernoulli(P(A)), so E[1A]=P(A).
Example 3.3 (Seats on a plane)
A full flight has n passengers with assigned seats, but every passenger ignores their assignment and sits in a uniformly random seat. What is E[number who sit in their own seat]?
Let Xi=1{passenger i sits in their own seat}. Then X=X1+X2+⋯+Xn. The Xi are not independent (if n=2 and passenger 1 is in their seat, passenger 2 must be too). But linearity of expectation does not require independence:
E[X]=i=1∑nE[Xi]=i=1∑nP(passenger i is in their seat)=n⋅n1=1.
Regardless of the number of passengers, on average exactly 1 person sits in their own seat.
LOTUS (Law of the Unconscious Statistician)
Theorem 3.2 (LOTUS)
If X is a discrete random variable and g:R→R is any function, then
E[g(X)]=x∈X∑g(x)P(X=x).
More generally, for a function of several random variables:
The key step is factoring the joint PMF into marginals (by independence), which allows separating the double sum into a product of single sums.
The converse is false.E[XY]=E[X]E[Y] does not imply X⊥Y. The condition E[XY]=E[X]E[Y] is called uncorrelation, which is strictly weaker than independence. As an exercise, construct dependent random variables that are uncorrelated.
Tail Sum Formula
Theorem 3.4 (Tail sum formula)
Let X be a random variable taking values in N={0,1,2,…}. Then
The key step is writing k=∑j=1k1 to introduce a double sum, then swapping the order of summation (Tonelli’s theorem ensures this is valid for nonnegative terms). Geometrically, this corresponds to “counting vertically then horizontally”: instead of weighting each column k by its height k, we sum across rows j=1,2,…, each contributing P(X≥j).
Intuition for the tail sum. Think of E[X] as the total area under the “staircase” of the survival function P(X≥k). Each unit step at height k contributes P(X≥k) to the total. This is the same idea as computing the area under a curve by integrating horizontally rather than vertically.
Variance
Definition 3.10 (Variance and standard deviation)
The variance of X measures the spread of X around its mean:
Var(X)≜σX2≜E[(X−E[X])2].
The standard deviation is σX=Var(X).
An equivalent computational formula (often easier to use):
These are my personal notes from Professor Kannan Ramchandran’s EECS 126 (Probability and Random Processes) course at UC Berkeley.
Last lecture we defined expectation and variance for a single random variable. In this lecture we study how variance behaves for sums of random variables, which leads to covariance and the correlation coefficient. We then compute the mean and variance of the four workhorse discrete distributions (Bernoulli, binomial, geometric, Poisson), apply these to the coupon collector problem, prove the memoryless property of the geometric distribution, study how Poisson random variables merge and split, and finally introduce conditional expectation.
Variance of Sums and Covariance
Recall from Lecture 3 the two forms of the variance,
Var(X)=E[(X−E[X])2]=E[X2]−(E[X])2,
and the scaling property
Var(aX+c)=a2Var(X).
Shifts by a constant c are not recorded in variance calculations: shifting every outcome by c moves the mean by c as well, so the deviations X−E[X] are unchanged.
The natural next question is: what is the variance of a sumX+Y? Unlike the mean, the answer depends on how X and Y interact.
Theorem 4.1 (Variance of a sum)
For any random variables X,Y with finite variances,
No independence was used. The derivation above holds for anyX and Y. Independence only enters at the very end, where it makes the cross term vanish (Corollary 4.1 below).
The cross term in (4.3) is important enough to get its own name.
Definition 4.1 (Covariance)
The covariance of random variables X and Y is
Cov(X,Y)≜E[(X−E[X])(Y−E[Y])]=E[XY]−E[X]E[Y].
In particular, Cov(X,X)=Var(X). With this notation,
Var(X+Y)=Var(X)+Var(Y)+2Cov(X,Y).
Equivalence of the two forms.
Write μX=E[X] and μY=E[Y], which are constants. Expanding the product and using linearity,
Interpreting the sign.Cov(X,Y)>0 means X and Y tend to be above their means together (and below their means together). Cov(X,Y)<0 means when one is above its mean, the other tends to be below. For a sum, positive covariance inflates the spread and negative covariance dampens it.
Corollary 4.1 (Independent summands)
If X⊥Y, then Cov(X,Y)=0, and therefore
Var(X+Y)=Var(X)+Var(Y).
Proof.
In Lecture 3 we proved that X⊥Y implies E[XY]=E[X]E[Y]. Hence Cov(X,Y)=E[XY]−E[X]E[Y]=0, and the cross term in (4.3) vanishes.
Corollary 4.2 (Variance of a sum of many random variables)
For random variables X1,…,Xn with finite variances,
Var(i=1∑nXi)=i=1∑nVar(Xi)+2i<j∑Cov(Xi,Xj).
In particular, if the Xi are independent (in fact, pairwise uncorrelated is enough), then
Var(i=1∑nXi)=i=1∑nVar(Xi).
Proof.
Let μi=E[Xi]. Since E[∑iXi]=∑iμi, the centered sum is ∑i(Xi−μi). Squaring a sum gives a double sum over all pairs (i,j):
The diagonal terms i=j give Cov(Xi,Xi)=Var(Xi). The off-diagonal terms come in symmetric pairs, Cov(Xi,Xj)=Cov(Xj,Xi), so they contribute 2∑i<jCov(Xi,Xj). If every pair is uncorrelated, all off-diagonal terms are zero.
Uncorrelated does not imply independent. Covariance only detects linear dependence. For example, let X be uniform on {−1,0,1} and Y=X2. Then E[X]=0 and E[XY]=E[X3]=31(−1)+31(0)+31(1)=0, so Cov(X,Y)=0−0⋅E[Y]=0. But Y is completely determined by X: for instance P(Y=0∣X=0)=1=31=P(Y=0). This was a question Ramchandran asked us at end of previous lecture.
The Correlation Coefficient
Covariance has units (units of X times units of Y), so its size alone does not tell us how strongly two variables are related. Normalizing by the standard deviations removes the units.
Definition 4.2 (Correlation coefficient)
For random variables X,Y with Var(X)>0 and Var(Y)>0, the correlation coefficient is
ρ(X,Y)≜Var(X)Var(Y)Cov(X,Y).
Ramchandran’s vector analogy. Think of random variables as vectors, with “dot product” ⟨U,V⟩=E[UV] and “length” E[U2]. For the centered variables U=X−E[X] and V=Y−E[Y]:
the dot product is E[UV]=Cov(X,Y);
the lengths are E[U2]=Var(X) and E[V2]=Var(Y).
So ρ plays the role of cosθ=∣u∣∣v∣u⋅v, the cosine of the angle between two vectors. For ordinary vectors, the Cauchy–Schwarz inequality ∣u⋅v∣≤∣u∣∣v∣ forces −1≤cosθ≤1. The same inequality, proved for random variables below, forces −1≤ρ≤1.
Lemma 4.1 (Cauchy–Schwarz inequality for random variables)
For any random variables U,V with E[U2]<∞ and E[V2]<∞,
(E[UV])2≤E[U2]E[V2].
Proof.
Case 1: E[V2]=0. Since V2≥0 and its mean is 0, we must have V=0 with probability 1. Then UV=0 with probability 1, so E[UV]=0 and both sides equal 0.
Case 2: E[V2]>0. For every real number t, the random variable (U−tV)2 is nonnegative, so its expectation is nonnegative. Expanding with linearity:
0≤E[(U−tV)2]=E[U2]−2tE[UV]+t2E[V2].
This holds for every t, so choose the t that minimizes the right-hand side, namely t⋆=E[UV]/E[V2]. Substituting,
Multiplying both sides by E[V2]>0 gives (E[UV])2≤E[U2]E[V2].
Theorem 4.2 (Range of the correlation coefficient)
Whenever ρ(X,Y) is defined,
−1≤ρ(X,Y)≤1.
Proof.
Apply Cauchy–Schwarz to the centered variables U=X−E[X] and V=Y−E[Y]. By definition, E[UV]=Cov(X,Y), E[U2]=Var(X), and E[V2]=Var(Y), so
(Cov(X,Y))2≤Var(X)Var(Y).
Taking square roots, ∣Cov(X,Y)∣≤Var(X)Var(Y). Dividing by the (positive) right-hand side gives ∣ρ(X,Y)∣≤1.
Extreme and zero values.∣ρ∣=1 exactly when equality holds in Cauchy–Schwarz, which happens when U−t⋆V=0 with probability 1, i.e. when Y is an exact linear function Y=aX+b of X (with ρ=+1 if a>0 and ρ=−1 if a<0). At the other end, ρ=0 means uncorrelated, which, as we just saw, is weaker than independent.
Mean and Variance of Common Distributions
We now compute E[X] and Var(X) for the four distributions introduced in Lecture 3. A recurring theme: the direct sums are often messy, and a better representation of the random variable makes the computation easy.
Bernoulli
Theorem 4.3 (Bernoulli mean and variance)
If X∼Bernoulli(p), then
E[X]=p,Var(X)=p(1−p).
Proof.
X takes only the values 0 and 1, with P(X=1)=p and P(X=0)=1−p.
E[X]=1⋅P(X=1)+0⋅P(X=0)=1⋅p+0=p.
For the second moment, by LOTUS,
E[X2]=x∑x2P(X=x)=12⋅P(X=1)+02⋅P(X=0)=p.
Therefore
Var(X)=E[X2]−(E[X])2=p−p2=p(1−p).
Binomial
Theorem 4.4 (Binomial mean and variance)
If X∼Binomial(n,p), then
E[X]=np,Var(X)=np(1−p).
The direct approach is
E[X]=x=0∑nx⋅P(X=x)=x=0∑nx(xn)px(1−p)n−x,
which is doable but unpleasant. Instead, think of the binomial as a sum of n Bernoulli trials.
Proof.
Let Xi=1{trial i is a success} for i=1,…,n. Each Xi∼Bernoulli(p), the Xi are independent (the trials are independent), and the total number of successes is
X=X1+X2+⋯+Xn.
Mean. By linearity of expectation (which needs no independence),
E[X]=i=1∑nE[Xi]=i=1∑np=np.
Variance. Because the Xi are independent, Corollary 4.2 lets us add the variances:
Var(X)=i=1∑nVar(Xi)=i=1∑np(1−p)=np(1−p).
Applying direct sum gives us the same result: Using the identity x(xn)=n(x−1n−1) for x≥1 (the x=0 term is zero),
where we substituted j=x−1 and used the binomial theorem. The indicator method reaches the same answer with far less algebra.
Geometric
Recall that X∼Geometric(p) counts the number of independent trials up to and including the first success:
pX(k)=P(X=k)=(1−p)k−1p,k=1,2,3,…
Reading the PMF. Here k marks the trial on which the first Success occurs (k=S). So pX(k) is the probability that the first success happens on trial k: the first k−1 trials are failures (probability (1−p)k−1) and trial k is a success (probability p). Note that pX(k) is not the probability of k successes; a geometric random variable always records exactly one success, and k counts how long we waited for it.
Definition 4.3 (Survival function)
For an integer-valued random variable X, the survival function (or tail) is k↦P(X>k). For X∼Geometric(p),
P(X>k)=(1−p)k,k=0,1,2,…(4.27)
Proof.
The event {X>k} means “no success in the first k trials,” i.e. we tried k times and failed every time. The trials are independent and each fails with probability 1−p, so P(X>k)=k times(1−p)⋯(1−p)=(1−p)k.
Theorem 4.5 (Geometric mean)
If X∼Geometric(p) with 0<p≤1, then
E[X]=p1.
The direct sum E[X]=∑k=1∞k(1−p)k−1p requires a trick. A better method is the tail sum formula from Lecture 3, which applies because X takes values in the nonnegative integers.
Proof.
By the tail sum formula,
E[X]=k=1∑∞P(X≥k).
For integer-valued X, {X≥k}={X>k−1}. Substituting j=k−1 (so j runs from 0 to ∞),
E[X]=k=1∑∞P(X>k−1)=j=0∑∞P(X>j).
Now plug in the survival function (4.27):
E[X]=j=0∑∞(1−p)j.
This is a geometric series ∑j≥0xj with ratio x=1−p. Since 0<p≤1 we have ∣x∣<1, so the series converges to 1/(1−x):
E[X]=1−(1−p)1=p1.
Exam note: tail sum formula will be on exam. For a random variable X taking values in {0,1,2,…},
E[X]=k=1∑∞P(X≥k)=k=0∑∞P(X>k).
It expresses the mean as the sum of the tail probabilities. It follows from writing X=∑k=1∞1{X≥k} and taking expectations of both sides.
The direct sum, for comparison. Differentiating the geometric series ∑k≥0xk=1−x1 term by term (valid for ∣x∣<1) gives ∑k≥1kxk−1=(1−x)21. With x=1−p,
E[X]=pk=1∑∞k(1−p)k−1=p⋅(1−(1−p))21=p⋅p21=p1.
The variance of the geometric is derived in Section 4.5, using the memoryless property.
Poisson
Theorem 4.6 (Poisson mean and variance)
If X∼Poisson(λ), so that pX(k)=k!e−λλk for k=0,1,2,…, then
E[X]=λ,Var(X)=λ.
Both computations rely on the Taylor series of the exponential,
ex=i=0∑∞i!xi=1+x+2!x2+3!x3+⋯,(4.36)
and on the cancellation k!k=(k−1)!1 for k≥1.
Proof of the mean.E[X]=k=0∑∞k⋅k!e−λλk=k=1∑∞k⋅k!e−λλk=k=1∑∞(k−1)!e−λλk=λe−λk=1∑∞(k−1)!λk−1=λe−λj=0∑∞j!λj=λe−λeλ=λ.(the k=0 term is 0)(cancel k against k!)(factor out λe−λ)(substitute j=k−1)(Taylor series (4.36))
For the variance, computing E[X2]=∑k2k!e−λλk directly is awkward because k2 does not cancel cleanly against k!. The fix is the factorial moment trick: since X2=X(X−1)+X, linearity gives
E[X2]=E[X(X−1)]+E[X],(4.37)
and k(k−1) cancels against k! just as k did.
Proof of the variance.
Step 1: the factorial moment.
E[X(X−1)]=k=0∑∞k(k−1)k!e−λλk=k=2∑∞k(k−1)k!e−λλk=k=2∑∞(k−2)!e−λλk=e−λλ2k=2∑∞(k−2)!λk−2=e−λλ2eλ=λ2.(the k=0,1 terms are 0)(cancel k(k−1) against k!)(factor out e−λλ2)(same trick: substitute j=k−2)
Step 2: the second moment. By (4.37),
E[X2]=E[X(X−1)]+E[X]=λ2+λ.
Step 3: the variance.
Var(X)=E[X2]−(E[X])2=(λ2+λ)−(λ)2=λ.
Mean equals variance (Poisson distribution). The Poisson is the only one of our four distributions whose mean and variance are equal. This is consistent with the Poisson being the limit of Binomial(n,λ/n): the binomial variance is n⋅nλ(1−nλ)=λ(1−nλ)→λ as n→∞.
The Coupon Collector Problem
Example 4.1 (Coupon collector)
There are N different coupons you want to collect, found inside cereal boxes. Each box contains exactly one coupon, whose type is uniformly random among the N types and independent of all other boxes. You buy boxes until you have received all N distinct coupons. What is the expected number of boxes you must buy?
Let T be the total time (number of boxes) to collect all N coupons. Break the process into N stages. For i=1,…,N, let
Ti=# of boxes bought to obtain the i-th new coupon,
counting from right after the (i−1)-th new coupon was obtained. Then the total time is the sum of the stage times,
T=i=1∑NTi.
Each stage is geometric. During stage i we already hold i−1 distinct coupons, so N−(i−1)=N−i+1 types would be new. Each box is independently a “success” (a new type) with probability
pi=NN−i+1,soTi∼Geometric(NN−i+1).
i=1: T1∼Geometric(NN−1+1)=Geometric(1), so T1=1. The first box always gives a new coupon.
i=2: T2∼Geometric(NN−2+1)=Geometric(NN−1).
i=N: TN∼Geometric(N1). The last coupon is the hardest to find.
Expected total. Since E[Ti]=1/pi=N−i+1N, linearity of expectation gives
E[T]=E[i=1∑NTi]=i=1∑NE[Ti]=i=1∑NN−i+1N.
Write out the terms, from i=1 (denominator N) to i=N (denominator 1):
where we substituted j=N−i+1 (as i runs from 1 to N, j runs from N down to 1). The sum is the N-th harmonic numberHN=∑j=1Nj1, so
E[T]=NHN.
Lemma 4.2 (Size of the harmonic numbers)
For every N≥1,
ln(N+1)≤HN≤1+lnN,
and more precisely HN=lnN+γ+o(1), where γ≈0.5772 is the Euler–Mascheroni constant.
Proof of the bounds.
Compare each term 1/j with the area under the curve 1/x. Since 1/x is decreasing, on the interval [j,j+1] we have 1/x≤1/j, and on [j−1,j] we have 1/x≥1/j. Hence
∫jj+1xdx≤j1≤∫j−1jxdx(j≥2 for the right inequality).
Summing the left inequality over j=1,…,N gives HN≥∫1N+1xdx=ln(N+1). Summing the right inequality over j=2,…,N and adding the j=1 term gives HN≤1+∫1Nxdx=1+lnN. (The sharper statement with γ is a classical result we take as given.)
Corollary 4.3 (Coupon collector asymptotics)
E[T]=NHN≈NlnN+γN≈NlnN.
So we need to buy about a factor of lnN more boxes than the N coupons we are trying to collect.
Numbers and intuition. For N=50, H50≈4.499, so E[T]≈225 boxes, about 4.5× the number of coupon types. Most of the cost comes at the end: the final coupon alone takes E[TN]=N boxes on average, while the entire first half of the collection takes fewer than N boxes in total (∑i≤N/2N−i+1N≤2N⋅2=N). This NlnN behavior shows up whenever we need to “hit every bin” by random sampling: hashing, load balancing, and covering every node in a network.
The Memoryless Property
Theorem 4.7 (Memoryless property of the geometric)
Let X∼Geometric(p) with 0<p<1. For all integers s,t≥0,
P(X>s+t∣X>s)=P(X>t).
In words: given that we have already failed s times, the probability of failing t more times is the same as if we were starting over from scratch.
Proof.
First note that P(X>s)=(1−p)s>0, so the conditional probability is well defined. By the definition of conditional probability,
P(X>s+t∣X>s)=P(X>s)P({X>s+t}∩{X>s}).
Since s+t≥s, the event {X>s+t} is contained in {X>s} (if we have s+t failures, we certainly have s failures), so the intersection is just {X>s+t}:
P(X>s+t∣X>s)=P(X>s)P(X>s+t).
Both numerator and denominator are values of the geometric survival function (4.27):
P(X>s)P(X>s+t)=(1−p)s(1−p)s+t=(1−p)t,
which is exactly the survival function of the geometric evaluated at t, i.e. P(X>t).
Two remarks on memorylessness.
The remaining wait is again geometric. Given X>s, the number of additional trials X−s has the same distribution as X: for k≥1,
P(X−s=k∣X>s)=P(X>s)P(X=s+k)=(1−p)s(1−p)s+k−1p=(1−p)k−1p.
This is the form we use in the derivations below.
Uniqueness. The geometric is the only memoryless distribution on {1,2,3,…}. Its continuous analog, the exponential distribution, will be the only memoryless continuous distribution.
To use memorylessness to recompute E[X], we need to split an expectation according to which of several events occurred. This is the expectation version of the law of total probability from Lecture 2.
Theorem 4.8 (Total expectation theorem)
Let A1,…,An be a partition of Ω with P(Ai)>0 for each i, and define the conditional expectation given an event, E[X∣Ai]=∑xxP(X=x∣Ai). Then
E[X]=i=1∑nP(Ai)E[X∣Ai].
Proof.
For each value x, the law of total probability gives P(X=x)=∑iP(Ai)P(X=x∣Ai). Substituting into the definition of expectation and swapping the order of summation (justified by absolute convergence),
Let X∼Geometric(p). Condition on the outcome of the first trial, using the partition {X=1} (first trial succeeds) and {X>1} (first trial fails):
E[X]=P(X=1)E[X∣X=1]+P(X>1)E[X∣X>1].
P(X=1)=p (success on the first try), and then X=1 exactly, so E[X∣X=1]=1.
P(X>1)=1−p. If the first trial failed, the geometric “tells us we start again”: by memorylessness the remaining wait X−1 is again Geometric(p), and we have already spent one trial. So
E[X∣X>1]=E[(X−1)+1∣X>1]=E[X]+1.
Subtracting E[X] from both sides gives 0=1−pE[X], i.e. pE[X]=1, so
E[X]=p1,
matching the tail sum computation.
Two checks on this argument.
Finiteness. Subtracting E[X] from both sides is only legitimate because E[X]<∞, which we already know from the tail sum. (If E[X]=∞, the equation ∞=∞+1−∞ says nothing.)
Sanity check the answer. Any correct formula must satisfy E[X]≥1 (you need at least one trial) and E[X]→∞ as p→0. A sign slip in the algebra can produce E[X]=1+p1, which fails both tests, since it is less than 1 for every p>0.
Theorem 4.9 (Geometric variance (supplementary))
If X∼Geometric(p), then
Var(X)=p21−p.
Proof.
We use the same first-trial conditioning, now on E[X2] (which is finite, since the tail of X decays geometrically).
E[X2]=P(X=1)E[X2∣X=1]+P(X>1)E[X2∣X>1].
Given X=1: X2=1, so E[X2∣X=1]=1.
Given X>1: by memorylessness, X=1+X′ where X′∼Geometric(p) has the same distribution as X. Expanding the square,
E[X2∣X>1]=E[(1+X′)2]=1+2E[X′]+E[X′2]=1+2E[X]+E[X2].
so E[X2]=E[X(X−1)]+E[X]=p22(1−p)+p2p=p22−p, in agreement.
Poisson Merging and Splitting
Poisson random variables model counts of arrivals (packets at a router, calls at a switchboard, customers at a queue). Two structural facts make them especially convenient: independent Poisson counts merge into a Poisson count, and randomly splitting a Poisson count produces independent Poisson counts.
Theorem 4.10 (Poisson merging (sum of independent Poissons))
Let X∼Poisson(λ) and Y∼Poisson(μ) be independent. Then
X+Y∼Poisson(λ+μ),
with mean E[X+Y]=λ+μ.
Proof (supplementary).
Fix n∈{0,1,2,…}. Since X,Y≥0, the event {X+Y=n} splits into the disjoint events {X=k,Y=n−k} for k=0,…,n:
P(X+Y=n)=k=0∑nP(X=k,Y=n−k)=k=0∑nP(X=k)P(Y=n−k)=k=0∑nk!e−λλk⋅(n−k)!e−μμn−k=e−(λ+μ)k=0∑nk!(n−k)!λkμn−k=n!e−(λ+μ)k=0∑nk!(n−k)!n!λkμn−k=n!e−(λ+μ)k=0∑n(kn)λkμn−k=n!e−(λ+μ)(λ+μ)n.(independence)(Poisson PMFs)(collect exponentials)(multiply and divide by n!)(binomial theorem)
This is exactly the Poisson(λ+μ) PMF evaluated at n. The mean λ+μ also follows directly from linearity of expectation.
Corollary 4.4 (Many independent Poissons)
If X1,…,Xm are independent with Xi∼Poisson(λi), then ∑i=1mXi∼Poisson(∑i=1mλi). (Apply the theorem repeatedly; X1+⋯+Xk is independent of Xk+1.)
Networking picture: merging. Two independent packet streams feed a router through separate buffers. If the numbers of packets arriving in each buffer during an interval are Poisson(λ) and Poisson(μ), the number of packets in the merged output buffer is Poisson(λ+μ).
Splitting is the reverse operation: each arriving packet is routed to one of two outputs by an independent coin flip. Given the total count X=n, the number Y sent to the first output is the number of successes in n independent Bernoulli(p) trials. This is a “binomial with a random number of trials.”
Theorem 4.11 (Poisson splitting)
Let X∼Poisson(λ), and suppose that, conditioned on X=n, the random variable Y satisfies
Y∣X=n∼Binomial(n,p).
Let Z=X−Y be the remainder. Then
Y∼Poisson(λp),Z∼Poisson(λ(1−p)),andY⊥Z.
Proof (supplementary).
We compute the joint PMF of (Y,Z) and show that it factors. Fix integers a,b≥0. The event {Y=a,Z=b} is the same as {X=a+b,Y=a} (the total is a+b, of which a went to the first output). By the chain rule,
P(Y=a,Z=b)=P(X=a+b)P(Y=a∣X=a+b)=(a+b)!e−λλa+b⋅(aa+b)pa(1−p)b=(a+b)!e−λλa+b⋅a!b!(a+b)!pa(1−p)b=e−λa!λapa⋅b!λb(1−p)b=Poisson(λp) PMF at aa!e−λp(λp)a⋅Poisson(λ(1−p)) PMF at bb!e−λ(1−p)(λ(1−p))b,(Poisson, then binomial)(expand the binomial coefficient)(cancel (a+b)!, split λa+b)(split e−λ=e−λpe−λ(1−p))
Marginal of Y. Sum over b≥0. The second factor is a PMF in b, so it sums to 1, leaving P(Y=a)=a!e−λp(λp)a. Thus Y∼Poisson(λp). Summing over a instead shows Z∼Poisson(λ(1−p)).
Independence. The joint PMF equals the product of the two marginals for every (a,b), which is the definition of Y⊥Z.
Why the independence is surprising. If the total X were a fixed number n, then Y and Z=n−Y would be perfectly (negatively) dependent: learning Y would tell you Z exactly. It is the randomness of the total count that makes the two outputs independent. A large value of Y suggests X was large, which exactly offsets what it would otherwise say about Z. This is special to the Poisson.
Conditional PMFs and Conditional Expectation
Definition 4.4 (Conditional PMF)
Let X,Y be discrete random variables and let y satisfy pY(y)>0. The conditional PMF of X given Y=y is
pX∣Y(x∣y)≜P(X=x∣Y=y)=pY(y)pX,Y(x,y).
It is a genuine PMF in x. For each fixed y with pY(y)>0:
pX∣Y(x∣y)≥0, since it is a ratio of a probability and a positive number;
it sums to one over x, by marginalizing the joint PMF:
x∑pX∣Y(x∣y)=pY(y)1x∑pX,Y(x,y)=pY(y)pY(y)=1.
So for each fixed value y, “X given Y=y” is just another random variable with its own distribution, and we can take its expectation. (Note that the fraction is pX,Y(x,y)/pY(y), a ratio of PMF values, rather than P(X∩Y)/P(Y), since X and Y are random variables rather than events.)
Definition 4.5 (Conditional expectation given Y=y)
For y with pY(y)>0, the conditional expectation of X given Y=y is
E[X∣Y=y]≜x∑x⋅pX∣Y(x∣y)=x∑x⋅P(X=x∣Y=y).(4.74)
Like any expectation, E[X∣Y=y] is just a real number.
By “sweeping” through the values of y in (4.74), we get a (possibly different) number E[X∣Y=y] for every value y. That is, y↦E[X∣Y=y] is a function of y.
Definition 4.6 (Conditional expectation as a random variable)
Define g(y)=E[X∣Y=y]. The conditional expectation of X given Y is the random variable
E[X∣Y]≜g(Y).
It is a function of Y, and therefore E[X∣Y] is itself a random variable: it takes the value g(y) with probability pY(y).
Notation: E[X∣Y=y] versus E[X∣Y]. These are different objects. E[X∣Y=y] (lowercase y, a specific value) is a number. E[X∣Y] (capital Y) is a random variable.
Example 4.3 (Die roll, conditioned on parity)
Roll a fair six-sided die. Let X be the result and Y=1{X is even}.
Given Y=1, X is uniform on {2,4,6}, so E[X∣Y=1]=32+4+6=4. Given Y=0, X is uniform on {1,3,5}, so E[X∣Y=0]=31+3+5=3. Hence
E[X∣Y]=g(Y)={43if Y=1,if Y=0,i.e.E[X∣Y]=3+Y.
This is a random variable taking the values 3 and 4, each with probability 21. Notice that its mean is 21(3)+21(4)=3.5=E[X]. That is no coincidence, as the next lecture will show.
Law of Iterated Expectation (Tower Rule): TBD next lecture. This was on today’s agenda but was not reached in lecture. It states that E[E[X∣Y]]=E[X]; the total expectation theorem of Section 4.5 is a special case.
EECS 126 (UC Berkeley) · Spring 2026 · February 3, 2026
Reading: Bertsekas & Tsitsiklis, §4.2–4.3; Ch. 3.
These are my personal notes from Professor Kannan Ramchandran’s EECS 126 (Probability and Random Processes) course at UC Berkeley.
We open with a famous game whose expected payout is infinite. We then finish the story of conditional expectation from Lecture 4: the law of iterated expectation (the tower rule), which we use to analyze a random walk, and its companion for variances, the law of total variance. The second half of the lecture moves from discrete to continuous random variables, introducing probability density functions (PDFs) and cumulative distribution functions (CDFs).
The St. Petersburg Paradox
Example 5.1 (St. Petersburg game)
I toss a fair coin until I get a heads. If I toss n times, I give you $2n. For example,
H↦$2,TH↦$4,TTH↦$8,…
Question: how much would you pay to play this game?
Let N be the number of tosses in the game and W=2N the amount of money you win. The game ends on the first heads, so N∼Geometric(21):
P(N=n)=n flips21⋅21⋯21=2−n,n=1,2,3,…
(The first n−1 flips are tails and the n-th is heads; each has probability 21.) By LOTUS,
E[W]=n=1∑∞2n⋅P(N=n)=n=1∑∞2n⋅2n1=n=1∑∞1=∞.
The expected payout is infinite. This is the St. Petersburg paradox.
Why is it a paradox? If expected value were the whole story, you should be willing to pay any finite price to play. Yet almost nobody would pay more than a few dollars: half the time the game pays $2, and P(W≤$8)=87. The infinite mean is driven entirely by astronomically rare, astronomically large payouts (each outcome n contributes exactly $1 to the mean). Two standard resolutions:
Diminishing utility. Daniel Bernoulli argued that the value of money grows more slowly than the amount, e.g. logarithmically. The expected log-payout is finite: E[log2W]=E[N]=2 (the geometric mean from Lecture 4), which corresponds to a “fair price” of about 22=$4.
Finite bankroll. No casino can pay more than some $2M. If payouts are capped at 2M, then
E[W]=n=1∑M2n2−n+n=M+1∑∞2M2−n=M+2M⋅2−M=M+1.
Even a billion-dollar bankroll (230≈1.07×109) gives an expected payout of only $31.
Conditional Expectation as a Random Variable
Recall from Lecture 4 that for each value y with P(Y=y)>0,
E[X∣Y=y]=x∑x⋅P(X=x∣Y=y)
is a number. Letting g(y)=E[X∣Y=y], the conditional expectation E[X∣Y]≜g(Y) is a function of Y, and therefore E[X∣Y] is a random variable.
Example 5.2 (Tossing a fair coin a random number of times)
We toss a fair coin N times, where N is itself a random variable taking values in {1,2,3,…}. Let X be the total number of heads. Given N=n, the n tosses are independent fair Bernoulli trials, so X∣N=n∼Binomial(n,21).
N=1: one toss gives 0 or 1 heads, each with probability 21:
E[X∣N=1]=0⋅21+1⋅21=21(a number).
N=2: two tosses give 0, 1, or 2 heads, with probabilities 41 (TT), 21 (HT or TH), and 41 (HH):
E[X∣N=2]=0⋅41+1⋅21+2⋅41=1(a number).
General N=n: by the binomial mean from Lecture 4,
E[X∣N=n]=n⋅21=2n(a number).
Sweeping over all values n and replacing n by the random variable N,
r.v.E[X∣N]=r.v.2N.(5.9)
This is an equality of random variables: for every outcome of the experiment, the two sides take the same value.
The outcomes are not equally likely. For N=2, averaging the possible head counts as 30+1+2=1 happens to give the right answer, but only by coincidence: the three outcomes have probabilities 41,21,41, not 31 each. For N=3 the same shortcut would still give 23 by symmetry, but for a biased coin it fails immediately. Always weight by the conditional PMF.
The Law of Iterated Expectation (Tower Property)
Since E[X∣Y] is a random variable, we can take its expectation. The answer is remarkably simple.
Theorem 5.1 (Law of iterated expectation)
For random variables X,Y with E[∣X∣]<∞,
E[E[X∣Y]]=E[X].
The inner expectation is over X (with Y held fixed); the outer expectation is over Y.
Proof.
Write E[X∣Y]=g(Y) with g(y)=E[X∣Y=y]. The outer expectation is the expectation of a function of Y, so by LOTUS (summing over the values y with P(Y=y)>0):
E[E[X∣Y]]=y∑E[X∣Y=y]⋅P(Y=y)=y∑x∑x⋅P(X=x∣Y=y)⋅P(Y=y)=y∑x∑x⋅P(X=x,Y=y)=x∑xy∑P(X=x,Y=y)=x∑x⋅P(X=x)=E[X].(outer expectation, LOTUS)(definition of E[X∣Y=y])(definition of conditional probability)(swap the order of summation)(marginalize out Y)
The third line uses P(X=x∣Y=y)P(Y=y)=P(X=x,Y=y), i.e. pX∣Y(x∣y)pY(y)=pX,Y(x,y). Swapping the sums is justified by E[∣X∣]<∞ (absolute convergence).
Intuition: an average of averages.E[X∣Y=y] is the average of X within the “group” where Y=y. The tower rule says: average these group averages, weighting each group by how likely it is, and you recover the overall average. The total expectation theorem from Lecture 4, E[X]=∑iP(Ai)E[X∣Ai], is the special case where Y records which event Ai of a partition occurred.
A useful companion result lets us pull functions of Y through the inner expectation: once we condition on Y, any function of Y is a known constant.
Theorem 5.2 (Taking out what is known)
For any function f with E[∣f(Y)X∣]<∞,
E[f(Y)X∣Y]=f(Y)E[X∣Y],
and consequently
E[f(Y)X]=E[f(Y)E[X∣Y]].(5.13)
Proof.
Fix y with P(Y=y)>0. Given Y=y, the random variable f(Y) equals the constant f(y), so it factors out of the conditional expectation:
Replacing y by Y gives E[f(Y)X∣Y]=f(Y)E[X∣Y]. Now apply the tower rule to the random variable f(Y)X:
E[f(Y)X]=E[E[f(Y)X∣Y]]=E[f(Y)E[X∣Y]].
Where the brackets go. In (5.13), f(Y) stays inside the outer expectation, multiplied by the random variable E[X∣Y]. It is not true in general that E[f(Y)X]=E[f(Y)]⋅E[X∣Y]; the right-hand side of that would not even be a number. For instance, with f(Y)=Y2: E[Y2X]=E[Y2E[X∣Y]].
Example 5.3 (Random number of tosses, with N∼Geometric(p))
Suppose in Example 5.2 that N is generated by a first coin with heads probability p, tossed until its first heads, so that N∼Geometric(p). We then toss a second, fair coin N times and let X be the number of heads. From (5.9), E[X∣N]=2N=21⋅N.
Mean. By the tower rule, linearity, and E[N]=p1 for N∼Geometric(p) (Lecture 4),
E[X]=E[E[X∣N]]=E[2N]=21E[N]=21⋅p1=2p1.
Sanity check: if p=1, then N=1 always, and one fair toss gives E[X]=21. ✓
A mixed moment. Taking out what is known with f(N)=N, and using E[N2]=p22−p from Lecture 4,
E[NX]=E[NE[X∣N]]=E[N⋅2N]=21E[N2]=2p22−p.
The Symmetric Random Walk
Example 5.4 (Random walk on the integers)
A drunk man is walking along the integer line. He starts at the origin, X0=0. At each step, independently of everything before, he moves one unit right with probability 21 or one unit left with probability 21. Let Xn be his location after n steps.
Questions: What is E[Xn]? What is E[Xn2], and how far from the origin is he typically?
Write the (n+1)-th step using two indicator random variables,
1+(n+1)={10if step n+1 is +1,otherwise,1−(n+1)={10if step n+1 is −1,otherwise.
Exactly one of them equals 1, so the step is 1+(n+1)−1−(n+1)∈{+1,−1}, and
Xn+1=Xn+1+(n+1)−1−(n+1).(5.19)
Notation. An indicator only takes the values 0 and 1, so a step of −1 is written by subtracting the indicator 1−(n+1). The superscript (n+1) records that each step is a fresh, independent coin flip. Similarly, the location Xn and the step taken at time n are different random variables, so we keep separate names for them.
The mean: 𝔼[Xₙ] = 0 for all n
Take expectations in (5.19). By linearity, and since E[1±(n+1)]=P(step is ±1)=21,
By induction on n. Base case:X0=0 is a constant, so E[X0]=0. Inductive step: suppose E[Xn]=0. By (5.20), E[Xn+1]=E[Xn]=0. Unrolled, this is just a chain of equalities:
E[Xn]=E[Xn−1]=E[Xn−2]=⋯=E[X1]=E[X0]=0.
Two more ways to see it.
Sum of steps. Let ξi∈{+1,−1} be the i-th step, so Xn=ξ1+ξ2+⋯+ξn. Each step has mean E[ξi]=(+1)⋅21+(−1)⋅21=0, and by linearity E[Xn]=∑i=1nE[ξi]=0.
Symmetry. Flipping the direction of every step turns the walk Xn into −Xn, and since left and right are equally likely, the flipped walk has exactly the same distribution. So E[Xn]=E[−Xn]=−E[Xn], which forces E[Xn]=0.
A zero mean does not mean the walker stays near the origin. He drifts away, but is equally likely to drift left or right, so the drifts cancel in the average. To measure how far he wanders, we need the second moment.
The second moment: 𝔼[Xₙ²] = n
Suppose Xn=k. The next step is ±1 with probability 21 each, independent of the past, so
The edge case k=0. When k=0, (k+1)2=(k−1)2=1, so the two events above are the same event, which has probability 1 (not 21). The computation of E[Xn+12∣Xn=0] is still correct, because we are really averaging over the two moves: 21⋅1+21⋅1=1=02+1.
We found g(k)=E[Xn+12∣Xn=k]=k2+1. Replacing the value k by the random variable Xn (the “pattern matching” step, exactly as in E[X∣N]=N/2):
E[Xn+12∣Xn]=Xn2+1.
By the law of iterated expectation,
E[Xn+12]=E[E[Xn+12∣Xn]]=E[Xn2+1]=1+E[Xn2].(law of iterated expectation)(linearity)
Each step adds exactly 1 to the second moment, starting from E[X02]=0:
E[X02]=0,E[X12]=1,E[X22]=2,…⟹E[Xn2]=n,
(formally, by induction exactly as for the mean). In particular E[Xn+12]=1+n.
Theorem 5.4 (Spread of the symmetric random walk)
For every n≥0,
Var(Xn)=E[Xn2]−(E[Xn])2=n−02=n,soσXn=n.
Cross-check with Lecture 4. With Xn=ξ1+⋯+ξn and independent steps, each step has Var(ξi)=E[ξi2]−02=1 (since ξi2=1 always). The variance of a sum of independent random variables is the sum of the variances, so Var(Xn)=n. Same answer, no conditioning needed.
Key takeaway. The walker’s expected position is 0 forever, but his typical distance from the origin is n: after 10,000 steps he is typically about 100 units away. This n growth is the signature of diffusion, and it reappears throughout the course.
Conditional Variance and the Law of Total Variance
Definition 5.1 (Conditional variance)
For y with P(Y=y)>0, the conditional variance of X given Y=y is the variance of the conditional distribution of X:
Interpretation: within-group plus between-group. Group the outcomes by the value of Y. Then E[Var(X∣Y)] is the average spread within each group, and Var(E[X∣Y]) is the spread between the group means. Total spread is the sum of the two. Since both terms are nonnegative, Var(X)≥E[Var(X∣Y)]: on average, learning Y can only reduce our uncertainty about X.
Example 5.5 (Variance of heads in a random number of tosses)
Continue the example with N∼Geometric(p) and X∣N∼Binomial(N,21). From the binomial formulas of Lecture 4,
Sanity check: if p=1, then N=1 and X∼Bernoulli(21), whose variance is 21⋅21=41. ✓
Continuous Random Variables
Continuous random variables (CRVs) let us measure uncertainty in a principled way for quantities that vary continuously, such as velocity, time, and distance.
Coming up. Important continuous distributions include the uniform, exponential, and gamma distributions, which we develop in upcoming lectures. The exponential is the continuous analog of the geometric (Lecture 4).
Why discrete tools break. Let X∼Uniform[0,1], a number chosen “uniformly at random” from [0,1]. Then:
P(X=x)=0 for any specific number x (there are uncountably many equally likely candidates);
yet P(X<21)=21.
So we cannot build probabilities by adding up point masses as we did with PMFs. Instead, we assign probabilities directly to sets that are “allowable events.”
Definition 5.2 (Allowable events (Borel sets))
The allowable events for a real-valued random variable include all intervals,
(−∞,a),[a,b],(a,b],…
together with everything obtainable from intervals by countable unions, countable intersections, and complements, e.g. (a,b)∪(c,d). These are the Borel sets; they form the Borel σ-algebra from Lecture 1. In practice, any “reasonable” set is allowable.
Recall that for a discrete random variable (DRV) and a set of values B,
P(X∈B)=x∈B∑pX(x).
For a CRV, the sum over points becomes an integral of a density.
Definition 5.3 (Continuous random variable and PDF)
A random variable X is continuous if there is a function fX:R→[0,∞), called its probability density function (PDF), such that for every allowable set B,
P(X∈B)=∫BfX(x)dx.
A density must satisfy
fX(x)≥0 for all x,and∫−∞∞fX(x)dx=1.
In particular, P(a≤X≤b)=∫abfX(x)dx is the area under the density between a and b.
Theorem 5.6 (Single points have probability zero)
If X is continuous, then P(X=x)=0 for every x∈R.
Proof.
Fix x and any δ>0. The event {X=x} is contained in {x≤X<x+δ}, so
P(X=x)≤P(x≤X<x+δ)=∫xx+δfX(u)du.
(We use the dummy variable u inside the integral so as not to confuse it with x, which now appears in the limits.) As δ→0, this is the integral of fX over a shrinking interval, which tends to 0. If fX is continuous at x, we can see this explicitly: the sliver is approximately a rectangle of height fX(x) and width δ, so the integral is ≈fX(x)δ→0. Since P(X=x) is smaller than a quantity that can be made arbitrarily small, P(X=x)=0.
A density is not a probability.fX(x) has units of probability per unit length. Wherever fX is continuous,
fX(x)=δ→0limδP(x≤X<x+δ),i.e.P(x≤X<x+δ)≈fX(x)δ for small δ.
Don’t confuse fX(x) with a probability: it is a density. Only areas under fX are probabilities, so fX(x) itself may exceed 1, as the next example shows.
Example 5.6 (An unbounded density)
Let
fX(x)=⎩⎨⎧2x100<x≤1,otherwise.
It is a valid PDF. Clearly fX≥0. For the total area, write 2x1=21x−1/2 and integrate:
It exceeds 1, and is even unbounded.fX(1)=21, but fX(0.01)=2(0.1)1=5, and fX(x)→∞ as x→0+. Nevertheless every probability is finite, e.g. P(X≤0.01)=∫00.0121x−1/2dx=0.01=0.1.
The Cumulative Distribution Function
Definition 5.4 (Cumulative distribution function (CDF))
The cumulative distribution function of any random variable X (discrete or continuous) is
FX(x)≜P(X≤x),x∈R.
For a continuous random variable,
FX(x)=∫−∞xfX(u)du.
Theorem 5.7 (Properties of the CDF)
Every CDF satisfies:
Nondecreasing: if x≤y then FX(x)≤FX(y), since {X≤x}⊆{X≤y}.
Limits:x→−∞limFX(x)=0 and x→+∞limFX(x)=1.
Intervals:P(a<X≤b)=FX(b)−FX(a), because {X≤b} is the disjoint union of {X≤a} and {a<X≤b}.
Theorem 5.8 (Recovering the PMF or PDF from the CDF)
CRV: wherever fX is continuous,
fX(x)=dxdFX(x).
Integer-valued DRV: for every integer k,
P(X=k)=FX(k)−FX(k−1).
Proof.
CRV:FX(x)=∫−∞xfX(u)du, so this is the fundamental theorem of calculus. DRV: because X only takes integer values, there are no possible values strictly between k−1 and k. So {X≤k} is the disjoint union of {X≤k−1} and {X=k}, giving FX(k)=FX(k−1)+P(X=k). (For a discrete random variable taking non-integer values, use the jump of FX at the value instead.)
Picturing the two kinds of CDF. For an integer-valued DRV, FX is a staircase. On each open interval (k−1,k) there are no possible values, so no new probability accumulates and FX stays flat, holding the value FX(k−1). It does not drop back to zero: all the probability collected up through k−1 is still counted. At k itself, FX jumps up by exactly P(X=k). For a CRV, single points carry no probability, so FX rises continuously with no jumps.
Corollary 5.1 (Consequences for continuous random variables)
Because points do not contribute, it does not matter whether the endpoints of an interval are included: P(a<X<b)=P(a≤X<b)=P(a<X≤b)=P(a≤X≤b). This is false for discrete random variables, where P(X<k) and P(X≤k) differ by P(X=k).
Example: A Random Dart on a Disk
Example 5.7 (Random dart on the unit disk)
A dart lands uniformly at random on a disk of radius 1 (the unit circle and its interior). “Uniformly” means the probability of landing in any region is proportional to its area:
P(dart lands in region R)=Area of full diskArea(R)=π(1)2Area(R).
Let Y be the dart’s distance from the center. Find the PDF fY(y).
It is easiest to compute FY(y)=P(Y≤y) first. For 0≤y≤1, the event {Y≤y} means the dart lands in the shaded disk of radius y:
FY(y)=P(Y≤y)=Area full diskArea shaded=π(1)2πy2=y2.
Outside [0,1]: FY(y)=0 for y<0 (distance is never negative) and FY(y)=1 for y>1 (the dart is always on the disk).
Differentiating,
fY(y)=dydFY(y)=dyd(y2)=2y,0≤y≤1,
and fY(y)=0 otherwise. Check: ∫012ydy=[y2]01=1. ✓
Or, equivalently, by the PDF: ∫0.50.62ydy=[y2]0.50.6=0.11.
Three traps in this example.
Y is not uniform on [0,1]. The dart’s position is uniform on the disk, but its distance from the center is not: the density 2y grows with y, because there is more area at larger radii. The ring 0.5<Y<0.6 has probability 0.11, while the same-width band 0<Y<0.1 near the center has only 0.12=0.01.
Don’t stop at the CDF.y2 is FY, not fY; the PDF requires the extra differentiation step.
πr21 is a 2-D density. The constant πr21 (here π1) is the density of the dart’s position per unit area. It is not fY, which is a density per unit length along the radius.
The CDF method. This “CDF first, then differentiate” strategy is the standard way to find the density of a function of a random variable.
Example: Meeting at Random Times
Not finished in lecture. We ran out of time after posing this problem. The full solution is given below.
Example 5.8 (Will A and B meet?)
A and B each arrive at a meeting spot at a uniformly random time between 4:00 pm and 5:00 pm, independently of each other. Whoever arrives first waits 10 minutes and then leaves. What is P(A and B meet)?
Setup. Measure time in minutes after 4:00 pm, so A and B are independent Uniform[0,60] random variables. The pair (A,B) is a point in the 60×60 square [0,60]2. Because A and B are independent and each uniform, the point (A,B) is uniform on the square:
P((A,B)∈R)=60×60Area(R)=3600Area(R).
(Joint distributions of several continuous random variables are developed formally in upcoming lectures; this “probability = area fraction” rule is the two-dimensional version of the uniform distribution, exactly as in the dart example.)
When do they meet? Whoever arrives first waits 10 minutes, so they meet exactly when their arrival times differ by at most 10 minutes:
{A and B meet}={∣A−B∣≤10}.
This is the shaded diagonal band in the figure below.
Compute the complement. The two blue corner regions, where they miss each other, are right triangles:
{A−B>10}: A arrives more than 10 minutes after B, so B has already left. The triangle has vertices (10,0),(60,0),(60,50) and legs of length 50.
{B−A>10}: the mirror image, with vertices (0,10),(0,60),(50,60), also with legs of length 50.
Each triangle has area 21⋅50⋅50=1250, so together they cover 2500 out of 3600:
P(miss)=36002⋅1250=36002500=3625.
Therefore
P(A and B meet)=1−3625=3611≈0.306.
Equivalently, the band has area 3600−2500=1100, and 36001100=3611.
Checks and generalization.
Boundaries don’t matter. The lines ∣A−B∣=10 have zero area, so it makes no difference whether “waits 10 minutes” includes the endpoint. This is the two-dimensional version of P(X<a)=P(X≤a).
General formula. With a window of length T and waiting time w≤T, the same picture gives
P(meet)=1−(1−Tw)2.
With w=10, T=60: 1−(5/6)2=11/36. Sanity checks: w=0 gives 0 (they must arrive at the exact same instant), and w=T gives 1.
The Leibniz rule (differentiation under the integral sign) justifies moving dαd outside the integral. Finally,
Var(Z)=E[Z2]−(E[Z])2=1−02=1.
Why only α=1? I was confused why we set α=1, and whether it could be something else. The identity I(α)=α−1/2 holds for everyα>0, so I is a function of α that we can differentiate, and differentiating in α is what produces the factor x2. We set α=1 only after differentiating, because the standard normal has e−x2/2, i.e. α=1. Setting α=1 first would leave the constant I(1)=1, whose derivative is 0.
Cross-check by integration by parts. With u=x and dv=2π1xe−x2/2dx, so v=−2π1e−x2/2:
Is fZ(z)⋅σ1 already the answer? I was unsure whether the line fX(x)=2π1e−z2/2⋅σ1 was correct. It is: substituting z=σx−μ gives exactly the N(μ,σ2) density. The factor σ1 in front comes from dxdz.
Should μ and σ have a subscript Z? I was also confused about this. No: Z always has mean 0 and variance 1. Here μ and σ are the shift and scale applied to Z, and they become the mean and standard deviation of X: E[X]=σE[Z]+μ=μ and Var(X)=σ2Var(Z)=σ2. If anything, they are μX and σX.
Corollary 7.1 (Standardization)
If X∼N(μ,σ2), then Z=σX−μ∼N(0,1), and
FX(x)=Φ(σx−μ).
Symmetry of Φ and Standardization
Theorem 7.4 (Symmetry of the standard normal CDF)
For every y∈R,
Φ(−y)=1−Φ(y).
So a table only needs Φ(y) for y≥0.
Proof.
fZ is even: fZ(−v)=fZ(v). Substitute u=−v, du=−dv:
Why 1−Φ(1)? I was confused why the answer is 1−Φ(1) rather than Φ(1). Φ(1) is the area to the left of 1; P(Z>1) is the area to the right, which is its complement.
Sums of Independent Gaussians
Theorem 7.5 (Sum of independent Gaussians)
If X∼N(μX,σX2) and Y∼N(μY,σY2) are independent, then
X+Y∼N(μX+μY,σX2+σY2).
The parameters follow from Lecture 4: E[X+Y]=E[X]+E[Y]=μX+μY, and by independence Var(X+Y)=Var(X)+Var(Y)=σX2+σY2. The content of the theorem is that X+Y is again Gaussian. This can be shown with a convolution, or in one line with moment generating functions.
Proof: MGF proof TBD in a later lecture.
Theorem 7.6 (Converse)
If X and Y are independent and X+Y is Gaussian, then X and Y are each Gaussian (allowing a constant, i.e. variance 0).
This direction is much harder; its proof is beyond the scope of this course.
Derived Distributions
Given X with known density fX and Y=g(X), find fY.
If g is strictly increasing, {x:g(x)≤y}={x≤g−1(y)}, so FY(y)=FX(g−1(y)). If g is strictly decreasing, the inequality flips: {x:g(x)≤y}={x≥g−1(y)}, so FY(y)=1−FX(g−1(y)).
Corollary 7.2 (Monotone change of variables)
If g is strictly monotone and differentiable, then
fY(y)=fX(g−1(y))dydg−1(y).(7.21)
Proof.
Increasing g: dydFX(g−1(y))=fX(g−1(y))dydg−1(y), with dydg−1(y)>0. Decreasing g: dyd[1−FX(g−1(y))]=−fX(g−1(y))dydg−1(y), with dydg−1(y)<0. In both cases the result is (7.21).
For X=σZ+μ: g−1(x)=σx−μ and dxdg−1(x)=σ1, which is the factor σ1 found in Section 7.3.
Example 7.2 (Square root of a uniform)
Let X∼Uniform[0,1] and Y=X. For 0≤y≤1, since x is increasing on [0,1] and both sides are nonnegative,
Why only 1 way for the third group? I was confused whether the right-hand group contributes (n−k⋅) more choices. It does not: once the middle sample and the k−1 left samples are chosen, the other n−k samples are forced to the right. (Two or more samples landing in (x,x+dx) has probability of order (dx)2, which is negligible.)
Why y? I was confused why the formula was written in y rather than x. The argument is a dummy variable: fX(k)(y) and fX(k)(x) are the same function. What matters is that one variable is used throughout, and that FX and fX are the CDF and PDF of a single sample, not of X(k).
Check, k=n (the maximum).P(X(n)≤x)=P(all Xi≤x)=[FX(x)]n, and dxd[FX(x)]n=n[FX(x)]n−1fX(x), matching (7.28) with k=n.
Corollary 7.3 (Uniform samples)
If Xi∼Uniform[0,1], then fX(x)=1 and FX(x)=x on [0,1], so
Do the gaps really sum to 1? I was unsure about this. They do: the gaps tile [0,1] exactly, which is the telescoping sum above.
Why are the gaps symmetric? Place 11 independent uniform points on a circle of circumference 1 and cut the circle at one of them. The other 10 points are i.i.d. uniform on the resulting interval [0,1], and the 11 arcs between consecutive points are exactly the gaps Δ1,…,Δ11. On the circle no arc is special, so all gaps have the same distribution.
Cross-check with (7.30). With k=1: fX(1)(x)=0!9!10!(1−x)9=10(1−x)9. Substituting u=1−x,
Multiply both sides by the marginal fX(x); the left side becomes the joint PDF of X and Z:
fX,Z(x,z)=fZ∣X(z∣x)fX(x)=fY(z−x)fX(x).
To get the marginal fZ, integrate over all possible x:
fZ(z)=∫−∞∞fX,Z(x,z)dx=∫−∞∞fX(x)fY(z−x)dx.
Why does the conditioning drop? I was unsure why we can remove “∣X=x”. Once X=x is fixed, the only random variable left in {Y≤z−x} is Y, and Y is independent of X, so conditioning on X=x does not change its distribution.
Proof by a thin strip.
P(z≤Z≤z+δ) is the probability that (X,Y) lands in the strip between the lines y=z−x and y=z+δ−x:
where the inner integral over an interval of width δ is approximated by a rectangle of height fY(z−x). Since also P(z≤Z≤z+δ)≈fZ(z)δ,
fZ(z)δ≈∫−∞∞fX(x)fY(z−x)δdx,
and dividing by δ and letting δ→0 gives (8.4).
The strip has negative slope because Z=X+Y means Y=Z−X. What we integrate over the strip is the joint density, so P(z≤Z≤z+δ) is the probability mass of the strip, not its area.
Example: Sum of Two Uniforms
Example 8.2 (Sum of two independent uniforms)
Let X,Y∼Uniform[0,1] be independent, so fX(x)=b−a1=1−01=1 on [0,1], and the same for fY. Find fZ for Z=X+Y.
and fZ(z)=0 otherwise. Check: the triangle has area 21⋅2⋅1=1.
Sliding overlap. As a function of x, fY(z−x) is a box on [z−1,z] that slides to the right as z increases. fZ(z) is the length of its overlap with the box [0,1]: it grows from 0 at z=0, is largest at z=1 (exact overlap), and shrinks back to 0 at z=2. The same flip-and-slide picture is how convolution is used in signal processing.
Bounding Tail Probabilities
Example 8.3 (How big must a buffer be?)
Over n time slots, Pi packets arrive in slot i, where P1,…,Pn∼Poisson(1) are i.i.d. A buffer holds 5n packets. How likely is it to overflow? We want to bound
P(i=1∑nPi>5n).
Theorem 8.2 (Markov’s inequality)
If X≥0 and a>0, then
P(X≥a)≤aE[X].
Proof.
Pointwise, X≥a1{X≥a}: if X≥a the right side is a≤X, and otherwise it is 0≤X. Taking expectations, E[X]≥aE[1{X≥a}]=aP(X≥a).
Let Sn=∑i=1nPi≥0. By linearity of expectation and E[Pi]=1 for Poisson(1),
Too loose. The bound 51 does not shrink as n grows, even though Sn/n stays close to its mean 1, far below 5, for large n. Markov only uses E[Sn].
The exponential trick. For t>0, the function x↦etx is strictly increasing, so the event is unchanged by applying it to both sides. Apply Markov to the nonnegative random variable etSn:
P(Sn>5n)=P(etSn>e5nt)≤e5ntE[etSn].(8.16)
Why etx? I was confused why this particular function. We want to apply a function T so that E[T(∑iPi)] splits into a product ∏iE[T(Pi)] by independence. That requires T(x+y)=T(x)T(y), which the exponential satisfies: T(x+y)=et(x+y)=etxety=T(x)T(y). The parameter t>0 is a scaling factor we are free to choose.
Since the Pi are independent and identically distributed,
For n=10: Markov gives 0.2, while this bound gives e−40.5≈2.7×10−18.
Is the bound ∝e−n? I was unsure about the rate. Any t>0 with g(t)<0 gives exponential decay eng(t); the best rate is 5ln5−4≈4.05, at t⋆=ln5. This method (Markov applied to etX, then optimizing over t) is called the Chernoff bound. The quantity E[etP] is the MGF of P, defined next.
Moment Generating Functions
Definition 8.2 (Moment generating function)
The moment generating function of a random variable X is
computing all the moments E[Xn] of a distribution;
sums of independent random variables: convolution becomes multiplication.
Theorem 8.3 (MGFs generate moments)
If MX(s)<∞ for all s in an open interval around 0, then for every n≥1,
MX(n)(0)=E[Xn].
Proof.
Here s is a constant inside the expectation and X is the random part, so dsdesX=XesX. Differentiating n times and moving the derivative inside the expectation (allowed because MX is finite near 0),
dsndnMX(s)=dsndnE[esX]=E[dsndnesX]=E[XnesX].
At s=0, e0⋅X=e0=1, so MX(n)(0)=E[XnesX]s=0=E[Xn].
Example 8.4 (MGF of the exponential)
Let X∼Exponential(λ): fX(x)=λe−λx for x∈[0,∞). Then
MX(s)=∫0∞esxλe−λxdx=λ∫0∞e(s−λ)xdx.
If s<λ, the exponent s−λ is negative and
MX(s)=λ[s−λ1e(s−λ)x]0∞=λ(0−s−λ1)=λ−sλ.
If s≥λ, the integrand e(s−λ)x≥1 for all x≥0, so the integral diverges:
MX(s)=⎩⎨⎧λ−sλ∞s<λ,s≥λ.
Moments.MX′(s)=(λ−s)2λ and MX′′(s)=(λ−s)32λ, so
If MX(s)=MY(s)<∞ for all s in some open interval (−ε,ε) around 0, then X and Y have the same distribution.
So if we recognize an MGF, we know the distribution. (The proof is beyond the scope of this course.)
Not finished in lecture. We ran out of time after starting the list of MGF properties. The main properties are filled in below.
Theorem 8.5 (Properties of MGFs)
MX(0)=1.
If Y=aX+b, then MY(s)=esbMX(as).
If X and Y are independent, then MX+Y(s)=MX(s)MY(s). More generally, for independent X1,…,Xn, MX1+⋯+Xn(s)=∏i=1nMXi(s), and (MX1(s))n if they are also identically distributed.
Proof.
MX(0)=E[e0⋅X]=E[1]=1.
MY(s)=E[es(aX+b)]=E[esbe(as)X]=esbE[e(as)X]=esbMX(as), since esb is a constant.
MX+Y(s)=E[es(X+Y)]=E[esXesY]=E[esX]E[esY]=MX(s)MY(s), using independence of esX and esY. The n-term version follows by induction.
Property 3 is the payoff: the density of X+Y requires a convolution integral, but its MGF is just a product.
MGF Proofs for Sums of Independent Random Variables
Lemma 8.1 (MGF of the Gaussian)
If X∼N(μ,σ2), then for all s∈R,
MX(s)=eμs+σ2s2/2.
Proof.
First let Z∼N(0,1). Complete the square in the exponent, z2−2sz=(z−s)2−s2:
EECS 126 (UC Berkeley) · Spring 2026 · February 17, 2026
Reading: Bertsekas & Tsitsiklis, §5.1; supplementary notes on concentration inequalities.
These are my personal notes from Professor Kannan Ramchandran’s EECS 126 (Probability and Random Processes) course at UC Berkeley.
Topics: Markov’s inequality, Chebyshev’s inequality, the Chernoff bound, Jensen’s inequality, Hoeffding’s inequality, and a first look at the law of large numbers and the central limit theorem. Each bound trades more information about X for a tighter estimate of a tail probability.
Markov’s Inequality
Theorem 9.1 (Markov’s inequality)
If X≥0 and a>0, then
P(X≥a)≤aE[X].(9.1)
Proof.
Compare X with the random variable a1{X≥a} pointwise:
if X≥a: a1{X≥a}=a≤X;
if X<a: a1{X≥a}=0≤X, since X≥0.
So X≥a1{X≥a} always. Taking expectations, and using E[1A]=P(A),
E[X]≥aE[1{X≥a}]=aP(X≥a).
Dividing by a>0 gives (9.1).
For x≥0, the line x lies above the step a1{x≥a}; averaging both sides gives Markov.
Example 9.1 (Markov for an exponential)
Let X∼Exponential(1), so E[X]=1 (Lecture 8) and P(X≥a)=∫a∞e−xdx=[−e−x]a∞=e−a. Markov gives
P(X≥a)≤a1.
At a=5: Markov gives 0.2, while the exact value is e−5≈0.0067.
Markov cannot be improved using only the mean. Fix m=E[X] and a≥m. The random variable
X={a0w.p. am,w.p. 1−am
has E[X]=a⋅am=m and P(X≥a)=am=aE[X], so (9.1) holds with equality. To do better, we need more information about X.
Chebyshev’s Inequality
Theorem 9.2 (Chebyshev’s inequality)
If X has mean μ and variance σ2, then for every c>0,
P(∣X−μ∣≥c)≤c2σ2.
With c=kσ:
P(∣X−μ∣≥kσ)≤k21.
Proof.
Both sides of ∣X−μ∣≥c are nonnegative, so squaring does not change the event: {∣X−μ∣≥c}={(X−μ)2≥c2}. Apply Markov to the nonnegative random variable (X−μ)2 with a=c2:
P(∣X−μ∣≥c)=P((X−μ)2≥c2)≤c2E[(X−μ)2]=c2σ2.
The parabola (cx−μ)2 lies above the indicator; averaging both sides gives Chebyshev. It uses the variance, not just the mean.
Example 9.2 (Chebyshev for a uniform)
Let X∼Uniform[0,1]. Then μ=21, E[X2]=∫01x2dx=31, and
σ2=E[X2]−μ2=31−41=121.
With c=0.4, the exact value is P(∣X−21∣≥0.4)=P(X≤0.1)+P(X≥0.9)=0.1+0.1=0.2, while
P(∣X−21∣≥0.4)≤(0.4)21/12=12⋅0.161=1.921≈0.52.
Example 9.3 (Polling with Chebyshev)
To estimate the fraction p of voters who support a candidate, poll n people independently. Let Xi∼Bernoulli(p) indicate support and Mn=n1∑i=1nXi. How large must n be so that P(∣Mn−p∣≥0.01)≤0.05?
E[Mn]=p and Var(Mn)=np(1−p) (Lecture 4 and Lecture 10). Since p is unknown, bound the variance:
p(1−p)=41−(p−21)2≤41.
By Chebyshev with c=ε,
P(∣Mn−p∣≥ε)≤nε2p(1−p)≤4nε21.
Setting 4nε21≤δ with ε=0.01, δ=0.05:
n≥4ε2δ1=4(0.01)2(0.05)1=0.000021=50,000.
The Chernoff Bound
Theorem 9.3 (Chernoff bound)
For every b and every s>0,
P(X≥b)≤e−sbMX(s),MX(s)=E[esX],
and therefore
P(X≥b)≤s>0mine−sbMX(s).
For the lower tail, P(X≤b)≤mins<0e−sbMX(s).
Proof.
For s>0, x↦esx is strictly increasing, so {X≥b}={esX≥esb}. Apply Markov to the nonnegative random variable esX:
P(X≥b)=P(esX≥esb)≤esbE[esX]=e−sbMX(s).
This holds for every s>0, so it holds for the minimizing s. For s<0, x↦esx is strictly decreasing, so {X≤b}={esX≥esb}, and the same argument gives the lower-tail bound.
For any s>0, the exponential es(x−b) lies above the indicator 1{x≥b}; averaging gives P(X≥b)≤e−sbMX(s), and we choose s to make the curve hug the indicator as tightly as possible.
Example 9.4 (Gaussian tail)
Let Z∼N(0,1), so MZ(s)=es2/2 (Lecture 8). For t>0,
P(Z≥t)≤s>0mine−st+s2/2.
The exponent h(s)=2s2−st has h′(s)=s−t=0 at s⋆=t, and h(t)=2t2−t2=−2t2. Therefore
P(Z≥t)≤e−t2/2.
Compare with Chebyshev, which gives P(Z≥t)≤P(∣Z∣≥t)≤t21:
Chebyshev decays polynomially; Chernoff decays like the true tail, up to a smaller factor.
Example 9.5 (Chernoff for coin flips)
Let Sn∼Binomial(n,p), a sum of n independent Bernoulli(p) flips, so MSn(s)=(1−p+pes)n: each flip has E[esXi]=(1−p)e0+pes, and the MGF of an independent sum is the product (Lecture 8). For p<q<1,
A function g is convex if for all x,y and λ∈[0,1],
g(λx+(1−λ)y)≤λg(x)+(1−λ)g(y):(9.23)
every chord lies above the graph. If g is differentiable, convexity is equivalent to every tangent line lying below the graph:
g(x)≥g(c)+g′(c)(x−c)for all x,c.(9.24)
g is concave if −g is convex. Examples: x2, esx, ∣x∣ are convex; lnx and x are concave on (0,∞).
Theorem 9.4 (Jensen’s inequality)
If g is convex, then
g(E[X])≤E[g(X)].
If g is concave, the inequality reverses: g(E[X])≥E[g(X)].
Proof.
Take the tangent line (9.24) at c=E[X] and substitute x=X:
g(X)≥g(E[X])+g′(E[X])(X−E[X]).
Take expectations. g(E[X]) and g′(E[X]) are constants, and E[X−E[X]]=0:
E[g(X)]≥g(E[X])+g′(E[X])⋅0=g(E[X]).
(For a convex g that is not differentiable, the same argument works with any supporting line through (E[X],g(E[X])).) For concave g, apply the result to −g.
For X equal to x1 or x2 with probability 21 each, E[g(X)] is the midpoint of the chord, which lies above g(E[X]) on the curve.
Example 9.6 (Consequences of Jensen)
g(x)=x2 (convex): (E[X])2≤E[X2], i.e. Var(X)=E[X2]−(E[X])2≥0.
g(x)=esx (convex): esE[X]≤MX(s), so an MGF is never smaller than esE[X].
g(x)=lnx (concave): E[lnX]≤lnE[X]. For X uniform on positive numbers {x1,…,xn},
n1i=1∑nlnxi≤ln(n1i=1∑nxi)⟹(i=1∏nxi)1/n≤n1i=1∑nxi,
the arithmetic–geometric mean inequality.
In the St. Petersburg game (Lecture 5), E[log2W]=2 is finite even though E[W]=∞, consistent with E[log2W]≤log2E[W].
Hoeffding’s Inequality
Chernoff requires the MGF. For bounded random variables, we can bound the MGF without knowing the distribution.
Lemma 9.1 (Hoeffding’s lemma)
If a≤X≤b and E[X]=0, then for every s∈R,
E[esX]≤es2(b−a)2/8.
Proof.
Since E[X]=0, we have a≤0≤b. Write x∈[a,b] as the convex combination x=λa+(1−λ)b with λ=b−ab−x. By convexity of esx (9.23),
esx≤b−ab−xesa+b−ax−aesb.
Substitute x=X and take expectations, using E[X]=0:
E[esX]≤b−abesa−b−aaesb.
Let p=b−a−a∈[0,1] and h=s(b−a), so sa=−ph and sb=h−ph. The right side becomes
Let C=∑i(bi−ai)2. Each centered term Xi−E[Xi] has mean 0 and lies in an interval of length bi−ai. By Chernoff, independence (Lecture 8), and Hoeffding’s lemma, for s>0,
Minimize the exponent: −t+4sC=0 at s⋆=C4t, giving
−C4tt+C216t2⋅8C=−C4t2+C2t2=−C2t2.
For the sample mean, {Mn−μ≥ε}={Sn−nμ≥nε}, so take t=nε and C=n(b−a)2: C2t2=n(b−a)22n2ε2=(b−a)22nε2. The lower tail is the same bound applied to −Xi, and adding the two tails gives the factor 2.
Example 9.7 (Polling with Hoeffding)
Return to polling: Xi∈[0,1], so b−a=1. By (9.36),
P(∣Mn−p∣≥ε)≤2e−2nε2≤δ⟺n≥2ε2ln(2/δ).
With ε=0.01, δ=0.05:
n≥2(0.01)2ln40=0.00023.689≈18,445,
compared with 50,000 from Chebyshev. The two bounds as functions of n (with ε=0.05):
Chebyshev decays like n1; Hoeffding decays exponentially in n.
A First Look at the LLN and the CLT
Law of large numbers. For i.i.d. Xi with mean μ and variance σ2, Chebyshev gives
P(∣Mn−μ∣≥ε)≤nε2σ2⟶0,
which is the weak law of large numbers (proved in full in Lecture 10).
Central limit theorem.Zn=σn(Mn−μ) is approximately N(0,1) for large n (Lecture 10), so
P(∣Mn−μ∣≥ε)=P(∣Zn∣≥σεn)≈2(1−Φ(σεn)).
For polling, σ2≤41, and 2(1−Φ(1.96))=0.05, so we need σεn≥1.96:
n≥ε2(1.96)2σ2,which holds for every p oncen≥4(0.01)2(1.96)2=9,604.
This is an approximation, not a guaranteed bound like Chebyshev or Hoeffding.
EECS 126 (UC Berkeley) · Spring 2026 · February 19, 2026
Reading: Bertsekas & Tsitsiklis, Ch. 5; supplementary notes on convergence.
These are my personal notes from Professor Kannan Ramchandran’s EECS 126 (Probability and Random Processes) course at UC Berkeley.
Topics: the weak law of large numbers (WLLN), convergence in probability, almost sure convergence and the strong law of large numbers (SLLN), and the central limit theorem (CLT).
Recap: Concentration Inequalities
The following bounds were derived in Lecture 9; we restate the ones used below.
Theorem 10.1 (Markov’s inequality)
If X≥0 and a>0, then
P(X≥a)≤aE[X].
Theorem 10.2 (Chebyshev’s inequality)
If X has mean μ and variance σ2, then for every c>0,
P(∣X−μ∣≥c)≤c2Var(X)=c2σ2.(10.2)
With c=kσ:
P(∣X−μ∣≥kσ)≤k21.
The left side is the probability that X deviates from its mean by at least c. For k=3, the two tails beyond μ±3σ have total probability at most 91, for any distribution with finite variance.
Theorem 10.3 (Chernoff bound)
For every b,
P(X≥b)≤s>0mine−sbMX(s),MX(s)=E[esX].
Example 10.1 (Chernoff bound for a Gaussian tail)
Let X∼N(0,σ2), so MX(s)=eσ2s2/2 (Lecture 8). With b=kσ,
Formally, for all ε,δ>0 there exists n(ε,δ) such that
P(∣Mn−μ∣≥ε)≤δfor all n≥n(ε,δ).
From (10.12), nε2σ2≤δ⟺n≥ε2δσ2, so n(ε,δ)=ε2δσ2 samples suffice. For example, with σ2=1, ε=0.1, δ=0.05: n≥(0.01)(0.05)1=2000.
What are ε and δ capturing? I had a question of what ε captures in this statement.
ε is the accuracy: how close Mn must be to μ.
δ is the confidence: the probability of a deviation of at least ε is at most δ. (It bounds a probability, not the deviation itself.)
n(ε,δ) is the number of samples needed for a given accuracy and confidence.
In words: for n≥n(ε,δ), ∣Mn−μ∣<ε with probability at least 1−δ.
Convergence in Probability
Definition 10.1 (Convergence in probability)
A sequence Y1,Y2,…converges in probability to a constant a, written Ynpa, if for every ε>0,
n→∞limP(∣Yn−a∣≥ε)=0.
The WLLN says exactly that Mnpμ.
Example 10.2 (Minimum of uniforms)
Let X1,X2,… be i.i.d. Uniform[0,1] and Yn=min(X1,…,Xn). Does Yn converge in probability, and to what?
As we draw more samples, the smallest one should approach 0. Fix 0<ε<1. Since Yn≥0,
P(∣Yn−0∣≥ε)=P(Yn≥ε)=P(min(X1,…,Xn)≥ε)=P(X1≥ε,X2≥ε,…,Xn≥ε)=i=1∏nP(Xi≥ε)=(1−ε)n⟶0as n→∞,(all must be ≥ε)(independence)
since 0<1−ε<1. (For ε≥1 the probability is 0.) Therefore Ynp0.
Example 10.3 (Discrete-time arrival process)
Time runs in slots n=1,2,3,…, grouped into intervals
Ik={2k,2k+1,…,2k+1−1},k=0,1,2,…,
so I0={1}, I1={2,3}, I2={4,…,7}, I3={8,…,15}, and ∣Ik∣=2k. There is exactly 1 arrival in each interval Ik, at a time chosen uniformly at random within Ik. Let
Yn={10if there is an arrival at time n,otherwise.
Each time in Ik is equally likely to hold the arrival, so
As n→∞, the interval index k containing n also goes to ∞, so
n→∞limP(Yn=1)=k→∞lim2k1=0.
For 0<ε≤1, P(∣Yn−0∣≥ε)=P(Yn=1)→0 (and it is 0 for ε>1), so Ynp0.
Converging, yet arrivals keep coming. Initially I was wondering how Yn can converge to 0 when, no matter which n I pick, infinitely many arrivals still come after it. This is why convergence in probability is a weak notion: it only says that at each fixed large n, an arrival at that particular time is unlikely. It says nothing about a single realization of the whole sequence, which still has Yn=1 once in every interval. This weakness belongs to convergence in probability, not to the WLLN itself.
Almost Sure Convergence and the Strong Law
Each outcome ω of the experiment produces a whole realization: an ordinary sequence of numbers Y1(ω),Y2(ω),….
Definition 10.2 (Almost sure convergence)
Ynconverges almost surely (a.s.) to Y, written Yna.s.Y, if
P({ω:n→∞limYn(ω)=Y(ω)})=1.
That is, the realization converges as an ordinary sequence for every outcome outside an event of probability 0.
Theorem 10.5 (Strong law of large numbers)
Let {Xn}n≥1 be i.i.d. with mean μ. Then
P(n→∞limn1i=1∑nXi=μ)=1,i.e.Mna.s.μ.
(The proof is beyond the scope of this course.) For fair die rolls, μ=61+2+⋯+6=621=3.5, and every realization of Mn (except on an event of probability 0) converges to 3.5:
Excursions: SLLN versus WLLN. Initially I was wondering whether the SLLN allows any excursions at all outside a band μ±ε. It does: almost every realization leaves the band only finitely many times, and after some point stays inside forever. Convergence in probability (the WLLN) only requires that, at each fixed large n, few realizations are outside the band; a single realization may still leave it infinitely often.
Theorem 10.6 (Almost sure convergence implies convergence in probability)
If Yna.s.Y, then YnpY. The converse is not necessarily true.
Proof.
Fix ε>0 and let
An=m≥n⋃{∣Ym−Y∣≥ε},
the event that the realization leaves the ε-band at some time m≥n. Then A1⊇A2⊇⋯. An outcome in every An leaves the band infinitely often, so its realization does not converge to Y; hence P(⋂nAn)≤P(Yn→Y)=0. By continuity of probability for decreasing events (a consequence of countable additivity, Lecture 1), P(An)→P(⋂nAn)=0. Since {∣Yn−Y∣≥ε}⊆An,
P(∣Yn−Y∣≥ε)≤P(An)⟶0.
The converse fails: the arrival process. Every realization has exactly one arrival in each interval Ik, so Yn(ω)=1 for infinitely many n and Yn(ω)=0 for infinitely many n. The sequence Yn(ω) never converges, for every outcome ω, so P(Yn→0)=0. Thus Ynp0 but Yn does not converge almost surely.
The Central Limit Theorem
Let X1,X2,… be i.i.d. and Sn=∑i=1nXi. What happens to the distribution of Sn as n grows?
Example 10.4 (Sums of uniforms)
Xi∼Uniform[0,1]. fS1 is a box and fS2 is the triangle from Lecture 8. Convolving once more, fS3(z)=∫z−1zfS2(x)dx:
Standardizing does not make Zn Gaussian. I had a question of whether the CLT just says that Zn becomes Gaussian once it is normalized. E[Zn]=0 and Var(Zn)=1 for every n, but for finite n, Zn is generally not Gaussian (for uniform Xi, Zn even has bounded support). The CLT is a statement about the limit: the CDF of Zn approaches Φ as n→∞.
Definition 10.3 (Convergence in distribution)
Znconverges in distribution to Z, written ZndZ, if
n→∞limP(Zn≤x)=P(Z≤x)
at every x where the CDF of Z is continuous.
Theorem 10.7 (Central limit theorem)
Let X1,X2,… be i.i.d. with mean μ and variance 0<σ2<∞, and Zn=nσSn−nμ. Then for every x∈R,
where Z∼N(0,1) and u is a dummy variable. That is, ZndN(0,1).
Implications.
In the limit, the distribution of Zn “wipes out” all information about the distribution of the Xi except the mean and the variance.
If there are a large number of independent small disturbances, their aggregate effect is approximately normally distributed. This is why the Gaussian is a good model for noise.
The finite-variance assumption is needed: without it, Zn need not approach a Gaussian.
Proof via MGFs.
Assume MX1(s)<∞ for s in an interval around 0. Standardize each term: Yi=σXi−μ, i.i.d. with E[Yi]=0 and E[Yi2]=Var(Yi)=1. Then
Zn=nσSn−nμ=nσ∑i=1n(Xi−μ)=n1i=1∑nYi.
By the MGF properties of Lecture 8 (scaling, then independent sums),
So MZn(s)→es2/2, which is the MGF of N(0,1) (Lecture 8). Finally, we use without proof the continuity theorem: if MZn(s)→MZ(s) for all s in an interval around 0, then ZndZ. Hence ZndN(0,1).
This proof assumes the MGF exists near 0. The CLT holds with only a finite variance; that more general proof uses characteristic functions and is beyond the scope of this course.