Principle of Inclusion–Exclusion (PIE): Fundamentals and Extensions

Lesson · Intermediate

Combinatorics

Inclusion–Exclusion Principle for two sets

For finite sets A and B:

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

Inclusion–Exclusion Principle for three sets

For finite sets A, B, and C:

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

General Inclusion–Exclusion Principle for n sets

For sets A₁, A₂, ..., Aₙ:

∣A1∪A2∪⋯∪An∣=∑i∣Ai∣−∑i<j∣Ai∩Aj∣+∑i<j<k∣Ai∩Aj∩Ak∣−⋯ \left|A_1\cup A_2\cup\cdots\cup A_n\right| = \sum_i |A_i| -\sum_{i<j}|A_i\cap A_j| +\sum_{i<j<k}|A_i\cap A_j\cap A_k| -\cdots

In compact form, the general principle is:

∣⋃i=1nAi∣=∑k=1n(−1)k+1∑1≤i1<i2<⋯<ik≤n∣Ai1∩Ai2∩⋯∩Aik∣ \left|\bigcup_{i=1}^{n}A_i\right| = \sum_{k=1}^{n}(-1)^{k+1} \sum_{1\le i_1<i_2<\cdots<i_k\le n} \left|A_{i_1}\cap A_{i_2}\cap\cdots\cap A_{i_k}\right|

Counting elements in exactly one set

Let E_j denote the number of elements that are contained in exactly j of the sets A₁, A₂, ..., Aₙ.

For two sets:

E1=∣A1∣+∣A2∣−2∣A1∩A2∣ E_1=|A_1|+|A_2|-2|A_1\cap A_2|

For three sets:

E1=∣A1∣+∣A2∣+∣A3∣−2∣A1∩A2∣−2∣A1∩A3∣−2∣A2∩A3∣+3∣A1∩A2∩A3∣ E_1 = |A_1|+|A_2|+|A_3| -2|A_1\cap A_2| -2|A_1\cap A_3| -2|A_2\cap A_3| +3|A_1\cap A_2\cap A_3|

The coefficients here are different from those in the ordinary Inclusion–Exclusion formula.