# Minimizer of parametrized convex function

So let us consider the following minimization problem parametrized in $z$

\begin{align*} \min_{x \in \mathbb{R}} L_z(x) = \frac{1}{2} \left(x - z\right)^2 + |x| \end{align*}

The goal is to then find the minimizer when $z \in [-1,1]$. I will lay out my solution and why I am uncertain about how I got there. So if we find the gradient to look for critical points, we get that

\begin{align*} \frac{d L_z}{dx}(x^*) = 0 = \begin{cases} (x^* - z) + 1 & x^* \geq 0 \\ (x^* - z) - 1 & x^* < 0 \end{cases} \end{align*}

and so we find that the case-wise critical point is

\begin{align*} x^* = \begin{cases} z - 1 & x^* \geq 0 \\ z + 1 & x^* < 0 \end{cases} \end{align*}

If we look at the case that $x^* \geq 0$ and the fact that $z \in [-1,1]$, we find that $-2 \leq x^* \leq 0$. If we look at the latter case and the fact that $z \in [-1,1]$, we find that $0 \leq x^* \leq 2$.

Taking both of these inequalities into account, we find that $0 \leq x^* \leq 0$ and thus $x^* = 0$ $\forall z \in [-1,1]$. This is validated if one write a program to solve the problem.

My issue is I feel like I should have been explicitly taking into account the case inequalities such as $x^* \geq 0$ for the first case and $x^* < 0$ for the second case. Can anyone explain why this is or is not important to do and how I should be using it if it is necessary?

A minor error in your solution is that you've determined the derivative when $x=0$. This function is not differentiable at this point.
Suppose $x^\star>0$. Then, as you've shown, then $x^\star=z-1$. If $z=1$, then we see that $x^\star=0$, which is a contradiction. If $z<1$, then $x^\star<0$, which is also a contradiction. Therefore, $x^\star\leq 0$.
Suppose that $x^\star<0$. Then, as you've shown, $x^\star=z+1$. If $z=-1$ then $x^\star=0$, which is a contradiction. If $z>-1$ then $x^\star>0$, which is a contradiction.
When $z\in[-1,1]$, our suppositions that $x>0$ or $x<0$ lead to contradictions. Therefore, $x=0$.
Thus, $x=0$ is the optimal point for all cases.