MathorynMathematical Formula Database

Combinatorics

Inclusion–Exclusion Principle

The inclusion–exclusion principle counts elements in a union by adding the sizes of the sets and subtracting the overlaps. For three sets it continues with +∣A∩B∩C∣+|A\cap B\cap C| after subtracting all pairwise intersections.

∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A\cup B|=|A|+|B|-|A\cap B|
LaTeX|A\cup B|=|A|+|B|-|A\cap B|

Variables

∣A∣|A|
number of elements of A
A∩BA\cap B
elements in both sets

Example

How many integers from 1 to 100 are divisible by 2 or 3?

  1. ∣A∣=50, ∣B∣=33, ∣A∩B∣=16|A|=50,\ |B|=33,\ |A\cap B|=16 (multiples of 6).
  2. 50+33−1650+33-16.

Answer: 6767.

Related formulas