Discrete Mathematics Module
Discrete Mathematics Module
1
2 0. Introduction and Preliminaries
Investigate!
Note: Throughout the text you will see Investigate! activities like this
one. Answer the questions in these as best you can to give yourself a feel
for what is coming next.
1. The most popular mathematician in the world is throwing
a party for all of his friends. As a way to kick things off,
they decide that everyone should shake hands. Assuming
all 10 people at the party each shake hands with every other
person (but not themselves, obviously) exactly once, how
many handshakes take place?
2. At the warm-up event for Oscar’s All Star Hot Dog Eating
Contest, Al ate one hot dog. Bob then showed him up by
eating three hot dogs. Not to be outdone, Carl ate five. This
continued with each contestant eating two more hot dogs
than the previous contestant. How many hot dogs did Zeno
(the 26th and final contestant) eat? How many hot dogs were
eaten all together?
3. After excavating for weeks, you finally arrive at the burial
chamber. The room is empty except for two large chests. On
each is carved a message (strangely in English):
we will study four main topics: combinatorics (the theory of ways things
combine; in particular, how to count these ways), sequences, symbolic
logic, and graph theory. However, there are other topics that belong
under the discrete umbrella, including computer science, abstract algebra,
number theory, game theory, probability, and geometry (some of these,
particularly the last two, have both discrete and non-discrete variants).
Ultimately the best way to learn what discrete math is about is to do it.
Let’s get started! Before we can begin answering more complicated (and
fun) problems, we must lay down some foundation. We start by reviewing
mathematical statements, sets, and functions in the framework of discrete
mathematics.
4 0. Introduction and Preliminaries
Investigate!
While walking through a fictional forest, you encounter three trolls
guarding a bridge. Each is either a knight, who always tells the
truth, or a knave, who always lies. The trolls will not let you pass
until you correctly identify each as either a knight or a knave. Each
troll makes a single statement:
Troll 1: If I am a knave, then there are exactly two
knights here.
Troll 2: Troll 1 is lying.
Troll 3: Either we are all knaves or at least one of us is
a knight.
Example 0.2.1
• 3 + 7 12
Note that we can break this down into two smaller statements. The
two shorter statements are connected by an “and.” We will consider 5
connectives: “and” (Sam is a man and Chris is a woman), “or” (Sam is a
man or Chris is a woman), “if. . . , then. . . ” (if Sam is a man, then Chris is
a woman), “if and only if” (Sam is a man if and only if Chris is a woman),
and “not” (Sam is not a man). The first four are called binary connectives
(because they connect two statements) while “not” is an example of a
unary connective (since it applies to a single statement).
These molecular statements are of course still statements, so they must
be either true or false. The absolutely key observation here is that which
truth value the molecular statement achieves is completely determined
by the type of connective and the truth values of the parts. We do not
need to know what the parts actually say, only whether those parts are
true or false. So to analyze logical connectives, it is enough to consider
propositional variables (sometimes called sentential variables), usually
capital letters in the middle of the alphabet: P, Q, R, S, . . .. We think of
these as standing in for (usually atomic) statements, but there are only two
6 0. Introduction and Preliminaries
values the variables can achieve: true or false.1 We also have symbols for
the logical connectives: ∧, ∨, →, ↔, ¬.
Logical Connectives.
• P ∧ Q is read “P and Q,” and called a conjunction.
• P ∨ Q is read “P or Q,” and called a disjunction.
• P → Q is read “if P then Q,” and called an implication or
conditional.
• P ↔ Q is read “P if and only if Q,” and called a biconditional.
Note that for us, or is the inclusive or (and not the sometimes used
exclusive or) meaning that P ∨ Q is in fact true when both P and Q are true.
As for the other connectives, “and” behaves as you would expect, as does
negation. The biconditional (if and only if) might seem a little strange,
but you should think of this as saying the two parts of the statements are
equivalent in that they have the same truth value. This leaves only the
conditional P → Q which has a slightly different meaning in mathematics
than it does in ordinary usage. However, implications are so common and
useful in mathematics, that we must develop fluency with their use, and
as such, they deserve their own subsection.
Implications
Implications.
An implication or conditional is a molecular statement of the form
P→Q
This is a reasonable way to think about implications: our claim is that the
conclusion (“then” part) is true, but on the assumption that the hypothesis
(“if” part) is true. We make no claim about the conclusion in situations
when the hypothesis is false.2
Still, it is important to remember that an implication is a statement,
and therefore is either true or false. The truth value of the implication is
determined by the truth values of its two parts. To agree with the usage
above, we say that an implication is true either when the hypothesis is
false, or when the conclusion is true. This leaves only one way for an
implication to be false: when the hypothesis is true and the conclusion is
false.
2However, note that in the case of the Pythagorean Theorem, it is also the case that if
a 2 + b 2 c 2 , then a and b are the legs of a right triangle with hypotenuse c. So we could
have also expressed this theorem as a biconditional: “a and b are the legs of a right triangle
with hypotenuse c if and only if a 2 + b 2 c 2 .”
8 0. Introduction and Preliminaries
Example 0.2.2
Example 0.2.3
Decide which of the following statements are true and which are
false. Briefly explain.
1. If 1 1, then most horses have 4 legs.
2. If 0 1, then 1 1.
3. If 8 is a prime number, then the 7624th digit of π is an 8.
4. If the 7624th digit of π is an 8, then 2 + 2 4.
Solution. All four of the statements are true. Remember, the only
way for an implication to be false is for the if part to be true and the
then part to be false.
1. Here both the hypothesis and the conclusion are true, so
the implication is true. It does not matter that there is no
meaningful connection between the true mathematical fact
and the fact about horses.
2. Here the hypothesis is false and the conclusion is true, so the
implication is true.
0.2. Mathematical Statements 9
3. I have no idea what the 7624th digit of π is, but this does
not matter. Since the hypothesis is false, the implication is
automatically true.
4. Similarly here, regardless of the truth value of the hypothesis,
the conclusion is true, making the implication true.
Perhaps a better way to say this is that to prove a statement of the form
P → Q directly, you must explain why Q is true, but you get to assume P
is true first. After all, you only care about whether Q is true in the case
that P is as well.
There are other techniques to prove statements (implications and
others) that we will encounter throughout our studies, and new proof
techniques are discovered all the time. Direct proof is the easiest and most
elegant style of proof and has the advantage that such a proof often does a
great job of explaining why the statement is true.
Example 0.2.4
Prove: If two numbers a and b are even, then their sum a + b is even.
Solution.
Proof. Suppose the numbers a and b are even. This means that
a 2k and b 2j for some integers k and j. The sum is then
a + b 2k + 2j 2(k + j). Since k + j is an integer, this means that
a + b is even.
Notice that since we get to assume the hypothesis of the impli-
cation, we immediately have a place to start. The proof proceeds
essentially by repeatedly asking and answering, “what does that
mean?” Eventually, we conclude that it means the conclusion.
10 0. Introduction and Preliminaries
Example 0.2.5
True or false: If you draw any nine playing cards from a regular
deck, then you will have at least three cards all of the same suit. Is
the converse true?
Solution. True. The original implication is a little hard to analyze
because there are so many different combinations of nine cards. But
consider the contrapositive: If you don’t have at least three cards all
of the same suit, then you don’t have nine cards. It is easy to see
why this is true: you can at most have two cards of each of the four
suits, for a total of eight cards (or fewer).
0.2. Mathematical Statements 11
The converse: If you have at least three cards all of the same suit,
then you have nine cards. This is false. You could have three spades
and nothing else. Note that to demonstrate that the converse (an
implication) is false, we provided an example where the hypothesis
is true (you do have three cards of the same suit), but where the
conclusion is false (you do not have nine cards).
Example 0.2.6
Suppose I tell Sue that if she gets a 93% on her final, then she will
get an A in the class. Assuming that what I said is true, what can
you conclude in the following cases:
1. Sue gets a 93% on her final.
2. Sue gets an A in the class.
3. Sue does not get a 93% on her final.
4. Sue does not get an A in the class.
Sue did not get a 93% on the final. Notice now we have the
implication ¬Q → ¬P which is the contrapositive of P → Q.
Since P → Q is assumed to be true, we know ¬Q → ¬P is
true as well.
You can think of “if and only if” statements as having two parts: an
implication and its converse. We might say one is the “if” part, and
the other is the “only if” part. We also sometimes say that “if and only
if” statements have two directions: a forward direction (P → Q) and
a backwards direction (P ← Q, which is really just sloppy notation for
Q → P).
Let’s think a little about which part is which. Is P → Q the “if” part or
the “only if” part? Consider an example.
Example 0.2.7
It is not terribly important to know which part is the “if” or “only if”
part, but this does illustrate something very, very important: there are many
ways to state an implication!
Example 0.2.8
1. I am asleep if I dream.
2. I dream only if I am asleep.
3. In order to dream, I must be asleep.
4. To dream, it is necessary that I am asleep.
5. To be asleep, it is sufficient to dream.
6. I am not dreaming unless I am asleep.
1. I dream if I am asleep.
2. I am asleep only if I dream.
3. It is necessary that I dream in order to be asleep.
4. It is sufficient that I be asleep in order to dream.
5. If I don’t dream, then I’m not asleep.
Hopefully you agree with the above example. We include the “neces-
sary and sufficient” versions because those are common when discussing
mathematics. In fact, let’s agree once and for all what they mean.
14 0. Introduction and Preliminaries
To be honest, I have trouble with these if I’m not very careful. I find it
helps to keep a standard example for reference.
Example 0.2.9
Thinking about the necessity and sufficiency of conditions can also help
when writing proofs and justifying conclusions. If you want to establish
some mathematical fact, it is helpful to think what other facts would be
enough (be sufficient) to prove your fact. If you have an assumption, think
about what must also be necessary if that hypothesis is true.
0.2. Mathematical Statements 15
Investigate!
Consider the statements below. Decide whether any are equivalent
to each other, or whether any imply any others.
1. You can fool some people all of the time.
2. You can fool everyone some of the time.
3. You can always fool some people.
4. Sometimes you can fool everyone.
P(n) → ¬P(n + 7)
where P(n) means “n is prime.” But this is not quite right. For one
thing, because this sentence has a free variable (that is, a variable that we
have not specified anything about), it is not a statement. A sentence that
contains variables is called a predicate.
Now, if we plug in a specific value for n, we do get a statement. In
fact, it turns out that no matter what value we plug in for n, we get a true
implication in this case. What we really want to say is that for all values of
n, if n is prime, then n + 7 is not. We need to quantify the variable.
Although there are many types of quantifiers in English (e.g., many, few,
most, etc.) in mathematics we, for the most part, stick to two: existential
and universal.
Universal and Existential Quantifiers.
The existential quantifier is ∃ and is read “there exists” or “there is.”
For example,
∃x(x < 0)
asserts that there is a number less than 0.
The universal quantifier is ∀ and is read “for all” or “every.” For
example,
∀x(x ≥ 0)
asserts that every number is greater than or equal to 0.
16 0. Introduction and Preliminaries
You would read this, “for every x there is some y such that y is less than x.”
Is this true? The answer depends on what our domain of discourse is: when
we say “for all” x, do we mean all positive integers or all real numbers or
all elements of some other set? Usually this information is implied. In
discrete mathematics, we almost always quantify over the natural numbers,
0, 1, 2, . . . , so let’s take that for our domain of discourse here.
For the statement to be true, we need it to be the case that no matter
what natural number we select, there is always some natural number that
is strictly smaller. Perhaps we could let y be x − 1? But here is the problem:
what if x 0? Then y −1 and that is not a number! (in our domain
of discourse). Thus we see that the statement is false because there is a
number which is less than or equal to all other numbers. In symbols,
∃x∀y(y ≥ x).
To show that the original statement is false, we proved that the negation
was true. Notice how the negation and original statement compare. This
is typical.
Quantifiers and Negation.
Essentially, we can pass the negation symbol over a quantifier, but that
causes the quantifier to switch type. This should not be surprising: if
not everything has a property, then something doesn’t have that property.
And if there is not something with a property, then everything doesn’t
have that property.
Implicit Quantifiers.
It is always a good idea to be precise in mathematics. Sometimes though,
we can relax a little bit, as long as we all agree on a convention. An example
of such a convention is to assume that sentences containing predicates
with free variables are intended as statements, where the variables are
universally quantified.
For example, do you believe that if a shape is a square, then it is a
rectangle? But how can that be true if it is not a statement? To be a little
more precise, we have two predicates: S(x) standing for “x is a square”
0.2. Mathematical Statements 17
and R(x) standing for “x is a rectangle”. The sentence we are looking at is,
S(x) → R(x).
This is neither true nor false, as it is not a statement. But come on! We all
know that we meant to consider the statement,
∀x(S(x) → R(x)),
Exercises
1. For each sentence below, decide whether it is an atomic statement, a
molecular statement, or not a statement at all.
(a) Customers must wear shoes.
(b) The customers wore shoes.
(c) The customers wore shoes and they wore socks.
2. Classify each of the sentences below as an atomic statement, a molecular
statement, or not a statement at all. If the statement is molecular, say
what kind it is (conjunction, disjunction, conditional, biconditional,
negation).
(a) The sum of the first 100 odd positive integers.
(b) Everybody needs somebody sometime.
(c) The Broncos will win the Super Bowl or I’ll eat my hat.
(d) We can have donuts for dinner, but only if it rains.
(e) Every natural number greater than 1 is either prime or composite.
(f) This sentence is false.
3. Suppose P and Q are the statements: P: Jack passed math. Q: Jill
passed math.
(a) Translate “Jack and Jill both passed math” into symbols.
(b) Translate “If Jack passed math, then Jill did not” into symbols.
(c) Translate “P ∨ Q” into English.
(d) Translate “¬(P ∧ Q) → Q” into English.
18 0. Introduction and Preliminaries
(e) Suppose you know that if Jack passed math, then so did Jill.
What can you conclude if you know that:
7. Consider the statement, “If you will give me a cow, then I will give you
magic beans.” Decide whether each statement below is the converse,
the contrapositive, or neither.
(a) If you will give me a cow, then I will not give you magic beans.
(b) If I will not give you magic beans, then you will not give me a
cow.
(c) If I will give you magic beans, then you will give me a cow.
(d) If you will not give me a cow, then I will not give you magic
beans.
(e) You will give me a cow and I will not give you magic beans.
(f) If I will give you magic beans, then you will not give me a cow.
8. Consider the statement “If Oscar eats Chinese food, then he drinks
milk.”
(a) Write the converse of the statement.
(b) Write the contrapositive of the statement.
(c) Is it possible for the contrapositive to be false? If it was, what
would that tell you?
(d) Suppose the original statement is true, and that Oscar drinks
milk. Can you conclude anything (about his eating Chinese
food)? Explain.
(e) Suppose the original statement is true, and that Oscar does
not drink milk. Can you conclude anything (about his eating
Chinese food)? Explain.
9. You have discovered an old paper on graph theory that discusses the
viscosity of a graph (which for all you know, is something completely
made up by the author). A theorem in the paper claims that “if a
graph satisfies condition (V), then the graph is viscous.” Which of
the following are equivalent ways of stating this claim? Which are
equivalent to the converse of the claim?
(a) A graph is viscous only if it satisfies condition (V).
(b) A graph is viscous if it satisfies condition (V).
(c) For a graph to be viscous, it is necessary that it satisfies condition
(V).
(d) For a graph to be viscous, it is sufficient for it to satisfy condition
(V).
20 0. Introduction and Preliminaries
(b) Write the negation of the original statement. What would you
need to show to prove that the statement is false?
(c) Even though you don’t know whether 10 is solitary (in fact,
nobody knows this), is the statement “if 10 is prime, then 10 is
solitary” true or false? Explain.
(d) It turns out that 8 is solitary. Does this tell you anything about
the truth or falsity of the original statement, its converse or its
contrapositive? Explain.
(e) Assuming that the original statement is true, what can you say
about the relationship between the set P of prime numbers and
the set S of solitary numbers. Explain.
24 0. Introduction and Preliminaries
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 an 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,
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}.
4. {x : x ∈ N ∧ −x ∈ N}.
26 0. Introduction and Preliminaries
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 numbers.
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!
1. Find the cardinality of each set below.
(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
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.
Having notation like this is useful. We will often want to add or remove
elements from sets, and our notation allows us to do so precisely.
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
represents 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
A B
C
Notice that the shaded regions above could also be arrived at in another
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
x 1 2 3 4
h(x) 3 6 9 12
Here the domain is the finite set {1, 2, 3, 4} and to codomain
is the set of natural numbers, N. At first you might think this
40 0. Introduction and Preliminaries
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. Switch-
ing the domain and codomain sets doesn’t help either, since
some phone numbers belong to multiple people (assuming
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
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 .
if x 3
x
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
1 2 3 4 1 2 3 4
f g .
d a c b d a a b
It might also be helpful to think about how you would write the
two-line notation for h. We would have something like:
1 2 3 4
h .
a, c? d b
There is nothing under 1 (bad) and we needed to put more than one
thing under 2 (very bad). With a rule that is actually a function, the
two-line notation will always “work”.
0.4. Functions 43
x 0 1 2 3 4 5 ...
f (x) 0 1 4 9 16 25 ...
Have I given you enough entries for you to be able to determine f (6)?
You might guess that f (6) 36, but there is no way for you to know this for
sure. Maybe I am being a jerk and intended f (6) 42. In fact, for every
natural number n, there is a function that agrees with the table above, but
for which f (6) n.
Okay, suppose I really did mean for f (6) 36, and in fact, for the rule
that you think is governing the function to actually be the rule. Then
I should say what that rule is. f (n) n 2 . Now there is no confusion
possible.
Giving an explicit formula that calculates the image of any element in
the domain is a great way to describe a function. We will say that these
explicit rules are closed formulas for the function.
There is another very useful way to describe functions whose domain
is N, that rely specifically on the structure of the natural numbers. We can
define a function recursively!
Example 0.4.4
f (6) f (5) + 11 25 + 11 36
Example 0.4.5
Solution.
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.
Be careful: “surjective” and “injective” are NOT opposites. You can see
in the two examples above that there are functions which are surjective but
not injective, injective but not surjective, both, or neither. In the case when
a function is both one-to-one and onto (an injection and surjection), we
say the function is a bijection, or that the function is a bijective function.
To illustrate the contrast between these two properties, consider a more
formal definition of each, side by side.
Injective vs Surjective.
A function is injective provided every element of the codomain is
the image of at most one element from the domain.
A function is surjective provided every element of the codomain
is the image of at least one element from the domain.
or might not have repeats. The bijective functions are those that do not
have repeats and do not miss elements.
Example 0.4.8
1 2 3 4 5 6
f .
a a b b b c
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
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.
1 2 3 4
f .
2 1 3 1
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 5
(b) f .
2 3 1 5 4
(c) f (x) 6 − x.
(
x/2 if x is even
(d) f (x) .
(x + 1)/2 if x is odd
1 2 3 4 5
(b) f .
1 2 3 1 2
(
x if x ≤ 3
(c) f (x) .
x−3 if x > 3
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
cycling 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.
(c) f : Z → Z given by f (n) 5n − 8.
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
(
n/2 if n is even
(d) f : Z → Z given by f (n)
(n + 1)/2 if n is odd.
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.
(c) If one or both of the above do not always hold, is there something
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.