Set Operations Calculator
Combine two sets with union, intersection, difference, symmetric difference, or complement, check whether one set is a subset of another and list its power set, build the Cartesian product of two sets, or verify whether a set identity like De Morgan's laws actually holds for your own sets. Every mode shows a distinct diagram, full step-by-step reasoning, and a callout explaining what the result means.
Background
A set is simply a collection of distinct elements, with no regard for order or repetition — {1, 2, 3} and {3, 1, 2, 2} describe the exact same set. Set operations are the rules for combining or comparing sets: union collects everything from either set, intersection keeps only what's shared, and so on. They show up constantly in probability, database queries, and logic, but the ideas are visual enough to reason about directly with a Venn diagram.
How to use this calculator
- Choose Basic Operations to combine two sets with union, intersection, difference, symmetric difference, or (given a universal set) complement.
- Choose Subsets & Power Set to check whether one set is contained in another, and to list every possible subset of a set.
- Choose Cartesian Product to list every ordered pair formed by combining one set's elements with another's.
- Choose Verify an Identity to check whether a classic set law (De Morgan's or the distributive law) actually holds true for sets you choose yourself.
- Click Calculate to see the diagram, the full step-by-step reasoning, and a callout explaining what the result means.
How Set Operations Work
A set has no duplicates and no order — {1,2,2,3} and {3,2,1} both describe the same set, {1,2,3}. This calculator automatically removes duplicates from whatever you type in.
Union (A ∪ B) collects every element that appears in A, in B, or in both — nothing is left out, and nothing is duplicated.
Intersection (A ∩ B) keeps only the elements that appear in both A and B at once.
Difference (A − B) keeps only what's in A but removes anything that's also in B. A − B and B − A are generally different sets.
Symmetric difference (A △ B) keeps everything that's in exactly one of the two sets — it's the union minus the intersection.
Complement (A′) needs a universal set U to make sense — it's everything in U that isn't in A.
A is a subset of B (A ⊆ B) when every element of A also belongs to B. The power set of A is the set of all its possible subsets, including the empty set and A itself — a set with n elements has exactly 2ⁿ subsets.
The Cartesian product A × B is the set of every ordered pair (a, b) with a from A and b from B. It has |A| × |B| pairs total, and (a, b) is generally different from (b, a).
The inclusion-exclusion principle explains why |A ∪ B| isn't simply |A| + |B|: |A ∪ B| = |A| + |B| − |A ∩ B|. Adding the two sizes double-counts every shared element once, so the overlap has to be subtracted back out.
Formulas & Equations Used
Union: A ∪ B = {x : x ∈ A or x ∈ B}
Intersection: A ∩ B = {x : x ∈ A and x ∈ B}
Difference: A − B = {x : x ∈ A and x ∉ B}
Symmetric difference: A △ B = (A ∪ B) − (A ∩ B)
Complement: A′ = {x ∈ U : x ∉ A}
Inclusion-exclusion: |A ∪ B| = |A| + |B| − |A ∩ B|
Power set size: |P(A)| = 2^|A|
Cartesian product size: |A × B| = |A| × |B|
Example Problems & Step-by-Step Solutions
Example 1 — Union
A = {1,2,3,4}, B = {3,4,5,6}. Find A ∪ B.
Step: Combine every element from both sets, listing shared elements (3, 4) only once.
Result: A ∪ B = {1,2,3,4,5,6}. Check: |A|+|B|−|A∩B| = 4+4−2 = 6. ✓
Example 2 — Complement
U = {1,...,8}, A = {2,4,6,8}. Find A′.
Step: Take every element of U that is not in A.
Result: A′ = {1,3,5,7}.
Example 3 — Power set
A = {1,2}. Find P(A).
Step: List every possible way to pick elements from A, including picking none or all.
Result: P(A) = {∅, {1}, {2}, {1,2}} — 2² = 4 subsets total.
Example 4 — Cartesian product
A = {1,2}, B = {x,y}. Find A × B.
Step: Pair every element of A with every element of B, keeping A's element first.
Result: A × B = {(1,x), (1,y), (2,x), (2,y)} — 2×2 = 4 pairs.
Frequently Asked Questions
Do the elements in a set have to be numbers?
No — this calculator accepts short text elements too (names, letters, words up to 24 characters), as long as they're separated by commas. Numbers and identical-looking text are treated as the same element.
What's the difference between A − B and B − A?
A − B keeps what's uniquely in A; B − A keeps what's uniquely in B. They're only equal when A and B don't share any elements at all (or are both empty).
Why does the complement need a universal set?
"Everything not in A" is meaningless without saying what the full universe of possible elements is. Complement is always relative to some U — without it, there's no way to know where to stop.
Is the empty set really a subset of everything?
Yes. A ⊆ B means every element of A is in B — and if A has no elements, that condition is trivially satisfied no matter what B is. This is why ∅ always appears in every power set.
Why does the order matter in a Cartesian product but not in a set?
A set just says which elements are present; an ordered pair (a, b) specifically tracks position, so (1,2) and (2,1) are different pairs even though {1,2} and {2,1} are the same set.
Do these identities always hold, no matter which sets I pick?
Yes — De Morgan's laws and the distributive law are true for every possible choice of sets, which is exactly why they're called laws rather than coincidences. This calculator lets you check that for yourself with specific sets rather than just taking it on faith.