Module contents
Lesson 1 of 24Review 55 min

Probability spaces and Kolmogorov's axioms

A dense review of the Kolmogorov model: a sample space, a family of events and a measure satisfying three axioms. Derive the consequences most used in ML (monotonicity, inclusion–exclusion, the union bound and continuity) and apply them to hash collisions. The rigorous version of a family of events arrives in lesson 3.

After this lesson you can

  • Formulate a random experiment as an explicit probability space (Ω, F, P).
  • Derive complements, monotonicity, inclusion–exclusion and the Bonferroni inequalities from the axioms.
  • Apply the union bound and recognize when it is nearly exact and when it is vacuous.
  • Calculate hash collision probabilities for a truncated hash (birthday paradox), exactly and approximately.
  • Prove continuity of probability and explain why countable additivity is required.

Before you start

Motivation: from frequencies to a model

Almost everything stated numerically in machine learning is a probabilistic claim, and what it is a probability of is rarely made clear.

  • “This classifier fails 3% of the time.” Three percent of which dataset, selected how?
  • “The language model assigns probability 0.40.4 to the next token.” Probability of what event, in what space?
  • “With 10910^9 documents and a 64-bit hash, can two distinct documents share a hash?” Before the lesson ends you will know that yes, with probability near 2.7 %2.7\,\%, and why intuition says it is impossible.

In each case a number is assigned to a set of possible outcomes, and those numbers must combine consistently: if two situations cannot occur together, the probability that either occurs must be their sum. The historical starting point is empirical. If an experiment is repeated nn times and event AA occurs kk times, its relative frequency fn(A)=k/nf_n(A) = k/n satisfies three evident properties: fn(A)≥0f_n(A) \ge 0, fn(todo)=1f_n(\text{todo}) = 1 and fn(A∪B)=fn(A)+fn(B)f_n(A \cup B) = f_n(A) + f_n(B) if AA and BB cannot occur together. In 1933 Andrey Kolmogorov proposed taking those properties, slightly strengthened, as the definition of probability without saying what probability “really” is: a number obeying those rules is a probability. Everything else (laws of large numbers reconnecting with frequencies, the central limit theorem, concentration inequalities) becomes a theorem.

This is a dense review lesson intended to establish vocabulary and proof techniques for the next 23: construct an explicit probability space, derive the rest from axioms, and bound the probability of a union of events, the most-used tool in learning theory. The rigorous definition of a “family of events” (σ-algebra) and measure arrives in lesson 3; here we introduce just enough that nothing asserted is false.

Probability spaces: the triple (Ω,F,P)(\Omega, \mathcal{F}, \Pr)

Modeling a random experiment requires deciding three things, in order: what can happen, what we want to be able to discuss, and how much weight each possibility has.

Events are sets, and operations on sets (set operations) are the connectives of the language: A∪BA \cup B means “AA or BB occurs”, A∩BA \cap B means “both occur”, Ac=Ω∖AA^c = \Omega \setminus A means “AA does not occur”, A⊆BA \subseteq B means “if AA occurs, BB occurs” and A∩B=∅A \cap B = \varnothing means “AA and BB are mutually exclusive” (also called disjoint). Event Ω\Omega is certain and ∅\varnothing impossible. What F\mathcal{F} requires is the minimum for this language to remain in the family: if you can ask about AA and BB, you can ask about “AA or BB”, “not AA” and “some A1,A2,…A_1, A_2, \dots”.

Three sizes of Ω\Omega

Finite. Two dice: Ω={1,…,6}2\Omega = \{1, \dots, 6\}^2 with 36 outcomes. Here F\mathcal{F} is the power set of Ω\Omega and P(A)=∣A∣/36\Pr(A) = \abs{A}/36, because die symmetry justifies weighting all 36 pairs equally.

Countable. Toss a fair coin until heads. The outcome is the number of tosses, Ω={1,2,3,… }\Omega = \{1, 2, 3, \dots\}, and P({k})=2−k\Pr(\{k\}) = 2^{-k}: it takes k−1k - 1 tails and one heads. Weights sum to ∑k≥12−k=1\sum_{k \ge 1} 2^{-k} = 1, as required, and any event is a countable union of points, so its probability is a series. For example, the probability that the first heads arrives on an even toss is ∑j≥12−2j=1/41−1/4=13\sum_{j \ge 1} 2^{-2j} = \tfrac{1/4}{1 - 1/4} = \tfrac{1}{3}. Notice that we already used infinite sums of probabilities: the third axiom justifies doing so.

Continuous. Choose a random point in [0,1][0, 1]: Ω=[0,1]\Omega = [0, 1] and P\Pr assigns each interval its length. Now P({x})=0\Pr(\{x\}) = 0 for every point xx, yet P(Ω)=1\Pr(\Omega) = 1: probability is not obtained by summing point probabilities. And F\mathcal{F} cannot be all subsets of [0,1][0, 1] while preserving what is essential about length: there is no countably additive probability defined on all subsets that, like length, is unchanged by translating a set (within [0,1][0, 1]). Where F\mathcal{F} comes from is the subject of lesson 3.

Construct one yourself

The next figure is the complete finite case. You choose AA and BB (select a preset or paint cells) and the figure computes probabilities as cardinalities divided by 36. On the right is the law of the sum of two dice: bars show the fine-grained model, and you can roll simulated dice to compare frequencies with it.

InteractiveA finite probability space with two dice
123456123456

rows: first die · columns: second die · cell number: sum

  • AA
  • BB
Distribution of sum SS: P(S=s)\Pr(S = s)
0.000.050.100.150.2023456789101112sum s of the two dice
  • fine model: k/36k/36
  • incorrect model: 1/111/11
  • observed frequency (±1.96 standard errors)
Paint on
Incorrect model on chart
P(A)\Pr(A)6/36 = 0.167
P(B)\Pr(B)9/36 = 0.250
P(A∩B)\Pr(A \cap B)0/36 = 0
P(A∪B)\Pr(A \cup B)15/36 = 0.417
P(A)+P(B)−P(A∩B)\Pr(A) + \Pr(B) - \Pr(A \cap B)0.417
P(A)P(B)\Pr(A)\Pr(B)0.042
P(Ac)\Pr(A^c)30/36 = 0.833
Frequencies (3 000 rolls)0.169 and 0.254
A∩B=∅A \cap B = \varnothing: they are disjoint and P(A∪B)=P(A)+P(B)\Pr(A \cup B) = \Pr(A) + \Pr(B). But P(A∩B)=0≠P(A)P(B)\Pr(A\cap B) = 0 \neq \Pr(A)\Pr(B): disjoint does not mean independent.
Choose or paint events AA and BB over the 36 outcomes and read their probabilities. Try ‘sum is 7’ and ‘both are even’: they are disjoint, so P(A∪B)=P(A)+P(B)\Pr(A \cup B) = \Pr(A) + \Pr(B). Then overlap AA and BB and check that P(A∩B)\Pr(A \cap B) must be subtracted. On the right are already 3,000 simulated rolls (add more or clear them): frequencies (with error margin) follow the fine-model bars and diverge from the red line, the model of ‘11 equally likely sums’. Why does that model fail even though it also distributes probability among 11 outcomes?

The red line is an error with history (attributed to Leibniz, who believed sums 11 and 12 from two dice equally probable) and teaches the first modeling rule: equiprobability is not an axiom; it is an assumption that must be earned from symmetry of the experiment. The 11 sums are not interchangeable, because sum 7 can be formed six ways and sum 12 one; the 36 pairs are. The same trap has another familiar form: with two coins, “one heads and one tails” is not one of three cases, but two of four, because {CX,XC}\{\mathrm{CX}, \mathrm{XC}\} are distinct outcomes. When in doubt, refine Ω\Omega until symmetry is obvious, and calculate on the fine space.

Kolmogorov’s axioms

The first two are a scale convention (frequencies lie between 0 and 1) and the third does the work. It is worth pausing on why countable, not just finite, is required.

  • Without it, probabilities of infinite events cannot be computed. In the coin example, P(«sale cara alguna vez»)=P(⋃k{k})\Pr(\text{«sale cara alguna vez»}) = \Pr\big(\bigcup_k \{k\}\big). That this equals ∑k2−k=1\sum_k 2^{-k} = 1 is exactly the third axiom. Finite additivity provides no way to pass from points to an infinite union.
  • Without it, limits do not commute with probabilities. You want to say that if AnA_n grows toward AA, then P(An)→P(A)\Pr(A_n) \to \Pr(A). That is continuity, seen later in this lesson and equivalent to the axiom.
  • It is a property of familiar measures. Length, area and volume are countably additive, and all integration in lesson 5 depends on it.

The cost of requiring it is real: what does not fit must be abandoned. An example is the “uniform” distribution of probability over all natural numbers.

Proof

By the third axiom, 1=P(N)=P(⋃k{k})=∑k≥1c1 = \Pr(\mathbb{N}) = \Pr\big(\bigcup_k \{k\}\big) = \sum_{k \ge 1} c. If c=0c = 0 the sum equals 00, and if c>0c > 0 it equals ∞\infty. Neither case equals 11.

∎

This result and its only reasonable alternative will be shown live at the end of the continuity section.

Immediate consequences

All calculation rules follow from three axioms. None is difficult, but they deserve one careful look, because their proof method (decompose an event into disjoint pieces and apply additivity) is used throughout.

Proof

(1) Apply axiom 3 to A1=ΩA_1 = \Omega and Ak=∅A_k = \varnothing for k≥2k \ge 2 (they are disjoint): P(Ω)=P(Ω)+∑k≥2P(∅)\Pr(\Omega) = \Pr(\Omega) + \sum_{k \ge 2} \Pr(\varnothing). Since P(Ω)=1\Pr(\Omega) = 1 is finite, the series of equal nonnegative terms ∑k≥2P(∅)\sum_{k \ge 2} \Pr(\varnothing) equals 00, forcing P(∅)=0\Pr(\varnothing) = 0.

(2) Complete with Ak=∅A_k = \varnothing for k>nk > n and use (1) and axiom 3.

(3) Ω=A∪Ac\Omega = A \cup A^c with A∩Ac=∅A \cap A^c = \varnothing, hence 1=P(A)+P(Ac)1 = \Pr(A) + \Pr(A^c) by (2).

(4) If A⊆BA \subseteq B, then B=A∪(B∖A)B = A \cup (B \setminus A) is a disjoint union, so P(B)=P(A)+P(B∖A)\Pr(B) = \Pr(A) + \Pr(B \setminus A) by (2), and P(B∖A)≥0\Pr(B \setminus A) \ge 0 by axiom 1.

(5) A⊆ΩA \subseteq \Omega, hence P(A)≤P(Ω)=1\Pr(A) \le \Pr(\Omega) = 1 by (4).

(6) Decompose into disjoint pieces: A∪B=A∪(B∖A)A \cup B = A \cup (B \setminus A) and B=(A∩B)∪(B∖A)B = (A \cap B) \cup (B \setminus A). By (2), P(A∪B)=P(A)+P(B∖A)\Pr(A \cup B) = \Pr(A) + \Pr(B \setminus A) and P(B)=P(A∩B)+P(B∖A)\Pr(B) = \Pr(A \cap B) + \Pr(B \setminus A). Subtract the equalities.

∎

Two observations about what these rules do not say. First, P(A)=0\Pr(A) = 0 does not mean AA is impossible, nor does P(A)=1\Pr(A) = 1 mean it is certain: in [0,1][0, 1] with length, every point has probability 00 and some point occurs. An event of probability 00 is negligible, not empty. Second, events being disjoint is a property of sets and has nothing to do with “not influencing each other”. Indeed, disjoint events of positive probability are never independent in the sense formalized in lesson 2 (P(A∩B)=P(A)P(B)\Pr(A \cap B) = \Pr(A)\Pr(B)): if AA occurs, you know for certain that BB did not. The dice figure shows this in readout P(A)P(B)\Pr(A)\Pr(B) when you choose two disjoint events.

Inclusion–exclusion and Bonferroni inequalities

Rule (6) gives the probability of the union of two events. For nn events a formula with 2n−12^n - 1 terms is needed, already known as the inclusion–exclusion principle, and the important question is what happens if you cut it short. Fix A1,…,An∈FA_1, \dots, A_n \in \mathcal{F} and define, for j=1,…,nj = 1, \dots, n,

Sj=∑1≤i1<⋯<ij≤nP(Ai1∩⋯∩Aij),Tm=∑j=1m(−1)j+1Sj=S1−S2+⋯±Sm.S_j = \sum_{1 \le i_1 < \cdots < i_j \le n} \Pr\big(A_{i_1} \cap \cdots \cap A_{i_j}\big), \qquad T_m = \sum_{j=1}^{m} (-1)^{j+1} S_j = S_1 - S_2 + \cdots \pm S_m .

S1S_1 is the sum of probabilities, S2S_2 that of all pairwise intersections, and so on. The Bonferroni inequalities say that partial sums TmT_m oscillate around union probability, alternating upper and lower bounds until equality at m=nm = n.

Proof

A combinatorial fact. For k≥1k \ge 1 and m≥0m \ge 0, ∑j=0m(−1)j(kj)=(−1)m(k−1m)\sum_{j=0}^m (-1)^j \binom{k}{j} = (-1)^m \binom{k-1}{m}. Prove by induction on mm: for m=0m = 0 both sides equal 11, and if true for mm, adding (−1)m+1(km+1)=(−1)m+1[(k−1m+1)+(k−1m)](-1)^{m+1}\binom{k}{m+1} = (-1)^{m+1}\big[\binom{k-1}{m+1} + \binom{k-1}{m}\big] cancels term (−1)m(k−1m)(-1)^m\binom{k-1}{m} and leaves (−1)m+1(k−1m+1)(-1)^{m+1}\binom{k-1}{m+1}. Thus partial sum tm(k):=∑j=1m(−1)j+1(kj)t_m(k) := \sum_{j=1}^m (-1)^{j+1}\binom{k}{j} equals 1−(−1)m(k−1m)1 - (-1)^m\binom{k-1}{m} if k≥1k \ge 1, and tm(0)=0t_m(0) = 0.

Cells. For each ε∈{0,1}n\varepsilon \in \{0, 1\}^n let Cε=⋂iAi(εi)C_\varepsilon = \bigcap_{i} A_i^{(\varepsilon_i)}, with A(1)=AA^{(1)} = A and A(0)=AcA^{(0)} = A^c. These are 2n2^n pairwise disjoint events whose union is Ω\Omega: each ω\omega belongs to the cell specifying for each ii whether or not it is in AiA_i. Let ∣ε∣=∑iεi\abs{\varepsilon} = \sum_i \varepsilon_i count events containing the ω\omega in the cell. Intersection AS=⋂i∈SAiA_S = \bigcap_{i \in S} A_i is the disjoint union of cells with εi=1\varepsilon_i = 1 for every i∈Si \in S, so its probability is the sum of those cells’ probabilities (rule 2). Summing over all SS with ∣S∣=j\abs{S} = j, each cell appears as many times as jj-element subsets fit in its ∣ε∣\abs{\varepsilon} ones, namely (∣ε∣j)\binom{\abs{\varepsilon}}{j} times:

Sj=∑ε(∣ε∣j)P(Cε),Tm=∑εtm(∣ε∣)P(Cε).S_j = \sum_{\varepsilon} \binom{\abs{\varepsilon}}{j} \Pr(C_\varepsilon), \qquad T_m = \sum_{\varepsilon} t_m(\abs{\varepsilon}) \Pr(C_\varepsilon).

Comparison. The union is the collection of cells with ε≠0\varepsilon \neq \mathbf{0}, so P(⋃iAi)=∑ε≠0P(Cε)\Pr(\bigcup_i A_i) = \sum_{\varepsilon \neq \mathbf{0}} \Pr(C_\varepsilon). Subtracting, and since tm(0)=0t_m(0) = 0 contributes nothing,

Tm−P(⋃iAi)=∑ε≠0(tm(∣ε∣)−1)P(Cε)=(−1)m+1∑ε≠0(∣ε∣−1m)P(Cε).T_m - \Pr\Big(\bigcup_i A_i\Big) = \sum_{\varepsilon \neq \mathbf{0}} \big(t_m(\abs{\varepsilon}) - 1\big)\Pr(C_\varepsilon) = (-1)^{m+1} \sum_{\varepsilon \neq \mathbf{0}} \binom{\abs{\varepsilon} - 1}{m}\Pr(C_\varepsilon).

The binomial coefficients are ≥0\ge 0 and probabilities are too, so the difference has sign (−1)m+1(-1)^{m+1}: positive (upper bound) for odd mm and negative (lower bound) for even mm. For m=nm = n we have ∣ε∣−1<n\abs{\varepsilon} - 1 < n, so all binomial coefficients vanish and equality holds.

∎

The first two orders are used most. m=1m = 1 says P(⋃Ai)≤S1\Pr(\bigcup A_i) \le S_1, the union bound in the next section. m=2m = 2 says P(⋃Ai)≥S1−S2\Pr(\bigcup A_i) \ge S_1 - S_2, giving a useful consequence.

The union bound

The case m=1m = 1, extended to countable families, is the most-used inequality in learning theory, and the one most often applied without noticing.

For a finite family this is exactly T1=S1T_1 = S_1 in the preceding theorem. A countable family requires axiom 3: replace AiA_i with disjoint pieces having the same union, Bi=Ai∖⋃k<iAkB_i = A_i \setminus \bigcup_{k<i} A_k, and use monotonicity, P(Bi)≤P(Ai)\Pr(B_i) \le \Pr(A_i). This is the first of the two proof exercises at the end, which you will do step by step.

The inequality is always true and sometimes useless. It is true because it uses only the axioms, with no assumption about relationships among events. It is useless when ∑iP(Ai)≥1\sum_i \Pr(A_i) \ge 1, because we already knew P≤1\Pr \le 1. Between these extremes, its quality depends on overlap, measured by the next figure.

InteractiveInclusion–exclusion versus the union bound
Ω, area 1
  • AA
  • BB
  • CC
1S₁ (union bound)0.600S₁ − S₂ (Bonferroni lower)0.433S₁ − S₂ + S₃ (exact)0.457
0.20
0.20
0.20
Exact P(A∪B∪C)\Pr(A \cup B \cup C)0.457
S1=∑P(Ai)S_1 = \sum \Pr(A_i), union bound0.600
Bound error, S1−P(∪)S_1 - \Pr(\cup)0.143
S2=∑i<jP(Ai∩Aj)S_2 = \sum_{i<j} \Pr(A_i \cap A_j), its ceiling0.167
S3=P(A∩B∩C)S_3 = \Pr(A \cap B \cap C)0.024
S1−S2S_1 - S_2, lower bound0.433
Three events in the unit square with uniform probability: each probability is the area of its disk. Drag centers and change areas. Below, Bonferroni bounds of orders 1, 2 and 3 are compared with exact probability (magenta line). Start with ‘Almost disjoint’: how far off is S1S_1? Then choose ‘Almost equal’: what are S1S_1 and the actual union? Finally, with ‘Large, triple overlap’, inspect how far S1−S2S_1 - S_2 is below exact and compare with S3S_3: for three events that error is exactly P(A∩B∩C)\Pr(A \cap B \cap C). Also check that S1S_1 error never exceeds S2S_2.

Three things shown by the figure are worth remembering:

  1. Rare overlap ⇒ nearly exact bound. If each event is rare and they almost never coincide, the union is almost disjoint and S1≈P(⋃)S_1 \approx \Pr(\bigcup). This is why the bound works well for small failure probabilities.
  2. Heavy overlap ⇒ vacuous bound. Three almost identical events of probability 0.40.4 give S1=1.2S_1 = 1.2 while the union is little more than 0.40.4. The bound is not “wrong”: it says a truth without content.
  3. Next order controls error. S1−S2≤P(⋃)≤S1S_1 - S_2 \le \Pr(\bigcup) \le S_1 bounds probability between two computable values. When S2S_2 is small relative to S1S_1 there is no need to go further. For three events the error formula says it all: S1S_1 exceeds by the probability of zones with exactly two events plus twice the triple zone, and S1−S2S_1 - S_2 falls short by exactly S3=P(A∩B∩C)S_3 = \Pr(A \cap B \cap C), so the lower bound’s error is never more than half the upper bound’s.

Uses

The union bound converts an individual guarantee into a simultaneous one. If you have mm “bad” events A1,…,AmA_1, \dots, A_m and each has probability P(Ai)≤δ/m\Pr(A_i) \le \delta/m, the probability any occurs is at most δ\delta, and with probability at least 1−δ1 - \delta none occurs. No independence assumption is needed.

  • Multiple testing. If you perform mm hypothesis tests and want probability of any false positive at most α\alpha, use level α/m\alpha/m in each: the Bonferroni correction. With m=20m = 20 tests at level 0.050.05 the union bound gives 20⋅0.05=120 \cdot 0.05 = 1, which says nothing (and for independent tests the actual probability of any false positive is 1−0.9520≈0.641 - 0.95^{20} \approx 0.64). With level 0.05/20=0.00250.05/20 = 0.0025 actual risk is 0.04880.0488 and bound 0.050.05 is nearly exact.
  • Finite hypothesis classes. If class H\mathcal{H} has ∣H∣\abs{\mathcal{H}} classifiers and each has probability ≤δ′\le \delta' that empirical error differs from true error by more than ε\eps, then with probability ≥1−∣H∣δ′\ge 1 - \abs{\mathcal{H}}\delta' all are simultaneously within ε\eps. When δ′\delta' decays exponentially with sample size nn (Hoeffding’s inequality gives δ′=2e−2nε2\delta' = 2e^{-2n\eps^2}), asking for δ′=δ/∣H∣\delta' = \delta/\abs{\mathcal{H}} only changes required sample size from log⁡(2/δ)/(2ε2)\log(2/\delta)/(2\eps^2) to (log⁡∣H∣+log⁡(2/δ))/(2ε2)\big(\log\abs{\mathcal{H}} + \log(2/\delta)\big)/(2\eps^2): an additive log⁡∣H∣\log \abs{\mathcal{H}}, not a factor ∣H∣\abs{\mathcal{H}}. This is the first result of PAC learning for finite classes.
  • Collisions. The next section uses it on (n2)\binom{n}{2} pairs of elements.

Birthdays and hash collisions

A bb-bit hash assigns each element one of N=2bN = 2^b values. If elements have no relationship to values (the idealized model of a good hash function), each lands on a uniform value independently of the others. Intuition says that with NN values, roughly NN elements will be needed before collisions appear, or at least N/2N/2. That is false. Let us calculate.

The space. Insert nn elements: Ω={1,…,N}n\Omega = \{1, \dots, N\}^n, all possible assignments, with uniform probability (all NnN^n are equiprobable by independence and uniformity of each element). The event “no collision” consists of assignments with distinct values, of which there are N(N−1)⋯(N−n+1)N(N-1)\cdots(N-n+1) (the arrangements of nn from NN). Thus

P(no hay colisioˊn)=N(N−1)⋯(N−n+1)Nn=∏i=1n−1(1−iN).\Pr(\text{no hay colisión}) = \frac{N(N-1)\cdots(N-n+1)}{N^n} = \prod_{i=1}^{n-1}\Big(1 - \frac{i}{N}\Big).

That formula is exact but opaque. Understanding it needs two bounds, one on each side, both from this lesson.

Above: the union bound. Let EijE_{ij} be the event “elements ii and jj have the same hash”. Each has probability 1/N1/N (the second lands where the first did). There are (n2)\binom{n}{2} pairs, and “a collision occurs” is the union of all EijE_{ij}, so

P(colisioˊn)≤(n2)1N=n(n−1)2N=:λ.\Pr(\text{colisión}) \le \binom{n}{2}\frac{1}{N} = \frac{n(n-1)}{2N} =: \lambda.

Below: 1−x≤e−x1 - x \le e^{-x}. Applied to each factor, ∏i<n(1−i/N)≤exp⁡(−∑i<ni/N)=e−λ\prod_{i<n}(1 - i/N) \le \exp(-\sum_{i<n} i/N) = e^{-\lambda}, so P(colisioˊn)≥1−e−λ\Pr(\text{colisión}) \ge 1 - e^{-\lambda}.

And the upper bound for no collision. For 0≤x≤1/20 \le x \le 1/2, 1−x≥e−x−x21 - x \ge e^{-x - x^2} holds because −ln⁡(1−x)=x+x22+x33+⋯≤x+x22(1+x+x2+⋯ )=x+x22(1−x)≤x+x2-\ln(1-x) = x + \tfrac{x^2}{2} + \tfrac{x^3}{3} + \cdots \le x + \tfrac{x^2}{2}(1 + x + x^2 + \cdots) = x + \tfrac{x^2}{2(1-x)} \le x + x^2. If n≤N/2+1n \le N/2 + 1, all i/Ni/N lie in that range and, since ∑i<ni2≤n3/3\sum_{i<n} i^2 \le n^3/3, this yields ∏i<n(1−i/N)≥exp⁡(−λ−n3/(3N2))\prod_{i<n}(1 - i/N) \ge \exp\big(-\lambda - n^3/(3N^2)\big).

The name “birthday paradox” comes from the case of birthdays, seen shortly. Notice what the approximation says. Everything depends on n2/Nn^2/N: with n=xNn = x\sqrt{N} this gives 1−e−x2/21 - e^{-x^2/2}, one curve for every hash size. Collision appears when nn is of order N\sqrt{N}, not NN. Half the time it already occurs with n=2ln⁡2 N≈1.18Nn = \sqrt{2\ln 2\, N} \approx 1.18\sqrt{N}. The classic 365 dates: 2ln⁡2⋅365≈22.5\sqrt{2 \ln 2 \cdot 365} \approx 22.5, and with n=23n = 23 people exact probability is 0.50730.5073.

InteractiveCollisions in a b-bit hash
  • exact
  • approximation 1−e−n2/2N1 - e^{-n^2/2N}
  • union bound n(n−1)/2Nn(n-1)/2N
20 (N = 1.0 × 10⁶)
1 024
Horizontal axis
Exact P(collision)\Pr(\text{collision})0.393
Approximation 1−e−n2/2N1 - e^{-n^2/2N}0.393
Union bound0.500
Simulated (0 trials)simulating…
N=2bN = 2^b and N\sqrt{N}1.0 × 10⁶ and 1 024
n/Nn/N0.0977 %
nn for 50 %50\,\% collision1 206 ≈ 1.18 √N
Choose bits bb and number of elements nn. The blue curve is exact probability; dashed curves show exponential approximation and union bound; the magenta curve is collision frequency in simulations in your browser (each trial inserts random values until the first collision). Switch to the n/Nn/\sqrt{N} axis and vary bb: what happens to curves? Then increase nn until the union bound reaches 1 and lower bb to 8: when does the exponential approximation stop being good?

What playing with the figure teaches: on axis nn, curves for different bb are the same shifted curve: each extra bit multiplies the collision point by 2\sqrt{2}. On axis n/Nn/\sqrt{N} they overlap, and only because probability depends on nn and NN through n2/Nn^2/N alone. The union bound is good while λ\lambda is small and then sticks to ceiling 11. The exponential approximation, read as collision probability, is excellent across the range: when it starts to fail, both are nearly 11. What deteriorates is no-collision probability in relative terms as soon as n3n^3 stops being small relative to N2N^2, around n∼N2/3n \sim N^{2/3} (with b=8b = 8, about 40 elements). At extreme n=Nn = N no-collision probability is N!/NN≈2πN e−NN!/N^N \approx \sqrt{2\pi N}\, e^{-N} (Stirling), whereas the approximation gives e−N/2e^{-N/2}: an error by a factor of order eN/2e^{N/2} in that tail.

Here are the numbers that matter in practice. To find nn giving collision probability pp, solve for n≈2Nln⁡(1/(1−p))n \approx \sqrt{2N\ln(1/(1-p))}:

bits bbnn for p=50 %p = 50\,\%nn for p=10−6p = 10^{-6}
327.7×1047.7 \times 10^49393
645.1×1095.1 \times 10^96.1×1066.1 \times 10^6
1282.2×10192.2 \times 10^{19}2.6×10162.6 \times 10^{16}
2564.0×10384.0 \times 10^{38}4.8×10354.8 \times 10^{35}

Three consequences revisited in other modules. A 32-bit hash supports only tens of elements if collision risk must be below one in a million, and is useless for deduplicating large collections: with 10510^5 documents collision probability is already 69 %69\,\%. A 64-bit hash handles millions of elements at one-in-a-million risk, but with 10910^9 documents it is already 2.7 %2.7\,\%, answering the opening question. And in security, collision resistance of an bb-bit cryptographic digest is only about b/2b/2 bits: an attacker who can choose inputs need not search 2b2^b values, about 2b/22^{b/2} suffice (the birthday attack). That is why signatures and content identifiers needing adversarial resistance use digests of 256 bits or more: size bb using this calculation, not intuition.

One last connection with Bonferroni. Events EijE_{ij} are pairwise independent (two distinct pairs share at most one element, and P(Eij∩Eik)=P(hi=hj=hk)=1/N2\Pr(E_{ij} \cap E_{ik}) = \Pr(h_i = h_j = h_k) = 1/N^2), but not mutually independent. This allows calculating S2=(M2)/N2S_2 = \binom{M}{2}/N^2 with M=(n2)M = \binom{n}{2} and obtaining a Bonferroni lower bound. For N=365N = 365 and n=23n = 23, M=253M = 253, S1=0.6932S_1 = 0.6932, S2=0.2393S_2 = 0.2393 and

0.4539=S1−S2 ≤ P(colisioˊn)=0.5073 ≤ S1=0.6932.0.4539 = S_1 - S_2 \ \le\ \Pr(\text{colisión}) = 0.5073 \ \le\ S_1 = 0.6932 .

Bound 1−e−λ=0.50001 - e^{-\lambda} = 0.5000 is much better than S1−S2S_1 - S_2: finer bounds than Bonferroni exist when problem structure is known.

Continuity of probability

Probability is a set function, and sets have limits. If a sequence of events A1,A2,…A_1, A_2, \dots increases or decreases monotonically, its set limit exists: union or intersection.

  • An↑AA_n \uparrow A means A1⊆A2⊆⋯A_1 \subseteq A_2 \subseteq \cdots and A=⋃nAnA = \bigcup_n A_n.
  • An↓AA_n \downarrow A means A1⊇A2⊇⋯A_1 \supseteq A_2 \supseteq \cdots and A=⋂nAnA = \bigcap_n A_n.

Continuity of probability says the limit of probabilities is the probability of the limit.

Proof

(1) Define D1=A1D_1 = A_1 and Dn=An∖An−1D_n = A_n \setminus A_{n-1} for n≥2n \ge 2. They are disjoint, ⋃k≤nDk=An\bigcup_{k \le n} D_k = A_n and ⋃kDk=A\bigcup_k D_k = A. By axiom 3 and finite additivity,

P(A)=∑k=1∞P(Dk)=lim⁡n→∞∑k=1nP(Dk)=lim⁡n→∞P(An).\Pr(A) = \sum_{k=1}^{\infty} \Pr(D_k) = \lim_{n \to \infty} \sum_{k=1}^n \Pr(D_k) = \lim_{n \to \infty} \Pr(A_n).

Monotonicity of P(An)\Pr(A_n) is rule 4.

(2) Complements satisfy Anc↑AcA_n^c \uparrow A^c (De Morgan’s laws), so by (1) P(Anc)→P(Ac)\Pr(A_n^c) \to \Pr(A^c), and P(An)=1−P(Anc)→1−P(Ac)=P(A)\Pr(A_n) = 1 - \Pr(A_n^c) \to 1 - \Pr(A^c) = \Pr(A).

(3) Countable additivity implies (1) and (2) as shown, and continuity at ∅\varnothing is a special case of (2). It remains to show continuity at ∅\varnothing implies countable additivity (that continuity from below implies it is the second proof exercise at the end). If B1,B2,…B_1, B_2, \dots are disjoint with union BB, remainders Rn=⋃k>nBkR_n = \bigcup_{k > n} B_k satisfy Rn↓∅R_n \downarrow \varnothing, so P(Rn)→0\Pr(R_n) \to 0. By finite additivity, P(B)=∑k≤nP(Bk)+P(Rn)\Pr(B) = \sum_{k \le n} \Pr(B_k) + \Pr(R_n), and letting n→∞n \to \infty yields P(B)=∑kP(Bk)\Pr(B) = \sum_k \Pr(B_k).

∎

Two typical uses. First, probabilities of “infinite” events approximated by finite ones: the probability a fair coin never gives heads is P(⋂nAn)\Pr(\bigcap_n A_n), with An={las n primeras son cruz}A_n = \{\text{las } n \text{ primeras son cruz}\} and P(An)=2−n↓0\Pr(A_n) = 2^{-n} \downarrow 0, so it equals 00 by continuity from above. It is a nonempty event (sequence XXXX⋯\mathrm{XXXX}\cdots exists) with zero probability. Second, An=[0,1/n]↓{0}A_n = [0, 1/n] \downarrow \{0\} in [0,1][0, 1] with length: P(An)=1/n→0=P({0})\Pr(A_n) = 1/n \to 0 = \Pr(\{0\}).

The impossible uniform distribution and its only consolation

Now we understand uniform allocation on N\mathbb{N}. There is a “limit” version that does exist, natural density d(A)=lim⁡N→∞∣A∩{1,…,N}∣/Nd(A) = \lim_{N \to \infty} \abs{A \cap \{1, \dots, N\}}/N, giving d(pares)=1/2d(\text{pares}) = 1/2 and d(muˊltiplos de k)=1/kd(\text{múltiplos de } k) = 1/k. It is the closest thing to uniform probability on N\mathbb{N}. And it fails precisely where the axioms predict. The figure has two tabs: the first lets you change mass cc per point, the second studies natural density.

InteractiveThe impossible uniform distribution on ℕ
  • partial sum ∑k≤Nc=Nc\sum_{k \le N} c = Nc
  • required total mass: 1
e = −4.0
Total mass ∑k≥1c\sum_{k \ge 1} c∞
NN where the sum exceeds 1N > 1.0 × 10⁴
Sum of the first 101010^{10} points1.0 × 10⁶
With c>0c > 0 the sum diverges: ∑c=∞≠1\sum c = \infty \neq 1. No cc normalizes.
First tab: give equal mass cc to every natural number. The first NN terms sum to NcNc: it exceeds 1 once N>1/cN > 1/c, and with c=0c = 0 never reaches it. Second tab: natural density. With ‘Even numbers’ and their complement, finite additivity works. With ‘One point’, each set {k}\{k\} has density 0 but N\mathbb{N} has density 1. With ‘The tail’ a decreasing sequence of density-1 sets has empty intersection. With ‘Blocks’ a set has no density. Which axiom, or consequence of the axioms, fails in each case?

The second tab shows symptoms of the same issue. Natural density is finitely additive where defined, but:

  • d({k})=0d(\{k\}) = 0 for each kk while d(N)=1d(\mathbb{N}) = 1: not countably additive.
  • Am={k>m}↓∅A_m = \{k > m\} \downarrow \varnothing but d(Am)=1d(A_m) = 1 for every mm: not continuous from above, which by (3) of the preceding theorem is the same lack of countable additivity.
  • It is not defined for all subsets, and even subsets with density do not form a family closed under intersections. Blocks E=⋃j[4j,2⋅4j)E = \bigcup_j [4^j, 2\cdot 4^j) have no density (it oscillates between 1/31/3 and 2/32/3). Set B=(E∩pares)∪(Ec∩impares)B = (E \cap \text{pares}) \cup (E^c \cap \text{impares}) has density 1/21/2 (counting by intervals shows evens and odds split equally in each block), as do the evens, but B∩pares=E∩paresB \cap \text{pares} = E \cap \text{pares} has frequency of EE divided by two and also has no density.

Does a probability exist on all subsets of N\mathbb{N} that equals 00 at each point? Yes, finitely additive: it is constructed using ultrafilters or Hahn–Banach (a “Banach limit” on indicators), but the construction is not explicit and is not countably additive, as shown impossible. The moral is the opening one: countable additivity is a requirement paid for by abandoning uniformity on N\mathbb{N}, a price gladly paid because limits then behave well.

What remains

We used F\mathcal{F} without saying where it comes from, the gap lesson 3 fills. For finite or countable Ω\Omega, F=2Ω\mathcal{F} = 2^{\Omega} works and nothing more is needed. For Ω=[0,1]\Omega = [0, 1], Vitali’s theorem guarantees no function on all subsets exists that is countably additive, translation invariant and gives [0,1][0,1] measure 11. One must choose a smaller family (the Borel σ-algebra), and existence of P\Pr (Lebesgue measure) is then a construction theorem, not an axiom. Also pending: what P(A∣B)\Pr(A \given B) means (lesson 2), how frequencies converge to probabilities (lesson 17), and probabilities of events depending on many variables at once (product measures, lesson 7).

Implementation from scratch

Start with the finite, completely exact case. Represent Ω\Omega as a set, P\Pr as a mass dictionary with Fraction (rational arithmetic: no rounding error, so axioms hold with equality), events as subsets and truncated inclusion–exclusion as a sum over subfamilies. Finite additivity is verified over all disjoint event pairs of a small space.

[ ]A finite probability space from scratchBrowser
from fractions import Fraction
from itertools import combinations, product
from math import comb

class EspacioFinito:
    """(Ω, 2^Ω, P) con Ω finito: P se guarda como la masa de cada resultado."""

    def __init__(self, masas):
        self.masa = {w: Fraction(m) for w, m in masas.items()}
        self.omega = frozenset(self.masa)

    def axiomas(self):
        assert all(m >= 0 for m in self.masa.values()), "falla el axioma 1: hay masas negativas"
        assert sum(self.masa.values()) == 1, "falla el axioma 2: P(Ω) ≠ 1"
        return True

    def P(self, suceso):
        suceso = frozenset(suceso)
        assert suceso <= self.omega, "un suceso es un subconjunto de Ω"
        return sum((self.masa[w] for w in suceso), Fraction(0))

    def union_ie(self, sucesos, orden=None):
        """Suma alternada de Bonferroni hasta `orden` (None = inclusión-exclusión completa)."""
        n = len(sucesos)
        orden = n if orden is None else orden
        total = Fraction(0)
        for j in range(1, orden + 1):
            S_j = sum(self.P(frozenset.intersection(*[frozenset(sucesos[i]) for i in idx]))
                      for idx in combinations(range(n), j))
            total += (-1) ** (j + 1) * S_j
        return total

# dos dados: Ω = {1..6}², los 36 resultados equiprobables
dados = EspacioFinito({w: Fraction(1, 36) for w in product(range(1, 7), repeat=2)})
print("axiomas:", dados.axiomas())

A = [w for w in dados.omega if w[0] % 2 == 0 and w[1] % 2 == 0]  # los dos pares
B = [w for w in dados.omega if max(w) >= 5]                       # máximo al menos 5
C = [w for w in dados.omega if w[0] == w[1]]                      # un doble
print("P(A), P(B), P(C) =", dados.P(A), dados.P(B), dados.P(C))

# aditividad finita: para TODOS los pares de sucesos disjuntos de un Ω pequeño
chico = EspacioFinito({"a": Fraction(1, 2), "b": Fraction(1, 3), "c": Fraction(1, 6)})
partes = [frozenset(s) for r in range(4) for s in combinations(chico.omega, r)]
pares = [(X, Y) for X in partes for Y in partes if not (X & Y)]
assert all(chico.P(X | Y) == chico.P(X) + chico.P(Y) for X, Y in pares)
print(f"aditividad finita verificada en {len(pares)} pares disjuntos de sucesos")

# unión exacta frente a inclusión-exclusión y a sus truncaciones
sucesos = [A, B, C]
exacta = dados.P(frozenset(A) | frozenset(B) | frozenset(C))
print("\nP(A ∪ B ∪ C) directa:", exacta, "=", float(exacta))
for m in (1, 2, 3):
    v = dados.union_ie(sucesos, m)
    lado = "cota superior" if m % 2 else "cota inferior"
    print(f"  orden {m}: {str(v):>6s} = {float(v):.4f}   ({lado}, error {float(abs(v - exacta)):.4f})")
assert dados.union_ie(sucesos) == exacta

# el modelo erróneo de Leibniz: 11 sumas «equiprobables»
suma = lambda w: w[0] + w[1]
print("\nP(suma = 7): fino =", dados.P([w for w in dados.omega if suma(w) == 7]), " erróneo = 1/11 =", round(1 / 11, 4))

The result agrees with theory: P(A∪B∪C)=13/18\Pr(A \cup B \cup C) = 13/18, the order-1 bound is 35/3635/36 (exactly 0.250.25 above), order 2 is 0.02780.0278 below, and order 3, the complete formula, is exact. Upper, lower, exact alternation is the theorem’s.

Now hash collisions. We calculate three theoretical quantities and a simulation with a real hash: the first bb bits of SHA-256, applied to distinct inputs. Two numerical precautions matter. Sum ∑ilog⁡(1−i/N)\sum_i \log(1 - i/N) uses log1p, which does not lose digits when i/Ni/N is tiny, and probability 1−e−x1 - e^{-x} uses expm1 for the same reason.

[ ]Hash collisions: exact, approximate, union bound and simulationBrowser
import hashlib, math, random

def p_exacta(n, N):
    """P(al menos una colisión) = 1 − ∏_{i=1}^{n−1} (1 − i/N), con log1p y expm1 para no perder cifras."""
    if n > N:
        return 1.0
    return -math.expm1(sum(math.log1p(-i / N) for i in range(1, n)))

def p_union(n, N):
    return min(1.0, n * (n - 1) / (2 * N))

def p_aprox(n, N):
    return -math.expm1(-n * n / (2 * N))

def hash_b_bits(dato: bytes, b: int) -> int:
    """Los b primeros bits de SHA-256 (b ≤ 64)."""
    return int.from_bytes(hashlib.sha256(dato).digest()[:8], "big") >> (64 - b)

def simula(n, b, pruebas, semilla=0):
    rng = random.Random(semilla)
    colisiones = 0
    for _ in range(pruebas):
        base = rng.getrandbits(64).to_bytes(8, "big")       # cada prueba usa entradas nuevas
        vistos = set()
        for i in range(n):
            h = hash_b_bits(base + i.to_bytes(4, "big"), b)
            if h in vistos:
                colisiones += 1
                break
            vistos.add(h)
    return colisiones / pruebas

print(f"{'b':>3} {'n':>6} {'exacta':>8} {'1-exp(-n²/2N)':>14} {'unión':>7} {'simulada':>9}")
for b, n in [(16, 100), (16, 300), (16, 600), (20, 1000)]:
    N = 2 ** b
    sim = simula(n, b, 300, semilla=1)
    print(f"{b:>3} {n:>6} {p_exacta(n, N):8.4f} {p_aprox(n, N):14.4f} {p_union(n, N):7.4f} {sim:9.3f}")

# el cumpleaños clásico
print("\nN = 365, n = 23:  exacta", round(p_exacta(23, 365), 4), " aprox", round(p_aprox(23, 365), 4),
      " unión", round(p_union(23, 365), 4), "  con n(n-1):", round(-math.expm1(-23 * 22 / (2 * 365)), 4))
M = 23 * 22 // 2
S1, S2 = M / 365, M * (M - 1) / 2 / 365 ** 2
print(f"Bonferroni: {S1 - S2:.4f} <= P <= {S1:.4f}")

# fuera de régimen: n comparable a N, mirando la probabilidad de NO colisión
for b, n in [(8, 20), (8, 40), (8, 100)]:
    N = 2 ** b
    q_ex, q_ap = 1 - p_exacta(n, N), math.exp(-n * n / (2 * N))
    print(f"b = {b}, n = {n:>3}:  P(no colisión) exacta {q_ex:.3e}   aproximada {q_ap:.3e}   cociente {q_ap / q_ex:.2f}")

Table rows match theory within the margin of a 300-trial simulation (typical error between 0.0140.014 and 0.0290.029): exact and approximate are almost indistinguishable while n≪Nn \ll N, and the union bound starts diverging when λ\lambda stops being small. The last lines show approximation failure as nn approaches NN: with b=8b = 8 and n=100n = 100, the no-collision probability, 1.7×10−101.7 \times 10^{-10}, is nearly twenty times greater in the approximation.

The professional version

NumPy vectorizes the cumulative logarithm sum, giving the entire curve in one pass. The standard library already includes numerically safe functions (log1p, expm1) needed when probabilities are tiny, as usual with long hashes.

[ ]Curves with NumPy, and why expm1Browser
import math
import numpy as np
import matplotlib.pyplot as plt

def curva_exacta(N, ns):
    """P(colisión) en cada n de `ns`: una sola suma acumulada vectorizada de log(1 − i/N)."""
    ns = np.asarray(ns)
    L = np.concatenate([[0.0], np.cumsum(np.log1p(-np.arange(1, ns.max()) / N))])
    return -np.expm1(L[ns - 1])

fig, ax = plt.subplots(figsize=(6.4, 3.4))
for b in (12, 16, 20):
    N = 2 ** b
    ns = np.unique(np.geomspace(2, 6 * math.sqrt(N), 120).astype(int))
    ax.plot(ns / math.sqrt(N), curva_exacta(N, ns), label=f"b = {b}")
x = np.geomspace(0.02, 6, 200)
ax.plot(x, -np.expm1(-x**2 / 2), "k--", label="1 − exp(−x²/2)")
ax.set_xscale("log"); ax.set_xlabel("n / √N"); ax.set_ylabel("P(colisión)"); ax.legend()
plt.show()

# 1 − exp(−λ) pierde todas las cifras cuando λ es diminuto; expm1 no
for b, n in [(128, 2**40), (256, 2**60)]:
    lam = n * (n - 1) / (2 * 2.0**b)
    print(f"b = {b:3d}, n = 2^{int(math.log2(n))}:  1 − exp(−λ) = {1 - np.exp(-lam):.3e}   −expm1(−λ) = {-np.expm1(-lam):.3e}")

def n_para_riesgo(b, p):
    """Menor n con P(colisión) ≈ p, despejando 1 − exp(−n²/2N) = p."""
    return math.sqrt(-2 * 2.0**b * math.log1p(-p))

print()
for b in (32, 64, 128, 256):
    print(f"b = {b:3d}:  p = 50 % para n ≈ {n_para_riesgo(b, 0.5):.3g};   p = 1e-6 para n ≈ {n_para_riesgo(b, 1e-6):.3g}")

# deduplicar 10^9 documentos con un hash de 64 bits
n, b = 10**9, 64
print(f"\n10^9 documentos, hash de 64 bits: P(alguna colisión falsa) = {-np.expm1(-n * (n - 1) / (2 * 2.0**b)):.4f}")
b_min = next(b for b in range(40, 200) if -math.expm1(-n * (n - 1) / (2 * 2.0**b)) <= 1e-6)
print("bits mínimos para que sea ≤ 1e-6:", b_min)

The first figure reproduces collapse of the interactive figure: three curves for hash sizes differing by a factor 1616 become one on axis n/Nn/\sqrt{N} and follow the universal curve. In the text output, comparing 1 - np.exp(-lam) with -np.expm1(-lam) explains why serious libraries’ functions of this kind use expm1: with a 256-bit hash and 2602^{60} elements, real probability is 5.7×10−425.7 \times 10^{-42} and the naive version returns exactly 00, answering “collision is impossible” when it is “almost impossible but nonzero”. Dependence on set size is the last line: deduplicating 10910^9 documents with false-collision risk below 10−610^{-6} requires 79 bits, not 64.

Common errors

Exercises

QuizDisjoint and independent
Let AA and BB be disjoint events with P(A)=0.3\Pr(A) = 0.3 and P(B)=0.4\Pr(B) = 0.4. Which statement is correct?
NumericUnion of three events
For three events P(A)=0.5\Pr(A) = 0.5, P(B)=0.4\Pr(B) = 0.4, P(C)=0.3\Pr(C) = 0.3, P(A∩B)=0.2\Pr(A \cap B) = 0.2, P(A∩C)=0.1\Pr(A \cap C) = 0.1, P(B∩C)=0.1\Pr(B \cap C) = 0.1 and P(A∩B∩C)=0.05\Pr(A \cap B \cap C) = 0.05. Calculate P(A∪B∪C)\Pr(A \cup B \cup C).
QuizWhich way does each bound point?
Let A1,…,A4A_1, \dots, A_4 be arbitrary events, SjS_j the sum of probabilities of intersections jj at a time in groups of jj, and U=P(A1∪A2∪A3∪A4)U = \Pr(A_1 \cup A_2 \cup A_3 \cup A_4). Which inequalities always hold?

More than one answer may be correct.

Numeric2²⁰ elements in a 40-bit hash
You insert 2202^{20} elements into a table with a uniform 40-bit hash. Approximately what is the probability of at least one collision?
NumericHow many bits to deduplicate?
You will deduplicate n=109n = 10^9 documents with a bb-bit hash. What is the smallest integer number of bits bb ensuring false-collision probability at most 10−610^{-6}? Use 1−e−n(n−1)/(2N)1 - e^{-n(n-1)/(2N)} with N=2bN = 2^b.
QuizDoes a uniform probability on ℕ exist?
Which statement about a “uniform” allocation of probability on natural numbers is correct?
ProofThe countable union bound
Prove: If A1,A2,⋯∈FA_1, A_2, \dots \in \mathcal{F}, then P(⋃iAi)≤∑iP(Ai)\Pr\big(\bigcup_{i} A_i\big) \le \sum_{i} \Pr(A_i).
0
Start only from the three axioms and elementary rules (including monotonicity). The AiA_i can overlap, so direct summation is impossible.

Step 1 of 4. How do you turn the union into a disjoint union?

ProofFinite additivity and continuity from below imply countable additivity
Prove: Let P\Pr be a function on F\mathcal{F} with P≥0\Pr \ge 0, P(Ω)=1\Pr(\Omega) = 1 and finite additivity. If it is also continuous from below (if Cn↑CC_n \uparrow C then P(Cn)→P(C)\Pr(C_n) \to \Pr(C)), it is countably additive.
0
Let B1,B2,⋯∈FB_1, B_2, \dots \in \mathcal{F} be pairwise disjoint and B=⋃kBkB = \bigcup_k B_k. Prove P(B)=∑kP(Bk)\Pr(B) = \sum_k \Pr(B_k).

Step 1 of 3. Which increasing sequence do you construct?

NumericBonferroni correction in practice
You perform m=20m = 20 independent tests of true null hypotheses, each at level α′=0.05/20=0.0025\alpha' = 0.05/20 = 0.0025 (Bonferroni correction for global level 0.050.05). What is the exact probability of at least one false positive? (Answer to four decimal places.)
CodeInclusion–exclusion with an oracle
Implement union_ie(n, inter, m=None), returning P(A1∪⋯∪An)\Pr(A_1 \cup \cdots \cup A_n) by inclusion–exclusion, truncated at order m if supplied (Bonferroni bound TmT_m) or complete if m is None. Oracle inter(S) receives a tuple S of distinct increasing indices (0 to n-1) and returns P(⋂i∈SAi)\Pr(\bigcap_{i \in S} A_i). You may call inter only on subsets of size at most m.
from itertools import combinations

def union_ie(n, inter, m=None):
  """P(A_1 ∪ ... ∪ A_n). inter(S) devuelve P(∩_{i∈S} A_i) para una tupla S de índices.
  Con m, trunca la fórmula en el orden m (cota de Bonferroni); con m=None es la fórmula completa."""
  m = n if m is None else m
  # tu código: Σ_{j=1}^{m} (-1)^(j+1) Σ_{|S|=j} inter(S)
  return 0.0
Shift+Enter to run

Summary

Key idea
A probability space (Ω,F,P)(\Omega, \mathcal{F}, \Pr) is a set of outcomes, family of events and measure satisfying three axioms; all probability calculation follows from decomposing events into disjoint pieces and applying additivity.
  • The axioms are nonnegativity, normalization P(Ω)=1\Pr(\Omega) = 1 and countable additivity. They imply P(∅)=0\Pr(\varnothing) = 0, complement, monotonicity and P(A∪B)=P(A)+P(B)−P(A∩B)\Pr(A \cup B) = \Pr(A) + \Pr(B) - \Pr(A \cap B). Equiprobability is an assumption requiring symmetry, not an axiom.
  • Inclusion–exclusion gives exact union probability, and partial sums Tm=S1−S2+⋯±SmT_m = S_1 - S_2 + \cdots \pm S_m are alternating bounds: upper for odd mm, lower for even mm. The cell proof gives explicit error.
  • The union bound, P(⋃Ai)≤∑P(Ai)\Pr(\bigcup A_i) \le \sum \Pr(A_i), is always true, nearly exact for barely overlapping events (error at most S2S_2), and vacuous when ∑P(Ai)≥1\sum \Pr(A_i) \ge 1. It converts individual guarantees into simultaneous ones by splitting failure budget.
  • In an bb-bit hash collision appears with n≈1.18Nn \approx 1.18\sqrt{N} elements (N=2bN = 2^b), not N/2N/2: P(colisioˊn)≈1−e−n2/2N\Pr(\text{colisión}) \approx 1 - e^{-n^2/2N} when n3≪N2n^3 \ll N^2. Collision resistance of an bb-bit digest is about b/2b/2 bits.
  • Probability continuity for monotone sequences is equivalent to countable additivity (given finite additivity). Its absence disqualifies natural density as “uniform on N\mathbb{N}”.
  • Which subsets are events remains open (lesson 3): one cannot take F=2Ω\mathcal{F} = 2^{\Omega} when Ω\Omega is continuous.