Given the function below, I would like to determine the Hessian with respect to $\mathbf{x}$, which will result in a $2 \times 2$ matrix. Note: $n$ and $\mathbf{z}$ are constants with respect to $\mathbf{x}$.
\begin{align}D(\cdot) &= \frac{1}{n^2}\left(1 + |x_1 - \frac{1}{2}|\right)\left(1 + |x_2 - \frac{1}{2}|\right) \\\\ &- \frac{2}{n}\left(1 + \frac{1}{2}|x_1 - \frac{1}{2}| - \frac{1}{2}|x_1 - \frac{1}{2}|^2\right) \left(1 + \frac{1}{2}|x_2 - \frac{1}{2}| - \frac{1}{2}|x_2 - \frac{1}{2}|^2\right) \\\\ &+ \frac{2}{n^2}\sum_{l=1}^{n-1}\left(1 + \frac{1}{2}|x_1 - \frac{1}{2}| + \frac{1}{2}|z_{l1} - \frac{1}{2}| - \frac{1}{2}|x_1 - z_{l1}|\right) \\\\ &* \left(1 + \frac{1}{2}|x_2 - \frac{1}{2}| + \frac{1}{2}|z_{l2} - \frac{1}{2}| - \frac{1}{2}|x_2 - z_{l2}|\right) \end{align}
A few notes: $\frac{d(|u(x)|)}{dx} = \text{sgn}(u(x))$ and $\frac{d(\text{sgn}(\cdot))}{dx} = 0$ except at $x$ (which I will ignore here)
Step 1: \begin{align}\frac{\partial(\cdot)}{\partial x_1} &= \frac{1}{n^2}\left(1 + |x_2 - \frac{1}{2}|\right)sgn\left(x_1 - \frac{1}{2}\right) \\\\ &- \frac{2}{n}\left(1 + \frac{1}{2}|x_2 - \frac{1}{2}| - \frac{1}{2}|x_2 - \frac{1}{2}|^2\right)\left(\frac{1}{2}sgn\left(x_1 - \frac{1}{2}\right) - |x_1 - \frac{1}{2}|sgn\left(x_1 - \frac{1}{2}\right) \right) \\\\ &+ \frac{2}{n^2}\sum_{l=1}^{n-1}\left(1 + \frac{1}{2}|x_2 - \frac{1}{2}| + \frac{1}{2}|z_{l2} - \frac{1}{2}| - \frac{1}{2}|x_2 - z_{l2}|\right) \\\\ &* \left(\frac{1}{2}sgn\left(x_1 - \frac{1}{2}\right) - \frac{1}{2}sgn\left(x_1 - z_{l1}\right) \right) \end{align}
Step 2: \begin{align}\frac{\partial^2(\cdot)}{\partial x_1^2} = \frac{2}{n}sgn\left(x_1 - \frac{1}{2}\right)sgn\left(x_1 - \frac{1}{2}\right) \left(1 + \frac{1}{2}|x_2 - \frac{1}{2}| - \frac{1}{2}|x_2 - \frac{1}{2}|^2\right)\end{align}
Step 3, similarly: \begin{align}\frac{\partial^2(\cdot)}{\partial x_2^2} = \frac{2}{n}sgn\left(x_2 - \frac{1}{2}\right)sgn\left(x_2 - \frac{1}{2}\right) \left(1 + \frac{1}{2}|x_1 - \frac{1}{2}| - \frac{1}{2}|x_1 - \frac{1}{2}|^2\right)\end{align}
Step 4: \begin{align}\frac{\partial^2(\cdot)}{\partial x_1x_2} &= \frac{1}{n^2} sgn\left(x_1 - \frac{1}{2}\right)sgn\left(x_2 - \frac{1}{2}\right) \\\\ &- \frac{2}{n}\left(\frac{1}{2}sgn\left(x_1 - \frac{1}{2}\right) - |x_1 - \frac{1}{2}|sgn\left(x_1 - \frac{1}{2}\right) \right) \\\\ &* \left(\frac{1}{2}sgn\left(x_2 - \frac{1}{2}\right) - |x_2 - \frac{1}{2}|sgn\left(x_2 - \frac{1}{2}\right) \right) \\\\ &+ \frac{1}{n^2}\sum_{l=1}^{n-1}\left(sgn\left(x_1 - \frac{1}{2}\right) - sgn\left(x_1 - z_{l1}\right)\right)\left(sgn\left(x_2 - \frac{1}{2}\right) - sgn\left(x_2 - z_{l2}\right)\right) \end{align}
Step 5:
$$ \frac{\partial^2(\cdot)}{\partial x_1x_2} = \frac{\partial^2(\cdot)}{\partial x_2x_1} $$ which can easily be confirmed.
Question:
Ignoring that $\frac{d(\text{sgn}(\cdot))}{dx}$ is undefined at $x$, is the above Hessian derivation correct? Am I simply able to treat $x_1$ and $z_{l1}$ as constants under the summation $\sum_{l=1}^{n-1}$ when determining $\frac{\partial^2(\cdot)}{\partial x_1x_2}$? Thanks!