Set Operations
Set operations combine sets into new sets. The union A ∪ B holds every element in A or B, the intersection A ∩ B holds the elements in both, the difference A − B holds the elements of A that are not in B, and the complement Ac holds everything in the universal set that is not in A.
Before this lesson: Sets and Subsets and Logical Equivalence
The four set operations
Each operation is built from a logical connective. Union uses “or,” intersection uses “and,” and complement uses “not.” The universal set U is the set of all objects under discussion, and the complement only makes sense once U is fixed.
| Operation | Symbol | Set-builder definition | In words |
|---|---|---|---|
| Union | A \cup B | \{x : x \in A \lor x \in B\} | in A, in B, or in both |
| Intersection | A \cap B | \{x : x \in A \land x \in B\} | in both A and B |
| Difference | A - B | \{x : x \in A \land x \notin B\} | in A but not in B |
| Complement | A^c | \{x \in U : x \notin A\} | in U but not in A |
Other books write A ∖ B for the difference and A′ or Ā for the complement. Two sets are disjoint when A ∩ B = ∅, so they share no elements.
Venn diagrams
A Venn diagram draws U as a rectangle and each set as a circle inside it. The overlap of two circles is A ∩ B, everything inside either circle is A ∪ B, the part of A outside B is A − B, and the region outside both circles is (A ∪ B)c.
Laws of set operations
Every law of logical equivalence gives a law for sets. The most used are De Morgan’s laws and the distributive laws:
(A \cup B)^c = A^c \cap B^c \qquad (A \cap B)^c = A^c \cup B^c
A \cap (B \cup C) = (A \cap B) \cup (A \cap C) \qquad A \cup (B \cap C) = (A \cup B) \cap (A \cup C)
Two more facts come up often: A − B = A ∩ Bc, and for finite sets, |A ∪ B| = |A| + |B| − |A ∩ B|. The second formula subtracts the overlap because it was counted twice.
How to prove a set identity
- To show two sets are equal, show that x is in the left side exactly when x is in the right side.
- Rewrite membership in each side with the definitions: ∪ becomes “or,” ∩ becomes “and,” and complement becomes “not.”
- Use a law of logic, such as De Morgan’s law, to turn one statement into the other.
- Or build a membership table: like a truth table, with 1 for “in the set” and 0 for “not in the set.” The identity holds when the two final columns match in every row.
Set operations examples
Example 1: Finding unions, intersections and complements
Let U = {1, 2, …, 10}, A = {2, 4, 6, 8, 10} and B = {3, 6, 9}. Find A ∪ B, A ∩ B, A − B, B − A, Ac and (A ∪ B)c.
A \cup B = \{2, 3, 4, 6, 8, 9, 10\}Combine the elements of both sets, listing 6 only once.
A \cap B = \{6\}6 is the only element in both sets.
A - B = \{2, 4, 8, 10\}Remove 6 from A, since 6 ∈ B.
B - A = \{3, 9\}Remove 6 from B, since 6 ∈ A.
A^c = \{1, 3, 5, 7, 9\}List the elements of U that are not in A.
(A \cup B)^c = \{1, 5, 7\}List the elements of U that are not in A ∪ B.
Answer: A ∪ B = {2, 3, 4, 6, 8, 9, 10}, A ∩ B = {6}, A − B = {2, 4, 8, 10}, B − A = {3, 9}, Ac = {1, 3, 5, 7, 9} and (A ∪ B)c = {1, 5, 7}. Notice that A − B ≠ B − A.
Example 2: Survey of students (word problem)
In a class of 40 students, 22 play a sport, 15 play an instrument, and 8 do both. How many students do at least one activity? How many do neither? How many play a sport but no instrument?
\vert S \cup M\vert = \vert S\vert + \vert M\vert - \vert S \cap M\vert
Let S = sport players and M = instrument players. Use the union formula.
\vert S \cup M\vert = 22 + 15 - 8
Substitute the counts.
\vert S \cup M\vert = 29
22 + 15 = 37 and 37 − 8 = 29.
\vert (S \cup M)^c\vert = 40 - 29 = 11
Neither: subtract from the class size.
\vert S - M\vert = 22 - 8 = 14
Sport only: remove the students who do both.
Answer: 29 students do at least one activity, 11 do neither, and 14 play a sport but no instrument. A Venn diagram would show 14, 8 and 7 in the circles and 11 outside, which adds up to 40.
Example 3: Operations on intervals
Let A = [−2, 3) and B = (1, 5], with U = ℝ. Find A ∪ B, A ∩ B, A − B, B − A and Ac.
A \cup B = [-2, 5]
The intervals overlap, so together they run from −2 to 5, keeping each closed endpoint.
A \cap B = (1, 3)
Both conditions hold for x > 1 and x < 3; both endpoints are excluded.
A - B = [-2, 1]
Remove (1, 5] from A; 1 is not in B, so it stays.
B - A = [3, 5]
Remove [−2, 3) from B; 3 is not in A, so it stays.
A^c = (-\infty, -2) \cup [3, \infty)
Everything in ℝ that is not in A.
Answer: A ∪ B = [−2, 5], A ∩ B = (1, 3), A − B = [−2, 1], B − A = [3, 5] and Ac = (−∞, −2) ∪ [3, ∞). Draw both intervals on a number line, as in compound inequalities, to check the endpoints.
Example 4: Proving De Morgan’s law for sets
Prove that (A ∪ B)c = Ac ∩ Bc.
x \in (A \cup B)^c
Start with an arbitrary element x of U.
\iff \lnot(x \in A \cup B)
Definition of complement.
\iff \lnot(x \in A \lor x \in B)
Definition of union.
\iff (x \notin A) \land (x \notin B)
De Morgan’s law for logic: ¬(p ∨ q) ≡ ¬p ∧ ¬q.
\iff x \in A^c \land x \in B^c
Definition of complement, twice.
\iff x \in A^c \cap B^c
Definition of intersection.
Answer: every step is an “if and only if,” so x ∈ (A ∪ B)c exactly when x ∈ Ac ∩ Bc. The two sets are equal. Check with Example 1: Ac ∩ Bc = {1, 3, 5, 7, 9} ∩ {1, 2, 4, 5, 7, 8, 10} = {1, 5, 7}.
Example 5: A membership table for the distributive law
Use a membership table to prove that A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C).
| A | B | C | B \cup C | A \cap (B \cup C) | A \cap B | A \cap C | (A \cap B) \cup (A \cap C) |
|---|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 |
| 1 | 0 | 1 | 1 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
2^3 = 8
Three sets give 8 rows, one for each way an element can be in or out of A, B and C.
B \cup C
Column 4 is 1 when B or C is 1.
A \cap (B \cup C)
Column 5 is 1 when A and column 4 are both 1.
A \cap B,\ A \cap C
Columns 6 and 7 are 1 when both of their sets are 1.
(A \cap B) \cup (A \cap C)
Column 8 is 1 when column 6 or column 7 is 1.
Answer: columns 5 and 8 match in all 8 rows, so A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C). Both sides are 1 exactly in the first three rows.
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Adding counts for a union | |S ∪ M| = 22 + 15 = 37 in Example 2 | Subtract the overlap: 22 + 15 − 8 = 29. |
| Treating difference as symmetric | Writing A − B = B − A | In Example 1, A − B = {2, 4, 8, 10} but B − A = {3, 9}. |
| Taking a complement with no universal set | Writing {1, 2}c with no U given | State U first. The complement changes when U changes. |
| Flipping only the sets in De Morgan’s law | (A ∪ B)c = Ac ∪ Bc | Also switch the operation: (A ∪ B)c = Ac ∩ Bc. |
| Mixing up endpoints with intervals | [−2, 3) − (1, 5] = [−2, 1) | 1 is not in (1, 5], so it stays in A − B: the answer is [−2, 1]. |
| Proving an identity with one example | Checking one Venn diagram with numbers and stopping | An example can disprove an identity. To prove one, chase an arbitrary element or use a membership table. |
Related ideas
Probability uses the same operations on events, which are sets of outcomes; see axioms of probability in Probability Theory.
The union formula is the two-set case of the inclusion-exclusion principle, which this course covers in the counting unit. The same formula appears as the addition rule in probability, where A ∪ B and A ∩ B are events. Set laws and laws of logic match because each set operation is defined by a connective from propositional logic.
Practice problems
For Problems 1–6, let U = {1, 2, …, 12}, A = {1, 2, 3, 4, 5, 6}, B = {4, 5, 6, 7, 8} and C = {2, 4, 6, 8, 10, 12}.
- Find A ∪ B.
- Find A ∩ C.
- Find B − A.
- Find Cc.
- Find (A ∩ B)c, and check that it equals Ac ∪ Bc.
- Find A ∩ (B ∪ C).
- A bakery had 60 customers. 35 bought coffee, 28 bought a pastry, and 12 bought both. How many bought neither? How many bought only a pastry?
- Let A = (0, 4] and B = [2, 6). Find A ∪ B, A ∩ B and A − B.
- Prove that A − B = A ∩ Bc.
- Use a membership table to decide whether (A − B) ∪ (B − A) = (A ∪ B) − (A ∩ B).
Show answers
1.
A \cup B = \{1, 2, 3, 4, 5, 6, 7, 8\}Combine both lists; 4, 5 and 6 appear once.
Answer: {1, 2, 3, 4, 5, 6, 7, 8}
2.
A \cap C = \{2, 4, 6\}Keep the even numbers of A.
Answer: {2, 4, 6}
3.
B - A = \{7, 8\}Remove 4, 5 and 6, which are in A.
Answer: {7, 8}
4.
C^c = \{1, 3, 5, 7, 9, 11\}The elements of U that are not even.
Answer: {1, 3, 5, 7, 9, 11}
5.
A \cap B = \{4, 5, 6\}Find the overlap first.
(A \cap B)^c = \{1, 2, 3, 7, 8, 9, 10, 11, 12\}Take everything else in U.
A^c = \{7, 8, 9, 10, 11, 12\},\ B^c = \{1, 2, 3, 9, 10, 11, 12\}Find each complement.
A^c \cup B^c = \{1, 2, 3, 7, 8, 9, 10, 11, 12\}Combine them; the result matches.
Answer: {1, 2, 3, 7, 8, 9, 10, 11, 12}, as De Morgan’s law predicts
6.
B \cup C = \{2, 4, 5, 6, 7, 8, 10, 12\}Find the union inside the parentheses first.
A \cap (B \cup C) = \{2, 4, 5, 6\}Keep the elements that are also in A.
Answer: {2, 4, 5, 6}
7.
\vert C \cup P\vert = 35 + 28 - 12 = 51
Union formula with C = coffee and P = pastry: 35 + 28 = 63 and 63 − 12 = 51.
60 - 51 = 9
Neither: subtract from the total.
28 - 12 = 16
Pastry only: remove the customers who bought both.
Answer: 9 bought neither, and 16 bought only a pastry
8.
A \cup B = (0, 6)
The intervals overlap, so the union runs from 0 to 6, with both ends open.
A \cap B = [2, 4]
Both conditions hold from 2 (included in B) to 4 (included in A).
A - B = (0, 2)
Remove [2, 6) from A; 2 is removed.
Answer: A ∪ B = (0, 6), A ∩ B = [2, 4], A − B = (0, 2)
9.
x \in A - B \iff x \in A \land x \notin B
Definition of difference.
\iff x \in A \land x \in B^c
Definition of complement.
\iff x \in A \cap B^c
Definition of intersection.
Answer: the memberships match for every x, so A − B = A ∩ Bc
10.
A = 1,\ B = 1:\ 0 \text{ and } 0Row 1: x is in both sets, so it is in neither difference and not in (A ∪ B) − (A ∩ B).
A = 1,\ B = 0:\ 1 \text{ and } 1Row 2: x is in A − B, and in A ∪ B but not in A ∩ B.
A = 0,\ B = 1:\ 1 \text{ and } 1Row 3: x is in B − A, and in A ∪ B but not in A ∩ B.
A = 0,\ B = 0:\ 0 \text{ and } 0Row 4: x is in none of the sets.
Answer: the two columns match in all 4 rows, so the sets are equal (both are the symmetric difference of A and B)
Set operations FAQ
What is the difference between union and intersection?
The union A ∪ B contains every element that is in at least one of the sets. The intersection A ∩ B contains only the elements that are in both, so A ∩ B is always a subset of A ∪ B.
What is the complement of a set?
The complement Ac is the set of elements of the universal set U that are not in A. If U = {1, 2, 3, 4} and A = {1, 2}, then Ac = {3, 4}.
What does A − B mean for sets?
A − B is the set of elements in A that are not in B. It is also written A ∖ B, and it equals A ∩ Bc.
What are De Morgan’s laws for sets?
They say (A ∪ B)c = Ac ∩ Bc and (A ∩ B)c = Ac ∪ Bc. Taking a complement switches union and intersection.
Summary
- Union (∪) means “or,” intersection (∩) means “and,” and complement means “not,” relative to a universal set U.
- A − B keeps the elements of A that are not in B, and A − B = A ∩ Bc.
- For finite sets, |A ∪ B| = |A| + |B| − |A ∩ B|.
- De Morgan’s laws: (A ∪ B)c = Ac ∩ Bc and (A ∩ B)c = Ac ∪ Bc.
- Prove set identities by chasing an element through the definitions or with a membership table.
Previous lesson: Sets and Subsets
Next lesson: Power Sets and Cartesian Products
Back to the Discrete Math Index