Sub topic 2
The addition rule for "or"
This chapter assumes you can compute a probability as favorable outcomes divided by total outcomes, simplify fractions, and read a Venn diagram. A sample space is the set of all possible outcomes of an experiment. An event is any subset of the sample space.
The addition rule for "or"
For events A and B, P(A or B) = P(A) + P(B) - P(A and B). The subtraction removes outcomes counted twice. If A and B are mutually exclusive, P(A and B) = 0, so the rule reduces to P(A) + P(B).
Roll two fair dice. Let A be "first die shows 6" and B be "second die shows 6." Then P(A) = 1/6, P(B) = 1/6, and P(A and B) = 1/36. So P(A or B) = 1/6 + 1/6 - 1/36 = 11/36.
What independence means
Two events are independent when one occurring does not change the probability of the other. Formally, A and B are independent when P(A and B) = P(A) x P(B).
Multiplying probabilities of independent events
Take the first die is even (P = 1/2) and the sum is 7 (P = 1/6). The pairs that satisfy both are (2,5), (4,3), and (6,1), so P(both) = 3/36 = 1/12. Since 1/2 x 1/6 = 1/12, the events are independent.
from fractions import Fraction
from itertools import product
space = list(product(range(1, 7), repeat=2))
def prob(event):
return Fraction(sum(1 for o in space if event(o)), len(space))
first_even = lambda o: o[0] % 2 == 0
sum_is_7 = lambda o: o[0] + o[1] == 7
both = prob(lambda o: first_even(o) and sum_is_7(o))
print(both) # 1/12
print(both == prob(first_even) * prob(sum_is_7)) # TrueConditional probability: shrinking the sample space
P(A|B) = P(A and B) / P(B). You restrict attention to outcomes where B happened. Given that the first die is even, there are 18 outcomes. Of these, the sum is 8 in three cases: (2,6), (4,4), and (6,2). So P(sum is 8 | first die even) = 3/18 = 1/6.
The general multiplication rule
P(A and B) = P(A) x P(B|A). This works for dependent events too. A bag holds 3 red and 2 blue marbles. Drawing two without replacement, P(both red) = 3/5 x 2/4 = 3/10. The second factor uses the updated count.
| Situation | Rule | Example value |
|---|---|---|
| Either event occurs | P(A) + P(B) - P(A and B) | 11/36 |
| Independent events, both occur | P(A) x P(B) | 1/12 |
| Any events, both occur | P(A) x P(B given A) | 3/10 |
Common errors: multiplying P(A) x P(B) for dependent events, forgetting to update counts without replacement, and omitting the overlap term in the addition rule.
Exercise
A bag has 4 red and 6 blue marbles. Two are drawn without replacement. What is P(both blue)?
Show answer
P = 6/10 x 5/9 = 30/90 = 1/3.