The codomain $~$\operatorname{cod}(f)$~$ of a function $~$f : X \to Y$~$ is $~$Y$~$, the set of possible outputs for the function. For example, the codomain of concat is the set of all strings, and the codomain of the function $~$+$~$ is the set of all numbers.

Visualizing a function as a map that takes every point in an input set to one point in an output set, the codomain is the output set (pictured on the right in blue in the image below).

The codomain of a function is not to be confused with the image of a function, which is the set of points in $~$Y$~$ that can actually be reached by following $~$f$~$, and which may not include the whole set $~$Y$~$. For example, consider all the functions that take a real number as input and produce another real number. Many of those functions cannot be made to produce every possible real number: For example, the function $~$\operatorname{square} : \mathbb R \to \mathbb R$~$ only produces non-negative numbers. For more on the distinction, see the page on codomain vs image.

[fixme: Add a lens talking about how codomains are arbitrary but often natural/useful. Use example like how we can consider $~$+$~$ to have codomain $~$\mathbb N$~$, $~$\mathbb Z$~$, etc., and examples like Ackerman where the codomain "nat" makes by far the most sense (though "int" is fine too).]

## Comments

Eric Rogstad

Does this make the definition of the codomain somewhat arbitrary?

The squares of reals happen to be a subset of the reals, but they're also a subset of all complex numbers. Why say the codomain is $~$\mathbb R$~$ rather than $~$\mathbb C$~$?