TL;DR
A surjective function is a Function whose outputs cover its whole target set. Every element of the codomain is the output of at least one input, so nothing in the target is missed. Surjectivity tells you that a rule can reach every possible answer, and it is the half of a one-to-one correspondence that is about coverage rather than repetition.
Builds on: Function · Leads to: bijective functions
Where it's used
Card suits. Sort a standard deck by suit: the rule "card to suit" maps 52 cards onto four suits. It is surjective, because every suit has at least one card. A rule that sent every card to hearts would not be surjective, since clubs, diamonds and spades would never be reached.
Classifiers. A machine-learning classifier, a learned function such as a linear classifier, chooses one label from a fixed list, such as cat, dog, bird or fish. The rule "image to label" is meant to reach every label. If, over a large test set, the model never predicts fish, the rule is not surjective onto its label list. That is a useful warning sign: either the training data lacks fish, or the code has a bug.
Mapping a formula's outputs. A rule that turns a temperature in degrees Celsius into a reading on a scale can be checked for surjectivity against the scale it is supposed to cover. If it never outputs values below a certain level, some readings are impossible, and the designer needs to know that before building an instrument on it.
How it works
Take a small set of inputs and a target set . Let send the inputs as follows: , , and .
- Read off the outputs. They are , , and . Every input has exactly one output, so is a function from to .
- List the target set. It has three elements, , and .
- Check each target in turn. Is an output? Yes, from input (and also input ). Is an output? Yes, from input . Is an output? Yes, from input .
- Every target is reached, so is surjective. Repeats do not matter: input and input both land on , and that is allowed.
- Now change one value and let instead. The outputs are , , and .
- Check the targets again. and are reached, but is not. No input leads to , so is no longer surjective.
The rule for checking is always the same: go through the target set and look for an input that reaches each element. One unreached target is enough to show that the function is not surjective.
The same idea appears on a graph. Consider on the real numbers, with the reals as the target. A horizontal line at height never touches the curve, because squares are never negative. So the value is not an output, and is not surjective onto the reals. A surjective function is one for which every horizontal line, at every height in the target, meets the graph at least once.
- f(x) = x²
- y = -1
Here is the first rule as a diagram. Each target must have at least one arrow arriving at it:
flowchart LR i1[input 1] --> ta[a] i2[input 2] --> ta i3[input 3] --> tb[b] i4[input 4] --> tc[c]
Targets , and each have an arrow arriving, so every target is covered.
The math
The symbol means "for every", and means "there exists". The arrow reads "maps to", as before. A function is surjective when this statement is true.
A function is surjective, or onto, if for every there exists with :
Equivalently, the range of , which is the set of all outputs, equals the whole codomain .
Step 3 in symbols
For the first rule, . We need an input for each target:
Each of , and appears as an output, so the condition holds. Input is not needed for coverage, and it is allowed to repeat an output.
Steps 5 and 6 in symbols
After the change, the outputs are , , and . Take the target . No in satisfies , since every output is or . The statement "there exists with " is false, so is not surjective. One false instance of the statement settles the matter.
Proving surjectivity for a formula
Let , a linear function, from the real numbers to the real numbers. To show surjectivity, take any target and find an input that reaches it. Set . Subtract to get , then divide by to get
This is a real number for every real . Check it: . Every target is reached, so is surjective. The pattern to follow in general is to start from and solve for . If the solution always exists, the function is surjective.
Surjectivity depends on the codomain
The range of a function is fixed by its rule, but the codomain is a choice. Take from the reals to the non-negative reals . Every target is reached, since gives . So is surjective onto , even though the same rule is not surjective onto the reals. Replacing the codomain by the range always makes a function surjective.
Worked examples
Let and . Define , and .
- Compute the outputs: , and .
- Check the target . It is reached from input .
- Check the target . It is reached from input .
- Both targets are covered, so is surjective.
Interpretation: a surjective rule can send several inputs to the same target, as long as no target is left out. Input adds nothing new, but it is harmless.
Let be the remainder when is divided by , for in .
- Compute the outputs: , , , , , , and .
- The outputs are only , and .
- With codomain , each target is reached, so is surjective onto that set.
- With codomain , the target is never an output, because a remainder on division by is always less than . So is not surjective onto this larger set.
Interpretation: the same rule is surjective or not depending only on the set we declare as the target. The remainder rule is designed to land in , so that set is its natural codomain.
A model labels photos as cat, dog, bird or fish. On six test photos it predicts: cat, dog, cat, dog, cat, dog. We ask whether the prediction rule is surjective onto the four labels.
- The predictions reach only cat and dog.
- Bird is a label, and no photo is predicted as bird, so bird is not reached.
- Fish is also a label, and it is not reached.
- So the rule is not surjective onto the four labels. It reaches two of them.
Try it: a seventh photo is labelled bird. Is the rule now surjective onto the four labels? Answer: no. Bird is now reached, but fish is still missing, so one target remains uncovered.
Common mistakes and tradeoffs
"Surjective means one-to-one." It is tempting to read "onto" as "no repeats". In fact the two are different properties. Surjectivity asks that every target be hit, and it allows many inputs to share an output. The property that forbids repeats is injectivity. A function can have one property without the other, as the examples above show.
"Surjective depends only on the formula." It is tempting to test and decide that it is or is not surjective. In fact the answer depends on the codomain. The same rule can be surjective onto one set and not onto another, as the squaring example showed.
"The outputs must be spread evenly." It is tempting to think that a surjective rule must hit each target the same number of times. In fact it only has to hit each target at least once. The card rule above sends 13 cards to each suit, but a rule that sent 49 cards to hearts and one card each to the other three suits would still be surjective.
When to care. Surjectivity matters when a target set is a list of options that should all be possible: the labels of a classifier, the positions on a scale, the suits of a deck. Checking it catches dead categories early.
Alternatives. If a rule is not surjective, you can often fix it by shrinking the target to its range, as the squaring example did. Surjectivity also survives composition: if and are both surjective, so is . You can also keep the target and accept that some outputs are never produced, which is common in practice; the question then becomes whether the missing outputs matter. A function that is both surjective and injective is called bijective, and it is the case with an inverse.
History
Long before formal set theory, mathematicians described a rule that covers its whole target in plain words such as "onto". Georg Cantor's comparisons of infinite sets in the 1870s and 1880s depended on matching the elements of one set with another.
In 1891 Cantor proved that no function from a set can be surjective onto its power set, the set of all its subsets. The formal terms "surjective", "injective" and "bijective" were introduced by the Bourbaki group of French mathematicians in their treatment of set theory, from the late 1930s, giving the two halves of a one-to-one correspondence separate names.
Recap
- A Function assigns each input one output.
- A function is surjective when every element of its codomain is the output of at least one input.
- To disprove surjectivity, find one target that no input reaches. To prove it for a formula, take any target and solve for an input.
- Surjectivity depends on the declared codomain, and shrinking the codomain to the range always makes a function surjective.
- Next, read Injective Function for the property that forbids repeated outputs. Together they define bijective functions, which are the functions with inverses.
Check yourself
QuestionLet with , , and . Is surjective?Show answer
No. Every input goes to , so the target is never reached. Repeats are allowed, but a missing target is not.
QuestionFor from the real numbers to the real numbers, find the input that gives the output , and state whether is surjective.Show answer
Solve . Then and . Check: . The same algebra works for any real target , since is always a real number. So is surjective.
QuestionWhy is surjective onto the non-negative reals but not onto all the reals?Show answer
Every non-negative equals for , so the non-negative targets are all reached. A negative target, such as , is never a square of a real number, so it is not reached when the codomain is all the reals.
QuestionA quality-control program assigns each manufactured part to one of five defect categories, and it wants the rule to be surjective, so that every category is actually observed. After a week, four categories have appeared but one never has. What does this tell you, and what are two possible reasons?Show answer
The rule is not surjective onto the five categories, since one category is never produced. Possible reasons are that the category is genuinely rare, so a week of data is too short to see it, or that the assignment rule has a gap and never selects that category. The program should check the rule and collect more data before drawing a conclusion.
Sources
- Surjective function, Wikipedia: https://en.wikipedia.org/wiki/Surjective_function
- Function (mathematics), Wikipedia: https://en.wikipedia.org/wiki/Function_(mathematics)
- Paul Halmos, Naive Set Theory (Springer): https://link.springer.com/book/10.1007/978-1-4757-1645-0