Sets and Set Theory
Contents
2.1. Sets and Set Theory#
Most of mathematics is built up from the very basic concept of a set. It is so basic in fact, that the concept of a set is rarely defined formally rather something thought of intuitively as just “a collection of objects”. Defining sets formally is outside the scope of this course and is described by “axiomatic set theory” and, in particular, Zermelo-Fraenkel Set Theory. Rather, we will follow naive set theory, and use the previously mentioned intuitive definition.
From grade school mathematics we have already been exposed to certain sets, although maybe not defined rigorously.
The set of natural numbers
are the “whole numbers”: .The set of integers
are the whole numbers and their negatives: .The set of real numbers
are “all” the numbers, including fractions, decimals, and irrational numbers like .The set of complex numbers
are all numbers of the form , where and are real numbers.
Important
Note that including
In this text, we will include 0 as a natural number.
From these different sets of numbers, we already have an intuitive definition of sets of numbers. But sets are more general than that. Sets are unordered collections (of unique) things. These “things” are called elements or members. To see how and why ordering (and unicity) are or are not important, we have to discuss things like equality of sets and the construction of sets. They will all come in the next section.
2.1.1. Set Construction#
Constructing a set is the first and foremost part of set theory. Naturally, we cannot use sets, or perform operations on sets, without having a set in the first place. We will see 3 ways to construct a set:
Roster method
Set builder notation
Interval notation
Roster Method#
The roster method for set construction is the most simple. We simply write down all of the members of a set between curly braces.
The set
When there is an obvious pattern to the elements of a set, one can abbreviate
the roster method using an ellipse (i.e.
The set of all positive multiples of
Notice that the set does not need to be finite to use the roster method. Generally, sets can have a finite or infinite number of members, as we will see.
Moreover, sets do not necessarily need to contain numbers or only numbers. Sets are collections of any “thing” or “object”. Those objects could be any combination of letters, strings, colors, shapes, matrices, etc. Sets can even contain other sets! (see Set Properties). As an example, the following as also valid sets:
Using the roster method, we can describe some well-known mathematical sets as follows.
Roster method for sets of numbers
Set Builder#
The second, and more general way of describing a set is using set builder notation. You have likely seen this notation used implicitly in previous math courses.
Set builder notation
Set builder notation specifies elements that should be included in a set based on a variable (respectively, some expression) and a condition on that variable (respectively, expression).
The variable and condition are separated by a vertical bar
In this notation the vertical bar
This notation may have included a new symbol for you:
The set of rational numbers or complex numbers are easily defined using set builder notation, but are quite complicated to define using the roster method.
Set of rational numbers and complex numbers
Note
In set builder notation, conditions which should simultaneously be satisfied are often simply listed after the
Set builder and conjunctions
The following sets are equivalent.
Set builder notation has one strong benefit over the roster method: you do not need to know the precise members of a set in order to construct the set. For example, maybe you want the set of roots of a polynomial. We know from grade school mathematics that a quadratic equation can be solved using
But what about cubics? Quadratics? Quintics? The following example shows that we can construct a set without necessarily knowing its elements.
Set of roots of a polynomial
Let
Similarly, consider some examples from predicate logic. The condition or property that we use within the set builder notation can be a predicate. We do not need to know ahead of time the set of objects for which that predicate holds.
Predicates and set builder notation
Let
Let
Notice from this previous example that specifying the domain of discourse is very important and can drastically change the objects in a set.
Natural language description#
Just as we can translate between Natural language and predicates, we can similarly use natural language in place of the explicit set builder notation. This is often called a semantic description of the set, where a sentence is used to describe the properties of objects contained in a set.
Semantic descriptions
The following are valid semantic descriptions of sets.
Let
be the set of three primary colors.Let
be the set of five smallest positive integers.Let
be the set of positive rational numbers with 1 as a numerator.
When using semantic descriptions, it is important that the sentence be as clear as possible and unambiguous. We have already seen in Section 1 how natural language can cause troubles and ambiguity when taken formally.
Interval Notation#
For sets of real numbers, a particularly useful notation is interval notation. We are probably familiar with this notation from calculus.
For two real numbers
The choice of including the end point or an interval or not determines if the interval is closed or open.
Definition (closed interval)
A closed interval is the set of all numbers between two end points, including those endpoints. It is denoted by square brackets.
Definition (open interval)
An open interval is the set of all numbers between two end points, excluding those endpoints. It is denoted by round brackets.
A half-open or half-closed interval is where one end point is included and one end point is excluded. To be more precise, we can say left-open or right-closed to mean only the right end point is included, e.g.
When we want to describe intervals which are unbounded on one side (i.e. go until positive or negative infinity) we use a round bracket and the infinity symbol.
Integer intervals
In computer science, it is increasingly common to define intervals over integers. Such notations have grown as programming languages become higher-level and compiler and interpreters get more sophisticated.
In Python, the function call range(a,b)
defines the integer interval (i.e. the set) starting at and including a
, and up to but excluding b
: {a, a+1, a+2, ..., b-2, b-1}
.
We can also use the function call range(a,b,step)
to define the integer interval {a, a + step, a + 2*step, b-step}
.
In MATLAB, we can use the colon operator. i:j
defines the closed integer interval from i
to j
: i, i+1, i+2, ..., j
. One can also increment by a step size other than one using i:step:j
to
obtain the interval i, i + step, i + 2*step, ..., i + m*step
, where m
is (j-i)/step
rounded down.
2.1.2. Set Properties#
Now that we know how to construct sets, it is time to discuss particular sets and their properties.
Membership and Equality#
Membership is the basic property of sets from which all other operations and properties can be defined. A set either contains an object or does not contain an object. Sets define a clear and unambiguous description of its members.
We have already see the notation
Again, membership is a strict binary. An object is either in a set or is not in a set. Because of that, we have the following interesting results.
Definition (equality of sets)
Two sets
Stated in predicate logic, two sets are equal if
Because the only basic property of a set is membership, a set does not care about the order in which elements are listed or the number of times each element appears in the set construction. For example, the following sets are equal.
To avoid this awkward and “non-canonical” description of sets, it is often said that sets should only contain unique, distinct, or distinguishable objects.
In particular, when using the roster method, one should only write each unique element once. Therefore
Exercise
In Python, sets are a particular kind of data structure. They follow much of the semantics of the mathematical set. Sets are generic collections of objects. However, for many reasons associated with simplicity and efficiency of programming, Python requires a canonical form for their sets. In particular, Python requires that every element in a set is unique. This avoid the previously described ambiguity of multiple copies of the same element being in a set.
set1 = {'a', 'b', 'c'}
set2 = {'b', 'c', 'c', 'a', 'c', 'b'}
print("set1:", set1)
print("set2:", set2)
print(set1 == set2);
set1: {'a', 'b', 'c'}
set2: {'a', 'b', 'c'}
True
Special Sets: Empty and Universal#
Some important sets have special names. In particular, the empty set and the universal set. Thinking again about set membership, their names suggest that these sets contain nothing or everything.
Definition (empty set)
The empty set is the unique set containing no elements. It is denoted by
The empty set can also be denoted by
In contrast with the empty set, the universal set is the set which contains every element. How can one thing contain everything? It may seem paradoxical. Does a thing containing everything contain itself? In formal set theory, such a universal set does not exist.
For practical purposes, we can instead consider a particular universe of things. That is, a universe or domain of discourse.
Indeed, we have already seen the set
Such a universe can be implicit, for example the set containing days of the week
In other cases, we have seen the universe being described explicitly in set building notation. For example, the following has the set of positive integers as its universe.
Sets and empty sets
Are the following equalities true or false?
Sets and empty sets
True.
True. No integer satisfies the equation
.False. The left-hand side is the empty set. The right-hand side is the set containing the empty set.
True. No real number satisfies the equation
.False. The left-hand side is the empty set. The right-hand side is the set containing the empty set.
Subsets#
Subsets describe sets which are “contained within” other sets. Intuitively, subsets are something between set membership and set equality.
Definition (subset)
A set
Notice that this definition is a one-way relation. Unlike equality, a subset only requires that every member of the subset is also a member of the superset.
Subsets
The following are valid subsets.
Tip
By the definition of subset, we have
Notice that the definition of subset does not restrict the subset to being strictly “smaller” than its superset.
Indeed, the symbol
Indeed, we can define set equality using subsets. Two sets
Equality as subsets
Let
We have:
We also have
Therefore,
Notice in this previous example that one set may be the subset of two other sets without
those two supersets being equal. Using the notation of the previous example, we have
This describes the case of proper subsets where a subset is strictly smaller than its superset. We have the following terms and notations:
Proper subset
Superset
Proper superset
or or
Important
The use of subset symbols is not consistent throughout texts. Some authors use
To align with the standard notation of
Size of a Set#
The last basic property of a set is its size. Sets are crucial in counting and combinatorics, so being able to discuss their size concretely is important. The terms “cardinality” and “size” are often used interchangeably.
Definition (cardinality)
The cardinality of a finite set is the number of distinct elements contained in the set. For a set
The cardinality of any set is non-negative. When the cardinality of a set is some non-negative integer
As a teaser for that topic, we can say that any set is finite if its cardinality is less than the cardinality of the natural numbers
A special kind of finite set is a singleton.
Definition (singleton)
A singleton is a set with cardinality one. That is, it is a set with exactly one member.
Finite cardinality
What is the cardinality of the following sets?
Finite cardinality
Power Set#
A power set is a special kind of set whose members are all sets themselves.
The power set of a set
Definition (power set)
The power set of a set
In set builder notation,
A power set
Let
Moreover,
How do we know if we have found ever possible subset? We can count!
Theorem
For a finite set
2.1.3. Operations on Sets#
There are many possible ways to manipulate, combine, and operate on sets to produce another. Some operations even produce multiple sets.
Before we the operations in particular, we will introduce a graphical representation of sets: Venn diagrams.
In Venn diagrams, a set is represented by a circle. It may or may not have its members indicated within the circle by labelled dots. If we want to be explicit about the universe from which a set is constructed, we draw the Venn diagram inside of a large rectangle. Circles are sets, dots are members, and a rectangle is the universe.
Fig. 2.1 The set
Subsets can also be shown using Venn diagrams.
Fig. 2.2 The sets
Union and Intersection#
The union of two sets is the “joining” of two sets together.
Definition (set union)
The union of two sets
In set builder notation, the union of two sets
Fig. 2.3 The union of sets
The intersection of two sets is about finding their overlap.
Definition (set intersection)
The intersection of two sets
In set builder notation, the intersection of two sets
Fig. 2.4 The intersection of sets
Union and Intersection
Let
Union and intersection are both associative and commutative operations.
Therefore, given multiple sets, say
When we have many sets, we can use
Although union and intersect are individually associative, they do not mix.
Indeed,
Union and Intersection, together
Let
Finally, we have one more definition.
Definition (disjoint sets)
Sets
Set union and intersect
Let:
What is the result of the following unions and intersections?
Set union and intersect
Set union and intersection also have some important identities.
The latter two are the absorption laws for sets. We have seen these already in the context of propositional logic. Visually, absorption for sets is easier to understand than in propositional logic.
Fig. 2.5 The intersection
As a final property of union and intersect, we have the inclusion-exclusion principle. Later, we will see this principle in its full generality. Here we state the special case for two sets.
Proposition
For two sets
Informally, the inclusion-exclusion principle says the size of two sets together
is the size of each set individually, minus the size of their overlap.
We subtract the size of the overlap to avoid double counting. Indeed, with just
Difference and Complement#
Set difference is the analogue of subtraction to sets.
Definition (set difference)
The difference between two sets
In set builder notation, the set difference
Fig. 2.6 The set difference
The complement of a set is everything not in a set. To compute the complement we need a universe
Definition (set complement)
The complement of a set
In set builder notation, the set complement
Fig. 2.7 The complement of a set
Set difference and complement
Let
Notice that the universe for
Set difference and complement also have some important identities.
Review Fig. 2.6 again with the first identity in mind. Can you see how the complement of
Difference and Complement
What is the result of the following difference and complement?
Difference and Complement
. The original set is all rational numbers which are not integers (where ). The complement of that is surely all integers.
Symmetric Difference#
A special kind of difference is symmetric difference. It is the set-equivalent of “exclusive or” from propositional logic.
Definition (symmetric difference)
The symmetric difference of two sets
The “symmetric” in symmetric difference comes from the following identity:
However, a more intuitive way to think about symmetric difference is as the union of two sets minus their intersection.
Which leads to the following Venn diagram.
Fig. 2.8 The symmetric difference of two sets
Cartesian Product#
The final set operation we will consider is their Cartesian product. But first, we need a new kind of discrete structure.
Tuples#
Definition (tuple)
A tuple is a finite ordered sequence of elements (from a set). An
We have special names for tuples of certain lengths:
a
-tuple is a monuple or a singleton,a
-tuple is a couple or a pair,a
-tuple is a triple or triplet,a
-tuple is a quadruple,a
-tuple is a pentuple, and so on
Tuples are denoted using parentheses. For example,
Tip
Unlike sets, ordering is important for tuples. Moreover, the same element may appear more than once in a tuple.
Therefore,
The elements of a tuple are called coordinates. In a tuple
Tuple equality
The tuples
Tuples will become increasingly important in Relations and Functions.
Back to Cartesian products.
The Cartesian product of two (not necessarily different) sets is a new set of tuples constructed from the elements of the two input sets.
Definition (Cartesian product)
The Cartesian product of two sets
The Cartesian product
Notice that if either
Cartesian product
Let
One way of viewing the Cartesian product
If
A Cartesian product also extends to more than two sets.
When a Cartesian product is made between a set and itself, i.e.
Cartesian and Complex planes
The Cartesian plane can be described by
We can also identify the
complex plane with
Fig. 2.9 The complex plane as a
2.1.4. Proofs with Sets#
Because sets are so fundamental to every area of mathematics, many proofs rely on arguments related to set membership. In this section we will examine how to use sets and set membership to prove some theorems.
The first step to most proofs involving sets is to remember the definition of set equality.
Two sets
Most proofs about sets follow this structure. Assume some condition, like
Proving subsets
Prove the following proposition.
Proposition
If
Proving subsets
We look to prove
Proof:
Assume
Assume . Then or . Proceed by cases:If
, we are done.If
, we know , therefore .
Assume . Therefore, must surely be in .
Let’s now examine and prove some more complex laws than just associativity and commutativity. These are examples we have already seen from propositional logic: distribution and De Morgan’s laws.
Distribution#
For sets, we have the following identities.
Visually, these laws can be seen in the following Venn diagrams.
Important
We cannot rely on visuals alone as proofs. Grant Sanderson and the famous 3Blue1Brown YouTube channel has an entire video on the fallacy of visual proofs.
Here is an example of a correct proof using sets to prove one of the distribution laws.
Proving set distribution
Proposition
For any sets
Proof:
Let
We first prove that . Assume . By union, we have that or . Proceed by cases:If
then surely and . Therefore .If
then and . Thus, belongs to both and . Therefore .
We now prove . Assume . Therefore, is a member of both and . By union of :If
then surely and .If
then . We also have ; but since then . Hence, and surely .
De Morgan’s Laws#
For sets, we have the following identities.
Must like propositional logic, De Morgan’s laws flip intersection to union, and vice versa.
A visual proof of the former De Morgan’s law
2.1.5. Exercises#
Exercise 2.1
Write out the following sets using the roster method.
Let
Solution to Exercise 2.1
Exercise 2.2
Write out the following sets using interval notation. Note some may require the union of several intervals.
Solution to Exercise 2.2
Exercise 2.3
Let
Let
Is
Solution to Exercise 2.3
Both.
Exercise 2.4
Let
Write out the following sets using the roster method.
Solution to Exercise 2.4
Exercise 2.5
Let
Write out the following sets using the roster method.
Solution to Exercise 2.5
Exercise 2.6
For any positive integer
What are the following sets? Write your answers using set builder notation or the roster method.
Solution to Exercise 2.6
Exercise 2.7
Prove the following proposition.
Proposition
If
Solution to Exercise 2.7
We look to prove
Proof:
Assume
Assume . Then . Assume . We look to prove , and thus and . The former holds by assumption. For the latter, we have and . Therefore, it must be that .
Exercise 2.8
Prove the following proposition.
Proposition
If
Solution to Exercise 2.8
We look to prove
Proof:
Assume
Assume . Then or . If , we get the desired result. If , we have that , thus . Assume . We look to prove , and thus or . The latter holds by assumption.
Exercise 2.9
Prove the following proposition.
Proposition
Let
Solution to Exercise 2.9
Proof:
Let
We first prove that . Assume . We must prove is in or . By intersect, we have that and . By union, proceed in cases:If
then , therefore .If
then , therefore .
We now prove . Assume . We must prove is in and in . By union, is a member of either or . Proceed by cases:If
then and . Since , we have and therefore .If
then and . Since , we have and therefore .
Exercise 2.10
Prove the following proposition.
Proposition
For any two sets
Solution to Exercise 2.10
Proof: To show equality we will show
Exercise 2.11
Prove the following proposition.
Proposition
Let
Solution to Exercise 2.11
Proof: We look to show that
Let
Let
. Then, and .Let
. Then, and .
Exercise 2.12
Prove the following proposition.
Proposition
Let
Solution to Exercise 2.12
Proof: We must prove a biconditional.
Assume . We look to show . Without loss of generality, suppose . Since , there must be some such that . Since , then . Therefore, . Hence, . Assume . Then, as required.
Exercise 2.13
Let