The Timpson Lyceum seal

The Timpson Lyceum · Discrete Math (2025)

Probability, Random Variables, and Expectation - Lecture 16 (Discrete Math)

Overview

This lecture introduces random variables and expectation, the bridge between a raw sample space and the numerical quantities we actually care about. Despite the name, a random variable is neither random nor a variable — it is simply a function whose domain is the sample space. Once we can attach a number to every outcome, we can ask for the probability that the function takes a given value, and we can ask what value we should expect it to take on average. The lecture builds intuition through dice, coin flips, and gambling-style spinner games, connects the binomial coefficient to the probability of getting a fixed number of heads, defines independence of random variables, and closes with the definition and key properties (linearity) of expected value.

Key Concepts

Sample space. A sample space is an ordered pair (S,P)(S, P) where SS is the set of all possible outcomes and P ⁣:S→RP\colon S \to \mathbb{R} is the probability function assigning each outcome a number in [0,1][0,1]. The probabilities of all outcomes must sum to 11. For one fair die, S={1,2,3,4,5,6}S = \{1,2,3,4,5,6\} and P(s)=16P(s) = \tfrac{1}{6} for every outcome.

Random variable. Given a sample space (S,P)(S,P) and any set VV, a function X ⁣:S→VX\colon S \to V is called a random variable. The only requirement is that its domain is SS — it assigns something to every outcome. The defining mental model: random variable = function.

Real random variable. The case we care about almost always: a function X ⁣:S→RX\colon S \to \mathbb{R} that maps every outcome to a real number — just like the probability function itself. (A non-real example: a function ZZ that maps a coin-flip string to the set of positions where heads occur. The output need not be a number; output sets can be anything.)

Probability that a random variable equals a value. Writing P(X=a)P(X = a) means the probability of the event "the outcome maps to aa": P(X=a)=∑s∈SX(s)=aP(s).P(X = a) = \sum_{\substack{s \in S \\ X(s) = a}} P(s). This replaces the old event-based language: instead of defining a separate event for "rolled a 7," we define one random variable XX and talk about P(X=7)P(X = 7). For most real numbers aa (e.g. π\pi, 2727, −6-6) this probability is 00, since no outcome maps there.

Building new random variables from old ones. Random variables can be combined like functions. For two dice with rolls written (a,b)(a,b), let X1(a,b)=aX_1(a,b) = a and X2(a,b)=bX_2(a,b) = b. Then X=X1+X2X = X_1 + X_2, defined by (X1+X2)(a,b)=X1(a,b)+X2(a,b)=a+b(X_1+X_2)(a,b) = X_1(a,b) + X_2(a,b) = a+b, is the familiar "sum of the dice" random variable.

Coin flips and the binomial connection. Flip a coin nn times; the sample space SnS^n consists of all length-nn strings of H's and T's. For a fair coin each string has probability 12n\tfrac{1}{2^n}. If XX counts the number of heads, then the number of strings with exactly hh heads is (nh)\binom{n}{h}, so: P(X=h)=(nh)2n(fair coin).P(X = h) = \frac{\binom{n}{h}}{2^n} \quad (\text{fair coin}). For an unfair coin with P(H)=pP(\text{H}) = p and P(T)=1−pP(\text{T}) = 1-p, each specific string with hh heads and n−hn-h tails has probability ph(1−p)n−hp^{h}(1-p)^{n-h}, so: P(X=h)=(nh) ph(1−p) n−h.P(X = h) = \binom{n}{h}\, p^{h}(1-p)^{\,n-h}. This is exactly a term of the binomial theorem, (x+y)n=∑k=0n(nk)xkyn−k(x+y)^n = \sum_{k=0}^{n}\binom{n}{k}x^{k}y^{n-k}, with x=px = p and y=1−py = 1-p. Since p+(1−p)=1p + (1-p) = 1 and 1n=11^n = 1, the full sum equals 11 — i.e. the probabilities of getting 0,1,2,…,n0,1,2,\dots,n heads add to 100%100\%, as they must.

Independent random variables. XX and YY on the same sample space are independent provided that for all values a,ba, b: P(X=a and Y=b)=P(X=a)⋅P(Y=b),P(X = a \text{ and } Y = b) = P(X = a)\cdot P(Y = b), equivalently P(X=a∣Y=b)=P(X=a)P(X = a \mid Y = b) = P(X = a) — knowing YY gives no information about XX. For two dice, X1X_1 (first die) and X2X_2 (second die) are independent, but the sum X=X1+X2X = X_1 + X_2 is not independent of X1X_1 (knowing the first die changes the distribution of the total).

Expected value. For a real random variable XX on (S,P)(S,P), the expected value is the probability-weighted average of its outputs: E(X)=∑s∈SX(s) P(s).E(X) = \sum_{s \in S} X(s)\, P(s). Equivalently — and usually easier to compute — sum over the values the variable can take: E(X)=∑a∈Ra P(X=a),E(X) = \sum_{a \in \mathbb{R}} a\, P(X = a), where all but finitely many terms vanish because P(X=a)=0P(X = a) = 0 for most aa. (Going from the first form to the second is a regrouping of terms by output value, valid because addition is commutative and associative and because a real random variable always outputs a real number to group by.) Expectation answers "what would the long-run average be over a huge number of trials?" — e.g. one fair die has E(X)=1+2+3+4+5+66=72=3.5E(X) = \tfrac{1+2+3+4+5+6}{6} = \tfrac{7}{2} = 3.5.

Linearity of expectation. For real random variables X,YX, Y and a constant c∈Rc \in \mathbb{R}:

This holds regardless of independence, mirroring the linearity of limits and derivatives. It makes scaling trivial: since one die has E=3.5E = 3.5, rolling 100100 dice has expected total 100×3.5=350100 \times 3.5 = 350.

Products are different. E(XY)=E(X) E(Y)E(XY) = E(X)\,E(Y) holds only when XX and YY are independent. It does not follow from linearity (compare: the derivative of a product is not the product of derivatives — it needs the product rule).

Worked Example

Unfair-spinner gambling game. A spinner lands on 1,2,3,41,2,3,4 with probabilities 12,14,18,18\tfrac12, \tfrac14, \tfrac18, \tfrac18. The payout random variable XX pays you the number you land on (in dollars): X(k)=kX(k) = k. What is the fair price to charge per spin? Compute E(X)E(X).

Apply the value-weighted definition E(X)=∑aa P(X=a)E(X) = \sum_{a} a\,P(X=a), then substitute:

E(X)=∑aa P(X=a)=1⋅12+2⋅14+3⋅18+4⋅18=48+48+38+48=158=1.875.\begin{aligned} E(X) &= \sum_{a} a\,P(X = a) \\ &= 1\cdot\tfrac{1}{2} + 2\cdot\tfrac{1}{4} + 3\cdot\tfrac{1}{8} + 4\cdot\tfrac{1}{8} \\ &= \tfrac{4}{8} + \tfrac{4}{8} + \tfrac{3}{8} + \tfrac{4}{8} \\ &= \tfrac{15}{8} = 1.875. \end{aligned}

So the game is worth about $1.88 per spin; charging $2 turns a steady profit. Note the intuition trap: a similar "odd pays $20, even pays $10" spinner feels like a $15 game but actually has E(Y) = 20\cdot\tfrac12 + 10\cdot\tfrac14 + 20\cdot\tfrac18 + 10\cdot\tfrac18 = \text{\} 16.25$ — higher than intuition suggests.

Proof sketch — linearity E(X+Y)=E(X)+E(Y)E(X+Y) = E(X) + E(Y). Starting from the definition and using that (X+Y)(s)=X(s)+Y(s)(X+Y)(s) = X(s) + Y(s):

E(X+Y)=∑s∈S(X(s)+Y(s)) P(s)=∑s∈SX(s)P(s)+∑s∈SY(s)P(s)=E(X)+E(Y).\begin{aligned} E(X+Y) &= \sum_{s \in S} \big(X(s) + Y(s)\big)\,P(s) \\ &= \sum_{s \in S} X(s)P(s) + \sum_{s \in S} Y(s)P(s) \\ &= E(X) + E(Y). \end{aligned}

Summary