Module 1 Discrete Math
Module 1 Discrete Math
Module 1 Discrete Math
COLLEGE DEPARTMENT
City of Kabankalan, Negros Occidental
IT 104: DISCRETE MATHEMATICS
LESSON 1
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):
Investigate!
While walking through a fictional forest, you encounter three trolls guarding a bridge
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.
Which troll is which?
Example
3 + 7 = 12
And these are not statements:
Would you like some cake?
The sum of two squares.
1 + 3 + 5 + 7 + · · · + 2n + 1.
Go to your room!
3 + x = 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, and R, S, We think of
these as standing in for (usually atomic) statements, but there are only two
values the variables can achieve: true or false.
Logical Connectives.
P ∧ Q is read “P and Q,” and called a conjunction.
P ∨ Q is read “P or Q,” and called a disjunction.
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 a2 + b2 = c2, 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 a2 + b2 = c2.”
Example
Example
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.
I have no idea what the 7624th digit of π is, but this does not matter. Since the hypothe
Similarly here, regardless of the truth value of the hypothesis, the conclusion is true, ma
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
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 = 2 j for some integers k and j. The sum is then
Example
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).
The converse: If you have at least three cards all of the same suit, then you have nine c
Example
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.
Solution. Note first that whenever P→Q and P are both true
statements, Q must be true as well. For this problem, take P to
mean “Sue gets a 93% on her final” and Q to mean “Sue will get
an A in the class.”
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
Suppose it is true that I sing if and only if I’m in the shower. We know this means bo
Example
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.
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
true (for example, f (x) = |x | at the point 0). Restate this fact using
“necessary and sufficient” language.
Thinking about the necessity and sufficiency of conditions can also help
when writingItproofs
Solution. is trueand
thatjustifying
in order for a function If
conclusions. toyou
be differentiable at a point c, it is ne
want to establish
It is true that to be continuous at a point c, it is sufficient that
some mathematical fact, it is helpful to think what other facts would be the function be differen
enough (be sufficient) to prove your fact. If you have an assumption, think
about what must also be necessary if that hypothesis is true.
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.
As with all mathematical statements, we would like to decide whether
quantified statements are true or false. Consider the statement
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.
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”
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)),
and this is what our convention tells us to consider.
Similarly, we will often be a bit sloppy about the distinction
between a predicate and a statement. For example, we might write,
( ) let P
n be the statement, “n is prime,” which is technically incorrect. It is
implicit that we mean that we are
( )defining P n to be a predicate, which
for each n becomes the statement, n is prime.
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.
(e) Suppose you know that if Jack passed math, then so did Jill.
What can you conclude if you know that:
6. Again, suppose the statement “if the square is blue, then the
triangle is green” is true. This time however, assume the converse is
false. Classify each statement below as true or false (if possible).
(a) The square is blue if and only if the triangle is green.
(b) The square is blue if and only if the triangle is not green.
(c) The square is blue.
(d) The triangle is green.
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).
Lesson 4: 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}.
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 g {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,
A = {0, 2, 4, 6, . . .},
A = {x ∈ N : x is even}.
Note: Sometimes mathematicians use or э for the “such that” symbol
|
instead of the colon. Also, there is a fairly even split between
mathemati- cians about whether 0 is an element of the natural numbers,
so be careful there.
This notation is usually called set builder notation. It tells us how
to build a set by telling us precisely the condition elements must meet to
gain access (the condition is the logical statement after the “:” symbol).
Reading and comprehending sets written in this way takes practice. Here
are some more examples:
Example
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}.
Solution.
1. This is the set of all numbers which are 3 less than a natural number (i.e., that if
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 : x2 ∈ N}
2. B = {x2 : 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 x2s 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 = n2 for some n ∈ N}.
We already have a lot of notation, and there is more yet. Below is a
handy chart of symbols. Some of these will be discussed in greater
detail as we move forward.
Special sets.
∅ The empty set is the set which contains no elements. The universe set is the
The set of natural numbers. That is, N = {0, 1, 2, 3 . . .}. The set of integers. T
U
The set of real numbers.
NZQ
R
P(A) The power set of any set A is the set of all subsets of A.
|A ∪ B| = 9. What is |A ∩ B|?
We have already said what it means for two sets to be equal: they have
exactly the same elements. Thus, for example,
(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).
{ 2, 3, 4 } ? Clearly A ≠ B,
What about the sets A = {1, 2, 3 } and B = 1,
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 ≤.
Example
1. A ⊂ B.
2. B ⊂ A.
3. B ∈ C.
Solution.
Let A = {1, 2, 3, 4, 5, 6 }, B = {2, 4, 6 }, C = {1, 2, 3 } and D = {7, 8, 9 }.
Determine which of the following are true, false, or meaningless.
1. A ⊂ 4. ∅ ∈ A. 7. 3 ∈ C.
B. 5. ∅ ⊂ A. 8. 3 ⊂ C.
2. B ⊂ 6. A < D. 9. {3} ⊂ C.
A.
3. B ∈ C.
Solution.
Example 0.3.4
P(A) = {∅, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}.
Notice that while 2 ∈A, it is wrong to write 2 ∈ P(A) since none
of the elements in P(A) are numbers! On the other hand, we do
have {2} ∈ P(A) because {2} ⊆ A.
What does a subset of P(A) look like? Notice that {2} ¢ P(A)
because not everything in {2} is in P(A). But we do have {{2}} ⊆
P(A). The only element of {{2}} is the set {2} which is also an
element of P(A). We could take the collection of all subsets of P(A)
and call that P(P(A)). Or even the power set of that set of sets of
sets.
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
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,
B =A
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
x ∈A∪B ⇔ x ∈ A ∨ x ∈ B.
Similarly,
x ∈A∩B ⇔ x ∈A∧x ∈
Also,
B. 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
also represent cardinality of a particular set by putting the number in
the corresponding region.
AB 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:
AB
AB
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. Th at region is ( A ∩ C) ∩ B. So the
above
Venn diagram also represents C ∩ (
.we have determined that A ∩ C) ∩ B
(B ∩ C) ∪ (C ∩ A) = C ∩ (A ∩ C) ∩ B .
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 : n2 − 3 ≥ 2}.
(b) {n ∈ N : n2 − 5 ∈ N}.
(c) {n2 + 1 : n ∈ N}.
(d) {n ∈ N : n = k2 + 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}.
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) = x2 + 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
0.4. FUnctIons
function is the same as f defined above. It is absolutely not. Even though the rule is th
Example 0.4.2
Just because you can describe a rule in the same way you would write a function, do
1.
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
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
= 3 3 2 4 1 .
f
0.4. FUnctIons
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 b c a c a c
b b d
d d
1 2 3 4 1 2 3 4
f = d a c g= d a a .
b 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
= a, c? d b .
h
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
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) = n2. 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
Solution.
1. f is not surjective. There are elements in the codomain which
Example 0.4.7
123
2. g : {1, 2, 3} → {a, b, c} defined by g = caa .
1 2
Solution.
1. f is injective. Each element in the codomain is assigned to at
most one element from the domain. If x is a multiple of three,
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 on
A function is surjective provided every element of the codomain is the image of at least
or might not have repeats. The bijective functions are those that do not
have repeats and do not miss elements.
set.
−
WARNING: f 1(y )is not an inverse function! Inverse functions only
−
exist for bijections, but f 1( y) is defined for any function f . The point:
f 1(y )is a set, not an element of the domain. This is just sloppy notation
−
for f 1({y }). To help make this distinction, we would call f 1( y) the
− −
−
complete inverse image of y under f . It is not the image of y under f 1
−
(since the function f 1 might not exist).
0.4. FUnctIons
Example 0.4.8
123456
f = aabbbc .
Example 0.4.9
− −. ( ). number of
Since f 1 y( is) a set, it makes sense to ask for f 1 y , the
elements in the domain which map to y.
Example 0.4.10
. f −1 .
Find a function f : {1, 2, 3, 4, 5} → N such that (7) = 5.
1 2 3 4 5
f = 7 7 7 7 7.
0.4. FUnctIons
Function Definitions.
Here is a summary of all the main concepts and definitions we use
when working with functions.
1 2 3 4
= 2 1 3 1 .
f
Exercises
1. Consider the function f : {1, 2, 3, 4} → {1, 2, 3, 4} given by
41 21 33 44
f (n) = .
1 2 3 4
(b) = .
1 2 3f 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?
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.
0.4. FUnctIons
( /
n 2 if n is even
(d) f : Z Z given by f ( n) =
→
(n + 1)/2 if n is odd.
13. Let A = {1, 2, 3, . . . , 10} . Consider the function f : P( A) → N given
by f (B ) = |B |. That is, f takes a subset of A as an input and outputs
the cardinality of that set.
(a) Is f injective? Prove your answer.
(b) Is f surjective? Prove your answer.
−1
(c) Find f (1).
−1
(d) Find f (0).
−1
(e) Find f (12).
14. Let X = {n ∈N : 0 ≤ n ≤ 999} be the set of all numbers with three
or fewer digits. Define the function f : X→N by f abc( = a + b + c,
where a, b, and c are the digits of the number in X) (write numbers
less than 100 with leading 0’s to make them three digits). For example,
f (253) = 2 + 5 + 3 = 10.
(a) Let A = {n ∈ X : 113 ≤ n ≤ 122}. Find f (A).
−1
(b) Find f ({1, 2})
−1
(c) Find f (3).
−1
(d) Find f (28).
(e) Is f injective? Explain.
(f) Is f surjective? Explain.
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).
−1 −1
(b) Find f (3) and f ({0, 1, 2, 3}).
− −1
(c) Give geometric descriptions of f 1(n) and f ({0, 1, . . . , n}) for
any n ≥ 1.
. − . . − .
(d) Find f 1(8) and f 1({0, 1, . . . , 8}) .
n−3 if n is odd.
(a) Is f injective? Prove your answer.
(b) Is f surjective? Prove your answer.
22. At the end of the semester a teacher assigns letter grades to each of
her students. Is this a function? If so, what sets make up the domain
and codomain, and is the function injective, surjective, bijective, or
neither?
0.4. FUnctIons
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.