Search the atlas

Surjective functions

How the codomain determines whether a function is onto, with examples involving a square, a cubic and a finite set of commands.

Reaching every output

A function f:A→Bf:A\to B is surjective, or onto, if every element of its codomain is the image of at least one element of its domain. In symbols,

∀y∈B∃x∈A: f(x)=y.\forall y\in B\quad \exists x\in A:\ f(x)=y.

Equivalently, f(A)=Bf(A)=B. The same formula can therefore define two functions with different answers to the question “Is it onto?” Take f(x)=x2f(x)=x^2 with domain R\mathbb R. With codomain R\mathbb R, every negative number is missed. With codomain [0,+∞)[0,+\infty), every target is reached.

Surjectivity means that each element of the codomain has at least one preimage. Injectivity means that each has at most one. For worked examples in Italian, see finite maps and bijections and linear maps between vector spaces.

How do you prove that every target is reached?

Consider p(x)=x3−xp(x)=x^3-x as a function from the real numbers to the real numbers. Testing a few inputs cannot settle the question. Instead, choose any target yy. For a sufficiently large RR, the cubic term dominates at both ends and p(−R)<y<p(R)p(-R)<y<p(R). The polynomial is continuous, so the intermediate value theorem guarantees at least one xx between −R-R and RR with p(x)=yp(x)=y. The choice of RR can depend on yy. No single bounded interval of inputs could cover every real target.

Now choose zero as the target. The equation x3−x=0x^3-x=0 has three solutions, x=−1,0,1x=-1,0,1. Knowing that the output was zero does not tell us which input produced it. Restricting the codomain to the image makes any well-defined function onto. Defining an inverse function on that image also requires a unique preimage for each output.

For a finite map, a simple coverage check suffices. Suppose six commands map to three states, A, B and C. If four commands lead to A and the other two lead to B, every command has a defined result, yet C is unreachable. The map is onto precisely when all three states occur among the results.

Sources

MIT, Mathematics for Computer Science, notes on relations and mappings

Back to contents