Probability — step-by-step proofs with the spam filter: from the axioms to Bayes (and the union that came out as 1.15)
In a class mock exam I added the probabilities of two events and got 1.15, and that is when I learnt that properties are not recited, they are proved. I had written for two events that overlapped. Had I known where the union formula comes from, I would have seen at once that I was missing a subtraction.
This article is the second part of the probability topic. In the theory you saw the results and how to use them with the email spam filter; here you see why they are true, which is what the “prove that” questions in the exam ask for. Every proof follows the same pattern: what we want to prove, what we start from, the steps one by one with the rule that justifies each, where people usually get stuck, the result for the cheat sheet and a check in R using the data from the week of 400 emails. At the end there are three for you to do, with the solution folded away.
Table of Contents
Before you start: the rules we will use
Every proof in this article comes from very few pieces. We number them so we can cite them at each step (“by R3”):
- R1 (axiom 1). for every event A.
- R2 (axiom 2). .
- R3 (axiom 3). If are pairwise disjoint, . In particular, for two: if , .
- R4 (set algebra). , , the distributive law and De Morgan’s laws , .
- R5 (conditional). If , , and therefore .
- R6 (multiplication principle). A task of steps with options can be done in ways.
The strategy behind almost all of them is the same, and it is worth having it in mind before starting: write the set you care about as a union of pieces that do not overlap and apply R3. If the pieces overlapped, R3 could not be used.
In the exam, cite the rule at each step even if it looks obvious (“by axiom 3, since they are disjoint…”). That is what makes a proof different from a calculation, and it is what gets marked.
Proof 1: the complement, the empty set and monotonicity
Where we are going. To derive from the axioms the three rules you will use in every exercise: the complement (the quick route for “at least one”), that the empty set has probability 0 and that a bigger event cannot be less likely. None of them is an axiom, and that is why they have to be proved. Monotonicity also gives , the piece Bonferroni needs in proof 3.
What we want to prove. Three properties used all the time:
- .
- .
- If , then (and in particular ).
What we start from. Only the axioms (R1, R2, R3) and R4.
Step by step (1). The left drawing is the idea: A and its complement split in two pieces.
- By R4, and : they are disjoint and together they make .
- Since they are disjoint, by R3: .
- But , and by R2 . So .
- Solving: .
Step by step (2). A special case of (1).
- The complement of is (there is nothing outside ).
- By (1) with : .
Step by step (3). Now the right drawing: A is inside B, and what A is missing to become B is .
- Since , we can write : B is A plus “the part of B that is not in A”.
- Those two pieces are disjoint: (R4).
- By R3: .
- By R1, . So .
- Since every event is inside , .
Notice that step 3 gives something stronger than the inequality: when . You will use it in the next proof.
Writing or “” and applying R3. Axiom 3 only works for disjoint pieces; A and B overlap (A is entirely inside B). That is why B must be split into A and .
Result for the cheat sheet. · · if : and · .
Check it with R. With the week of 400 emails: the event A = “spam and free” is inside B = “spam”.
n <- 400 p_spam <- 100 / n; p_legitimate <- 300 / n c(complement = 1 - p_spam, counted = p_legitimate) # must match: 0.75 p_A <- 60 / n # A = spam and free (inside B) p_B <- 100 / n # B = spam c(P_A = p_A, P_B = p_B, difference = p_B - p_A, spam_not_free = 40 / n)
Output:
complement counted
0.75 0.75
P_A P_B difference spam_not_free
0.15 0.25 0.10 0.10
The first line confirms that is exactly the proportion of legitimate emails counted. The second, that matches the 40 spam without “free” out of 400: it is , the piece A was missing.
Check you’ve got it: at which step of monotonicity do we use that A is inside B? Try A = “spam” and B = “free”, which do not satisfy it.
In the first one, when writing . If A is not inside B, that right-hand side is no longer B but . With the week: A is 100 emails and is the 15 legitimate emails with “free”; the right-hand side has 115 emails and B only 75. That is why here can be larger than without contradicting anything.
Proof 2: the probability of the union
Where we are going. To the union formula when the events overlap, which is exactly what went wrong in my mock exam. Axiom 3 only works for pieces that do not overlap; here we will see how to split so we can use it anyway. Bonferroni, the union of three events and the first “Prove it yourself” all come from this formula.
What we want to prove. For any two events (whether they overlap or not):
What we start from. R3, R4 and the result from step 3 of proof 1.
The idea. In the drawing, is three pieces that do not overlap: A without B, the intersection, and B without A. When we add , the middle piece goes in twice. We have to subtract it once.
Step by step.
- We split the union into two disjoint pieces: . That is, “all of A, plus the part of B that is not in A”. They are disjoint for the same reason as in proof 1: .
- By R3: .
- Now we split B: , also disjoint (one is inside A and the other outside). This follows from R4: by the distributive law.
- By R3: , so .
- Substituting into step 2: .
Where people get stuck. In step 1. The temptation is to write as “A plus B” and be done. But A and B are not disjoint, and axiom 3 cannot be used. The whole trick of the proof is finding a split into pieces that are disjoint.
In the exam, stating the union formula “by definition”. It is not a definition: it is a consequence of the axioms, and in a “prove that” question it has to be derived.
Result for the cheat sheet. ; if they are disjoint, . With three: .
Check it with R. With S = spam and F = free: the formula against counting directly the emails that are spam or say free.
n <- 400 p_S <- 100 / n; p_F <- 75 / n; p_SF <- 60 / n formula <- p_S + p_F - p_SF # P(S) + P(F) - P(S and F) counted <- (60 + 40 + 15) / n # the spam cells (60 + 40) plus legitimate with free (15) c(formula = formula, counted = counted, no_subtraction = p_S + p_F)
Output:
formula counted no_subtraction
0.2875 0.2875 0.4375
The formula and the count both give 0.2875. The no_subtraction column (0.4375) is my mock exam mistake: the 60 emails in the intersection counted twice.
Check you’ve got it: if A and B are disjoint, what is left of the formula, and at which step of the proof do you notice it?
You are left with , axiom 3: the term being subtracted is (proof 1). In the proof you notice it at the first step: if they do not overlap, the part of B that is not in A is the whole of B, , and the partition is directly A and B. The general formula contains the axiom as a special case.
Proof 3: Bonferroni and the union bound
Where we are going. Sometimes you know and but not how they are related, and without the union formula cannot be used. These two inequalities say what can still be stated: a minimum for the intersection (Bonferroni) and a maximum for the union (Boole). With many alarms, Boole guarantees that the probability of at least one going off never exceeds the sum.
What we want to prove. Two inequalities:
- Bonferroni: .
- Boole (union bound): for any , .
What we start from. The union formula (proof 2) and the fact that every probability is at most 1 (proof 1). For the second, induction.
Step by step (1).
- By proof 2: (the union formula with the intersection isolated).
- By proof 1, , so .
- Adding to both sides: .
What is it for? It bounds the intersection without knowing anything about how A and B are related. If the ULPGC filter stops 90 % of the spam and Gmail’s 80 %, at least of the spam is stopped by both, whether they are independent or not.
Step by step (2). The drawing gives the intuition: the union counts each zone once; the sum of probabilities, as many times as circles cover it. The formal proof is by induction on .
- Base case, . By proof 2, , because (R1). (For it is a trivial equality.)
- Induction hypothesis. We assume it is true for events: .
- Step. Call . The union of the events is : two events. By the base case: .
- By the induction hypothesis, . Substituting: .
- Since it holds for and, if it holds for , it holds for , it holds for every .
Why the base case works for a whole union
The step people skip most is applying the base case to . The base case does not say “for two simple events” but “for any two events”, and B is an event like any other even though it is the union of the first . Then the two inequalities chain because they point the same way: , and is at most the sum of the first . If one were and the other , they could not be combined.
Where people get stuck. In step 3: seeing that the union of events can be treated as the union of two (the first together, and the last one). That is the trick of almost every induction with unions.
In an induction, checking the base case and “generalising” without writing the hypothesis or the step from to . Without step 4 there is no proof.
Result for the cheat sheet. Bonferroni: . Boole: , with equality if the are disjoint.
Check it with R. We simulate 10,000 emails with three spam “signals” that sometimes coincide (a link, “free” and an unknown sender) and compare the proportion of emails with some signal with the sum of the three proportions.
set.seed(2026) n <- 10000 link <- runif(n) < 0.40 free <- runif(n) < 0.20 unknown <- (runif(n) < 0.30) | (free & runif(n) < 0.5) # overlaps with "free" on purpose union <- mean(link | free | unknown) # | is the logical "or": some signal total <- mean(link) + mean(free) + mean(unknown) c(union = union, sum = total, holds = union <= total) bonferroni <- c(intersection = mean(link & free), bound = mean(link) + mean(free) - 1) bonferroni
Output:
union sum holds
0.6617 0.9727 1.0000
intersection bound
0.0828 -0.3949
The union (0.6617) stays below the sum (0.9727), as Boole says: the difference is the emails with two or three signals, counted more than once in the sum. The 1 under holds is a TRUE: c() puts numbers and logicals in one vector and turns TRUE into 1. In the second output, the Bonferroni bound is negative: it is true but says nothing. Bonferroni is only useful when is clearly above 1, as in the example of the two filters.
Check you’ve got it: with the week of 400 emails, what bound does Bonferroni give for P(spam and free)? Is it any use?
. It is true, because the real intersection is , which is larger, but it says nothing: we already knew a probability cannot go below 0 (R1). Bonferroni only helps when the two probabilities add up to clearly more than 1, as with the two filters ().
Proof 4: the number of combinations and Pascal’s identity
Where we are going. To see where comes from without memorising it: by counting the same thing in two ways. It matters because, with equally likely outcomes, probability is favourable over possible, and counting them almost always needs this formula. Pascal shows the other counting trick: split into piles that do not overlap and add.
What we want to prove.
- The number of ways to choose objects out of , without order and without repetition, is .
- Pascal’s identity: if , .
What we start from. The multiplication principle (R6) and the number of ordered lists without repetition, .
Step by step (1). We count the ordered lists in two ways and set them equal.
- First way (directly). For an ordered list of distinct objects, the first is chosen from , the second from , …, the last from . By R6 there are lists.
- Second way (in two steps). An ordered list can be built by first choosing which objects go in (an unordered group: ways, which is what we want to count) and then in which order ( ways to order objects). By R6 there are lists.
- Both count the same thing, so .
- Solving: .
The why behind the first equality, : contains every factor from n down to 1, and dividing by cancels those from down to 1. The first r are left. With and : . And the ways of ordering a group are R6 again: r options for the first place, for the second, and so on down to 1.
In the drawing, with blacklist words and : there are ordered lists, which group into 4 columns of , one per unordered group. That is why .
Step by step (2). It can be done with factorials, but the counting proof is shorter and easier to understand. Look at one of the emails, the last one.
- The groups of emails out of split into two piles that do not overlap: those that contain email and those that do not.
- If email is in, more must be chosen from the other : there are groups.
- If it is not, all are chosen from the other : there are groups.
- Since each group is in one and only one pile, the total is the sum: .
With numbers: , and .
If you are asked to do it with factorials, the way is to add the two fractions over the common denominator :
In the first term we multiplied top and bottom by (because ); in the second, by (because ).
Where people get stuck. In the factorial version, in seeing why we multiply by and by . If you get stuck, write down what is missing for both denominators to be equal: the first one lacks an to have ; the second, an to have .
Dividing by “just because”. You have to say why: each unordered group appears exactly times among the ordered lists.
Result for the cheat sheet. · · · Pascal: · .
Check it with R. combn() actually generates every group; ncol() counts them. So we can compare the formula with the full list.
groups <- combn(20, 3) # every group of 3 words out of 20, one per column ncol(groups) # how many there are, counted one by one factorial(20) / (factorial(3) * factorial(17)) # the formula choose(5, 2) == choose(4, 1) + choose(4, 2) # Pascal with n = 5, r = 2 n <- 12 all(choose(n, 0:n) == choose(n, n:0)) # symmetry for every r at once sum(choose(n, 0:n)) == 2^n # the sum of a row of Pascal's triangle
Output:
[1] 1140 [1] 1140 [1] TRUE [1] TRUE [1] TRUE
The 1140 groups generated one by one match the formula, Pascal holds, and so does symmetry for the thirteen values of from 0 to 12. The last line is the cheat sheet result : the total number of subsets of 12 words.
Check you’ve got it: with 20 words and groups of 3, which two piles do you get by looking at the last word, and how many groups does each one have?
The ones that contain it: 2 more are needed from the other 19, . The ones that do not: all 3 come from the 19, . Each group is in exactly one pile, so the total is , what combn() counted. By the first part: lists divided by orders, 1140 again.
Proof 5: conditional probability is a probability
Where we are going. To prove that, once you know B has happened, the new probabilities are still a real probability. It matters because it saves work: if it satisfies the three axioms, everything in proofs 1 to 3 holds with “” after it without proving it again.
What we want to prove. If , the function satisfies the three axioms. That is, conditioning on B gives another probability, and therefore every property from proofs 1 and 2 also holds with “” after it.
What we start from. The definition R5 and the axioms for .
Step by step. We check the three axioms for .
- Axiom 1. . The numerator is by R1 and the denominator is by hypothesis. So .
- Axiom 2. , because .
- Axiom 3. Let be pairwise disjoint. By the distributive law (R4), . The pieces are also disjoint (if two do not touch, neither do their pieces inside B). By R3:
Each equality in that line, with its why:
- The first: definition of Q (R5) and distributivity, .
- The second: R3, because the are disjoint (shown in “Where people get stuck”).
- The third: dividing a sum by is dividing each term.
- The fourth: each is .
- Since satisfies the three axioms, it is a probability.
Direct consequences. Being a probability, everything proved so far holds “conditionally”:
- .
- .
- If , .
With the filter: if , then with no extra calculation.
Where people get stuck. In axiom 3, in justifying that the are disjoint. One line is enough: .
Writing or . The complement goes to the left of the bar; what is on the right (B) is not touched, because it is the universe you are in.
Result for the cheat sheet. For a fixed B with , is a probability: and the union formula holds with ““.
Check it with R. Conditioning on a column with prop.table(..., margin = 2) must give columns that add up to 1 (axiom 2 for ), and the conditional complement is 1 minus the conditional.
emails <- matrix(c(60, 40, 15, 285), nrow = 2, byrow = TRUE,
dimnames = list(type = c("spam", "legitimate"), word = c("free", "no free")))
q <- prop.table(emails, margin = 2) # Q(·) = P(· | column)
colSums(q) # axiom 2: each column adds up to 1
c(legitimate_given_free = q["legitimate", "free"], one_minus = 1 - q["spam", "free"])
Output:
free no free
1 1
legitimate_given_free one_minus
0.2 0.2
Both columns add up to exactly 1, and matches .
Check you’ve got it: if you keep the event on the left fixed and change the one on the right, is a probability?
No, and one axiom is enough to see it. With on the right, , and axiom 2 required 1. With “free” and “no free”, which are complements: , which has no reason to be 1. The proof only works with B fixed on the right, which is why the complement is taken on the left of the bar.
Proof 6: total probability and Bayes’ theorem
Where we are going. To two formulas that go in opposite directions. Total probability computes when A can come through several paths and you know what happens on each one. Bayes turns the condition around: the filter knows , but when you see a spam email what you want is .
What we want to prove. Let be a partition of (pairwise disjoint, with union ) with . Then, for any event A:
- Total probability: .
- Bayes: if also , .
What we start from. R3, R4 and R5.
Step by step (1). In the drawing, the strips cut A into pieces that do not overlap.
- Since the cover : .
- By the distributive law (R4): .
- The pieces are pairwise disjoint, because the are: .
- By R3: .
- By the multiplication rule (R5), . Substituting: .
Step by step (2). Bayes follows in two lines from the above.
- By the definition of conditional probability (R5): .
- The numerator, by the multiplication rule the other way round: .
- The denominator, by the total probability of part (1).
- Putting it together: .
With the theory example (sources campus, lists and external): and .
The example’s calculation, branch by branch
The line above squeezes in six calculations. Spelled out, with A = spam and the partition into the three sources:
| Source | Why | ||||
|---|---|---|---|---|---|
| campus | 0.5 | 0.02 | Product rule (R5) and then Bayes | ||
| lists | 0.3 | 0.10 | The same, with the lists branch | ||
| external | 0.2 | 0.60 | The same, with the outside branch | ||
| Total | 1 | 0.16 | 1 | The product column adds up to : that is total probability |
Bayes is not a new calculation: each row of the second-to-last column is its product divided by that column’s total. External sends only 20 % of the emails but takes 75 % of the spam, because its branch has the highest rate.
Where people get stuck. In step 3 of total probability: forgetting to justify that the pieces are disjoint, without which axiom 3 cannot be used. And in Bayes, in step 2: you have to flip the intersection () to be able to write the conditional we know, .
Using total probability with events that do not form a partition (they overlap or do not cover everything). If the do not add up to 1, it is not a partition and the formula does not hold.
Result for the cheat sheet. With a partition: and . With two: .
Check it with R. We simulate 100,000 emails: first the source, then whether it is spam according to its source. The proportion of external emails among the spam should get close to 0.75.
set.seed(2026)
n <- 100000
source <- sample(c("campus", "lists", "external"), n, replace = TRUE, prob = c(0.5, 0.3, 0.2))
rate <- c(campus = 0.02, lists = 0.10, external = 0.60)
spam <- runif(n) < rate[source] # each email uses its own source's rate
round(mean(spam), 4) # total probability: close to 0.16
round(prop.table(table(source[spam])), 4) # Bayes: which source the spam comes from
Output:
[1] 0.1625 campus external lists 0.0626 0.7525 0.1849
The simulation gives a spam proportion of 0.1625, very close to 0.16, and among the spam 75.25 % external, 18.49 % from the lists and 6.26 % from the campus, against 0.75, 0.1875 and 0.0625 in the theory’s Bayes table. The line rate[source] is the R trick that builds the tree: it gives each email the spam probability of its branch.
Check you’ve got it: why do the three Bayes probabilities, 0.0625, 0.1875 and 0.75, add up to exactly 1?
With numbers: the numerators are the products in the table and the denominator is their sum, so . With the proofs: is a probability (proof 5) and the three sources are disjoint and cover , so by R3 and R2 they add up to . If they do not add up to 1 in the exam, check the denominator.
Prove it yourself
Three proofs to practice with the same rules. Try them on paper before opening the solution.
1. De Morgan with probabilities. Prove that . Use it to compute the probability that an email from the week is neither spam nor says “free”.
See the solution to 1
By De Morgan (R4), . By proof 1 (complement), . By proof 2 (union), . Substituting: .
With the week: , which matches the cell of legitimate emails without “free”: 285/400 = 0.7125.
2. Independence of the complements. Prove that if A and B are independent, so are A and (and, applying it twice, and ).
See the solution to 2
We split A into two disjoint pieces: (R4). By R3, , so .
Since A and B are independent, . Substituting: , using the complement (proof 1) in the last step. That is exactly the definition of A and being independent.
For and : apply the same to the pair and A (we already know they are independent), swapping roles: it follows that and are independent.
With the filters: if “the ULPGC filter stops it” and “Gmail’s stops it” are independent, so are “it escapes ULPGC” and “it escapes Gmail”, and that is why in the theory we could multiply .
3. The union of three events. Prove that .
See the solution to 3
We group and apply the two-event formula (proof 2) with :
.
The first term, again by proof 2: .
The last one: by the distributive law, . Applying the two-event formula to these two events: , and .
Substituting everything and tidying up: . The triple intersection is added at the end because subtracting the three pairs removed it once too often.
When to use each result
| If you are asked for… | Use | Watch out for… |
|---|---|---|
| The probability of “not A” or “at least one” | Complement: | “At least one” = 1 − P(none) |
| The probability of “A or B” | Union: | Only add without subtracting if they are disjoint |
| A bound without knowing how A and B relate | Bonferroni or Boole | Bonferroni says nothing if |
| Counting unordered groups | If order matters, it is an ordered selection | |
| Properties of | Proof 5: everything holds “conditionally” | The complement goes to the left of the bar |
| The probability of A when there are several “paths” | Total probability | The must form a partition |
| “Given A, where does it come from?” | Bayes | Do not mix up and |
| Independence of “not A” and “not B” | Prove it yourself 2 | Independent ≠ mutually exclusive |
Common mistakes when proving
- Applying axiom 3 to overlapping events. You always have to split into disjoint pieces and say so.
- Using the formula you want to prove. In the union proof you cannot use the three-event union; in Bayes you cannot use Bayes.
- Skipping the “why”. “It is obvious” gets no marks. Every step, with its rule.
- Induction without a hypothesis. Write the base case, the hypothesis for and the step to .
- Mixing up the side of the bar. In , B is the universe; the complement is taken of A.
- Not checking with numbers. A good proof must give the same as counting in an example. If the 400-email table does not add up, something is off.
Try it in the R playground
Open the site’s R playground and paste this script. It checks this article’s results with the week of 400 emails; change the numbers in the table and see that they still hold.
# The week of 400 emails: rows type, columns word
t <- matrix(c(60, 40, 15, 285), nrow = 2, byrow = TRUE,
dimnames = list(type = c("spam", "legitimate"), word = c("free", "no free")))
p <- t / sum(t) # joint probabilities
p_S <- sum(p["spam", ]); p_F <- sum(p[, "free"]); p_SF <- p["spam", "free"]
p_S + p_F - p_SF # union (proof 2)
1 - p_S - p_F + p_SF # neither spam nor free (Prove it yourself 1)
p["legitimate", "no free"] # counted: must match
p_SF >= p_S + p_F - 1 # Bonferroni (proof 3)
colSums(prop.table(t, margin = 2)) # the conditional adds up to 1 (proof 5)
What to look at:
- In Environment, the matrix
tand the three probabilitiesp_S,p_F,p_SF. - The second and third outputs must be the same number (0.7125).
- Change the 60 to 70 and the 40 to 30 (still 100 spam): the union changes, but both calculations of “neither spam nor free” still match.
- Try
choose(10, 3) == choose(9, 2) + choose(9, 3)in the console: Pascal with other numbers.
Summary
| Proof | Result | The idea |
|---|---|---|
| 1 | , , monotonicity | and |
| 2 | The intersection goes in twice | |
| 3 | Bonferroni and Boole | Union ≤ 1 and induction |
| 4 | , Pascal | Count the same thing in two ways |
| 5 | is a probability | Check the three axioms |
| 6 | Total probability and Bayes | Partition + multiplication rule |
Three ideas to keep:
- Almost everything comes from splitting into disjoint pieces and applying axiom 3.
- Counting the same thing twice is the shortest way to prove counting formulas.
- Conditioning gives another probability: everything you know holds with “” after it.
With the proofs clear, move on to the R practice: we simulate a week of the filter, count repeated codes and build Bayes in a table. And in the probability exercises there is a short proof inside an exam-style problem, as in the continuous assessment.
Next step: practiceProbability — R practice with the spam filter: simulate a week, count repeated codes and Bayes in a table (and the prob I wrote backwards)Did this article help you? Here is how you can support SergioLearns →



