# Why co-domain of a function needs to be defined beyond the function's range?

I've recently watched this video and struggle to wrap my mind around difference between codomain and range of a function. I understand that range is a subset of the codomain, but at the same time if there is no any restrictions on how the codomain is defined, why it needs to be defined beyond the range? Is it author of a function who defines the codomain? And if so, what makes him define the codomain beyond the range of a function (as the author, he is supposed to know all possible restrictions).

If it's not "authors" but rather for consumers of a function, who have to deduce the codomain, how can they even approximate the codomain without knowing entire range? And if they know the range, why again codomain needs to be defined beyond range?

Yes, it is the

author of a function who defines the codomain

but the author may not have a particular function with known range when starting the discussion.

For example, we often want to consider the set of all real valued functions of a real variable. Those functions all have domain and codomain $$\mathbb{R}$$. Some of them will have range $$\mathbb{R}$$, some not.

In computer programming languages you often have to specify the domain and codomain (the "types") without knowing the range.

Finding the range might actually be quite difficult, or even unknown. For example, no one knows whether there are any odd perfect numbers. What is the range of the function with domain the odd natural numbers and codomain $$\{0,1\}$$ such that $$f(n) = 1$$ if $$n$$ is a perfect number, $$f(n) = 0$$ otherwise?

The consumer of a properly defined function will never have to deduce the codomain, since the codomain is part of the definition of such a function. When the codomain is "obvious" it may not be explicitly specified, but it is part of the definition of the function.

Having the codomain different from the range of the function is an essential property of functions. We say a function is surjective if its range is equal to the codomain, and this property permeates all of mathematics. In fact, strictly speaking we would say that a function $$f:A\to B$$ is a different function from $$f:A\to R(f)$$, where $$f$$ is the range of $$f$$, if $$R(f)\neq B$$. Indeed, the functions act identically on elements of $$A$$, but one is surjective, the other is not.

It is also useful in a different sense. Sometimes two spaces $$A$$ and $$B$$ are interesting objects in themselves, and so you want to consider functions between them, i.e. $$f:A\to B$$. Requiring that $$f$$ is surjective, i.e. that $$R(f)=B$$, is too restrictive, so you lose a lot of important functions.

Considering the range of a function as a subset of the codomain is a very important approach both in linear algebra, abstract algebra, topology, geometry and many more.

Hope this gives you some idea why it is important to separate the idea of range and of codomain.