Rules of Probability
A handful of rules follow from the definition , and they let you compute probabilities of complicated events from simpler ones without listing outcomes.
The basic rules
For events , in a sample space :
- , , .
- Complement: .
- Monotonicity: if then .
- Disjoint additivity: if then .
- Inclusion-exclusion: .
- Union bound: .
Each follows by splitting sums over outcomes. For rule 5, the outcomes in are counted twice in , so subtract them once, exactly as in counting with inclusion-exclusion.
Checking the rules on dice
from fractions import Fraction
from itertools import product
omega = list(product(range(1, 7), repeat=2))
P = lambda event: Fraction(sum(1 for w in omega if event(w)), len(omega))
A = lambda w: w[0] + w[1] >= 10 # sum at least 10
B = lambda w: w[0] == w[1] # a double
print("P(A) =", P(A), " P(B) =", P(B), " P(A and B) =", P(lambda w: A(w) and B(w)))
print("P(A or B) directly: ", P(lambda w: A(w) or B(w)))
print("by inclusion-exclusion: ", P(A) + P(B) - P(lambda w: A(w) and B(w)))
print("P(not A) =", P(lambda w: not A(w)), "= 1 - P(A) =", 1 - P(A))P(A) = 1/6 P(B) = 1/6 P(A and B) = 1/18
P(A or B) directly: 5/18
by inclusion-exclusion: 5/18
P(not A) = 5/6 = 1 - P(A) = 5/6
Three or more events
Inclusion-exclusion extends by alternating signs:
A classic application is the matching problem: letters are put into addressed envelopes at random. The probability that at least one letter is in the right envelope is
because for any specific letters, all are in place with probability , and there are ways to choose them, giving the term .
import math
import random
def p_match(n):
return sum((-1) ** (k + 1) / math.factorial(k) for k in range(1, n + 1))
rng = random.Random(4)
def simulate(n, trials=50_000):
hits = 0
for _ in range(trials):
perm = list(range(n))
rng.shuffle(perm)
hits += any(perm[i] == i for i in range(n))
return hits / trials
for n in [2, 3, 5, 10]:
print(n, round(p_match(n), 4), simulate(n))
print("limit 1 - 1/e =", round(1 - 1 / math.e, 4))2 0.5 0.4985
3 0.6667 0.66226
5 0.6333 0.63318
10 0.6321 0.63484
limit 1 - 1/e = 0.6321
Surprisingly, the answer hardly depends on once : whether 10 or 10,000 letters, the chance of at least one match is about 63%.
The union bound in practice
The union bound needs no knowledge of how events overlap, which makes it the most used inequality in computer science. If each of 1000 servers fails on a given day with probability , the probability that any fails is at most , whatever the dependencies between failures.
In software
Reliability engineering applies these rules daily: the complement rule ("probability that all replicas survive"), the union bound (worst-case failure estimates), and inclusion-exclusion (overlapping failure modes). Probabilistic data structures such as Bloom filters are analysed with the same rules (Hashing and the Birthday Bound).
Exercises
Exercise 1: Cards
One card is drawn from a standard 52-card deck. What is the probability it is a heart or a face card (J, Q, K)?
Answer
.
Solution
, , . Inclusion-exclusion: .
Exercise 2: Bounds
and . What are the smallest and largest possible values of ?
Answer
Between and .
Solution
, and by monotonicity. Both extremes are achievable.
Exercise 3: Divisible by 2, 3 or 5 (code)
A number is chosen uniformly from 1 to 300. Find the probability that it is divisible by 2, 3 or 5, using inclusion-exclusion, and check by counting.
Answer
.
Solution
(exact here because 300 is a multiple of 30).
from fractions import Fraction as F
ie = F(1, 2) + F(1, 3) + F(1, 5) - F(1, 6) - F(1, 10) - F(1, 15) + F(1, 30)
count = sum(1 for n in range(1, 301) if n % 2 == 0 or n % 3 == 0 or n % 5 == 0)
print(ie, F(count, 300), count)11/15 11/15 220
Test yourself
If , and and are disjoint, what is ?
- 0.12
- 0.7
- 0.58
- 1
The union bound states that is…
- equal to the sum
- at most the sum of the
- at least the sum
- the product of the
For large , the chance that a random permutation has at least one fixed point is about…
- 1