Set Difference

The set difference of two sets A and B, also called the relative complement of B in A, is the set of all elements that belong to A but not to B. $$ A-B = \{ x \mid x \in A \text{ and } x \notin B \} $$ In other words, to find A-B, start with all the elements of A and remove any elements that also belong to B. This operation is read as "A minus B".

The following Venn diagram shows the set difference graphically.
set difference between two sets

The set difference is usually written as

$$ A \setminus B $$

and is read as "A minus B" or, more formally, "the relative complement of B in A".

A Practical Example

Let's look at two finite sets:

$$ A = \{ 0, 2, 4, 8, 10 \} $$

$$ B = \{ 2, 4, 6, 12 \} $$

To compute A-B, keep only the elements that belong to A and remove any elements that also appear in B.

$$ A-B = A \setminus B = \{ 0, 8, 10 \} $$

The elements 2 and 4 belong to both sets, so they are excluded. The remaining elements, {0, 8, 10}, form the set difference.

the set difference A minus B

Example 2

Consider the following sets:

$$ A = \{ 1, 2, 3, 4, 5, 6, 7 \} $$

$$ B = \{ 2, 4, 6 \} $$

In this case, B is a proper subset of A because every element of B is also an element of A.

The set difference A-B is

$$ A-B = A \setminus B = \{ 1, 3, 5, 7 \} $$

After removing the elements 2, 4, and 6 from A, the elements that remain are 1, 3, 5, and 7.

In the Euler-Venn diagram below, the shaded region represents the set difference.

Euler-Venn diagram showing a set difference

Properties of Set Difference

Set difference has several useful properties that are worth remembering.

  • Set difference is not commutative.

    In general,

    $$ A-B \ne B-A $$

    Example. Consider the sets $$ A = \{ 0, 2, 4, 8, 10 \} $$ $$ B = \{ 2, 4, 6, 12 \} $$ Then $$ A-B = \{ 0, 8, 10 \} $$ while $$ B-A = \{ 6, 12 \}. $$ Since the two results are different, set difference is not commutative.

  • If A and B are disjoint sets, then A-B = A.

    Two sets are disjoint when they have no elements in common.

    $$ A \cap B = \varnothing \Longleftrightarrow A-B = A $$

    Example. Consider the sets $$ A = \{ 2, 4, 6, 8 \} $$ $$ B = \{ 1, 3, 5, 7, 9 \} $$ Since the sets do not share any elements, $$ A-B = A = \{ 2, 4, 6, 8 \}. $$ The following diagram illustrates this case.
    set difference of two disjoint sets
    Likewise, $$ B-A = B = \{ 1, 3, 5, 7, 9 \}. $$

  • If A and B are equal sets, their difference is the empty set.

    When two sets contain exactly the same elements, removing the elements of B from A leaves nothing behind.

    $$ A = B \Longleftrightarrow A-B = \varnothing $$

The set difference is one of the fundamental operations in set theory. It is widely used in mathematics, logic, probability theory, computer science, and data analysis whenever it is necessary to identify elements that belong to one collection but not to another.

 
 

Please feel free to point out any errors or typos, or share suggestions to improve these notes. English isn't my first language, so if you notice any mistakes, let me know, and I'll be sure to fix them.

FacebookTwitterLinkedinLinkedin
knowledge base

Set