Understanding Set Operations

Conceptual Overview of Set Operations

Conceptual overview of set operations, union, intersection, difference and symmetric difference, using simple examples and Venn diagrams.
Author

Bilal Mustafa

Published

July 18, 2025

Introduction:

Set theory serves as a foundation for many fields of mathematics and data analysis. Understanding sets and their operations is critical for a wide range of scientific and computational applications. In this post, we will define the essential set operations in abstract terms: union, intersection, difference, symmetric difference, subset, and complement. We’ll describe each operation using standard notation and basic examples (mathematical notation for precision). Venn diagrams are a valuable visual tool throughout, demonstrating how various operations combine or relate sets. By the end, you should have a good idea of what each operation represents. (In Part II, we will look at how these abstract procedures may be applied to real biological data; a hint is provided at the conclusion!)


Union

Figure of unions representation

Figure: Venn diagram illustrating the union of two sets A and B. The shaded region represents A∪B, which includes any element that lies in either set (or both sets).

The union of two sets A and B (denoted AB) is the set containing all elements that are in either A or B (or both). In set‐builder notation:

AB={xxA or xB}.

In this case, the term “or” is inclusive, which means that x can belong to either A or B, or both. For example, if

A={1,2,3}andB={3,4},

then

AB={1,2,3,4},

(the number 3 exists in both, but in the union it is listed once as every distinct element is included). The union operation is analogous to logical OR in that an element is in AB if it is in at least one of the sets. Union is also commutative and associative, thus

AB=BA,

and

A(BC)=(AB)C.

In practice, the union joins two sets into a single larger set that has all of their unique components.


Intersection

Figure of intersections representation

Figure: Venn diagram for the intersection of A and B. The shaded region (where the circles overlap) represents A∩B, containing elements that both sets have in common.

The intersection of sets A and B (denoted AB) is the set of all elements that belong to both A and B. Using set‐builder notation:

AB={xxA and xB}.

Only elements from both sets appear in the intersection. For example, if

A={1,2,3}andB={3,4,5},

then

AB={3},

since 3 is the single element contained in both sets. If the two sets have no elements in common, the intersection is the empty set, . (We then term the sets disjoint.) Intersection, like union, is commutative and associative. For example,

AB=BA.

Importantly, any intersection AB will always be a subset of each set A and B, capturing exactly what the two sets share.


Difference (Relative Complement)

Figure of Differences representation

Figure: Venn diagram for the difference A−B (also denoted A∖B). The shaded area is the part of set A that lies outside set B, representing elements in A that are not in B

The difference between two sets A and B, denoted as AB (or AB), consists of all elements in A but not in B. Formally:

AB={xxA and xB}.

In other words, we “subtract” set B from A, removing all elements that A and B share. For example, if

A={a,b,c,d}andB={b,d,f},

then

AB={a,c},

since we eliminate b and d because they also belong to B.

It is important to note that set difference is not commutative. That is, AB does not generally equal BA. In our example,

BA={f},

which is not the same as AB. The difference operation is also known as the relative complement of B in A, since it yields all elements of A that are not in B.

  • If B and A have no overlap, then AB=A (nothing is removed).
  • If B contains all elements of A, then AB=.

Symmetric Difference

Figure of Differences representation

Figure: Venn diagram for the symmetric difference of A and B. The shaded regions represent A△B, which includes elements in either set but not in the overlap. Equivalently, it is everything in A or B except the intersection.

The symmetric difference between sets A and B (denoted AB, or occasionally AB) is the set of elements that are in exactly one of the two sets, but not in both. You can characterize it in two equivalent ways:

  • Using difference:
    AB=(AB)(BA).

  • Using union and intersection:
    AB=(AB)(AB).

For example, if
A={1,2,3,4}andB={3,4,5},
then
- AB={1,2},
- BA={5},

so
AB={1,2,5}.

Symmetric difference corresponds to the logical “exclusive or” (XOR):
xAB(xA)(xB).
It is commutative and associative, for instance

AB=BA,A(BC)=(AB)C.

In summary, AB yields precisely those elements that belong to one set or the other, but not to their intersection.


Subset and Superset

A subset describes the relationship between two sets rather than creating a new one. Set A is a subset of set B (written AB) if every element of A is also in B. In logical form:

ABx,(xAxB).

For example, if

A={dog,cat}andB={dog,cat,elephant},

then AB because all members of A (dog and cat) are contained in B. A Venn diagram typically shows this by drawing the circle for A entirely inside the circle for B. Every set is a subset of itself, so AA always holds. If AB but AB, we call A a proper subset of B, written AB, indicating that B has at least one element not in A. Dually, B is a superset of A (written BA) whenever AB.

It’s worth noting how subset relations affect union and intersection. If AB, then

AB=B,AB=A,

since adding a smaller set to a larger one brings nothing new, and their overlap is exactly the smaller set. These identities follow directly from the definitions of union and intersection.


Complement

In set theory, a complement is defined as all elements that are not part of a set, relative to a universal set U, which represents the complete collection under consideration. The complement of A (denoted Ac, also written A or A) is the set of all elements in U that are not in A. In formula terms:

Ac=UA={xxU and xA}.

Simply put, Ac is the “opposite” of A within the universe U, containing everything A does not. For example, if

U={1,2,3,4,5,6,7}andA={3,4,5},

then

Ac={1,2,6,7},

which are exactly the elements of U not in A.

Complements share several fundamental properties:

  • Partition of the universe:
    AAc=U,AAc=.

  • Double complement:
    (Ac)c=A.

  • De Morgan’s laws:
    (AB)c=AcBc,(AB)c=AcBc.

These identities follow directly from the logic of “not (A or B)” versus “not A and not B,” and vice versa. Complements thus invert membership and, combined with union and intersection, complete the basic algebra of sets.


Closing teaser

While we have explored these set operations in abstract mathematical terms, they are far from being purely theoretical. When combined with real-world data, they become extremely effective tools. In biology, for example, set operations may be used to compare groups of genes or proteins: the intersection of two gene lists may reveal common genes associated with two conditions, a difference may isolate unique genes expressed only in one experiment, and a union may combine all genes discovered in multiple studies. Subsets can form hierarchies such as species within a genus, whereas complements can represent “everything not in a given list” (for example, all genes except those in a specific pathway). These biological applications (and others) will be discussed in Part II, where we will see set operations used to make sense of complex biological data. Stay tuned!


References

Number Analytics. Set theory definitions and properties. Retrieved July 16, 2025, from https://numberanalytics.com

MathMonks. Comprehensive guide to set operations. Retrieved July 16, 2025, from https://mathmonks.com


Back to top
1,364 Total Pageviews