TITLE: What is the purpose of a function being surjective?
QUESTION [31 upvotes]: So as far as I understand, a function $f\colon A \to B$ is surjective if and only if for every $b\in B$ there exists $a\in A$ such that $f(a) = b$.
My question is when is this actually relevant? Couldn't you arbitrarily define the set $B$ so that any elements never "used" are removed from the set, leaving you with a surjective function?

REPLY [8 votes]: $\newcommand{\Reals}{\mathbf{R}}\newcommand{Ratls}{\mathbf{Q}}$Mathematical problems often come in the form of,

"Some value $y$ depends deterministically on data $x$; is every prospective value $y$ an actual value?"

Two common formulations are:

Let $Y$ be a set of prospective values (specified in advance by the context of an external question), $X$ the set of allowable inputs, and $f:X \to Y$ a mapping representing the dependence $y = f(x)$.
The question above means Is $f$ surjective?
Let $Y \subset Z$ be a set of prospective values, $X$ the set of allowable inputs, and $f:X \to Z$ a mapping representing the dependence $y = f(x)$.
The question above means Is $Y \subset f(X)$?

Here's a selection of five examples, four of them kind of the same:

Is every real number the square of some real number?
That is, if $f:\Reals \to \Reals$ is defined by $f(x) = x^{2}$, is $f$ surjective? (Answer: No. For instance, $-1$ is not in the image.)
Is every non-negative real number the square of some real number?
That is, if $f:\Reals \to \Reals$ is defined by $f(x) = x^{2}$, is $[0,\infty)$ contained in the image of $f$? (Answer: Yes, though proving this "existence of real square roots" requires non-trivial use of the completeness axiom for the real numbers, even though the result is usually introduced into the curriculum many years prior to a careful analysis course.)
Is every positive rational number the square of some rational number?
That is, if $f:\Ratls \to \Ratls$ is defined by $f(x) = x^{2}$, is $[0,\infty) \cap \Ratls$ contained in the image of $f$? (Answer: No. For instance, $2$ is not in the image.)
If $y:\Reals \to \Reals$ is a continuous function, does there exist a differentiable function $x:\Reals \to \Reals$ such that $x' = y$?
That is, if $X$ is the set of differentiable, real-valued functions on $\Reals$, and $Y$ is the space of continuous functions, and $Z$ the space of all functions, and if $f(x) = x'$, is $Y$ contained in the image of $X$? (Yes: One of the fundamental theorems of calculus guarantees that every continuous function on $\Reals$ is the derivative of some differentiable function.)
Let $(M, g_{0})$ be a compact Kähler manifold. If $\rho$ is a smooth $(1, 1)$-form in the cohomology class $2\pi\, c_{1}(M)$, does there exist a Kähler metric $g$ whose Kähler form is cohomologous to the Kähler form of $g_{0}$ and whose Ricci form is $\rho$?
Analogously to the preceding example, you can imagine that there is a partial differential equation of the abstract form $\rho = f(g)$, and the question amounts to surjectivity of the Ricci curvature operator $f$. The answer turns out to be "yes"; largely for this resolution of the Calabi conjecture, S. T. Yau was awarded the Fields Medal in 1982.
The take-away is, not only is surjectivity interesting, but proving that a specific mapping is surjective can constitute a major work in a distinguished mathematical career.