---
title: Sample spaces, events and the axioms
heading: Listing what can happen, then adding up chances
eyebrow: A11 · Lesson 2 · Sample spaces and events
xp: 40
---

::: hook
A three-bit code word crosses a noisy link. What's the chance that exactly one bit arrives wrong? That at least one does? That the first bit is wrong or the word has an odd number of errors? Questions like these get confusing fast unless you do what probability theory does: list everything that can happen, mark the outcomes each question is about, and add up their chances. Three rules, the axioms, are enough to make that bookkeeping consistent.
:::

::: play
- Two dice are thrown many times. The histogram counts each sum from 2 to 12; the line is what exact counting predicts.
- The readout measures how often the sum is at least $k$. Move $k$ and compare with counting the outcomes on the 6 by 6 grid.
- At $k = 7$, how many of the 36 outcomes count? Does the measured fraction agree?
:::
:::

```sim plot
view: random
x: s = 1.5..12.5
slider: k = 2..12 step 1 = 7
sample: dice(2)
trials: 20000
bins: 11
density: (6 - abs(s - 7))/36
measure: step(s - k + 0.5) | name: P
readout: fraction with sum ≥ k = P | digits: 4
readout: outcomes counted, of 36 = round(36*P) | digits: 3
```

::: predict
## Two dice are thrown. What is the chance that the sum is 7 or that the first die shows 6?

- [ ] $\frac{12}{36}$
- [x] $\frac{11}{36}$
- [ ] $\frac{6}{36}$
- [ ] $\frac{1}{3}$ exactly, because each event has chance $\frac{1}{6}$

::: reveal
$\frac{11}{36}$. Each event has 6 of the 36 outcomes, but one outcome, (6, 1), is in both. Adding $\frac{6}{36} + \frac{6}{36}$ would count it twice, so subtract it once: $\frac{6 + 6 - 1}{36}$.
:::
:::

::: nameit
## Outcomes and events

The **sample space** $S$ is the list of every possible outcome of the experiment. For two dice it has 36 ordered pairs; for a three-bit word sent over a link, the error pattern is one of 8 strings from 000 to 111.

An **event** is a set of outcomes, the ones a question is about: "the sum is 7" is the event {(1,6), (2,5), (3,4), (4,3), (5,2), (6,1)}. Events combine like sets:

| Event | Means | Symbol |
|---|---|---|
| $A$ or $B$ | at least one happens | $A \cup B$ |
| $A$ and $B$ | both happen | $A \cap B$ |
| not $A$ | $A$ doesn't happen | $A^c$ |

$A$ and $B$ are **mutually exclusive** if they can't both happen: $A \cap B$ is empty.

## The axioms

A probability $P$ assigns a number to every event so that

1. $P(A) \ge 0$;
2. $P(S) = 1$;
3. if $A$ and $B$ are mutually exclusive, $P(A \cup B) = P(A) + P(B)$ (and the same for any list of them).

Everything else follows. For example:

- **complement:** $P(A^c) = 1 - P(A)$;
- **inclusion-exclusion:** $P(A \cup B) = P(A) + P(B) - P(A \cap B)$;
- **equally likely outcomes:** if $S$ has $N$ outcomes, each with chance $\frac{1}{N}$, then $P(A) = \frac{|A|}{N}$, the number of outcomes in $A$ over $N$.

With three events, inclusion-exclusion adds the singles, subtracts the pairs and adds back the triple: $P(A \cup B \cup C) = P(A) + P(B) + P(C) - P(AB) - P(AC) - P(BC) + P(ABC)$.
:::

::: example
## Each bit of a three-bit word is flipped independently with probability $p = 0.1$. List the sample space and find the chance of exactly one error.

::: solution
1. **List the sample space.** The error pattern is one of 000, 001, ..., 111, with chance $p^k(1 - p)^{3 - k}$ for a pattern with $k$ ones.
2. **Pick out exactly one error.** It's the event {100, 010, 001}, three mutually exclusive outcomes, each with chance
   $$0.1 \times 0.9^2 = 0.081$$
3. **Add them.**
   $$\begin{aligned} P &= 3 \times 0.081 \\ &= 0.243 \end{aligned}$$
4. **Check.** The eight chances add to $(p + 1 - p)^3 = 1$.

**Answer:** the sample space is the eight patterns 000 to 111, and the chance of exactly one error is 0.243.
:::
:::

::: example
## In a batch of chips, 5% fail a speed test, 3% fail a leakage test, and 1% fail both. What fraction fails at least one test? Passes both?

::: solution
1. **Inclusion-exclusion.** Write $S$ for failing the speed test and $L$ for failing the leakage test:
   $$\begin{aligned} P(S \cup L) &= 0.05 + 0.03 - 0.01 \\ &= 0.07 \end{aligned}$$
   so 7% fail something.
2. **Passing both is the complement.**
   $$1 - 0.07 = 0.93$$

**Answer:** 7% fail at least one test, and 93% pass both.
:::
:::

::: example
## Two independent tests each give a false alarm on 2% of good boards. What fraction of good boards fail at least one?

::: solution
1. **Use the complement.** The event "at least one false alarm" is the complement of "neither":
   $$1 - 0.98^2 = 0.0396$$
   just under 4%.
2. **Compare with adding the rates.** Adding the two rates gives 4%, which slightly overcounts the boards that fail both:
   $$0.02^2 = 0.0004$$
3. **Inclusion–exclusion agrees.**
   $$\begin{aligned} P &= 0.02 + 0.02 - 0.0004 \\ &= 0.0396 \end{aligned}$$

**Answer:** 3.96% of good boards fail at least one test, just under 4%.
:::
:::

::: check
given: a = 4 | 5 | 9
answer: a - 1
tolerance: 0.01%

## Two dice are thrown. How many of the 36 outcomes have a sum of {a}?

::: right
Right. For a sum of $s$ from 2 to 7 there are $s - 1$ ways: {answer}.
:::

::: misses
- [a] Count the pairs: the first die can't be 0.
- [any] Not yet. List the pairs $(d_1, s - d_1)$ with both dice from 1 to 6.
:::
:::

::: check
given: pa = 0.3 | 0.4; pb = 0.25 | 0.5; pab = 0.1 | 0.15
answer: pa + pb - pab
tolerance: 0.5%

## $P(A)$ = {pa}, $P(B)$ = {pb} and $P(A \cap B)$ = {pab}. What is $P(A \cup B)$?

::: right
Right. $P(A) + P(B) - P(A \cap B)$ = {answer}.
:::

::: misses
- [pa + pb] The overlap is counted twice; subtract it once.
- [any] Not yet. Inclusion-exclusion.
:::
:::

::: check
given: p = 0.01 | 0.05 | 0.2
answer: 3*p*(1 - p)^2
tolerance: 0.5%

## Each bit of a three-bit word flips independently with probability {p}. What is the chance of exactly one error?

::: right
Right. Three patterns, each with chance $p(1 - p)^2$: {answer}.
:::

::: misses
- [p*(1 - p)^2] That's one specific pattern, like 100. Three patterns have exactly one error.
- [3*p] The other two bits must be right: multiply by $(1 - p)^2$.
- [any] Not yet. Add the chances of 100, 010 and 001.
:::
:::

::: check
given: p = 0.01 | 0.1 | 0.2
answer: 1 - (1 - p)^3
tolerance: 0.5%

## With the same link (flip probability {p}), what is the chance that at least one bit of the three is wrong?

::: right
Right. The complement of "no errors": $1 - (1 - p)^3$ = {answer}.
:::

::: misses
- [3*p] Adding the three single-bit chances counts patterns with two or three errors more than once.
- [(1 - p)^3] That's the chance of no errors.
- [any] Not yet. Use the complement.
:::
:::

::: check
given: f1 = 0.04 | 0.06; f2 = 0.02 | 0.03; both = 0.015 | 0.02
answer: 1 - (f1 + f2 - both)
tolerance: 0.5%

## A board fails inspection A with probability {f1}, inspection B with probability {f2}, and both with probability {both}. What is the chance it passes both?

::: right
Right. $1 - P(A \cup B)$ = {answer}.
:::

::: misses
- [1 - f1 - f2] Boards failing both were subtracted twice; add them back.
- [(1 - f1)*(1 - f2)] That assumes the failures are independent, which the numbers don't say.
- [any] Not yet. The complement of failing at least one.
:::
:::

::: check
kind: choice

## Events $A$ and $B$ are mutually exclusive, each with probability 0.3. Which is true?

- [x] $P(A \cup B) = 0.6$ and $P(A \cap B) = 0$
- [ ] $P(A \cup B) = 0.51$
- [ ] $P(A \cap B) = 0.09$
- [ ] They must be independent

::: right
Right. They can't happen together, so the overlap is empty and the chances simply add.
:::

::: misses
- [2] 0.51 is $1 - 0.7^2$, which treats them as independent.
- [3] 0.09 is the product, for independent events. Mutually exclusive events never happen together.
- [4] Mutually exclusive events with nonzero chances are never independent: knowing one happened tells you the other didn't.
:::
:::

::: check
kind: parts
given: a = 0.02 | 0.05; b = 0.03 | 0.04; c = 0.005 | 0.01

## Chips fail test A with probability {a}, test B with {b}, and both with {c}.

::: part
answer: a + b - c
tolerance: 0.5%

### What fraction fails at least one?

::: misses
- [a + b] Subtract the overlap, counted twice.
- [any] Inclusion–exclusion.
:::
:::

::: part
answer: a - c
tolerance: 0.5%

### What fraction fails A only?

::: misses
- [any] Remove the overlap from A.
:::
:::
:::

::: check
kind: derivation
vars: p = 0.01..0.5, q = 0.01..0.5

## Two independent events have probabilities $p$ and $q$.

::: step
answer: p*q

### What is the chance both happen?
:::

::: step
answer: p + q - p*q

### What is the chance at least one happens?
:::

::: right
Right. Independence makes the overlap a product.
:::
:::

::: explain
## Why does inclusion-exclusion subtract $P(A \cap B)$?

::: model
$P(A) + P(B)$ adds the chances of every outcome in $A$ and every outcome in $B$. An outcome in both sets is added twice, once from each, but the event "$A$ or $B$" should count it only once. Subtracting $P(A \cap B)$ removes the extra copy. When the events can't overlap, $P(A \cap B) = 0$ and the rule reduces to the third axiom.
:::
:::

::: practice

::: check
given: s = 8 | 10 | 11
answer: 13 - s
tolerance: 0.01%

## How many of the 36 outcomes of two dice have a sum of {s}?

::: misses
- [s - 1] Above 7 the count falls: $13 - s$.
- [any] List the pairs.
:::
:::

::: check
given: pa = 0.2 | 0.35; pb = 0.4 | 0.5
answer: pa + pb
tolerance: 0.5%

## $A$ and $B$ are mutually exclusive, with chances {pa} and {pb}. What is $P(A \cup B)$?

::: misses
- [any] They don't overlap: add.
:::
:::

::: check
given: pa = 0.1 | 0.25 | 0.3 | 0.6 | 0.7 | 0.85 | 0.9
answer: 1 - pa
tolerance: 0.5%

## $P(A)$ = {pa}. What is $P(A^c)$?

::: misses
- [any] $1 - P(A)$.
:::
:::
:::
