**Other math topics**

# Basics of set theory and Venn diagrams

*schedule*Aug 10, 2023

*toc*Table of Contents

*expand_more*

**mathematics behind data science**with 100+ top-tier guides

Start your free 7-days trial now!

This guide will cover the essential basics of set theory that will be helpful when studying various fields of mathematics such as statistics, calculus and linear algebra.

# What are sets?

A set can simply be thought of as a list of elements where the ordering does not matter. For instance, the following is a set of some numbers:

Typically, an uppercase letter is used to denote a set. Sets don't necessarily have to hold numbers - they can hold virtually any element such as letters, variables and outcomes:

Since the ordering of the elements within a set does not matter, two sets are considered equivalent if they contain the same elements. For instance, the following two sets are equivalent:

# Special sets

The following are special sets that serve as the backbone of mathematics:

the set $\mathbb{Z}=\{\cdots,-2,-1,0,1,2,\cdots\}$ is the set of all integers.

the set $\mathbb{N}=\{1,2,3,\cdots\}$ is the set of all natural numbers.

the set $\mathbb{Q}$ is the set of all rational numbers.

the set $\mathbb{R}$ is the set of all real numbers.

the set $\mathbb{C}$ is the set of all complex numbers.

To emphasize the fact that these are special sets, they are written in a font called blackboard bold - for instance, we write $\mathbb{R}$ instead of $R$.

## Empty sets

A set that contains no elements is called an empty set, represented by the symbol $\emptyset$.

## Universal sets

A universal set contains all the elements under consideration. For instance, suppose we roll a dice once - the universal set $S$ could represent all possible outcomes:

We will discuss more about universal sets in the section about Venn diagramslink later.

# Set notations

## Containment

To indicate that an element belongs to a set, we use the $\in$ symbol. For instance, consider the following set:

To state that $3$ is contained in this set $A$:

In contrast, if an element does not belong to a set, then we use the $\notin$ symbol. For instance, to indicate that $4$ is not contained in our set $A$:

The containment symbol is extremely common in mathematics because we typically characterize the nature of a variable using $\in$. For instance, to indicate that a variable $x$ is an integer, we would write $x\in\mathbb{Z}$. In linear algebra, we denote a vector $\boldsymbol{v}$ in two-dimensional space as $\boldsymbol{v}\in\mathbb{R}^2$.

## Subsets

We say that set $A$ is a subset of set $B$ if and only if all elements in set $A$ are also contained in set $B$. For instance, consider the following sets $A$ and $B$ that contain some numbers:

Here, $A$ is a subset of $B$ because all the numbers within $A$ also belong to $B$. We can mathematically express this as follows:

Note that $A\subset{B}$ is to be read as "$A$ is a subset of $B$". Equivalently, we can call $B$ the superset of $A$, that is, $B$ contains all elements of $A$.

As another example, consider the set of natural numbers $\mathbb{N}$ and integers $\mathbb{Z}$:

This means that the set of natural numbers is a subset of the set of integers.

## Intersection

The intersection of sets $A$ and $B$, which is denoted by $A\cap{B}$, is the set of all elements that are contained in both $A$ and $B$. For instance, consider the following set:

The numbers $1$ and $2$ both belong to sets $A$ and $B$. Therefore, the intersection of $A$ and $B$ is:

Notice how intersections are guaranteed to be subsets of both $A$ and $B$, that is:

### Disjoint sets

Two sets $A$ and $B$ are considered disjoint sets if there is no common element between them. For instance, consider the following sets:

Because there exists no element that belongs to both sets $A$ and $B$, we say that $A$ and $B$ are disjoint sets. Mathematically, disjoint sets are expressed as:

This means that the intersection of $A$ and $B$ is the empty set.

## Union

The union of sets $A$ and $B$, which is denoted by $A\cup{B}$, is the combined set of elements in $A$ or $B$. For instance, consider the following sets:

The union of sets $A$ and $B$ is:

Notice how numbers $1$ and $2$ are contained in both $A$ and $B$, but they only appear once in the union. In other words, duplicates are removed in the resulting union.

## Exclusion

The operation $A\setminus{B}$ returns a set of elements in $A$ that do not exist in $B$. For instance, consider the following sets:

To remove elements in $A$ and $B$ that belong to $C$, use the $\setminus$ operation like so:

## Cardinality

Cardinality of a set refers to the number of elements within a set. For instance, consider the following set:

The cardinality of $A$, denoted as $\vert{A}\vert$, is equal to 3.

Since empty sets do not contain any elements, their cardinality is $0$, that is, $\vert{\emptyset}\vert=0$.

# Set-builder notation

Up to now, we have only defined sets explicitly like $A=\{1,2,3\}$. However, we can also define sets by specifying using the set-builder notation. For instance, let's define a set that contains even integers:

This is read as "the set of all integers $x$ such that $x$ is even". The vertical line $|$, which means "such that", is sometimes written as $:$ instead. The set-builder notation is quite flexible - we can also equivalently write \eqref{eq:ufvKee1gfATYcRyK2an} as follows:

As another example, let's define another set that holds natural numbers less than $8$:

Finally, here's another one:

This set contains all the points on a parabola!

# Intervals

## Closed intervals

The endpoints are included in the interval. These intervals are expressed using square brackets:

Here's an example:

The ends points $3$ and $8$ are included in this interval.

## Open intervals

The endpoints are not included in the interval. These intervals are expressed using parentheses:

The endpoints $a$ and $b$ are excluded from the interval.

## Mixing open and closed intervals

We could also mix the notation of open and closed intervals:

## Denoting elements that belong to an interval

Suppose we wanted to mathematically state that a variable $x$ lies in the interval from $2$ to $6$ where both endpoints are included. We can use the containment symbol from earlier:

This notation is extremely common in calculus!

# Venn diagrams to visualize sets

Venn diagrams are a useful way to visualize the relationship between sets. Typically, we use circles to represent sets, but we can in fact use any shape we wish. Consider the following set:

We can represent this set using a Venn diagram like so:

We can think of the circle as the container of elements, just as the curly brackets $\{\cdots\}$ are in set notation.

## Intersection

Recall that the intersection of sets $A$ and $B$, which is denoted by $A\cap{B}$, is the set of all elements that are contained in both $A$ and $B$. For example, consider the following two sets:

The intersection $A\cap{B}$ can be visualized in a Venn diagram like so:

Here, the shaded area represents the intersection of the two sets.

## Union

Recall that the union of sets $A$ and $B$, which is denoted by $A\cup{B}$, is the set of all elements that are contained in either $A$ or $B$. For example, consider the same sets \eqref{eq:B4V9tinT2Y5LHf7E2Q7} as above. The union of $A$ and $B$ can be visualized in a Venn diagram like so:

Here, the shaded area in light blue represents the union of the two sets.

## Disjoint sets

Recall that sets $A$ and $B$ are called disjoint sets if they have no common elements. For example, consider the following two disjoint sets:

Disjoint sets are represented in a Venn diagram like so:

Notice how unlike the previous Venn diagrams, the circles do not overlap, which means that the sets do not share any common element.

## Universal and complementary sets

Recall that the universal setlink contains all elements under consideration. For instance, suppose we roll a dice - the universal set $S$ could hold all possible outcomes:

Now, suppose we have a set $A$ that holds only the even outcomes:

The Venn diagram in this case would look like the following:

The universal set $S$, as the name suggests, contains all the elements in the Venn diagram. Clearly, set $A$ is a subset of $S$.

A complementary set of $A$, which is denoted by $A'$ (or $A^c$ in some textbooks), holds all elements in the universal set $S$ that is not contained in $A$. This means that a complementary set contains everything else. In our dice example, the complementary set of $A$ will hold odd outcomes:

In our Venn diagram above, the complementary set $A'$ is the set outside of $A$. To make this clearer, the light-blue region below represents $A'$:

Note that by definition, $A'$ will again be a subset of the universal set $S$.