Search⌘ K
AI Features

Difference

Explore how to calculate the difference between sets and the symmetric difference, understanding their properties and non-commutative nature. Learn to apply these concepts through practical examples and Python code to analyze sets efficiently.

Set difference

If we have two sets, AA and BB, the difference, A−BA−B, is the set containing all the elements that are members of AA and not members of BB. Some authors also denote this difference as A∖BA \setminus B. We can represent it mathematically as follows:

Because the difference A−BA−B contains all the elements of AA except those that are common with BB, we can infer the following:

Examples

Let’s explore a few examples.

For the first example, let’s consider the following sets:

To find the members of AA that are not in MM, we look at their set difference as follows:

To find the members of MM that are not members of AA, we derive the difference as follows:

Now, let’s look at another example. In the English alphabet, each letter is a vowel or a consonant, but not both. We can represent this information using set-theoretic notation, as shown below:

The following set of consonants contains the letters from the alphabet that are not vowels:

Similarly, we can tell that V=E∖CV = E\setminus C.

Properties of set differences

The set difference operation is not commutative, as can be seen from the examples above. From its definition, we can note the following:

B−A={x∣x∈B∧x∉A}B-A=\{ x \mid x\in B \land x\not\in A\} ...

Set difference of A and B
Set difference of A and B