Logic, Sets and Infinity

Set Theory Basics, Unions, Intersections and Complements

Learn set notation, the main operations and their laws, and count elements correctly using worked examples with small numbers.

Key takeaways

  • A set is determined entirely by its members, so order and repetition make no difference.
  • The union uses "or", the intersection uses "and", and the complement uses "not".
  • A complement only makes sense relative to a stated universal set.
  • To count a union of two sets, add their sizes and subtract the size of the overlap.

A set is a collection of distinct objects, treated as a single thing. The three basic operations answer simple questions about two collections: what is in either one (union), what is in both (intersection), and what is left outside (complement).

Almost every branch of mathematics is written in this vocabulary, so a little fluency pays off in probability, algebra, analysis and computing.

Sets and their members

You can describe a set by listing its members in braces, as in {2, 3, 5, 7}. The members are also called elements. Write 3 ∈ A to say that 3 is an element of A, and 4 ∉ A to say that 4 is not.

You can also describe a set by a property. The notation {n ∈ ℕ : n is even and n < 10} reads "the set of natural numbers n such that n is even and less than 10". If the natural numbers ℕ include 0, as they do in this article, the set is {0, 2, 4, 6, 8}.

Two sets are equal when they have exactly the same members. So {1, 2, 3}, {3, 1, 2} and {1, 1, 2, 3} are all the same set.

The empty set, written ∅ or {}, has no members. Note that {∅} is not empty: it has one member, namely the empty set. Think of a box containing an empty box.

Subsets

A is a subset of B, written A ⊆ B, if every element of A is also in B. If in addition B has something A lacks, A is a proper subset.

Keep membership and inclusion apart. With B = {1, 2, 3}:

Statement True? Reason
2 ∈ B yes 2 is listed
{2} ⊆ B yes its only member is in B
{2} ∈ B no B's members are numbers, not sets
2 ⊆ B no here 2 is treated as an element, not a set of elements of B
∅ ⊆ B yes there is nothing in ∅ that could be missing

The last line is vacuously true, a notion explained in why a false premise makes an implication true. To prove A = B, the standard method is to show A ⊆ B and B ⊆ A.

Sets you will meet often

A few sets have standard symbols, and they nest inside one another.

  • ℕ, the natural numbers: 0, 1, 2, 3 and so on in this article. Some books start at 1, so check.
  • ℤ, the integers: the natural numbers together with their negatives.
  • ℚ, the rational numbers: all fractions p/q with p and q integers and q ≠ 0.
  • ℝ, the real numbers: every point on the number line, including √2 and π.

In symbols, ℕ ⊆ ℤ ⊆ ℚ ⊆ ℝ, and each inclusion is proper. The number −3 is in ℤ but not ℕ, one half is in ℚ but not ℤ, and √2 is in ℝ but not ℚ.

Intervals are subsets of ℝ with their own shorthand. A square bracket includes an end point and a round one leaves it out, so [1, 4) holds every real x with 1 ≤ x < 4. Then [1, 4) ∩ [3, 6] = [3, 4), while [1, 4) ∪ [3, 6] = [1, 6]. The complement of [1, 4) within ℝ is everything below 1 together with everything from 4 upward.

Union, intersection and difference

  • Union: A ∪ B = {x : x ∈ A or x ∈ B}. The "or" is inclusive.
  • Intersection: A ∩ B = {x : x ∈ A and x ∈ B}.
  • Difference: A \ B = {x : x ∈ A and x ∉ B}.
  • Symmetric difference: A △ B holds what is in exactly one of the two.

Let A = {1, 2, 3, 4, 5} and B = {4, 5, 6, 7}.

A ∪ B = {1, 2, 3, 4, 5, 6, 7}
A ∩ B = {4, 5}
A \ B = {1, 2, 3}
B \ A = {6, 7}
A △ B = {1, 2, 3, 6, 7}

Sets with an empty intersection are disjoint. The even and odd integers are disjoint, and their union is all of the integers.

Complements and the universal set

To say what is "not in A", you must say what the candidates are. Fix a universal set U containing everything under discussion. The complement of A is Aᶜ = U \ A.

If U = {1, 2, ..., 10} and A = {2, 4, 6, 8, 10}, then Aᶜ = {1, 3, 5, 7, 9}. Change U to the integers and the complement of the same A becomes infinite.

There is no universal set containing absolutely everything in standard set theory. Allowing one without restriction leads to trouble, described in Russell's paradox.

Where an element can be, given sets A and B
In A and in B The intersection In A, not in B The difference A \ B In B, not in A The difference B \ A In neither Complement of the union In A and in B The intersection In A, not in B The difference A \ B In B, not in A The difference B \ A In neither Complement of the union

Every element of U falls in exactly one of these four regions.

The laws of set algebra

Law Statement
Commutative A ∪ B = B ∪ A and A ∩ B = B ∩ A
Associative (A ∪ B) ∪ C = A ∪ (B ∪ C), and the same for ∩
Distributive A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
Distributive A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
Complement A ∪ Aᶜ = U and A ∩ Aᶜ = ∅
De Morgan (A ∪ B)ᶜ = Aᶜ ∩ Bᶜ and (A ∩ B)ᶜ = Aᶜ ∪ Bᶜ

These mirror the laws of logic because each operation is defined by a logical word. The same abstract pattern appears in Boolean algebra.

Proving an identity

Here is a proof that A \ B = A ∩ Bᶜ, where B lives inside U along with A. Take any x.

x ∈ A \ B
⇔ x ∈ A and x ∉ B           definition of difference
⇔ x ∈ A and x ∈ Bᶜ          x is in U, being in A
⇔ x ∈ A ∩ Bᶜ                definition of intersection

The symbol ⇔ means "if and only if". Since the two sets have the same members, they are equal. This technique, following a typical element, is called element chasing.

Disproving a false identity

Not every plausible formula holds. Consider the claim A \ (B \ C) = (A \ B) \ C, which looks like an associative law.

Take A = {1, 2}, B = {2} and C = {2}. On the left, B \ C is empty, so A \ (B \ C) = {1, 2}. On the right, A \ B = {1}, and removing C changes nothing, leaving {1}. The two sides differ, so set difference is not associative.

The example was found by looking for an element in all three sets, since that is where the two sides treat it differently. The left side keeps it, because it was removed from B before B was removed from A.

A true statement about the same expressions is A \ (B \ C) = (A \ B) ∪ (A ∩ C). An element survives on the left when it is in A and it is not the case that it is in B but not C. So it is in A and either outside B or inside C.

Counting elements

For a finite set A, write |A| for the number of elements. For two finite sets:

|A ∪ B| = |A| + |B| − |A ∩ B|

With the example above: 5 + 4 − 2 = 7, which matches the union listed.

Say that in a hypothetical class of 30, there are 18 students who play chess, 15 who play go, and 8 who play both. Then 18 + 15 − 8 = 25 play at least one, so 30 − 25 = 5 play neither. Exactly one game is played by (18 − 8) + (15 − 8) = 17.

For three sets, add the three sizes, subtract the three pairwise overlaps, and add back the triple overlap. This is the start of the inclusion-exclusion principle. Pictures help here, drawn carefully as in reading and drawing Venn diagrams.

Beyond two sets

You can take the union or intersection of any family of sets, even an infinite one. The union holds whatever belongs to at least one member of the family, and the intersection whatever belongs to all of them. For instance, let Iₙ be the interval of real numbers from 0 to 1/n, including 0 and excluding 1/n, for n = 1, 2, 3 and so on. Every Iₙ contains 0. No positive number lies in all of them, because 1/n eventually drops below it. So the intersection is {0}.

Two other constructions come up early. The Cartesian product A × B is the set of ordered pairs (a, b), and has |A| × |B| elements when both are finite. The power set of A is the set of all its subsets, with 2ⁿ members when A has n elements, as shown in power sets.

Where you will use this

In probability, an event is a subset of the set of all possible outcomes. "A or B happens" is the union, "both happen" is the intersection, and "A does not happen" is the complement. The counting formula above becomes the addition rule for probabilities.

In algebra, the solutions of two equations taken together form the intersection of their solution sets. The equation (x − 1)(x − 4) = 0 has the union of the solution sets of x − 1 = 0 and x − 4 = 0, namely {1, 4}.

In computing, a search for pages that mention one word and not another is a set difference, and many programming languages offer a built-in set type with these operations.

Practice with answers

Let U = {1, 2, ..., 12}, let E be the even numbers in U and let T be the multiples of 3 in U. Work these out before reading on: E ∩ T, E ∪ T, (E ∪ T)ᶜ and T \ E.

The overlap E ∩ T is {6, 12}, the multiples of 6. The union is {2, 3, 4, 6, 8, 9, 10, 12}, with 6 + 4 − 2 = 8 elements. Its complement is {1, 5, 7, 11}. Finally, T \ E = {3, 9}.

Common mistakes

  • Confusing ∈ with ⊆. Ask whether the thing on the left is one member or a collection of members.
  • Adding sizes without removing overlap. This counts shared elements twice.
  • Reading A \ B as symmetric. In general it differs from B \ A.
  • Taking a complement with no universe. State U first.
  • Treating ∅ and {∅} as equal. One has no elements, the other has one.

A good check on any claimed identity is to test it on small sets with all four regions occupied. One mismatch disproves it. A match is only encouragement, and the element-chasing proof finishes the job.

Written for 4Mathematics with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 41 articles in Logic, Sets and Infinity →

Latest news on this topic