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 ABA \setminus B.

Given sets AA and BB, the set difference ABA \setminus B (also written ABA - B) is defined as {xxA and xB}\{x \mid x \in A \text{ and } x \notin B\}.

Key Formula

AB={xxA and xB}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 ABA \setminus B and BAB \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.
AB={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.
BA={7,9}B \setminus A = \{7, 9\}
Observe order matters: ABBAA \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: AB={1,2,4}A \setminus B = \{1, 2, 4\} and BA={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 AB=BAA \setminus B = B \setminus A.
Correction: Set difference depends on which set comes first. ABA \setminus B removes BB's elements from AA, while BAB \setminus A removes AA's elements from BB. These generally produce different results.