# How is the codomain for a function defined?

Or, in other words, why aren't all functions surjective? Isn't any subset of the codomain which isn't part of the image rather arbitrary?

-
Every function $f: X \rightarrow Y$ is surjective on its image $f(X) = \{ y \in Y: f(x) = y, \; x \in X \}$ but not every function has image $f(X) = Y$, which is, I think, the main problem you're encountering. –  Andy Sep 26 '10 at 10:41

Often what is important is not functions but collections of functions, especially subsets of the set of functions between two sets $X$ and $Y$, some of which will be surjective and some of which won't. What also doesn't get emphasized a lot at the level of elementary set theory is the compositional structure of functions, e.g. a function $f : X \to Y$ can be composed with a function $g : Y \to Z$ to give a function $fg : X \to Z$. For the purposes of studying this compositional structure (for example if $X = Y = Z$) it is generally important not to require that $f$ and $g$ be surjective or you will miss out on structure.

For example, a simple way to define a dynamical system is just as a function $f : X \to X$. Whether $f$ is surjective or not is an important aspect of classifying the dynamics of $f$, or in other words of classifying the behavior of the sequences $\{ x, f(x), f^2(x), f^3(x), ... \}$ for various $x$. This sequence is not well-defined if you pretend that the domain and codomain of $f$ are different just because the range and the codomain aren't equal.

This is another way of saying that a function really consists of three pieces of data (a domain, a codomain, and the mapping from one to the other), but the reason these three pieces of data are all important is really the compositional structure.

-

This is something that trips people up the more they dwell on it. And depending on how you like to think about mathematical objects, you have different preferred answers.

More often than not, I tend to think of a function as consisting of three things: a domain $A$, a range $B$ and a subset $S$ of $A \times B$ which satisfies this condition, that for any $a \in A$ there is a unique $b \in B$ such that $(a,b) \in S$. To be precise, a "function" $f$ is a triple $(A,B,S)$ where $S \subset A\times B$ satisfies the above criterion. We say $f : A \to B$ and $f(a) = b$ provided $(a,b) \in S$.

In the above formalism, you can't describe a function without specifying the domain and range before hand. To be specific, here are two different ways of specifying the function that in a calculus class would just be called $x^2$: $f=(\mathbb R, \mathbb R, \{(x,x^2) : x \in \mathbb R\})$. $g=(\mathbb R, [0,\infty), \{(x,x^2) : x \in \mathbb R\})$. So in this formalism, $f$ is not an onto function, while $g$ is an onto function. Although $f(x)=g(x)$ for all $x$ in the domain of $f$ and $g$, $f \neq g$ since they have different ranges.

If you don't use a formalism like the above, yes, the range (or co-domain as you say) is just any arbitrary set containing the image. Frequently this is taken care of by considering the range to be a typical "universal" set. In a standard calculus course what happens is people never really mention the range, they only talk about the image.

-
@Ryan: Your usage of the word "range" in this context is quite unfortunate. @OP: When reading this post, if it trips you up, replace all copies of the word "range" with the word "codomain. –  user126 Sep 26 '10 at 8:50
It sounds like you're set on "range" being synonymous with "image", which is your choice I suppose, but it's not standard. –  Ryan Budney Sep 26 '10 at 16:23
@Ryan: It seems to be standard for MathWorld (mathworld.wolfram.com/Range.html) and the Springer Online Encyclopedia of Mathematics (eom.springer.de/R/r077410.htm). –  Rahul Sep 26 '10 at 17:36
Rahul, you're correct about MathWorld. SOEM technically is defining "Range of values" -- the emphasis on "values" gives it a rather different meaning. Take a look at most topology textbooks for example, like Munkres or Dugunji, and you will not see "codomain" but you will see "range" instead. Even the Wikipedia article on functions, although it attempts to systematically use "codomain" you'll see it slips at one point and uses "range" where it should be using "codomain". This is a situation where everyone adapts to each others usage rather than there being a uniform standard. –  Ryan Budney Sep 26 '10 at 17:59
For what it's worth, I take "range" to mean image when I'm trying to parse a statement carefully (or trying to speak carefully), although I will also use it to mean codomain in conversation (without deliberately intending to; it's just easier to say than codomain, and so slips out). I hadn't realized that in fact some people deliberately use it as a synonym for codomain, rather than image; interesting! –  Matt E Sep 27 '10 at 3:21

Here is an answer which directly addresses the question in the title: the codomain has to be given as part of the information telling you what the functions is; it can't be deduced (or in the language of question, "defined") if all you know is the domain and values of the function. It is an extra piece of data. (This is why it seems arbitrary to you; you are thinking about how to determine the codomain from the other data, which can't be done! You have to be told what it is as part of the initial description of the function.)

First note that this is incompatible with one traditional definition of a function as being a set of ordered pairs. The set of ordered pairs definition determines the domain and values of the function, but not the codomain. (I guess that some people do use this definition of function; for them, a function doesn't have a codomain separate from its image.)

To define a function which has a domain and a codomain, one should instead use the scheme described by Ryan: a function is a triple (domain $A$, codomain $B$, set of elements of $A\times B$ determining its values).

As to why we introduce the concept of codomain, Qiaochu's answer describes this.

-

Yes it is arbitrary, and in a sense this is exactly the problem. When we have a function we would like to be able to talk about the inverse of the function (assuming it is 1-1.)

Consider the following: I have some function $f$ that maps $\mathbb{N} \rightarrow \mathbb{R}$ such that $$f(x) = (e^\sqrt{3.7x}+137.2)^3$$ The point here is that it is much easier to say that my codomain is $\mathbb{R}$ and my function is not surjective than to explicitly list the image of my function and say that $f$ is surjective on this subset of $\mathbb{R}$.

I know that every output will be a real number, but it is hard to say exactly which numbers I will get out of $f$ and which real numbers I can never get. To get to the point, if my function was surjective I know that I could plug any real number into $f^{-1}$. But I know it's not and I therefore have to be very careful with my inputs to $f^{-1}$, restricting my attention only to $f$'s image (otherwise the inverse is undefined.) In this case, we say that $f$ does not have the 'nice' property of surjectivity.

-

In the same sense you could ask why all functions aren't total functions. The real question is perhaps "what is the use of writing $f:\ S\rightarrow T$" or even more general "what is the use of writing "$v \in S$"?

I'd expect that in most cases where it is mentioned explicitly it's a way to say "this object belongs to this class of objects" and is done because it belonging to that class is somehow considered relevant or useful at that point. This might sound a bit obvious, but I don't think there is much more to it.

-
False, all functions are necessarily total. –  user126 Sep 26 '10 at 9:13
@97832123: Care to elaborate? Just saying something isn't true isn't really helpful. –  mweerden Sep 26 '10 at 9:51
It is part of a definition for a function to be total: a relation R is 'functional' if and only if for each x, there exists a unique y, such that xRy. A 'partial function' is not a function, but a generalization of the concept of function. –  Niel de Beaudrap Sep 26 '10 at 13:08
mweerden, there is quite a lot of variation among what people mean when they say "$f$ is a function", inside the mathematics community and to a slightly greater extent outside the mathematics community. The OP appears to be fairly comfortable with the set theoretic orthodoxy so that's why people are responding with that framework in mind. That said, I think some users tend to be a little overzealous in stating the correctness of their favourite interpretations. –  Ryan Budney Sep 26 '10 at 18:10
This article explains the set-theoretic orthodoxy on functions pretty well, including your question about being total: en.wikipedia.org/wiki/Function_%28mathematics%29 –  Ryan Budney Sep 26 '10 at 18:11
show 1 more comment

As far as I know, relations can be defined in two ways:

1. Given two sets $A$ and $B$, any subset $R$ of $A\times B$ is a relation. The domain is $\{x\in A:\exists y(y\in B,(x,y)\in R)\}$. The codomain is $\{y\in B:\exists x(x\in A,(x,y)\in R)\}$. Obviously the domain is a subset of $A$ and the codomain is a subset of $B$. Not every relation is surjective.
2. Every set that only contains ordered pairs is a relation. The domain is $\{x\in\bigcup\bigcup R:\exists y((x,y)\in R)\}$. The codomain is $\{y\in\bigcup\bigcup R:\exists x((x,y)\in R)\}$. Every relation is surjective.

My preferred definition is the first one, but you may like the second one, instead.

-