Mathwords logoMathwords

Set Difference — Definition, Formula & Examples

Set difference is the operation that produces a new set containing all elements that belong to one set but not to another. If you start with set AA and remove every element that also appears in set BB, the remaining elements form the set difference A∖BA \setminus B.

Given sets AA and BB, the set difference A∖BA \setminus B (also written A−BA - B) is defined as {x∣x∈A and x∉B}\{x \mid x \in A \text{ and } x \notin B\}.

Key Formula

A∖B={x∣x∈A and x∉B}A \setminus B = \{x \mid x \in A \text{ and } x \notin B\}
Where:
  • AA = The set you start with
  • BB = The set whose elements you remove from A
  • xx = An arbitrary element being tested for membership

Worked Example

Problem: Let A={1,2,3,4,5}A = \{1, 2, 3, 4, 5\} and B={3,5,7,9}B = \{3, 5, 7, 9\}. Find A∖BA \setminus B and B∖AB \setminus A.
Find A \ B: Keep elements of AA that are not in BB. The elements 3 and 5 appear in both sets, so remove them from AA.
A∖B={1,2,4}A \setminus B = \{1, 2, 4\}
Find B \ A: Now keep elements of BB that are not in AA. The elements 7 and 9 are in BB but not in AA.
B∖A={7,9}B \setminus A = \{7, 9\}
Observe order matters: A∖B≠B∖AA \setminus B \neq B \setminus A, which confirms that set difference is not commutative.
{1,2,4}≠{7,9}\{1, 2, 4\} \neq \{7, 9\}
Answer: A∖B={1,2,4}A \setminus B = \{1, 2, 4\} and B∖A={7,9}B \setminus A = \{7, 9\}.

Why It Matters

Set difference appears in database queries (SQL's EXCEPT operator), probability calculations where you subtract overlapping events, and programming when filtering collections. In discrete mathematics courses, it is essential for proving subset relationships and working with partitions.

Common Mistakes

Mistake: Treating set difference as commutative, assuming A∖B=B∖AA \setminus B = B \setminus A.
Correction: Set difference depends on which set comes first. A∖BA \setminus B removes BB's elements from AA, while B∖AB \setminus A removes AA's elements from BB. These generally produce different results.

Related Terms

  • Complement of a Set — Complement is set difference with the universal set
  • Intersection — Elements in both sets, related by A∖B=A∖(A∩B)A \setminus B = A \setminus (A \cap B)
  • Element of a Set — Membership determines which elements survive
  • Empty Set — Result when A is a subset of B
  • Cardinality — Counts how many elements remain after differencing