Chapter 0: The Bare Necessities of Sets and Functions
TODOs
I still need to
- Add extra exercises and solutions to existing exercises.
Almost any serious mathematical subject requires a minimum understanding of sets. Here we will discuss that minimum.
Later in the course we will revisit set theory, to discuss it in a deeper and axiomatic way.
Set Extensionality
A set is a fundamental mathematical object, and as such, cannot be formally defined.
Note
Why can’t a set be formally defined? A philosophical note. The idea that certain concepts cannot be defined may seem paradoxical.
Here’s an argument for why we must deal in concepts which are not defined. Any time that one concept is defined, it is defined in terms of other concepts.
(Amusingly, in Moliere’s play Le Malade Imaginaire, a medical student is asked why opium causes sleep — to which he responds (translated) “because it possesses a virtus dormitiva!” But then virtus dormitiva just means “causes sleep”. So the joke goes: Opium causes sleep because opium causes sleep. A useless circular explanation.)
So a concept, when defined, is necessarily defined in terms of some other concepts. But these other concepts must, themselves, be understood either because they are defined, or because they are simply fundamental and undefined. So we have a dilemma.
You can think of this like a network of concepts. Say that concept A is defined in terms of B, C, and D. Then concept B is defined in terms of, say, E. And so on — each concept defined in terms of others.
If the chain goes on infinitely, then we never actually define the concept A. This would imply the impossibility of definition, and so we must reject this "horn of the dilemma".
If the chain does not go on infinitely, then we arrive at a concept which is not defined. We must accept this horn of the dilemma.
Although we cannot define "sets" formally, we can gesture at some intuitions. A set is meant to be a “collection” or a “gathering together” of some disparate objects.
For example, the set contains four objects (numbers), brought together into a single set.
The set is indicated by curly braces, and then we list the elements of the set.
A set is defined “extensionally”, which is a fancy way of saying:
A set’s only true defining feature is “what is in it, and what is not”.
In the example above, -1 is in the set but 0 is not.
To express membership, we write an infix , like below.
This expresses that “-1 is in the set ”.
When something is not in the set we write . So for example
Extensionality implies that is equal to . After all, they have the same members!
This demonstrates that
Sets do not respect ordering.
Extensionality also implies that
Sets do not respect repetition.
Note that the set {1, 2} is equal to the set {1, 1, 2, 2, 2, 2}, because again, these have the same elements.
Exercise
Decide on the truth of the following expressions. 2. 3. 4. 5. 6. 7. 8. 9.
Solution
- False
- True
- True
- False
- False
- False
- False
- True
Definition
Let X and Y be sets.
We say that X is a subset of Y if, for every we have .
When X is a subset of Y we write .
If X is not a subset of Y we write .
For example, is a subset of , so
Of course the reverse subset inclusion is not true.
It is important to recognize that "set equality" and the "subset relation" have a close relationship.
Set equality is just two subset relations.
More precisely, the set equality is true if and only if we have both
- and
Exercise
For each of the following sets, decide which of the other sets are subsets.
Solution
(2.) is a subset of (1.) and (3.). (1.) is a subset of (3.). No other subset relation holds among the sets.
Number Sets
Definition
The set of natural numbers is
The set of integers is
The set of rational numbers is the set of all fractions, and is denoted . We cannot easily give a pattern for this set, but we can say that and .
In a section below we will introduce set-builder notation. Once you understand set-builder notation, we can then define
The real numbers will be formally defined later, but for now we intuitively define this as the "set of all decimal expansions". It is denoted . For example and .
It is commonly known that and and are real numbers, but not rational.
We will prove some of these claims later, but at least for the duration of this chapter I will assume that this is true.
We will also rely on the fact, without proof, that the rational numbers are the numbers with a decimal expansion which eventually repeats some sequence.
So for example, 1.23454545... is a rational number because its decimal expansion begins to repeat '45' infinitely often.
On the other hand, say is constructed by using only the digits 0 and 1. We start with a single 0 ended by 1. Then two 0's ended by 1. Then three 0's ended by 1, and so on.
This number, x, will never have a repeating pattern in its decimal expansion. Therefore x cannot be rational.
Exercise
Decide whether the following are rational. (Note that 1 is equivalent to 1.0, which is also equivalent to 1.000...)
- 1
- This number is formed by writing down the squares of each natural number, as part of the decimal expansion. So first we write 0 dot, so to speak. Then we write . Then we write . Then . Then we write , and so on.
It is clear that and , and .
Of course it immediately follows that , and . Likewise .
To summarize all of these subset relationships we simply write
Exercise
Let X, Y, and Z be sets such that and .
Show that .
The property of subsets that you are demonstrating in this exercise, is called "transitivity". Recall that we said is not transitive. We are now seeing that is transitive.
Sets of Non-numbers
Sets of numbers will be our most common use of sets.
But in principle we can form sets of anything. We could form sets of letters, like . We could form sets of equations, like
We could form sets of … well, sets!
This can be confusing at first: How many elements does X have?
It has three elements.
You might have thought “but I see seven elements”.
Well yeah, but 1 is not in X. Rather, and . And yet .
In jargon, this means "set membership is not transitive". We will discuss the idea of "transitivity" more later.
Exercise
Let .
Decide which of the following is true.
Find the number of elements in Y.
Set Builder Notation
Most of the sets that we’ll be interested in, are defined by a property, like “all even natural numbers”. We could write this set as
But X is defined by a property! So we would prefer to write it in a way that expresses its property, rather than making you infer it from a pattern.
To do so we use “set builder notation”, demonstrated below.
The way to read this is:
-
The curly brace means “set”.
-
The lower-case x is a “variable” — this will represent any one of the elements in the set.
-
The tells us that x will be a natural number. This essentially establishes the "type" of object that x is.
-
Everything after the colon, “:”, states the property that x must have.

You can imagine it working like this:
Consider the number 1. Since , then 1 is a possible value of x. So we temporarily set . We then check whether x satisfies the property, “x is even”. It does not have the property, so .
Moving on, consider the number 2. Since , then 2 is a possible value of x. So we temporarily set . We then check whether x has the property, “x is even”. It does have the property, so .
And so on. In this way we can confirm that ,
Exercise
Write out the three smallest elements of the set
Solution
Since the possible candidates of X are natural numbers, we can start by considering 1. Temporarily set and then evaluates to -1. Therefore the inequality is not satisfied, therefore 1 is not in this set.
Next temporarily set and then evaluates to 0. Because the inequality is strict, therefore the inequality is not satisfied and 2 is not in the set.
Next set and then evaluates to 3. Since this is greater than 0, then 3 is the smallest element of the set.
Next set , the expression evaluates to 8, so 4 is in the set.
Do it again with and we see that 5 is in the set.
So the three smallest elements are 3,4,5.
Exercise
Give two negative numbers in the set
Solution
-1 and -2. Of course others are possible as well.
There are some variations on set builder notation that you’ll sometimes see when you read other texts. For one example, you can move the “type” after the colon.
For example one could write the set of even natural numbers as
This now says that x is a variable, and it takes values which are both natural numbers and even.
Another variation is that the symbol before the colon does not have to be merely a variable. It is allowed to be a function. For example,
To list out some of the elements of S, we may let x first take the value 1. Then the expression has the value . Therefore .
Next let . Then the expression has the value . Therefore .
Therefore, to represent S by listing a few of its values,
The important point here is that:
Whatever is in the curly braces, before the colon, is the object that is actually in the set.
Exercise
List two more elements of the set S described above.
That is to say: Determine two elements of S which are larger than 26.
Solution
The next two values of are 6 and 7, giving and . Thus two more elements are 37 and 50.
Exercise
List all of the elements of the set
Exercise
List all elements of
Exercise
Consider the sets
Of these sets, which of them are equal? Which is a subset of some other set? Write out all of the relationships that apply.
Exercise
Consider the set
Does the set contain 0? Does it contain positive numbers? Does it contain negative numbers?
Is there a number which you can prove is not in the set? (Hint: Use the fact that an even times any number is even, and the sum of even numbers is even.)
Definition
If then we denote subset of positive elements of X by . That is to say,
Likewise
which are, respectively, the negative, nonnegative, and nonpositive elements of X.
For example, if then
For another, let . Then
If you think about what or , you'll realize that it has no elements. That means that these are equal to the "empty set", which we describe in the next section.
Note that .
Exercise
Determine the elements of .
The Empty Set
Definition
The set which has no elements is called the empty set.
It is written as or .
So of course, for any integer a we have .
One of the facts that students often find the most confusing about the empty set, is that it is a subset of every set.
For example, .
Why? This is equivalent to saying
For every element we have .
But of course the part is simply never true! So how could we then go on to evaluate the part? — and how do we then assess the truth of the entire sentence?
It is precisely because is never true, that therefore the entire sentence “For every element we have ” is necessarily true. That is to say, a sentence of the form “Every P is Q” will always be true when there is no object which is P.
If that confuses you, here are a few explanations which try to make this fact sensible.
-
As you remove elements, you should still have a subset.
So for example, , of course. But if we remove 3, then we still have a subset, . And if we then remove 2 we still have a subset, .
A subset is supposed to be “the same elements or fewer”. So if we continue this progression one more time, and remove 1, we should have .
-
Consider a computer program that checks whether the set X is a subset of Y.
- It considers each element of X.
- If that element is not in Y, the program returns
False. - If no such “counterexample” is ever found, then the program returns
True(i.e. the program determines that X is a subset of Y).
- If that element is not in Y, the program returns
- If that program now runs with , then there is no element to consider. The program never finds a counterexample, and so returns
True-- that is to say, such a program determines that the empty set is a subset of any set.
- It considers each element of X.
Definition
Consider the following principle.
Any sentence of the form “Every P is Q.” is true, whenever there is no object that is P.
This principle is called vacuous quantification.
We will revisit the idea of vacuous quantification later, in the section on logic.
Set Operations
When working with sets it is common to need to “put sets together” in a variety of ways. The following diagrams show the common set operations of union, intersection, complement, and set-minus.

I’ll demonstrate each of these with the sets and .
-
Their union is the set of all elements which are in either A or B. In the diagram this is the merged region in purple.
-
For example since then therefore or . Therefore .
-
Since then therefore or . Therefore .
-
Since and then therefore is not in A or B. Therefore .
-
In this example the union is equal to
-
Their intersection is the set of elements in both A and B. In the diagram this means the overlap shown in green.
-
Since but then therefore .
-
Since and then therefore .
-
The set is equal to
- The complement of the set A is the set of all elements in the “universe” which are not in A. This is the region inside the universe, but outside of A, shown in yellow.
What is the universe? It is whatever set of elements we currently want to discuss. For the purpose of this example, we’ll choose the universe to be , although we could pick it to be many other things.
-
Since therefore .
-
Since then therefore .
-
The set equals
-
The set of A minus B is the set of elements in A but not in B. In the diagram, this is the blue region in A, but removing the portion that overlaps with B.
-
Since and then therefore .
-
Since then .
-
Since and then .
-
The set equals
Definition
Let U be any set which we call the universe.
Let .
Then their union is the set of all elements in A or B, and is denoted .
Their intersection is the set of elements in both A and B, and is denoted .
The complement of A is the set of elements in U which are not in A, and is denoted .
The set of A set-minus B is the set of elements in A but not B, and is denoted .
Exercise
Let the universe be , and , and .
Find
Exercise
Let U be the universe and .
- Show that .
- Show that .
- Show that and .
- Show that .
Definition
Let X and Y be two sets. We say that X and Y are disjoint if
Exercise
Show that is disjoint from every other set.
Exercise
Of the following sets, decide which pairs are disjoint.
- The set of positive integers.
- The set of negative integers.
- The set of even integers.
- The set of odd integers.
- The set of prime integers.
For example, the set of positive integers and the set of negative integers are disjoint.
Which other pairs taken from this list are disjoint?
Bounds, Max, Min
Definition
Let be a nonempty set. Let .
We say that a is a lower bound of X if, for every element , we have
We say that a is an upper bound of X if, for every element , we have
We say that a is the minimum of X if a is a lower bound of X and also .
We say that a is the maximum of X if a is an upper bound of X and also .
When the minimum exists, we denote it by . When the maximum exists, we denote it by .
For example, an upper bound of the set is 5, but the maximum is 3. A lower bound of this set is -100 but the minimum is 1.
Note that we sometimes drop the parentheses in the expression if it causes no confusion. So when I write , this is really shorthand for .
Note that the maximum and minimum need not always exist. For example, there is no maximum of the set . And of course, the set has neither a maximum nor a minimum.
However, there is a fact which we will accept as fundamental throughout this course:
Theorem
Let be nonempty.
If X is bounded below, then X has a minimum.
If X is bounded above, then X has a maximum.
No proof
The proof of this theorem is beyond the scope of this course. We will instead accept this result without proof.
Later in the course, after we have discussed enough logic and set theory, we might revisit the proof of this theorem.
Exercise
Consider the set
Write out several elements of B.
Integer Intervals
To lead with an example, the interval of all natural numbers from 5 to 9 is
To be more precise, we might call this the "inclusive" interval from 5 to 9, since we include 5 and 9. We might also talk about the "exclusive" interval from 5 to 9, which would then be
We will denote the inclusive interval from 5 to 9 with the notation
Definition
Let a and b be integers such that .
The (inclusive) integer interval from a to b is
The exclusive integer interval from a to b is
The out-in integer interval from a to b is
The in-out integer interval from a to b is
We further extend this notation to allow for infinite sets,
and
and
We call a the left end-point of the interval, and b the right end-point.
Exercise
Determine the elements of
Real and Rational Intervals
We will also use intervals of rational and real numbers. For these, we will use a different notation. This notation is a bit unfortunate, because it can look exactly the same as the notation for pairs. But because it is standard, we will use it.
Definition
Let a and b be two real numbers such that .
The inclusive (real) interval from a to b is
This interval is commonly called the "closed interval from a to b". That vocabulary comes from topology, but because we are very far from discussing topology, we will not adopt that vocabulary.
The exclusive interval from a to b is
In the common vocabulary, this is called the "open interval from a to b". Again this vocabulary is from topology, so we don't adopt it now.
The in-out interval from a to b is
and the out-in interval from a to b is
We further extend these to sets with an upper or lower bound, in the same way as with integer intervals.
In every case, we call a the left end-point of the interval, and b the right end-point.
For example, the exclusive interval (0, 4) is a set of real numbers — that is to say, each element is a decimal expansion. It contains the decimal 1 (which can also be written as 1.0 or 1.000...). It also contains 0.5 (or ), and it contains and a bunch of other real numbers.
Exercise
Which of the following are in the interval (0, 4)?
- 2
- 0
- 4
- 5
Exercise
In every case below, I give you a set formed from intervals and set operations. For example, in problem number (1.) below, the solution is that this is equal to .
In each case, it is possible to rewrite each set as a single interval. Find that interval.
We have discussed interval vocabulary and notation for integers, which automatically also covers notation for natural numbers. If you want an interval for natural numbers, just make sure the left end-point is at least 1.
But that means we still must say something about intervals of rational numbers.
To simplify matters, we'll just use what we've already done for real numbers, and simply restrict them to rationals.
So for instance if we want the interval of rational numbers from 1 to 2, we will merely write
So we think of this as starting from the interval of real numbers and then filtering it so that it contains only the rationals.
Definition
Let a and b be any two real numbers, and let I be any interval from a to b.
The rational interval from a to b is the set
Exercise
Determine whether the following statements are true or false.
Lists and Set Products
A list of objects is a finite sequence of them. So for instance, the list of the integers from 1 to 5 is (1, 2, 3, 4, 5) and the list of the numbers from 4 down to 0 is (4, 3, 2, 1, 0).
A list is similar to a set, in the sense that both are formed by a collection of elements. They are, in that sense, both examples of "data structures". They are containers for data.
However, unlike a set, a list respects both order and repetition.
- The list (1, 2) is not the same as (2, 1).
- The list (1, 2) is not the same as (1, 1, 2).
We can also form lists of elements which are not of the same type. For example, we might have a list containing a set and a number, like
This list has length two because it, technically, contains two items: The first item is the set and the second is the number 7.
Consider the list (‘a’, 10, {1,2,3}), which has length 3. We will often want to refer to the elements in the list. To aid in this we refer to the “indices” of elements: In this example, the element ‘a’ is at index 1, the element 10 is at index 2, and the element is at index 3.
The objects at these indices are called the “coordinates”. So the first coordinate in the example above is ‘a’, the second coordinate is 10, and the third coordinate is .
We will use bracket notation to reference the indices of a list. So for example, if the list is then and .
Exercise
Let . Determine
Definition
Let be any list of n elements, for . Let . Then is called an index of .
The expression refers to the ith element of , which we call the element of at index i.
Exercise
Explain why it would make no sense to try to define a notion of "index" for sets.
Definition
For any objects a and b, the pair of them is the list of length two: .
For any three objects, a, b, c, the triple of them is the list of length three: .
Let A and B be sets. Then their set product is , which is the set of all pairs with a left coordinate in A, and a right coordinate in B. That is to say,
More generally if we have n sets, , then their set product is
We also define, for each positive integer ,
So the set is the set of all lists of length n which have elements from the set A.
Suppose that we have sets
Then
Also
Note that it is not an accident that has four elements, and that . That is to say, the number of elements in the set product, is the same as taking the number of elements in each set and multiplying them together.
This fact generalizes: If the number of elements in is , and the number of elements in is , and so on, then the number of elements in is
Note
We will regard as the same as . Also note that, technically,
So by being very technical, is not the same as .
However, we will not care about this difference. That is to say, we will regard as being equal to , and in fact we regard these as also equal to .
It just makes things easier to treat these things as equal, and nothing harmful happens because of this slight “abuse of notation”. If we are being very technical, we would say that all three of these are “isomorphic”. However, we have to develop some more mathematical theory before I can explain what that means exactly.
So for now, just rest assured that this technicality is unimportant—and later on, we can even prove that it is unimportant!
Exercise
Let .
Find and and .
Also find .
Also find .
Exercise
Show that if A is any set, then .
Functions
We are mostly familiar with functions, like . You can give it an input, like 0. It gives back an output, in this case .
Likewise we can find that and , and so on.
We can graph this input-output relationship like so:

Recall the idea of the graph: There is the entire space of coordinates, where x measures how far you go along the horizontal direction, and y how far you go vertically. That's the entire coordinate plane.
A point like is on the graph of f because . The input, 0, is identified on the horizontal axis. The output, 1, is identified on the vertical axis. The point (0, 1) is then on the graph of f.
More generally, the points on the graph are the input-output pairs for the function.
Not every possible curve in the coordinate plane is the graph of a function. Recall the essential idea of a function: If you input something, you get one output. So for example, the following graph is not the graph of any function.

That is because, for a particular choice of x, like say , we can trace that up and down to two different points on the graph.

This is an interesting mathematical object, surely. But it is not a function.
This means that a function must pass the “vertical line test”. The idea of the vertical line test is: If you can draw some vertical line on a graph, and intersect it at two different points, then the graph is not the graph of any function.
Conversely, if every vertical line that you can draw intersects the graph at one point, then it is the graph of some function.
Exercise
Determine which of the following equations has a graph that is a function. This means that you'll need to determine the graph of each equation.
Domain
A function typically has a domain and a “range”.
The idea of the domain is likely to be familiar to anyone who has taken high school algebra: It is the set of values which one is able to give as input to the function.
For example, the domain of f above is just “all real numbers”. If you have any doubt about the meaning of "real numbers", for now, don't worry about it. Just regard this as "all numbers".
Sometimes we like to write a set of real numbers using interval notation. In this particular case, the interval of “all real numbers” is written , so this is the domain of f.
On the other hand, the function has domain equal to all real numbers except for . That is to say, this function has one real number not in its domain, because is undefined.
The best way to represent this domain is
If we wish to express this domain in interval notation (which students are often taught to do in high school, so we might as well connect that to what we're doing here), then we would write . But clearly this is much more notation than just , and therefore we prefer to use the simpler expression.
Let’s see another example. Assuming that we’re sticking to real numbers, the function has domain equal to all nonnegative real numbers. That is to say, its domain is . This is because there is no real square root of negative numbers.
You can identify the domain of a function by looking at its graph. For example, the graph above for has no “gaps” in it—you can set x to anything and find a corresponding y value on the graph.
Here is the graph for .

You can see that when there is no corresponding value on the graph.
And here is the graph of .

Again you can see where the domain is missing: negative numbers.
Exercise
Find the domain of each function below.
If you find it helpful then you should put this function into some kind of graphing software and use the graph to help identify the domain.
Range
In many US high schools, the word "range" is often used in an ambiguous way. Therefore we need to clarify the meaning of this word.
-
At times, students are taught that the range of a function is “the set of all outputs”. If you refer back to this graph of , you would identify every y-value with a point in the range.
The least y value you can identify in this graph is at (0,1), where the y-value is 1.
For every number above 1, you can find this y-value on the graph.
So by this definition, the range is .
-
At other times, students are taught that the range of a function is “any set that contains the outputs”.
You will often see it stated that a function like has a range equal to all real numbers, . Because this set contains all of the outputs of f, then according to this definition, is an acceptable choice for “the range of f”.
Of course this ambiguity is unpleasant, and therefore we will do what many university mathematics courses do: We distinguish between the “range” and the “codomain”.
So for us, the range of a function is “the set of all outputs”.
We will define the codomain of a function to be “any set that contains all outputs”.
According to these definitions, therefore the range of f is and the codomain of f can be .
Let’s see the range for the other functions that we’ve been describing. If you look back at the graph of , it should be clear that the range is . If you look at the graph of it should be clear that the range is .
Exercise
Go back to the previous exercise, which asked you to find the domains of several functions. Now find their ranges.
Codomain
You may be asking a very reasonable question: Why do we even have the concept of a codomain?
I mean, the range seems natural, precisely defined, and descriptive of what the function is.
The codomain can be just any set bigger than the range. That seems less natural, less precise, and less descriptive. Why even bother with this concept?
There are two reasons not to answer this right now. First, we will discuss it later on, when we’ve developed more rigorous and serious ideas in mathematics which will help us to talk about it. Second, I want to keep the current section short.
Domain and Range Notation
If f is a function with domain A and codomain B, we will write .
Exercise
Look back at the previous exercise, which asked you to find the domains of several functions. Write each function using the notation introduced here, specifying its domain and a possible codomain.