Squaring a number, reflecting a point and seating each guest at a table are all processes that turn one thing into another, and a proof about any of them needs to know exactly what such a process is and when it can be undone.
The previous lesson made collections precise as sets, with subsets, the Cartesian product of ordered pairs, and the habit of proving two sets equal by showing each contains the other. A set on its own does nothing, though. This lesson builds processes out of sets, assuming only the lesson on sets, the quantifiers, and the direct, contrapositive and inductive proofs before it. As throughout the course, starts at .
What a function is
Let and be sets. A function is a rule that assigns to each element of exactly one element of , written and called the value of at , or the image of . The set is the domain of and is its codomain. The words map and mapping mean the same as function. A rule given by a formula is often written with a barred arrow, as in , read " goes to ", and the whole function as ", ".
"Rule" is informal: it suggests a formula or a procedure, and neither is needed. The previous lesson supplies the formal version.
Definition. A function from to consists of the sets and together with a subset of with the property that for every there is exactly one with . The set is the graph of the function, and names the unique with .
So a function is its table of values, nothing more: a list of pairs (input, output) in which every input appears exactly once. A seating plan that puts each of five guests at one of two tables is a function from the set of guests to the set of tables, as much as is a function from to , and neither is "more" of a function for having a formula. Written out, the condition on is the conjunction of two quantified statements:
The first says every element of the domain receives a value; the second says none receives two. A proposed function can fail either, and checking that a rule defines a function means checking both. The second is often called checking that is well defined, a phrase the next lesson meets again in a sharper form.
The rule "send to a real number whose square is " fails both as a function from to : at there is no such number, and at there are two. The square root repairs both by shrinking the domain to and choosing the non-negative root, a convention rather than a discovery. A rule can also fail the second condition in disguise. "Send the fraction to " looks like a function from to , but , and the rule sends that one rational number to through one name and to through the other. Whenever an input can be named in more than one way and the rule reads the name, the second condition needs a proof.
Two functions are equal when they have the same domain, the same codomain, and the same value at every element of the domain; equivalently, the same domain, codomain and graph. So and on are one function written two ways, and to prove two functions equal, let be arbitrary and show .
A few functions appear so often that they have names. The identity on a set is , , whose graph is the diagonal . If , the inclusion is ; it has the same graph as but a different codomain, and the next section explains why that makes it a different function. A constant function sends every element to one fixed . The projections , , and , , pick out a coordinate.
Two more are functions in disguise. A sequence of real numbers is a function , with written for its value at , and the sequences of the course's last lesson, on limits, are functions in exactly this sense. For , the characteristic function is on and off it. It records the subset as a function, and Problem 10 shows that subsets of and functions correspond exactly.
Functions of several variables need no new definition. Addition of real numbers is a function , , whose domain happens to be a product, and is shorthand for .
Is a function really just a set of pairs?
It took mathematics about a century to say yes. For Leonhard Euler, in his Introductio in analysin infinitorum of 1748, a function of a variable was an analytic expression built from the variable and constants: a formula. That view came under strain from Fourier series. Joseph Fourier claimed in the early nineteenth century that quite arbitrary functions, including ones given by different formulas on different intervals, could be written as sums of sines and cosines, and mathematicians had to decide whether such a sum, or a curve drawn freehand, was "one function".
Peter Gustav Lejeune Dirichlet settled the matter in the direction this lesson takes. In a paper of 1837 on Fourier series he said, in substance, that is a function of when to each in an interval there corresponds a definite , whether or not a single law connects them. His famous example, from 1829, is the function on that is at every rational number and at every irrational one: it has no graph anyone can draw and no formula of the kind Euler meant, and it is a perfectly good function. The fully set-theoretic version, a function as a set of ordered pairs with the "exactly one" condition, became standard in the twentieth century along with the set theory of the previous lesson.
There is one wrinkle, and it is why the definition above says "the sets and together with" a graph rather than "a graph". The graph determines the domain, which is the set of first coordinates, but it does not determine the codomain: the graph of on is the same set of pairs whether the codomain is or . Some books define a function to be its graph alone and treat the codomain as extra information; most modern ones, and this course, make the codomain part of the function, because the property of being surjective depends on it. The two conventions describe the same mathematics and differ only in bookkeeping.
The ordered pair itself can be defined from sets. Kazimierz Kuratowski's definition of 1921, , has the one property pairs need, that exactly when and . With it, functions, relations and products are all sets, and set theory can serve as the foundation for the whole of mathematics.
Why the codomain is part of the function
Take the rule with two codomains: and , with . They have the same set of pairs, yet they answer one question differently: is every element of the codomain a value? For it is, since each equals (square roots exist, as the lesson on the real numbers proves). For it is not, since no real number squares to .
That question decides, later in this lesson, whether a function can be undone: an inverse of would have to send somewhere, and there is nowhere to send it. That is why the codomain is recorded as part of the function, why and count as different, and why " is surjective" is neither true nor false until the codomain is named.
The values a function actually takes form its range, , a subset of the codomain. For and alike it is . The codomain is where values may land; the range is where they do. Many books call the range the image of and write it , a notation the next section explains. Beware that some older books use "range" for the codomain; when a text's usage matters, check its definition.
The codomain can always be shrunk to the range, or to any set containing it, and the codomain can always be enlarged: if and , the same graph defines a function . Shrinking the codomain of to produced . Enlarging a codomain can destroy surjectivity but never create it, and it never changes whether the function is injective (both notions are defined below).
The domain is less flexible. A formula such as does not come with a domain, and "the function " is incomplete until one is chosen. Calculus usually takes the largest set of reals on which the formula makes sense, here , and calls it the natural domain, but that is a convention, and a proof must say which domain it means. A statement as simple as " is decreasing" is false on (since and ) and true on .
Image and preimage
A function acts on elements, and through them on sets of elements. For and , the image of is
the set of values taken on . For , the preimage (or inverse image) of is
the set of inputs that land in . The range is the image of the whole domain, . The notation carries two traps. First, uses the same brackets as with a set in place of an element: is a set with one element, not the element . Second, is a set, and it exists for every function, whether or not has an inverse. The preimage of a single element is written for and is called the fibre of over ; it may be empty, or have one element, or many.
Membership in each is a statement with a quantifier, and proofs use it in that form. For the image the quantifier is existential: exactly when there is with . For the preimage there is none: exactly when and . That difference, an "exists" hidden in one definition and absent from the other, explains almost everything in the next section.
With on , the image of is . Squares of numbers in lie between and , and each in is the square of , so both inclusions hold. The preimage of is , since negative inputs count too, and the preimage of is .
Computing an image is a small existence proof, and it is easy to get half of it. The claim is an equality of sets, so it needs double inclusion: that every value on lies in , and that every element of is actually reached. The first half alone would equally "prove" . A preimage computation is an "if and only if": exactly when , exactly when .
A round trip need not return where it started: the preimage of under is , whose image is , strictly smaller than . One inclusion always holds, though.
Example. Let and . Prove that .
Let . By the definition of image, for some . By the definition of preimage, means . So , and since was arbitrary, the inclusion holds.
The reverse fails for because is not a value at all. In general , exactly the part of that reaches, so equality holds for every precisely when every element of is a value (Problem 6).
Now you. Let and . Prove that , and find a set for which the inclusion is strict when .
Answer
Let . Then is the value of at an element of , so by the definition of image. By the definition of preimage, an element of whose value lies in belongs to , so . Hence . For strictness take : then and , which contains . The round trip collects every input that shares a value with something in .
Images, preimages and the set operations
Unions, intersections and complements are the tools of the previous lesson, and a first question about any new operation on sets is which of them it respects. For preimages the answer is all of them. For images it is only some, and knowing which is part of knowing what a function is.
Theorem. Let , let and let . Then:
(i) ;
(ii) ;
(iii) ;
(iv) ;
(v) , and the inclusion can be strict.
Proof. Parts (i) to (iii) are chains of equivalences, each step reversible, so each gives both inclusions at once. For (i), for every :
using the definition of preimage, then of union, then of preimage and union again. Part (ii) is the same chain with and in place of and . For (iii), for every , if and only if , if and only if (since automatically), if and only if , which for means .
For (iv), double inclusion. Let , so for some . If then , and if then ; either way . Conversely, let . If , then for some , and , so ; the case is the same with the indices exchanged.
Part (v) is the Example below.
The proofs of (i) to (iii) never needed cases: "" translates directly into "", and the set operation passes straight through. The same argument works for any family of sets, finite or not. If for each in an index set , then
and likewise the image of a union of any family is the union of the images. Both images and preimages also respect inclusion: if then , and if then . The proofs are one line each.
Example. Let and . Prove that , and show that equality can fail.
Let . Then for some . Since , , and since , . So , and as was arbitrary the inclusion holds.
For the failure, take on , and . Then , so , while and .
The attempted proof of the reverse inclusion shows exactly where it breaks. Let . Then for some , and for some . To finish we need one element of with value , and all we have is two elements, one in each set, with the same value. If never sends two different elements to the same value, then and the proof goes through; that property is injectivity, defined in the next section, and Problem 5 proves that it is exactly what equality in (v) for all and requires.
Now you. Let and . Prove that , and give an example where the inclusion is strict.
Answer
Let . Then , so for some , and . If were in , then would lie in , which it does not; so . Hence and .
For strictness take on , and . Then and , while . The element survives the difference, but its value is shared with the removed element .
Taking in the Now you, and writing for , gives : the image of a complement contains the part of the range outside , and that is all that can be said in general. The image of a complement need not be inside the complement of the image either. With and , the image of is , while , and these two sets are disjoint.
Why does the preimage respect every set operation when the image does not?
Look at the two definitions side by side. Membership in a preimage, , is the statement , with no quantifier. Membership in an image, , is the statement , with an existential quantifier. Every set operation is a connective in disguise (union is "or", intersection is "and", complement is "not"), so the question is which connectives pass through each definition.
With no quantifier in the way, all of them pass through the preimage: "" is literally " and ". The image has to move the connective past "there exists", and the lesson on quantifiers showed which moves are allowed. The existential quantifier distributes over "or": is equivalent to , and that is part (iv). It does not distribute over "and": implies , but not conversely, since the two witnesses on the right may be different objects. That is part (v), and the counterexample with and is exactly two different witnesses. Negation fails worst of all, because "not exists" is "for all not", a different kind of statement.
This is more than bookkeeping. The preimage turns into a function , , which runs backwards and preserves unions, intersections and complements: in the language of algebra it is a homomorphism of Boolean algebras. Much of later mathematics is built on it. In topology a function between spaces is defined to be continuous when the preimage of every open set is open, and in measure theory a function is measurable when preimages of measurable sets are measurable. Both definitions use preimages rather than images for the reason given here: conditions stated through preimages are automatically compatible with unions, intersections and complements, so they combine well. For functions on , the preimage definition of continuity turns out to be equivalent to the , definition met in the course's last lesson.
Injective, surjective and bijective
A function is injective, or one-to-one, when distinct inputs give distinct outputs: for all , if then . The useful form is the contrapositive: for all , if then . The proof template is "Let with ", then algebra, then "so ". To disprove it, one pair suffices: and .
A classic slip is to prove the converse, "if then ". That is true of every function, since it is the "none receives two values" half of the definition, so a proof of it says nothing about injectivity.
It is surjective, or onto, when every element of the codomain is a value: for every there exists with . Equivalently, the range is all of . The template follows the quantifiers: "Let . Put ", then check that and . The formula for comes from scratch work solving , which is not part of the proof; the check that lies in the domain is, and it is the step most often forgotten. To disprove it, name one and prove that has no solution in .
It is bijective, a bijection or a one-to-one correspondence, when it is both, so that each is the value of exactly one . The three properties have a compact description through fibres. For each , the fibre is the set of inputs with value . Then is injective when every fibre has at most one element, surjective when every fibre has at least one, and bijective when every fibre has exactly one. For a function on drawn as a graph, the fibre over is where the horizontal line at height meets the graph, which is the "horizontal line test" of school.
The properties are independent. The map , , is injective, since gives , but not surjective, since forces . With the even natural numbers as codomain, the same rule is a bijection. The function , , is surjective and not injective, and is neither. The identity on any set is a bijection.
Example. Prove that , , is a bijection.
Injective: let with . Then , so , and dividing by gives . Surjective: let and put . This is a real number, and . So is injective and surjective, hence a bijection.
On the integers the same rule, from to , is injective by the same argument but not surjective: needs , not an integer. The membership check is exactly where the two cases part.
Now you. Let be given by . Show that never takes the value , so that it is a function into , and prove that it is a bijection.
Answer
Values: would give , which is false. Injective: let with . Clearing denominators, , so . Surjective: let and put , defined since . It is not , since would give . And
So is a bijection. Both excluded points were forced: because the formula fails there, because it is never reached.
For functions between sets of real numbers, one sufficient condition for injectivity is used constantly. A function with is strictly increasing if implies for all , and strictly decreasing if implies .
Proposition. A strictly increasing or strictly decreasing function on a set of real numbers is injective.
Proof. Let be strictly increasing, and let be in its domain. The statement is symmetric in and , so without loss of generality . Then , so . The decreasing case is the same with the inequality reversed.
So is injective on : if then , and the second factor is , which is positive unless , which cannot happen when . The converse of the proposition fails: on is injective, since gives , but it is neither increasing nor decreasing, as the section on the codomain showed. Proving that is also surjective on , that every real number has a real cube root, needs the completeness of the real numbers, which the lesson on the real numbers uses to prove that exists; the argument for cube roots is the same.
Composition
Given and , the composite is defined by , read " after ": runs first. The composite exists only when the codomain of is the domain of (or, more loosely, when the range of lies inside the domain of ), so that every value of is something can act on.
Order matters. With and on , and , so while . When the sets differ, one composite may exist and the other not: with and , makes sense and does not.
Proposition. Let , and . Then
(i) ;
(ii) and .
Proof. Both sides of (i) are functions from to , so it is enough to compare values. For , , and . For (ii), and for every .
Associativity means brackets can be dropped, and has one meaning: apply , then , then . Composition behaves like a multiplication with identities but without commutativity, which is how it reappears in algebra, where matrices multiply because the linear maps they represent compose.
Example. Prove that if and are injective, then is injective.
Let with . The elements and of have the same value under , and is injective, so . Since is injective, . So is injective.
The proof peels the functions off from the outside in.
Now you. Prove that if and are surjective, then is surjective.
Answer
Let . Since is surjective, there is with . Since is surjective, there is with . Then , so is surjective. Again the proof works from the outside in, finding before .
Together the two results say that a composite of bijections is a bijection. The converses hold only in part, and each half is worth knowing exactly.
Proposition. Let and .
(i) If is injective, then is injective.
(ii) If is surjective, then is surjective.
Proof. (i) Let with . Applying gives , and since is injective, .
(ii) Let . Since is surjective, there is with . Put , an element of . Then .
The other halves fail. Let be the inclusion, , and , squaring on . Then is on , which is injective (it is strictly increasing there), yet is not injective. The fault is that is only ever applied to values of , and the values where misbehaves, the negative numbers, are never reached. Similarly, with , , and , , the composite from to is surjective, while is not. So if is a bijection, all that follows is that is injective and is surjective; Problem 8 shows that nothing more follows without further hypotheses.
Inverses
To undo is to have a function going back that cancels it from both sides. A function is an inverse of when
that is, for every and for every . A function with an inverse is called invertible. The two conditions do different jobs, and the theorem that says which functions have inverses shows exactly how.
Theorem. A function has an inverse if and only if it is a bijection.
Proof. () Suppose is an inverse of . For injectivity, let with . Applying gives . For surjectivity, let and put , an element of . Then . So is a bijection.
() Suppose is a bijection. For each , surjectivity gives some with , and injectivity says there is only one. Let be that . This assigns exactly one element of to each , so is a function; in terms of graphs, the graph of is , the graph of with each pair reversed, and bijectivity is precisely what makes this reversed set satisfy the "exactly one" condition. By construction for every . For , is the unique element of with value , and is such an element, so . Hence is an inverse of .
In the forward direction, forced injectivity and forced surjectivity. Neither alone is enough, as the next section shows.
Proposition. Let .
(i) If has an inverse, it has only one.
(ii) If is the inverse of , then is a bijection and is the inverse of .
(iii) If and are bijections, then is a bijection, and its inverse is .
Proof. (i) Let and both be inverses of . Using associativity and both halves of the definition,
(ii) The two equations and , read with the roles of and exchanged, say that is an inverse of . By the theorem, is then a bijection.
(iii) By the associativity of composition,
and in the same way . So is an inverse of , which is therefore a bijection by the theorem.
By (i) the inverse earns a name, . For on it is , the formula the surjectivity proof already found. The order reversal in (iii) is the rule of socks and shoes: socks go on first and shoes second, so to undo the process the shoes come off first.
The symbol now has two meanings, the preimage of a set under any function and the inverse function of a bijection, and they agree wherever both make sense. If is a bijection and , then (preimage) means , which, applying the inverse, means for some , that is, lies in the image of under the function . So the clash is harmless, as long as the preimage is never mistaken for evidence that an inverse exists.
A bijection from a set to itself is also called a permutation of the set. The permutations of a set are closed under composition and inverses and include , which makes them the first example of a group; for a set of elements there are of them, as the section on counting shows.
Left and right inverses
Splitting the definition of an inverse in two gives two weaker notions. Let . A function is a left inverse of if , and a right inverse of if . (The names follow the side on which is written in the composite.) A left inverse undoes : apply , then , and you are back where you started. A right inverse is undone by : picks, for each , an input that sends back to .
Theorem. Let .
(i) If is not empty, then is injective if and only if it has a left inverse.
(ii) is surjective if and only if it has a right inverse.
(iii) If has a left inverse and a right inverse , then , and is a bijection with inverse .
Proof. (i) () If and , then , as in the proof of the previous theorem. () Suppose is injective. Since is not empty, fix an element . Define by cases. If lies in the range , there is an with , and by injectivity only one, so let be that . If , let . Every falls in exactly one case and receives exactly one value, so is a function. For , the element lies in the range, and is the unique element with value , so . Hence .
(ii) () If and , put ; then . () Suppose is surjective. For each the fibre is not empty; choose an element of it and call it . Then is a function, and for every , because lies in the fibre over . Hence .
(iii) Using associativity, . So satisfies both and , and it is an inverse of ; by the previous theorem is a bijection.
The hypothesis in (i) is needed only for a technical reason, and the reason is instructive. The empty function is injective, because the condition "if then " has no instances to fail. A left inverse would be a function , and if has an element there is nowhere to send it. So the empty function into a non-empty set is injective with no left inverse, and the theorem has to exclude it.
Left and right inverses, unlike two-sided ones, are usually far from unique, and the Example shows how many there can be.
Example. Let , , as before. Describe all left inverses of , and show that none of them is a right inverse.
A function is a left inverse exactly when for every , that is, when for every natural number . This fixes on the even numbers, where it must halve, and says nothing about the odd ones. So the left inverses of are exactly the functions
where is any function from the odd natural numbers to . For instance and give two different left inverses. None of them is a right inverse: for every left inverse , the value is even, so it is not , and . That agrees with the theorem, since is injective and not surjective.
Now you. Let send to its quotient on division by , so that with . Show that is surjective, find two different right inverses of , and show that has no left inverse.
Answer
By the division algorithm, is a function: each integer has exactly one quotient. The fibre over is , because and are divisions with remainder in range, so both have quotient , and any with quotient equals with . Every fibre is non-empty, so is surjective.
A right inverse must choose one element of each fibre. Let and . Then and for every , so both are right inverses, and they differ, for instance . Mixing the choices, say for even and for odd , gives infinitely many more.
A left inverse would make injective, by part (i) of the theorem. But with , so is not injective and has no left inverse.
What does "choose an element of each fibre" rely on?
In the Now you nothing was really chosen: the fibres were written down, and "take the smaller element" is a rule. The same works for any surjection whose domain is , since the well-ordering principle gives every non-empty fibre a least element, and "send to the least element of its fibre" defines a right inverse outright. The proof of part (ii) of the theorem, though, said "choose an element of each fibre" for an arbitrary surjection, possibly with infinitely many fibres and no rule to pick from any of them. That is an infinite number of arbitrary choices made at once, and none of the principles used so far licenses it.
The principle that does is the axiom of choice: for every family of non-empty sets, there is a function picking one element from each. Ernst Zermelo stated it explicitly in 1904, to prove that every set can be well-ordered, and it was controversial at once, precisely because it asserts that a function exists without describing it. Bertrand Russell's illustration is well known: from infinitely many pairs of shoes one can choose one shoe from each pair by a rule ("take the left one"), but from infinitely many pairs of socks, where the two members of a pair cannot be told apart, no rule is available, and the axiom is needed to say that a choice exists at all.
The statement "every surjection has a right inverse" is not merely a consequence of the axiom of choice; it is equivalent to it. Given a family of non-empty sets , the function sending each pair with to its index is a surjection onto the index set, and a right inverse picks, for each , a pair with , which is exactly a choice of one element from each set. So part (ii) of the theorem cannot be proved without the axiom.
Kurt Gödel showed in 1938 that adding the axiom of choice to the other axioms of set theory cannot produce a contradiction unless they already contain one, and Paul Cohen showed in 1963 that the same is true of adding its negation. So the axiom is independent of the others: they neither prove nor refute it. Almost all of mainstream mathematics accepts it, and much of analysis and algebra uses it, often in the form of Zorn's lemma, which the lesson on order states. The left-inverse half of the theorem needs no such axiom: there the only choice is the single element , and choosing one element from one non-empty set is ordinary logic.
Restriction
Many useful functions are not injective, and most of them become injective once part of the domain is discarded. Let and . The restriction of to is the function given by for . Its graph is the part of the graph of lying over , and in terms of composition , where is the inclusion. Conversely, when we call an extension of to .
Restriction keeps some properties and changes others. The range of is , the image of , which is how images and restrictions are tied together. If is injective, so is every restriction, since a pair of inputs in with the same value is a pair in with the same value; formally, is a composite of injections. Surjectivity is usually lost, and injectivity is often gained: is not injective on , but is, because is strictly increasing on .
Restricting the domain and shrinking the codomain to the range together turn a function into a bijection whenever the restriction is injective. If is injective, then the same rule, viewed as a function , is surjective by the definition of the range and injective because is, so it is a bijection. This is how the classical inverse functions are made. The square root is the inverse of restricted to with codomain . The function is the inverse of restricted to , with codomain ; other intervals would have done, and the choice of that one is a convention, like the choice of the non-negative square root.
Example. Let , . Show that is not injective, and prove that its restriction to , with codomain , is a bijection. Find its inverse.
Completing the square, . So , and is not injective on : the graph is symmetric about the line .
Let be the restriction, with the smaller codomain. It is a function into , since gives . Injective: let with . Then , and both and are non-negative. Two non-negative numbers with the same square are equal (if and , then , so , or , which forces ). So and . Surjective: let and put , defined because . Then , so is in the domain, and . So is a bijection, and the element with value is , which gives .
The restriction to would have worked as well, with inverse . Each half of the parabola carries its own inverse.
Now you. Let , . Prove that the restriction of to , with codomain , is a bijection, and find its inverse.
Answer
Completing the square, , so every value is at least and the restriction is a function.
Injective: let with . Then . Here and , so and are non-negative numbers with the same square, hence equal, and .
Surjective: let and put , defined because . Then , so is in the domain, and .
So is a bijection with inverse . The minus sign in front of the root is forced by the choice of the left half of the parabola; the plus sign would give a number outside the domain whenever .
Going the other way, a function can be built on a set piece by piece and then glued. Suppose , and and agree on the overlap, meaning for every . Then there is exactly one function with and : its graph is the union of the graphs of and . Each lies in or , so it receives a value; if it lies in both, the two values agree, so it receives only one. This is what justifies a definition by cases, such as for and for : the pieces overlap at , and there they agree. Where pieces overlap and disagree, as in " for and for ", no function has been defined.
Counting functions between finite sets
For finite sets the three properties can be counted, and the counts explain a good deal. Write for the number of elements of a finite set .
Theorem. Let and .
(i) There are functions from to .
(ii) There are injections from to , a product of factors; in particular there are none when .
(iii) There are bijections from to when , and none otherwise.
Proof. (i) By induction on . When , , and there is exactly one function from to , since its graph must be a subset of , and the empty graph satisfies the "exactly one" condition vacuously; and . Suppose the count is right for sets of elements, and let . Fix and put , with elements. A function is determined by the pair , and every pair with and arises from exactly one , by the gluing principle of the previous section. So the functions correspond exactly to the elements of the product of the set of functions with , which by the product rule of the previous lesson has elements.
(ii) The same induction, with one change. An injection is determined by the pair , where is an injection and must avoid its values: choices for each of the injections . That gives , the formula for . When , the factor appears in the product, so the count is .
(iii) If , the theorem below shows that the bijections are exactly the injections, and there are of them. If , a bijection would make the two sets the same size, which the counts of values forbid: an injection needs by (ii), and a surjection needs , since inputs take at most values.
The product is a falling factorial, and it counts ordered selections without repetition, the subject of the Discrete Mathematics lesson on arrangements. The statement that there is no injection from a set of elements into a set of elements is the pigeonhole principle: put more than letters into pigeonholes and some pigeonhole receives two. The lesson on contrapositive and contradiction uses it as a tool; here it has appeared as a count.
A computer listing every function on small sets agrees. From a 3-element set to a 4-element set there are functions, of which are injective. From a 4-element set to itself there are , and exactly are injective, the same that are surjective. The falling factorial also settles the birthday problem: of the ways to give 23 people birthdays, ignoring 29 February, the injective fraction is , so a shared birthday is more likely than not.
Counting surjections is harder, since there is no single running choice to count, and it needs inclusion and exclusion. For small sets it can be done by hand: a surjection from a 4-element set onto a 3-element set must send exactly two elements to one value and one element to each of the other two, and Problem 11 counts them.
What is a function from the empty set?
Exactly one, for every set , including : its graph is the empty set, and the condition on graphs holds vacuously, since there is no element of for it to fail at. It is called the empty function.
A function from a non-empty set to is another matter: an element needs a value in , and there is none. So there are no functions from a non-empty set to the empty set.
These are exactly the values of that the counting formula needs. The number of functions with is , and the number of functions with is . The single case gives one function, the empty function from to itself, and this is one of the reasons mathematicians working with finite sets take . Likewise counts the one bijection from to itself.
The empty function is injective, since there is no pair of inputs to collide, and surjective only onto ; it is why part (i) of the theorem on left inverses needs to be non-empty. Cases like this look like pedantry, but they are what let formulas such as and hold without exceptions.
For sets of the same finite size, the counts show that injective and surjective come together, and there is a direct proof.
Theorem. Let and be finite sets with , and let . Then is injective if and only if it is surjective, and so if and only if it is a bijection.
Proof. Let .
() Suppose is injective. Its values at the elements of are all different, so the range has elements. It is a subset of , and the elements of outside it number . So , and is surjective.
() Suppose is surjective but not injective. The fibres , for , are disjoint, since each element of has one value, and their union is , so their sizes add up to . Each of the fibres has at least one element, by surjectivity, and some fibre has at least two, since two different elements share a value. Then the sizes add up to at least , a contradiction. So is injective.
The theorem is used constantly in a practical form: to show that a map between finite sets of the same size is a bijection, prove only one of the two properties, whichever is easier. It fails without both hypotheses. It needs the sizes equal, as the inclusion of in shows, and it needs finiteness.
What goes wrong for infinite sets?
The map , , is injective and not surjective, and the map on is surjective and not injective, since and both go to . So for maps from an infinite set to itself, the two properties separate completely, and the theorem above is special to finite sets. The proof shows where finiteness entered: it subtracted and added numbers of elements, and for infinite sets there are no such numbers to compare.
Galileo noticed the phenomenon in his Two New Sciences of 1638. The squares are a small part of the natural numbers, becoming rarer the further one goes, yet pairs the natural numbers one to one with the squares. He concluded that "equal", "greater" and "less" do not apply to infinite quantities. Richard Dedekind turned the paradox into a definition in 1888: he called a set infinite when it can be put in bijection with a proper subset of itself, as can with the even numbers or the squares. By the theorem above, no finite set has this property, since a bijection from a finite set onto a proper subset , composed with the inclusion of in , would be an injection that is not surjective.
Georg Cantor took the other way out of Galileo's paradox. Rather than give up comparing infinite sets, define two sets to have the same size when there is a bijection between them, and accept that a set can have the same size as a part of itself. The lesson on counting the infinite develops this, with bijections and injections doing all the work, and finds that infinite sets come in more than one size.
When one output is not enough
A function relates each input to exactly one output, and that restriction is what made composition and inverses work. Many relations mathematics cares about break it. "Divides" on the positive integers links to , , and every other multiple. The equation links to both and and links to nothing, so the circle is not the graph of a function from to . "Leaves the same remainder on division by " links to , and .
Each is still a set of ordered pairs, a subset of a product, with the "exactly one" condition dropped. Functions themselves produce such relations: every gives the relation "has the same value under as" on , which links to when , and whose linked groups are exactly the non-empty fibres. The next lesson takes such relations up, beginning with the ones that declare two things to be the same for present purposes, and shows that every one of them arises from a function in this way.
Problems
Work each problem on paper before opening anything; for Core and Challenge problems, try the hint before the solution.
Warm-up
1. Let and . Which of these subsets of are graphs of functions ? For each one that is, give its range and say whether it is injective and whether it is surjective. (a) ; (b) ; (c) ; (d) .
Solution
(a) A function: each of , , appears exactly once as a first coordinate. It is the constant function with value , its range is , it is not injective ( and share the value ) and not surjective ( is not a value).
(b) Not a function: does not appear as a first coordinate, so it receives no value.
(c) Not a function: appears twice, with values and .
(d) A function with range , so it is surjective. It is not injective, since and both have value . No function from a set of three elements to a set of two can be injective, by the pigeonhole principle.
2. Let , . Find , , , and , justifying the first by double inclusion.
Solution
. If , then , so every value on lies in . Conversely, if , then and , so is a value on .
, since exactly when or .
, since for every .
, as is the identity on non-negative numbers, so , strictly larger than .
, since always and exactly when . Then , strictly smaller than . This is , as Problem 6 predicts.
3. Decide whether each function is injective and whether it is surjective, with proofs. (a) , . (b) , . (c) , . (d) , .
Solution
(a) Injective: if then . Surjective: let and put , an integer, with . So it is a bijection.
(b) Injective: if then . Not surjective: if for an integer , then , but a divisor of has absolute value at most . So is not a value.
(c) Surjective: let be an integer; then and . Not injective: and .
(d) Surjective: let ; then and . Not injective: and are different pairs with the same value . In fact every fibre is a whole line, .
4. Let be given by and . Find formulas for and and show that they are different functions. Find and check both of the equations that make it an inverse.
Solution
, and . At the first is and the second is , so .
Solving for suggests . Check: for every real , , and for every real , . So both and are the identity on .
Core
5. Let . Prove that is injective if and only if for all subsets and of .
Hint
For the forward direction one inclusion is the Example in the lesson; the other is where the lesson's failed attempt got stuck. For the backward direction, use the contrapositive with one-element sets.
Solution
() Suppose is injective, and let . The inclusion holds for every function, by the Example in the section on set operations. For the reverse, let . Then for some and for some . So , and by injectivity . This element lies in both and , so .
() We prove the contrapositive. Suppose is not injective, so there are in with . Take and . Then , so , while , which is not empty. So the equality fails for this pair of subsets.
6. Let .
(a) Prove that for every , and deduce that is surjective if and only if for every .
(b) Prove that is injective if and only if for every .
Hint
Each "if and only if" has one direction that needs a single well-chosen set: in (a), and a one-element set in (b).
Solution
(a) Let . By the Example in the section on image and preimage, , and every element of is a value of , so lies in ; hence . Conversely, let . Then for some , and , so and .
If is surjective, then , and for every , so . Conversely, if for every , take : since , this says , so is surjective.
(b) () Suppose is injective and let . The inclusion holds for every function (the Now you in the section on image and preimage). For the reverse, let . Then , so for some , and by injectivity .
() Suppose for every , and let with . Take . Then , so , which gives . So is injective.
7. Find the flaw in this proof, and show that the claim is false.
Claim. Let and . If is injective, then is injective.
Proof. Let with . Write and with . Then , and since is injective, . Hence , so is injective.
Hint
The second sentence asserts that something exists. What property of would guarantee it?
Solution
The flaw is the second sentence. It assumes that and are values of , which holds for all only when is surjective, and nothing in the hypothesis says so. The argument never considers elements of outside the range of , and those are exactly where may fail to be injective.
A counterexample: let , , , with and . Then is injective, since its domain has only one element, but is not, since and .
The argument does prove a correct statement: if is injective and is surjective, then is injective. Then the second sentence is justified by surjectivity, and the rest goes through unchanged.
8. Let and . Prove or disprove each claim. (a) If is a bijection, then is surjective. (b) If is surjective and is injective, then is surjective. (c) If and are bijections, then is a bijection. (d) If is injective and is surjective, then is surjective.
Hint
Two are true. For the false ones, the smallest sets you can think of will do: the counterexample in Problem 7 is a good place to start. For (c), write as a composite.
Solution
(a) False. Take , , , and . Then is a bijection, but is not surjective, since is not a value. Nor is injective, so a bijective composite says nothing about being surjective or being injective.
(b) True. Let . Then , and is surjective, so there is with . Since is injective, . So every is a value of .
(c) True. Since is a bijection it has an inverse , and by associativity. So is a composite of the bijections and , and a composite of bijections is a bijection.
(d) False. The example in (a) works again: is injective, is surjective, and is not surjective.
9. Prove that , , is a bijection, and find a formula for .
Hint
First check that the values lie in and that has the same sign as . Then split injectivity and surjectivity into the cases of non-negative and negative inputs, where the absolute value can be removed.
Solution
Values. For every real , , so and . So is a function into . Since the denominator is positive, when , when , and when .
Injective. Let with . By the sign observation, and are both non-negative or both negative. If both are non-negative, then , so and . If both are negative, then and , so , which gives and .
Surjective. Let . If , put , a real number since , and non-negative. Then , so . If , put , a real number since , and negative since . Then and , so .
So is a bijection. The two cases of the surjectivity proof combine into one formula, since is for and for :
A bijection between and a bounded interval may be surprising. It shows that, in the sense of the lesson on counting the infinite, the whole line and a short piece of it have the same size.
10. Let be a set, and let be the set of all functions from to . For , let be the characteristic function of .
(a) Prove that , , is a bijection, by showing that , , is its inverse.
(b) Prove that and for all , where the operations on the right are taken value by value.
(c) Deduce that a set of elements has subsets.
Hint
For (a), check and ; the second is an equality of functions, proved by comparing values at an arbitrary , in two cases. For (c), use the counting theorem.
Solution
(a) For , , by the definition of . So .
For , let ; we show by comparing values. Let . If , then , so . If , then , so . These cases are exhaustive, since takes values in . So , and . Hence is an inverse of , and is a bijection.
(b) Let . If , both sides of the first equation are at , since . If , then or , so one of and is and the product is . For the second, if then , and if then .
(c) Let . By the counting theorem, there are functions from to the 2-element set , so . Since is a bijection from to , and a bijection between finite sets exists only when they have the same number of elements (the same theorem, part (iii)), . This is the count the previous lesson proved by induction, now obtained by translating subsets into functions. Part (b) shows the translation also turns set operations into arithmetic, which is how computers store and combine sets, as strings of bits.
11. How many surjections are there from a set of elements onto a set of elements? Check your answer by counting the functions that are not surjective and adding.
Hint
The fibres of a surjection partition the domain into non-empty pieces, one for each element of the codomain. What sizes can they have?
Solution
Let and . The three fibres of a surjection are non-empty, disjoint, and together make up , so their sizes are positive integers adding to : one fibre has elements and the others each.
A surjection is therefore determined by three choices: which element of has the fibre of size ( ways); which two elements of form that fibre ( ways: , , , , , ); and how the remaining two elements of are sent to the remaining two elements of , one each ( ways). Different choices give different functions, and every surjection arises from one set of choices, namely its own. So there are surjections.
Check. A function that is not surjective has range of size or . Range of size : a constant function, of them. Range of size : choose the two values ( ways), then a function from onto that 2-element set; there are functions from to a 2-element set, of which are constant, so are onto, giving . In total , the number of all functions from to .
Challenge
12. Let .
(a) Prove that is injective if and only if, for every set and all functions , implies .
(b) Prove that is surjective if and only if, for every set and all functions , implies .
Hint
The forward directions compare values. For the backward directions argue by contrapositive and build and on very small sets: a one-element in (a), and in (b), with a characteristic function.
Solution
(a) () Suppose is injective, and let with . For every , , so by injectivity. The functions and have the same domain, codomain and values, so .
() Suppose the cancellation property holds, and let with . Let , and define by and . Then , so , and the property gives . Hence , and is injective.
(b) () Suppose is surjective, and let with . Let . There is with , and then . So .
() We prove the contrapositive. Suppose is not surjective, and choose outside the range of . Let , let be the constant function , and let , which is at and elsewhere. For every , , so , and . But , so , and the cancellation property fails.
The two properties describe injectivity and surjectivity purely by how composes with other functions, without mentioning elements. That is how category theory, which studies mathematical structures through the maps between them, defines its general notions of monomorphism and epimorphism. Note that no choice was needed in (b), unlike the right inverse of the lesson: cancellation is a weaker property than having a right inverse, and is available for every surjection outright.
13. Prove that there is no function with for every integer .
Hint
Compute in two ways: as applied to , and as applied to . That determines up to one constant.
Solution
Suppose, for a contradiction, that satisfies for every integer . Let . Applying the hypothesis to the integer gives . Applying to both sides of gives . Hence
Let . We show for every integer . For this is an induction on : it holds at , and if then . For negative integers, rewrite the displayed equation as and induct on for the statement : it holds at , and if , then .
Now apply the hypothesis at : . But is even and is odd, and no integer is both. This contradiction shows that no such exists.
The obstruction is arithmetic, not logical. On the function satisfies , and on the equation is satisfied by ; the proof shows that on every solution of is a translation by , which exists exactly when is even.
14. A function is idempotent if .
(a) Prove that is idempotent if and only if for every in the range .
(b) Prove that an idempotent function that is injective, or surjective, is the identity.
(c) How many idempotent functions are there from to itself?
Hint
For (c), use (a): an idempotent function is determined by its range and by where it sends the elements outside . Count by the size of .
Solution
(a) () Let be idempotent and , say . Then . () Suppose fixes every element of its range, and let . Then is in the range, so . Hence .
(b) Let be idempotent. If is injective, then for each the equation says that and have the same value, so . If is surjective, its range is , and by (a) it fixes every element of . In both cases .
(c) Let . By (a), an idempotent fixes each element of its range , which is non-empty because is, and sends each element of into . So determines a pair , where is a non-empty subset of and is a function .
Conversely, every such pair comes from exactly one idempotent. Given a non-empty and , define to be the identity on and on . Its range contains , since fixes , and is contained in , since every value lies in ; so the range is , fixes its range, and is idempotent by (a). Its pair is again, and different pairs give different functions. So the idempotents correspond exactly to the pairs.
For there are functions , by the counting theorem. Summing over the subsets by size: subsets of size , each giving ; of size , each giving ; of size , each giving ; and of size , giving . The total is .