Set Difference is not Associative

Theorem
For any three sets $$R, S, T$$:
 * $$R \setminus \left({S \setminus T}\right)$$ does not, in general, equal $$\left({R \setminus S}\right) \setminus T$$

where $$R \setminus S$$ etc. denotes set difference.

From Set Difference with Union, we have:
 * $$\left({R \setminus S}\right) \setminus T = R \setminus \left({S \cup T}\right)$$

From Set Difference with Set Difference is Union of Set Difference with Intersection, we have:
 * $$R \setminus \left({S \setminus T}\right) = \left({R \setminus S}\right) \cup \left({R \cap T}\right)$$;

These appear to be different.

In fact:


 * $$\left({R \setminus S}\right) \setminus T \subseteq R \setminus \left({S \setminus T}\right)$$

Thus it is clear that set difference is not associative.

The expression:
 * $$\left({R \setminus S}\right) \setminus T = R \setminus \left({S \setminus T}\right)$$

holds exactly when $$R \cap T = \varnothing$$.

Proof
We assume a universe $$\mathbb U$$ such that $$R, S, T \subseteq \mathbb U$$.

We have the identity Set Difference as Intersection with Complement:
 * $$R \setminus S = R \cap \overline S$$

where $$\overline S$$ is the set complement of $$S$$: $$\overline S = \mathbb U \setminus S$$.

Thus we can represent the two expressions as follows.

The first one is easy enough:

$$ $$

The second one is more involved:

$$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $$

As can be seen, this full expansion of the second expression can be expressed:
 * $$R \setminus \left({S \setminus T}\right) = \left({\left({R \setminus S}\right) \setminus T}\right) \cup \left({R \cap T}\right)$$

Hence the first result, from Subset of Union.

It directly follows from Intersection with Null that:
 * $$R \setminus \left({S \setminus T}\right) = \left({R \setminus S}\right) \setminus T \iff R \cap T = \varnothing$$

Also see

 * Intersection is Associative
 * Union is Associative
 * Symmetric Difference is Associative