Introduction and Preliminaries - Sets and Functions
Introduction and Preliminaries - Sets and Functions
0.3 Sets
The most fundamental objects we will use in our studies (and really in
all of math) are sets. Much of what follows might be review, but it is
very important that you are fluent in the language of set theory. Most of
the notation we use below is standard, although some might be a little
different than what you have seen before.
For us, a set will simply be an unordered collection of objects. Two
examples: we could consider the set of all actors who have played The
Doctor on Doctor Who, or the set of natural numbers between 1 and 10
inclusive. In the first case, Tom Baker is a element (or member) of the set,
while Idris Elba, among many others, is not an element of the set. Also,
the two examples are of different sets. Two sets are equal exactly if they
contain the exact same elements. For example, the set containing all of
the vowels in the declaration of independence is precisely the same set as
the set of vowels in the word “questionably” (namely, all of them); we do
not care about order or repetitions, just whether the element is in the set
or not.
Notation
We need some notation to make talking about sets easier. Consider,
A {1, 2, 3}.
This is read, “A is the set containing the elements 1, 2 and 3.” We use
curly braces “{, }” to enclose elements of a set. Some more notation:
a ∈ {a, b, c}.
The symbol “∈” is read “is in” or “is an element of.” Thus the above
means that a is an element of the set containing the letters a, b, and c.
Note that this is a true statement. It would also be true to say that d is not
in that set:
d < {a, b, c}.
Be warned: we write “x ∈ A” when we wish to express that one of the
elements of the set A is x. For example, consider the set,
cannot say that the set B is one of the elements of A. Therefore B < A.
(Soon we will see that B is a subset of A, but this is different from being an
element of A.)
We have described the sets above by listing their elements. Sometimes
this is hard to do, especially when there are a lot of elements in the set
(perhaps infinitely many). For instance, if we want A to be the set of all
even natural numbers, would could write,
A {0, 2, 4, 6, . . .},
A {x ∈ N : ∃n ∈ N(x 2n)}.
Let’s look at this carefully. First, there are some new symbols to digest:
“N” is the symbol usually used to denote that natural numbers, which
we will take to be the set {0, 1, 2, 3, . . .}. Next, the colon, “:”, is read such
that; it separates the elements that are in the set from the condition that
the elements in the set must satisfy. So putting this all together, we would
read the set as, “the set of all x in the natural numbers, such that there
exists some n in the natural numbers for which x is twice n.” In other
words, the set of all natural numbers, that are even. Here is another way
to write the same set.
A {x ∈ N : x is even}.
Example 0.3.1
Describe each of the following sets both in words and by listing out
enough elements to see the pattern.
1. {x : x + 3 ∈ N}.
2. {x ∈ N : x + 3 ∈ N}.
3. {x : x ∈ N ∨ −x ∈ N}.
26 0. Introduction and Preliminaries
4. {x : x ∈ N ∧ −x ∈ N}.
Solution.
1. This is the set of all numbers which are 3 less than a natural
number (i.e., that if you add 3 to them, you get a natural num-
ber). The set could also be written as {−3, −2, −1, 0, 1, 2, . . .}
(note that 0 is a natural number, so −3 is in this set because
−3 + 3 0).
2. This is the set of all natural numbers which are 3 less than a
natural number. So here we just have {0, 1, 2, 3 . . .}.
3. This is the set of all integers (positive and negative whole
numbers, written Z). In other words, {. . . , −2, −1, 0, 1, 2, . . .}.
4. Here we want all numbers x such that x and −x are natural
numbers. There is only one: 0. So we have the set {0}.
Example 0.3.2
List a few elements in the sets below and describe them in words.
The set Z is the set of integers; positive and negative whole num-
bers.
1. A {x ∈ Z : x 2 ∈ N}
2. B {x 2 : x ∈ N}
Solution.
1. The set of integers that pass the condition that their square
is a natural number. Well, every integer, when you square it,
gives you a non-negative integer, so a natural number. Thus
A Z {. . . , −2, −1, 0, 1, 2, 3, . . .}.
2. Here we are looking for the set of all x 2 s where x is a natural
number. So this set is simply the set of perfect squares. B
{0, 1, 4, 9, 16, . . .}.
Another way we could have written this set, using more
strict set builder notation, would be as B {x ∈ N : x
n 2 for some n ∈ N}.
0.3. Sets 27
Investigate!
(Remember, the order the elements are written down in does not
matter.) Also,
since these are all ways to write the set containing the first three positive
integers (how we write them doesn’t matter, just what they are).
What about the sets A {1, 2, 3} and B {1, 2, 3, 4}? Clearly A , B,
but notice that every element of A is also an element of B. Because of this
we say that A is a subset of B, or in symbols A ⊂ B or A ⊆ B. Both symbols
are read “is a subset of.” The difference is that sometimes we want to say
that A is either equal to or is a subset of B, in which case we use ⊆. This
is analogous to the difference between < and ≤.
0.3. Sets 29
Example 0.3.3
1. A ⊂ B. 4. ∅ ∈ A. 7. 3 ∈ C.
2. B ⊂ A. 5. ∅ ⊂ A. 8. 3 ⊂ C.
3. B ∈ C. 6. A < D. 9. {3} ⊂ C.
Solution.
Example 0.3.4
P(A) {∅, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}.
30 0. Introduction and Preliminaries
Another way to compare sets is by their size. Notice that in the example
above, A has 6 elements and B, C, and D all have 3 elements. The size of a
set is called the set’s cardinality . We would write |A| 6, |B| 3, and so
on. For sets that have a finite number of elements, the cardinality of the
set is simply the number of elements in the set. Note that the cardinality
of {1, 2, 3, 2, 1} is 3. We do not count repeats (in fact, {1, 2, 3, 2, 1} is
exactly the same set as {1, 2, 3}). There are sets with infinite cardinality,
such as N, the set of rational numbers (written Q), the set of even natural
numbers, and the set of real numbers (R). It is possible to distinguish
between different infinite cardinalities, but that is beyond the scope of this
text. For us, a set will either be infinite, or finite; if it is finite, the we can
determine its cardinality by counting elements.
Example 0.3.5
Solution.
Operations On Sets
Is it possible to add two sets? Not really, however there is something
similar. If we want to combine two sets to get the collection of objects that
are in either set, then we can take the union of the two sets. Symbolically,
C A ∪ B,
read, “C is the union of A and B,” means that the elements of C are exactly
the elements which are either an element of A or an element of B (or an
element of both). For example, if A {1, 2, 3} and B {2, 3, 4}, then
A ∪ B {1, 2, 3, 4}.
The other common operation on sets is intersection. We write,
C A∩B
and say, “C is the intersection of A and B,” when the elements in C are
precisely those both in A and in B. So if A {1, 2, 3} and B {2, 3, 4},
then A ∩ B {2, 3}.
Often when dealing with sets, we will have some understanding as
to what “everything” is. Perhaps we are only concerned with natural
numbers. In this case we would say that our universe is N. Sometimes
we denote this universe by U. Given this context, we might wish to
speak of all the elements which are not in a particular set. We say B is the
complement of A, and write,
BA
Example 0.3.6
Solution.
Example 0.3.7
You might notice that the symbols for union and intersection slightly
resemble the logic symbols for “or” and “and.” This is no accident. What
does it mean for x to be an element of A ∪ B? It means that x is an element
of A or x is an element of B (or both). That is,
x ∈A∪B ⇔ x ∈ A ∨ x ∈ B.
Similarly,
x ∈A∩B ⇔ x ∈ A ∧ x ∈ B.
Also,
x∈A ⇔ ¬(x ∈ A).
which says x is an element of the complement of A if x is not an element
of A.
There is one more way to combine sets which will be useful for us: the
Cartesian product, A × B. This sounds fancy but is nothing you haven’t
seen before. When you graph a function in calculus, you graph it in
the Cartesian plane. This is the set of all ordered pairs of real numbers
(x, y). We can do this for any pair of sets, not just the real numbers with
themselves.
Put another way, A × B {(a, b) : a ∈ A ∧ b ∈ B}. The first coordinate
comes from the first set and the second coordinate comes from the second
set. Sometimes we will want to take the Cartesian product of a set with
itself, and this is fine: A × A {(a, b) : a, b ∈ A} (we might also write A2
for this set). Notice that in A × A, we still want all ordered pairs, not just
the ones where the first and second coordinate are the same. We can also
take products of 3 or more sets, getting ordered triples, or quadruples,
and so on.
Example 0.3.8
Venn Diagrams
There is a very nice visual tool we can use to represent operations on sets.
A Venn diagram displays sets as intersecting circles. We can shade the
region we are talking about when we carry out an operation. We can
34 0. Introduction and Preliminaries
A B A B
C
Each circle represents a set. The rectangle containing the circles rep-
resents the universe. To represent combinations of these sets, we shade
the corresponding region. For example, we could draw A ∩ B as:
A B
A B
C
Notice that the shaded regions above could also be arrived at in an-
other way. We could have started with all of C, then excluded the region
where C and A overlap outside of B. That region is (A ∩ C) ∩ B. So the
above Venn diagram also represents C ∩ (A ∩ C) ∩ B . So using just the
picture, we have determined that
(B ∩ C) ∪ (C ∩ A) C ∩ (A ∩ C) ∩ B .
0.3. Sets 35
Exercises
1. Let A {1, 4, 9} and B {1, 3, 6, 10}. Find each of the following sets.
(a) A ∪ B.
(b) A ∩ B.
(c) A \ B.
(d) B \ A.
2. Find the least element of each of the following sets, if there is one.
(a) {n ∈ N : n 2 − 3 ≥ 2}.
(b) {n ∈ N : n 2 − 5 ∈ N}.
(c) {n 2 + 1 : n ∈ N}.
(d) {n ∈ N : n k 2 + 1 for some k ∈ N}.
3. Find the following cardinalities:
(a) |A| when A {4, 5, 6, . . . , 37}.
(b) |A| when A {x ∈ Z : −2 ≤ x ≤ 100}.
(c) |A ∩ B| when A {x ∈ N : x ≤ 20} and B {x ∈ N : x is prime}.
4. Find a set of largest possible size that is a subset of both {1, 2, 3, 4, 5}
and {2, 4, 6, 8, 10}.
5. Find a set of smallest possible size that has both {1, 2, 3, 4, 5} and
{2, 4, 6, 8, 10} as subsets.
6. Let A {n ∈ N : 20 ≤ n < 50} and B {n ∈ N : 10 < n ≤ 30}.
Suppose C is a set such that C ⊆ A and C ⊆ B. What is the largest
possible cardinality of C?
7. Let A {1, 2, 3, 4, 5} and B {2, 3, 4}. How many sets C have the
property that C ⊆ A and B ⊆ C.
8. Let A {1, 2, 3, 4, 5}, B {3, 4, 5, 6, 7}, and C {2, 3, 5}.
(a) Find A ∩ B.
(b) Find A ∪ B.
(c) Find A \ B.
(d) Find A ∩ (B ∪ C).
9. Let A {x ∈ N : 4 ≤ x < 12} and B {x ∈ N : x is even}.
(a) Find A ∩ B.
(b) Find A \ B.
36 0. Introduction and Preliminaries
26. In a regular deck of playing cards there are 26 red cards and 12
face cards. Explain, using sets and what you have learned about
cardinalities, why there are only 32 cards which are either red or a
face card.
27. Find an example of a set A with |A| 3 which contains only other
sets and has the following property: for all sets B ∈ A, we also have
B ⊆ A. Explain why your example works. (FYI: sets that have this
property are called transitive.)
28. Consider the sets A and B, where A {3, |B|} and B {1, |A|, |B|}.
What are the sets?
29. Explain why there is no set A which satisfies A {2, |A|}.
30. Find all sets A, B, and C which satisfy the following.
0.4 Functions
A function is a rule that assigns each input exactly one output. We call the
output the image of the input. The set of all inputs for a function is called
the domain. The set of all allowable outputs is called the codomain. We
would write f : X → Y to describe a function with name f , domain X and
codomain Y. This does not tell us which function f is though. To define
the function, we must describe the rule. This is often done by giving a
formula to compute the output for any input (although this is certainly
not the only way to describe the rule).
For example, consider the function f : N → N defined by f (x) x 2 +3.
Here the domain and codomain are the same set (the natural numbers).
The rule is: take your input, multiply it by itself and add 3. This works
because we can apply this rule to every natural number (every element of
the domain) and the result is always a natural number (an element of the
codomain). Notice though that not every natural number is actually an
output (there is no way to get 0, 1, 2, 5, etc.). The set of natural numbers
that are outputs is called the range of the function (in this case, the range
is {3, 4, 7, 12, 19, 28, . . .}, all the natural numbers that are 3 more than a
perfect square).
The key thing that makes a rule a function is that there is exactly one
output for each input. That is, it is important that the rule be a good rule.
What output do we assign to the input 7? There can only be one answer
for any particular function.
Example 0.4.1
Example 0.4.2
Just because you can describe a rule in the same way you would
write a function, does not mean that the rule is a function. The
following are NOT functions.
1. f : N → N defined by f (n) n2 . The reason this is not a
function is because not every input has an output. Where
does f send 3? The rule says that f (3) 32 , but 32 is not an
element of the codomain.
2. Consider the rule that matches each person to their phone
number. If you think of the set of people as the domain
and the set of phone numbers as the codomain, then this is
not a function, since some people have two phone numbers.
Switching the domain and codomain sets doesn’t help either,
since some phone numbers belong to multiple people (as-
suming some households still have landlines when you are
reading this).
Describing Functions
It is worth making a distinction between a function and its description.
The function is the abstract mathematical object that in some way exists
whether or not anyone ever talks about it. But when we do want to talk
about the function, we need a way to describe it. A particular function
can be described in multiple ways.
Some calculus textbooks talk about the Rule of Four, that every function
can be described in four ways: algebraically (a formula), numerically (a
table), graphically, or in words. In discrete math, we can still use any of
these to describe functions, but we can also be more specific since we are
primarily concerned with functions that have N or a finite subset of N as
their domain.
Describing a function graphically usually means drawing the graph of
the function: plotting the points on the plane. We can do this, and might
get a graph like the following for a function f : {1, 2, 3} → {1, 2, 3}.
0.4. Functions 41
1 2 3
This shows that the function f sends 1 to 2, 2 to 1 and 3 to 3: just
follow the arrows.
The arrow diagram used to define the function above can be very
helpful in visualizing functions. We will often be working with functions
with finite domains, so this kind of picture is often more useful than a
traditional graph of a function.
Note that for finite domains, finding an algebraic formula that gives
the output for any input is often impossible. Of course we could use a
piecewise defined function, like
x+1 if x 1
f (x) x − 1 if x 2 .
x if x 3
This describes exactly the same function as above, but we can all agree is
a ridiculous way of doing so.
Since we will so often use functions with small domains and codomains,
let’s adopt some notation to describe them. All we need is some clear way
of denoting the image of each element in the domain. In fact, writing a
table of values would work perfectly:
x 0 1 2 3 4
f (x) 3 3 2 4 1
We simplify this further by writing this as a matrix with each input
directly over its output:
0 1 2 3 4
f .
3 3 2 4 1
42 0. Introduction and Preliminaries
Note this is just notation and not the same sort of matrix you would find
in a linear algebra class (it does not make sense to do operations with
these matrices, or row reduce them, for example).
One advantage of the two-line notation over the arrow diagrams is
that it is harder to accidentally define a rule that is not a function using
two-line notation.
Example 0.4.3
a c a b c d a b c d
b d
Example 0.4.4
f (6) f (5) + 11 25 + 11 36
Example 0.4.5
Solution.
f (0) 1; f (n + 1) (n + 1) · f (n).
Example 0.4.6
1 2 3
1 2 3
Solution.
Example 0.4.7
1 2 3
2. g : {1, 2, 3} → {a, b, c} defined by g .
c a a
3. h : {1, 2, 3} → {1, 2, 3} defined as follows:
1 2 3
1 2 3
Solution.
or might not have repeats. The bijective functions are those that do not
have repeats and do not miss elements.
Example 0.4.8
Example 0.4.9
Since f −1 (y) is a set, it makes sense to ask for f −1 (y), the number of
elements in the domain which map to y.
Example 0.4.10
Find a function f : {1, 2, 3, 4, 5} → N such that f −1 (7) 5.
Solution. There is only one such function. We need five elements
of the domain to map to the number 7 ∈ N. Since there are only
five elements in the domain, all of them must map to 7. So
1 2 3 4 5
f .
7 7 7 7 7
50 0. Introduction and Preliminaries
Function Definitions.
Here is a summary of all the main concepts and definitions we use when
working with functions.
Exercises
1. Consider the function f : {1, 2, 3, 4} → {1, 2, 3, 4} given by
1 2 3 4
f (n) .
4 1 3 4
1 2 3 4
(b) f .
1 2 3 2
(c) f (x) gives the number of letters in the English word for the
number x. For example, f (1) 3 since “one” contains three
letters.
5. Write out all functions f : {1, 2, 3} → {a, b} (using two-line notation).
How many functions are there?
How many are injective?
How many are surjective?
How many are bijective?
6. Write out all functions f : {1, 2} → {a, b, c} (in two-line notation).
How many functions are there?
How many are injective?
How many are surjective?
How many are bijective?
7. Consider the function f : {1, 2, 3, 4, 5} → {1, 2, 3, 4} given by the table
below:
x 1 2 3 4 5
f (x) 3 2 4 1 2
1 2 3 4 x
Note that with the initial condition f (0) 1, the values of the function
are: f (1) 4, f (2) 2, f (3) 1, f (4) 4, and so on, the images cy-
cling through those three numbers. Thus f is NOT injective (and also
certainly not surjective). Might it be under other initial conditions?3
(a) If f satisfies the initial condition f (0) 5, is f injective? Explain
why or give a specific example of two elements from the domain
with the same image.
(b) If f satisfies the initial condition f (0) 3, is f injective? Explain
why or give a specific example of two elements from the domain
with the same image.
(c) If f satisfies the initial condition f (0) 27, then it turns out that
f (105) 10 and no two numbers less than 105 have the same
image. Could f be injective? Explain.
(d) Prove that no matter what initial condition you choose, the
function cannot be surjective.
12. For each function given below, determine whether or not the function
is injective and whether or not the function is surjective.
(a) f : N → N given by f (n) n + 4.
(b) f : Z → Z given by f (n) n + 4.
3It turns out this is a really hard question to answer in general. The Collatz conjecture is
that no matter what the initial condition is, the function will eventually produce 1 as an
output. This is an open problem in mathematics: nobody knows the answer.
54 0. Introduction and Preliminaries
15. Consider the set N2 N × N, the set of all ordered pairs (a, b) where
a and b are natural numbers. Consider a function f : N2 → N given
by f ((a, b)) a + b.
(a) Let A {(a, b) ∈ N2 : a, b ≤ 10}. Find f (A).
(b) Find f −1 (3) and f −1 ({0, 1, 2, 3}).
(c) Give geometric descriptions of f −1 (n) and f −1 ({0, 1, . . . , n}) for
any n ≥ 1.
(d) Find f −1 (8) and f −1 ({0, 1, . . . , 8}).
23. In the game of Hearts, four players are each dealt 13 cards from a
deck of 52. Is this a function? If so, what sets make up the domain
and codomain, and is the function injective, surjective, bijective, or
neither?
24. Seven players are playing 5-card stud. Each player initially receives 5
cards from a deck of 52. Is this a function? If so, what sets make up
the domain and codomain, and is the function injective, surjective,
bijective, or neither?
25. Consider the function f : N → N that gives the number of handshakes
that take place in a room of n people assuming everyone shakes hands
with everyone else. Give a recursive definition for this function.
26. Let f : X → Y be a function and A ⊆ X be a finite subset of the
domain.
What can you say about the relationship between |A| and
f (A)? Consider both the general case and what happens when you
know f is injective, surjective, or bijective.
27. Let f : X → Y be a function and B ⊆ Y be a finite subset of the
codomain.
What can you say about the relationship between |B| and
f −1 (B)? Consider both the general case and what happens when you
know f is injective, surjective, or bijective.
28. Let f : X → Y be a function, A ⊆ X and B ⊆ Y.
(a) Is f −1 f (A) A? Always, sometimes, never? Explain.
(b) Is f f −1 (B) B? Always, sometimes, never? Explain.
(c) If one or both of the above do not always hold, is there some-
thing else you can say? Will equality always hold for particular
types of functions? Is there some other relationship other than
equality that would always hold? Explore.
29. Let f : X → Y be a function and A, B ⊆ X be subsets of the domain.
(a) Is f (A ∪ B) f (A) ∪ f (B)? Always, sometimes, or never?
Explain.
(b) Is f (A ∩ B) f (A) ∩ f (B)? Always, sometimes, or never?
Explain.
30. Let f : X → Y be a function and A, B ⊆ Y be subsets of the codomain.
(a) Is f −1 (A ∪ B) f −1 (A) ∪ f −1 (B)? Always, sometimes, or never?
Explain.
(b) Is f −1 (A ∩ B) f −1 (A) ∩ f −1 (B)? Always, sometimes, or never?
Explain.