How Union and Intersection Work
A set is a collection of distinct elements — numbers, letters, or any other items — with no regard to order and no duplicates. Given two sets A and B, the two most basic set operations are the union and the intersection. This calculator parses the elements you type into Set A and Set B, then computes their union, intersection, difference, and symmetric difference.
Formula and method
The union of A and B, written A ∪ B, is the set of every element that belongs to A, to B, or to both: A ∪ B = {x : x ∈ A or x ∈ B}. The intersection, written A ∩ B, is the set of elements that belong to both A and B: A ∩ B = {x : x ∈ A and x ∈ B}. The calculator also reports the relative difference A − B (elements in A that are not in B) and the symmetric difference A △ B = (A − B) ∪ (B − A), the elements that belong to exactly one of the two sets. To count elements without double-counting the overlap, the inclusion-exclusion principle gives |A ∪ B| = |A| + |B| − |A ∩ B|, since elements in the intersection are otherwise counted once in |A| and once again in |B|.
Common sources of error
- Treating a set like a list: a set never contains duplicates, so entering "2, 2, 3" is identical to entering "2, 3" — repeats collapse to a single element.
- Case and spacing mismatches: "Apple" and "apple" are different text elements unless you normalize capitalization first; extra spaces around commas are trimmed automatically by this tool.
- Confusing intersection with union: intersection is never larger than the smaller input set, while union is always at least as large as the bigger one — if your result breaks that rule, re-check which operation you meant.
Checking your result
A quick sanity check uses the inclusion-exclusion principle: the number of elements in the union plus the number in the intersection should always equal the number in A plus the number in B, i.e. |A ∪ B| + |A ∩ B| = |A| + |B|. If that identity does not hold for your two sets, an element was likely miscounted or mistyped.
Applications
Union and intersection appear throughout probability (combining or overlapping events), database queries (JOIN and UNION operations), search filtering (matching any keyword versus all keywords), and Venn-diagram reasoning in statistics and logic courses. Recording both sets and the operation used makes a result easy to reproduce or double-check later.