Toolkit 50

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

Inclusion–Exclusion Principle for two sets

For finite sets AA and BB:

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

Inclusion–Exclusion Principle for three sets

For finite sets AA, BB, and CC:

ABC=A+B+CABACBC+ABC|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 A1,A2,,AnA_1,A_2,\dots,A_n:

A1A2An=iAii<jAiAj+i<j<kAiAjAk|A_1\cup A_2\cup\cdots\cup A_n|=\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+11i1<i2<<iknAi1Ai2Aik\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 PA1,A2,,AnP_{A_1,A_2,\dots,A_n} denote the number of elements that are contained in exactly one of the sets A1,A2,,AnA_1,A_2,\dots,A_n.

For two sets:

PA1,A2=A1+A22A1A2P_{A_1,A_2}=|A_1|+|A_2|-2|A_1\cap A_2|

For three sets:

PA1,A2,A3=A1+A2+A32A1A22A1A32A2A3+3A1A2A3P_{A_1,A_2,A_3}=|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 the ordinary Inclusion–Exclusion formula.