The operations, and what each one asks
A set is an unordered collection of distinct things. Two properties follow immediately and both trip people up: {1, 2, 2, 3} is the same set as {1, 2, 3}, because repetition carries no information, and {3, 1, 2} is the same set again, because order carries none either. This calculator therefore removes duplicates on input and displays results in sorted order purely for readability.
The operations answer different membership questions about an element x:
- Union
A ∪ B- is x in A or in B (or both)? - Intersection
A ∩ B- is x in A and in B? - Difference
A − B- is x in A but not in B? - Symmetric difference
A Δ B- is x in exactly one of them? - Complement
A′- is x in the universe but not in A?
Read that list again as logic and the correspondence is exact: union is OR, intersection is AND, complement is NOT, and symmetric difference is exclusive OR. That is not an analogy - set algebra and Boolean algebra are the same structure with different notation, and every identity in one has a twin in the other.
Two further constructions change the type of the answer rather than filtering it. The power set P(A) is the set of all subsets of A, so its members are sets rather than elements. The Cartesian product A × B is the set of all ordered pairs with the first entry from A and the second from B - and because the pairs are ordered, A × B and B × A are different sets whenever A and B differ.
Counting: inclusion-exclusion and the two size rules
The cardinality of a union is not the sum of the cardinalities, because elements in both sets would be counted twice. Subtracting the overlap once fixes it:
|A ∪ B| = |A| + |B| − |A ∩ B|
For three sets the pattern continues, adding back what has been over-subtracted:
|A ∪ B ∪ C| = |A| + |B| + |C| − |A∩B| − |A∩C| − |B∩C| + |A∩B∩C|
The alternating signs are the whole content of the inclusion-exclusion principle, and it generalises to any number of sets with the same alternation. It is the counting tool behind derangement problems, the sieve of Eratosthenes, and the probability rule P(A or B) = P(A) + P(B) − P(A and B), which is the identical statement with measure in place of count.
Two more counting rules are worth knowing cold. The power set has |P(A)| = 2|A| members, because building a subset means making an independent in-or-out decision for each of the |A| elements. And the Cartesian product has |A × B| = |A| · |B| members, one for each way of choosing a first entry and then a second.
Notice the boundary cases those formulas handle correctly. The empty set has 20 = 1 subset - itself - so P(∅) = {∅}, a set with one member, not an empty set. And ∅ × B is empty for any B, since there is no first entry to choose.
The complement is the only operation that needs outside information. A′ is meaningless until you say what the universe is: the complement of the even numbers is the odd numbers within the integers, but something quite different within the reals. That is why the universal set is a separate input here, and why the calculator refuses to compute a complement without one.
Worked example: A = {1, 2, 3, 4, 5} and B = {4, 5, 6, 7}
Take the universe to be U = {1, 2, …, 10}.
- Union. Everything in either set:
A ∪ B = {1, 2, 3, 4, 5, 6, 7}, seven elements. - Intersection. Only what appears in both:
A ∩ B = {4, 5}, two elements. - Check inclusion-exclusion. |A| + |B| − |A ∩ B| = 5 + 4 − 2 = 7. That matches the union count, which is the arithmetic check worth doing every time.
- Differences.
A − B = {1, 2, 3}andB − A = {6, 7}. These are different sets - set difference is not commutative. - Symmetric difference. The two differences combined:
A Δ B = {1, 2, 3, 6, 7}, five elements. Equivalently |A ∪ B| − |A ∩ B| = 7 − 2 = 5. - Complements.
A′ = {6, 7, 8, 9, 10}andB′ = {1, 2, 3, 8, 9, 10}. - De Morgan check.
(A ∪ B)′ = {8, 9, 10}. AndA′ ∩ B′- the elements in both complements - is also{8, 9, 10}. The law holds. - Counts. The power set of A has 25 = 32 subsets, and A × B has 5 × 4 = 20 ordered pairs.
One warning about that last line. A × B has 20 members; B × A also has 20, but they are not the same 20. (1, 4) belongs to the first and (4, 1) to the second, and the two products share no member at all unless A and B overlap.
Reading the relationships
Three relationships between two sets matter more than the rest, and the calculator reports each when it holds.
Disjoint means the intersection is empty - the sets share nothing. Then |A ∪ B| collapses to |A| + |B| with no correction term, and in probability, disjoint events cannot both occur, so their probabilities simply add.
Subset means every element of one lies in the other. When A ⊆ B, the union is B and the intersection is A - the two operations degenerate. Every set is a subset of itself, and the empty set is a subset of every set, which is why ∅ ⊆ A is always true and not a special case.
Equal means each is a subset of the other. That is the standard way to prove two set expressions describe the same set: show containment in both directions. It is worth noticing that equality has nothing to do with the order you typed the elements in.
Watch the cardinality of the symmetric difference as a distance. |A Δ B| counts the elements the two sets disagree about, and it behaves like a genuine metric: zero exactly when the sets are equal, symmetric in A and B, and obeying the triangle inequality. Divide it by |A ∪ B| and you have the Jaccard distance used to compare documents, gene sets and search results.
Set identities worth memorising
| Name | Set form | Boolean form |
|---|---|---|
| Commutative | A ∪ B = B ∪ A | a + b = b + a |
| Associative | (A ∪ B) ∪ C = A ∪ (B ∪ C) | (a + b) + c = a + (b + c) |
| Distributive | A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) | a(b + c) = ab + ac |
| De Morgan (union) | (A ∪ B)′ = A′ ∩ B′ | (a + b)′ = a′b′ |
| De Morgan (intersection) | (A ∩ B)′ = A′ ∪ B′ | (ab)′ = a′ + b′ |
| Idempotent | A ∪ A = A | a + a = a |
| Absorption | A ∪ (A ∩ B) = A | a + ab = a |
| Double complement | (A′)′ = A | (a′)′ = a |
| Difference as intersection | A − B = A ∩ B′ | ab′ |
| Symmetric difference | A Δ B = (A − B) ∪ (B − A) | a ⊕ b = ab′ + a′b |
The Boolean column uses + for OR, juxtaposition for AND and a prime for NOT. Every row can be verified on this page by entering sets that make both sides computable.
Where people go wrong
- Treating a set like a list. Duplicates vanish and order is meaningless. If you need repetition, you want a multiset or bag; if you need order, you want a sequence or tuple.
- Assuming set difference is commutative. A − B and B − A are different sets, and they are equal only when both are empty - that is, only when A = B.
- Taking a complement without a universe. A′ is undefined until the universal set is stated, and it changes completely when the universe changes.
- Confusing ∈ with ⊆. For A = {1, 2}, we have 1 ∈ A and {1} ⊆ A, but 1 ⊆ A and {1} ∈ A are both false. Elements and subsets are different kinds of thing - and the distinction matters most inside power sets, where the members are themselves sets.
- Writing the empty set as {∅}. Those differ: ∅ has no members and {∅} has exactly one, namely the empty set. |∅| = 0 and |{∅}| = 1.
- Adding cardinalities without subtracting the overlap. |A| + |B| overcounts every shared element exactly once, which is what inclusion-exclusion corrects.
Why these operations turn up everywhere
Relational databases are set theory with a query language on top. SQL's UNION, INTERSECT and EXCEPT are exactly the three operations above - with one important difference: SQL tables are multisets by default, so UNION ALL keeps duplicates while plain UNION removes them and behaves like the set operation. A CROSS JOIN is the Cartesian product, and its row count is the product of the two table sizes, which is why an accidental cross join is so catastrophic on large tables.
Probability is measure theory on sets. Events are subsets of a sample space, P(A ∪ B) = P(A) + P(B) − P(A ∩ B) is inclusion-exclusion, mutually exclusive means disjoint, and the complement rule P(A′) = 1 − P(A) is the complement operation with the universe being the whole sample space.
In combinatorics, the power-set formula 2n is the reason a set of n elements has that many subsets, and splitting the count by subset size gives the binomial coefficients, since the number of k-element subsets is exactly n choose k. Summing those coefficients over all k returns 2n, which is the combinatorial proof of the power-set rule.
In digital logic, sets over a universe of n elements are bit vectors of length n, and the operations become bitwise AND, OR, XOR and NOT - which is why set operations on small universes are among the fastest things a processor does. The same correspondence lets you carry any identity from the table above straight into a truth table or a Karnaugh map, and back again.
Notation
- ∈
- Membership:
3 ∈ {1, 2, 3}reads ‘3 is an element of the set’. - ⊆
- Subset: every element of the left set is in the right set. Every set is a subset of itself.
- ∅
- The empty set: the unique set with no members. Its cardinality is 0 and it is a subset of every set.
- |A|
- Cardinality: the number of distinct elements in A.
- P(A)
- Power set: the set of all subsets of A, with 2|A| members.
- A × B
- Cartesian product: all ordered pairs (a, b) with a in A and b in B.
