Experiments and sample spaces
An experiment is anything with an uncertain result: rolling a die, tossing a coin, drawing a card. Each possible result is an outcome. The set of all outcomes is the sample space, written (the Greek capital omega).
- One die: , six outcomes.
- A coin tossed twice: , with H for heads and T for tails. (heads, then tails) and are different outcomes.
- Two dice, one red and one blue: each outcome is a pair , red first. There are 36 pairs.
Each time the experiment runs, exactly one outcome happens. So the sample space must list every possible result, and no two of its outcomes can happen together.
Rule: Sample space
Each run of the experiment produces exactly one element of . Keep different results apart: with two dice, and are two outcomes.
Try it
product(range(1, 7), repeat=2) lists every pair of faces, red first. A Python set of the pairs is , as in lesson 0.2.1.
The last line counts the pairs and checks that and are both there.
Events are sets of outcomes
An event is a set of outcomes: a subset of , which means every element of it is in . An event happens when the outcome of the run is one of its elements.
With one die, "the roll is even" is the event . A roll of 4 makes happen; a roll of 3 does not.
Two events are special. always happens: it is the certain event. The empty set has no elements and never happens: the impossible event.
A single outcome is an event too, such as .
With two dice, set-builder notation (lesson 0.2.1) describes events by a rule:
, "the sum is 7", has 6 outcomes, from to . , "at least one six", has 11. Six have the red die on 6 and six the blue die, but counts once.
The 36 outcomes of two dice, each labelled with its sum. Event , a sum of 7, is the outlined diagonal of 6 cells; event , at least one six, is the 11 shaded cells. They share 2 cells.
And, or, not
The words that combine events become operations on sets.
Rule: Union, intersection, complement
The union holds every outcome in , in or in both. The intersection holds the outcomes in both. The complement holds every outcome of that is not in .
With one die, take , "even", and , "at least 4".
- : even, or at least 4, or both.
- : even and at least 4.
- : odd.
In probability, "or" always includes "both". Two events with no outcome in common, , are disjoint, also called mutually exclusive: they cannot happen together. "Even" and "odd" are disjoint, and so is any event with its complement; together the two make up .
On the grid, , and has outcomes: the overlap must not be counted twice.
Try it
Python's set operators match the symbols: | is , & is , and Omega - E is .
E & {1, 3, 5} prints set(), the empty set: even and odd are disjoint. The last line counts , , and on the grid.
The three axioms
A probability gives every event a number , read "the probability of ". It runs from 0 (the event never happens) to 1 (it always does) and has no units. It is often written as a percentage: is 25%.
One way to read it: run the experiment many times, and happens in a share of the runs close to . The last section tests this with a simulation.
Any way of giving events numbers counts as a probability if it obeys three rules, the axioms. They are taken as the starting point, and every other rule follows from them.
Rule: The axioms of probability
No probability is negative, some outcome is certain to happen, and the probabilities of disjoint events add. The third axiom also holds for a list of disjoint events that never ends, which lesson 5.2.3 needs.
The outcomes need not be equally likely. A loaded die might show 6 half the time and each other face with probability 0.1. These six numbers are not negative and add up to 1, so they obey the axioms.
Single outcomes are disjoint, so axiom 3 adds them up for any event. For the loaded die, .
Two rules that follow
Not. and are disjoint and together make up . So axioms 2 and 3 give .
Rule: Complement rule
The probability that does not happen. With it gives . Use it when "not " is easier to count, as for "at least one".
With two fair dice, each of the 36 outcomes has probability ; a later section says why. "At least one six" is the complement of "no six", and no six leaves of the 36 outcomes. So .
Or. When and overlap, counts the outcomes of twice. Subtract them once.
Rule: Addition rule
For any two events. When they are disjoint, and the rule is axiom 3.
On the grid, . For the loaded die, , since the overlap has probability 0.6.
The axioms also fix the range. Since , no probability is above 1. And if every outcome of is in , then .
The Proof Gym proves these rules from the axioms.
Try it
The loaded die is a dictionary from faces to probabilities. The cell checks that none is negative and that they add up to 1, then adds single outcomes to get each event.
round(…, 10) hides float noise such as 0.7999999999999999.
Equally likely outcomes: probability by counting
Often every outcome is equally likely: a fair die, a fair coin, a well-shuffled deck. With outcomes, each then has probability , because the probabilities must add up to 1. So a probability becomes a count.
Rule: Equally likely outcomes
is the number of outcomes in , and the number in the sample space. This works only when every outcome is equally likely.
Two fair dice have 36 equally likely outcomes. Counting the cells of the grid for each sum gives a table:
| sum | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| outcomes | 1 | 2 | 3 | 4 | 5 | 6 | 5 | 4 | 3 | 2 | 1 |
So , the most likely sum, and . The algebra agrees: for each red value , exactly one blue value, , makes 7, so there are 6 outcomes. A sum of 2 needs both dice on 1.
The sums themselves are not equally likely. Treating the 11 sums as equally likely outcomes would give each , which is wrong. The same trap hides in the number of heads in two tosses: one head comes from or , so , not .
Lesson 5.1.2 counts outcomes in sample spaces too large to list.
Try it
Counter counts the pairs that give each sum, which rebuilds the table. Fraction keeps the answers exact.
The last line counts the tosses with exactly one head. True counts as 1 in a sum.
Simulation: probability as a long-run share
A computer can run an experiment many times, and the share of runs in which happens estimates . NumPy's random numbers come from a generator, made by np.random.default_rng(seed). The same seed gives the same numbers every time, so anyone can repeat the run.
rng.integers(1, 7, size=(n, 2)) rolls two dice times: whole numbers from 1 to 6, stopping before 7 as range does. With the seed 1, the share of sums equal to 7 came out as:
| rolls | 100 | 10,000 | 1,000,000 |
|---|---|---|---|
| share with sum 7 | 0.19 | 0.1652 | 0.1665 |
The exact answer is . After 100 rolls the share is off by more than 0.02; after a million it is within 0.0002. These numbers come from one seeded run: another seed gives slightly different shares.
The running share of sevens in one seeded run of a million rolls. It wanders at first, then settles on .
Lesson 5.7.2 explains why the share settles, and how fast. For now a simulation is a check: if a million runs land far from your exact answer, one of the two is wrong.
Try it
The cell rolls two dice a million times with the seed 1. rolls.sum(axis=1) adds each pair, and (s[:n] == 7).mean() is the share of sevens among the first n rolls.
The next line checks two answers from above: at least one six, , and , . The last lines roll the loaded die 100,000 times; its even share should be near 0.7.
Case study 5.1.6 uses these rules on a table of credit ratings, where each row of probabilities must add up to 1.
Common mistakes
- "Or" includes "both". only for disjoint events. Otherwise subtract , or the overlap counts twice.
- Counting needs equally likely outcomes. The 11 sums of two dice are not equally likely, and neither are 0, 1 and 2 heads. Count the equally likely pairs instead.
- Order counts in the sample space. With two dice, and are different outcomes, so a sum of 3 has probability , not .
- The complement of "at least one" is "none", not "exactly one". .
- A probability lies between 0 and 1. An answer outside that range means a mistake, often an overlap counted twice. Six rolls of a die do not give a six with probability ; lesson 5.1.2 finds the true value.
- A simulated share is an estimate. It changes with the seed and the number of runs, so quote it rounded and beside the exact answer.
Sample spaces, events and axioms
0 of 13 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
How to type answers
- Powers with
^:x^7,2^(1/3),a^-2. - Multiply with
*or by writing side by side:3x^2,2(x+1). ln(x)is the natural log,log(x, 2)is log base 2,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for sin²x.- Your first answer to each question is saved: it counts towards your score and brings the question back for review.
- Exact answers like
ln(20)/ln(3)are best. Decimals need about 4 significant figures.
Summary card
- An experiment's sample space lists every outcome; exactly one happens per run. An event is a set of outcomes.
- is " or or both", is " and ", is "not ". Disjoint events have .
- Axioms: , , and probabilities of disjoint events add.
- , and .
- With equally likely outcomes, . Sums of dice and numbers of heads are not equally likely.
- A seeded simulation estimates by the share of runs in which happens; it settles on as the runs grow.