Method line M5 · When and why do we use it?

Inclusion–Exclusion

In the Chinese book: 容斥原理

Add the parts, subtract what you overcounted, add back what you oversubtracted.

📖 Chapter 5 of 《解题方法与策略》

One idea, one pictureSwitch on the seven terms of the formula one at a time, and watch the middle region. How many times has it been counted? With all seven terms on, what does each badge say?

Loading figure…

In one sentence

Why these seven terms, with these signs? Look at any single element. If it belongs to exactly of the sets (), the formula counts it

times: no more, no less, exactly once. The figure above spreads this out for you: each term you switch on adds one to, or takes one from, the “times counted” of the regions it covers.

Example: how many numbers from 1 to 100 are multiples of 2, 3 or 5?

Step 1 / 4
Loading figure…
  1. First add the single sets

    , , . The regions where two sets overlap are counted times; the very middle is counted times.

Predict first

After adding the three single sets and subtracting the three pairwise intersections, how many times in total has the region common to all three () been counted?

Choose an answer first; then you can see the result.

Stop 1 · Operations on Sets (Vol. 1)

“Satisfies none of them” is the intersection . By De Morgan's laws it equals : count the union first, then subtract it from the universal set.

Example: how many numbers from 1 to 1000 are multiples of none of 2, 3 and 5?

Step 1 / 4
  1. De Morgan

    We are counting the intersection of three complements, which is the complement of the union.

Stop 2 · Counting the Elements of a Finite Set (Vol. 1)

Count surjections: every element of the target is hit at least once. The opposite is “some element is never hit”, which is exactly what inclusion–exclusion does best.

Example: how many surjections are there from a 5-element set onto the 3-element set {a, b, c}?

Step 1 / 4
  1. All mappings

    Each element has places to go.

Stop 3 · Inclusion–Exclusion and derangements (Vol. 1)

letters go into addressed envelopes. In how many ways can every letter go into the wrong envelope? That is the derangement number .

Example: find D₄

Step 1 / 4
  1. Bad events

    : letter is in the right envelope. A derangement is when none of the happens.

Practice

Exercise 1Basic

How many of are multiples of or multiples of ?

Exercise 2Advanced

How many of are divisible by none of ?

Exercise 3Advanced

people each write a greeting card. The cards are collected, shuffled and handed out, one per person. In how many ways can this happen so that nobody gets their own card?

Exercise 4Challenge

In how many ways can different balls be put into different boxes so that every box gets at least one ball?

Mistake Museum · Exhibits from this stop

Before you leave, look at the traps other people fell into here.See every exhibit in the museum →

Exhibit

Stopping after subtracting the pairwise intersections

The wrong step: Among there are multiples of , or .
What went wrong? Think first, then open

Diagnosis When you add the three sets, the numbers that are multiples of all of () are counted times; when you subtract the three pairwise intersections they are subtracted times. In the end they are not counted at all.

The right step: Add back the intersection of all three sets: . The formula for three sets has seven terms, with signs alternating .

“Added three times and subtracted three times means never counted”

Exhibit

Dividing by the wrong number for an intersection

The wrong step: Among there are numbers that are multiples of both and .
What went wrong? Think first, then open

Diagnosis Being a multiple of both and means being a multiple of their least common multiple , not of their product . The number itself was missed.

The right step: There are . The lcm equals the product only when the two numbers are coprime.

“For an intersection, use the lcm”

Stops on this line

The same idea, used once in each of several places.

  1. Operations on SetsVol. 1 Sets, ch. 2
  2. Counting the Elements of a Finite SetVol. 1 Sets, ch. 3
  3. Inclusion–ExclusionVol. 1 Sets, ch. 9