Method stop · When and why do we use it?

Inclusion–Exclusion

In the Chinese book: 容斥原理

Add, subtract the overlaps, add back… until every element is counted once.

Before this stop, visit:Counting the Elements of a Finite Set (Skill)The Extremal Principle (Method)

One idea, one pictureTurn on only |A|, |B|, |C| first and see which regions are counted too often. Which terms must you add so that every region is counted exactly once?

Loading figure…

In one sentence

When several sets are pairwise disjoint, the size of their union is the sum of their sizes (the addition principle). When they overlap, the overlaps are counted too often and must be subtracted; if you subtract too much, add it back:

This is the inclusion–exclusion principle. The workbench above marks how many times each region has been counted: the formula is right exactly when every region is counted time.

Why every region is counted exactly once

Step 1 / 4
Loading figure…
  1. Add everything first

    : regions inside one circle are counted time, regions inside two circles times, and the middle times.

Stop 1 · Integers: counting “none of them”

How many numbers in are coprime to ? Being coprime to means being a multiple of neither , nor , nor : the region outside all the circles. Above, the circles hold numbers, so the outside has .

Predict first

How many numbers in are multiples of neither , nor , nor ?

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

Stop 2 · Permutations: derangements

letters go into addressed envelopes, every letter in a wrong envelope. In how many ways can this happen?

Counting derangements by inclusion–exclusion

Step 1 / 4
  1. Set up the sets

    There are ways to fill the envelopes. Let be the ways in which letter is in the right envelope. We want the ways that lie in none of the .

Stop 3 · Mappings: no empty box

In how many ways can different balls go into different boxes with no box empty? Two ways of thinking, and the answers must agree:

One problem, several solutions

different balls go into different boxes with no box empty. Count the ways.

Inclusion–exclusion: remove the ways with an empty box

Without restrictions there are ways. Let be “box is empty”: , , and all three empty is impossible.

The ways with an empty box number , so the ways with no empty box number .

CostMechanical, and works just as well for balls and boxes.

Partitions: group first, then assign

First split the balls into non-empty groups: ways (an exercise in station 4). Then hand the groups to the boxes: ways.

In all, ways.

CostYou need to count partitions first (station 4), but the structure is clearer.

Practice

Exercise 1Basic

How many numbers in are multiples of or multiples of ?

Exercise 2Basic

A class has students. are in the math club, are in the physics club, and are in neither. How many are in both?

Exercise 3Advanced

people each write a greeting card. The cards are collected and handed back at random, one per person. In how many ways can this be done so that nobody gets their own card?

Exercise 4Challenge

In how many ways can different balls go into different boxes with no box empty?

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:
What went wrong? Think first, then open

Diagnosis Look at the middle region : the first three terms count it times, the last three subtract it times, leaving times. It has been left out.

The right step: Add back. On the workbench, switch off the last term and the middle region immediately turns amber and is marked “”.

“If you subtract too much, add it back, until every region is counted exactly once”

Exhibit

Counting “neither” and stopping after subtracting

The wrong step: The numbers in that are neither multiples of nor multiples of number .
What went wrong? Think first, then open

Diagnosis The numbers are multiples of both and , so they were subtracted twice. In fact there are : .

The right step: Find the union first: , then take the complement: .

“To count a complement, first get the union right”