Partial derivative of a Piecewise function If I have the following equation: 
$$ f(x,y) =
\begin{cases}
x; & y \ge 0 \\
y; & y < 0 \\
\end{cases}
$$
What are the partial derivatives (both x and y) of the function?
I have trouble applying the definition in these cases, how should i do it?
 A: For certain functions, it helps to think of computing the partial derivative at a point, instead of as a whole, and then fall back on the definition.
Let $(a,b)$ be a point. Consider the cases $b > 0$, $b = 0$, and $b < 0$ separately. First, $b > 0$:
$$\lim_{h \to 0} \frac{f(a+h,b) - f(a,b)}{h} - \lim_{h \to 0} \frac{a + h - a}{h} = 1 \implies \frac{\partial f}{\partial x}(a,b) = 1$$
$$\lim_{h \to 0} \frac{f(a,b+h) - f(a,b)}{h} - \lim_{h \to 0} \frac{a - a}{h} = 0 \implies \frac{\partial f}{\partial y}(a,b) = 0$$
Case: $b < 0$:
$$\lim_{h \to 0} \frac{f(a+h,b) - f(a,b)}{h} - \lim_{h \to 0} \frac{b - b}{h} = 0 \implies \frac{\partial f}{\partial x}(a,b) = 0$$
$$\lim_{h \to 0} \frac{f(a,b+h) - f(a,b)}{h} - \lim_{h \to 0} \frac{b + h - b}{h} = 1 \implies \frac{\partial f}{\partial x}(a,b) = 1$$
Case: $b = 0$:
$$\lim_{h \to 0} \frac{f(a+h,b) - f(a,b)}{h} - \lim_{h \to 0} \frac{a + h - a}{h} = 1 \implies \frac{\partial f}{\partial x}(a,b) = 1$$
$$\lim_{h \to 0} \frac{f(a,b+h) - f(a,b)}{h} = \textrm{DNE (consider the left and right limits)}$$

A more sophisticated way of doing this would be to note that, if $f,g$ are functions from $\mathbb{R}^n \to \mathbb{R}^m$ that agree on an open set $U \subseteq \mathbb{R}^n$ (i.e, $\forall x \in U$, $f(x) = g(x)$), then their partials agree on $U$ as well.
So we compare $f(x,y)$ to the functions $g_1(x,y) = x$ on $U_1 = \{ (x,y) \mid y > 0 \}$ and $g_2(x,y) = y$ on $U_2 = \{ (x,y) \mid y < 0 \}$, which have obvious partial derivatives. The case where $y = 0$ cannot be handled in this way, though.
