About the Inclusion-Exclusion Principle

This simulation visualises the inclusion-exclusion principle, the combinatorial rule for counting elements in the union of overlapping sets without double-counting their shared parts. For two sets it gives |A∪B| = |A| + |B| − |A∩B|, and for three sets |A∪B∪C| = |A| + |B| + |C| − |A∩B| − |A∩C| − |B∩C| + |A∩B∩C|. The principle alternately adds and subtracts intersection sizes so each element is counted exactly once.

You choose between 2-Set and 3-Set mode, then drag the region sliders (A only, B only, A∩B, and for three sets A∩C, B∩C, A∩B∩C) to reshape the Venn diagram against a universe of 100 elements. The View buttons switch between the Venn picture, a term-by-term Formula breakdown, and worked Examples such as divisibility counting, derangements, surjections and a sieve, showing where the principle is used in real combinatorics.

Frequently Asked Questions

What is the inclusion-exclusion principle?

It is a counting rule that finds how many elements lie in the union of several sets by adding the individual set sizes, then subtracting the sizes of all pairwise intersections, adding back triple intersections, and so on. The alternating signs correct for elements that would otherwise be counted more than once.

Why do we subtract the intersection?

When you add |A| and |B|, every element that belongs to both sets is counted twice — once in each. Subtracting |A∩B| removes exactly one of those duplicate counts, leaving each shared element counted just once. The simulation highlights this correction in the Formula view.

What is the formula for three sets?

|A∪B∪C| = |A| + |B| + |C| − |A∩B| − |A∩C| − |B∩C| + |A∩B∩C|. The single sets are added, the three pairwise overlaps are subtracted, and the central triple overlap is added back because it was first counted three times then removed three times.

What do the region sliders control?

Each slider sets the count of elements in one disjoint region of the Venn diagram: A only, B only, A∩B in 2-set mode, plus C only, A∩C only, B∩C only and A∩B∩C in 3-set mode. Full set sizes such as |A| are derived by summing the regions inside circle A.

What does the universe of 100 represent?

The dashed rectangle labelled 𝒰 = 100 is the total population of elements under consideration. The "Neither" result reports how many of those 100 fall outside every set, calculated as 100 minus the union size. It cannot drop below zero.

What is the difference between 2-Set and 3-Set mode?

2-Set mode shows two overlapping circles and the simpler two-term correction, while 3-Set mode adds a third circle with seven distinct regions and the longer alternating formula. Switching modes changes which sliders appear and how the union is computed.

Is the simulation mathematically accurate?

Yes. Because you enter the disjoint region counts directly, the union is simply their sum, and the Formula view reconstructs the same total through the inclusion-exclusion expansion. The two methods always agree, which demonstrates that the alternating sums genuinely avoid double-counting.

How does inclusion-exclusion generalise to n sets?

For n sets the union equals the sum of single set sizes, minus all pairwise intersections, plus all triple intersections, and so on, with the sign of each term given by (−1) raised to one less than the number of sets intersected. The number of terms grows as 2 to the power n minus one.

What is a derangement and how is it counted?

A derangement is a permutation in which no element stays in its original position. Inclusion-exclusion over the events "element i is fixed" gives D(n) = n! · Σ (−1)^k / k! for k from 0 to n. The Examples view shows D(4) = 9.

Where is inclusion-exclusion used in practice?

It underpins divisibility and prime counting in number theory, the sieve of Eratosthenes, counting surjective functions, probability of unions of events, and many database and search problems involving overlapping categories. The Examples panel works through several of these cases.