4.9.2Probability Theory & Statistics

Inclusion-exclusion principle

1,884 words9 min readdifficulty · medium1 backlinks

WHY does this principle exist?

WHAT goes wrong with naive addition: an element in kk of the sets is added kk times when we want it added 11 time. We need a correction that nets to 11 for every k1k \ge 1.


Deriving the two-set case from scratch

WHY start here: every general case is built from this.

Partition the union ABA \cup B into three disjoint pieces:

  • only AA (not BB): size aa
  • only BB (not AA): size bb
  • both AA and BB: size c=ABc = |A \cap B|

Then by disjoint addition: AB=a+b+c.|A \cup B| = a + b + c. But A=a+c|A| = a + c and B=b+c|B| = b + c. So: A+B=(a+c)+(b+c)=a+b+2c.|A| + |B| = (a+c) + (b+c) = a + b + 2c. Why this step? The overlap cc appears in both A|A| and B|B|, hence twice. Subtract one copy of c=ABc = |A\cap B|: A+BAB=a+b+c=AB.|A| + |B| - |A\cap B| = a + b + c = |A\cup B|. \checkmark


Three sets — derive, don't memorise

Start by adding singles, then we over-subtract the pairwise overlaps and must add the triple back.

A+B+Ccounts a triple-element 3 times.|A| + |B| + |C| \quad\text{counts a triple-element 3 times.} Subtract the three pairwise intersections: (AB+AC+BC).-(|A\cap B| + |A\cap C| + |B\cap C|). Why this step? Each pairwise term removes the double-counting of elements in exactly two sets — good. But an element in all three sets sat in all three pairwise intersections, so it just got subtracted 33 times after being added 33 times → net 00. That's wrong; we want it counted once.

So add back the triple intersection once: +ABC.+|A\cap B\cap C|.

Figure — Inclusion-exclusion principle

The general formula (and WHY the signs alternate)

HOW the alternating signs are forced — first-principles proof. Take any element xx lying in exactly mm of the sets (m1m \ge 1). We must show the right-hand side counts it exactly once.

  • xx appears in (m1)\binom{m}{1} single terms, (m2)\binom{m}{2} pair terms, …, (mk)\binom{m}{k} of the kk-fold intersections.
  • Its net contribution is: S  =  k=1m(1)k+1(mk).S \;=\; \sum_{k=1}^{m} (-1)^{k+1}\binom{m}{k}. Use the binomial theorem with x=1x=-1: k=0m(1)k(mk)=(11)m=0.\sum_{k=0}^{m}(-1)^{k}\binom{m}{k} = (1-1)^m = 0. Why this step? This single identity contains all our terms, including the k=0k=0 term (m0)=1\binom{m}{0}=1. Split off k=0k=0: 0  =  (m0)+k=1m(1)k(mk)  =  1k=1m(1)k+1(mk)  =  1S.0 \;=\; \binom{m}{0} + \sum_{k=1}^{m}(-1)^{k}\binom{m}{k} \;=\; 1 - \sum_{k=1}^{m}(-1)^{k+1}\binom{m}{k} \;=\; 1 - S. Why the sign flip? For k1k\ge 1, (1)k=(1)k+1(-1)^k = -(-1)^{k+1}, so k=1m(1)k(mk)=S\sum_{k=1}^m(-1)^k\binom mk = -S. Hence 0=1S0 = 1 - S, giving S=1.S = 1. Every element is counted exactly once — QED.

Probability version


Worked examples


Common mistakes


Recall Feynman: explain to a 12-year-old

Suppose you ask your class "who plays football, and who plays cricket?" and add the two hand-counts. Some kids raised their hand twice because they play both! So you'd over-count them. To fix it, you count the both-players once and subtract them, so everyone is counted just one time. With three sports it's trickier: when you subtract the overlapping pairs you accidentally erase the "play-all-three" kids completely, so you have to add them back. That add–subtract–add dance is inclusion–exclusion.


Active recall

Two-set inclusion–exclusion formula
AB=A+BAB|A\cup B| = |A| + |B| - |A\cap B|
Why subtract the intersection in two-set case
Elements in both sets are counted twice in A+B|A|+|B|; subtracting AB|A\cap B| removes the one extra count.
Three-set inclusion–exclusion formula
A+B+CABACBC+ABC|A|+|B|+|C| - |A\cap B|-|A\cap C|-|B\cap C| + |A\cap B\cap C|
Sign pattern in general I–E
Odd-size intersections get ++, even-size get -: term for kk sets has sign (1)k+1(-1)^{k+1}.
Net count of an element in exactly mm sets
Exactly 11, since k=1m(1)k+1(mk)=1\sum_{k=1}^m(-1)^{k+1}\binom mk = 1.
Probability form for two events
P(AB)=P(A)+P(B)P(AB)P(A\cup B)=P(A)+P(B)-P(A\cap B)
Derangement formula via I–E
Dn=n!k=0n(1)kk!D_n = n!\sum_{k=0}^n \frac{(-1)^k}{k!}
Count of integers 29\le 29 divisible by 3 or 5
9+51=139+5-1=13
Why add back triple intersection
An all-three element is added 3 (singles) and subtracted 3 (pairs), netting 0; adding it once restores the correct count of 1.

Connections

  • Set Theory & Venn Diagrams — the union/intersection structure underlying the principle
  • Counting Principles & Combinatorics — uses (nk)\binom nk in the general proof
  • Probability Axioms — the additivity axiom is the disjoint special case
  • Derangements & Permutations — a classic application
  • Binomial Theorem — provides the (11)m=0(1-1)^m=0 identity that proves alternating signs
  • Bonferroni Inequalities — truncating I–E gives upper/lower bounds

Concept Map

naive sum over-counts

core fix

simplest case

derived from

overlap counted twice

extends to

triple subtracted 3 times

generalises to

uses

proved by

nets to

Counting problem: size of union

Over-counting overlaps

Add parts then remove overlaps

Two sets formula

Disjoint partition a b c

Subtract intersection once

Three sets formula

Add triple back once

General formula

Alternating signs

Binomial identity per element

Each element counted once

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, Inclusion–Exclusion ka core idea bahut simple hai: jab aap do groups ko "ya" (union) se count karte ho, to overlap wale log do baar count ho jaate hain. Jaise class mein football aur cricket khelne wale — jo dono khelte hain unka haath dono baar utha, isliye unhe ek baar subtract karna padta hai. Bas yahi soch hai: pehle saare add karo, phir jo extra count hua use minus karo, taaki har element exactly ek hi baar gine.

Teen sets ke case mein thoda twist hai. Jab aap saare pairwise overlaps subtract karte ho, to "teeno mein hone wale" elements galti se zero ho jaate hain (3 baar add, 3 baar subtract). Isliye triple intersection ko wapas plus karna padta hai. Yahi reason hai ki signs alternate hote hain — plus, minus, plus, minus. General rule: odd-size intersections ko ++, even-size ko - sign milta hai.

Yeh kyun important hai? Probability mein P(AB)=P(A)+P(B)P(AB)P(A\cup B)=P(A)+P(B)-P(A\cap B) direct isi se aata hai. Aur combinatorics mein derangements (jaise "koi bhi letter sahi envelope mein na jaaye") jaise tough problems isi principle se solve hote hain. Exam mein zyadatar mistake yahi hoti hai ki students triple intersection wapas add karna bhool jaate hain — to bas yaad rakho: subtract pairs, phir add triple. Practice karo do-teen Venn diagram problems, concept pakka clear ho jayega.

Go deeper — visual, from zero

Test yourself — Probability Theory & Statistics

Connections