In class we have been learning about functions, and that if $f:A\to B$ and $g: A^{'} \to B^{'}$, then $f=g$ if and only if $A=A^{'}$ and $B=B^{'}$ and they share the same values.
Why does $B=B^{'}$ have to be the case? Why can't we base it solely on sharing the same values, or perhaps at least the codomain containing the entire image?
Example; Let $f: \mathbb{R} \to \mathbb{R}$ where $f(x) = x^2$. Let $g: \mathbb{R} \to \{x \in \mathbb{R} : x \geq 0 \}$ where $g(x) = x^2$. Intuitively I would say these functions are equivalent as they share the same values, but by the definition they're not. Why?
Defining them this way let us ask more interesting question such as does every element of the codomain has a preimage, also known as surjective/ onto.
For the first case, $f$ does not have this property.
But for the second case, every element of the codomain does have a preimage.
So why do we study surjective function? If a function is one-to-one and onto, then we know that the inverse of a function exists.