Set Operations Calculator
Compute the union, intersection, difference, and symmetric difference of two sets.
A = {1, 2, 3} with |A| = 3; B = {2, 3, 4} with |B| = 3. Neither set is a subset of the other.
A set operation combines two sets of distinct elements. For A = {1, 2, 3} and B = {2, 3, 4}: the union A ∪ B = {1, 2, 3, 4}, the intersection A ∩ B = {2, 3}, the difference A − B = {1}, B − A = {4}, and the symmetric difference A △ B = {1, 4}. Neither set is a subset of the other.
What set operations do
A set is an unordered collection of distinct elements — no duplicates, no position. Set operations build a new set from two existing sets A and B. The union (A ∪ B) gathers every element that appears in either set; the intersection (A ∩ B) keeps only elements in both; the difference (A − B, also written A \ B) keeps elements of A that are not in B; and the symmetric difference (A △ B) keeps elements in exactly one of the two sets. This calculator parses each box into a set — splitting on commas or spaces and discarding duplicates — then reports every operation together with the cardinalities |A|, |B|, |A ∪ B|, and |A ∩ B|.
The four core operations in set-builder notation. A ⊆ B holds when every element of A is also in B.
Worked example: A = {1, 2, 3}, B = {2, 3, 4}
The two sets overlap in 2 and 3. Walk through each operation element by element.
- 1 Parse each set and remove duplicates. A = {1, 2, 3} and B = {2, 3, 4}. A set ignores order and repeats, so “2, 2, 3” collapses to {2, 3}.
- 2 Union — take everything, once. List every element from A or B without repeating shared ones: A ∪ B = {1, 2, 3, 4}, so |A ∪ B| = 4.
- 3 Intersection — keep the shared elements. Only 2 and 3 appear in both sets, so A ∩ B = {2, 3} and |A ∩ B| = 2.
- 4 Difference — subtract one from the other. Remove B’s elements from A: A − B = {1}. Remove A’s elements from B: B − A = {4}. Difference is not symmetric.
- 5 Symmetric difference — in exactly one set. Combine the two differences: A △ B = (A − B) ∪ (B − A) = {1, 4}. It equals the union minus the intersection.
- 6 Check subset and superset. A ⊆ B only if A − B is empty. Here A − B = {1} is not empty, so neither set is a subset of the other.
Set operations at a glance
Each operation with its meaning and its result for A = {1, 2, 3}, B = {2, 3, 4}.
| Operation | Meaning | Result |
|---|---|---|
| Union — A ∪ B | In A or B (or both) | {1, 2, 3, 4} |
| Intersection — A ∩ B | In both A and B | {2, 3} |
| Difference — A − B | In A but not B | {1} |
| Difference — B − A | In B but not A | {4} |
| Symmetric difference — A △ B | In exactly one set | {1, 4} |
| Subset — A ⊆ B | Every element of A is in B | false (A − B ≠ ∅) |
Duplicates, order, and the empty set
Because a set is defined by membership alone, duplicates and order carry no meaning. Entering “3, 1, 2” or “1, 1, 2, 3” both describe the set {1, 2, 3}, and the calculator normalises them before computing. The symmetric difference collects the elements that belong to exactly one set — equivalently A △ B = (A ∪ B) − (A ∩ B) — which makes it the set analogue of exclusive-or (XOR). When two sets share no elements they are disjoint, so A ∩ B = ∅ (the empty set) and A △ B equals the full union. A ⊆ B means B is a superset of A; if that holds in both directions the sets are equal.