liveBook · Manning

Complement rule

As explained in Statistics Every Programmer Needs

The complement rule calculates the probability of an event by subtracting the probability of that event's complement from one.

The complement rule finds the probability of an event by calculating the probability that it does not occur and subtracting that value from 1. For event A, the complement is written Aᶜ, so P(Aᶜ) = 1 − P(A), or equivalently P(A) = 1 − P(Aᶜ). Use it when the inverse event is easier to count or compute. section 3.2.1

Apply the rule in a short sequence:

  • Define the desired event and its complement. section 3.2.1
  • Calculate the complement, using the multiplication rule when repeated independent outcomes are involved. section 3.2.1
  • Subtract the complement probability from 1 and interpret the result as the probability of the desired event. section 3.2.3

Getting at least one 4

For two dice rolls, directly counting the cases containing at least one 4 requires three scenarios: a 4 first, a 4 second, or two 4s. The complement is simpler: neither die shows 4. Each die then has probability 5/6 of avoiding 4, so P(neither 4) = (5/6)² = 25/36. Therefore, P(at least one 4) = 1 − 25/36 = 11/36, about 31%. Python expresses the calculation as probability_not_4 = 5/6 and probability_not_4_both = pow(probability_not_4, 2). section 3.2.1

A bounded dice sum

Two dice produce a sum from 2 through 12. To find the probability of a sum between 2 and 11 inclusive, exclude the sole complementary outcome: a sum of 12, which requires double sixes and has probability 1/36. The desired probability is 1 − 1/36 = 35/36, approximately 97%. section 3.2.3

How Statistics Every Programmer Needs covers it

How deep it goes
Defines the formula and works through dice examples, stopping short of formal proof or broader distribution theory.
Examples
Uses two dice for at-least-one-four and bounded-sum problems, with short Python calculations for the first example.
What it assumes
Assumes basic event notation and probability arithmetic while reinforcing multiplication and addition rules through examples.
What you can do after
Apply the complement rule to shorten probability calculations and implement repeated complement probabilities in Python.
How it connects
Connects event complements with the multiplication rule and addition rule in probability calculations.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.