Let $f(x) = (|x_1| + |x_2|)^2$ for $x \in \mathbb{R}^2$
How do we find the subgradient $\partial f(x)$?
I tried to express $f(x)$ as $x_1^2 + x_2^2 + 2|x_1||x_2|$. I know how to handle the cases where neither of $x_1$ nor $x_2$ are 0, but I'm not sure how to handle the cases where $x_1$ or $x_2$ are $0$.
It's pretty straight forward. The subgradient of $|x|$ when $x\neq 0$ is $\text{sgn{x}}$, and $[-1,1]$ when $x=0$. Therefore $$ \partial\frac{1}{2}(|x_1|+|x_2|)^2 = \begin{cases} &x_i +\text{sgn}(x_i)|x_j|, &x_i\neq 0 \\ &[-1, 1]|x_j|, &x_i = 0 \end{cases} $$
Additional comment: I calculated this after unpacking the quadratic term, but notice that the chain rule would also work in this case. For the general case, let $h=f\circ g$. Assume $f$ is a nondecreasing convex function and $g$ is a convex function. Then for a point $x$, assuming that $f$ is differentiable at $g(x)$, the subdifferential $\partial h(x)=f'(g(x))\partial g(x)$. In your case, we may define $f(t)=\max\{t,0\}^2$ to get a nondecreasing convex function.