Significance of codomain of a function

What I am trying to say is that range of $\sin x$ is $(-1,1)$.

You made a mistake here. The range of sine is a closed interval, which we denote with $[-1, 1]$, not an open one $(-1,1)$.

While as per my understanding codomain is $\Re$(real numbers).

Yup, real numbers. But they are usualy denoted with $\mathbb R$ (LaTeX/MathJax \mathbb R), not $\Re$ (\Re).

But defining codomain of $\sin x$ as say $(-2,2)$ is not going to change anything.

You're wrong. Redefining the codomain may change properties of a function. Giving the sine function a codomain of $(-2,2)$ doesn't change it much, but giving it $[-1,1]$ changes a lot:

$$\sin : \mathbb R \to [-1,1]$$

is a surjection (a function "onto"), while

$$\sin : \mathbb R \to \mathbb R$$

is not.

Redefining a domain may change the function's properties, too:

$$\sin : \left[0, \tfrac\pi 2\right] \to \mathbb R$$

is an injection (a function "into"), while

$$\sin : \left[0, \pi\right] \to \mathbb R$$

is not.

To answer specifically the last sentence from the question:

What compelled mathematicians to define codomain why were they not happy with the concept of range only.

Here I copy what I previously added in the comment below:

we need codomains, because we sometimes need to consider functions, whose definition is known together with a codomain, but the range is unknown. Sometimes we do not even have the definition, only some properties are known and we are satisfied with knowing the codomain without narrowing it to the range ("suppose $f$ is a real-valued function such that...; show $f$ is constant" – we know the codomain is $\mathbb R$ and we just need to show the range is one-point, not necessarily which one).

Expansion:

Be also aware that the range of a function may be hard to describe. For continuous real functions we consider at schools the range is often an interval or a sum of intervals – but those are special cases. There are functions with much less regular ranges.
For example see this question at Math.SE: Show that the function f is continuous only at the irrational points for a function described also at Wikipedia: Thomae's function – it is defined on real numbers, but its range is a set of reciprocals of all natural numbers and zero: $$\mathbb R \to \{\tfrac 1n:n\in\mathbb N\}\cup\{0\}.$$ One can easily declare a function whose range is literary any predefined nonempty set $S\subseteq\mathbb R$ – just choose any $s\in S$ and define: $$f:x\mapsto \begin{cases}x&\text{if }x\in S,\\s&\text{otherwise.}\end{cases}$$

In more general approach the range can be even harder to describe analytically.

Consider a function, whose parameter is real and values are pairs of real numbers (or complex numbers, which is equivalent to latter thanks to the complex plane by Jean-Robert Argand). If the function is continuous, its range is a curve on a plane. For example if the function is a position of a projectile in terms of a height and a distance, we get a complete trajectory. It's not too likely one will need to compare such trajectories – we will usually be interested in the maximum height and a maximum distance reachable under some conditions, but not the whole shape. Anyway, it is possible. But how would you compare a curve of a ballistic trajectory to a simple square? ...to a Koch snowflake? ...to the Warsaw Circle? ...or to a Heighway dragon?

And how about non-continuous functions, or those defined on some subsets of $\mathbb R$, whose ranges may become any figure on the plane, for example a family of concentric circles intersected by a family of parallel lines? ...or the interior of an annulus?

Things get even more weird if the 'target space' of a function is some more complex set, like a space of integer sequences, a space of real matrices $5\times 5$, a space of real functions integrable over a unit interval, and so on. You don't always need to know the range of a function, often it's just enough to know what its codomain is.


Generally function $f=(F,A,B)$ is defined by triple, where $A$, $B$ are sets, $F$ is functional graph and domain $pr_1F=A$ as it is in "Theory of Sets" N. Bourbaki. So you can consider different triples and obtain different functions.

Let's denote, for example, by SIN graph for $\sin$. Then $$(\text{SIN},\mathbb{R}, [-1, 1])$$ $$(\text{SIN},\mathbb{R},[-2,2])$$ Are formally different functions.