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
to describe a function with name
domain
and codomain
This does not tell us
which function
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
defined by
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
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.
The following are all examples of functions:
defined by The domain and codomain are both the set of integers. However, the range is only the set of integer multiples of 3.
defined by and The domain is the set the codomain is the set and the range is the set Note that and are the same element of the codomain. This is okay since each element in the domain still has only one output.
-
defined by the table:
Here the domain is the finite set and to codomain is the set of natural numbers, At first you might think this function is the same as defined above. It is absolutely not. Even though the rule is the same, the domain and codomain are different, so these are two different functions.
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.
defined by The reason this is not a function is because not every input has an output. Where does send 3? The rule says that but is not an element of the codomain.
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 (assuming some households still have landlines when you are reading this).
Subsection 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
or a finite subset of
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
It would be absolutely WRONG to connect the dots or try to fit them to some curve. There are only three elements in the domain. A curve would mean that the domain contains an entire interval of real numbers.
Here is another way to represent that same function:
This shows that the function
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
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:
We simplify this further by writing this as a “matrix” with each input directly over its output:
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.
Which of the following diagrams represent a function? Let
and
Solution.
is a function. So is There is no problem with an element of the codomain not being the image of any input, and there is no problem with from the codomain being the image of both 2 and 3 from the domain. We could use our two-line notation to write these as
However, is NOT a function. In fact, it fails for two reasons. First, the element 1 from the domain has not been mapped to any element from the codomain. Second, the element 2 from the domain has been mapped to more than one element from the codomain ( and ). Note that either one of these problems is enough to make a rule not a function. In general, neither of the following mappings are functions:
It might also be helpful to think about how you would write the two-line notation for We would have something like:
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”.
We will also be interested in functions with domain
Here two-line notation is no good, but describing the function algebraically is often possible. Even tables are a little awkward, since they do not describe the function completely. For example, consider the function
given by the table below.
|
0 |
1 |
2 |
3 |
4 |
5 |
|
|
0 |
1 |
4 |
9 |
16 |
25 |
|
Have I given you enough entries for you to be able to determine
You might guess that
but there is no way for you to
know this for sure. Maybe I am being a jerk and intended
In fact, for every natural number
there is a function that agrees with the table above, but for which
Okay, suppose I really did mean for
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.
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
that rely specifically on the structure of the natural numbers. We can define a function
recursively!
Example 0.4.4.
Consider the function
given by
and
Find
Solution.
The rule says that (we are using so ). We don’t know what is though. Well, we know that So we need to compute which will require knowing which will require … will it ever end?
Yes! In fact, this process will always end because we have as our domain, so there is a least element. And we gave the value of explicitly, so we are good. In fact, we might decide to work up to instead of working down from
It looks that this recursively defined function is the same as the explicitly defined function Is it? Later we will prove that it is.
Recursively defined functions are often easier to create from a “real world” problem, because they describe how the values of the functions are changing. However, this comes with a price. It is harder to calculate the image of a single input, since you need to know the images of other (previous) elements in the domain.
Recursively Defined Functions.
For a function
a
recursive definition consists of an
initial condition together with a
recurrence relation. The initial condition is the explicitly given value of
The recurrence relation is a formula for
in terms for
(and possibly
itself).
Example 0.4.5.
Give recursive definitions for the functions described below.
gives the number of snails in your terrarium years after you built it, assuming you started with 3 snails and the number of snails doubles each year.
gives the number of push-ups you do days after you started your push-ups challenge, assuming you could do 7 push-ups on day 0 and you can do 2 more push-ups each day.
defined by Recall that is the product of all numbers from through We also define
Solution.
The initial condition is To get we would double the number of snails in the terrarium the previous year, which is given by Thus The full recursive definition contains both of these, and would be written,
We are told that on day 0 you can do 7 push-ups, so The number of push-ups you can do on day is 2 more than the number you can do on day which is given by Thus
Here To get the recurrence relation, think about how you can get from If you write out both of these as products, you see that is just like except you have one more term in the product, an extra So we have,
Subsection Surjections, Injections, and Bijections
We now turn to investigating special properties functions might or might not possess.
In the examples above, you may have noticed that sometimes there are elements of the codomain which are not in the range. When this sort of the thing
does not happen, (that is, when everything in the codomain is in the range) we say the function is
onto or that the function maps the domain
onto the codomain. This terminology should make sense: the function puts the domain (entirely) on top of the codomain. The fancy math term for an onto function is a
surjection, and we say that an onto function is a
surjective function.
Example 0.4.6.
Which functions are surjective (i.e., onto)?
defined by
defined by
-
defined as follows:
Solution.
is not surjective. There are elements in the codomain which are not in the range. For example, no gets mapped to the number 1 (the rule would say that would be sent to 1, but is not in the domain). In fact, the range of the function is (the integer multiples of 3), which is not equal to
is not surjective. There is no (the domain) for which so which is in the codomain, is not in the range. Notice that there is an element from the codomain “missing” from the bottom row of the matrix.
is surjective. Every element of the codomain is also in the range. Nothing in the codomain is missed.
To be a function, a rule cannot assign a single element of the domain to two or more different elements of the codomain. However, we have seen that the reverse
is permissible: a function might assign the same element of the codomain to two or more different elements of the domain. When this
does not occur (that is, when each element of the codomain is the image of at most one element of the domain) then we say the function is
one-to-one. Again, this terminology makes sense: we are sending at most one element from the domain to one element from the codomain. One input to one output. The fancy math term for a one-to-one function is an
injection. We call one-to-one functions
injective functions.
Example 0.4.7.
Which functions are injective (i.e., one-to-one)?
defined by
defined by
-
defined as follows:
Solution.
is injective. Each element in the codomain is assigned to at most one element from the domain. If is a multiple of three, then only is mapped to If is not a multiple of 3, then there is no input corresponding to the output
is not injective. Both inputs and are assigned the output Notice that there is an element from the codomain that appears more than once on the bottom row of the matrix.
is injective. Each output is only an output once.
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.
Notice both properties are determined by what happens to elements of the codomain: they could be repeated as images or they could be “missed” (not be images). Injective functions do not have repeats but might or might not miss elements. Surjective functions do not miss elements, but might or might not have repeats. The bijective functions are those that do not have repeats and do not miss elements.
Subsection Image and Inverse Image
When discussing functions, we have notation for talking about an element of the domain (say
) and its corresponding element in the codomain (we write
which
is the image of
). Sometimes we will want to talk about all the elements that are images of some subset of the domain. It would also be nice to start with some element of the codomain (say
) and talk about which element or elements (if any) from the domain it is the image of. We could write “those
in the domain such that
” but this is a lot of writing. Here is some notation to make our lives easier.
To address the first situation, what we are after is a way to describe the
set of images of elements in some subset of the domain. Suppose
is a function and that
is some subset of the domain (possibly all of it). We will use the notation
to denote the
image of under , namely the set of elements in
that are the image of elements from
That is,
We can do this in the other direction as well. We might ask which elements of the domain get mapped to a particular set in the codomain. Let
be a function and suppose
is a subset of the codomain. Then we will write
for the
inverse image of under , namely the set of elements in
whose image are elements in
In other words,
Often we are interested in the element(s) whose image is a particular element
of in the codomain. The notation above works:
is the set of all elements in the domain that
sends to
It makes sense to think of this as a set: there might not be anything sent to
(if
is not in the range), in which case
Or
might send multiple elements to
(if
is not injective). As a notational convenience, we usually drop the set braces around the
and write
instead for this set.
WARNING:
is not an inverse function! Inverse functions only exist for bijections, but
is defined for any function
The point:
is a
set, not an
element of the domain. This is just sloppy notation for
To help make this distinction, we would call
the
complete inverse image of under . It is not the image of
under
(since the function
might not exist).
Example 0.4.8.
Consider the function
given by
Solution.
since and are the elements in the codomain to which sends and
since these are exactly the elements that sends to and
since is not in the range of
Example 0.4.9.
Consider the function
defined by
Find
and
Then find
and
Solution.
Note that The first is an element: The second is a set:
To find we need to find all integers such that Clearly only 0 works, so (note that even though there is only one element, we still write it as a set with one element in it).
To find we need to find all such that We see
Finally, if then we are looking for an such that There are no such integers so
Since
is a set, it makes sense to ask for
the number of elements in the domain which map to
Example 0.4.10.
Find a function
such that
Solution.
There is only one such function. We need five elements of the domain to map to the number Since there are only five elements in the domain, all of them must map to 7. So
Function Definitions.
Here is a summary of all the main concepts and definitions we use when working with functions.
A function is a rule that assigns each element of a set, called the domain, to exactly one element of a second set, called the codomain.
Notation: is our way of saying that the function is called the domain is the set and the codomain is the set
To specify the rule for a function with small domain, use two-line notation by writing a matrix with each output directly below its corresponding input, as in:
means the element of the domain (input) is assigned to the element of the codomain. We say is an output. Alternatively, we call the image of under .
The range is a subset of the codomain. It is the set of all elements which are assigned to at least one element of the domain by the function. That is, the range is the set of all outputs.
A function is injective (an injection or one-to-one) if every element of the codomain is the image of at most one element from the domain.
A function is surjective (a surjection or onto) if every element of the codomain is the image of at least one element from the domain.
A bijection is a function which is both an injection and surjection. In other words, if every element of the codomain is the image of exactly one element from the domain.
The image of an element in the domain is the element in the codomain that is mapped to. That is, the image of under is
The complete inverse image of an element in the codomain, written is the set of all elements in the domain which are assigned to by the function.
The image of a subset of the domain is the set
The inverse image of a subset of the codomain is the set