Are these functions equal? Consider the function $f:\mathbb R\to \mathbb R$ and $g:\mathbb R\to \mathbb R^+$ (in that question $\mathbb R^+$ is a set of nonnegative real numbers). And let define for any $x$ in domains of this functions $f(x)=x^2$ and $g(x)=x^2$. And if we look at set-theoretical definition of function it seems this functions must be equal, because $f$ contains all elements of $g$ and vice versa. But $f$ is not surjective but $g$ is. Isn't it a contradiction ? Or maybe I made a mistake and this functions are not equal, so are this functions equal ?
 A: The functions are not equal, since their codomains are different !
A: The mathematical definition of a function does not only consist of how it maps ($f(x)=\dots$) but also of from where to where it maps. So your functions are different as one can indeed see from the fact that one is surjective and the other is not.
A: In my book (Kunen's set theory), functions are sets of pairs fulfilling certain properties (specifically, no first component appears twice), along with a domain, consisting only of points which appear as the first component of the pairs. A codomain is not part of that definition, so any codomain you choose (as long as it contains the image) will result in an equal function.
Edit: Reviewing the definition (I.6.3 in the second edition), he doesn't even require a domain to define a function. Merely that it is a set of ordered pairs fulfilling the functional property. However, relations (such as functions) may be restricted to a product $A\times B$, and in so doing you get a domain and a codomain.
A: A function is defined using 3 things: domain, mapping, codomain.
Those 3 need to be always given at the definition, and 2 functions are equal if and only if all of those things are equal.
We have that the mapping and the domain are equal but the codomain is not equal (even though the images of the 2 are equal, only one of them is surjective)
A: A function $h : A \to B$ is defined as a subset $h \subseteq A \times B$ such that for every $x \in A$ there exists a unique $y \in B$ such that $(x,y) \in h$.
Your functions $f$ and $g$ are in this sense both equal to $$\{(x, x^2) : x \in \mathbb{R}\}$$
so $f = g$.
