Skip to content

Set difference

Textbook

The difference $A\setminus B$ contains the elements of $A$ that do not belong to $B$:

$$A\setminus B=\{x\mid x\in A\land x\notin B\}.$$

Both conditions are required. An element absent from $A$ cannot enter the result, even if it is also absent from $B$. Therefore $A\setminus B\subseteq A$.

Argument order matters: generally $A\setminus B\ne B\setminus A$. The definition gives the boundary cases $A\setminus\varnothing=A$, $\varnothing\setminus B=\varnothing$, and $A\setminus A=\varnothing$.

The result shares no elements with $B$. Moreover, $A\setminus B=\varnothing$ exactly when $A\subseteq B$: an empty difference means that no element of $A$ lies outside $B$.

Membership in $A$ is checked before the exclusion condition involving $B$. If the first answer is negative, no later check can admit that object. When $A$ and $B$ have no common elements, their difference equals $A$: nothing can be removed. Adding to $B$ an object absent from $A$ also leaves the result unchanged. Here $B$ supplies a prohibition, never a source of new candidates.

Related concepts: Set membership.

In plain language

Difference resembles a shopping list after items already at home have been crossed out. The home inventory removes entries without adding new ones. Reversing the order gives a different list: things at home that were absent from the shopping list. An ordinary set records presence rather than apple counts; the refrigerator declines responsibility for that accounting.

Example

For the illustrative sets $A=\{1,2,3\}$ and $B=\{3,4\}$, the difference is computed in both directions.

Set difference

Initial set A

Only elements of A can enter A minus B.

Step 1 of 3: Initial set A

Read all steps
  1. Initial set A

    Only elements of A can enter A minus B.

    A
    1current2current3current
    B
    34
  2. Exclusion of elements in B

    Three is removed. Four is not added: it was never in A.

    A
    1included2included3excluded
    A minus B
    1included2included
  3. Reversed direction

    Now B is the starting set. The shared 3 is removed, leaving 4.

    B
    3excluded4included
    B minus A
    4included

First, three is removed from $A$ because it occurs in $B$. Four is not a candidate for that operation because it was never in $A$. After reversing direction, four survives, while one and two cannot arrive from the second list. Two conditions govern every result element: was it in the left argument, and is it absent from the right? Reversing the arguments changes both questions together.

The original text of this free article is published under CC BY-NC-ND 4.0.

Previous / next

Previous
Set intersection
Next
Set complement
  • Set membership

    What membership states, why order and repetition do not change a set, and how an empty set differs from a set containing it.

    Read article
    Set Theory
  • Set equality

    How to prove set equality element by element or through two inclusions, and why equal size is not enough.

    Read article
    Set Theory
  • Set inclusion

    How to check that every element of one set is in another, and why inclusion differs from membership.

    Read article
    Set Theory