The two-set inclusion-exclusion formula

|A \cup B| = |A| + |B| - |A \cap B|

is the sort of identity that looks trivial once you have seen the Venn diagram and mysterious if you have not. Students learn it by copying, apply it robotically, and then get blindsided by a problem where the overlap is zero (or where it equals one of the sets outright). The fix is to turn the formula into a live object — one you can poke. Change one input and watch two other quantities change. After a minute of dragging, the subtraction stops being a memorised rule and starts being the only arithmetic that can possibly be correct.

The live calculator

Drag the three coloured dots below. The top dot controls |A|, the middle dot controls |B|, and the bottom dot controls |A \cap B|. The formula line at the top updates in real time.

Interactive inclusion-exclusion calculator with three draggable inputsThree parallel horizontal number lines labelled size of A, size of B, and size of A intersect B. Each line has a red draggable dot. A readout panel at the top shows the current values of the three inputs along with the computed size of A union B using the inclusion-exclusion formula. Below the lines, a legend explains that the union size equals size of A plus size of B minus size of A intersect B. drag the three red dots below |A| |B| |A∩B| 0 30
Three sliders — one for each term of the formula. The top readout computes $|A \cup B| = |A| + |B| - |A \cap B|$ live. Slide $|A \cap B|$ up to $|A|$ and notice that $|A \cup B|$ collapses to $|B|$. Slide it down to $0$ and the formula becomes plain addition.

What to notice while dragging

Three boundary cases are worth feeling, not just reading.

Disjoint sets. Drag |A \cap B| all the way to 0. The formula reduces to |A \cup B| = |A| + |B|. This is the everyday intuition — "two groups of students, no overlap, total is the sum." It is a special case, not the general rule. The moment any student is in both groups, addition over-counts.

Why: when A and B share no elements, each element of the union lives in exactly one of the two sets. Summing |A| and |B| visits each union-element exactly once, so no correction is needed.

One set inside the other. Set |A| = 10 and |B| = 6, then drag |A \cap B| up to 6. The readout shows |A \cup B| = 10. Why? Because B has slipped entirely inside A, so their union is just A. The formula gives 10 + 6 - 6 = 10, which matches. The subtraction has exactly cancelled the extra |B|.

Why: if every element of B is also in A, then A \cap B = B, so |A \cap B| = |B|, and the formula telescopes to |A \cup B| = |A|.

Impossible overlap. Try to drag |A \cap B| above \min(|A|, |B|). On paper, people sometimes write |A \cap B| = 12 while |A| = 10 and not notice. The Venn diagram forbids it — the intersection cannot be larger than either set, because the overlap is a subset of each. Whenever a competition problem lets you compute |A \cap B| from other data and the answer exceeds |A| or |B|, you have made an arithmetic error.

Reading the formula as a correction

The cleanest mental model is add-then-correct.

  1. Add. Sum |A| + |B| as if the two sets were disjoint. This counts every union-element at least once, but it double-counts every element that is in both.
  2. Correct. The elements in the overlap were counted twice — once inside |A| and once inside |B|. Subtracting |A \cap B| once removes one of the two counts, leaving exactly one.

Net effect: every element of A \cup B is counted exactly once. The formula is not a magic identity; it is a counting audit.

Worked check: class of 40, cricket and chess

In a class of 40 students, 28 play cricket, 15 play chess, and 9 play both. Find the number who play at least one game.

Set |A| = 28, |B| = 15, |A \cap B| = 9 in the live calculator. The readout gives |A \cup B| = 28 + 15 - 9 = 34.

Why: add the two sizes (28 + 15 = 43), then subtract the 9 double-counted students to get 34 distinct at-least-one-game players.

And since the class has 40 students, the number who play neither game is 40 - 34 = 6.

Sanity check. 34 \le 40. 34 \ge \max(28, 15) = 28. 34 \le 28 + 15 = 43. All three bounds are satisfied, so the answer is internally consistent.

Three bounds every answer must satisfy

The calculator enforces these silently, but writing them down is useful for spotting bad exam answers.

If an answer breaks any of these, the arithmetic is wrong somewhere upstream — recheck the givens before moving on.

Related: Set Operations · Three-Set Venn Diagram · Venn Diagrams from Scratch · Cardinality Meter · Sets — Introduction