Tutorials › Real Analysis › Set Difference

Sets and Functions · Tutorial 50 of 1000

Set Difference

The difference \(A\setminus B\) contains the elements of \(A\) that do not belong to \(B\).

Beginner 11 min read

What You'll Learn

  • How set difference is defined by membership and nonmembership
  • How to evaluate differences of finite and condition-defined sets
  • Why the order of the two sets matters
  • How to characterize subsets of a set difference
  • How a set is separated into elements inside and outside another set

Keeping the Elements That Remain

The Intersection of Sets keeps elements shared by two sets: membership requires belonging to both. Set difference combines membership in one set with failure of membership in another. It answers a different question: which elements belong to \(A\), after excluding every element that also belongs to \(B\)?

Let \(A\) and \(B\) be sets. Their difference, written \(A\setminus B\), is the set of objects that belong to \(A\) and do not belong to \(B\): $$ A\setminus B=\{x:x\in A\text{ and }x\notin B\}. $$ Thus its membership rule is $$ x\in A\setminus B \quad\Longleftrightarrow\quad (x\in A)\land(x\notin B). $$ The left set \(A\) supplies the candidates to consider. The right set \(B\) specifies which candidates to remove.

Some texts use \(A-B\) for the same operation. Here we use \(A\setminus B\) to keep set difference visually distinct from numerical subtraction. The notation is directional: switching the sets changes both the candidates and the exclusion rule. In general, \(A\setminus B\) and \(B\setminus A\) are different sets.

Difference means “in the first set, not the second.” An object outside \(A\) cannot enter \(A\setminus B\), even if it is also outside \(B\). An object belongs to the difference only when both parts of the membership rule hold.

Evaluating Set Differences

For finite sets, begin with the elements of the first set and remove any that also appear in the second. Do not begin with the second set: its elements are not the candidates being filtered. The membership test is always the same—first verify \(x\in A\), then verify \(x\notin B\).

Worked Example: Removing Shared Elements

Let $$ A=\{2,4,6,8,10\},\qquad B=\{1,4,5,8,11\}. $$ The elements of \(A\) that also occur in \(B\) are \(4\) and \(8\), so those elements are removed from \(A\). The remaining elements are \(2,6,10\), and hence $$ A\setminus B=\{2,6,10\}. $$ For example, \(6\in A\) and \(6\notin B\), so \(6\in A\setminus B\). Although \(1\in B\), it does not belong to \(A\), so it cannot be in \(A\setminus B\). Conversely, \(4\in A\) but also \(4\in B\), so \(4\notin A\setminus B\).

Reversing the order gives \(B\setminus A=\{1,5,11\}\). This differs from \(A\setminus B\): the first difference retains elements of \(A\), whereas the reversed difference retains elements of \(B\).

When sets are given by conditions, the difference keeps the original domain restriction and adds a requirement that the second condition fail. This is the set-builder membership rule applied to both conditions for the same candidate. The earlier result on combining successive conditions gives the same interpretation of the simultaneous requirements.

Worked Example: Difference of Condition-Defined Sets

Let \(U=\{-4,-3,-2,-1,0,1,2,3,4\}\), and define $$ A=\{x\in U:x^2\leq9\},\qquad B=\{x\in U:x\geq0\}. $$ The elements of \(U\) with \(x^2\leq9\) are \(-3,-2,-1,0,1,2,3\), so $$ A=\{-3,-2,-1,0,1,2,3\}. $$ The elements of \(A\) that also satisfy \(x\geq0\) are \(0,1,2,3\). Removing these leaves $$ A\setminus B=\{-3,-2,-1\}. $$ Equivalently, a candidate \(x\) must lie in \(U\), satisfy \(x^2\leq9\), and fail \(x\geq0\). The latter failure means \(x<0\). Thus the candidates are exactly \(-3,-2,-1\). The domain matters: this description does not add real numbers outside \(U\).

Set difference is not commutative. For instance, if \(A=\{a,b\}\) and \(B=\{b,c\}\), then \(A\setminus B=\{a\}\), while \(B\setminus A=\{c\}\). The two results answer different questions. They happen to be equal for some choices, such as \(A=B\), when both differences are empty; that special case does not make the operation commutative in general.

Subset Criteria for a Difference

A subset \(C\) lies inside \(A\setminus B\) precisely when two requirements hold: every element of \(C\) is in \(A\), and no element of \(C\) is in \(B\). The second requirement can be expressed by saying that \(C\) and \(B\) have no elements in common, or \(C\cap B=\varnothing\).

Theorem (Subset of a Difference). Let \(A\), \(B\), and \(C\) be sets. Then $$ C\subseteq A\setminus B \quad\Longleftrightarrow\quad (C\subseteq A\text{ and }C\cap B=\varnothing). $$

Proof. First suppose \(C\subseteq A\setminus B\). Let \(x\in C\) be arbitrary. By the assumed inclusion, \(x\in A\setminus B\). The membership characterization of difference gives \(x\in A\) and \(x\notin B\). Since this holds for every \(x\in C\), the definition of subset gives \(C\subseteq A\).

We also show \(C\cap B=\varnothing\). If an object \(x\) belonged to \(C\cap B\), the membership characterization of intersection would give \(x\in C\) and \(x\in B\). Since \(C\subseteq A\setminus B\), the first membership would imply \(x\in A\setminus B\), and therefore \(x\notin B\). This contradicts \(x\in B\). Thus no object belongs to \(C\cap B\), and the Characterization of the Empty Set gives \(C\cap B=\varnothing\).

Conversely, suppose \(C\subseteq A\) and \(C\cap B=\varnothing\). Let \(x\in C\) be arbitrary. The inclusion \(C\subseteq A\) gives \(x\in A\). We claim \(x\notin B\). If \(x\in B\), then \(x\in C\) and \(x\in B\), so the membership characterization of intersection gives \(x\in C\cap B\), contradicting \(C\cap B=\varnothing\). Hence \(x\notin B\). We have shown \(x\in A\) and \(x\notin B\), so \(x\in A\setminus B\). Because this holds for every \(x\in C\), it follows that \(C\subseteq A\setminus B\). This proves both directions.

Taking \(C=A\setminus B\) in the theorem shows that the difference is contained in \(A\) and has no elements in common with \(B\). The first claim also follows directly from the membership rule; the second says \((A\setminus B)\cap B=\varnothing\). These are useful checks on a proposed difference: it must never contain an element absent from \(A\), and it must never retain an element of \(B\).

Worked Example: Testing a Subset Claim

Let $$ A=\{1,2,3,4,5,6\},\qquad B=\{2,4,6,8\},\qquad C=\{1,3,5\}. $$ Every element of \(C\) belongs to \(A\), so \(C\subseteq A\). Also, no element of \(C\) belongs to \(B\), so \(C\cap B=\varnothing\). By the Subset of a Difference theorem, $$ C\subseteq A\setminus B. $$ Indeed, removing \(2,4,6\) from \(A\) gives \(A\setminus B=\{1,3,5\}\), so in this case \(C=A\setminus B\).

The hypotheses cannot be replaced by just one of these requirements. For example, \(D=\{2\}\) is contained in \(A\), but \(D\cap B=\{2\}\ne\varnothing\); therefore \(D\not\subseteq A\setminus B\). And \(E=\{9\}\) has no elements in common with \(B\), but \(E\not\subseteq A\), so \(E\) cannot be contained in \(A\setminus B\). Both conditions are necessary.

1
Start with an arbitrary element: to prove a subset inclusion, take \(x\in C\).
2
Establish the positive membership: use \(C\subseteq A\) to obtain \(x\in A\).
3
Establish the exclusion: use \(C\cap B=\varnothing\) to conclude \(x\notin B\).
4
Apply the definition: \(x\in A\) and \(x\notin B\) imply \(x\in A\setminus B\), proving \(C\subseteq A\setminus B\).

Difference and Intersection Separate a Set

Each element of \(A\) has exactly one of two possibilities: it belongs to \(B\), or it does not. Elements in the first group are in \(A\cap B\); elements in the second are in \(A\setminus B\). These groups do not overlap, and together they make up all of \(A\).

Theorem (Decomposition by a Set). For any sets \(A\) and \(B\), $$ A=(A\setminus B)\cup(A\cap B), \qquad (A\setminus B)\cap(A\cap B)=\varnothing. $$

Proof. We first prove the equality. Let \(x\) be any object. By the membership characterization of union, $$ x\in(A\setminus B)\cup(A\cap B) \quad\Longleftrightarrow\quad \bigl(x\in A\setminus B\text{ or }x\in A\cap B\bigr). $$ Using the membership characterizations of difference and intersection, this is equivalent to $$ \bigl((x\in A\text{ and }x\notin B) \text{ or }(x\in A\text{ and }x\in B)\bigr). $$ In either alternative, \(x\in A\). Conversely, if \(x\in A\), then either \(x\in B\) or \(x\notin B\). If \(x\notin B\), then \(x\in A\setminus B\). If \(x\in B\), then \(x\in A\cap B\). In either case \(x\in(A\setminus B)\cup(A\cap B)\). We have proved that \(x\) belongs to this union if and only if \(x\in A\), for every object \(x\). Equality by double inclusion therefore gives $$ A=(A\setminus B)\cup(A\cap B). $$

It remains to prove that the two sets in the union are disjoint. Suppose \(x\in(A\setminus B)\cap(A\cap B)\). Membership in the first set implies \(x\notin B\). Membership in the second implies \(x\in B\). These statements cannot both hold, so no object belongs to the displayed intersection. By the Characterization of the Empty Set, $$ (A\setminus B)\cap(A\cap B)=\varnothing. $$ Both claims follow.

Worked Example: Splitting a Set into Two Groups

Let $$ A=\{a,b,c,d,e\},\qquad B=\{b,d,f\}. $$ The elements of \(A\) that also belong to \(B\) form $$ A\cap B=\{b,d\}. $$ The elements of \(A\) that do not belong to \(B\) form $$ A\setminus B=\{a,c,e\}. $$ Their union is \(\{a,b,c,d,e\}=A\), and their intersection is empty: none of \(a,c,e\) is \(b\) or \(d\). Thus the elements of \(A\) are accounted for exactly once, in one of the two groups. The element \(f\) is not in either group because it is not in \(A\).

The word “partition” is often used for a division into nonoverlapping groups that together cover the set. The theorem gives such a division of \(A\) according to membership in \(B\). It does not claim that \(B\) itself is split into these two sets: both pieces are formed from elements of \(A\), and their union is \(A\).

Useful Identities and Common Pitfalls

A few special cases follow immediately from the definition. Removing the empty set removes nothing, while removing a set from itself leaves nothing: $$ A\setminus\varnothing=A,\qquad A\setminus A=\varnothing,\qquad \varnothing\setminus A=\varnothing. $$ For the first identity, every \(x\in A\) also satisfies \(x\notin\varnothing\), since the empty set has no elements. The second has no possible member: it would require both \(x\in A\) and \(x\notin A\). The third has no candidates because no object belongs to \(\varnothing\). Each identity follows by applying the Characterization of the Empty Set where appropriate.

The order of a difference must not be reversed casually. For the sets \(A=\{1,2,3\}\) and \(B=\{3,4\}\), we get \(A\setminus B=\{1,2\}\), whereas \(B\setminus A=\{4\}\). Also, set difference is not ordinary subtraction of numbers or of set sizes. For instance, the number of elements in \(A\setminus B\) depends on which elements overlap; it is not determined by merely subtracting the number of elements of \(B\) from the number of elements of \(A\).

Keep the difference rule distinct from the intersection rule. Intersection asks for membership in both sets. Difference asks for membership in the first set and nonmembership in the second. In particular, saying \(x\notin A\setminus B\) does not by itself say whether \(x\in A\) or \(x\in B\): it only says that at least one part of the membership requirement fails. The negation rules for quantified statements, established earlier in the course, explain how to unpack such a negation when needed. De Morgan’s Laws, to come, will treat the corresponding rules for set operations.

Expression Membership test Interpretation
\(x\in A\setminus B\) \(x\in A\) and \(x\notin B\) Keep an element of \(A\) that is not in \(B\).
\(A\setminus B\) Start with \(A\); exclude elements in \(B\) The order determines the candidate set.
\(A\setminus\varnothing\) \(x\in A\) and \(x\notin\varnothing\) Equals \(A\).
\(A\setminus A\) \(x\in A\) and \(x\notin A\) Equals \(\varnothing\).
\(C\subseteq A\setminus B\) \(C\subseteq A\) and \(C\cap B=\varnothing\) The subset stays in \(A\) and avoids \(B\).
Check both membership conditions. To establish \(x\in A\setminus B\), show \(x\in A\) and \(x\notin B\). To establish \(C\subseteq A\setminus B\), show \(C\subseteq A\) and \(C\cap B=\varnothing\).

Use the membership rule for difference in each question. Keep the first set as the source of candidates, and exclude only those candidates that also belong to the second set.

Check Your Understanding

  1. Let \(A=\{0,2,4,6,8\}\) and \(B=\{1,2,5,6\}\). Find \(A\setminus B\) and \(B\setminus A\). Are they equal?
  2. Let \(U=\{-3,-2,-1,0,1,2,3\}\), \(A=\{x\in U:x^2<5\}\), and \(B=\{x\in U:x\leq0\}\). Find \(A\setminus B\).
  3. If \(x\in B\) but \(x\notin A\), can \(x\) belong to \(A\setminus B\)? Explain using the membership definition.
  4. Suppose \(C\subseteq A\) and \(C\cap B=\varnothing\). Which theorem gives \(C\subseteq A\setminus B\)?
  5. For arbitrary sets \(A\) and \(B\), what are \(A\setminus\varnothing\), \(A\setminus A\), and \(\varnothing\setminus A\)?
  6. How does \(A\) decompose into a part that belongs to \(B\) and a part that does not? Are these two parts disjoint?