When 2 functions are equal? Are 2 functions equal when they have same domain, same codomain and same law ?
EXAMPLE 1
$f: \mathbb{R} \to \mathbb{R}$
$x \to x^2$
and
$g: \mathbb{R} \to \mathbb{R^+_0}$    (set of positive reals with zero)
$x \to x^2$
are equal ?
EXAMPLE 2
$f: \mathbb{R} \to \mathbb{R}$
$x \to x^2$
and
$g: \mathbb{R^+_0} \to \mathbb{R}$
$x \to x^2$
are equal ?
 A: Functions are sets of cartesian products that fulfill certain conditions, so for example a function $\;f:A\to B\;$ is a subset $\;f\subset A\times B\;$ which must fulfill the condition that $\;(a,b),\,(a,b')\in f\implies b=b'\;$.
Thus, two function are equal if, when thinking of them as sets, they are equal as such, and this means they both are subsets of the same cartesian product $\;A\times B\;$ , which thus means they have exactly the same domain, and also
$$(a,b)\in f\iff (a,b)\in g$$
which means that pointwise they're identical, and in usual functionwise notation:: 
$$\;\forall\,a\in A\;,\;\;f(a)=g(a)\;$$
A: Ok, this is when a careful definition becomes so critical in answering a question. We need a careful set theoretic definition of a function and we need some prerequisite definitions.
Def: An ordered pair is the following set: 
   (a,b)= { {a},{a,b}} 
where a,b are elements. 2 ordered pairs are said to be equal iff they are subsets of each other.
Def: Let A and B be sets. Then the Cartesian product of 2 sets is the following set: 
$A\times B$ = { (a,b)| $a\in A$ and $b\in B$} 
Now the definition of a function: 
Def:Let A and B be sets. Then we define a function from A into B, denoted $f:A \rightarrow B$ as $f\subseteq A\times B$ such that (a,b),(a,d)$\in f$ iff b = d. (In other words,no 2 different ordered pairs in a function have the same first member.) A is called the domain the function and it consists of all the first members of all the ordered pairs of f. B is called the codomain of the function. The range of the function is the set of all second members of the ordered pairs of the function and it is a subset of B.   
Notice our definition of function is completely independent of whether or not it's defined by a formula or not.   
Now let's look at the examples. Consider example 1. Given the definition of f and g,despite having different codomains,the ranges of both functions is the set of positive reals because $x^2\geq 0$ for all $x\in \mathbb R$. Since the domains are $\mathbb R$ for both f and g ,clearly every ordered pair in f is in g and vice versa. Therefore f= g. 
Now consider example 2. The domain of f is $\mathbb R$ while the domain of g is $\mathbb R \geq 0$. Therefore, {(x,$x^2$)| $x\leq 0$ } $\subset f$ but  {(x,$x^2$)| $x\leq 0$ } is not a subset of g. Therefore f is not equal to g. 
