liveBook · Manning

Addition rule

As explained in Statistics Every Programmer Needs

The addition rule of counting determines the number of outcomes from mutually exclusive alternatives by adding their numbers of possibilities.

Use the addition rule when an outcome can come from one of several mutually exclusive alternatives. Count the possibilities in each alternative, then add the counts. For events that cannot occur together, add their individual probabilities to find the probability of either event: P(A or B) = P(A) + P(B). Check that the alternatives do not overlap before adding. section 2.2.2

Choose the rule by asking what can happen in one trial:

  • One action or the other: flipping a coin offers 2 outcomes; rolling a die offers 6. If only one action is performed, there are 2 + 6 = 8 possible action-and-result outcomes. This is a count, not a probability. section 2.2.2
  • Both actions: flipping a coin and rolling a die produces combinations of results, so multiply 2 × 6. Independent events occurring together call for the multiplication rule, not this count of alternatives. section 2.2 section 2.2.2

Two dice: a sum of 7 or 11

A roll cannot have both sums, so their probabilities can be added. Enumerate the 36 ordered pairs and check each count before calculating the result: pairs = [(a, b) for a in range(1, 7) for b in range(1, 7)] seven = sum(a + b == 7 for a, b in pairs) eleven = sum(a + b == 11 for a, b in pairs) print(seven, eleven, len(pairs)) # 6 2 36 print(f'{(seven + eleven) / len(pairs):.4f}') # 0.2222 Thus P(sum is 7 or 11) = 6/36 + 2/36 = 8/36, about 22.2%. The separate counts validate the numerator; mutual exclusivity justifies adding them. section 3.2.3

The same idea accumulates probabilities in a discrete cumulative distribution function: P(X ≤ x) sums the probabilities of eligible values. For two dice, the probabilities of sums 2, 3, and 4 add to P(X ≤ 4) ≈ 0.167. When an event includes many values, computing its complement may be simpler than adding every case. section 2.4.3 section 3.2.3

Figure 2.5 The CDF for rolling a pair of six-sided dice. The shape of the distribution resembles a two-dimensional flight of stairs in which the horizontal line segments represent consecutive values for x and the vertical lines represent their respective probabilities.
figure

The two-dice CDF plot shows successive probabilities accumulating into a step-shaped total. section 2.4.3

How Statistics Every Programmer Needs covers it

How deep it goes
Defines the exclusivity condition, contrasts multiplication, and works numerical examples; does not develop a rule for overlapping events.
Examples
Uses coin-or-die choices, travel routes, and two-dice sums of 7 or 11.
What it assumes
Builds from elementary outcome counts and probabilities, illustrating exclusivity with familiar coin and dice outcomes.
What you can do after
Apply it to count exclusive alternatives and calculate disjoint-event probabilities after checking that outcomes cannot overlap.
How it connects
Connects mutually exclusive events with the multiplication rule, complementary rule, and cumulative distribution functions.

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.