A function assigns to each element of one set exactly one element of another. Almost every mathematical construction uses them: sequences are functions, so are the operations of arithmetic, and the structure-preserving maps of algebra and geometry are functions with extra properties. Functions are also how sets are compared, since a function that pairs off the elements of two sets shows that they have the same size.
This topic gives the formal definition, the standard ways of building and combining functions, how functions act on subsets, and the properties of being injective, surjective and invertible.
Conventions
- means that is a function from to , and describes what it does to an element, as in . “Map” and “mapping” are synonyms for “function”.
- A function includes its codomain, so changing the codomain gives a different function. Some authors identify a function with its graph, and then a function has no definite codomain.
- is the image of a subset and is the preimage of a subset . The form is a common alternative, especially in set theory, because it avoids an ambiguity.
- The preimage is defined for every function, while the inverse function exists only for bijections.
- “Range” is avoided, because authors use it for either the codomain or the image. This topic says “codomain” or “image”.
- Injective, surjective and bijective are also called one-to-one, onto and one-to-one correspondence. “One-to-one” is the risky term, since it is sometimes misread as “bijective”.
- Composition is applied from right to left: . Some authors, particularly in algebra, write functions on the right and compose from left to right.
- Composition requires the codomain of to be the domain of . Many authors only require to be a subset of the domain of .
- is the set of all functions from to .
- Sets defines and using tuples, while here and products of families are sets of functions. So and , and likewise and , are identified rather than literally equal. In the same way, the notation that Sets mentions for is identified with .
- , which matches the number of functions .
- A characteristic function here is the indicator of a subset. In probability the term means something else, and “indicator function” is used for this one.
- , and intervals are as in Sets, with and in addition. Sets uses informally, and it is defined here. The indexed families described there as assignments are functions in the sense of this topic.
Builds on
Sets, in particular Cartesian products, double inclusion, indexed families and power sets. Informal familiarity with proof by induction.
What a function is
A function is often first met as a rule, such as “square the input”, or as a table listing an output for each input. What matters in both cases is the same: each allowed input has exactly one output. The set of pairs (input, output) records all of this, and gives a definition that does not depend on any rule being written down.
A function from a set to a set , written , consists of the sets and together with a subset such that for every there is exactly one with .
The set is the domain of , the set is its codomain, and is its graph. The unique with is the value of at , written .
The function given by has as its graph the parabola .
For and , the table , , describes the function with graph . Two inputs may share a value, and an element of the codomain, here , need not be a value at all.
Each input must have a value, and only one. Those are the two ways an attempted definition can fail.
- The rule does not define a function , since has no value. It does define a function .
- The rule does not define a function . It sends to , which is not in the codomain, so has no value in . It does define a function .
- “The with ” does not define a function , since would have both and as values.
- The unit circle is not the graph of a function . The input is paired with two values, and the input with none.
A rule that refers to a particular way of writing its input must give the same output for every way of writing that input. Such a rule is called well defined. For example, "" does not define a function , because would have both and as values.
Since a graph is determined by the values, a function is determined by its domain, its codomain and its values.
Functions and are equal if and only if they have the same domain , the same codomain, and for every .
A function consists of its domain, codomain and graph, so we must show that functions with the same domain and codomain have the same graph exactly when they have the same values. If the graphs are equal, then lies in the graph of , so by uniqueness of the value. If the values are equal, each graph is the set of pairs with , so the graphs are equal.
So as a function and as a function are different functions, even though they have the same values. The difference matters for surjectivity.
Some authors define a function to be just its graph, a set of pairs in which no two pairs have the same first entry. The domain can be recovered from such a set, but the codomain cannot. So with that definition, being surjective, which means that every element of the codomain is a value, only makes sense relative to a stated codomain.
For any set , the empty set is a subset of that vacuously satisfies the condition, so there is exactly one function . It is called the empty function, with the codomain understood from context. If , there is no function , since an element of would need a value.
Several familiar objects are functions under other names.
- A sequence in a set is a function , written with in place of .
- An -tuple in can be regarded as a function .
- A function on a product has a single input, the pair , but we write instead of and speak of a function of two variables. Addition of real numbers is a function .
An indexed family can be regarded as a function on whose value at is the set , for instance with codomain . The choice of codomain plays no role for families, as long as every is an element of it. It cannot be “the set of all sets”, because there is no such set.
is the set of all functions from to .
This is a set, because for fixed and a function is determined by its graph, and the graphs are elements of . The exponential notation is explained by the count of functions between finite sets.
Standard constructions
Some functions come up so often, in every part of mathematics, that they have names of their own.
The identity function on is with . A function is constant if there is some with for every .
If , the inclusion of in is the function given by . The restriction of to is the function given by . We also say that is an extension of .
The inclusion of in is not the identity on unless , because the codomains differ.
The projections of are the functions with and with .
An -tuple with can be regarded as a function on whose value at lies in . Read this way, a product no longer needs its factors to be listed in order, so it can have any index set.
Let be an indexed family of sets. Its product is the set of all functions with for every . We usually write for . For each , the projection is given by .
For , and , the product has six elements, one for each pair in . The product is the set of sequences of zeros and ones.
For , elements of the product correspond to -tuples, so it matches the Cartesian product of under this identification. When and every equals , the product is . If some is empty, the product is empty. The product of the empty family has exactly one element, the empty function.
For , the characteristic function of is the function with if and if . It is also called the indicator function, and is sometimes written .
Composition
Applying one function after another gives a new function, provided that the codomain of the first is the domain of the second.
For and , the composition of and is the function given by .
Note the order: applies first.
Let with and . Then and . These differ at , with values and , so . For functions between different sets, one of the two compositions may not even be defined.
For , and :
- ;
- and .
For (1), both sides have domain and codomain , and for each both have the value . So they are equal. For (2), each function has domain and codomain , and for each each has the value .
Because of (1), we can write without brackets.
Images and preimages
A function acts on single elements, but it also carries whole subsets of its domain to subsets of its codomain, and subsets of its codomain back to subsets of its domain.
Let and . The image of under is , a subset of . The set is the image of .
Let and . The preimage, or inverse image, of under is , a subset of . The preimage of a single element is called the fibre of over .
Let with . Then
- ;
- ;
- ;
- .
The notation uses the same parentheses as the value . This is ambiguous only when something is both an element and a subset of the domain. That is rare, but it can happen: if , then and , so could mean the value at the element or the image of the subset . Writing avoids the problem. The notation does not claim that an inverse function exists: it is defined for every .
Both operations respect inclusion.
Let . If , then . If , then .
If , then for some , so . If , then , so .
Membership in a preimage is a statement about a single value , so preimages interact perfectly with set operations.
Let , let be a family of subsets of , and let . Then:
- ;
- if , then ;
- .
For , each of the following is equivalent to the next: lies in the left side of (1); for some ; for some ; lies in the right side of (1). Statement (2) is the same with “for every ” in place of “for some ”. For (3), if and only if , which holds if and only if .
Images behave well with unions, but not with intersections, because different elements can have the same value.
Let and let be a family of subsets of . Then:
- ;
- if , then .
For (1), lies in the left side if and only if for some lying in some , which says exactly that for some . For (2), if with in every , then for every .
The inclusion in (2) can be strict. For on , let and . Then , while .
Images of complements are no better. For , we have and , and neither is a subset of the other.
Image and preimage are not inverse operations, though each comes close.
Let , and . Then:
- ;
- , and in particular .
For (1), if then , so .
For (2), an element of has the form with , so . Conversely, if , then for some , and because . So .
For on , the set has , and the set has .
For composites, images and preimages can be taken one function at a time.
For , , and , we have and .
An element of lies in if and only if it equals for some , and that says exactly that it lies in . For the second identity, if and only if , if and only if , if and only if .
Injective, surjective and bijective functions
The two features of a function that the definition leaves open are whether different inputs can share a value, and whether every element of the codomain is a value.
A function is injective if for all , implies . Equivalently, different elements have different values, or each fibre has at most one element.
A function is surjective if . That is, for every there is some with . Equivalently, each fibre has at least one element.
A function is bijective, or a bijection, if it is both injective and surjective. Equivalently, each fibre has exactly one element.
The words “injection” and “surjection” are also used. Every identity function is bijective, directly from these definitions.
To prove that is injective, assume and deduce . To prove that is surjective, take an arbitrary and find an with . For with : if then , and for any the number has .
Both properties depend on the sets involved as well as on the rule.
The rule gives four different functions:
- is neither injective nor surjective;
- is surjective but not injective;
- is injective but not surjective;
- is bijective.
More generally, any function becomes surjective when its codomain is replaced by , and an injective function then becomes a bijection .
Let and .
- If and are injective, then is injective.
- If and are surjective, then is surjective.
- If and are bijective, then is bijective.
- If is injective, then is injective.
- If is surjective, then is surjective.
For (1), if , then because is injective, and so because is injective.
For (2), take . Since is surjective, for some , and since is surjective, for some . Then .
Statement (3) combines (1) and (2).
For (4), if , then , so because is injective.
For (5), each equals for some , which is a value of at the element .
In (4), need not be injective, and in (5), need not be surjective. Let be the inclusion and let be constant. Then is bijective, but is not surjective and is not injective.
The inclusions and failures found for images and preimages come exactly from functions not being injective or surjective.
For , the following are equivalent:
- is injective;
- for every ;
- for all ;
- for every .
Also, the following are equivalent:
- is surjective;
- for every ;
- for every .
(1) implies (2): by the earlier proposition it is enough to show . If , then for some , and by injectivity.
(2) implies (1): if , then , so .
(1) implies (3): the inclusion holds in general. If , then with and . By injectivity , which then lies in , so .
(3) implies (1): if but , then and give and , contradicting (3).
(1) implies (4): let , so with . If also with , then by injectivity, a contradiction. So .
(4) implies (1): if but , take . Then , but , contradicting (4).
(5) and (6): by the earlier proposition. If this equals . Conversely, taking gives , so if (6) holds then .
(5) implies (7): let . By surjectivity for some , and because . So .
(7) implies (5): taking gives .
Inverses
An inverse undoes a function. Undoing can happen on one side only, and it is the one-sided versions that correspond to injectivity and surjectivity.
Let and . Then is a left inverse of if , and a right inverse of if . It is a two-sided inverse, or simply an inverse, if it is both.
Let . If has a left inverse, then is injective. Conversely, if is injective and , then has a left inverse.
If , then is injective, so is injective by part (4) of the theorem on composition.
Conversely, let be injective and choose some . Define as follows. If , let be the element with , which is unique by injectivity. If , let . Then for every .
The condition is needed: the empty function is injective, but if there is no function at all.
A function is surjective if and only if it has a right inverse.
If , then is surjective, so is surjective by part (5) of the theorem on composition.
Conversely, let be surjective. Each fibre is nonempty, so we can choose one element from it for each . Then for every .
The proof above makes one choice for each , possibly infinitely many at once. Justifying that requires the axiom of choice, which states that for any family of nonempty sets one element can be chosen from each. In terms of products, it says that the product of any family of nonempty sets is nonempty, since an element of the product is exactly such a choice. In fact, the statement that every surjection has a right inverse is equivalent to the axiom of choice. No such axiom is needed when is finite, or when there is an explicit way to pick, such as taking the least element of each fibre when .
One-sided inverses are generally not unique. On , let , and let , where is the greatest integer at most . Then , so is a left inverse of , and is a right inverse of .
Here is injective but not surjective, and is surjective but not injective. The function is another right inverse of . The function with for even and for odd is another left inverse of .
If a function has inverses on both sides, the choices disappear.
Let .
- If is a left inverse of and is a right inverse of , then .
- is bijective if and only if it has a two-sided inverse.
- A two-sided inverse of is unique when it exists. It is written .
For (1), by the composition laws,
For (2), if is bijective, then each has exactly one with . Define to be this . Then and for all and , so is a two-sided inverse, with no appeal to the axiom of choice. Conversely, a two-sided inverse is both a left and a right inverse, so is injective and surjective by the previous two theorems.
For (3), if and are both two-sided inverses, then by (1).
The function with is bijective, and solving for gives . The exponential function is bijective with inverse . On , the function is bijective with inverse .
When is bijective, the symbol has two meanings, the inverse function and the preimage. They agree: the preimage of under equals the image of under the function .
If and are bijective, then and are bijective, with and .
The equations and say that is a two-sided inverse of , so is bijective with inverse . Next, is bijective by part (3) of the theorem on composition, and by the composition laws,
and similarly . So is the two-sided inverse of .
The order reverses for the same reason as with socks and shoes: the last thing done is the first thing undone.
Functions between finite sets
Counting a set means pairing off its elements with , and such a pairing is a bijection. This makes precise the idea of size that Sets uses informally. Below, and . The first step is to show that a set cannot be counted in two ways with different results.
If there is an injective function , then .
We use induction on , for all at once. The case is immediate. Let be injective. Then , since must have a value. Let be the bijection of that exchanges and and fixes every other element (so is the identity if ). Then is injective and has value at , so it never takes the value on . Restricting it to and replacing the codomain by therefore gives an injective function . By the induction hypothesis , so .
A set is finite if there is a bijection for some . This , which is unique, is the size of , written . A set that is not finite is infinite.
If there are bijections and , then .
If and are such bijections, then and are bijections between and , so the lemma gives and .
The following basic facts about size can be proved from this definition, by induction where needed, and are used freely below:
- a subset of a finite set is finite;
- if and , then ;
- if is finite and there is a bijection , then is finite and ;
- the size of a disjoint union of finitely many finite sets is the sum of their sizes.
For finite sets, functions can be counted, and the conditions of being injective and surjective become statements about sizes. The starting point is that the fibres of a function divide up its domain.
For a function between finite sets,
Each element of lies in exactly one fibre, so is the disjoint union of the fibres, and its size is the sum of theirs.
The next two theorems follow from this equation.
Let be a function between finite sets, and let . If , then some fibre of has more than elements. In particular, if , then is not injective.
If every fibre had at most elements, then would give . The last statement is the case .
There is a matching statement for surjections. If is surjective, every term of is at least 1, so . Hence if , then is not surjective.
Among 13 people, two share a birth month. Among 100 people, at least 9 share a birth month, since . For , among any integers, two have the same remainder on division by , so their difference is divisible by .
Let be a function between finite sets with . Then is injective if and only if is surjective, and so each of these is equivalent to being bijective.
In , the sum has terms and equals . If is injective, every term is at most 1, and if is surjective, every term is at least 1. In either case the total can only equal if every term is exactly 1, which means that is bijective.
This fails for infinite sets: the functions and on are respectively injective but not surjective, and surjective but not injective. The same equation shows that a bijection between finite sets forces them to have the same size. Extending that idea, so that two possibly infinite sets have the same size when there is a bijection between them, is the starting point of the theory of cardinality.
Let and be finite with and .
- There are functions , so . Here .
- If , there are injective functions , with . If , there are none.
- If , there are bijections .
We use induction on for (1) and for the first claim of (2). For , the only function is the empty function, which is injective, and .
Now let , choose and let . A function is determined by its restriction to and its value , and these can be chosen independently. So there are functions.
If also , then is injective exactly when is injective and . Since is injective, has elements, so there are possible values of , for a total of injective functions.
The second claim of (2) is the pigeonhole principle. For (3), when the bijections are exactly the injections, and there are of them.
Surjections are harder to count, because whether a function is surjective depends on all of its values together. The number of surjective functions from a set of size to a set of size is , with . This follows from the general form of the inclusion-exclusion principle, and is not proved here.
Characteristic functions connect functions with subsets. They also explain why is another notation for the power set, with read as the two-element set .
For any set , the function given by is a bijection, with inverse given by .
For , the set is exactly . For , let . Then exactly when , and both functions take only the values and , so . The two functions are therefore inverses of each other.
Combined with the count of functions, this gives for a set with elements, a result proved directly in Sets.
Summary
- A function consists of a domain, a codomain and a graph with exactly one pair for each element of the domain. Two functions are equal when these all agree.
- The identity, inclusion and restriction, projections and characteristic functions are standard constructions, and is the set of functions from to .
- The product of a family consists of the functions on whose value at each lies in .
- Composition applies first. It is associative with identities but not commutative.
- The image is and the preimage is . Preimages preserve unions, intersections and complements. Images preserve unions, but only give an inclusion for intersections. The preimage of a single element is the fibre over .
- In general, and .
- Injective means different inputs have different values, surjective means every element of the codomain is a value, and bijective means both. Injectivity and surjectivity can be read off from images and preimages.
- Composites of injections are injective and of surjections are surjective. If is injective then is, and if is surjective then is.
- A function with a nonempty domain is injective exactly when it has a left inverse, and a function is surjective exactly when it has a right inverse, which needs the axiom of choice in general.
- A function is bijective exactly when it has a two-sided inverse, which is unique, and .
- A set is finite if there is a bijection from to it, and this is its size.
- For a function between finite sets, the sizes of the fibres add up to the size of the domain. By the pigeonhole principle, if then some fibre has more than elements, so there is no injection when . There is no surjection when . Between sets of equal finite size, injective, surjective and bijective are equivalent. From a set of size to a set of size there are functions, and injections if (none if ).
- Characteristic functions give a bijection between and .