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 -

ABA \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 ABA \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

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

Keep what’s only in A.


More Examples

AABBABA \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.

ABBAA \setminus B \neq B \setminus A

Example:

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

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

Different results. Think of it like subtraction: 53355 - 3 \neq 3 - 5.


Properties

Difference with itself:

AA=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

AB={xxA and xB}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?