pdf-and-cdf-basics

Tue Jul 14 2026

The sitting in one line For a continuous random variable, probability lives on small segments, never on points. The density is the CDF's slope, f=Ff = F', every probability is an area under ff, and any single point carries exactly zero.

From staircase to ramp

In the discrete world (probability-distributions-and-random-variables) the CDF is a staircase and the PMF lives in the jumps: P(X=x)=F(x)F(x)P(X = x) = F(x) - F(x^-), the jump height at xx. A continuous CDF is a smooth ramp with no jumps at all. Apply the same jump formula and it forces P(X=x)=0P(X = x) = 0 for every single xx. Nothing is left over for any individual point.

The interesting part is what falls out on the way. Writing the small difference at xx gives F(x)dxF'(x)\,dx, and as dx0    P(X=x)=F(x).dx0dx \rightarrow 0 \implies P(X = x) = F'(x).dx \rightarrow 0. It is the chapter's central object: f(x)=F(x)f(x) = F'(x), the probability density function.

One cheap consequence worth pocketing: since endpoints carry zero, P(a<X<b)=P(aXb)P(a < X < b) = P(a \le X \le b), and every half-open version in between. No more << vs \le anxiety.

Probability lives on segments (the dx view)

f(x)f(x) is not a probability. f(x)dxf(x)\,dx is: the probability that XX lands in a tiny window of width dxdx around xx. Density is probability per unit length, which means it carries units. My waiting-time example: XX uniform on half an hour has density height 2 measured in hours and height 1/30 measured in minutes. Same random variable, same probabilities, different heights. Only height times width is real.

That also settles why a density can exceed 1. The only validity conditions are f0f \ge 0 everywhere and total area 1. Height 2 (or 3, or 100) is fine as long as the support is narrow enough. Unif(0,1/3)\text{Unif}(0, 1/3) sits at height 3 everywhere and is a perfectly legal distribution. The mantra: height is probability per unit length, only area is probability.

The same view is the right way to think about transformations. To understand Y=g(X)Y = g(X), don't ask where a point goes, ask what happens to a small segment. The map gg sends [x,x+dx][x, x + dx] to a segment around g(x)g(x), and the probability mass f(x)dxf(x)\,dx riding on it is conserved. If the segment gets stretched, that mass spreads over more length, so the density drops. Compressed, the density rises.

pdf-cdf-segment-stretch

3blue1brown has a video on exactly this segment intuition, from his probability playlist.

Working with densities

The practical workflow: differentiate the CDF when you want the shape, use the CDF directly when you want a probability. The Rayleigh warm-up shows both. Its CDF is F(x)=1ex2/2F(x) = 1 - e^{-x^2/2} for x>0x > 0, so the density is f(x)=xex2/2f(x) = x\,e^{-x^2/2} by the chain rule, and the tail needs no integral at all: P(X>2)=1F(2)=e2P(X > 2) = 1 - F(2) = e^{-2}. The CDF already did the integrating.

Everything from the discrete world translates with one mechanical dictionary: sums become integrals, P(X=x)P(X = x) becomes f(x)dxf(x)\,dx. So E(X)=xf(x)dxE(X) = \int x\,f(x)\,dx and LOTUS reads E(g(X))=g(x)f(x)dxE(g(X)) = \int g(x)\,f(x)\,dx. Linearity, LOTUS, and the variance identity from lotus-and-variance all carry over unchanged.

The Uniform

Unif(a,b)\text{Unif}(a, b) formalizes "a completely random number between aa and bb": a flat density f(x)=1/(ba)f(x) = 1/(b-a) on the support, forced by area 1, and a ramp CDF F(x)=(xa)/(ba)F(x) = (x-a)/(b-a) there. My first CDF attempt failed the standard sanity checks, so they are worth naming: FF must be 0 at the left edge, 1 at the right edge, and it must stay at those values outside the support. Writing "0 otherwise" claims P(U5)=0P(U \le 5) = 0 for Unif(0,1)\text{Unif}(0,1), which no CDF can do.

For UUnif(0,1)U \sim \text{Unif}(0,1), probability literally is length: P(U(0.2,0.5))=0.3P(U \in (0.2, 0.5)) = 0.3. Its moments are E(U)=1/2E(U) = 1/2 and Var(U)=1/12\text{Var}(U) = 1/12. The general case needs zero new integrals: a+(ba)UUnif(a,b)a + (b-a)U \sim \text{Unif}(a,b) (stretch, then shift), so E=(a+b)/2E = (a+b)/2 and Var=(ba)2/12\text{Var} = (b-a)^2/12. The variance contains only the width bab - a. Where the interval sits doesn't matter, only how wide the room is.

Same support is not same distribution: the U² trap

A friend argues: U2U^2 still lands in (0,1)(0,1), so it is still completely random there. The test comes from the Uniform section: completely random means flat PDF, which means linear CDF. Compute it: P(U2x)=P(Ux)=xP(U^2 \le x) = P(U \le \sqrt{x}) = \sqrt{x}. Not linear. Same support, different distribution.

The segment view says where the mass went. Squaring pulls every value in (0,1)(0,1) downward, compressing segments near 0, so the density piles up there. About 70% of draws land below 1/2, since 1/20.707\sqrt{1/2} \approx 0.707.

pdf-cdf-u-squared-mass

This is exactly the classic nonce-bias bug in ECDSA and Schnorr. Reduce a uniform 256-bit number mod the group order nn and every residue is still possible, but residues below 2256modn2^{256} \bmod n get hit slightly more often. The support looks fine, the distribution is not uniform, and with enough signatures lattice attacks turn that tiny skew into the secret key. The flat-PDF test is the formal version of the check that catches it.

Universality of the Uniform

One theorem, two directions, both riding on the Uniform's special property: its CDF is the identity, P(Up)=pP(U \le p) = p, so UU can hand you an event of any probability you name.

Universality of the Uniform Let FF be a continuous, strictly increasing CDF and let UUnif(0,1)U \sim \text{Unif}(0,1). Then:

  1. Manufacture. X=F1(U)X = F^{-1}(U) is a random variable whose CDF is exactly FF.
  2. Flatten. If XX is a random variable with CDF FF, then F(X)Unif(0,1)F(X) \sim \text{Unif}(0,1).

Direction 1: F1(U)F^{-1}(U) has CDF FF. I want X=g(U)X = g(U) with P(Xx)=F(x)P(X \le x) = F(x). Solve for gg instead of verifying a given answer:

P(g(U)x)=P(Ug1(x))=g1(x),P(g(U) \le x) = P(U \le g^{-1}(x)) = g^{-1}(x),

so matching against F(x)F(x) forces g1=Fg^{-1} = F, that is X=F1(U)X = F^{-1}(U). The first step silently used that gg is increasing, which is why the theorem assumes FF strictly increasing.

My own reading of what the proof does: we have a family of events {Xx}\{X \le x\} whose probabilities we want to be F(x)F(x). The Uniform has the special property P(Uu)=uP(U \le u) = u, so in particular P(UF(x))=F(x)P(U \le F(x)) = F(x), an event with exactly the right probability, sitting there pre-made. Setting X=F1(U)X = F^{-1}(U) just lines {Xx}\{X \le x\} up with {UF(x)}\{U \le F(x)\}. The important property is realizing P(UF(x))=F(x)P(U \le F(x)) = F(x). That is the core of the proof.

The percentile reading makes the result feel obvious: a CDF converts values to percentiles, F1F^{-1} is the percentile-to-value lookup, and to draw from any distribution you draw a percentile uniformly and look up which value owns it.

The picture is uniform rain on the percentile axis:

pdf-cdf-universality-rain

Where FF is steep, a wide band of percentiles gets squeezed into a narrow window of values, so landings pile up exactly where the density is tall. The slope F=fF' = f is the local compression ratio of this transport, the segment view from above, one more time. And U2U^2 was already this machine running: target F(x)=xF(x) = \sqrt{x} gives F1(u)=u2F^{-1}(u) = u^2.

Direction 2: F(X)Unif(0,1)F(X) \sim \text{Unif}(0,1). Feed XX into its own CDF and it flattens, whatever distribution XX had. One line, using that a strictly increasing FF makes {F(X)u}\{F(X) \le u\} and {XF1(u)}\{X \le F^{-1}(u)\} the same event:

P(F(X)u)=P(XF1(u))=F(F1(u))=u.P(F(X) \le u) = P(X \le F^{-1}(u)) = F(F^{-1}(u)) = u.

You never invert FF inside a probability, you just rename the event: both descriptions represent the same values underneath, because FF is a simple one-one mapping xF(x)x \to F(x). Strict monotonicity is what makes the renaming valid in both directions.

Why (0,1)(0,1) and not some Unif(a,b)\text{Unif}(a,b)? In direction 2 it is forced: FF outputs probabilities, so F(X)F(X) physically lives in [0,1][0,1]. In direction 1 it is just the canonical choice. From a VUnif(a,b)V \sim \text{Unif}(a,b) source, standardize first and use X=F1((Va)/(ba))X = F^{-1}\big((V-a)/(b-a)\big). Direction 1 is what simulation libraries call inverse transform sampling: computers only generate uniform bits, and this is how uniform bits become samples from anything with a tractable F1F^{-1}.

What stayed shaky

The sitting's one real miss: I claimed neither probability nor dxdx has units. Probability is a pure number, but dxdx is a length in XX's units, and that is what makes density a per-unit-length quantity. The re-test for next week: is the hours-to-minutes rescaling (height 2 vs height 1/30) still obvious? If yes, the density concept is durably in.