# Motivation for codomain of a function [duplicate]

Let's say we have a function f (x) = x and define its domain D to be the integers. Then according to calculus the image K of f is the set of all integers. However, I cannot quite understand the need to define codomain because isn't the codomain A of f just a set of numbers such that K is a subset of A? Because if that were the case, couldn't we chose any of Q, R, C or even the extended complex plane as the codomain of f? What have I gotten wrong, and what is the motivation for Codomain? :)

## marked as duplicate by Eric Wofsey, Leucippus, Namaste calculus StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Jul 9 '17 at 1:09

Any function $f:D\to A$ does in fact correspond to a surjective function $f:D\to K =f(D)$. That said, the concept of codomain is very useful when the image of $f$ is either unspecified, or is not known a priori. Consider for example the following.
• "A function $f:\mathbb{Q} \to \mathbb{R}$ cannot be surjective". In this case the function $f$ is unspecified, thus so is its image. However, the proposition is true, and easy to state in terms of codomain.
• "Define $f:\mathbb{N}\to\mathbb{N} \cup \{0\}$ as $f(n)$ is the number of ways that $2(n+1)$ can be written as a sum of two primes". It is not currently known whether $0$ does in fact belong to the image of $f$ i.e. whether $\,0 \in f(\mathbb{N})\,$ (though of course Goldbach's conjecture strongly suggests it doesn't).