Inclusion–Exclusion Calculator screenshot

Inclusion–Exclusion Calculator

Apply inclusion–exclusion to up to four explicit sets, printing every intersection term and checking the total against a direct count of the union.

Privacy First
0 Runs
Updated 2026-11-22
Runs in your browser
No sign-up, no upload
Each term checkable

Inclusion–Exclusion Calculator

Apply inclusion–exclusion to up to four explicit sets, printing every intersection term and checking the total against a direct count of the union.

How this page computes

Each line is parsed into a set. Sizes and intersections are then computed for every non-empty subset of the sets by filtering the first member set's elements on membership in the others.

Terms alternate by subset size. The union is collected directly from all the elements, and the comparison between the two totals is printed as the final check.

The calculation runs entirely in this browser tab; nothing is uploaded.

The page applies inclusion–exclusion to up to four sets: add the singles, subtract the pairs, add the triples, subtract the quadruples. For {1,2,3}, {2,3,4} and {3,4,5} the sum is 3 + 3 + 3 − 2 − 1 − 2 + 1 = 5, which matches the five distinct elements.

Every term is printed with its intersection size, so the arithmetic can be followed rather than taken on trust. The union is also counted directly from the elements, and the two numbers are compared — that comparison is the point of the page.

How to use Inclusion–Exclusion Calculator

Type one set per line, each as a comma-separated list, then press Run. Two to four lines are accepted; one line is not an inclusion–exclusion problem, and five is past what this page takes.

The output prints each single set's size, then every intersection term with its sign, then the total and the directly counted union. A mismatch between the two would be a bug, and the page says so rather than hiding it.

Why the alternating sum counts each element once

An element that belongs to exactly k of the sets is counted once in each single, once in each of the C(k,2) pairs, once in each of the C(k,3) triples, and so on, with alternating signs. Those counts sum to 1 for every k of at least 1, by the binomial identity, so the element contributes exactly once.

An element in no set contributes nothing to any term. That is the whole proof, and the page makes it checkable by printing each term separately instead of jumping to the total.

What to Expect

Best for

  • The size of a union of two to four explicit sets
  • Checking an inclusion–exclusion computation term by term
  • Seeing why the alternating signs are correct

Not ideal for

  • More than four sets, which this page refuses
  • Sets described by a rule rather than listed
  • The seven Venn regions, which have their own page

What this tool keeps

  • Every element exactly as typed

What may need cleanup

  • Nothing: the total is final

Common errors

  • Fewer than two lines is refused with the reason
  • More than four lines is refused with the limit named
  • A sign is never guessed: each term is computed from the elements

Example use cases

  • Check 3 + 3 + 3 - 2 - 1 - 2 + 1 = 5 for three sets
  • See each pairwise intersection printed separately
  • Confirm a hand-worked union count

Sample input

{1,2,3}, {2,3,4}, {3,4,5} on three lines

Sample output

inclusion–exclusion total 5, direct union count 5

Who this is for

  • Students learning inclusion–exclusion
  • Readers checking a counting argument

Frequently asked questions

Why does the same element get counted several times?

Because each term counts a different intersection. The alternating signs make those counts cancel down to one per element, which is exactly the binomial identity the method rests on.

What is the direct count for?

It is an independent computation of the same quantity. If the formula and the direct count ever disagreed, one of them would be wrong, and the page prints both rather than only the one it trusts.

Can a set be empty?

Not on this page: an empty line is skipped and an empty field is refused. A genuinely empty set would contribute nothing, so leaving it out gives the same answer.

Developer program

Build custom tools for your store

Join the SDK program to create useful ecommerce utilities for your store.