Why do we have codomain? This really ties to the question I asked last night about $f:A\rightarrow B$, but I still don't understand some things. I'm only in AP Calculus BC, and we've never discussed this codomain set $B$. Why does it exist? If the range of $f$ is $\{f(a)\mid a\in A\}$, then why don't we use the range where $B$ is? The way I see it, one could simply say $\Bbb U=\Bbb{R}\cup \{ a+bi\mid a\in\Bbb R\wedge b\in\Bbb R\wedge i^2=-1\}$ and set $B=\Bbb U$ and never have to worry about it again, so how do you know what to set the codomain equal to?
 A: Short Answer It is convenient to know where the output lies. I can tell whether a function is real-valued or complex-valued with an appropriate use of the codomain.
Long Answer Functions exist in many contexts; not just Calculus. In Linear Algebra, the functions of interest are linear transformations. In Algebra, the functions of interest are (group/ring) homomorphisms. In Topology, the functions of interest are continuous functions. In Calculus, (one of the) the functions of interest are real-valued functions from $\mathbb{R}$ to $\mathbb{R}$. The "space" $\mathbb{R}$ you are working in doesn't change. However in other contexts the "space" can change.
For example, in Linear Algebra the "spaces" are vector spaces (typically but not always finite-dimensional). There's not one vector space that's studied always, in fact there are infinitely many of them such as $\mathbb{R}^n$ ($n\in\mathbb{N}$). In Algebra there are groups, rings, fields, etc. In Topology there are what's called topological spaces, which unlike Calculus does not have one space that's studied always. So functions from one space to another are best defined via a domain and codomain. You are right that in Calculus it seems that all codomains could theoretically be $\mathbb{C}$ the complex numbers, but now that you know that spaces can change, the codomain serves as a means of telling you if the space changed or not.
A: I think the main reason is that codomain is a useful concept.
You are right, we could always set the codomain to be $f(A)$ if we wanted.
But without knowing the function $f$, it is hard to imagine what is $f(A)$.
Similarly, an analogous concept is why do we need to have a domain? We could always define the domain to be the largest set where the function makes sense. E.g. for $f(x)=\sqrt x$, we can set the domain $A=[0,\infty)$.
Eventually you will learn the important concept "Surjective" or "Onto": A function $f:A\to B$ is surjective if $f(A)=B$.
