Codomain (of a function)
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.
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).
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\)?
Narrowness is a virtue, especially in mathematics. The tighter and more precise you can make your statement, the more you could say about it.
But wouldn’t following that principle lead you to say the codomain is the positive reals, since that’s the smallest set that contains the image (i.e. it is the image)?
Yes, but the difference between reals and positive reals isn’t that big. However, I might be confused on this whole topic (see the other comment I tagged you in).
Fixed. (Would be nice to have a way to resolve these comments.)
Yes, I think I should have used “question/objection” rather than comment. (But I’m trying do what feels natural rather than using my inside information on how the platform is supposed to work.)