Set Difference

What is Set Difference?

You have tasks. Your friend already did some of them.

What’s left? That’s set difference — what’s in A but not in B.

Symbol: ∖\setminus or −-

A∖BA \setminus B

This reads: “A minus B”


Example

A={1,2,3,4}A = \{1, 2, 3, 4\} B={3,4,5}B = \{3, 4, 5\}

Find A∖BA \setminus B:

Go through A — is it also in B? If so, remove it.

  • 1: not in B → keep
  • 2: not in B → keep
  • 3: in B → remove
  • 4: in B → remove

A∖B={1,2}A \setminus B = \{1, 2\}

Keep what’s only in A.


More Examples

AABBA∖BA \setminus BWhy?
{a,b,c}\{a, b, c\}{b,c,d}\{b, c, d\}{a}\{a\}Only a isn’t in B
{1,2,3}\{1, 2, 3\}{4,5}\{4, 5\}{1,2,3}\{1, 2, 3\}Nothing to remove
{1,2}\{1, 2\}{1,2,3}\{1, 2, 3\}∅\emptysetEverything removed
{1,2,3}\{1, 2, 3\}∅\emptyset{1,2,3}\{1, 2, 3\}Empty set removes nothing

Order Matters

Unlike union and intersection, order matters here.

A∖B≠B∖AA \setminus B \neq B \setminus A

Example:

A={1,2,3},B={3,4,5}A = \{1, 2, 3\}, \quad B = \{3, 4, 5\}

  • A∖B={1,2}A \setminus B = \{1, 2\}
  • B∖A={4,5}B \setminus A = \{4, 5\}

Different results. Think of it like subtraction: 5−3≠3−55 - 3 \neq 3 - 5.


Properties

Difference with itself:

A∖A=∅A \setminus A = \emptyset

Remove everything, nothing left.

Difference with empty set:

A∖∅=AA \setminus \emptyset = A

Nothing to remove.

Empty set difference:

∅∖A=∅\emptyset \setminus A = \emptyset

Start with nothing, end with nothing.


The Formal Definition

A∖B={x∣x∈A and x∉B}A \setminus B = \{x \mid x \in A \text{ and } x \notin B\}

This reads: “The set of all xx such that xx is in A and xx is not in B.”

Set difference asks: is it only in A?