1.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 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.
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:
| 0 | 1 | 2 | 3 | 4 | |
|---|---|---|---|---|---|
| 3 | 3 | 2 | 4 | 1 |
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.
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!
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.
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.
In pictures:
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.
In pictures:
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.
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.
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).
Since is a set, it makes sense to ask for , the number of elements in the domain which map to .
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 .
Consider the function given by the table below:
| 1 | 2 | 3 | 4 | 5 | |
|---|---|---|---|---|---|
| 3 | 2 | 4 | 1 | 2 |
- Is injective? Explain.
- Is surjective? Explain.
- Write the function using two-line notation.
- is not injective, since ; two different inputs have the same output.
- is surjective, since every element of the codomain is an element of the range.
- .
Consider the function given by the graph below.
- Is injective? Explain.
- Is surjective? Explain.
- Write the function using two-line notation.
Suppose satisfies the recurrence relation
. Note that with the initial condition , the values of the function are: , , , , and so on, the images cycling through those three numbers. Thus is NOT injective (and also certainly not surjective). Might it be under other initial conditions?1
- If satisfies the initial condition , is injective? Explain why or give a specific example of two elements from the domain with the same image.
- If satisfies the initial condition , is injective? Explain why or give a specific example of two elements from the domain with the same image.
- If satisfies the initial condition , then it turns out that and no two numbers less than 105 have the same image. Could be injective? Explain.
- Prove that no matter what initial condition you choose, the function cannot be surjective.
For each function given below, determine whether or not the function is injective and whether or not the function is surjective.
- given by .
- given by .
- given by .
- given by
- is injective, but not surjective (since 0, for example, is never an output).
- is injective and surjective. Unlike in the previous question, every integers is an output (of the integer 4 less than it).
- is injective, but not surjective (10 is not 8 less than a multiple of 5, for example).
- is not injective, but is surjective. Every integer is an output (of twice itself, for example) but some integers are outputs of more than one input: .
Let . Consider the function given by . That is, takes a subset of as an input and outputs the cardinality of that set.
- Is injective? Prove your answer.
- Is surjective? Prove your answer.
- Find .
- Find .
- Find .
- is not injective. To prove this, we must simply find two different elements of the domain which map to the same element of the codomain. Since and , we see that is not injective.
- is not surjective. The largest subset of is itself, and . So no natural number greater than 10 will ever be an output.
- (the set of all the singleton subsets of ).
- . Note, it would be wrong to write - that would claim that there is no input which has 0 as an output.
- , since there are no subsets of with cardinality 12.
Consider the set , the set of all ordered pairs where and are natural numbers. Consider a function given by .
- Let . Find .
- Find and .
- Give geometric descriptions of and for any .
- Find and .
Let be some function. Suppose . What can you say about if you know,
- is injective? Explain.
- is surjective? Explain.
- is bijective? Explain.
- . In other words, either is the empty set or is a set containing exactly one element. Injective functions cannot have two elements from the domain both map to 3.
- . In other words, is a set containing at least one elements, possibly more. Surjective functions must have something map to 3.
- . There is exactly one element from which gets mapped to 3, so is the set containing that one element.
Find a set and a function so that .
can really be any set, as long as or for every . For example, and works.
What can you deduce about the sets and if you know,
- there is an injective function ? Explain.
- there is a surjective function ? Explain.
- there is a bijective function ? Explain.
Suppose is a function. Which of the following are possible? Explain.
- is injective but not surjective.
- is surjective but not injective.
- and is injective but not surjective.
- and is surjective but not injective.
- , and are finite, and is injective but not surjective.
- , and are finite, and is surjective but not injective.
Let and be functions. We can define the composition of and to be the function for which the image of each is . That is, plug into , then plug the result into (just like composition in algebra and calculus).
- If and are both injective, must be injective? Explain.
- If and are both surjective, must be surjective? Explain.
- Suppose is injective. What, if anything, can you say about and ? Explain.
- Suppose is surjective. What, if anything, can you say about and ? Explain.
Work with some examples. What if and ?
Consider the function given by
- Is injective? Prove your answer.
- Is surjective? Prove your answer.
- is injective.
- is surjective.
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?
Yes, this is a function, if you choose the domain and codomain correctly. The domain will be the set of students, and the codomain will be the set of possible grades. The function is almost certainly not injective, because it is likely that two students will get the same grade. The function might be surjective – it will be if there is at least one student who gets each grade.
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?
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?
This is not a function.
Consider the function that gives the number of handshakes that take place in a room of people assuming everyone shakes hands with everyone else. Give a recursive definition for this function.
To find the recurrence relation, consider how many new handshakes occur when person enters the room.
The recurrence relation is .
Let be a function and be a finite subset of the domain. What can you say about the relationship between and ? Consider both the general case and what happens when you know is injective, surjective, or bijective.
In general, , since you cannot get more outputs than you have inputs (each input goes to exactly one output), but you could have fewer outputs if the function is not injective. If the function is injective, then , although you can have equality even if is not injective (it must be injective restricted to ).
Let be a function and be a finite subset of the codomain. What can you say about the relationship between and ? Consider both the general case and what happens when you know is injective, surjective, or bijective.
In general, there is no relationship between and . This is because might contain elements that are not in the range of , so we might even have . On the other hand, there might be lots of elements from the domain that all get sent to a few elements in , making larger than .
More specifically, if is injective, then (since every element in must come from at most one element from the domain). If is surjective, then (since every element in must come from at least one element of the domain). Thus if is bijective then .
Let be a function, and .
- Is ? Always, sometimes, never? Explain.
- Is ? Always, sometimes, never? Explain.
- 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.
Let be a function and be subsets of the domain.
- Is ? Always, sometimes, or never? Explain.
- Is ? Always, sometimes, or never? Explain.
One of these is not always true. Try some examples!
Let be a function and be subsets of the codomain.
- Is ? Always, sometimes, or never? Explain.
- Is ? Always, sometimes, or never? Explain.
Discrete Mathematics: An Open Introduction, 3rd edition, by Oscar Levin (discrete.openmathbooks.org), licensed under CC BY-SA 4.0; this adaptation is distributed under the same license. License: CC-BY-SA-4.0.