Absolute value: First Derivative Heaviside Function + Second Derivative Dirac Delta Function Distribution I have some issues concerning the derivative of an absolute value $|x|$, the Heaviside function $\theta(x)$ and the Dirac Delta Distribution.
Given the definition of the Heaviside function
\begin{equation}
  \theta(x) = \left\{
                \begin{array}{ll}
                  1 \quad \text{for} \quad x \ge 0\\
                  0 \quad \text{for} \quad x<0
                \end{array}
              \right.
\end{equation}
I suppose it is right to express the first derivative of an absolute value as
\begin{equation}
  \frac{d |x|}{dx} = \left\{
                \begin{array}{ll}
                  +1 \quad \text{for} \quad x > 0\\
                  -1 \quad \text{for} \quad x<0
                \end{array}
              \right.
\overset{!}{=} \theta(x) - \theta(-x),
\end{equation}
evaluating the derivatives of $|x|$ from the left and right side. Here I have some issues with the case of $x=0$
\begin{equation}
  \left.\frac{d |x|}{dx}\right|_{x=0}=\theta(0)-\theta(0)=1-1=0,
\end{equation}
which is not defined in my original "first derivative" of $d |x|/ dx$. 
So how can the first derivative of an absolute value be correctly expressed in terms of the Heaviside function?
Anyways taking my assumption of the first derivative for granted I want to perform a second derivative with the identity
\begin{equation}
  \frac{d \theta(x)}{dx} = \delta(x)
\end{equation},
which then leads to
\begin{equation}
  \frac{ d^2 |x|}{dx^2} = \frac{d}{dx}(\theta(x)-\theta(-x)) = \delta(x)-\delta(-x)=\delta(x)-\delta(x)=0.
\end{equation}
The last expression cannot be true and should be 
\begin{equation}
  \frac{d^2 |x|}{dx^2} = 2 \delta(x)
\end{equation}
following Second derivative of absolute value function proportional to Dirac delta function?
What am I missing to get to the correct expression?
 A: If you draw $|x|$ then you should see the derivative does depend on the direction you approach the point from.  Trying to assign it a numerical value does not make sense.  Your expressions are correct although you could try to assign the derivative to be infinite at $x=0$.
For your second point, the chain rule is missing from your calculation,
$$
\frac{d\theta(-x)}{dx} = \left.\frac{d(-x)}{dx} \frac{d\theta(y)}{dy}\right\vert_{y=-x} = - \delta(y)\vert_{y=-x} = -\delta(-x)=-\delta(x) .
$$
A: It does make more sense than you think, I think.
Although there is no true derivative for the absolute value, Ive seen optimization problems such as this treated.  I do believe it was called the "subgradient".
Basically you take the one-sided derivatives at $0$, and you get both $+1$ and $-1$ simultaneously for $x=0$, depending on the side you approach from.  This forms a range of values, I will express as the interval $(-1,1)$.  An argument can be made that $f' \in (-1,1)$, being all possible slopes concurrently.  This can be argued because any line you draw through the point at $x=0$ and having any slope in this range will fail to cross through the function.  And as you can see, $0\in(-1,1)$; a slope of $0$ is indicative of a peak. Consequently, $x=0$ is a local optimization point. So its not unreasonable to suggest that the derivative of $|x|$ at $x=0$ is zero, or, at least, we can say that a horizontal line is tangent to the function (i.e. touches it once without crossing) and that a peak exists there.
