An event is a set of outcomes: “the sum is 7” is six cells of the dice grid. Learn to read or, and and not as union, intersection and complement, to prove De Morgan’s laws by following one outcome, and to turn phrases like at least one into sets.
M06.1.2L1 Core25 minIn review (what this means)
The maths and code on this page are checked by automated tests on every change, but an independent reader has not signed it off yet. Spot a mistake or a confusing step? Tell us.
Write an event described in words as a subset of the sample space, and say when it occurs.
Form the union, intersection and complement of events, and read them as or, and and not.
Prove De Morgan’s two laws by following a single outcome.
Turn phrases such as at least one, neither and exactly one into set expressions, and check them with Python sets.
The question
Roll two dice. “At least one six”, “neither die is a six”, “exactly one six” and “not a double six” sound alike, but they pick out 11, 25, 10 and 35 of the 36 outcomes. How do you turn a phrase in words into the right set of outcomes every time, and check that you did?
From the last lesson
1. What is the sample space of a roll of two dice, and how many outcomes does it have?
Show answer
The set of ordered pairs \({(i, j)}\), with \(i\) the first die and \(j\) the second, each from 1 to 6: \({6 \times 6 = 36}\) outcomes, drawn as a 6 by 6 grid.
2. What two rules make a list of outcomes a proper sample space?
Show answer
Nothing is left out (whatever happens is on the list) and no two items overlap (whatever happens matches exactly one item).
Intuition
Questions about an experiment are rarely about one outcome. “Is the sum 7?” is answered yes by six different rolls. Gather those rolls into a set, and you have an event.
An event is a set of outcomes: a subset of the sample space \(\Omega\). Run the experiment, get one outcome \(\omega\). The event \(A\)occurs when \(\omega\) is in \(A\), and does not occur when it is not. On the dice grid an event is a group of cells, and a roll is a dot that lands in one cell.
M06.1.2-F1
The event \(A\) = “the sum is 7” is a set of six cells. Whether \(A\) occurs depends only on which cell the roll lands in.
The same translation runs all through machine learning. “Emails flagged as spam that a person marked as safe” is a set of rows of a table, built from two simpler sets with and. Learning to write words as sets now is learning to write correct filters later.
Build it up
Step 1. The extreme events. The whole sample space \(\Omega\) is an event that always occurs: the certain event. The empty set \(\emptyset\) is an event that never occurs: the impossible event. A single outcome makes an event too, such as “the sum is 12” \({= \{(6, 6)\}}\).
Step 2. Or is union. “\(A\) or \(B\) occurs” means the outcome is in \(A\), or in \(B\), or in both. That is the union\({A \cup B}\). In mathematics “or” always includes “both”.
Step 3. And is intersection. “\(A\) and \(B\) both occur” means the outcome is in each of them: the intersection\({A \cap B}\).
Step 4. Not is complement. “\(A\) does not occur” means the outcome is in \(\Omega\) but not in \(A\): the complement\({A^c}\). The complement is always taken inside \(\Omega\).
M06.1.2-F2
The three words as three regions. Or fills both circles, and fills only the overlap, and not fills everything outside one circle.
Step 5. Events that cannot both happen. Two events are disjoint (or mutually exclusive) when \({A \cap B = \emptyset}\): no outcome is in both, so they never occur together. On the dice grid, “the sum is 7” and “a double” are disjoint, because a double \({(k, k)}\) has the even sum \({2k}\).
The formal statement
NoteDefinition: events and their operations
An event is a subset \({A \subseteq \Omega}\). It occurs when the outcome \(\omega\) lies in \(A\). For events \(A\) and \(B\):
the union\({A \cup B}\), read “\(A\) or \(B\)”, holds the outcomes in \(A\), in \(B\) or in both;
the intersection\({A \cap B}\), read “\(A\) and \(B\)”, holds the outcomes in both;
the complement\({A^c}\), read “not \(A\)”, holds the outcomes of \(\Omega\) that are not in \(A\);
the difference\({A - B = A \cap B^c}\), read “\(A\) but not \(B\)”;
\(A\) and \(B\) are disjoint when \({A \cap B = \emptyset}\).
In set-builder notation (M01.6), with every \(\omega\) taken from \(\Omega\):
\[
\begin{aligned}
A \cup B &= \{\omega : \omega \in A \text{ or } \omega \in B\}, \\
A \cap B &= \{\omega : \omega \in A \text{ and } \omega \in B\}, \\
A^c &= \{\omega : \omega \notin A\}.
\end{aligned}
\]
These are the set operations of M01.6, with a new reading: each one answers a yes-or-no question about the outcome. The most useful laws about them are De Morgan’s.
In words: “not (\(A\) or \(B\))” is “neither”, and “not (\(A\) and \(B\))” is “not both”. M01.6 checked these region by region on a Venn diagram. Here is a proof that never draws a picture, by following a single outcome. To show two sets are equal, show that every outcome in one is in the other, and the other way round.
First law. Take any outcome \(\omega\). Each line below says the same thing as the line before.
\({\omega \in (A \cup B)^c}\).
\(\omega\) is not in \({A \cup B}\), by the definition of the complement.
It is not true that (\(\omega\) is in \(A\) or \(\omega\) is in \(B\)), by the definition of the union.
\(\omega\) is not in \(A\), and \(\omega\) is not in \(B\). An “or” is false exactly when both of its parts are false.
\({\omega \in A^c}\) and \({\omega \in B^c}\), by the definition of the complement.
\({\omega \in A^c \cap B^c}\), by the definition of the intersection.
Every step runs both ways, so an outcome is in the left side exactly when it is in the right side, and the two sets are equal.
M06.1.2-F3
Following one outcome. The dot \(\omega\) lies outside \(A\) and outside \(B\), so it is in both hatchings on the right, and outside the union on the left. The cross-hatched region is exactly the region shaded on the left.
Second law. The same chain, with “and” and “or” swapped at step 3: an “and” is false exactly when at least one of its parts is false. So \({\omega \in (A \cap B)^c}\) exactly when \({\omega \notin A}\) or \({\omega \notin B}\), that is, when \({\omega \in A^c \cup B^c}\).
Go deeper: De Morgan's laws for many events
The same proof works for any number of events, even infinitely many. An outcome is outside \({A_1 \cup A_2 \cup \cdots}\) exactly when it is outside every \(A_i\), so
Read with \(A_i\) = “event number \(i\) happens”, the left side is “none of them happens”. The complement of “none” is “at least one”, so P(at least one) will be one minus P(none), a rule the next modules use again and again.
Worked example
On two dice, write “at least one six”, “neither die is a six” and “exactly one six” as sets, and count them.
Name the building blocks. Let \({S_1}\) = “the first die shows a six”, the right-hand column of the grid, and \({S_2}\) = “the second die shows a six”, the top row. Each has 6 cells, and they share the single cell \({(6, 6)}\): \({S_1 \cap S_2 = \{(6, 6)\}}\).
At least one six means a six on the first die or on the second, which is a union: \({S_1 \cup S_2}\). The column and the row hold \({6 + 6 = 12}\) cells, but \({(6, 6)}\) was counted in both, so
\[
|S_1 \cup S_2| = 6 + 6 - 1 = 11 .
\]
Neither die is a six means not a six on the first and not a six on the second: \({S_1^c \cap S_2^c}\). Each die then shows 1 to 5, so there are \({5 \times 5 = 25}\) cells. By De Morgan’s first law this is \({(S_1 \cup S_2)^c}\), and indeed \({36 - 11 = 25}\).
Exactly one six means at least one, but not both: \({(S_1 \cup S_2) - (S_1 \cap S_2)}\), with \({11 - 1 = 10}\) cells. Written another way, it is \({(S_1 \cap S_2^c) \cup (S_1^c \cap S_2)}\): a six on the first only (5 cells) or on the second only (5 cells).
M06.1.2-F4
The three phrases as three sets of cells. The counts check each other: \({11 + 25 = 36}\), since “neither” is the complement of “at least one”, and \({10 + 1 = 11}\), since “at least one” is “exactly one” or “both”.
Code
Python’s sets do exactly what events do: | is union, & is intersection, and subtracting from the sample space gives the complement.
from itertools import productomega =set(product(range(1, 7), repeat=2)) # the 36 ordered pairsdef event(rule):"""The event made of every outcome for which rule(outcome) is true."""return {w for w in omega if rule(w)}S1 = event(lambda w: w[0] ==6)S2 = event(lambda w: w[1] ==6)at_least_one = S1 | S2neither = (omega - S1) & (omega - S2)exactly_one = at_least_one - (S1 & S2)not_both = omega - (S1 & S2)print(len(at_least_one), len(neither), len(exactly_one), len(not_both))
11 25 10 35
The two events of the next lessons, and the disjoint pair from the build-up:
A = event(lambda w: w[0] + w[1] ==7) # the sum is 7B = event(lambda w: w[0] %2==0) # the first die is evenC = event(lambda w: w[0] == w[1]) # a doubleprint("A:", len(A), " B:", len(B), " A and B:", sorted(A & B), " A or B:", len(A | B))print("A and C:", A & C)
A: 6 B: 18 A and B: [(2, 5), (4, 3), (6, 1)] A or B: 21
A and C: set()
A proof covers every case; a program can only try cases. But on a small sample space it can try them all. Three coin flips have 8 outcomes and so \({2^8 = 256}\) events. The cell below checks both of De Morgan’s laws on every one of the \({256 \times 256 = 65{,}536}\) pairs.
from itertools import combinationsflips = {"".join(p) for p in product("HT", repeat=3)}events = [set(c) for k inrange(9) for c in combinations(sorted(flips), k)]checked =0for E in events:for F in events:assert flips - (E | F) == (flips - E) & (flips - F)assert flips - (E & F) == (flips - E) | (flips - F) checked +=1print(len(events), "events,", checked, "pairs checked")
256 events, 65536 pairs checked
Explore
The event explorer in lesson M06.1.4 lets you choose two events on the dice grid, from presets or by clicking cells, and light up their union, intersection or complement. Try “at least one six” against “doubles”.
Pitfalls
M06.1.2-F5
Wrong beside right. “Not a double six” excludes one cell. Reading it as “neither die is a six” wrongly drops the ten rolls with exactly one six.
“Not both sixes means neither is a six.”
De Morgan’s second law says \({(S_1 \cap S_2)^c = S_1^c \cup S_2^c}\): not both means at least one of the two fails, which is 35 rolls. “Neither” is the much smaller set \({S_1^c \cap S_2^c}\), with 25. When you push “not” inside brackets, “and” must turn into “or”, and “or” into “and”.
“A or B means one or the other, but not both.”
In everyday speech “or” is sometimes exclusive. In probability it never is: \({A \cup B}\) includes the outcomes in both. When you mean exactly one, write it out as \({(A \cup B) - (A \cap B)}\). The counts differ: 11 rolls have at least one six, 10 have exactly one.
“Disjoint events have nothing to do with each other.”
The opposite is true. If \(A\) and \(C\) are disjoint, learning that \(A\) happened tells you for certain that \(C\) did not. “The sum is 7” rules out “a double”. Events that have nothing to do with each other are called independent, and lesson M06.3.4 shows that disjoint events with positive probability are never independent.
Check yourself
Recall
1. What is an event, and when does it occur?
Show answer
An event is a subset of the sample space. It occurs when the outcome of the experiment lies in it.
2. Which set operations do the words or, and and not stand for?
Show answer
Or is union, \({A \cup B}\) (including both); and is intersection, \({A \cap B}\); not is the complement \({A^c}\), taken inside \(\Omega\).
3. What does it mean for two events to be disjoint? Give a pair on the dice grid.
Show answer
They have no outcome in common, \({A \cap B = \emptyset}\), so they cannot both happen. “The sum is 7” and “a double” are disjoint.
4. State De Morgan’s two laws.
Show answer
\({(A \cup B)^c = A^c \cap B^c}\) and \({(A \cap B)^c = A^c \cup B^c}\): not either is neither, and not both is at least one fails.
5. How many of the 36 rolls of two dice have at least one six, and how many have exactly one?
Show answer
11 have at least one six (\({6 + 6 - 1}\)) and 10 have exactly one (all of those but \({(6, 6)}\)).
Exercises
1.★ On two dice, let \(A\) = “the sum is 7” and \(C\) = “a double”. Find \({A \cap C}\) and \({|A \cup C|}\).
Show solution
A double \({(k, k)}\) has sum \({2k}\), which is even, so it is never 7: \({A \cap C = \emptyset}\), and the events are disjoint. With no outcome counted twice, \({|A \cup C| = 6 + 6 = 12}\).
2.★★ Flip a coin three times. Let \(E\) = “the first flip is heads” and \(F\) = “the last flip is heads”. List \({E \cap F}\), \({E \cup F}\) and \({(E \cup F)^c}\).
Show solution
Listing the outcomes, \(E\) holds HHH, HHT, HTH and HTT, and \(F\) holds HHH, HTH, THH and TTH. So \({E \cap F}\) holds HHH and HTH, and \({E \cup F}\) holds HHH, HHT, HTH, HTT, THH and TTH: 6 outcomes. By De Morgan, \({(E \cup F)^c = E^c \cap F^c}\): first flip tails and last flip tails, which is THT or TTT. The counts check: \({6 + 2 = 8}\).
3.★★★ Show, by following one outcome, that \({(A \cup B) - (A \cap B)} = {(A \cap B^c)} \cup {(A^c \cap B)}\): both sides say “exactly one of \(A\) and \(B\) occurs”.
Show solution
Take any outcome \(\omega\) and look at the four cases for whether it is in \(A\) and in \(B\).
In both: it is in \({A \cap B}\), so not in the left side. It is in neither \({A \cap B^c}\) nor \({A^c \cap B}\), so not in the right side.
In \(A\) only: it is in \({A \cup B}\) and not in \({A \cap B}\), so in the left side. It is in \({A \cap B^c}\), so in the right side.
In \(B\) only: the same argument with \(A\) and \(B\) swapped puts it in both sides.
In neither: it is not in \({A \cup B}\), so not in the left side, and in neither piece of the right.
In every case \(\omega\) is in both sides or in neither, so the sets are equal.
Summary card
An event is a set of outcomes, and words become set operations.
Jeremy Orloff and Jonathan Bloom, Reading 2: Probability, terminology and examples, MIT OpenCourseWare 18.05, Spring 2022: an event is a subset of the sample space (Section 2.2, Example 6, “exactly two heads” as a set of three outcomes) and the Venn pictures of a complement and of two disjoint events (Section 3).
Charles M. Grinstead and J. Laurie Snell, Introduction to Probability, second edition (free PDF). Section 1.2: every subset of the sample space is an event, with the basic set operations drawn in Figure 1.7.
Python Software Foundation, Set types: | for union, & for intersection and - for difference.