Lesson 3 of 15

Complement Rule & At-Least-One Problems

The Complement Rule

From the axioms: P(A)+P(Ac)=1P(A) + P(A^c) = 1, so:

P(Ac)=1P(A)P(A^c) = 1 - P(A)

This is more powerful than it looks. Many problems are easier to solve via the complement.

At-Least-One Problems

What is the probability of getting at least one success in nn independent trials?

The complement is "zero successes in all nn trials":

P(at least one)=1P(all failures)=1(1p)nP(\text{at least one}) = 1 - P(\text{all failures}) = 1 - (1-p)^n

# P(at least one head in 3 fair coin flips)
p_failure = 0.5   # P(tails on one flip)
n = 3
p = 1 - p_failure**n
print(round(p, 4))  # 0.875

Birthday Problem

How many people do you need so there's a >50% chance two share a birthday? The complement is "all birthdays distinct":

P(match)=1365364(365n+1)365nP(\text{match}) = 1 - \frac{365 \cdot 364 \cdots (365-n+1)}{365^n}

The answer is just 23 people — a famously counterintuitive result.

Your Task

Implement at_least_one(p_failure, n_trials) that returns P(at least one success)=1pfailurenP(\text{at least one success}) = 1 - p_{\text{failure}}^n, rounded to 4 decimal places.

Pyodide loading...
Loading...
Click "Run" to execute your code.