Discrete MathSets and Functions

Set Operations

Union, intersection, difference and complement, pictured with Venn diagrams, with De Morgan's laws for sets.

Not started Jump to practice

In probability you combined events with "or," "and" and "not." Events are sets of outcomes, so those were set operations all along. Here they get their general names and notation, building on sets and subsets.

Key idea

For sets inside a universe $U$: the union $A \cup B$ is everything in $A$ or $B$ (or both); the intersection $A \cap B$ is everything in both; the difference $A \setminus B$ is what is in $A$ but not $B$; the complement $A^{c} = U \setminus A$ is everything in $U$ not in $A$. De Morgan's laws hold for sets: $(A \cup B)^{c} = A^{c} \cap B^{c}$ and $(A \cap B)^{c} = A^{c} \cup B^{c}$.

Why it works

Each operation is a logical connective applied to membership. $x \in A \cup B$ means $x \in A \vee x \in B$; $x \in A \cap B$ means $x \in A \wedge x \in B$; $x \in A^{c}$ means $\neg(x \in A)$. So every logical equivalence becomes a set identity. De Morgan's laws for sets are the same laws you proved with truth tables, with "or" and "and" replaced by $\cup$ and $\cap$. (Probability books often write $A'$ for the complement; it means the same as $A^{c}$.)
Tap regions, or pick an event. Compare $(A \cap B)'$ with $A' \cap B'$: they are different regions. (This visual writes the complement as $A'$.)

Worked examples

Worked example: Computing with a universe

Let $U = \{1, 2, \ldots, 10\}$, $A = \{2, 4, 6, 8, 10\}$ (the even numbers) and $B = \{3, 6, 9\}$ (the multiples of $3$). Find $A \cup B$, $A \cap B$, $A \setminus B$, $A^{c}$ and $(A \cup B)^{c}$.
  1. $A \cup B = \{2, 3, 4, 6, 8, 9, 10\}$ (each element once).
  2. $A \cap B = \{6\}$, and $A \setminus B = \{2, 4, 8, 10\}$.
  3. $A^{c} = \{1, 3, 5, 7, 9\}$, the odd numbers.
  4. $(A \cup B)^{c} = \{1, 5, 7\}$: in neither set. Check De Morgan: $$A^{c} \cap B^{c} = \{1, 3, 5, 7, 9\} \cap \{1, 2, 4, 5, 7, 8, 10\} = \{1, 5, 7\}.$$

Answer: $\{2, 3, 4, 6, 8, 9, 10\}$, $\{6\}$, $\{2, 4, 8, 10\}$, $\{1, 3, 5, 7, 9\}$, $\{1, 5, 7\}$

Worked example: Sizes with De Morgan

In a universe of $40$ people, $|A| = 18$, $|B| = 15$ and $|A \cap B| = 6$. How many people are in $A^{c} \cup B^{c}$?
  1. De Morgan: $A^{c} \cup B^{c} = (A \cap B)^{c}$.
  2. So the count is everyone except the $6$ people in both: $40 - 6 = 34$.

Answer: $34$

Common mistake

Complementing each piece without switching the operation. $(A \cap B)^{c}$ is not $A^{c} \cap B^{c}$. To be outside "both $A$ and $B$," you only need to miss one of them, so $(A \cap B)^{c} = A^{c} \cup B^{c}$. Check with one element: in the example above, $3$ is in $(A \cap B)^{c}$ (it is not in both), but $3$ is not in $A^{c} \cap B^{c}$ (it is in $B$).

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 1 XP.

Loading practice…

Builds on

Leads to

Sources and further reading

  • Oscar Levin, Discrete Mathematics: An Open Introduction (3rd ed.), section "Sets" (operations on sets, Venn diagrams)
  • MIT OpenCourseWare 6.042J Mathematics for Computer Science (Lehman, Leighton and Meyer), chapter "Mathematical Data Types" (set operations)
@teddyrookbook GitHub